pax_global_header00006660000000000000000000000064151357423460014524gustar00rootroot0000000000000052 comment=f7edb0869e64b9d687f46961adeef7154921fe92 picolibc-1.8.11/000077500000000000000000000000001513574234600134005ustar00rootroot00000000000000picolibc-1.8.11/.clang-format000066400000000000000000000030771513574234600157620ustar00rootroot00000000000000--- BasedOnStyle: WebKit AlignAfterOpenBracket: Align AlignArrayOfStructures: Left AlignConsecutiveBitFields: Enabled: true AlignConsecutiveDeclarations: Enabled: true AcrossEmptyLines: true AcrossComments: true AlignFunctionDeclarations: true AlignFunctionPointers: true PadOperators: true AlignConsecutiveMacros: Enabled: true AcrossEmptyLines: true AlignEscapedNewlines: LeftWithLastLine AlignTrailingComments: Kind: Always OverEmptyLines: 0 AllowShortFunctionsOnASingleLine: Inline AttributeMacros: - '__pure' - '__picolibc_format' - '__nonnull' - '__returns_nonnull' - '__alloc_size' - '__alloc_size2' - '__alooc_align' - '__noreturn' - '__const' - '__unused' - '__used' - '__packed' - '__aligned' - '__section' - '__naked' - '__noinline' - '__always_inline' - '__warn_unused_result' - '__weak' - '__nothrow' - '__no_sanitize_address' - '__no_sanitize' - '__no_sanitize_undefined' - '__disable_sanitizer_instrumentation' - '__disable_sanitizer' - '__deprecated_m' - '__deprecated' - '__no_builtin' - '__malloc_like_with_free' - '__malloc_like' - '__returns_twice' BreakAfterReturnType: AllDefinitions ColumnLimit: 100 PointerAlignment: Right SortIncludes: Enabled: false SpaceAroundPointerQualifiers: Before StatementMacros: - '__ssp_redirect' - '__ssp_redirect_raw' - '__ssp_redirect_wc' - '__ssp_redirect0' - '__ssp_bos_wicheck3' - '__ssp_bos_wicheck3_restrict' - '__ssp_bos_wicheck2_restrict' TypenameMacros: - '__declare_extern_inline' - '__strong_reference' - '__weak_reference' ... picolibc-1.8.11/.clang-format-ignore000066400000000000000000000000411513574234600172270ustar00rootroot00000000000000!**/*.[ch] **/*asm*.h **/*.ld.in picolibc-1.8.11/.editorconfig000066400000000000000000000002571513574234600160610ustar00rootroot00000000000000[*] tab_width = 8 charset = utf-8 insert_final_newline = true [*.{c,h,s,S}] indent_size = 4 indent_style = space [meson*] indent_style = space [*.yml] indent_style = space picolibc-1.8.11/.gitattributes000066400000000000000000000011451513574234600162740ustar00rootroot00000000000000# -*- conf -*- ## Set merge driver for ChangeLog files # See gnulib's lib/git-merge-changelog.c (or git-merge-changelog(1)) # for per-user setup instructions. # # The short version of this (optional) procedure is: # # (1) Install git-merge-changelog (this is the tricky part!) # # (2) Add something like the following to your ~/.gitconfig: # # [merge "merge-changelog"] # name = GNU-style ChangeLog merge driver # driver = git-merge-changelog %O %A %B # # (3) Enjoy mostly effortless ChangeLog merges, at least until the # file gets renamed again ... ChangeLog merge=merge-changelog picolibc-1.8.11/.github/000077500000000000000000000000001513574234600147405ustar00rootroot00000000000000picolibc-1.8.11/.github/CODEOWNERS000066400000000000000000000000731513574234600163330ustar00rootroot00000000000000# Automatically request review on all PRs * @keith-packard picolibc-1.8.11/.github/Dockerfile000066400000000000000000000016141513574234600167340ustar00rootroot00000000000000FROM debian:sid COPY .github/linux-packages.txt / COPY .github/linux-files.txt / RUN dpkg --add-architecture i386 && \ (apt-get update || apt-get update || apt-get update) && \ (apt-get upgrade -y || apt-get upgrade -y || apt-get upgrade -y) && \ (xargs -a linux-packages.txt apt-get install -y --no-install-recommends || \ xargs -a linux-packages.txt apt-get install -y --no-install-recommends || \ xargs -a linux-packages.txt apt-get install -y --no-install-recommends || \ xargs -a linux-packages.txt apt-get install -y --no-install-recommends) && \ apt-get clean && \ mkdir -p /opt && \ (cd /opt && \ for file in `cat /linux-files.txt`; do \ echo "Fetching $file"; \ wget -nv "$file" || exit 1; \ echo "Unpacking $file"; \ tar xf `basename "$file"`; \ echo "Removing $file"; \ rm `basename "$file"`; \ done) && \ rm -rf /var/lib/apt/lists/* picolibc-1.8.11/.github/Dockerfile-check-format000066400000000000000000000016271513574234600213010ustar00rootroot00000000000000FROM debian:sid COPY .github/check-format-packages.txt / COPY .github/check-format-files.txt / RUN (apt-get update || apt-get update || apt-get update) && \ (apt-get upgrade -y || apt-get upgrade -y || apt-get upgrade -y) && \ (xargs -a check-format-packages.txt apt-get install -y --no-install-recommends || \ xargs -a check-format-packages.txt apt-get install -y --no-install-recommends || \ xargs -a check-format-packages.txt apt-get install -y --no-install-recommends || \ xargs -a check-format-packages.txt apt-get install -y --no-install-recommends) && \ apt-get clean && \ mkdir -p /opt && \ (cd /opt && \ for file in `cat /check-format-files.txt`; do \ echo "Fetching $file"; \ wget -nv "$file" || exit 1; \ echo "Unpacking $file"; \ tar xf `basename "$file"`; \ echo "Removing $file"; \ rm `basename "$file"`; \ done) && \ rm -rf /var/lib/apt/lists/* picolibc-1.8.11/.github/Dockerfile-coreboot000066400000000000000000000020201513574234600205360ustar00rootroot00000000000000# syntax=docker/dockerfile:1 FROM coreboot/coreboot-sdk COPY .github/coreboot-packages.txt / COPY .github/coreboot-files.txt / USER root RUN apt-get update && \ apt-get install -y --no-install-recommends ca-certificates wget gnupg && \ (apt-get update || apt-get update || apt-get update) && \ (apt-get upgrade -y || apt-get upgrade -y || apt-get upgrade -y) && \ (xargs -a coreboot-packages.txt apt-get install -y --no-install-recommends || \ xargs -a coreboot-packages.txt apt-get install -y --no-install-recommends || \ xargs -a coreboot-packages.txt apt-get install -y --no-install-recommends || \ xargs -a coreboot-packages.txt apt-get install -y --no-install-recommends) && \ mkdir -p /opt && \ (cd /opt && \ for file in `cat /coreboot-files.txt`; do \ echo "Fetching $file"; \ wget "$file" || exit 1; \ echo "Unpacking $file"; \ tar xf `basename "$file"`; \ echo "Removing $file"; \ rm `basename "$file"`; \ done) && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* picolibc-1.8.11/.github/Dockerfile-zephyr000066400000000000000000000022351513574234600202530ustar00rootroot00000000000000# syntax=docker/dockerfile:1 FROM debian:sid COPY .github/zephyr-packages.txt / COPY .github/zephyr-files.txt / COPY .github/zephyr-setup / RUN (apt-get update || apt-get update || apt-get update) && \ (apt-get upgrade -y || apt-get upgrade -y || apt-get upgrade -y) && \ (xargs -a zephyr-packages.txt apt-get install -y --no-install-recommends || \ xargs -a zephyr-packages.txt apt-get install -y --no-install-recommends || \ xargs -a zephyr-packages.txt apt-get install -y --no-install-recommends || \ xargs -a zephyr-packages.txt apt-get install -y --no-install-recommends) && \ apt-get clean && \ mkdir -p /opt && \ (cd /opt && \ for file in `cat /zephyr-files.txt`; do \ echo "Fetching $file"; \ wget -nv "$file" || exit 1; \ echo "Unpacking $file"; \ tar xf `basename "$file"`; \ echo "Removing $file"; \ rm `basename "$file"`; \ done) && \ if [ -f /opt/zephyr-sdk-*-hosttools*.sh ]; then \ echo "Unpacking host tools"; \ /opt/zephyr-sdk-*-hosttools*.sh -y -d /opt/zephyr-sdk-hosttools; \ rm /opt/zephyr-sdk-*-hosttools*.sh; \ else \ echo "No host tools found"; \ fi && \ rm -rf /var/lib/apt/lists/* picolibc-1.8.11/.github/check-format-files.txt000066400000000000000000000000001513574234600211320ustar00rootroot00000000000000picolibc-1.8.11/.github/check-format-packages.txt000066400000000000000000000000331513574234600216140ustar00rootroot00000000000000clang-format findutils git picolibc-1.8.11/.github/coreboot-files.txt000066400000000000000000000000001513574234600204030ustar00rootroot00000000000000picolibc-1.8.11/.github/coreboot-packages.txt000066400000000000000000000000001513574234600210570ustar00rootroot00000000000000picolibc-1.8.11/.github/dependabot.yml000066400000000000000000000002031513574234600175630ustar00rootroot00000000000000version: 2 updates: - package-ecosystem: github-actions directory: "/" schedule: interval: "daily" target-branch: "main" picolibc-1.8.11/.github/do-arm000077500000000000000000000011461513574234600160470ustar00rootroot00000000000000#!/bin/sh set -e HERE=`dirname "$0"` "$HERE"/do-test native -Dnative-tests=false -Dtests-enable-posix-io=false "$HERE"/do-test native -Dnative-tests=false -Dtests-enable-posix-io=false -Dio-float-exact=false -Dio-long-long=true -Dio-percent-b=true -Dio-long-double=true -Dnewlib-obsolete-math=false -Dwant-math-errno=true -Dnewlib-multithread=false -Dnewlib-retargetable-locking=false -Dmb-capable=true -Dnewlib-nano-malloc=false -Dpicoexit=false "$HERE"/do-test native -Dnative-tests=false -Dtests-enable-posix-io=false -Dformat-default=integer -Dposix-io=false -Dnewlib-obsolete-math=true -Dwant-math-errno=true picolibc-1.8.11/.github/do-avr000077500000000000000000000001631513574234600160560ustar00rootroot00000000000000#!/bin/bash export AVR_SDK_INSTALL_DIR=/opt/avr-gcc-12.1.0-x64-linux PATH=$AVR_SDK_INSTALL_DIR/bin:$PATH exec "$@" picolibc-1.8.11/.github/do-avr-build000077500000000000000000000001051513574234600171470ustar00rootroot00000000000000#!/bin/bash here=`dirname "$0"` "$here"/do-avr "$here"/do-build "$@" picolibc-1.8.11/.github/do-build000077500000000000000000000017321513574234600163700ustar00rootroot00000000000000#!/bin/sh HERE=`dirname "$0"` TARGET=$1 shift if [ -d /opt/picolibc-ci ]; then TOP=/opt/picolibc-ci else TOP=/opt fi # Put only the relevant toolchain in PATH for specific CI targets. # Fallback to previous behavior for other targets. case "$TARGET" in *clang-hexagon*) for p in "$TOP"/*hexagon*/bin "$TOP"/*/models/*; do [ -d "$p" ] && PATH="$p":$PATH done ;; *clang-arm*|*clang-aarch64*|*clang-thumb*) for p in "$TOP"/LLVM-ET-Arm*/bin "$TOP"/*/models/*; do [ -d "$p" ] && PATH="$p":$PATH done ;; *) for p in "$TOP"/*/bin "$TOP"/*/models/*; do PATH="$p":$PATH done ;; esac ANALYZER="-Danalyzer=true" CDEFS="-Dtests-cdefs=true -Dtests=false" # Disable analyzer on m68k because the compiler gets very confused # about complex values case "$TARGET" in *m68k*) ANALYZER="" ;; esac OPTIONS="$ANALYZER $CDEFS" "$HERE"/do-run "$TARGET" $OPTIONS "$@" picolibc-1.8.11/.github/do-check-format000077500000000000000000000001531513574234600176300ustar00rootroot00000000000000#!/bin/sh git config --global --add safe.directory /picolibc git ls-files | xargs clang-format -n --Werror picolibc-1.8.11/.github/do-cmake-linux000077500000000000000000000002731513574234600175050ustar00rootroot00000000000000#!/bin/sh set -e HERE=`dirname "$0"` for target in cmake-thumbv6m cmake-clang-thumbv6m cmake-thumbv7m cmake-clang-thumbv7m cmake-rx; do "$HERE"/do-cmake-test "$target" "$@" "$@" done picolibc-1.8.11/.github/do-cmake-test000077500000000000000000000017131513574234600173250ustar00rootroot00000000000000#!/bin/sh TARGET=$1 DIR=build-"$TARGET" CONFIGURE=do-"$TARGET"-configure shift # Put only the relevant toolchain in PATH for specific CI targets. # Fallback to previous behavior for other targets. case "$TARGET" in *clang-thumb*) for p in /opt/LLVM-ET-Arm*/bin /opt/*/models/*; do [ -d "$p" ] && PATH="$p":$PATH done ;; *) for p in /opt/*/bin /opt/*/models/*; do PATH="$p":$PATH done ;; esac mkdir $DIR trap 'rm -rf "$DIR"' 0 (cd $DIR || exit 1 echo '##################################################' echo '##########' ../scripts/"$CONFIGURE" "$@" echo '##################################################' ../scripts/$CONFIGURE "$@" case $? in 0) echo 'Configuration succeeded' ;; 77) echo 'Configuration skipped' exit 0 ;; *) echo 'Configuration failed' exit 1 ;; esac cat CMakeFiles/CMakeOutput.log ninja --quiet && ninja --quiet test) || exit 1 picolibc-1.8.11/.github/do-coreboot000077500000000000000000000003101513574234600170740ustar00rootroot00000000000000#!/bin/sh set -e HERE=`dirname "$0"` "$HERE"/do-test coreboot-arm-eabi "$@" "$HERE"/do-test coreboot-i386-elf "$@" "$HERE"/do-test coreboot-riscv-elf "$@" "$HERE"/do-test coreboot-x86_64-elf "$@" picolibc-1.8.11/.github/do-linux-arm000077500000000000000000000003511513574234600172010ustar00rootroot00000000000000#!/bin/sh set -e HERE=`dirname "$0"` "$HERE"/do-test-noopt arm "$@" "$HERE"/do-test clang-arm "$@" "$HERE"/do-test aarch64 "$@" "$HERE"/do-test cortex-a9 "$@" "$HERE"/do-test clang-aarch64 "$@" "$HERE"/do-test clang-aarch64-fvp "$@" picolibc-1.8.11/.github/do-linux-misc000077500000000000000000000014411513574234600173560ustar00rootroot00000000000000#!/bin/sh set -e HERE=`dirname "$0"` "$HERE"/do-build lx106 "$@" "$HERE"/do-build powerpc64le "$@" "$HERE"/do-build powerpc64 "$@" "$HERE"/do-test loongarch64 "$@" "$HERE"/do-build sparc64 "$@" "$HERE"/do-test-noopt clang-x86 "$@" "$HERE"/do-test-noopt clang-x86_64 "$@" "$HERE"/do-test-noopt x86_64 "$@" "$HERE"/do-test-noopt i386 "$@" "$HERE"/do-test-noopt native "$@" "$HERE"/do-test power9 "$@" "$HERE"/do-test power9-fp128 "$@" "$HERE"/do-build mips64 "$@" "$HERE"/do-build mips "$@" "$HERE"/do-build mipsel "$@" "$HERE"/do-test clang-hexagon "$@" "$HERE"/do-test-noopt x86 "$@" "$HERE"/do-test m68k-unknown-elf "$@" "$HERE"/do-test rx-zephyr-elf "$@" "$HERE"/do-test sh-unknown-elf "$@" "$HERE"/do-avr-build avr "$@" "$HERE"/do-test msp430-unknown-elf "$@" "$HERE"/do-test lm32-unknown-elf "$@" picolibc-1.8.11/.github/do-linux-riscv000077500000000000000000000003271513574234600175530ustar00rootroot00000000000000#!/bin/sh set -e HERE=`dirname "$0"` "$HERE"/do-test-noopt riscv "$@" "$HERE"/do-test-noopt clang-riscv "$@" "$HERE"/do-test-noopt clang-rv32imafdc "$@" "$HERE"/do-test-noopt rv32imac "$@" "$HERE"/do-test or1k "$@" picolibc-1.8.11/.github/do-many000077500000000000000000000005531513574234600162350ustar00rootroot00000000000000#!/bin/bash dir=`dirname $0` scripts=() configs=() dirs=() working=t while [ $working = t ]; do if [ "$1" = "end" -o "$1" = "--" -o "$1" = "" ]; then shift working=f else scripts+=($1) shift configs+=($1) shift dirs+=($1) shift fi done for i in ${!scripts[@]}; do "$dir"/"${scripts[$i]}" "${configs[$i]}" "${dirs[$i]}" "$@" || exit 1 done picolibc-1.8.11/.github/do-native000077500000000000000000000001551513574234600165550ustar00rootroot00000000000000#!/bin/sh set -e HERE=`dirname "$0"` "$HERE"/do-test-noopt native "$@" "$HERE"/do-test-noopt native-m32 "$@" picolibc-1.8.11/.github/do-native-math000077500000000000000000000001441513574234600175020ustar00rootroot00000000000000#!/bin/sh set -e HERE=`dirname "$0"` "$HERE"/do-test-noopt native -Dexhaustive-math-tests=true "$@" picolibc-1.8.11/.github/do-run000077500000000000000000000043301513574234600160720ustar00rootroot00000000000000#!/bin/sh TARGET=$1 DIR=build-"$TARGET" CONFIGURE=do-"$TARGET"-configure shift (mkdir "$DIR" || exit 1 cd "$DIR" || exit 2 echo '##################################################' echo '##########' ../scripts/"$CONFIGURE" -Dwerror=true -Ddebug=false "$@" echo '##################################################' date ../scripts/"$CONFIGURE" -Dwerror=true -Ddebug=false "$@" > config.log 2>&1 case $? in 0) echo 'Configuration succeeded' ;; 77) echo 'Configuration skipped' exit 0 ;; *) exit 3 ;; esac echo '##########' "$TARGET" 'ninja' date ninja > ninja.log 2>&1 || exit 4 echo 'Build succeeded' echo '##########' "$TARGET" 'meson test -t 20' date meson test -t 20 > test.log 2>&1 || exit 5 echo 'Test succeeded' date) case $? in 0) rm -rf "$DIR" ;; 1) echo '##################################' echo '############# mkdir' "$DIR" 'failed' echo '##################################' exit 1 ;; 2) echo '##################################' echo '############# cd' "$DIR" 'failed' echo '##################################' exit 1 ;; 3) echo '##################################' echo '############# Configuration failed' echo '##################################' echo 'config.log' echo '##################################' cat "$DIR"/config.log echo '##################################' echo 'meson-logs/meson-log.txt' echo '##################################' cat "$DIR"/meson-logs/meson-log.txt exit 1 ;; 4) echo '##################################' echo '############# Build failed' echo '##################################' echo 'ninja.log' echo '##################################' cat "$DIR"/ninja.log exit 1 ;; 5) echo '##################################' echo '############# Test failed' echo '##################################' echo 'test.log' echo '##################################' cat "$DIR"/test.log echo '##################################' echo 'meson-logs/testlog.txt' echo '##################################' cat "$DIR"/meson-logs/testlog.txt exit 1 ;; *) echo '##################################' echo '############# Unknown failure' "$?" echo '##################################' cat "$DIR"/meson-logs/* exit 1 ;; esac picolibc-1.8.11/.github/do-test000077500000000000000000000023271513574234600162510ustar00rootroot00000000000000#!/bin/sh HERE=`dirname "$0"` TARGET="$1" shift if [ -d /opt/picolibc-ci ]; then TOP=/opt/picolibc-ci else TOP=/opt fi # Put only the relevant toolchain in PATH for specific CI targets. # Fallback to previous behavior for other targets. case "$TARGET" in *clang-hexagon*) for p in "$TOP"/*hexagon*/bin "$TOP"/*/models/*; do [ -d "$p" ] && PATH="$p":$PATH done ;; *clang-arm*|*clang-aarch64*|*clang-thumb*) for p in "$TOP"/LLVM-ET-Arm*/bin "$TOP"/*/models/*; do [ -d "$p" ] && PATH="$p":$PATH done ;; *) for p in "$TOP"/*/bin "$TOP"/*/models/*; do PATH="$p":$PATH done ;; esac # We can't use both the analyzer and sanitizer because # the analyzer is run after the sanitizer and generates a lot # of false positives, so just use the sanitizer as it # appears to find more relevant bugs at this point. SANITIZER="-Dsanitize=undefined" # Use traps with the sanitizer on msp430 as the handlers make many # tests too large case "$TARGET" in *msp430*) SANITIZER="$SANITIZER -Dsanitize-trap-on-error=true" ;; esac OPTIONS="$SANITIZER -Dexhaustive-math-tests=native" "$HERE"/do-run "$TARGET" $OPTIONS "$@" picolibc-1.8.11/.github/do-test-noopt000077500000000000000000000004271513574234600174050ustar00rootroot00000000000000#!/bin/sh HERE=`dirname "$0"` TARGET=$1 shift ANALYZER="-Danalyzer=true" # Disable analyzer on m68k because the compiler gets very confused # about complex values case "$TARGET" in *m68k*) ANALYZER="" ;; esac OPTIONS="$ANALYZER" "$HERE"/do-run "$TARGET" $OPTIONS "$@" picolibc-1.8.11/.github/do-zephyr000077500000000000000000000012071513574234600166070ustar00rootroot00000000000000#!/bin/sh set -e HERE=`dirname "$0"` "$HERE"/do-zephyr-test aarch64-zephyr "$@" "$HERE"/do-zephyr-test arc "$@" "$HERE"/do-zephyr-test arc64 "$@" "$HERE"/do-zephyr-build microblazeel "$@" "$HERE"/do-zephyr-test mips-zephyr "$@" "$HERE"/do-zephyr-test nios2 "$@" "$HERE"/do-zephyr-test sparc-zephyr "$@" "$HERE"/do-zephyr-test x86_64-zephyr "$@" "$HERE"/do-zephyr-test xtensa-dc233c "$@" "$HERE"/do-zephyr-build xtensa-espressif_esp32 "$@" "$HERE"/do-zephyr-build xtensa-espressif_esp32s2 "$@" "$HERE"/do-zephyr-build xtensa-nxp_imx_adsp "$@" "$HERE"/do-zephyr-build xtensa-nxp_imx8m_adsp "$@" "$HERE"/do-zephyr-build xtensa-sample_controller "$@" picolibc-1.8.11/.github/do-zephyr-build000077500000000000000000000001051513574234600177000ustar00rootroot00000000000000#!/bin/bash here=`dirname "$0"` "$here"/zephyr "$here"/do-build "$@" picolibc-1.8.11/.github/do-zephyr-test000077500000000000000000000001041513574234600175570ustar00rootroot00000000000000#!/bin/bash here=`dirname "$0"` "$here"/zephyr "$here"/do-test "$@" picolibc-1.8.11/.github/linux-files.txt000066400000000000000000000025541513574234600177460ustar00rootroot00000000000000https://github.com/picolibc/picolibc-ci-tools/releases/download/v11/avr.linux-amd64.tar.xz https://github.com/picolibc/picolibc-ci-tools/releases/download/v11/lm32-unknown-elf.linux-amd64.tar.xz https://github.com/picolibc/picolibc-ci-tools/releases/download/v11/loongarch64-unknown-elf.linux-amd64.tar.xz https://github.com/picolibc/picolibc-ci-tools/releases/download/v11/m68k-unknown-elf.linux-amd64.tar.xz https://github.com/picolibc/picolibc-ci-tools/releases/download/v11/msp430-unknown-elf.linux-amd64.tar.xz https://github.com/picolibc/picolibc-ci-tools/releases/download/v11/or1k-unknown-elf.linux-amd64.tar.xz https://github.com/picolibc/picolibc-ci-tools/releases/download/v11/rx-zephyr-elf.linux-amd64.tar.xz https://github.com/picolibc/picolibc-ci-tools/releases/download/v11/sh-unknown-elf.linux-amd64.tar.xz https://github.com/picolibc/picolibc-ci-tools/releases/download/v11/qemu-stable.linux-amd64.tar.xz https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-18.1.3/LLVM-ET-Arm-18.1.3-Linux-x86_64.tar.xz https://github.com/picolibc/toolchains/raw/refs/heads/main/FVP_Base_RevC-2xAEMvA_11.28_23_Linux64-nonexecstack.tar.xz https://github.com/picolibc/picolibc-ci-tools/releases/download/v11/clang-hexagon-toolchain.Linux-x86_64.tar.xz https://github.com/picolibc/picolibc-ci-tools/releases/download/v11/qemu-hexagon.linux-amd64.tar.xz picolibc-1.8.11/.github/linux-packages.txt000066400000000000000000000013251513574234600204150ustar00rootroot00000000000000build-essential meson cmake file ninja-build gcc libx32gcc-15-dev lib32gcc-15-dev gcc-i686-linux-gnu libc6-dev-i386-cross gcc-arm-none-eabi gcc-riscv64-unknown-elf gcc-aarch64-linux-gnu libc6-dev-arm64-cross gcc-xtensa-lx106 gcc-mips-linux-gnu libc6-dev-mips-cross gcc-mips64-linux-gnuabi64 libc6-dev-mips64-cross gcc-mipsel-linux-gnu libc6-dev-mipsel-cross gcc-or1k-elf gcc-powerpc64-linux-gnu libc6-dev-ppc64-cross gcc-powerpc64le-linux-gnu libc6-dev-ppc64el-cross gcc-sparc64-linux-gnu libc6-dev-sparc64-cross libc6:i386 libc6-dev-i386 lib32stdc++-15-dev lld clang llvm-libunwind1 qemu-system-x86 qemu-system-arm qemu-system-misc qemu-system-ppc64 libdbus-1-dev ca-certificates wget gnupg locales libc++-dev libc++abi-dev picolibc-1.8.11/.github/workflows/000077500000000000000000000000001513574234600167755ustar00rootroot00000000000000picolibc-1.8.11/.github/workflows/.editorconfig000066400000000000000000000001231513574234600214460ustar00rootroot00000000000000[*] tab_width = 8 charset = utf-8 insert_final_newline = true indent_style = space picolibc-1.8.11/.github/workflows/Makefile000066400000000000000000000014101513574234600204310ustar00rootroot00000000000000LINUX_DEPS=\ make-workflow \ head \ variants-cmake \ variants \ steps-head \ steps-cmake \ steps-minsize \ steps-release all: linux.yml zephyr.yml native.yml linux.yml: $(LINUX_DEPS) ./make-workflow > $@ ZEPHYR_DEPS=\ make-workflow-zephyr \ head-zephyr \ variants \ steps-head \ steps-minsize \ steps-release zephyr.yml: $(ZEPHYR_DEPS) ./make-workflow-zephyr > $@ NATIVE_DEPS=\ make-workflow \ head-native \ variants \ steps-head \ steps-minsize \ steps-release native.yml: $(NATIVE_DEPS) ./make-workflow-native > $@ COREBOOT_DEPS=\ make-workflow-coreboot \ head-coreboot \ variants \ steps-head \ steps-minsize \ steps-release coreboot.yml: $(COREBOOT_DEPS) ./make-workflow-coreboot > $@ clean: rm -f linux.yml zephyr.yml coreboot.yml picolibc-1.8.11/.github/workflows/check-format.yml000066400000000000000000000045061513574234600220700ustar00rootroot00000000000000name: Check Format on: push: branches: - main pull_request: branches: - main workflow_dispatch: permissions: contents: read # When a PR is updated, cancel the jobs from the previous version. Merges # do not define head_ref, so use run_id to never cancel those jobs. concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true env: DOCKERFILE: picolibc/.github/Dockerfile-check-format IMAGE_FILE: dockerimg-check-format.tar.zst IMAGE: picolibc-check-format PACKAGES_FILE: picolibc/.github/check-format-packages.txt EXTRA_FILE: picolibc/.github/check-format-files.txt jobs: cache-maker: runs-on: ubuntu-latest steps: - name: Clone picolibc uses: actions/checkout@v6 with: path: picolibc - name: Cache the Docker Image id: cache uses: actions/cache@v5 with: path: ${{ env.IMAGE_FILE }} key: ${{ env.IMAGE_FILE }}-${{ hashFiles( env.DOCKERFILE, env.PACKAGES_FILE, env.EXTRA_FILE ) }} lookup-only: true - name: Set up Docker Buildx if: steps.cache.outputs.cache-hit != 'true' uses: docker/setup-buildx-action@v3 - name: Build picolibc container if: steps.cache.outputs.cache-hit != 'true' uses: docker/build-push-action@v6 with: platforms: linux/amd64 file: .github/Dockerfile-check-format tags: ${{ env.IMAGE }}:latest outputs: type=docker,force-compression=true,compression=zstd,compression-level=22,dest=${{ env.IMAGE_FILE }} check-format: needs: cache-maker runs-on: ubuntu-latest steps: - name: Clone picolibc uses: actions/checkout@v6 with: path: picolibc - name: Restore the Docker Image uses: actions/cache@v5 with: path: ${{ env.IMAGE_FILE }} key: ${{ env.IMAGE_FILE }}-${{ hashFiles( env.DOCKERFILE, env.PACKAGES_FILE, env.EXTRA_FILE ) }} fail-on-cache-miss: true - name: Load and Check the Docker Image run: | docker load -i $IMAGE_FILE docker images -a $IMAGE - name: Check Formatting run: | docker run -v $(readlink -f picolibc):/picolibc -w /picolibc $IMAGE bash --login -c "./.github/do-check-format" picolibc-1.8.11/.github/workflows/head000066400000000000000000000027651513574234600176330ustar00rootroot00000000000000name: Linux on: push: branches: - main pull_request: branches: - main workflow_dispatch: # When a PR is updated, cancel the jobs from the previous version. Merges # do not define head_ref, so use run_id to never cancel those jobs. concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true env: DOCKERFILE: picolibc/.github/Dockerfile IMAGE_FILE: dockerimg-linux.tar.zst IMAGE: picolibc-linux PACKAGES_FILE: picolibc/.github/linux-packages.txt EXTRA_FILE: picolibc/.github/linux-files.txt jobs: cache-maker: runs-on: ubuntu-latest steps: - name: Clone picolibc uses: actions/checkout@v6 with: path: picolibc - name: Cache the Docker Image id: cache uses: actions/cache@v5 with: path: ${{ env.IMAGE_FILE }} key: ${{ env.IMAGE_FILE }}-${{ hashFiles( env.DOCKERFILE, env.PACKAGES_FILE, env.EXTRA_FILE ) }} lookup-only: true - name: Set up Docker Buildx if: steps.cache.outputs.cache-hit != 'true' uses: docker/setup-buildx-action@v3 - name: Build picolibc container if: steps.cache.outputs.cache-hit != 'true' uses: docker/build-push-action@v6 with: platforms: linux/amd64 file: .github/Dockerfile tags: ${{ env.IMAGE }}:latest outputs: type=docker,force-compression=true,compression=zstd,compression-level=22,dest=${{ env.IMAGE_FILE }} picolibc-1.8.11/.github/workflows/head-coreboot000066400000000000000000000031271513574234600214360ustar00rootroot00000000000000name: Coreboot on: push: branches: - main pull_request: branches: - main # When a PR is updated, cancel the jobs from the previous version. Merges # do not define head_ref, so use run_id to never cancel those jobs. concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true env: # .github/do-coreboot --buildtype release # is the largest cache, 429.5M (September 2023). DOCKERFILE: picolibc/.github/Dockerfile-coreboot IMAGE_FILE: dockerimg-coreboot.tar.zst IMAGE: picolibc PACKAGES_FILE: picolibc/.github/coreboot-packages.txt EXTRA_FILE: picolibc/.github/coreboot-files.txt jobs: cache-maker: runs-on: ubuntu-latest steps: - name: Clone picolibc uses: actions/checkout@v6 with: path: picolibc - name: Cache the Docker Image id: cache uses: actions/cache@v5 with: path: ${{ env.IMAGE_FILE }} key: ${{ env.IMAGE_FILE }}-${{ hashFiles( env.DOCKERFILE, env.PACKAGES_FILE, env.EXTRA_FILE ) }} lookup-only: true - name: Set up Docker Buildx if: steps.cache.outputs.cache-hit != 'true' uses: docker/setup-buildx-action@v3 - name: Build picolibc container if: steps.cache.outputs.cache-hit != 'true' uses: docker/build-push-action@v6 with: platforms: linux/amd64 file: .github/Dockerfile-coreboot tags: ${{ env.IMAGE }}:latest outputs: type=docker,force-compression=true,compression=zstd,compression-level=22,dest=${{ env.IMAGE_FILE }} picolibc-1.8.11/.github/workflows/head-native000066400000000000000000000027661513574234600211200ustar00rootroot00000000000000name: Native on: push: branches: - main pull_request: branches: - main workflow_dispatch: # When a PR is updated, cancel the jobs from the previous version. Merges # do not define head_ref, so use run_id to never cancel those jobs. concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true env: DOCKERFILE: picolibc/.github/Dockerfile IMAGE_FILE: dockerimg-linux.tar.zst IMAGE: picolibc-linux PACKAGES_FILE: picolibc/.github/linux-packages.txt EXTRA_FILE: picolibc/.github/linux-files.txt jobs: cache-maker: runs-on: ubuntu-latest steps: - name: Clone picolibc uses: actions/checkout@v6 with: path: picolibc - name: Cache the Docker Image id: cache uses: actions/cache@v5 with: path: ${{ env.IMAGE_FILE }} key: ${{ env.IMAGE_FILE }}-${{ hashFiles( env.DOCKERFILE, env.PACKAGES_FILE, env.EXTRA_FILE ) }} lookup-only: true - name: Set up Docker Buildx if: steps.cache.outputs.cache-hit != 'true' uses: docker/setup-buildx-action@v3 - name: Build picolibc container if: steps.cache.outputs.cache-hit != 'true' uses: docker/build-push-action@v6 with: platforms: linux/amd64 file: .github/Dockerfile tags: ${{ env.IMAGE }}:latest outputs: type=docker,force-compression=true,compression=zstd,compression-level=22,dest=${{ env.IMAGE_FILE }} picolibc-1.8.11/.github/workflows/head-zephyr000066400000000000000000000030011513574234600211320ustar00rootroot00000000000000name: Zephyr on: push: branches: - main pull_request: branches: - main workflow_dispatch: # When a PR is updated, cancel the jobs from the previous version. Merges # do not define head_ref, so use run_id to never cancel those jobs. concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true env: DOCKERFILE: picolibc/.github/Dockerfile-zephyr IMAGE_FILE: dockerimg-zephyr.tar.zst IMAGE: picolibc PACKAGES_FILE: picolibc/.github/zephyr-packages.txt EXTRA_FILE: picolibc/.github/zephyr-files.txt jobs: cache-maker: runs-on: ubuntu-latest steps: - name: Clone picolibc uses: actions/checkout@v6 with: path: picolibc - name: Cache the Docker Image id: cache uses: actions/cache@v5 with: path: ${{ env.IMAGE_FILE }} key: ${{ env.IMAGE_FILE }}-${{ hashFiles( env.DOCKERFILE, env.PACKAGES_FILE, env.EXTRA_FILE ) }} lookup-only: true - name: Set up Docker Buildx if: steps.cache.outputs.cache-hit != 'true' uses: docker/setup-buildx-action@v3 - name: Build picolibc container if: steps.cache.outputs.cache-hit != 'true' uses: docker/build-push-action@v6 with: platforms: linux/amd64 file: .github/Dockerfile-zephyr tags: ${{ env.IMAGE }}:latest outputs: type=docker,force-compression=true,compression=zstd,compression-level=22,dest=${{ env.IMAGE_FILE }} picolibc-1.8.11/.github/workflows/linux.yml000066400000000000000000000265561513574234600206750ustar00rootroot00000000000000name: Linux on: push: branches: - main pull_request: branches: - main workflow_dispatch: # When a PR is updated, cancel the jobs from the previous version. Merges # do not define head_ref, so use run_id to never cancel those jobs. concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true env: DOCKERFILE: picolibc/.github/Dockerfile IMAGE_FILE: dockerimg-linux.tar.zst IMAGE: picolibc-linux PACKAGES_FILE: picolibc/.github/linux-packages.txt EXTRA_FILE: picolibc/.github/linux-files.txt jobs: cache-maker: runs-on: ubuntu-latest steps: - name: Clone picolibc uses: actions/checkout@v6 with: path: picolibc - name: Cache the Docker Image id: cache uses: actions/cache@v5 with: path: ${{ env.IMAGE_FILE }} key: ${{ env.IMAGE_FILE }}-${{ hashFiles( env.DOCKERFILE, env.PACKAGES_FILE, env.EXTRA_FILE ) }} lookup-only: true - name: Set up Docker Buildx if: steps.cache.outputs.cache-hit != 'true' uses: docker/setup-buildx-action@v3 - name: Build picolibc container if: steps.cache.outputs.cache-hit != 'true' uses: docker/build-push-action@v6 with: platforms: linux/amd64 file: .github/Dockerfile tags: ${{ env.IMAGE }}:latest outputs: type=docker,force-compression=true,compression=zstd,compression-level=22,dest=${{ env.IMAGE_FILE }} cmake-linux: needs: cache-maker runs-on: ubuntu-latest strategy: matrix: cmake_flags: [ "", # optional configurations "-D__IO_FLOAT=y -D__IO_FLOAT_EXACT=n -D__IO_LONG_LONG=y -D_MB_CAPABLE=y -D_MB_EXTENDED_CHARSETS_ALL=y -D__IO_POS_ARGS=y -D_WANT_MINIMAL_IO_LONG_LONG=y -D_PRINTF_PERCENT_N=y", ] test: [ "./.github/do-cmake-linux -DCMAKE_BUILD_TYPE=RelWithDebInfo", "./.github/do-cmake-linux -DCMAKE_BUILD_TYPE=MinSizeRel", ] steps: - name: Clone picolibc uses: actions/checkout@v6 with: path: picolibc - name: Restore the Docker Image uses: actions/cache@v5 with: path: ${{ env.IMAGE_FILE }} key: ${{ env.IMAGE_FILE }}-${{ hashFiles( env.DOCKERFILE, env.PACKAGES_FILE, env.EXTRA_FILE ) }} fail-on-cache-miss: true - name: Load and Check the Docker Image run: | docker load -i $IMAGE_FILE docker images -a $IMAGE - name: CMake test run: | docker run -v $(readlink -f picolibc):/picolibc -w /picolibc $IMAGE ${{ matrix.test }} ${{ matrix.cmake_flags }} minsize-linux-arm: needs: cache-maker runs-on: ubuntu-latest strategy: matrix: meson_flags: [ "", # math configurations, one with multithread disabled and with locale, original malloc and atexit/onexit code "-Dio-float-exact=false -Dio-long-long=true -Dio-percent-b=true -Dio-long-double=true -Dnewlib-obsolete-math=false -Dwant-math-errno=true -Dsingle-thread=true -Dmb-capable=true -Dmb-extended-charsets=true -Dprintf-small-ultoa=true -Dprintf-percent-n=true", "-Dformat-default=integer -Dfreestanding=true -Dnewlib-obsolete-math=true -Dwant-math-errno=true -Dassert-verbose=false -Dfast-bufio=true -Dstdio-locking=true -Dfstat-bufsiz=true", ] test: [ "./.github/do-linux-arm", ] steps: - name: Clone picolibc uses: actions/checkout@v6 with: path: picolibc - name: Restore the Docker Image uses: actions/cache@v5 with: path: ${{ env.IMAGE_FILE }} key: ${{ env.IMAGE_FILE }}-${{ hashFiles( env.DOCKERFILE, env.PACKAGES_FILE, env.EXTRA_FILE ) }} fail-on-cache-miss: true - name: Load and Check the Docker Image run: | docker load -i $IMAGE_FILE docker images -a $IMAGE - name: Minsize test run: | docker run -v $(readlink -f picolibc):/picolibc -w /picolibc $IMAGE ${{ matrix.test }} ${{ matrix.meson_flags }} --buildtype minsize minsize-linux-riscv: needs: cache-maker runs-on: ubuntu-latest strategy: matrix: meson_flags: [ "", # math configurations, one with multithread disabled and with locale, original malloc and atexit/onexit code "-Dio-float-exact=false -Dio-long-long=true -Dio-percent-b=true -Dio-long-double=true -Dnewlib-obsolete-math=false -Dwant-math-errno=true -Dsingle-thread=true -Dmb-capable=true -Dmb-extended-charsets=true -Dprintf-small-ultoa=true -Dprintf-percent-n=true", "-Dformat-default=integer -Dfreestanding=true -Dnewlib-obsolete-math=true -Dwant-math-errno=true -Dassert-verbose=false -Dfast-bufio=true -Dstdio-locking=true -Dfstat-bufsiz=true", ] test: [ "./.github/do-linux-riscv", ] steps: - name: Clone picolibc uses: actions/checkout@v6 with: path: picolibc - name: Restore the Docker Image uses: actions/cache@v5 with: path: ${{ env.IMAGE_FILE }} key: ${{ env.IMAGE_FILE }}-${{ hashFiles( env.DOCKERFILE, env.PACKAGES_FILE, env.EXTRA_FILE ) }} fail-on-cache-miss: true - name: Load and Check the Docker Image run: | docker load -i $IMAGE_FILE docker images -a $IMAGE - name: Minsize test run: | docker run -v $(readlink -f picolibc):/picolibc -w /picolibc $IMAGE ${{ matrix.test }} ${{ matrix.meson_flags }} --buildtype minsize minsize-linux-misc: needs: cache-maker runs-on: ubuntu-latest strategy: matrix: meson_flags: [ "", # math configurations, one with multithread disabled and with locale, original malloc and atexit/onexit code "-Dio-float-exact=false -Dio-long-long=true -Dio-percent-b=true -Dio-long-double=true -Dnewlib-obsolete-math=false -Dwant-math-errno=true -Dsingle-thread=true -Dmb-capable=true -Dmb-extended-charsets=true -Dprintf-small-ultoa=true -Dprintf-percent-n=true", "-Dformat-default=integer -Dfreestanding=true -Dnewlib-obsolete-math=true -Dwant-math-errno=true -Dassert-verbose=false -Dfast-bufio=true -Dstdio-locking=true -Dfstat-bufsiz=true", ] test: [ "./.github/do-linux-misc", ] steps: - name: Clone picolibc uses: actions/checkout@v6 with: path: picolibc - name: Restore the Docker Image uses: actions/cache@v5 with: path: ${{ env.IMAGE_FILE }} key: ${{ env.IMAGE_FILE }}-${{ hashFiles( env.DOCKERFILE, env.PACKAGES_FILE, env.EXTRA_FILE ) }} fail-on-cache-miss: true - name: Load and Check the Docker Image run: | docker load -i $IMAGE_FILE docker images -a $IMAGE - name: Minsize test run: | docker run -v $(readlink -f picolibc):/picolibc -w /picolibc $IMAGE ${{ matrix.test }} ${{ matrix.meson_flags }} --buildtype minsize release-linux-arm: needs: cache-maker runs-on: ubuntu-latest strategy: matrix: meson_flags: [ "", # math configurations, one with multithread disabled and with locale, original malloc and atexit/onexit code "-Dio-float-exact=false -Dio-long-long=true -Dio-percent-b=true -Dio-long-double=true -Dnewlib-obsolete-math=false -Dwant-math-errno=true -Dsingle-thread=true -Dmb-capable=true -Dmb-extended-charsets=true -Dprintf-small-ultoa=true -Dprintf-percent-n=true", "-Dformat-default=integer -Dfreestanding=true -Dnewlib-obsolete-math=true -Dwant-math-errno=true -Dassert-verbose=false -Dfast-bufio=true -Dstdio-locking=true -Dfstat-bufsiz=true", ] test: [ "./.github/do-linux-arm", ] steps: - name: Clone picolibc uses: actions/checkout@v6 with: path: picolibc - name: Restore the Docker Image uses: actions/cache@v5 with: path: ${{ env.IMAGE_FILE }} key: ${{ env.IMAGE_FILE }}-${{ hashFiles( env.DOCKERFILE, env.PACKAGES_FILE, env.EXTRA_FILE ) }} fail-on-cache-miss: true - name: Load and Check the Docker Image run: | docker load -i $IMAGE_FILE docker images -a $IMAGE - name: Release test run: | docker run -v $(readlink -f picolibc):/picolibc -w /picolibc $IMAGE ${{ matrix.test }} ${{ matrix.meson_flags }} --buildtype release release-linux-riscv: needs: cache-maker runs-on: ubuntu-latest strategy: matrix: meson_flags: [ "", # math configurations, one with multithread disabled and with locale, original malloc and atexit/onexit code "-Dio-float-exact=false -Dio-long-long=true -Dio-percent-b=true -Dio-long-double=true -Dnewlib-obsolete-math=false -Dwant-math-errno=true -Dsingle-thread=true -Dmb-capable=true -Dmb-extended-charsets=true -Dprintf-small-ultoa=true -Dprintf-percent-n=true", "-Dformat-default=integer -Dfreestanding=true -Dnewlib-obsolete-math=true -Dwant-math-errno=true -Dassert-verbose=false -Dfast-bufio=true -Dstdio-locking=true -Dfstat-bufsiz=true", ] test: [ "./.github/do-linux-riscv", ] steps: - name: Clone picolibc uses: actions/checkout@v6 with: path: picolibc - name: Restore the Docker Image uses: actions/cache@v5 with: path: ${{ env.IMAGE_FILE }} key: ${{ env.IMAGE_FILE }}-${{ hashFiles( env.DOCKERFILE, env.PACKAGES_FILE, env.EXTRA_FILE ) }} fail-on-cache-miss: true - name: Load and Check the Docker Image run: | docker load -i $IMAGE_FILE docker images -a $IMAGE - name: Release test run: | docker run -v $(readlink -f picolibc):/picolibc -w /picolibc $IMAGE ${{ matrix.test }} ${{ matrix.meson_flags }} --buildtype release release-linux-misc: needs: cache-maker runs-on: ubuntu-latest strategy: matrix: meson_flags: [ "", # math configurations, one with multithread disabled and with locale, original malloc and atexit/onexit code "-Dio-float-exact=false -Dio-long-long=true -Dio-percent-b=true -Dio-long-double=true -Dnewlib-obsolete-math=false -Dwant-math-errno=true -Dsingle-thread=true -Dmb-capable=true -Dmb-extended-charsets=true -Dprintf-small-ultoa=true -Dprintf-percent-n=true", "-Dformat-default=integer -Dfreestanding=true -Dnewlib-obsolete-math=true -Dwant-math-errno=true -Dassert-verbose=false -Dfast-bufio=true -Dstdio-locking=true -Dfstat-bufsiz=true", ] test: [ "./.github/do-linux-misc", ] steps: - name: Clone picolibc uses: actions/checkout@v6 with: path: picolibc - name: Restore the Docker Image uses: actions/cache@v5 with: path: ${{ env.IMAGE_FILE }} key: ${{ env.IMAGE_FILE }}-${{ hashFiles( env.DOCKERFILE, env.PACKAGES_FILE, env.EXTRA_FILE ) }} fail-on-cache-miss: true - name: Load and Check the Docker Image run: | docker load -i $IMAGE_FILE docker images -a $IMAGE - name: Release test run: | docker run -v $(readlink -f picolibc):/picolibc -w /picolibc $IMAGE ${{ matrix.test }} ${{ matrix.meson_flags }} --buildtype release picolibc-1.8.11/.github/workflows/make-workflow000077500000000000000000000011361513574234600215110ustar00rootroot00000000000000#!/bin/bash cat head for build in cmake; do for arch in linux; do echo " $build-$arch:" cat variants-$build cat <&2 exit 1 ;; esac export ZEPHYR_SDK_INSTALL_DIR=$sdk for hosttools in . zephyr-sdk-hosttools fail; do if [ -f $sdk/$hosttools/environment-setup-* ]; then break fi done case $hosttools in fail) echo 'No Zephyr host tools found' 1>&2 exit 1 ;; esac . $ZEPHYR_SDK_INSTALL_DIR/$hosttools/environment-setup-* for dir in "$ZEPHYR_SDK_INSTALL_DIR"/* "$ZEPHYR_SDK_INSTALL_DIR"/qemu*; do if [ -d "$dir" -a -d "$dir"/bin ]; then PATH="$dir"/bin:$PATH fi done exec "$@" picolibc-1.8.11/.github/zephyr-files.txt000066400000000000000000000045531513574234600201310ustar00rootroot00000000000000https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/toolchain_linux-x86_64_aarch64-zephyr-elf.tar.xz https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/toolchain_linux-x86_64_arc-zephyr-elf.tar.xz https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/toolchain_linux-x86_64_arc64-zephyr-elf.tar.xz https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/toolchain_linux-x86_64_microblazeel-zephyr-elf.tar.xz https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/toolchain_linux-x86_64_mips-zephyr-elf.tar.xz https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/toolchain_linux-x86_64_nios2-zephyr-elf.tar.xz https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/toolchain_linux-x86_64_sparc-zephyr-elf.tar.xz https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/toolchain_linux-x86_64_x86_64-zephyr-elf.tar.xz https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/toolchain_linux-x86_64_xtensa-dc233c_zephyr-elf.tar.xz https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/toolchain_linux-x86_64_xtensa-espressif_esp32s2_zephyr-elf.tar.xz https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/toolchain_linux-x86_64_xtensa-espressif_esp32_zephyr-elf.tar.xz https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/toolchain_linux-x86_64_xtensa-intel_ace15_mtpm_zephyr-elf.tar.xz https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/toolchain_linux-x86_64_xtensa-intel_tgl_adsp_zephyr-elf.tar.xz https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/toolchain_linux-x86_64_xtensa-nxp_imx8m_adsp_zephyr-elf.tar.xz https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/toolchain_linux-x86_64_xtensa-nxp_imx_adsp_zephyr-elf.tar.xz https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/toolchain_linux-x86_64_xtensa-sample_controller_zephyr-elf.tar.xz https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/hosttools_linux-x86_64.tar.xz https://github.com/picolibc/picolibc-ci-tools/releases/download/v7/qemu-9.0.linux-amd64.tar.xz https://github.com/picolibc/picolibc-ci-tools/releases/download/v7/qemu-arc.linux-amd64.tar.xz https://github.com/picolibc/picolibc-ci-tools/releases/download/v7/qemu-stable.linux-amd64.tar.xz picolibc-1.8.11/.github/zephyr-packages.txt000066400000000000000000000002521513574234600205750ustar00rootroot00000000000000build-essential cmake file libgtk-3-0 libjack0 libpulse0 libsndio7.0 librados2 librbd1 libvte-2.91-0 meson ninja-build qemu-system-x86 ca-certificates wget gnupg locales picolibc-1.8.11/.github/zephyr-setup000077500000000000000000000000561513574234600173460ustar00rootroot00000000000000#!/bin/sh sh ./zephyr-sdk-*hosttools* -y -d . picolibc-1.8.11/.gitignore000066400000000000000000000005531513574234600153730ustar00rootroot00000000000000*.diff *.patch *.orig *.rej *~ .#* *# *.flt *.gmo *.info *.la *.lo *.o *.pyc *.swp *.tmp .deps .libs autom4te.cache config.cache config.intl config.log config.status libtool POTFILES *-POTFILES tags TAGS TAGS.sub .gdbinit .gdb_history # ignore core files, but not java/net/protocol/core/ core !core/ lost+found # ignore meson build directories build-*/ picolibc-1.8.11/CMakeLists.txt000066400000000000000000000254061513574234600161470ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # cmake_minimum_required(VERSION 3.20.0) project(Picolibc VERSION 1.8.11 LANGUAGES C ASM) # Set a default build type if none was specified set(default_build_type "MinSizeRel") if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES AND NOT DEFINED ZEPHYR_BASE) message(STATUS "Setting build type to '${default_build_type}' as none was specified.") set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE) endif() if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64") set(CMAKE_SYSTEM_PROCESSOR "aarch64") endif() set(CMAKE_SYSTEM_SUB_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}) if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") set(CMAKE_SYSTEM_PROCESSOR "x86") endif() if(ZEPHYR_BASE) if(NOT CONFIG_PICOLIBC_USE_MODULE) return() endif() include(zephyr/zephyr.cmake) endif() include(cmake/picolibc.cmake) enable_testing() set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) # Set all configure values to defaults for now # Use atomics for fgetc/ungetc for re-entrancy set(__ATOMIC_UNGETC 1) # Always optimize strcmp for performance if(NOT DEFINED __FAST_STRCMP) option(__FAST_STRCMP "Always optimize strcmp for performance" ON) endif() # use global errno variable if(NOT DEFINED __GLOBAL_ERRNO) option(__GLOBAL_ERRNO "use global errno variable" OFF) endif() # use thread local storage if(NOT DEFINED __THREAD_LOCAL_STORAGE) option(__THREAD_LOCAL_STORAGE "use thread local storage for static data" ON) endif() # use thread local storage for stack protection canary if(NOT DEFINED __THREAD_LOCAL_STORAGE_STACK_GUARD) option(__THREAD_LOCAL_STORAGE_STACK_GUARD "use thread local storage for stack protection canary" OFF) endif() # enable malloc code if(NOT DEFINED ENABLE_MALLOC) option(ENABLE_MALLOC "provide malloc family of functions based on sbrk" ON) endif() option(POSIX_CONSOLE "Use POSIX I/O for stdin/stdout/stderr" OFF) # Optimize for space over speed if(NOT DEFINED __PREFER_SIZE_OVER_SPEED) if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel") set(default_prefer_size ON) else() set(default_prefer_size OFF) endif() option(__PREFER_SIZE_OVER_SPEED "Prefer smaller code size" ${default_prefer_size}) endif() set(__TINY_STDIO 1) if(NOT TLS_MODEL) set(TLS_MODEL "local-exec") endif() set(_ATEXIT_DYNAMIC_ALLOC 0) set(__FSEEK_OPTIMIZATION 0) set(__FVWRITE_IN_STREAMIO 0) # Use bitfields in packed structs picolibc_flag(__HAVE_BITFIELDS_IN_PACKED_STRUCTS) # Compiler has support for flag to prevent mis-optimizing memcpy/memset patterns picolibc_flag(__HAVE_CC_INHIBIT_LOOP_TO_LIBCALL) # Compiler supports _Complex picolibc_flag(__HAVE_COMPLEX) set(__HAVE_FCNTL 0) # IEEE fp funcs available set(__IEEEFP_FUNCS 0) # compiler supports INIT_ARRAY sections set(__INIT_FINI_ARRAY 1) # Support _init() and _fini() functions set(__INIT_FINI_FUNCS 0) # Enable MMU in pico crt startup set(__PICOCRT_ENABLE_MMU 1) # _set_tls and _init_tls functions available if(NOT DEFINED __THREAD_LOCAL_STORAGE_API OR NOT __THREAD_LOCAL_STORAGE) set(__THREAD_LOCAL_STORAGE_API 0) endif() set(__SEMIHOST 1) # math library does not set errno (offering only ieee semantics) set(__IEEE_LIBM 1) if(NOT DEFINED __IO_FLOAT_EXACT) option(__IO_FLOAT_EXACT "Provide exact binary/decimal conversion for printf/scanf" ON) endif() if(NOT DEFINED __ASSERT_VERBOSE) option(__ASSERT_VERBOSE "Assert provides verbose information" ON) endif() if(NOT DEFINED __MB_CAPABLE) option(__MB_CAPABLE "Enable multi-byte support" OFF) endif() if(NOT DEFINED __MB_EXTENDED_CHARSETS_ALL) option(__MB_EXTENDED_CHARSETS_ALL "Enable UCS, ISO, Windows and JIS multibyte encodings" OFF) endif() if(NOT DEFINED __MB_EXTENDED_CHARSETS_UCS) option(__MB_EXTENDED_CHARSETS_UCS "Enable UCS encodings" OFF) endif() if(NOT DEFINED __MB_EXTENDED_CHARSETS_ISO) option(__MB_EXTENDED_CHARSETS_ISO "Enable ISO encodings" OFF) endif() if(NOT DEFINED __MB_EXTENDED_CHARSETS_WINDOWS) option(__MB_EXTENDED_CHARSETS_WINDOWS "Enable Windows encodings" OFF) endif() if(NOT DEFINED __MB_EXTENDED_CHARSETS_JIS) option(__MB_EXTENDED_CHARSETS_JIS "Enable JIS multibyte encodings" OFF) endif() set(__NANO_FORMATTED_IO OFF) option(__NANO_MALLOC "Use smaller malloc implementation" ON) set(_GLOBAL_ATEXIT OFF) set(__UNBUF_STREAM_OPT OFF) if(NOT DEFINED __IO_C99_FORMATS) option(__IO_C99_FORMATS "Support C99 formats in printf/scanf" ON) endif() if(NOT DEFINED __IO_LONG_LONG) option(__IO_LONG_LONG "Support long long in integer printf/scanf" OFF) endif() if(NOT DEFINED __IO_LONG_DOUBLE) option(__IO_LONG_DOUBLE "Support long double in printf/scanf" OFF) endif() if(NOT DEFINED __IO_MINIMAL_LONG_LONG) option(__IO_MINIMAL_LONG_LONG "Support long long in minimal printf/scanf" OFF) endif() if(NOT DEFINED __IO_POS_ARGS) option(__IO_POS_ARGS "Support positional args in integer printf/scanf" OFF) endif() option(__IO_FLOAT "Support floating point in printf/scanf by default" ON) if(NOT DEFINED __IO_SMALL_ULTOA) option(__IO_SMALL_ULTOA "Avoid soft divide in printf" ON) endif() if(NOT DEFINED __IO_PERCENT_N) option(__IO_PERCENT_N "Support %n formats in printf" OFF) endif() if(NOT DEFINED __IO_PERCENT_B) option(__IO_PERCENT_B "Support %b/%B formats in printf/scanf" OFF) endif() if(NOT DEFINED __IO_WCHAR) option(__IO_WCHAR "Support %ls/%lc formats in printf even without multi-byte" OFF) endif() if(NOT DEFINED __IO_DEFAULT) set(__IO_DEFAULT d) endif() # math library sets errno set(__MATH_ERRNO OFF) set(_WANT_REGISTER_FINI OFF) set(__WIDE_ORIENT OFF) if(NOT DEFINED __ELIX_LEVEL) set(__ELIX_LEVEL 4) endif() # Use old math code for double funcs (0 no, 1 yes) set(__OBSOLETE_MATH_FLOAT ON) # Use old math code for double funcs (0 no, 1 yes) set(__OBSOLETE_MATH_DOUBLE ON) # Compute static memory area sizes at runtime instead of link time set(__PICOCRT_RUNTIME_SIZE OFF) if(NOT DEFINED __SINGLE_THREAD) option(__SINGLE_THREAD "Disable multithreading support" OFF) endif() set(NEWLIB_VERSION 4.3.0) set(NEWLIB_MAJOR 4) set(NEWLIB_MINOR 3) set(NEWLIB_PATCH 0) set(PICOLIBC_INCLUDE ${PROJECT_BINARY_DIR}/picolibc/include) set(PICOLIBC_SCRIPTS "${CMAKE_CURRENT_SOURCE_DIR}/scripts") include(CheckIncludeFile) set(CMAKE_REQUIRED_QUIET TRUE) CHECK_INCLUDE_FILE(xtensa/config/core-isa.h _XTENSA_HAVE_CONFIG_CORE_ISA_H) configure_file(picolibc.h.in "${PICOLIBC_INCLUDE}/picolibc.h") set(INCLUDEDIR include) set(LIBDIR .) if(__THREAD_LOCAL_STORAGE) set(TLSMODEL "-ftls-model=${TLS_MODEL}") endif() set(LINK_SPEC "") set(CC1_SPEC "") set(CC1PLUS_SPEC "") set(ADDITIONAL_LIBS "") set(SPECS_EXTRA "") set(SPECS_ISYSTEM "-isystem ${PROJECT_BINARY_DIR}/${include}") set(SPECS_LIBPATH "-L${PROJECT_BINARY_DIR}") set(SPECS_STARTFILE "${PROJECT_BINARY_DIR}/crt0.o") string(APPEND SPECS_PRINTF "%{DPICOLIBC_FLOAT_PRINTF_SCANF:--defsym=vfprintf=__f_vfprintf}" " %{DPICOLIBC_FLOAT_PRINTF_SCANF:--defsym=vfscanf=__f_vfscanf}" " %{DPICOLIBC_DOUBLE_PRINTF_SCANF:--defsym=vfprintf=__d_vfprintf}" " %{DPICOLIBC_DOUBLE_PRINTF_SCANF:--defsym=vfscanf=__d_vfscanf}" " %{DPICOLIBC_INTEGER_PRINTF_SCANF:--defsym=vfprintf=__i_vfprintf}" " %{DPICOLIBC_INTEGER_PRINTF_SCANF:--defsym=vfscanf=__i_vfscanff}" " %{DPICOLIBC_MINIMAL_PRINTF_SCANF:--defsym=vfprintf=__m_vfprintf}" " %{DPICOLIBC_MINIMAL_PRINTF_SCANF:--defsym=vfscanf=__i_vfscanff}" ) set(PREFIX "${PROJECT_BINARY_DIR}") configure_file(picolibc.specs.in "${PROJECT_BINARY_DIR}/picolibc.specs" @ONLY) set(PICOLIBC_COMPILE_OPTIONS "-nostdlib" "-D_LIBC" ${TLSMODEL} ${TARGET_COMPILE_OPTIONS} ${PICOLIBC_EXTRA_COMPILE_OPTIONS} ${PICOLIBC_MATH_FLAGS} ) # Strip out any generator expressions as those cannot be used with # try_compile foreach(c_option "${PICOLIBC_COMPILE_OPTIONS}") if(NOT "${c_option}" MATCHES "\\$") list(APPEND PICOLIBC_TEST_COMPILE_OPTIONS "${c_option}") endif() endforeach() picolibc_supported_compile_options( "-fno-common" "-fno-stack-protector" "-ffunction-sections" "-fdata-sections" "-Wall" "-Wextra" "-Werror=implicit-function-declaration" "-Werror=vla" "-Warray-bounds" "-Wold-style-definition" "-frounding-math" "-fsignaling-nans" ) add_library(c STATIC) target_compile_options(c PRIVATE ${PICOLIBC_COMPILE_OPTIONS}) set(PICOLIBC_INCLUDE_DIRECTORIES "${PICOLIBC_INCLUDE}") target_include_directories(c SYSTEM PUBLIC ${PICOLIBC_INCLUDE_DIRECTORIES}) define_property(GLOBAL PROPERTY PICOLIBC_HEADERS BRIEF_DOCS "Installed header files" FULL_DOCS "These are names of header files which are to be installed.") add_subdirectory(libc) add_subdirectory(libm) install(TARGETS c LIBRARY DESTINATION lib PUBLIC_HEADER DESTINATION include) option(TESTS "Enable tests" OFF) if(TESTS) # This could use some generalization, but it's good enough to do # semihosting-based tests add_subdirectory(semihost) add_subdirectory(picocrt) set(PICOCRT_OBJ $) set(PICOCRT_SEMIHOST_OBJ $) # semihost and libc have mutual-dependencies, so place them in a # linker group set(PICOLIBC_TEST_LINK_LIBRARIES ${PICOCRT_SEMIHOST_OBJ} -Wl,--start-group c semihost -Wl,--end-group ${PICOLIBC_LINK_FLAGS} ) add_subdirectory(test) endif() install(FILES ${CMAKE_BINARY_DIR}/picolibc.specs DESTINATION lib) install(FILES ${CMAKE_BINARY_DIR}/picolibc/include/picolibc.h DESTINATION include) picolibc-1.8.11/CODE_OF_CONDUCT.md000066400000000000000000000064521513574234600162060ustar00rootroot00000000000000# Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies within all project spaces, and it also applies when an individual is representing the project or its community in public spaces. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at conduct@keithp.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html [homepage]: https://www.contributor-covenant.org For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq picolibc-1.8.11/CONTRIBUTING.md000066400000000000000000000064031513574234600156340ustar00rootroot00000000000000# Contributing to Picolibc We welcome contributions of all forms, including patches to code and documentation, issue reports, or just kind words. ## Getting Current Source Code Picolibc sources are maintained in git and hosted in two places. 1. [keithp.com](https://keithp.com/cgit/picolibc.git/). This is the 'canonical' source location. 2. [github](https://github.com/keith-packard/picolibc). This should exactly mirror the code at keithp.com. I've placed it here to make contributing to Picolibc easier for people familiar with github. You can create a local copy of the repository with git clone: $ git clone git://keithp.com/git/picolibc.git or $ git clone https://github.com/keith-packard/picolibc.git ## Meson Picolibc uses the [meson](https://mesonbuild.com/) build tool. You'll need to make sure that's installed before you start trying to build the software. ## Building Picolibc from Source As Picolibc is designed to be used for embedded systems, getting that configured correctly can be a challenge. Learn more about that in the [build](doc/build.md) page. ## Formatting Source Code Picolibc code comes from a multitude of sources using an enormous range of styles. As picolibc tries to retain compatibility with newlib so that bug fixes can be shared between projects, we can't easily reformat all of the existing code. Here are suggestions on how to preserve compatibility while still being able to write readable code: 1. Whitespace-only changes are not helpful, please don't submit changes that are only fixing formatting. 2. Try to adopt local coding styles as much as you can manage by matching code within the same files. 3. For brand-new files, please use the global .editorconfig settings if possible: * no literal tab characters, only spaces * 4-space indentation for nested elements * no trailing whitespace * utf-8 encoding ## Patch Submission You can submit patches in a couple of ways: 1. Mail to the picolibc list (see below). This can be tricky as it requires a friendly email system, and you'll have to subscribe to the mailing list before it will let you post anything (sigh). Here's a simple example sending the latest patch in your local repository to the list: $ git send-email --to picolibc@keithp.com HEAD^ 2. Generate a pull-request in github. 1. Fork the picolibc project into your own github account 2. Push patches to that repository 3. While viewing your repository, click on the 'New pull request' button and follow the instructions there. ## Issue Tracking We're using the issue tracker on Github for now; if you have issues, please submit them to the [Picolibc Issue Tracker](https://github.com/keith-packard/picolibc/issues) ## Mailing List Picolibc has a mailing list, hosted at keithp.com. You can [subscribe here](https://keithp.com/mailman/listinfo/picolibc). This is a public list, with public archives. Participants are expected to abide by the [Picolibc Code of Conduct](CODE_OF_CONDUCT.md). ## Code of Conduct Picolibc uses the [Contributor Covenant](https://www.contributor-covenant.org/), which you'll find in the source tree as [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md). Please help make picolibc a kind and welcoming environment by following those rules. picolibc-1.8.11/COPYING.picolibc000066400000000000000000006425271513574234600162360ustar00rootroot00000000000000Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: picolibc Upsream-Contact: Keith Packard Source: https://keithp.com/git/picolibc Copyright: 2019 Keith Packard License: BSD3-1 Files: * Copyright: 2020 The Newlib Project License: Default-1 Files: debian/* Copyright: 2019-2022 Keith Packard License: BSD3-1 Files: *.md Copyright: 2019 Keith Packard License: BSD3-1 Files: scripts/GeneratePicolibcCrossFile.sh Copyright: 2022 R. Diez - Licensed under the GNU AGPLv3 License: AGPL3-1 Files: libc/include/devctl.h Copyright: 2016,2019 Joel Sherrill . License: BSD2-1 Files: libc/include/iconv.h Copyright: 2003-2004, Artem B. Bityuckiy, SoftMine Corporation. Rights transferred to Franklin Electronic Publishers. License: BSD2-1 Files: libc/include/langinfo.h libc/include/wchar.h Copyright: 2001 Alexey Zelkin License: BSD2-1 Files: libc/include/machine/fenv-softfloat.h Copyright: 2004-2011 David Schultz License: BSD2-1 Files: libc/include/spawn.h Copyright: 2008 Ed Schouten License: BSD2-1 Files: libc/include/strings.h libc/include/sys/_timeval.h Copyright: 2002 Mike Barcroft License: BSD2-1 Files: libc/include/sys/endian.h Copyright: 2002 Thomas Moestl License: BSD2-1 Files: libc/include/sys/iconvnls.h Copyright: 2003-2004, Artem B. Bityuckiy. Rights transferred to Franklin Electronic Publishers. License: BSD2-1 Files: libc/machine/aarch64/machine/_fpmath.h libc/machine/riscv/machine/_fpmath.h Copyright: 2002, 2003 David Schultz 2014 The FreeBSD Foundation License: BSD2-1 Files: libc/machine/aarch64/machine/fenv-fp.h libc/machine/aarch64/machine/fenv.h libc/machine/arm/machine/fenv.h libc/machine/mips/machine/fenv-fp.h libc/machine/mips/machine/fenv.h libc/machine/powerpc/machine/fenv-fp.h libc/machine/powerpc/machine/fenv.h libc/machine/sh/machine/fenv.h libc/machine/sparc/machine/fenv.h libm/ld/common/s_frexpl.c Copyright: 2004-2005 David Schultz License: BSD2-1 Files: libc/machine/lm32/setjmp.S Copyright: 2008 Jon Beniston License: BSD2-1 Files: libc/machine/loongarch/machine/_fpmath.h Copyright: 2002, 2003 David Schultz 2014 The FreeBSD Foundation 2024 Jiaxun Yang License: BSD2-1 Files: libc/machine/sh/machine/fenv-fp.h Copyright: 2004-2005 David Schultz 2013 Andrew Turner License: BSD2-1 Files: libc/machine/x86/machine/fenv.h Copyright: 2010-2019 Red Hat, Inc. License: BSD2-1 Files: libc/machine/x86_64/machine/_fpmath.h libm/ld/ld80/i386_fpmath.h Copyright: 2002, 2003 David Schultz License: BSD2-1 Files: libc/stdlib/arc4random.h Copyright: 2016 embedded brains GmbH License: BSD2-1 Files: libc/stdlib/imaxabs.c libc/stdlib/imaxdiv.c libc/stdlib/llabs.c libc/stdlib/lldiv.c Copyright: 2001 Mike Barcroft License: BSD2-1 Files: libc/stdlib/reallocf.c Copyright: 1998, M. Warner Losh License: BSD2-1 Files: libc/stdlib/rpmatch.c Copyright: 2004-2005 Tim J. Robbins. License: BSD2-1 Files: libc/string/ffsl.c libc/string/ffsll.c libc/string/fls.c libc/string/flsl.c libc/string/flsll.c libm/machine/arm/s_sqrt.c libm/machine/arm/sf_sqrt.c Copyright: 2017 embedded brains GmbH License: BSD2-1 Files: libc/string/wcscat.c libc/string/wcschr.c libc/string/wcscpy.c libc/string/wcscspn.c libc/string/wcslen.c libc/string/wcsncat.c libc/string/wcsncpy.c libc/string/wcspbrk.c libc/string/wcsrchr.c libc/string/wcsspn.c libc/string/wcsstr.c libc/string/wmemchr.c libc/string/wmemcmp.c libc/string/wmemcpy.c libc/string/wmemmove.c libc/string/wmemset.c Copyright: 1999 Citrus Project, License: BSD2-1 Files: libm/common/fma_inc.h Copyright: 2005-2011 David Schultz License: BSD2-1 Files: libm/complex/csqrtl.c Copyright: 2007-2008 David Schultz License: BSD2-1 Files: libm/ld/common/e_remainderl.c libm/ld/common/s_rintl.c libm/ld/ld128/invtrig.c libm/ld/ld128/invtrig.h libm/ld/ld80/invtrig.c libm/ld/ld80/invtrig.h Copyright: 2008 David Schultz License: BSD2-1 Files: libm/ld/common/s_fdiml.c libm/ld/common/s_finitel.c libm/ld/common/s_fmaxl.c libm/ld/common/s_fminl.c libm/ld/common/s_isinfl.c libm/ld/common/s_isnanl.c libm/ld/common/s_scalbl.c libm/ld/common/s_scalbln.c libm/ld/common/s_signbitl.c Copyright: 2004 David Schultz License: BSD2-1 Files: libm/ld/common/s_lrintl.c libm/ld/common/s_lround.c Copyright: 2005 David Schultz License: BSD2-1 Files: libm/ld/ld128/s_exp2l.c libm/ld/ld80/s_exp2l.c Copyright: 2005-2008 David Schultz License: BSD2-1 Files: test/test-stdio/test-fmemopen.c Copyright: 2010 Takehiko NOZAKI, License: BSD2-1 Files: test/testsuite/newlib.iconv/iconv.exp test/testsuite/newlib.iconv/iconvjp.c test/testsuite/newlib.iconv/iconvnm.c test/testsuite/newlib.iconv/iconvru.c Copyright: 2003, Artem B. Bityuckiy, SoftMine Corporation. Rights transferred to Franklin Electronic Publishers. License: BSD2-1 Files: libc/include/machine/fenv.h Copyright: 2019 Joel Sherrill License: BSD2-2 Files: libm/fenv/fe_dfl_env.c Copyright: 2019 Joel Sherrill License: BSD2-4 Files: libc/machine/pru/setjmp.s libm/machine/pru/fpclassify.c libm/machine/pru/fpclassifyf.c libm/machine/pru/isfinite.c libm/machine/pru/isfinitef.c libm/machine/pru/isinf.c libm/machine/pru/isinff.c libm/machine/pru/isnan.c libm/machine/pru/isnanf.c libm/machine/pru/isnormal.c libm/machine/pru/isnormalf.c Copyright: 2018-2019 Dimitar Dimitrov License: BSD2-4 Files: libc/machine/or1k/setjmp.S Copyright: 2014, Hesham ALMatary License: BSD2-5 Files: libc/machine/sparc/machine/fenv-fp.h Copyright: 2004-2005 David Schultz License: BSD2-6 Files: libc/machine/xtensa/machine/fenv-fp.h libc/machine/xtensa/machine/fenv.h Copyright: 2011 Tensilica Inc. License: BSD2-7 Files: libc/posix/collate.h Copyright: 1995 Alex Tatmanjants at Electronni Visti IA, Kiev, Ukraine. License: BSD2-8 Files: libc/posix/collcmp.c Copyright: 1996 Andrey A. Chernov, Moscow, Russia. License: BSD2-9 Files: libc/signal/sig2str.c Copyright: 2021 Matthew Joyce License: BSD2-10 Files: libm/ld/common/e_sqrtl.c libm/ld/common/s_cosl.c libm/ld/common/s_sinl.c libm/ld/common/s_tanl.c Copyright: 2007 Steven G. Kargl License: BSD2-11 Files: libm/ld/common/s_roundl.c Copyright: 2003, Steven G. Kargl License: BSD2-11 Files: libm/ld/ld128/s_nanl.c libm/ld/ld80/s_nanl.c Copyright: 2007 David Schultz License: BSD2-12 Files: CMakeLists.txt cmake/picolibc.cmake libc/CMakeLists.txt libc/argz/CMakeLists.txt libc/ctype/CMakeLists.txt libc/errno/CMakeLists.txt libc/include/CMakeLists.txt libc/include/arpa/CMakeLists.txt libc/include/byteswap.h libc/include/machine/CMakeLists.txt libc/include/rpc/CMakeLists.txt libc/include/rpc/meson.build libc/include/ssp/CMakeLists.txt libc/include/stdio-bufio.h libc/include/sys/CMakeLists.txt libc/machine/CMakeLists.txt libc/machine/aarch64/CMakeLists.txt libc/machine/aarch64/machine/CMakeLists.txt libc/machine/aarch64/machine/math.h libc/machine/aarch64/machine/meson.build libc/machine/aarch64/sys/meson.build libc/machine/arc/CMakeLists.txt libc/machine/arc/meson.build libc/machine/arc/tls.c libc/machine/arc64/CMakeLists.txt libc/machine/arc64/meson.build libc/machine/arm/CMakeLists.txt libc/machine/arm/machine/CMakeLists.txt libc/machine/arm/sys/meson.build libc/machine/avr/meson.build libc/machine/m68k/machine/CMakeLists.txt libc/machine/mips/CMakeLists.txt libc/machine/mips/machine/CMakeLists.txt libc/machine/mips/machine/meson.build libc/machine/mips/meson.build libc/machine/mips/tls.c libc/machine/msp430/meson.build libc/machine/nios2/CMakeLists.txt libc/machine/nios2/meson.build libc/machine/powerpc/CMakeLists.txt libc/machine/powerpc/machine/CMakeLists.txt libc/machine/powerpc/machine/meson.build libc/machine/riscv/CMakeLists.txt libc/machine/riscv/machine/CMakeLists.txt libc/machine/sparc/CMakeLists.txt libc/machine/sparc/machine/CMakeLists.txt libc/machine/sparc/machine/meson.build libc/machine/sparc/meson.build libc/machine/x86/CMakeLists.txt libc/machine/x86/machine/CMakeLists.txt libc/machine/x86/sys/meson.build libc/machine/xtensa/CMakeLists.txt libc/machine/xtensa/machine/CMakeLists.txt libc/machine/xtensa/tls.c libc/misc/CMakeLists.txt libc/posix/CMakeLists.txt libc/search/CMakeLists.txt libc/signal/CMakeLists.txt libc/ssp/CMakeLists.txt libc/stdio/CMakeLists.txt libc/stdio/ecvt_r.c libc/stdio/ecvtf_r.c libc/stdio/ecvtl_r.c libc/stdio/fcvt_r.c libc/stdio/fcvtf_r.c libc/stdio/fcvtl_r.c libc/stdio/fmemopen.c libc/stdio/getline.c libc/stdio/remove.c libc/stdio/strtoimax_l.c libc/stdio/strtol_l.c libc/stdio/strtoll_l.c libc/stdio/strtoul_l.c libc/stdio/strtoull_l.c libc/stdio/strtoumax_l.c libc/stdio/tmpfile.c libc/stdio/tmpnam.c libc/stdlib/CMakeLists.txt libc/string/CMakeLists.txt libc/time/CMakeLists.txt libc/xdr/CMakeLists.txt libm/CMakeLists.txt libm/common/CMakeLists.txt libm/common/s_iseqsig.c libm/common/sf_iseqsig.c libm/common/sl_iseqsig.c libm/fenv/CMakeLists.txt libm/fenv/fegetmode.c libm/fenv/fesetmode.c libm/ld/CMakeLists.txt libm/ld/common/meson.build libm/ld/common/s_issignalingl.c libm/ld/common/s_significandl.c libm/ld/e_acoshl.c libm/ld/e_acosl.c libm/ld/e_asinl.c libm/ld/e_atan2l.c libm/ld/e_atanhl.c libm/ld/e_coshl.c libm/ld/e_expl.c libm/ld/e_fmodl.c libm/ld/e_hypotl.c libm/ld/e_lgammal.c libm/ld/e_lgammal_r.c libm/ld/e_log10l.c libm/ld/e_log2l.c libm/ld/e_logl.c libm/ld/e_powl.c libm/ld/e_remainderl.c libm/ld/e_sinhl.c libm/ld/e_sqrtl.c libm/ld/e_tgammal.c libm/ld/invtrig.c libm/ld/k_cosl.c libm/ld/k_rem_pio2.c libm/ld/k_sinl.c libm/ld/k_tanl.c libm/ld/ldd/s_ceill.c libm/ld/ldd/s_floorl.c libm/ld/ldd/s_fpclassifyl.c libm/ld/ldd/s_nanl.c libm/ld/ldd/s_nearbyintl.c libm/ld/ldd/s_truncl.c libm/ld/math_ld.h libm/ld/meson.build libm/ld/polevll.c libm/ld/s_asinhl.c libm/ld/s_atanl.c libm/ld/s_cbrtl.c libm/ld/s_ceill.c libm/ld/s_copysignl.c libm/ld/s_cosl.c libm/ld/s_erfl.c libm/ld/s_exp2l.c libm/ld/s_expm1l.c libm/ld/s_fabsl.c libm/ld/s_fdiml.c libm/ld/s_finitel.c libm/ld/s_floorl.c libm/ld/s_fmal.c libm/ld/s_fmaxl.c libm/ld/s_fminl.c libm/ld/s_fpclassifyl.c libm/ld/s_frexpl.c libm/ld/s_getpayloadl.c libm/ld/s_ilogbl.c libm/ld/s_isnanl.c libm/ld/s_issignalingl.c libm/ld/s_llrintl.c libm/ld/s_llroundl.c libm/ld/s_log1pl.c libm/ld/s_logbl.c libm/ld/s_lrintl.c libm/ld/s_lroundl.c libm/ld/s_modfl.c libm/ld/s_nanl.c libm/ld/s_nextafterl.c libm/ld/s_nexttoward.c libm/ld/s_nexttowardf.c libm/ld/s_remquol.c libm/ld/s_rintl.c libm/ld/s_roundl.c libm/ld/s_scalbl.c libm/ld/s_scalbln.c libm/ld/s_scalbnl.c libm/ld/s_significandl.c libm/ld/s_sincosl.c libm/ld/s_sinl.c libm/ld/s_tanhl.c libm/ld/s_tanl.c libm/ld/s_truncl.c libm/machine/CMakeLists.txt libm/machine/aarch64/CMakeLists.txt libm/machine/arm/CMakeLists.txt libm/machine/arm/s_fabs.c libm/machine/arm/sf_fabs.c libm/machine/powerpc/CMakeLists.txt libm/machine/powerpc/complex128.c libm/machine/riscv/CMakeLists.txt libm/machine/x86/CMakeLists.txt libm/math/CMakeLists.txt picocrt/CMakeLists.txt picocrt/machine/arc/CMakeLists.txt picocrt/machine/arc64/CMakeLists.txt picocrt/machine/arm/CMakeLists.txt picocrt/machine/powerpc/crt0.S picocrt/machine/powerpc/powerpc_crt.h picocrt/machine/sh/CMakeLists.txt semihost/CMakeLists.txt semihost/common/CMakeLists.txt semihost/common/getentropy.c semihost/fake/fake_exit.c semihost/fake/fake_io.c semihost/fake/fake_kill.c semihost/fake/fake_stub.c semihost/fake/meson.build semihost/machine/arc/CMakeLists.txt semihost/machine/arc64/CMakeLists.txt semihost/machine/arm/CMakeLists.txt semihost/machine/powerpc/opal.h semihost/machine/powerpc/opal_call.S semihost/machine/powerpc/opal_cec_power_down.c semihost/machine/powerpc/opal_console_write.c semihost/machine/sh/sh_io.c test/CMakeLists.txt test/lock-valid.c test/long_double.c test/native-locks.c test/test-efcvt.c test/test-except.c test/test-stdio/CMakeLists.txt test/test-stdio/test-fopen.c test/test-stdio/test-mktemp.c test/test-strtod.c test/testsuite/newlib.time/meson.build zephyr/zephyr.cmake Copyright: 2022 Keith Packard License: BSD3-1 Files: cmake/TC-arm-none-eabi.ld cmake/TC-microbit.ld hello-world/hello-worldpp.cpp libc/errno/errno.c libc/include/machine/math.h libc/include/ssp/meson.build libc/include/sys/auxv.h libc/machine/aarch64/tls.c libc/machine/arm/arm_tls.h libc/machine/arm/machine/meson.build libc/machine/csky/meson.build libc/machine/riscv/machine/math.h libc/machine/riscv/machine/meson.build libc/machine/x86/machine/meson.build libc/misc/getauxval.c libc/posix/meson.build libc/stdio/asnprintf.c libc/stdio/asprintf.c libc/stdio/compare_exchange.c libc/stdio/ecvt.c libc/stdio/ecvtf.c libc/stdio/ecvtl.c libc/stdio/exchange.c libc/stdio/fcvt.c libc/stdio/fcvtf.c libc/stdio/fcvtl.c libc/stdio/fflush.c libc/stdio/filestrget.c libc/stdio/filestrput.c libc/stdio/filestrputalloc.c libc/stdio/filewstrget.c libc/stdio/gcvt.c libc/stdio/gcvtf.c libc/stdio/gcvtl.c libc/stdio/perror.c libc/stdio/setvbuf.c libc/stdio/strtod_l.c libc/stdio/strtof_l.c libc/stdio/strtold_l.c libc/stdio/vasnprintf.c libc/stdio/vasprintf.c libm/machine/arm/s_fma_arm.c libm/machine/arm/sf_fma_arm.c libm/machine/riscv/s_fma.c libm/machine/riscv/s_sqrt.c libm/machine/riscv/sf_fma.c libm/machine/riscv/sf_sqrt.c libm/math/s_lgamma.c scripts/run-aarch64 scripts/run-arc scripts/run-i386 scripts/run-m68k scripts/run-mips scripts/run-msp430 scripts/run-nios2 scripts/run-or1k scripts/run-sh scripts/run-sparc scripts/run-x86 scripts/run-x86_64 semihost/common/fstat.c semihost/common/isatty.c semihost/common/mapstdio.c semihost/common/sys_iserror.c semihost/common/sys_system.c semihost/common/sys_tickfreq.c test/fenv.c test/ffs.c test/malloc.c test/malloc_stress.c test/math_errhandling.c test/math_errhandling_tests.c test/regex.c test/semihost/meson.build test/semihost/semihost-argv.c test/semihost/semihost-clock.c test/semihost/semihost-close.c test/semihost/semihost-elapsed.c test/semihost/semihost-errno.c test/semihost/semihost-exit-extended-failure.c test/semihost/semihost-exit-extended.c test/semihost/semihost-exit-failure.c test/semihost/semihost-exit.c test/semihost/semihost-flen.c test/semihost/semihost-get-cmdline.c test/semihost/semihost-gettimeofday.c test/semihost/semihost-heapinfo.c test/semihost/semihost-iserror.c test/semihost/semihost-istty.c test/semihost/semihost-no-argv.c test/semihost/semihost-open.c test/semihost/semihost-read.c test/semihost/semihost-readc.c test/semihost/semihost-remove.c test/semihost/semihost-rename.c test/semihost/semihost-seek.c test/semihost/semihost-system-failure.c test/semihost/semihost-system.c test/semihost/semihost-tickfreq.c test/semihost/semihost-time.c test/semihost/semihost-times.c test/semihost/semihost-tmpnam.c test/semihost/semihost-tmpname.c test/semihost/semihost-write.c test/semihost/semihost-write0.c test/semihost/semihost-writec.c test/setjmp.c test/stack-smash.c test/tls.c test/try-ilp32-sub.c test/try-ilp32.c test/try-ilp32.h Copyright: 2020 Keith Packard License: BSD3-1 Files: cmake/TC-rx.ld libc/ctype/iswspace_l.c libc/ctype/mkctype-extended.py libc/iconv/CMakeLists.txt libc/iconv/iconv.c libc/iconv/iconv_close.c libc/iconv/iconv_open.c libc/iconv/iconv_private.h libc/iconv/meson.build libc/include/monetary.h libc/locale/CMakeLists.txt libc/locale/duplocale.c libc/locale/freelocale.c libc/locale/getlocalename_l.c libc/locale/locale_ctype_ptr.c libc/locale/locale_ctype_ptr_l.c libc/locale/locale_mb_cur_max.c libc/locale/locale_names.c libc/locale/locale_private.h libc/locale/localeconv.c libc/locale/localedata.c libc/locale/meson.build libc/locale/newlocale.c libc/locale/nl_langinfo.c libc/locale/posix_locale.c libc/locale/setlocale.c libc/locale/timedata.c libc/locale/uselocale.c libc/machine/aarch64/interrupt_vector.S libc/machine/loongarch/tls.c libc/machine/m68k/read_tp.S libc/machine/m68k/set_tls.c libc/machine/m68k/tls-local.h libc/machine/m68k/tls.c libc/machine/or1k/tls.c libc/machine/powerpc/hwcap.c libc/machine/powerpc/machine/_ssp_tls.h libc/machine/powerpc/tls.c libc/machine/sh/tls.c libc/machine/x86/interrupt.S libc/machine/x86/interrupt.c libc/posix/posix-local.h libc/posix/strfmon.c libc/posix/strfmon_l.c libc/posix/vstrfmon.c libc/stdio/dprintf.c libc/stdio/flockfile_init.c libc/stdio/vdprintf.c libc/stdio/wcstod.c libc/stdio/wcstod_l.c libc/stdio/wcstof.c libc/stdio/wcstof_l.c libc/stdio/wcstoimax.c libc/stdio/wcstoimax_l.c libc/stdio/wcstol.c libc/stdio/wcstol_l.c libc/stdio/wcstold.c libc/stdio/wcstold_l.c libc/stdio/wcstoll.c libc/stdio/wcstoll_l.c libc/stdio/wcstoul.c libc/stdio/wcstoul_l.c libc/stdio/wcstoull.c libc/stdio/wcstoull_l.c libc/stdio/wcstoumax.c libc/stdio/wcstoumax_l.c libc/stdlib/ejtouc.c libc/stdlib/jis.h libc/stdlib/jis_charsets.h libc/stdlib/jitouc.c libc/stdlib/mk-jis-charsets.py libc/stdlib/mk-sb-charsets.py libc/stdlib/sb_charsets.h libc/stdlib/sjtouc.c libc/stdlib/uctoej.c libc/stdlib/uctoji.c libc/stdlib/uctosj.c libc/time/getdate.c libc/time/getdate_r.c libc/ubsan/CMakeLists.txt libc/ubsan/meson.build libc/ubsan/ubsan.h libc/ubsan/ubsan_cfi_type_check_to_string.c libc/ubsan/ubsan_error.c libc/ubsan/ubsan_handle_add_overflow.c libc/ubsan/ubsan_handle_alignment_assumption.c libc/ubsan/ubsan_handle_builtin_unreachable.c libc/ubsan/ubsan_handle_cfi_bad_type.c libc/ubsan/ubsan_handle_cfi_check_fail.c libc/ubsan/ubsan_handle_divrem_overflow.c libc/ubsan/ubsan_handle_dynamic_type_cache_miss.c libc/ubsan/ubsan_handle_float_cast_overflow.c libc/ubsan/ubsan_handle_function_type_mismatch.c libc/ubsan/ubsan_handle_implicit_conversion.c libc/ubsan/ubsan_handle_invalid_builtin.c libc/ubsan/ubsan_handle_invalid_objc_cast.c libc/ubsan/ubsan_handle_load_invalid_value.c libc/ubsan/ubsan_handle_missing_return.c libc/ubsan/ubsan_handle_mul_overflow.c libc/ubsan/ubsan_handle_negate_overflow.c libc/ubsan/ubsan_handle_nonnull_arg.c libc/ubsan/ubsan_handle_nonnull_return.c libc/ubsan/ubsan_handle_nonnull_return_v1.c libc/ubsan/ubsan_handle_nullability_arg.c libc/ubsan/ubsan_handle_nullability_return.c libc/ubsan/ubsan_handle_nullability_return_v1.c libc/ubsan/ubsan_handle_out_of_bounds.c libc/ubsan/ubsan_handle_pointer_overflow.c libc/ubsan/ubsan_handle_shift_out_of_bounds.c libc/ubsan/ubsan_handle_sub_overflow.c libc/ubsan/ubsan_handle_type_mismatch.c libc/ubsan/ubsan_handle_type_mismatch_v1.c libc/ubsan/ubsan_handle_vla_bound_not_positive.c libc/ubsan/ubsan_message.c libc/ubsan/ubsan_type_check_to_string.c libc/ubsan/ubsan_val_to_imax.c libc/ubsan/ubsan_val_to_string.c libc/ubsan/ubsan_val_to_umax.c libc/ubsan/ubsan_warning.c libm/math/s_sincos.c libm/math/sf_sincos.c picocrt/machine/lm32/crt0.S picocrt/machine/or1k/crt0.S picocrt/machine/or1k/crt0.c picocrt/machine/rx/crt0.c picocrt/machine/x86/traps.S picocrt/machine/x86/traps.c semihost/machine/lm32/lm32_errno.c semihost/machine/rx/rx_iob.c semihost/machine/rx/rx_semihost.h semihost/machine/sh/sh_syscall.c test/test-ctype/test-wcase.c test/test-getdate.c test/test-hello.c test/test-iconv/meson.build test/test-iconv/test-iconv.c test/test-math/CMakeLists.txt test/test-math/meson.build test/test-math/test-acos.5c test/test-math/test-acos.c test/test-math/test-acos.h test/test-math/test-acosh.5c test/test-math/test-acosh.c test/test-math/test-acosh.h test/test-math/test-asin.5c test/test-math/test-asin.c test/test-math/test-asin.h test/test-math/test-asinh.5c test/test-math/test-asinh.c test/test-math/test-asinh.h test/test-math/test-atan.5c test/test-math/test-atan.c test/test-math/test-atan.h test/test-math/test-atan2.5c test/test-math/test-atan2.c test/test-math/test-atan2.h test/test-math/test-atanh.5c test/test-math/test-atanh.c test/test-math/test-atanh.h test/test-math/test-cacos.5c test/test-math/test-cacos.c test/test-math/test-cacos.h test/test-math/test-cacosh.5c test/test-math/test-cacosh.c test/test-math/test-cacosh.h test/test-math/test-casin.5c test/test-math/test-casin.c test/test-math/test-casin.h test/test-math/test-casinh.5c test/test-math/test-casinh.c test/test-math/test-casinh.h test/test-math/test-catan.5c test/test-math/test-catan.c test/test-math/test-catan.h test/test-math/test-catanh.5c test/test-math/test-catanh.c test/test-math/test-catanh.h test/test-math/test-cbrt.5c test/test-math/test-cbrt.c test/test-math/test-cbrt.h test/test-math/test-ccos.5c test/test-math/test-ccos.c test/test-math/test-ccos.h test/test-math/test-ccosh.5c test/test-math/test-ccosh.c test/test-math/test-ccosh.h test/test-math/test-cexp.5c test/test-math/test-cexp.c test/test-math/test-cexp.h test/test-math/test-clog.5c test/test-math/test-clog.c test/test-math/test-clog.h test/test-math/test-complex-complex.h test/test-math/test-complex-one.h test/test-math/test-cos.5c test/test-math/test-cos.c test/test-math/test-cos.h test/test-math/test-cosh.5c test/test-math/test-cosh.c test/test-math/test-cosh.h test/test-math/test-cpow.5c test/test-math/test-cpow.c test/test-math/test-cpow.h test/test-math/test-csin.5c test/test-math/test-csin.c test/test-math/test-csin.h test/test-math/test-csinh.5c test/test-math/test-csinh.c test/test-math/test-csinh.h test/test-math/test-csqrt.5c test/test-math/test-csqrt.c test/test-math/test-csqrt.h test/test-math/test-ctan.5c test/test-math/test-ctan.c test/test-math/test-ctan.h test/test-math/test-ctanh.5c test/test-math/test-ctanh.c test/test-math/test-ctanh.h test/test-math/test-erf.5c test/test-math/test-erf.c test/test-math/test-erf.h test/test-math/test-erfc.5c test/test-math/test-erfc.c test/test-math/test-erfc.h test/test-math/test-exp.5c test/test-math/test-exp.c test/test-math/test-exp.h test/test-math/test-exp10.5c test/test-math/test-exp10.c test/test-math/test-exp10.h test/test-math/test-exp2.5c test/test-math/test-exp2.c test/test-math/test-exp2.h test/test-math/test-expm1.5c test/test-math/test-expm1.c test/test-math/test-expm1.h test/test-math/test-hypot.5c test/test-math/test-hypot.c test/test-math/test-hypot.h test/test-math/test-int-real.h test/test-math/test-j0.5c test/test-math/test-j0.c test/test-math/test-j0.h test/test-math/test-j1.5c test/test-math/test-j1.c test/test-math/test-j1.h test/test-math/test-jn.5c test/test-math/test-jn.c test/test-math/test-jn.h test/test-math/test-lgamma.5c test/test-math/test-lgamma.c test/test-math/test-lgamma.h test/test-math/test-log.5c test/test-math/test-log.c test/test-math/test-log.h test/test-math/test-log10.5c test/test-math/test-log10.c test/test-math/test-log10.h test/test-math/test-log1p.5c test/test-math/test-log1p.c test/test-math/test-log1p.h test/test-math/test-log2.5c test/test-math/test-log2.c test/test-math/test-log2.h test/test-math/test-math-compare.c test/test-math/test-math.h test/test-math/test-pow.5c test/test-math/test-pow.c test/test-math/test-pow.h test/test-math/test-real-int.h test/test-math/test-real-one.h test/test-math/test-real-real.h test/test-math/test-sin.5c test/test-math/test-sin.c test/test-math/test-sin.h test/test-math/test-sincos-cos.c test/test-math/test-sincos-sin.c test/test-math/test-sinh.5c test/test-math/test-sinh.c test/test-math/test-sinh.h test/test-math/test-sqrt.5c test/test-math/test-sqrt.c test/test-math/test-sqrt.h test/test-math/test-tan.5c test/test-math/test-tan.c test/test-math/test-tan.h test/test-math/test-tanh.5c test/test-math/test-tanh.c test/test-math/test-tanh.h test/test-math/test-tgamma.5c test/test-math/test-tgamma.c test/test-math/test-tgamma.h test/test-math/test-ulp.h test/test-monetary/CMakeLists.txt test/test-monetary/meson.build test/test-scmpu.c test/test-stdio/meson.build test/test-stdio/test-dprintf.c test/test-stdio/test-setvbuf.c test/test-string/meson.build test/test-string/test-memchr.c test/test-string/test-memmem.c test/test-time.c test/test-wctomb.c Copyright: 2025 Keith Packard License: BSD3-1 Files: doc/printf-sample/Makefile doc/printf-sample/printf.c libc/machine/arm/machine/fenv-fp.h libc/machine/m68k/CMakeLists.txt libc/machine/m68k/machine/fenv-fp.h libc/machine/m68k/machine/fenv.h libc/stdio/dtox_engine.c libc/stdio/ftox_engine.c libc/stdio/getdelim.c libc/stdio/ldtox_engine.c libc/stdio/swprintf.c libc/stdio/vswprintf.c picocrt/machine/m68k/crt0.c picocrt/machine/mips/crt0.c picocrt/machine/msp430/crt0.c picocrt/machine/nios2/crt0.c picocrt/machine/sparc/crt0.c semihost/machine/aarch64/aarch64-semihost.h semihost/machine/aarch64/aarch64_iob.c semihost/machine/arc/arc_close.c semihost/machine/arc/arc_errno.c semihost/machine/arc/arc_exit.c semihost/machine/arc/arc_fstat.c semihost/machine/arc/arc_lseek.c semihost/machine/arc/arc_open.c semihost/machine/arc/arc_read.c semihost/machine/arc/arc_semihost.h semihost/machine/arc/arc_stat.c semihost/machine/arc/arc_unlink.c semihost/machine/arc/arc_write.c semihost/machine/m68k/m68k_close.c semihost/machine/m68k/m68k_exit.c semihost/machine/m68k/m68k_fstat.c semihost/machine/m68k/m68k_lseek.c semihost/machine/m68k/m68k_open.c semihost/machine/m68k/m68k_read.c semihost/machine/m68k/m68k_semihost.S semihost/machine/m68k/m68k_semihost.h semihost/machine/m68k/m68k_stat.c semihost/machine/m68k/m68k_unlink.c semihost/machine/m68k/m68k_write.c semihost/machine/msp430/msp430-iob.c semihost/machine/msp430/msp430-semihost.h semihost/machine/nios2/nios2_close.c semihost/machine/nios2/nios2_exit.c semihost/machine/nios2/nios2_fstat.c semihost/machine/nios2/nios2_lseek.c semihost/machine/nios2/nios2_open.c semihost/machine/nios2/nios2_read.c semihost/machine/nios2/nios2_semihost.c semihost/machine/nios2/nios2_semihost.h semihost/machine/nios2/nios2_stat.c semihost/machine/nios2/nios2_unlink.c semihost/machine/nios2/nios2_write.c semihost/machine/or1k/or1k_iob.c semihost/machine/or1k/or1k_semihost.h semihost/machine/sh/sh_semihost.h semihost/machine/sparc/sparc-semihost.h semihost/machine/sparc/sparc_iob.c semihost/machine/xtensa/xtensa-iob.c semihost/machine/xtensa/xtensa-semihost.h test/test-fma.c test/test-raise.c test/test-stdio/test-fread-fwrite.c test/test-stdio/test-gets.c test/test-stdio/test-long-long.c test/test-ubsan.c test/testsuite/newlib.time/asctime.c Copyright: 2023 Keith Packard License: BSD3-1 Files: empty-libs/empty.c libc/machine/arm/memmove.c libc/machine/xtensa/machine/meson.build libc/stdio/atold_engine.c libc/stdio/ldtoa_engine.c libc/stdio/matchcaseprefix.c libc/stdio/rewind.c libc/stdio/strfromd.c libc/stdio/strfromf.c libc/stdio/strfroml.c libc/stdlib/atexit.c libc/stdlib/cxa-atexit.c libc/stdlib/exit.c libc/stdlib/exitprocs.c libc/stdlib/local-onexit.h libc/stdlib/onexit.c libm/common/exp10l.c libm/common/math_inexact.c libm/common/math_inexactf.c libm/common/math_inexactl.c libm/common/s_getpayload.c libm/common/sf_getpayload.c libm/ld/ld128/s_getpayloadl.c libm/ld/ld80/s_getpayloadl.c libm/machine/powerpc/meson.build libm/test/scalb_vec.c libm/test/scalbn_vec.c picocrt/machine/aarch64/meson.build picocrt/machine/arc/meson.build picocrt/machine/arc64/meson.build picocrt/machine/arm/meson.build picocrt/machine/lm32/meson.build picocrt/machine/m68k/meson.build picocrt/machine/mips/meson.build picocrt/machine/msp430/meson.build picocrt/machine/nios2/meson.build picocrt/machine/or1k/meson.build picocrt/machine/powerpc/meson.build picocrt/machine/riscv/meson.build picocrt/machine/sh/meson.build picocrt/machine/sparc/meson.build picocrt/machine/x86/CMakeLists.txt picocrt/machine/x86/meson.build scripts/do-power9-configure scripts/do-power9-fp128-configure scripts/do-powerpc64-configure scripts/do-powerpc64le-configure semihost/common/gettimeofday.c semihost/machine/aarch64/aarch64_exit.c semihost/machine/aarch64/aarch64_stub.c semihost/machine/aarch64/meson.build semihost/machine/arc/arc_stub.c semihost/machine/arc/meson.build semihost/machine/arc64/meson.build semihost/machine/arm/meson.build semihost/machine/m68k/m68k_stub.c semihost/machine/m68k/meson.build semihost/machine/msp430/meson.build semihost/machine/msp430/msp430-exit.c semihost/machine/msp430/msp430-stub.c semihost/machine/nios2/meson.build semihost/machine/nios2/nios2_stub.c semihost/machine/or1k/meson.build semihost/machine/or1k/or1k_exit.c semihost/machine/or1k/or1k_stub.c semihost/machine/powerpc/meson.build semihost/machine/powerpc/powerpc_exit.c semihost/machine/powerpc/powerpc_io.c semihost/machine/powerpc/powerpc_kill.c semihost/machine/powerpc/powerpc_stub.c semihost/machine/riscv/meson.build semihost/machine/rx/CMakeLists.txt semihost/machine/rx/meson.build semihost/machine/rx/rx_exit.c semihost/machine/rx/rx_stub.c semihost/machine/sh/meson.build semihost/machine/sh/sh_exit.c semihost/machine/sh/sh_stub.c semihost/machine/sparc/meson.build semihost/machine/sparc/sparc_exit.c semihost/machine/sparc/sparc_stub.c semihost/machine/x86/bios.S semihost/machine/x86/e9_exit.c semihost/machine/x86/e9_io.c semihost/machine/x86/e9_kill.c semihost/machine/x86/e9_stub.c semihost/machine/x86/meson.build semihost/machine/xtensa/meson.build semihost/machine/xtensa/xtensa-exit.c semihost/machine/xtensa/xtensa-stub.c test/atexit.c test/constructor-skip.c test/constructor.c test/hosted-exit.c test/libc-testsuite/testcase.h test/math-funcs.c test/on_exit.c test/rounding-mode-sub.c test/rounding-mode.c test/rounding-mode.h test/test-stdio/test-put.c test/test-string/test-memchr-simple.c test/test-string/test-memset.c test/test-string/test-strchr.c test/timegm.c test/timegm.h Copyright: 2021 Keith Packard License: BSD3-1 Files: empty-libs/meson.build libc/ctype/ctype_class.h libc/machine/arc64/sys/meson.build libc/machine/arc64/tls.c libc/machine/arc64/vector_table.c libc/machine/loongarch/CMakeLists.txt libc/machine/loongarch/machine/CMakeLists.txt libc/machine/msp430/CMakeLists.txt libc/stdio/atomic_store.c libc/stdio/bufio_close.c libc/stdio/bufio_close_nf.c libc/stdio/bufio_setvbuf.c libm/math/sf_rem_pio2.c test/test-ctype/CMakeLists.txt test/test-ctype/meson.build test/test-ctype/test-iswctype.c test/test-stdio/test-fdevopen.c test/test-stdio/test-freopen.c test/test-string/CMakeLists.txt Copyright: 2026 Keith Packard License: BSD3-1 Files: hello-world/Makefile hello-world/hello-world.c hello-world/printf.c hello-world/run-aarch64 hello-world/run-aarch64++ hello-world/run-arm hello-world/run-riscv hello-world/run-riscv++ libc/argz/meson.build libc/ctype/meson.build libc/errno/meson.build libc/include/arpa/meson.build libc/include/endian.h libc/include/machine/meson.build libc/include/meson.build libc/include/newlib.h libc/include/picotls.h libc/include/sys/meson.build libc/machine/aarch64/interrupt.c libc/machine/arm/interrupt.c libc/machine/arm/meson.build libc/machine/riscv/meson.build libc/machine/riscv/tls.c libc/machine/sparc/interrupt.S libc/machine/sparc/tls.c libc/machine/x86/meson.build libc/meson.build libc/misc/dso_handle.c libc/misc/inittls.c libc/misc/meson.build libc/misc/picosbrk.c libc/search/meson.build libc/signal/meson.build libc/ssp/meson.build libc/stdio/bufio.c libc/stdio/fdopen.c libc/stdio/fileno.c libc/stdio/fopen.c libc/stdio/freopen.c libc/stdio/fseek.c libc/stdio/fseeko.c libc/stdio/ftell.c libc/stdio/ftello.c libc/stdio/fwide.c libc/stdio/meson.build libc/stdio/posixiob_stderr.c libc/stdio/posixiob_stdin.c libc/stdio/posixiob_stdout.c libc/stdio/setbuf.c libc/stdio/setbuffer.c libc/stdio/setlinebuf.c libc/stdlib/meson.build libc/string/meson.build libc/time/meson.build libc/xdr/meson.build libm/common/meson.build libm/common/s_issignaling.c libm/common/sf_issignaling.c libm/common/signgam.c libm/common/sl_issignaling.c libm/complex/meson.build libm/fenv/meson.build libm/machine/arm/meson.build libm/machine/riscv/meson.build libm/machine/x86/meson.build libm/math/meson.build libm/meson.build libm/test/copysign_vec.c libm/test/copysignf_vec.c libm/test/issignaling_vec.c libm/test/meson.build libm/test/modf_vec.c libm/test/modff_vec.c libm/test/pow_vec.c libm/test/powf_vec.c meson_options.txt picocrt/crt0.h picocrt/machine/aarch64/crt0.c picocrt/machine/arc/crt0.c picocrt/machine/arm/crt0.c picocrt/machine/sh/crt0.c picocrt/meson.build picocrt/shared/crt0.c scripts/do-aarch64-configure scripts/do-aarch64-none-elf-configure scripts/do-aarch64-zephyr-configure scripts/do-aarch64-zephyr-elf-configure scripts/do-arc-configure scripts/do-arc64-configure scripts/do-arm-configure scripts/do-avr-configure scripts/do-clang-aarch64-configure scripts/do-clang-aarch64-fvp-configure scripts/do-clang-arm-configure scripts/do-clang-msp430-configure scripts/do-clang-riscv-configure scripts/do-clang-rv32imafdc-configure scripts/do-clang-thumb-configure scripts/do-clang-thumbv6m-configure scripts/do-clang-thumbv7-a-configure scripts/do-clang-thumbv7e+dp-configure scripts/do-clang-thumbv7e+fp-configure scripts/do-clang-thumbv7m-configure scripts/do-configure scripts/do-cortex-a9-configure scripts/do-esp32-configure scripts/do-freedom-tools-configure scripts/do-i386-configure scripts/do-lx106-configure scripts/do-mips-configure scripts/do-mips-zephyr-configure scripts/do-mips64-configure scripts/do-mipsel-configure scripts/do-msp430-configure scripts/do-msp430-unknown-elf-configure scripts/do-native-configure scripts/do-native-m32-configure scripts/do-nios2-configure scripts/do-or1k-configure scripts/do-riscv-configure scripts/do-rv32imac-configure scripts/do-sh-unknown-elf-configure scripts/do-sparc-zephyr-configure scripts/do-sparc64-configure scripts/do-thumbv8_1m-configure scripts/do-thumbv8m_main_fp-configure scripts/do-x86-configure scripts/do-x86_64-configure scripts/do-x86_64-zephyr-configure scripts/do-xtensa-dc233c-configure scripts/do-xtensa-espressif_esp32-configure scripts/do-xtensa-espressif_esp32s2-configure scripts/do-xtensa-intel_apl_adsp-configure scripts/do-xtensa-intel_s1000-configure scripts/do-xtensa-nxp_imx8m_adsp-configure scripts/do-xtensa-nxp_imx_adsp-configure scripts/do-xtensa-sample_controller-configure scripts/do-zephyr-aarch64-configure scripts/do-zephyr-arm-configure scripts/do-zephyr-riscv-configure scripts/run-arm scripts/run-power9 scripts/run-riscv semihost/common/close.c semihost/common/exit.c semihost/common/iob.c semihost/common/kill.c semihost/common/lseek.c semihost/common/lseek64.c semihost/common/meson.build semihost/common/open.c semihost/common/read.c semihost/common/semihost-private.h semihost/common/semihost.h semihost/common/sys_clock.c semihost/common/sys_close.c semihost/common/sys_elapsed.c semihost/common/sys_errno.c semihost/common/sys_exit.c semihost/common/sys_exit_extended.c semihost/common/sys_feature.c semihost/common/sys_flen.c semihost/common/sys_get_cmdline.c semihost/common/sys_getc.c semihost/common/sys_heapinfo.c semihost/common/sys_istty.c semihost/common/sys_open.c semihost/common/sys_putc.c semihost/common/sys_read.c semihost/common/sys_remove.c semihost/common/sys_rename.c semihost/common/sys_seek.c semihost/common/sys_time.c semihost/common/sys_tmpnam.c semihost/common/sys_write.c semihost/common/sys_write0.c semihost/common/sysconf.c semihost/common/times.c semihost/common/unlink.c semihost/common/write.c semihost/machine/aarch64/semihost-aarch64.S semihost/machine/arm/semihost-arm.S semihost/machine/riscv/semihost-riscv.S semihost/meson.build test/libc-testsuite/meson.build test/meson.build test/rand.c test/test-stdio/test-posix-io.c test/test-stdio/test-printf-scanf.c test/test-stdio/test-ungetc.c test/testsuite/meson.build test/testsuite/newlib.iconv/meson.build test/testsuite/newlib.locale/meson.build test/testsuite/newlib.search/meson.build test/testsuite/newlib.stdio/meson.build test/testsuite/newlib.stdlib/meson.build test/testsuite/newlib.string/meson.build test/testsuite/newlib.wctype/meson.build Copyright: 2019 Keith Packard License: BSD3-1 Files: libc/ctype/ctype_extended.h libc/ctype/ctype_table.c libc/ctype/ctype_table.h libc/ctype/mkctype.py libc/ctype/mkctype_class.py libc/include/stdnoreturn.h libc/include/sys/_initfini.h libc/include/uchar.h libc/machine/arc/vector_table.c libc/machine/m68k/interrupt.c libc/machine/m68k/machine/meson.build libc/machine/rx/CMakeLists.txt libc/machine/sh/CMakeLists.txt libc/machine/sh/machine/CMakeLists.txt libc/machine/sh/machine/meson.build libc/posix/fpathconf.c libc/posix/pathconf.c libc/stdio/atomic_load.c libc/stdio/flockfile.c libc/stdio/ftrylockfile.c libc/stdio/funlockfile.c libc/stdio/funopen.c libc/string/memset_explicit.c libc/uchar/CMakeLists.txt libc/uchar/c16rtomb.c libc/uchar/c32rtomb.c libc/uchar/c8rtomb.c libc/uchar/mbrtoc16.c libc/uchar/mbrtoc32.c libc/uchar/mbrtoc8.c libc/uchar/meson.build libc/uchar/uchar-local.h libm/fenv/fenv.c picocrt/crt0-none.c picocrt/machine/xtensa/crt0.S picocrt/machine/xtensa/crt1.c picocrt/machine/xtensa/meson.build scripts/do-clang-x86-configure scripts/do-clang-x86_64-configure scripts/run-xtensa-dc233c scripts/validate-cdefs semihost/machine/lm32/lm32_close.c semihost/machine/lm32/lm32_exit.c semihost/machine/lm32/lm32_lseek.c semihost/machine/lm32/lm32_open.c semihost/machine/lm32/lm32_read.c semihost/machine/lm32/lm32_scall.c semihost/machine/lm32/lm32_semihost.h semihost/machine/lm32/lm32_stub.c semihost/machine/lm32/lm32_unlink.c semihost/machine/lm32/lm32_write.c semihost/machine/lm32/meson.build semihost/machine/xtensa/simcall.S semihost/machine/xtensa/simcall.c semihost/machine/xtensa/simcall.h semihost/machine/xtensa/xtensa-close.c semihost/machine/xtensa/xtensa-lseek.c semihost/machine/xtensa/xtensa-open.c semihost/machine/xtensa/xtensa-read.c semihost/machine/xtensa/xtensa-unlink.c semihost/machine/xtensa/xtensa-write.c test/test-cplusplus.cpp test/test-ctype/test-ctype.c test/test-ctype/test-encode.c test/test-ctype/test-wctype.c test/test-stdio/test-flockfile.c test/test-stdio/test-funopen.c test/test-uchar.c Copyright: 2024 Keith Packard License: BSD3-1 Files: libc/machine/aarch64/meson.build libm/machine/aarch64/meson.build Copyright: 2019 Keith Packard, 2020 Anthony Anderson License: BSD3-1 Files: libc/machine/arm/machine/math.h Copyright: 2020 Keith Packard 2017 embedded brains GmbH. 2011, 2012 ARM Ltd. License: BSD3-1 Files: libc/machine/arm/read_tp.S Copyright: 2020 Keith Packard 2024 Stephen Street License: BSD3-1 Files: libc/machine/arm/set_tls.c libc/machine/arm/tls.c Copyright: 2019 Keith Packard 2024 Stephen Street License: BSD3-1 Files: libc/machine/lm32/meson.build libc/machine/loongarch/asm.h libc/machine/loongarch/machine/fenv.h picocrt/machine/lm32/crt0.c scripts/do-lm32-unknown-elf-configure Copyright: 2024 Jiaxun Yang License: BSD3-1 Files: libc/machine/loongarch/machine/math.h semihost/machine/loongarch/semihost-loongarch.S Copyright: 2024 Jiaxun Yang License: BSD3-1 Files: libc/machine/loongarch/machine/meson.build Copyright: 2020 Keith Packard 2024 Jiaxun Yang License: BSD3-1 Files: libc/machine/loongarch/meson.build Copyright: 2019 Keith Packard 2024 Jiaxun Yang License: BSD3-1 Files: libc/machine/m68k/meson.build scripts/do-m68k-configure scripts/do-m68k-unknown-elf-configure Copyright: 2020 Thomas Daede License: BSD3-1 Files: libc/machine/microblaze/CMakeLists.txt libc/machine/microblaze/meson.build scripts/do-microblazeel-configure Copyright: 2023 Advanced Micro Devices, Inc. (AMD) 2023 Alp Sayin License: BSD3-1 Files: libc/machine/or1k/CMakeLists.txt libc/machine/or1k/meson.build Copyright: 2025 NVIDIA Corporation License: BSD3-1 Files: libc/machine/powerpc/meson.build Copyright: 2019 Ash Logan, Keith Packard License: BSD3-1 Files: libc/machine/rx/interrupt.c libc/machine/rx/meson.build picocrt/machine/rx/CMakeLists.txt picocrt/machine/rx/meson.build scripts/do-rx-zephyr-elf-configure scripts/run-rx Copyright: 2025 Renesas Electronics Corporation License: BSD3-1 Files: libc/machine/sh/meson.build Copyright: 2023 Adrian Siekierka License: BSD3-1 Files: libc/machine/x86/machine/_ssp_tls.h libc/machine/x86/machine/_tls.h libc/machine/x86/tcb-32.S libc/machine/x86/tcb-64.S libc/machine/x86/tls.c Copyright: 2025 TK Chia License: BSD3-1 Files: libc/machine/xtensa/meson.build Copyright: 2019 Jonathan McDowell License: BSD3-1 Files: libc/stdio/sprintf_s.c libc/stdio/vfprintf_s.c libc/stdio/vsnprintf_s.c libc/stdlib/ignore_handler_s.c libc/stdlib/local_s.h libc/stdlib/set_constraint_handler_s.c libc/string/memcpy_s.c libc/string/memmove_s.c libc/string/memset_s.c libc/string/strcat_s.c libc/string/strcpy_s.c libc/string/strerror_s.c libc/string/strerrorlen_s.c libc/string/string_private.h libc/string/strncat_s.c libc/string/strncpy_s.c libc/string/strnlen_s.c test/test-stdio/test-fgetc.c test/test-stdio/test-fgets-eof.c test/test-stdio/test-sprintf-s.c test/test-stdio/test-vfprintf-s.c test/test-stdio/test-vsnprintf-s.c test/test-string/test-memcpy_s.c test/test-string/test-memmove_s.c test/test-string/test-memset_s.c test/test-string/test-strcat_s.c test/test-string/test-strcpy_s.c test/test-string/test-strerror_s.c test/test-string/test-strerrorlen_s.c test/test-string/test-strncat_s.c test/test-string/test-strncpy_s.c test/test-string/test-strnlen_s.c Copyright: 2024, Synopsys Inc. License: BSD3-1 Files: libm/machine/riscv/s_copysign.c libm/machine/riscv/s_fabs.c libm/machine/riscv/s_finite.c libm/machine/riscv/s_fmax.c libm/machine/riscv/s_fmin.c libm/machine/riscv/s_fpclassify.c libm/machine/riscv/s_isinf.c libm/machine/riscv/s_isnan.c libm/machine/riscv/s_llrint.c libm/machine/riscv/s_llround.c libm/machine/riscv/s_lrint.c libm/machine/riscv/s_lround.c libm/machine/riscv/sf_copysign.c libm/machine/riscv/sf_fabs.c libm/machine/riscv/sf_finite.c libm/machine/riscv/sf_fmax.c libm/machine/riscv/sf_fmin.c libm/machine/riscv/sf_fpclassify.c libm/machine/riscv/sf_isinf.c libm/machine/riscv/sf_isnan.c libm/machine/riscv/sf_llrint.c libm/machine/riscv/sf_llround.c libm/machine/riscv/sf_lrint.c libm/machine/riscv/sf_lround.c Copyright: 2020 Kito Cheng License: BSD3-1 Files: meson.build Copyright: 2019-2021 Keith Packard License: BSD3-1 Files: picocrt/machine/loongarch/crt0.c Copyright: 2024 Jiaxun Yang < License: BSD3-1 Files: picocrt/machine/loongarch/meson.build semihost/machine/loongarch/meson.build Copyright: 2024 Jiaxun Yang 2021 Keith Packard License: BSD3-1 Files: picocrt/machine/powerpc/cstart.c picocrt/machine/riscv/crt0.c Copyright: 2020 Sebastian Meyer License: BSD3-1 Files: picocrt/machine/x86/crt0-32.S picocrt/machine/x86/crt0-64.S Copyright: 2021 Mike Haertel and Keith Packard License: BSD3-1 Files: scripts/do-coreboot-arm-eabi-configure scripts/do-coreboot-i386-elf-configure scripts/do-coreboot-riscv-elf-configure scripts/do-coreboot-x86_64-elf-configure Copyright: 2024 The ChromiumOS Authors License: BSD3-1 Files: scripts/do-freedom-tools-package Copyright: 2020 SiFive Inc. License: BSD3-1 Files: scripts/do-loongarch64-configure Copyright: 2024 Jiaxun Yang 2019 Keith Packard License: BSD3-1 Files: scripts/run-aarch64-fvp Copyright: 2024 Arm Limited and/or its affiliates License: BSD3-1 Files: scripts/run-loongarch64 Copyright: 2024 Jiaxun Yang 2020 Keith Packard License: BSD3-1 Files: semihost/machine/mips/meson.build Copyright: 2021 Keith Packard 2025 Jiaxun Yang License: BSD3-1 Files: semihost/machine/mips/mips_close.c semihost/machine/mips/mips_exit.c semihost/machine/mips/mips_fstat.c semihost/machine/mips/mips_lseek.c semihost/machine/mips/mips_open.c semihost/machine/mips/mips_read.c semihost/machine/mips/mips_semihost.h semihost/machine/mips/mips_stub.c semihost/machine/mips/mips_unlink.c semihost/machine/mips/mips_write.c Copyright: 2025 Jiaxun Yang License: BSD3-1 Files: test/test-getopt.c Copyright: 2021 Nordic Semiconductor License: BSD3-1 Files: test/test-monetary/test-strfmon.c Copyright: 2025 Keith Packard 2025 The Zephyr Project Contributors License: BSD3-1 Files: test/test-stdio/test-sprintf-percent-n.c test/test-stdio/test-vfscanf-percent-a.c test/test-stdio/test-wchar.c Copyright: 2024, Synopsys Inc. 2024, Solid Sands B.V. License: BSD3-1 Files: test/test-stdio/test-tmpnam.c Copyright: 2024 Mostafa Salmaan License: BSD3-1 Files: test/test-stdio/test-ungetc-ftell.c Copyright: 2024 Hana Ashour License: BSD3-1 Files: test/test-string/test-strncpy.c Copyright: 2025 Fredrik Gihl License: BSD3-1 Files: test/time-tests.c Copyright: 2021 R. Diez License: BSD3-1 Files: libc/ctype/ctype_.c libc/ctype/ctype_class.c libc/ctype/ctype_wide.c libc/ctype/isalnum.c libc/ctype/isalpha.c libc/ctype/isascii.c libc/ctype/iscntrl.c libc/ctype/isdigit.c libc/ctype/isgraph.c libc/ctype/islower.c libc/ctype/isprint.c libc/ctype/ispunct.c libc/ctype/isspace.c libc/ctype/isupper.c libc/ctype/isxdigit.c libc/ctype/toascii.c libc/ctype/tolower.c libc/ctype/toupper.c libc/include/pwd.h Copyright: 1989 The Regents of the University of California. License: BSD3-2 Files: libc/include/dirent.h libc/string/wcsncmp.c Copyright: 1989, 1993 The Regents of the University of California. License: BSD3-2 Files: libc/include/ndbm.h libc/include/search.h libc/search/hash_func.c libc/search/ndbm.c libc/stdlib/getsubopt.c libc/string/wcscmp.c Copyright: 1990, 1993 The Regents of the University of California. License: BSD3-2 Files: libc/include/sys/_select.h libc/include/sys/_timespec.h libc/include/sys/_types.h libc/include/sys/_wait.h libc/include/sys/config.h libc/include/sys/dirent.h libc/include/sys/errno.h libc/include/sys/fcntl.h libc/include/sys/file.h libc/include/sys/param.h libc/include/sys/resource.h libc/include/sys/select.h libc/include/sys/stat.h libc/include/sys/time.h libc/include/sys/timeb.h libc/include/sys/times.h libc/include/sys/types.h libc/include/sys/unistd.h libc/include/sys/utime.h libc/include/sys/wait.h Copyright: 1982, 1986, 1993 The Regents of the University of California. License: BSD3-2 Files: libc/include/sys/cdefs.h libc/include/sys/queue.h Copyright: 1991, 1993 The Regents of the University of California. License: BSD3-2 Files: libc/include/sys/syslimits.h libc/stdlib/atoll.c Copyright: 1988, 1993 The Regents of the University of California. License: BSD3-2 Files: libc/include/unctrl.h libc/misc/ffs.c libc/misc/misc.tex libc/misc/unctrl.c Copyright: 1981, 1993 The Regents of the University of California. License: BSD3-2 Files: libc/posix/cclass.h libc/posix/cname.h libc/posix/regex2.h libc/posix/utils.h Copyright: 1992, 1993, 1994 Henry Spencer. 1992, 1993, 1994 The Regents of the University of California. License: BSD3-2 Files: libc/search/bsearch.c libc/search/extern.h libc/search/hcreate.3 libc/search/tdelete.c libc/search/tdestroy.c libc/search/tfind.c libc/search/tsearch.c libc/search/twalk.c Copyright: 1991, 1993, 1994 The Regents of the University of California. License: BSD3-2 Files: libc/search/db_local.h libc/search/hash.c libc/search/hash.h libc/search/hash_bigkey.c libc/search/hash_buf.c libc/search/hash_log2.c libc/search/hash_page.c libc/search/page.h Copyright: 1990, 1993, 1994 The Regents of the University of California. License: BSD3-2 Files: libc/search/qsort.c Copyright: 1992, 1993 The Regents of the University of California. License: BSD3-2 Files: libc/stdlib/div.c libc/stdlib/ldiv.c Copyright: 1990 Regents of the University of California. License: BSD3-2 Files: libc/stdlib/getsubopt.3 Copyright: 1990, 1991, 1993 The Regents of the University of California. License: BSD3-2 Files: libc/string/strtok_r.c libc/string/strtok_r.h libc/string/wcstok.c Copyright: 1988 Regents of the University of California. License: BSD3-2 Files: libc/ctype/iswalnum.c libc/ctype/iswalpha.c libc/ctype/iswblank.c libc/ctype/iswcntrl.c libc/ctype/iswctype.c libc/ctype/iswdigit.c libc/ctype/iswgraph.c libc/ctype/iswlower.c libc/ctype/iswprint.c libc/ctype/iswpunct.c libc/ctype/iswspace.c libc/ctype/iswupper.c libc/ctype/iswxdigit.c libc/ctype/local.h libc/ctype/towctrans.c libc/ctype/towlower.c libc/ctype/towupper.c libc/ctype/wctrans.c libc/ctype/wctype.c Copyright: 2002 Red Hat Incorporated. License: BSD3-3 Files: libc/machine/hppa/setjmp.S Copyright: 1995, 2002 Red Hat Incorporated. License: BSD3-3 Files: libc/machine/m32c/setjmp.S Copyright: 2005 Red Hat Incorporated. License: BSD3-3 Files: libc/machine/rl78/setjmp.S Copyright: 2011 Red Hat Incorporated. License: BSD3-3 Files: libc/stdlib/environ.c Copyright: 1995, 1996, 2002 Red Hat Incorporated. License: BSD3-3 Files: libc/include/ar.h libc/include/assert.h libc/include/ctype.h libc/include/errno.h libc/include/fastmath.h libc/include/fcntl.h libc/include/ieeefp.h libc/include/locale.h libc/include/malloc.h libc/include/math.h libc/include/paths.h libc/include/regdef.h libc/include/setjmp.h libc/include/signal.h libc/include/stdlib.h libc/include/string.h libc/include/termios.h libc/include/time.h libc/include/unistd.h libc/include/utime.h libc/include/utmp.h Copyright: 1991, 1993 The Regents of the University of California. License: BSD3-4 Files: libc/include/grp.h Copyright: 1989, 1993 The Regents of the University of California. License: BSD3-4 Files: libc/include/envlock.h libc/include/fnmatch.h Copyright: 1992, 1993 The Regents of the University of California. License: BSD3-5 Files: libc/include/glob.h Copyright: 1989, 1993 The Regents of the University of California. License: BSD3-5 Files: libc/include/regex.h Copyright: 1992 Henry Spencer. 1992, 1993 The Regents of the University of California. License: BSD3-5 Files: libc/include/sys/timespec.h Copyright: 1982, 1986, 1993 The Regents of the University of California. License: BSD3-5 Files: libc/posix/engine.c libc/posix/regcomp.c libc/posix/regerror.c libc/posix/regexec.c libc/posix/regfree.c Copyright: 1992, 1993, 1994 Henry Spencer. 1992, 1993, 1994 The Regents of the University of California. License: BSD3-5 Files: libc/posix/fnmatch.c Copyright: 1989, 1993, 1994 The Regents of the University of California. License: BSD3-5 Files: libc/posix/rune.h libc/posix/runetype.h Copyright: 1993 The Regents of the University of California. License: BSD3-5 Files: libc/posix/sysexits.h Copyright: 1987, 1993 The Regents of the University of California. License: BSD3-5 Files: libc/string/strcasestr.c Copyright: 1990, 1993 The Regents of the University of California. License: BSD3-5 Files: libc/include/rpc/types.h libc/include/rpc/xdr.h libc/xdr/xdr.c libc/xdr/xdr_array.c libc/xdr/xdr_float.c libc/xdr/xdr_float_vax.c libc/xdr/xdr_mem.c libc/xdr/xdr_rec.c libc/xdr/xdr_reference.c libc/xdr/xdr_sizeof.c libc/xdr/xdr_stdio.c Copyright: 2009, Sun Microsystems, Inc. License: BSD3-6 Files: libc/include/stdio.h Copyright: 2002, 2005, 2007 Joerg Wunsch 1990, 1991, 1993 The Regents of the University of California. License: BSD3-7 Files: libc/machine/avr/macros.inc Copyright: 2002, 2005, 2006, 2007 Marek Michalkiewicz 2006 Dmitry Xmelkov License: BSD3-7 Files: libc/machine/avr/sectionname.h Copyright: 2009 Atmel Corporation License: BSD3-7 Files: libc/machine/avr/setjmp.S Copyright: 2002, Marek Michalkiewicz License: BSD3-7 Files: libc/stdio/atod_engine.c libc/stdio/atof_engine.c libc/stdio/conv_flt.c libc/stdio/scanf_private.h libc/stdio/strtoi.h libc/stdio/strtoimax.c libc/stdio/strtol.c libc/stdio/strtoll.c libc/stdio/strtoul.c libc/stdio/strtoull.c libc/stdio/strtoumax.c libc/stdio/vfscanf.c Copyright: 2002,2004,2005 Joerg Wunsch 2008 Dmitry Xmelkov License: BSD3-7 Files: libc/stdio/clearerr.c libc/stdio/fclose.c libc/stdio/feof.c libc/stdio/ferror.c libc/stdio/fgetc.c libc/stdio/stdio_private.h Copyright: 2002,2005 Joerg Wunsch License: BSD3-7 Files: libc/stdio/dtoa.h libc/stdio/dtoa_engine.c libc/stdio/sprintfd.c libc/stdio/sprintff.c libc/stdio/vffprintf.c libc/stdio/vffscanf.c libc/stdio/vfiprintf.c libc/stdio/vfiscanf.c libc/stdio/vflprintf.c libc/stdio/vflscanf.c libc/stdio/vfmprintf.c libc/stdio/vfmscanf.c libc/stdio/vfwprintf.c libc/stdio/vfwscanf.c Copyright: 2018, Keith Packard License: BSD3-7 Files: libc/stdio/fdevopen.c Copyright: 2002,2005, 2007 Joerg Wunsch License: BSD3-7 Files: libc/stdio/fgets.c libc/stdio/fgetwc.c libc/stdio/fgetws.c libc/stdio/fprintf.c libc/stdio/fputc.c libc/stdio/fputs.c libc/stdio/fputwc.c libc/stdio/fputws.c libc/stdio/fread.c libc/stdio/fscanf.c libc/stdio/fwprintf.c libc/stdio/fwrite.c libc/stdio/fwscanf.c libc/stdio/getchar.c libc/stdio/gets.c libc/stdio/getwchar.c libc/stdio/printf.c libc/stdio/putchar.c libc/stdio/puts.c libc/stdio/putwchar.c libc/stdio/scanf.c libc/stdio/snprintf.c libc/stdio/sprintf.c libc/stdio/sscanf.c libc/stdio/swscanf.c libc/stdio/ungetc.c libc/stdio/ungetwc.c libc/stdio/wprintf.c libc/stdio/wscanf.c Copyright: 2002, Joerg Wunsch License: BSD3-7 Files: libc/stdio/snprintfd.c libc/stdio/snprintff.c Copyright: 2021 Keith Packard License: BSD3-7 Files: libc/stdio/strtod.c libc/stdio/strtof.c libc/stdio/strtold.c Copyright: 2002-2005 Michael Stumpf 2006,2008 Dmitry Xmelkov License: BSD3-7 Files: libc/stdio/swprintfd.c Copyright: 2025 Keith Packard License: BSD3-7 Files: libc/stdio/ultoa_invert.c Copyright: 2017 Keith Packard License: BSD3-7 Files: libc/stdio/vfprintf.c libc/stdio/vfprintf_char.c libc/stdio/vfprintf_float.c libc/stdio/vfprintf_int.c libc/stdio/vfprintf_n.c libc/stdio/vfprintf_str.c Copyright: 2002, Alexander Popov (sasho@vip.bg) 2002,2004,2005 Joerg Wunsch 2005, Helmut Wallner 2007, Dmitry Xmelkov License: BSD3-7 Files: libc/stdio/vprintf.c libc/stdio/vscanf.c libc/stdio/vsscanf.c libc/stdio/vswscanf.c libc/stdio/vwprintf.c libc/stdio/vwscanf.c Copyright: 2005, Joerg Wunsch License: BSD3-7 Files: libc/stdio/vsnprintf.c libc/stdio/vsprintf.c Copyright: 2003, Joerg Wunsch License: BSD3-7 Files: libc/include/sys/_sigset.h Copyright: 1982, 1986, 1989, 1991, 1993 The Regents of the University of California. License: BSD3-8 Files: libc/machine/aarch64/machine/_types.h Copyright: 2012 ARM Ltd License: BSD3-9 Files: libc/machine/aarch64/setjmp.S libm/machine/aarch64/s_ceil.c libm/machine/aarch64/s_floor.c libm/machine/aarch64/s_fma.c libm/machine/aarch64/s_fmax.c libm/machine/aarch64/s_fmin.c libm/machine/aarch64/s_llrint.c libm/machine/aarch64/s_llround.c libm/machine/aarch64/s_lrint.c libm/machine/aarch64/s_lround.c libm/machine/aarch64/s_nearbyint.c libm/machine/aarch64/s_rint.c libm/machine/aarch64/s_round.c libm/machine/aarch64/s_trunc.c libm/machine/aarch64/sf_ceil.c libm/machine/aarch64/sf_floor.c libm/machine/aarch64/sf_fma.c libm/machine/aarch64/sf_fmax.c libm/machine/aarch64/sf_fmin.c libm/machine/aarch64/sf_llrint.c libm/machine/aarch64/sf_llround.c libm/machine/aarch64/sf_lrint.c libm/machine/aarch64/sf_lround.c libm/machine/aarch64/sf_nearbyint.c libm/machine/aarch64/sf_rint.c libm/machine/aarch64/sf_round.c libm/machine/aarch64/sf_trunc.c libm/machine/arm/s_ceil.c libm/machine/arm/s_floor.c libm/machine/arm/s_nearbyint.c libm/machine/arm/s_rint.c libm/machine/arm/s_round.c libm/machine/arm/s_trunc.c libm/machine/arm/sf_ceil.c libm/machine/arm/sf_floor.c libm/machine/arm/sf_nearbyint.c libm/machine/arm/sf_rint.c libm/machine/arm/sf_round.c libm/machine/arm/sf_trunc.c Copyright: 2011, 2012 ARM Ltd License: BSD3-9 Files: libc/machine/arm/aeabi_memset.c libc/machine/arm/bzero.c libc/machine/arm/machine/_endian.h libc/machine/arm/memset-arm.S libc/machine/arm/memset-thumb.S libc/machine/arm/memset-thumb2.S libc/machine/arm/memset.S libc/machine/arm/memset.c libm/machine/aarch64/s_fabs.c libm/machine/aarch64/s_sqrt.c libm/machine/aarch64/sf_fabs.c libm/machine/aarch64/sf_sqrt.c Copyright: 2015 ARM Ltd License: BSD3-9 Files: libc/machine/arm/arm_asm.h Copyright: 2009 ARM Ltd License: BSD3-9 Files: libc/machine/arm/machine/acle-compat.h libc/machine/arm/strcmp-armv6m.S Copyright: 2014 ARM Ltd License: BSD3-9 Files: libc/machine/arm/memcpy-armv7m.S Copyright: 2013 ARM Ltd License: BSD3-9 Files: libc/machine/arm/memcpy.S Copyright: 2013-2015 ARM Ltd License: BSD3-9 Files: libc/machine/arm/strcmp-arm-tiny.S libc/machine/arm/strcmp-armv4.S libc/machine/arm/strcmp-armv4t.S libc/machine/arm/strcmp-armv6.S libc/machine/arm/strcmp-armv7.S libc/machine/arm/strcmp-armv7m.S libc/machine/arm/strcmp.S Copyright: 2012-2014 ARM Ltd License: BSD3-9 Files: libc/machine/arm/strcpy.S Copyright: 2008 ARM Ltd License: BSD3-9 Files: libc/machine/arm/strlen.c Copyright: 2008-2015 ARM Ltd License: BSD3-9 Files: libc/stdlib/calloc.c libc/stdlib/free.c libc/stdlib/getpagesize.c libc/stdlib/local-malloc.h libc/stdlib/mallinfo.c libc/stdlib/malloc-stats.c libc/stdlib/malloc-usable-size.c libc/stdlib/malloc.c libc/stdlib/mallopt.c libc/stdlib/memalign.c libc/stdlib/posix-memalign.c libc/stdlib/pvalloc.c libc/stdlib/realloc.c libc/stdlib/valloc.c Copyright: 2012, 2013 ARM Ltd License: BSD3-9 Files: test/testsuite/newlib.string/memcpy-1.c test/testsuite/newlib.string/strcmp-1.c Copyright: 2011 ARM Ltd License: BSD3-9 Files: libc/machine/aarch64/memchr-stub.c libc/machine/aarch64/memcmp-stub.c libc/machine/aarch64/memmove-stub.c libc/machine/aarch64/strlen-stub.c libc/machine/aarch64/strncmp-stub.c libc/machine/aarch64/strnlen-stub.c libc/machine/aarch64/strnlen.S Copyright: 2013, Linaro Limited License: BSD3-10 Files: libc/machine/aarch64/memcpy-stub.c libc/machine/aarch64/memset-stub.c libc/machine/aarch64/strcmp-stub.c Copyright: 2012-2013, Linaro Limited License: BSD3-10 Files: libc/machine/aarch64/strlen.S Copyright: 2013-2015, Linaro Limited License: BSD3-10 Files: libc/machine/aarch64/strncmp.S Copyright: 2013, 2018, Linaro Limited License: BSD3-10 Files: libc/machine/arm/memchr.c libc/machine/arm/memcpy.c libc/machine/arm/strlen-thumb1-Os.S libc/machine/arm/strlen-thumb2-Os.S libc/machine/arm/strlen.S Copyright: 2015 ARM Ltd. License: BSD3-10 Files: libc/machine/aarch64/rawmemchr-stub.c libc/machine/aarch64/rawmemchr.S Copyright: 2015-2016, ARM Limited License: BSD3-11 Files: libc/machine/aarch64/stpcpy-stub.c Copyright: 2015, ARM Limited License: BSD3-11 Files: libc/machine/aarch64/strchr-stub.c libc/machine/aarch64/strchrnul-stub.c libc/machine/aarch64/strcpy-stub.c libc/machine/aarch64/strrchr-stub.c libc/machine/aarch64/strrchr.S Copyright: 2014, ARM Limited License: BSD3-11 Files: libc/machine/aarch64/strchr.S libc/machine/aarch64/strchrnul.S Copyright: 2014-2022, ARM Limited License: BSD3-11 Files: libc/machine/aarch64/strcpy.S Copyright: 2013, 2014, 2015, 2020-2023 ARM Ltd. License: BSD3-11 Files: libc/machine/arc/asm.h libc/machine/arc/strchr.S Copyright: 2015, Synopsys, Inc. License: BSD3-12 Files: libc/machine/arc/memcmp-bs-norm.S libc/machine/arc/memcmp-stub.c libc/machine/arc/memcmp.S libc/machine/arc/memcpy-archs.S libc/machine/arc/memcpy-bs.S libc/machine/arc/memcpy-stub.c libc/machine/arc/memcpy.S libc/machine/arc/memset-archs.S libc/machine/arc/memset-bs.S libc/machine/arc/memset-stub.c libc/machine/arc/memset.S libc/machine/arc/setjmp.S libc/machine/arc/strchr-bs-norm.S libc/machine/arc/strchr-bs.S libc/machine/arc/strchr-stub.c libc/machine/arc/strcmp-archs.S libc/machine/arc/strcmp-stub.c libc/machine/arc/strcmp.S libc/machine/arc/strcpy-bs-arc600.S libc/machine/arc/strcpy-bs.S libc/machine/arc/strcpy-stub.c libc/machine/arc/strcpy.S libc/machine/arc/strncpy-bs.S libc/machine/arc/strncpy-stub.c libc/machine/arc/strncpy.S Copyright: 2015-2024, Synopsys, Inc. License: BSD3-12 Files: libc/machine/arc64/memchr.S libc/machine/arc64/memcmp-stub.c libc/machine/arc64/memcmp.S libc/machine/arc64/memcpy-stub.c libc/machine/arc64/memcpy.S libc/machine/arc64/memmove.S libc/machine/arc64/memset-stub.c libc/machine/arc64/memset.S libc/machine/arc64/setjmp.S libc/machine/arc64/strcat.S libc/machine/arc64/strcmp.S libc/machine/arc64/strlen.S libc/machine/arc64/sys/asm.h Copyright: 2024, Synopsys, Inc. License: BSD3-12 Files: libc/machine/arm/memchr.S Copyright: 2010-2011, Linaro Limited License: BSD3-13 Files: libc/machine/arm/memcpy-armv7a.S Copyright: 2013, Linaro Limited License: BSD3-13 Files: libc/machine/arm/strlen-armv7.S Copyright: 2010-2011,2013 Linaro Limited License: BSD3-13 Files: libc/machine/epiphany/setjmp.S Copyright: 2011, Adapteva, Inc. License: BSD3-14 Files: libc/machine/loongarch/machine/fenv-fp.h Copyright: 2017 Michael R. Neilly 2024 Jiaxun Yang License: BSD3-15 Files: libc/machine/riscv/machine/fenv-fp.h Copyright: 2017 Michael R. Neilly License: BSD3-15 Files: libc/machine/microblaze/abort.c libc/machine/microblaze/longjmp.S libc/machine/microblaze/setjmp.S Copyright: 2001, 2009 Xilinx, Inc. License: BSD3-16 Files: libc/machine/microblaze/strcmp.c libc/machine/microblaze/strcpy.c libc/machine/microblaze/strlen.c Copyright: 2009 Xilinx, Inc. License: BSD3-16 Files: libc/machine/mips/machine/asm.h libc/machine/mips/machine/regdef.h Copyright: 1996-2007 MIPS Technologies, Inc. 2009 CodeSourcery, LLC. License: BSD3-17 Files: libc/machine/mips/memcpy.S Copyright: 2012-2015 MIPS Technologies, Inc., California. License: BSD3-18 Files: libc/machine/mips/memset.S Copyright: 2013 MIPS Technologies, Inc., California. License: BSD3-18 Files: libc/machine/mips/strcmp.S Copyright: 2014 Imagination Technologies Limited. License: BSD3-19 Files: libc/machine/nds32/abort.c libc/machine/nds32/memcpy.S libc/machine/nds32/memset.S libc/machine/nds32/setjmp.S libc/machine/nds32/strcmp.S libc/machine/nds32/strcpy.S Copyright: 2013 Andes Technology Corporation. License: BSD3-20 Files: libm/machine/nds32/w_sqrt.S libm/machine/nds32/wf_sqrt.S Copyright: 2013-2014 Andes Technology Corporation. License: BSD3-20 Files: libc/machine/nios2/setjmp.s Copyright: 2003 Altera Corporation License: BSD3-21 Files: libc/machine/sparc/setjmp.S Copyright: 1992, 1993 The Regents of the University of California. License: BSD3-22 Files: libc/machine/spu/c99ppe.h libc/machine/spu/clearerr.c libc/machine/spu/fclose.c libc/machine/spu/feof.c libc/machine/spu/ferror.c libc/machine/spu/fflush.c libc/machine/spu/fgetc.c libc/machine/spu/fgetpos.c libc/machine/spu/fgets.c libc/machine/spu/fileno.c libc/machine/spu/fopen.c libc/machine/spu/fputc.c libc/machine/spu/fputs.c libc/machine/spu/fread.c libc/machine/spu/freopen.c libc/machine/spu/fseek.c libc/machine/spu/fsetpos.c libc/machine/spu/ftell.c libc/machine/spu/fwrite.c libc/machine/spu/getc.c libc/machine/spu/getchar.c libc/machine/spu/gets.c libc/machine/spu/perror.c libc/machine/spu/putc.c libc/machine/spu/putchar.c libc/machine/spu/puts.c libc/machine/spu/remove.c libc/machine/spu/rename.c libc/machine/spu/rewind.c libc/machine/spu/setbuf.c libc/machine/spu/setvbuf.c libc/machine/spu/sys/custom_file.h libc/machine/spu/tmpfile.c libc/machine/spu/tmpnam.c libc/machine/spu/ungetc.c libc/machine/spu/vfprintf.c libc/machine/spu/vfscanf.c libc/machine/spu/vprintf.c libc/machine/spu/vscanf.c libc/machine/spu/vsnprintf.c libc/machine/spu/vsprintf.c libc/machine/spu/vsscanf.c Copyright: IBM Corp. 2006 License: BSD3-23 Files: libc/machine/spu/calloc_ea.c libc/machine/spu/ea_internal.h libc/machine/spu/free_ea.c libc/machine/spu/include/ea.h libc/machine/spu/malloc_ea.c libc/machine/spu/memchr_ea.c libc/machine/spu/memcmp_ea.c libc/machine/spu/memcpy_ea.c libc/machine/spu/memmove_ea.c libc/machine/spu/memset_ea.c libc/machine/spu/mmap_ea.c libc/machine/spu/mremap_ea.c libc/machine/spu/msync_ea.c libc/machine/spu/munmap_ea.c libc/machine/spu/posix_memalign_ea.c libc/machine/spu/realloc_ea.c libc/machine/spu/strcat_ea.c libc/machine/spu/strchr_ea.c libc/machine/spu/strcmp_ea.c libc/machine/spu/strcpy_ea.c libc/machine/spu/strcspn_ea.c libc/machine/spu/strlen_ea.c libc/machine/spu/strncat_ea.c libc/machine/spu/strncmp_ea.c libc/machine/spu/strncpy_ea.c libc/machine/spu/strpbrk_ea.c libc/machine/spu/strrchr_ea.c libc/machine/spu/strspn_ea.c libc/machine/spu/strstr_ea.c Copyright: IBM Corp. 2007, 2008 License: BSD3-23 Files: libc/machine/spu/fdopen.c libm/common/copysignl.c libm/common/fabsl.c libm/common/frexpl.c libm/common/nanl.c libm/common/scalbnl.c libm/ld/s_isinfl.c libm/ld/s_signbitl.c Copyright: IBM Corp. 2009 License: BSD3-23 Files: libc/machine/spu/include/spu_timer.h libc/machine/spu/pread_ea.c libc/machine/spu/pwrite_ea.c libc/machine/spu/read_ea.c libc/machine/spu/readv_ea.c libc/machine/spu/spu-gmon.c libc/machine/spu/spu-mcount.S libc/machine/spu/spu_clock_stop.c libc/machine/spu/spu_clock_svcs.c libc/machine/spu/spu_timebase.c libc/machine/spu/spu_timer_flih.S libc/machine/spu/spu_timer_free.c libc/machine/spu/spu_timer_internal.h libc/machine/spu/spu_timer_slih.c libc/machine/spu/spu_timer_slih_reg.c libc/machine/spu/spu_timer_stop.c libc/machine/spu/spu_timer_svcs.c libc/machine/spu/sys/linux_syscalls.h libc/machine/spu/write_ea.c libc/machine/spu/writev_ea.c Copyright: IBM Corp. 2008 License: BSD3-23 Files: libc/machine/spu/setjmp.S Copyright: IBM Corp. 2005, 2006 License: BSD3-23 Files: libc/machine/spu/sys/mman.h Copyright: IBM Corp. 2007 License: BSD3-23 Files: libc/machine/spu/fiprintf.S libc/machine/spu/fiscanf.S libc/machine/spu/fprintf.S libc/machine/spu/fscanf.S libc/machine/spu/iprintf.S libc/machine/spu/iscanf.S libc/machine/spu/printf.S libc/machine/spu/scanf.S libc/machine/spu/siprintf.S libc/machine/spu/siscanf.S libc/machine/spu/sniprintf.S libc/machine/spu/snprintf.S libc/machine/spu/sprintf.S libc/machine/spu/sscanf.S libc/machine/spu/stack_reg_va.S Copyright: 2007, Toshiba Corporation License: BSD3-24 Files: libc/machine/spu/mk_syscalls libc/machine/spu/syscall.def Copyright: 2007 TOSHIBA CORPORATION License: BSD3-24 Files: libc/machine/spu/include/fenv.h libc/machine/spu/machine/fenv.h Copyright: 2006, 2007 International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, License: BSD3-25 Files: libc/machine/spu/machine/_types.h libc/machine/spu/sys/dirent.h libm/machine/spu/headers/dom_chkd_less_than.h libm/machine/spu/headers/dom_chkd_negone_one.h libm/machine/spu/headers/dom_chkf_less_than.h libm/machine/spu/headers/dom_chkf_negone_one.h libm/machine/spu/sf_finite.c libm/machine/spu/sf_isinf.c libm/machine/spu/sf_isinff.c libm/machine/spu/sf_isnan.c libm/machine/spu/sf_isnanf.c libm/machine/spu/sf_nan.c Copyright: 2007 International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, License: BSD3-25 Files: libc/machine/spu/memcmp.c libc/machine/spu/straddr.h libc/machine/spu/strcat.c libc/machine/spu/strcpy.c libc/machine/spu/strcpy.h libc/machine/spu/strncat.c libc/machine/spu/strncpy.c Copyright: 2008 International Business Machines Corporation License: BSD3-25 Files: libc/machine/spu/memcpy.c libc/machine/spu/memmove.c libc/machine/spu/memset.c libc/machine/spu/strchr.c libc/machine/spu/strcmp.c libc/machine/spu/strcspn.c libc/machine/spu/strlen.c libc/machine/spu/strncmp.c libc/machine/spu/strpbrk.c libc/machine/spu/strrchr.c libc/machine/spu/strspn.c libc/machine/spu/strxfrm.c libc/machine/spu/vec_literal.h libm/machine/spu/headers/atanf.h libm/machine/spu/headers/cbrt.h libm/machine/spu/headers/cbrtf.h libm/machine/spu/headers/ceil.h libm/machine/spu/headers/ceilf.h libm/machine/spu/headers/copysign.h libm/machine/spu/headers/copysignf.h libm/machine/spu/headers/exp2f.h libm/machine/spu/headers/expf.h libm/machine/spu/headers/fabs.h libm/machine/spu/headers/fabsf.h libm/machine/spu/headers/fdim.h libm/machine/spu/headers/fdimf.h libm/machine/spu/headers/feclearexcept.h libm/machine/spu/headers/fefpscr.h libm/machine/spu/headers/fegetenv.h libm/machine/spu/headers/fegetexceptflag.h libm/machine/spu/headers/fegetround.h libm/machine/spu/headers/feholdexcept.h libm/machine/spu/headers/feraiseexcept.h libm/machine/spu/headers/fesetenv.h libm/machine/spu/headers/fesetexceptflag.h libm/machine/spu/headers/fesetround.h libm/machine/spu/headers/fetestexcept.h libm/machine/spu/headers/feupdateenv.h libm/machine/spu/headers/floor.h libm/machine/spu/headers/floorf.h libm/machine/spu/headers/fma.h libm/machine/spu/headers/fmaf.h libm/machine/spu/headers/fmax.h libm/machine/spu/headers/fmaxf.h libm/machine/spu/headers/fmin.h libm/machine/spu/headers/fminf.h libm/machine/spu/headers/fmod.h libm/machine/spu/headers/fmodf.h libm/machine/spu/headers/frexp.h libm/machine/spu/headers/frexpf.h libm/machine/spu/headers/ilogb.h libm/machine/spu/headers/ilogbf.h libm/machine/spu/headers/ldexp.h libm/machine/spu/headers/ldexpf.h libm/machine/spu/headers/llrint.h libm/machine/spu/headers/llrintf.h libm/machine/spu/headers/llround.h libm/machine/spu/headers/llroundf.h libm/machine/spu/headers/log10f.h libm/machine/spu/headers/log2f.h libm/machine/spu/headers/logf.h libm/machine/spu/headers/lrint.h libm/machine/spu/headers/lrintf.h libm/machine/spu/headers/lround.h libm/machine/spu/headers/lroundf.h libm/machine/spu/headers/nearbyint.h libm/machine/spu/headers/remainder.h libm/machine/spu/headers/remainderf.h libm/machine/spu/headers/remquo.h libm/machine/spu/headers/remquof.h libm/machine/spu/headers/rint.h libm/machine/spu/headers/round.h libm/machine/spu/headers/roundf.h libm/machine/spu/headers/scalbn.h libm/machine/spu/headers/scalbnf.h libm/machine/spu/headers/sqrt.h libm/machine/spu/headers/trunc.h libm/machine/spu/headers/truncf.h libm/machine/spu/headers/vec_literal.h libm/machine/spu/llrint.c libm/machine/spu/llrintf.c libm/machine/spu/llround.c libm/machine/spu/llroundf.c libm/machine/spu/log2f.c libm/machine/spu/s_cbrt.c libm/machine/spu/s_ceil.c libm/machine/spu/s_copysign.c libm/machine/spu/s_fabs.c libm/machine/spu/s_fdim.c libm/machine/spu/s_floor.c libm/machine/spu/s_fma.c libm/machine/spu/s_fmax.c libm/machine/spu/s_fmin.c libm/machine/spu/s_frexp.c libm/machine/spu/s_ilogb.c libm/machine/spu/s_ldexp.c libm/machine/spu/s_lrint.c libm/machine/spu/s_lround.c libm/machine/spu/s_nearbyint.c libm/machine/spu/s_remquo.c libm/machine/spu/s_rint.c libm/machine/spu/s_round.c libm/machine/spu/s_scalbn.c libm/machine/spu/s_trunc.c libm/machine/spu/sf_atan.c libm/machine/spu/sf_cbrt.c libm/machine/spu/sf_ceil.c libm/machine/spu/sf_copysign.c libm/machine/spu/sf_fabs.c libm/machine/spu/sf_fdim.c libm/machine/spu/sf_floor.c libm/machine/spu/sf_fma.c libm/machine/spu/sf_fmax.c libm/machine/spu/sf_fmin.c libm/machine/spu/sf_frexp.c libm/machine/spu/sf_ilogb.c libm/machine/spu/sf_ldexp.c libm/machine/spu/sf_lrint.c libm/machine/spu/sf_lround.c libm/machine/spu/sf_remquo.c libm/machine/spu/sf_round.c libm/machine/spu/sf_scalbn.c libm/machine/spu/sf_trunc.c libm/machine/spu/w_fmod.c libm/machine/spu/w_remainder.c libm/machine/spu/w_sqrt.c libm/machine/spu/wf_exp.c libm/machine/spu/wf_exp2.c libm/machine/spu/wf_fmod.c libm/machine/spu/wf_log.c libm/machine/spu/wf_log10.c libm/machine/spu/wf_remainder.c Copyright: 2001,2006, International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, License: BSD3-25 Files: libc/machine/spu/stdio.c Copyright: 2007 Sony Computer Entertainment Inc. 2007 Sony Corp. License: BSD3-25 Files: libc/machine/spu/strncmp.h Copyright: 2001,2006,2008 International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, License: BSD3-25 Files: libc/machine/tic6x/setjmp.S Copyright: 1996-2010 Texas Instruments Incorporated http://www.ti.com License: BSD3-26 Files: libc/machine/visium/memcpy.c libc/machine/visium/memcpy.h libc/machine/visium/memmove.c libc/machine/visium/memset.c libc/machine/visium/memset.h libc/machine/visium/setjmp.S Copyright: 2015 Rolls-Royce Controls and Data Services Limited. License: BSD3-27 Files: libc/search/hcreate.c libc/search/hcreate_r.c test/testsuite/newlib.search/hsearchtest.c Copyright: 2001 Christopher G. Demetriou License: BSD3-28 Files: libc/search/tsearch.3 Copyright: 1997 Todd C. Miller License: BSD3-29 Files: libc/stdio/ftoa_engine.c Copyright: 2005, Dmitry Xmelkov License: BSD3-30 Files: libc/stdlib/aligned_alloc.c Copyright: 2020 Arm Ltd. License: BSD3-31 Files: libc/string/memmem.c libc/string/strstr.c libm/common/cosf.c libm/common/exp.c libm/common/exp2.c libm/common/exp_data.c libm/common/log.c libm/common/log2.c libm/common/log2_data.c libm/common/log_data.c libm/common/math_denorm.c libm/common/math_denormf.c libm/common/math_denorml.c libm/common/math_err_check_oflow.c libm/common/math_err_check_uflow.c libm/common/math_err_divzero.c libm/common/math_err_invalid.c libm/common/math_err_may_uflow.c libm/common/math_err_oflow.c libm/common/math_err_uflow.c libm/common/math_err_with_errno.c libm/common/math_errf_check_oflowf.c libm/common/math_errf_check_uflowf.c libm/common/pow.c libm/common/pow_log_data.c libm/common/sincosf.c libm/common/sincosf.h libm/common/sincosf_data.c libm/common/sinf.c libm/ld/math_errl_check_oflowl.c libm/ld/math_errl_check_uflowl.c libm/ld/math_errl_divzerol.c libm/ld/math_errl_invalidl.c libm/ld/math_errl_oflowl.c libm/ld/math_errl_uflowl.c libm/ld/math_errl_with_errnol.c Copyright: 2018 Arm Ltd. License: BSD3-31 Files: libm/common/math_config.h libm/common/math_errf_divzerof.c libm/common/math_errf_invalidf.c libm/common/math_errf_may_uflowf.c libm/common/math_errf_oflowf.c libm/common/math_errf_uflowf.c libm/common/math_errf_with_errnof.c libm/common/sf_pow.c Copyright: 2017-2018 Arm Ltd. License: BSD3-31 Files: libm/common/sf_exp.c libm/common/sf_exp2.c libm/common/sf_exp2_data.c libm/common/sf_log.c libm/common/sf_log2.c libm/common/sf_log2_data.c libm/common/sf_log_data.c libm/common/sf_pow_log2_data.c Copyright: 2017 Arm Ltd. License: BSD3-31 Files: libc/time/strptime.c libc/time/strptime_l.c Copyright: 1999 Kungliga Tekniska Högskolan Royal Institute of Technology, Stockholm, Sweden). License: BSD3-32 Files: libm/common/nexttoward.c libm/common/nexttowardl.c Copyright: 2014 Mentor Graphics, Inc. License: BSD3-33 Files: libm/ld/common/s_fabsl.c Copyright: 2003 Dag-Erling Coïdan Smørgrav License: BSD3-34 Files: libm/machine/spu/headers/acos.h libm/machine/spu/headers/acosd2.h libm/machine/spu/headers/acosf.h libm/machine/spu/headers/acosh.h libm/machine/spu/headers/acoshf.h libm/machine/spu/headers/asin.h libm/machine/spu/headers/asind2.h libm/machine/spu/headers/asinf.h libm/machine/spu/headers/asinh.h libm/machine/spu/headers/asinhf.h libm/machine/spu/headers/atan.h libm/machine/spu/headers/atan2.h libm/machine/spu/headers/atan2f.h libm/machine/spu/headers/atanh.h libm/machine/spu/headers/atanhf.h libm/machine/spu/headers/cos.h libm/machine/spu/headers/cosf.h libm/machine/spu/headers/cosh.h libm/machine/spu/headers/coshd2.h libm/machine/spu/headers/coshf.h libm/machine/spu/headers/coshf4.h libm/machine/spu/headers/erf.h libm/machine/spu/headers/erfc.h libm/machine/spu/headers/erfcf.h libm/machine/spu/headers/erff.h libm/machine/spu/headers/exp.h libm/machine/spu/headers/exp2.h libm/machine/spu/headers/expm1.h libm/machine/spu/headers/expm1f.h libm/machine/spu/headers/hypot.h libm/machine/spu/headers/hypotd2.h libm/machine/spu/headers/hypotf.h libm/machine/spu/headers/isnan.h libm/machine/spu/headers/isnand2.h libm/machine/spu/headers/isnanf.h libm/machine/spu/headers/isnanf4.h libm/machine/spu/headers/lgamma.h libm/machine/spu/headers/lgammaf.h libm/machine/spu/headers/log.h libm/machine/spu/headers/log10.h libm/machine/spu/headers/log1p.h libm/machine/spu/headers/log1pf.h libm/machine/spu/headers/log2.h libm/machine/spu/headers/logbf.h libm/machine/spu/headers/logbf4.h libm/machine/spu/headers/nearbyintf.h libm/machine/spu/headers/nextafter.h libm/machine/spu/headers/nextafterf.h libm/machine/spu/headers/pow.h libm/machine/spu/headers/powf.h libm/machine/spu/headers/rintf.h libm/machine/spu/headers/signbit.h libm/machine/spu/headers/signbitd2.h libm/machine/spu/headers/simdmath.h libm/machine/spu/headers/sin.h libm/machine/spu/headers/sincos.h libm/machine/spu/headers/sincosf.h libm/machine/spu/headers/sinf.h libm/machine/spu/headers/sinh.h libm/machine/spu/headers/sinhd2.h libm/machine/spu/headers/sinhf.h libm/machine/spu/headers/sinhf4.h libm/machine/spu/headers/sqrtf.h libm/machine/spu/headers/tan.h libm/machine/spu/headers/tanf.h libm/machine/spu/headers/tanh.h libm/machine/spu/headers/tanhf.h libm/machine/spu/headers/tgamma.h libm/machine/spu/headers/tgammaf.h libm/machine/spu/log2.c libm/machine/spu/s_asinh.c libm/machine/spu/s_atan.c libm/machine/spu/s_cos.c libm/machine/spu/s_erf.c libm/machine/spu/s_expm1.c libm/machine/spu/s_isnan.c libm/machine/spu/s_log1p.c libm/machine/spu/s_nextafter.c libm/machine/spu/s_sin.c libm/machine/spu/s_tan.c libm/machine/spu/s_tanh.c libm/machine/spu/sf_asinh.c libm/machine/spu/sf_cos.c libm/machine/spu/sf_erf.c libm/machine/spu/sf_expm1.c libm/machine/spu/sf_log1p.c libm/machine/spu/sf_logb.c libm/machine/spu/sf_nearbyint.c libm/machine/spu/sf_nextafter.c libm/machine/spu/sf_rint.c libm/machine/spu/sf_sin.c libm/machine/spu/sf_tan.c libm/machine/spu/sf_tanh.c libm/machine/spu/w_acos.c libm/machine/spu/w_acosh.c libm/machine/spu/w_asin.c libm/machine/spu/w_atan2.c libm/machine/spu/w_atanh.c libm/machine/spu/w_cosh.c libm/machine/spu/w_exp.c libm/machine/spu/w_exp2.c libm/machine/spu/w_hypot.c libm/machine/spu/w_lgamma.c libm/machine/spu/w_log.c libm/machine/spu/w_log10.c libm/machine/spu/w_pow.c libm/machine/spu/w_sincos.c libm/machine/spu/w_sinh.c libm/machine/spu/w_tgamma.c libm/machine/spu/wf_acos.c libm/machine/spu/wf_acosh.c libm/machine/spu/wf_asin.c libm/machine/spu/wf_atan2.c libm/machine/spu/wf_atanh.c libm/machine/spu/wf_cosh.c libm/machine/spu/wf_hypot.c libm/machine/spu/wf_lgamma.c libm/machine/spu/wf_pow.c libm/machine/spu/wf_sincos.c libm/machine/spu/wf_sinh.c libm/machine/spu/wf_sqrt.c libm/machine/spu/wf_tgamma.c Copyright: 2006,2008, International Business Machines Corporation License: BSD3-35 Files: libm/machine/spu/headers/acosf4.h libm/machine/spu/headers/asinf4.h libm/machine/spu/headers/atanf4.h libm/machine/spu/headers/cos_sin.h libm/machine/spu/headers/cosd2.h libm/machine/spu/headers/cosf4.h libm/machine/spu/headers/divd2.h libm/machine/spu/headers/divf4.h libm/machine/spu/headers/exp2d2.h libm/machine/spu/headers/exp2f4.h libm/machine/spu/headers/expd2.h libm/machine/spu/headers/expf4.h libm/machine/spu/headers/floord2.h libm/machine/spu/headers/floorf4.h libm/machine/spu/headers/ldexpd2.h libm/machine/spu/headers/ldexpf4.h libm/machine/spu/headers/log10d2.h libm/machine/spu/headers/log2d2.h libm/machine/spu/headers/log2f4.h libm/machine/spu/headers/logd2.h libm/machine/spu/headers/logf4.h libm/machine/spu/headers/powd2.h libm/machine/spu/headers/powf4.h libm/machine/spu/headers/recipd2.h libm/machine/spu/headers/recipf4.h libm/machine/spu/headers/sind2.h libm/machine/spu/headers/sinf4.h libm/machine/spu/headers/sqrtd2.h libm/machine/spu/headers/sqrtf4.h libm/machine/spu/headers/tand2.h libm/machine/spu/headers/tanf4.h libm/machine/spu/headers/truncd2.h libm/machine/spu/headers/truncf4.h Copyright: 2001,2008, International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, License: BSD3-35 Files: libm/machine/spu/headers/acoshd2.h libm/machine/spu/headers/acoshf4.h libm/machine/spu/headers/asinhd2.h libm/machine/spu/headers/asinhf4.h libm/machine/spu/headers/atan2d2.h libm/machine/spu/headers/atan2f4.h libm/machine/spu/headers/atand2.h libm/machine/spu/headers/atanhd2.h libm/machine/spu/headers/atanhf4.h libm/machine/spu/headers/erf_utils.h libm/machine/spu/headers/erfcd2.h libm/machine/spu/headers/erfcf4.h libm/machine/spu/headers/erfd2.h libm/machine/spu/headers/erff4.h libm/machine/spu/headers/expm1d2.h libm/machine/spu/headers/expm1f4.h libm/machine/spu/headers/hypotf4.h libm/machine/spu/headers/lgammad2.h libm/machine/spu/headers/lgammaf4.h libm/machine/spu/headers/log1pd2.h libm/machine/spu/headers/log1pf4.h libm/machine/spu/headers/nextafterd2.h libm/machine/spu/headers/nextafterf4.h libm/machine/spu/headers/sincosd2.h libm/machine/spu/headers/sincosf4.h libm/machine/spu/headers/tanhd2.h libm/machine/spu/headers/tanhf4.h libm/machine/spu/headers/tgammad2.h libm/machine/spu/headers/tgammaf4.h Copyright: 2007,2008, International Business Machines Corporation License: BSD3-35 Files: libm/machine/spu/headers/nearbyintf4.h libm/machine/spu/headers/rintf4.h libm/machine/spu/headers/scalbnf4.h Copyright: 2006,2008, International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, License: BSD3-35 Files: .clang-format .editorconfig .gitattributes .github/Dockerfile .github/Dockerfile-check-format .github/Dockerfile-coreboot .github/Dockerfile-zephyr .github/do-build .github/do-cmake-test .github/do-linux-misc .github/do-many .github/do-run .github/do-test .github/do-test-noopt .github/do-zephyr .github/linux-files.txt .github/linux-packages.txt .github/workflows/Makefile .github/workflows/check-format.yml .github/workflows/head .github/workflows/head-coreboot .github/workflows/head-native .github/workflows/head-zephyr .github/workflows/linux.yml .github/workflows/make-workflow .github/workflows/make-workflow-coreboot .github/workflows/make-workflow-native .github/workflows/make-workflow-zephyr .github/workflows/native.yml .github/workflows/steps-head .github/workflows/variants .github/workflows/zephyr.yml .github/zephyr .github/zephyr-files.txt .github/zephyr-packages.txt .gitignore README.md cmake/TC-clang-thumbv6m.cmake cmake/TC-clang-thumbv7m.cmake cmake/TC-rx.cmake cmake/TC-thumbv6m.cmake cmake/TC-thumbv7m.cmake cmake/have-bitfields-in-packed-structs.c cmake/have-cc-inhibit-loop-to-libcall.c doc/build.md doc/ctype.md doc/embedsource.md doc/init.md doc/linking.md doc/locking.md doc/os.md doc/picolibc.svg doc/printf.md doc/releasing.md doc/testing.md doc/tls.md doc/using.md hello-world/README.md libc/ctype/ctype.tex libc/include/sys/_tz_structs.h libc/libc.in.xml libc/machine/aarch64/sys/fcntl.h libc/machine/hexagon/longjmp.S libc/machine/hexagon/meson.build libc/machine/hexagon/setjmp.S libc/machine/hexagon/tls.c libc/machine/necv70/necv70.tex libc/machine/nvptx/clock.c libc/machine/riscv/xlenint.h libc/machine/xtensa/xtensa.tex libc/ssp/ssp.tex libc/stdlib/mul_overflow.h libc/string/wcstrings.tex libc/time/strftime.c libc/time/tzset.c libc/xdr/README libm/complex/CMakeLists.txt libm/complex/complex.tex libm/fenv/fenv.tex libm/ld/files libm/libm.in.xml picocrt/machine/aarch64/crt0.S picocrt/machine/hexagon/crt0.S picocrt/machine/hexagon/crt0.c picocrt/machine/hexagon/meson.build picolibc-native.specs.in picolibc.h.in picolibc.ld.in picolibc.specs.in scripts/checkpatch scripts/cross-aarch64-linux-gnu.txt scripts/cross-aarch64-none-elf.txt scripts/cross-aarch64-zephyr-elf.txt scripts/cross-arc-zephyr-elf.txt scripts/cross-arc64-zephyr-elf.txt scripts/cross-arm-none-eabi.txt scripts/cross-arm-zephyr-eabi.txt scripts/cross-avr.txt scripts/cross-clang-aarch64-none-elf.txt scripts/cross-clang-arm-none-eabi.txt scripts/cross-clang-cortex-r82.txt scripts/cross-clang-hexagon.txt scripts/cross-clang-msp430.txt scripts/cross-clang-riscv64-unknown-elf.txt scripts/cross-clang-riscv64-zephyr-elf.txt scripts/cross-clang-rv32imafc.txt scripts/cross-clang-rv32imafdc-unknown-elf.txt scripts/cross-clang-thumb-none-eabi.txt scripts/cross-clang-thumbv6m-none-eabi.txt scripts/cross-clang-thumbv7-a-none-eabi.txt scripts/cross-clang-thumbv7e+dp-none-eabi.txt scripts/cross-clang-thumbv7e+fp-none-eabi.txt scripts/cross-clang-thumbv7m-none-eabi.txt scripts/cross-clang-x86.txt scripts/cross-clang-x86_64.txt scripts/cross-coreboot-arm-eabi.txt scripts/cross-coreboot-i386-elf.txt scripts/cross-coreboot-riscv-elf.txt scripts/cross-coreboot-x86_64-elf.txt scripts/cross-cortex-a9-none-eabi.txt scripts/cross-i686-linux-gnu.txt scripts/cross-lm32-unknown-elf.txt scripts/cross-loongarch64-unknown-elf.txt scripts/cross-m68k-linux-gnu.txt scripts/cross-m68k-unknown-elf.txt scripts/cross-microblazeel-zephyr-elf.txt scripts/cross-mips-linux-gnu.txt scripts/cross-mips-zephyr-elf.txt scripts/cross-mips64-linux-gnuabi64.txt scripts/cross-mipsel-linux-gnu.txt scripts/cross-msp430-unknown-elf.txt scripts/cross-msp430.txt scripts/cross-nios2-zephyr-elf.txt scripts/cross-or1k-elf.txt scripts/cross-or1k-unknown-elf.txt scripts/cross-power9-fp128.txt scripts/cross-power9.txt scripts/cross-powerpc64-linux-gnu.txt scripts/cross-powerpc64le-linux-gnu.txt scripts/cross-riscv64-unknown-elf.txt scripts/cross-riscv64-zephyr-elf.txt scripts/cross-rv32imac.txt scripts/cross-rv32imac_zicsr_zbb.txt scripts/cross-rx-zephyr-elf.txt scripts/cross-sh-unknown-elf.txt scripts/cross-sparc-zephyr-elf.txt scripts/cross-sparc64-linux-gnu.txt scripts/cross-thumbv8_1m-none-eabi.txt scripts/cross-thumbv8m_main_fp-none-eabi.txt scripts/cross-x86-linux-gnu.txt scripts/cross-x86_64-linux-gnu.txt scripts/cross-x86_64-zephyr-elf.txt scripts/cross-xtensa-dc233c_zephyr-elf.txt scripts/cross-xtensa-esp32-elf.txt scripts/cross-xtensa-espressif_esp32_zephyr-elf.txt scripts/cross-xtensa-espressif_esp32s2_zephyr-elf.txt scripts/cross-xtensa-intel_apl_adsp_zephyr-elf.txt scripts/cross-xtensa-intel_s1000_zephyr-elf.txt scripts/cross-xtensa-lx106-elf.txt scripts/cross-xtensa-nxp_imx8m_adsp_zephyr-elf.txt scripts/cross-xtensa-nxp_imx_adsp_zephyr-elf.txt scripts/cross-xtensa-sample_controller_zephyr-elf.txt scripts/do-arm-tk scripts/do-clang-hexagon-configure scripts/duplicate-names scripts/monitor-e9 scripts/run-hexagon scripts/run-lm32 scripts/test-picolibc semihost/machine/hexagon/hexagon_close.c semihost/machine/hexagon/hexagon_errno.c semihost/machine/hexagon/hexagon_exit.c semihost/machine/hexagon/hexagon_flen.c semihost/machine/hexagon/hexagon_ftell.c semihost/machine/hexagon/hexagon_get_cmdline.c semihost/machine/hexagon/hexagon_isatty.c semihost/machine/hexagon/hexagon_lseek.c semihost/machine/hexagon/hexagon_open.c semihost/machine/hexagon/hexagon_read.c semihost/machine/hexagon/hexagon_semihost.c semihost/machine/hexagon/hexagon_semihost.h semihost/machine/hexagon/hexagon_stub.c semihost/machine/hexagon/hexagon_unlink.c semihost/machine/hexagon/hexagon_write.c semihost/machine/hexagon/meson.build semihost/machine/x86/bios.ld test/CP720 test/complex-funcs.c test/long_double_gen.5c test/long_double_vec.h test/test-argv.c test/test-atomic.c test/test-math/.clang-format-ignore test/test-math/Makefile test/test-math/math-test-copyright test/test-math/test-complex.5c test/test-math/test-float.5c test/test-stdio/test-sprintf-time.c test/test-strftime.c test/test-wcsftime.c test/testsuite/newlib.time/tzset.c Copyright: License: Default-1 Files: libc/ctype/caseconv.c libc/ctype/ctype_.h libc/ctype/isalnum_l.c libc/ctype/isalpha_l.c libc/ctype/isascii_l.c libc/ctype/isblank_l.c libc/ctype/iscntrl_l.c libc/ctype/isdigit_l.c libc/ctype/isgraph_l.c libc/ctype/islower_l.c libc/ctype/isprint_l.c libc/ctype/ispunct_l.c libc/ctype/isspace_l.c libc/ctype/isupper_l.c libc/ctype/iswalnum_l.c libc/ctype/iswalpha_l.c libc/ctype/iswblank_l.c libc/ctype/iswcntrl_l.c libc/ctype/iswctype_l.c libc/ctype/iswdigit_l.c libc/ctype/iswgraph_l.c libc/ctype/iswlower_l.c libc/ctype/iswprint_l.c libc/ctype/iswpunct_l.c libc/ctype/iswupper_l.c libc/ctype/iswxdigit_l.c libc/ctype/isxdigit_l.c libc/ctype/toascii_l.c libc/ctype/tolower_l.c libc/ctype/toupper_l.c libc/ctype/towctrans_l.c libc/ctype/towlower_l.c libc/ctype/towupper_l.c libc/ctype/wctrans_l.c libc/ctype/wctype_l.c libc/include/sys/_locale.h libc/string/strcasecmp_l.c libc/string/strcoll_l.c libc/string/strncasecmp_l.c libc/string/strxfrm_l.c libc/string/wcscasecmp_l.c libc/string/wcscoll_l.c libc/string/wcsncasecmp_l.c libc/string/wcsxfrm_l.c Copyright: 2016 Corinna Vinschen License: Default-1 Files: libc/ctype/categories.h Copyright: 2017 Thomas Wolff towo@towo.net License: Default-1 Files: libc/ctype/isblank.c libc/stdlib/btowc.c libc/stdlib/mbrlen.c libc/stdlib/mbrtowc.c libc/stdlib/mbsinit.c libc/stdlib/mbsrtowcs.c libc/stdlib/wcrtomb.c libc/stdlib/wcsrtombs.c libc/stdlib/wctob.c Copyright: 2002 Thomas Fitzsimmons License: Default-1 Files: libc/ctype/mkcaseconv libc/ctype/mkcategories libc/ctype/mkunidata libc/string/mkunidata libc/string/mkwide libc/string/mkwidthA Copyright: 2018 Thomas Wolff License: Default-1 Files: libc/include/_newlib_version.h Copyright: 2016 Jeff Johnston License: Default-1 Files: libc/include/alloca.h Copyright: 2000 Werner Almesberger License: Default-1 Files: libc/include/arpa/inet.h libc/include/machine/endian.h libc/include/machine/param.h libc/machine/arm/machine/param.h Copyright: 2004 Jeff Johnston License: Default-1 Files: libc/include/cpio.h libm/complex/clog10.c libm/complex/clog10f.c libm/complex/clog10l.c Copyright: 2016 Yaakov Selkowitz License: Default-1 Files: libc/include/libgen.h libc/include/sys/string.h libc/time/gettzinfo.c Copyright: 2005 Jeff Johnston License: Default-1 Files: libc/include/limits.h libc/include/machine/malloc.h libc/include/machine/stdlib.h libc/include/machine/termios.h libc/include/sys/lock.h libc/include/wctype.h libc/stdlib/_Exit.c libc/stdlib/a64l.c libc/stdlib/l64a.c libc/string/memccpy.c libc/string/mempcpy.c libc/string/strdup.c libc/string/strerror_r.c libc/string/strndup.c libc/string/strnlen.c libc/time/local.h test/testsuite/newlib.wctype/tiswctype.c test/testsuite/newlib.wctype/twctrans.c Copyright: 2002 Jeff Johnston License: Default-1 Files: libc/include/machine/_default_types.h libc/machine/spu/creat.c libc/machine/spu/sys/errno.h libc/machine/spu/sys/sched.h libc/machine/spu/sys/syscall.h libc/machine/spu/sys/uio.h libc/machine/spu/sys/utime.h Copyright: 2007 Patrick Mansfield License: Default-1 Files: libc/include/machine/_endian.h libc/include/machine/_time.h libc/include/memory.h Copyright: 2016 Sebastian Huber License: Default-1 Files: libc/include/machine/_types.h Copyright: 2005 Ralf Corsepious License: Default-1 Files: libc/include/machine/ansi.h Copyright: 2001 Jeff Johnston License: Default-1 Files: libc/include/ssp/stdlib.h libc/include/ssp/wchar.h libc/ssp/stack_protector.c libc/string/wmempcpy.c Copyright: 2017 Yaakov Selkowitz License: Default-1 Files: libc/include/sys/_default_fcntl.h libc/include/sys/custom_file.h libc/machine/x86/machine/fastmath.h Copyright: 2007 Jeff Johnston License: Default-1 Files: libc/include/sys/dir.h Copyright: 2010 Yaakov Selkowitz License: Default-1 Files: libc/include/tar.h Copyright: 2007 Ralf Corsepius License: Default-1 Files: libc/machine/aarch64/asmdefs.h Copyright: 2019-2023, Arm Limited. SPDX-License-Identifier: MIT License: Default-1 Files: libc/machine/aarch64/memchr.S Copyright: 2014-2022, Arm Limited. SPDX-License-Identifier: MIT License: Default-1 Files: libc/machine/aarch64/memcmp.S Copyright: 2013-2022, Arm Limited. SPDX-License-Identifier: MIT License: Default-1 Files: libc/machine/aarch64/memcpy.S libc/machine/aarch64/memset.S libc/machine/aarch64/strcmp.S Copyright: 2012-2022, Arm Limited. SPDX-License-Identifier: MIT License: Default-1 Files: libc/machine/aarch64/memrchr-stub.c Copyright: 2023 embedded brains GmbH & Co. KG License: Default-1 Files: libc/machine/aarch64/memrchr.S Copyright: 2020-2022, Arm Limited. SPDX-License-Identifier: MIT License: Default-1 Files: libc/machine/aarch64/stpcpy.S Copyright: 2020, Arm Limited. SPDX-License-Identifier: MIT License: Default-1 Files: libc/machine/arm/setjmp.S Copyright: 1997 Nick Clifton, Cygnus Solutions License: Default-1 Files: libc/machine/cr16/setjmp.S libc/machine/crx/setjmp.S Copyright: 2004 National Semiconductor Corporation License: Default-1 Files: libc/machine/frv/setjmp.S Copyright: 2002 Dave Brolley License: Default-1 Files: libc/machine/h8300/h8sx_strcpy.S Copyright: 2003 Richard Sandiford License: Default-1 Files: libc/machine/h8300/setarch.h Copyright: 2003 Kazu Hirata License: Default-1 Files: libc/machine/iq2000/setjmp.S Copyright: 2003 Anthony Green License: Default-1 Files: libc/machine/m68k/m68kasm.h Copyright: 2008 Jeff Johnston License: Default-1 Files: libc/machine/mep/setjmp.S Copyright: 2003 DJ Delorie, Red Hat Inc. License: Default-1 Files: libc/machine/microblaze/mb_endian.h Copyright: 2013 Corinna Vinschen License: Default-1 Files: libc/machine/mt/setjmp.S Copyright: 2005 Aldy Hernandez License: Default-1 Files: libc/machine/rx/memchr.S libc/machine/rx/memcpy.S libc/machine/rx/memmove.S libc/machine/rx/mempcpy.S libc/machine/rx/memset.S libc/machine/rx/setjmp.S libc/machine/rx/strcat.S libc/machine/rx/strcmp.S libc/machine/rx/strcpy.S libc/machine/rx/strlen.S libc/machine/rx/strncat.S libc/machine/rx/strncmp.S libc/machine/rx/strncpy.S Copyright: 2009 Nick Clifton License: Default-1 Files: libc/machine/sh/memcpy.S libc/machine/sh/memset.S libc/machine/sh/strcmp.S libc/machine/sh/strcpy.S libc/machine/sh/strlen.S Copyright: 2002 SuperH Ltd. License: Default-1 Files: libc/machine/sh/strncpy.S Copyright: 2003 SuperH Ltd. License: Default-1 Files: libc/machine/spu/assert.c libc/machine/spu/sleep.c Copyright: 2008 Patrick Mansfield License: Default-1 Files: libc/machine/spu/usleep.c Copyright: 2002 Jeff Johnston License: Default-1 Files: libc/machine/spu/vfiprintf.c libc/machine/spu/vfiscanf.c libc/machine/spu/viprintf.c libc/machine/spu/viscanf.c libc/machine/spu/vsiprintf.c libc/machine/spu/vsiscanf.c libc/machine/spu/vsniprintf.c Copyright: 2007 Kazunori Asayama License: Default-1 Files: libc/machine/xstormy16/mallocr.c libc/machine/xstormy16/tiny-malloc.c Copyright: 2002 Geoffrey Keating License: Default-1 Files: libc/misc/lock.c Copyright: 2016 Thomas Preud'homme License: Default-1 Files: libc/search/bsd_qsort_r.c libc/search/qsort_r.c Copyright: 2014 Yaakov Selkowitz License: Default-1 Files: libc/signal/psignal.c Copyright: 2002, 2011 Red Hat Inc. License: Default-1 Files: libc/ssp/chk_fail.c Copyright: 2017 Yaakov Selkowitz License: Default-1 Files: libc/stdlib/abort.c libc/stdlib/abs.c libc/stdlib/assert.c libc/stdlib/assert_func.c libc/stdlib/assert_no_arg.c libc/stdlib/atexit.h libc/stdlib/atof.c libc/stdlib/atoff.c libc/stdlib/atoi.c libc/stdlib/atol.c libc/stdlib/eprintf.c libc/stdlib/labs.c libc/stdlib/local.h libc/stdlib/mbctype.h libc/stdlib/mblen.c libc/stdlib/mbstowcs.c libc/stdlib/mbtowc.c libc/stdlib/mbtowc_r.c libc/stdlib/rand.c libc/stdlib/rand_r.c libc/stdlib/srand.c libc/stdlib/stdlib.tex libc/stdlib/system.c libc/stdlib/wcstombs.c libc/stdlib/wctomb.c libc/stdlib/wctomb_r.c Copyright: 1990 Regents of the University of California. License: Default-1 Files: libc/stdlib/getenv_r.c Copyright: 1991 DJ Delorie. License: Default-1 Files: libc/stdlib/itoa.c libc/stdlib/utoa.c Copyright: 2014 Corinna Vinschen License: Default-1 Files: libc/stdlib/mbsnrtowcs.c libc/stdlib/sb_charsets.c libc/stdlib/wcsnrtombs.c libc/string/local.h libc/string/wcscasecmp.c libc/string/wcsdup.c libc/string/wcsncasecmp.c Copyright: 2009 Corinna Vinschen License: Default-1 Files: libc/stdlib/random.c libc/stdlib/srandom.c Copyright: 2016 Joel Sherrill License: Default-1 Files: libc/string/memrchr.c Copyright: 2012 Corinna Vinschen License: Default-1 Files: libc/string/rawmemchr.c Copyright: 2013 Yaakov Selkowitz License: Default-1 Files: libc/string/stpcpy.c libc/string/stpncpy.c libc/string/wcpcpy.c libc/string/wcpncpy.c libc/string/wcsxfrm.c Copyright: 2007 Corinna Vinschen License: Default-1 Files: libc/string/strchrnul.c Copyright: 2011 Corinna Vinschen License: Default-1 Files: libc/string/strnstr.c Copyright: 2017 Sichen Zhao <1473996754@qq.com> License: Default-1 Files: libc/string/strsep.c Copyright: 2002, Red Hat Inc. License: Default-1 Files: libc/string/swab.c Copyright: 2000 Alexandre Oliva License: Default-1 Files: libc/string/uniset Copyright: 2018 Markus Kuhn License: Default-1 Files: libc/string/wcscoll.c libc/string/wcswidth.c libc/string/wcwidth.c Copyright: 2003 Corinna Vinschen License: Default-1 Files: libc/string/xpg_strerror_r.c Copyright: 2011 Eric Blake License: Default-1 Files: libc/time/month_lengths.c libc/time/tzcalc_limits.c Copyright: 2002 Arthur David Olson License: Default-1 Files: libc/time/tzvars.c Copyright: 2005 Tom Walsh License: Default-1 Files: libc/time/wcsftime.c Copyright: 2009 Craig Howland License: Default-1 Files: libm/machine/x86/fenv.c Copyright: 2010-2019 Red Hat, Inc. License: Default-1 Files: scripts/cross-clang-aarch64-none-elf-fvp.txt Copyright: 2024 Arm Limited and/or its affiliates License: Default-1 Files: zephyr/Kconfig Copyright: 2021 Amazon.com, Inc. or its affiliates. SPDX-License-Identifier: Apache-2.0 License: Default-1 Files: libc/include/fenv.h libc/machine/riscv/asm.h libc/machine/riscv/ieeefp.c libc/machine/riscv/machine/fenv.h libc/machine/riscv/memset.S libc/machine/riscv/rv_strcpy.h libc/machine/riscv/setjmp.S libc/machine/riscv/strcmp.S libc/machine/riscv/strcpy.c libc/machine/riscv/strlen.c Copyright: 2017 SiFive Inc. License: FreeBSD-1 Files: libc/machine/csky/setjmp.S Copyright: 2020 C-SKY Microsystems License: FreeBSD-1 Files: libc/machine/loongarch/setjmp.S Copyright: 2024 Jiaxun Yang License: FreeBSD-1 Files: libc/machine/riscv/memcpy-asm.S libc/machine/riscv/memmove.S libc/machine/riscv/memmove.c Copyright: 2019 SiFive Inc. License: FreeBSD-1 Files: libc/machine/riscv/memcpy.c Copyright: 2017 SiFive Inc. 2025 Mahmoud Abumandour License: FreeBSD-1 Files: libc/machine/riscv/stpcpy.c Copyright: 2025 SiFive Inc. License: FreeBSD-1 Files: libc/machine/riscv/rv_string.h Copyright: 2017 SiFive Inc. License: FreeBSD-2 Files: test/test-stdio/test-printf-testcases.h test/test-stdio/test-printf.c Copyright: 2013 Bart Massey License: GPL2-1 Files: libc/argz/argz_add.c libc/argz/argz_add_sep.c libc/argz/argz_append.c libc/argz/argz_count.c libc/argz/argz_create.c libc/argz/argz_create_sep.c libc/argz/argz_delete.c libc/argz/argz_extract.c libc/argz/argz_next.c libc/argz/argz_replace.c libc/argz/argz_stringify.c libc/argz/buf_findstr.c libc/argz/buf_findstr.h libc/argz/envz_add.c libc/argz/envz_entry.c libc/argz/envz_get.c libc/argz/envz_merge.c libc/argz/envz_remove.c libc/argz/envz_strip.c libc/include/argz.h libc/include/envz.h libm/common/s_fdim.c libm/common/s_fma.c libm/common/s_fmax.c libm/common/s_fmin.c libm/common/s_signbit.c libm/common/sf_fdim.c libm/common/sf_fma.c libm/common/sf_fmax.c libm/common/sf_fmin.c libm/common/sf_signbit.c libm/machine/spu/sf_fpclassify.c test/testsuite/config/default.exp test/testsuite/include/check.h test/testsuite/lib/checkoutput.exp test/testsuite/lib/newlib.exp test/testsuite/lib/passfail.exp test/testsuite/newlib.elix/elix.exp test/testsuite/newlib.elix/tmmap.c test/testsuite/newlib.locale/UTF-8.c test/testsuite/newlib.locale/UTF-8.exp test/testsuite/newlib.locale/locale.exp test/testsuite/newlib.search/hsearchtest.exp test/testsuite/newlib.stdlib/atexit.c test/testsuite/newlib.stdlib/atexit.exp test/testsuite/newlib.string/string.exp test/testsuite/newlib.string/tstring.c test/testsuite/newlib.wctype/twctype.c test/testsuite/newlib.wctype/wctype.exp Copyright: 2002 Red Hat, Incorporated. License: Other-1 Files: libc/argz/argz_insert.c Copyright: 2002, 2005 Red Hat, Incorporated. License: Other-1 Files: libc/include/inttypes.h libc/include/stdint.h libc/include/sys/_intsup.h libc/include/sys/_stdint.h Copyright: 2004, 2005 by Ralf Corsepius, Ulm/Germany. License: Other-1 Files: libc/include/wordexp.h Copyright: 2002, 2010 Red Hat, Incorporated. License: Other-1 Files: libc/machine/x86/memchr-32.S libc/machine/x86/memset-32.S libc/machine/x86/strchr-32.S libc/machine/x86/strlen-32.S Copyright: 1998, 2002, 2008 Red Hat Inc. License: Other-1 Files: libc/machine/x86/memcmp-32.S libc/machine/x86/memcpy-32.S libc/machine/x86/memmove-32.S libm/machine/x86/f_atan2.S libm/machine/x86/f_atan2f.S libm/machine/x86/f_exp.c libm/machine/x86/f_expf.c libm/machine/x86/f_frexp.S libm/machine/x86/f_frexpf.S libm/machine/x86/f_ldexp.S libm/machine/x86/f_ldexpf.S libm/machine/x86/f_log.S libm/machine/x86/f_log10.S libm/machine/x86/f_log10f.S libm/machine/x86/f_logf.S libm/machine/x86/f_math.h libm/machine/x86/f_pow.c libm/machine/x86/f_powf.c libm/machine/x86/f_tan.S libm/machine/x86/f_tanf.S libm/machine/x86/i386mach.h Copyright: 1998, 2002 Red Hat Inc. License: Other-1 Files: libc/machine/x86/memcpy-64.S libc/machine/x86/memset-64.S libc/machine/x86/setjmp-64.S libc/machine/x86/x86_64mach.h Copyright: 2007 Ellips BV. License: Other-1 Files: libc/machine/xstormy16/setjmp.S Copyright: 2001 Red Hat, Incorporated. License: Other-1 Files: libc/posix/basename.c libc/posix/dirname.c Copyright: 2005 Shaun Jackman License: Other-1 Files: libc/string/gnu_basename.c Copyright: 2015 Red Hat, Inc. License: Other-1 Files: libc/string/str-two-way.h Copyright: 2008, 2010 Eric Blake License: Other-1 Files: libm/common/s_fpclassify.c libm/common/sf_fpclassify.c libm/ld/ld128/s_fpclassifyl.c libm/ld/ld80/s_fpclassifyl.c Copyright: 2002, 2007 Red Hat, Incorporated. License: Other-1 Files: libm/complex/cabsl.c libm/complex/cimagl.c libm/complex/creall.c libm/math/sl_hypot.c Copyright: 2015 Red Hat, Incorporated. License: Other-1 Files: libm/ld/common/s_sincosl.c Copyright: 2013 Elliot Saba Developed at the University of Washington License: Other-1 Files: libm/ld/ld128/k_tanl.c libm/ld/ld80/k_tanl.c Copyright: 2004 Sun Microsystems, Inc. 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. License: Other-1 Files: test/testsuite/lib/flags.exp Copyright: 2002, 2011 Red Hat, Incorporated. License: Other-1 Files: test/testsuite/newlib.stdio/nulprintf.c Copyright: 2014 ARM Ltd. License: Other-1 Files: test/testsuite/newlib.stdio/stdio.exp test/testsuite/newlib.stdio/swprintf.c Copyright: 2011 ARM Ltd. License: Other-1 Files: test/testsuite/newlib.stdlib/size_max.c test/testsuite/newlib.stdlib/stdlib.exp Copyright: 2008 CodeSourcery, Inc. License: Other-1 Files: test/testsuite/newlib.time/time.exp Copyright: 2022 jdoubleu. License: Other-1 Files: libc/include/complex.h Copyright: 2010 Matthias Drochner. License: Other-2 Files: libc/string/explicit_bzero.c Copyright: 2014 Ted Unangst License: Other-2 Files: libc/include/getopt.h Copyright: 1997 Gregory Pietsch License: Other-3 Files: libc/include/machine/_arc4random.h libc/stdlib/arc4random.c libc/stdlib/chacha_private.h Copyright: 1996, David Mazieres 2008, Damien Miller 2013, Markus Friedl 2014, Theo de Raadt License: Other-4 Files: libc/stdlib/arc4random_uniform.c Copyright: 2008, Damien Miller License: Other-4 Files: libc/stdlib/reallocarray.c Copyright: 2008 Otto Moerbeek License: Other-4 Files: libc/string/strlcat.c libc/string/strlcpy.c libc/string/wcslcat.c libc/string/wcslcpy.c Copyright: 1998, 2015 Todd C. Miller License: Other-4 Files: libc/string/timingsafe_bcmp.c Copyright: 2010 Damien Miller. License: Other-4 Files: libc/string/timingsafe_memcmp.c Copyright: 2014 Google Inc. License: Other-4 Files: libm/ld/common/polevll.c libm/ld/ld128/e_expl.c libm/ld/ld128/e_lgammal_r.c libm/ld/ld128/e_log10l.c libm/ld/ld128/e_log2l.c libm/ld/ld128/e_logl.c libm/ld/ld128/s_expm1l.c libm/ld/ld128/s_log1pl.c libm/ld/ld80/e_expl.c libm/ld/ld80/e_log10l.c libm/ld/ld80/e_log2l.c libm/ld/ld80/e_logl.c libm/ld/ld80/e_powl.c libm/ld/ld80/e_tgammal.c libm/ld/ld80/s_expm1l.c libm/ld/ld80/s_log1pl.c Copyright: 2008 Stephen L. Moshier License: Other-4 Files: libm/ld/ld128/e_tgammal.c Copyright: 2011 Martynas Venckus License: Other-4 Files: libc/include/machine/fastmath.h libc/include/machine/ieeefp.h libc/include/machine/setjmp.h libc/include/machine/time.h libc/include/machine/types.h libc/machine/x86/setjmp-32.S Copyright: 1991 DJ Delorie License: Other-5 Files: libc/include/sched.h libc/include/sys/sched.h Copyright: 1989-2010. On-Line Applications Research Corporation (OAR). License: Other-6 Files: libc/include/sys/features.h Copyright: 1989-2014. On-Line Applications Research Corporation (OAR). License: Other-6 Files: libc/string/strsignal.c Copyright: 2010, 2017. On-Line Applications Research Corporation (OAR). License: Other-6 Files: libc/machine/amdgcn/abort.c libc/machine/amdgcn/atexit.c libc/machine/amdgcn/getreent.c libc/machine/amdgcn/signal.c Copyright: 2014-2017 Mentor Graphics. License: Other-7 Files: libc/machine/amdgcn/exit-value.h libc/machine/amdgcn/mlock.c Copyright: 2017 Mentor Graphics. License: Other-7 Files: libc/machine/bfin/longjmp.S libc/machine/bfin/setjmp.S Copyright: 2006 Analog Devices, Inc. License: Other-7 Files: libc/machine/cr16/getenv.c libc/machine/cr16/sys/libh.h libc/machine/cr16/sys/syscall.h libc/machine/crx/getenv.c libc/machine/crx/sys/asm.h libc/machine/crx/sys/libh.h libc/machine/crx/sys/syscall.h Copyright: 2004 National Semiconductor Corporation License: Other-7 Files: libc/machine/cr16/sys/asm.h Copyright: 2012 National Semiconductor Corporation License: Other-7 Files: libc/machine/ft32/memcpy.S libc/machine/ft32/memset.S libc/machine/ft32/setjmp.S libc/machine/ft32/stpcmp.S libc/machine/ft32/strcmp.S libc/machine/ft32/strcpy.S libc/machine/ft32/strlen.S Copyright: 2014 FTDI (support@ftdichip.com) License: Other-7 Files: libc/machine/m68hc11/setjmp.S Copyright: 1999, 2000, 2001, 2002 Stephane Carrez (stcarrez@nerim.fr) License: Other-7 Files: libc/machine/m68k/memcpy.S libc/machine/m68k/memset.S Copyright: 2007 mocom software GmbH & Co KG) License: Other-7 Files: libc/machine/mips/strlen.c Copyright: 2001, 2002 Red Hat, Inc. License: Other-7 Files: libc/machine/mips/strncpy.c Copyright: 2001 Red Hat, Inc. License: Other-7 Files: libc/machine/moxie/setjmp.S Copyright: 2009, 2019 Anthony Green License: Other-7 Files: libc/machine/nvptx/_exit.c libc/machine/nvptx/abort.c libc/machine/nvptx/calloc.c libc/machine/nvptx/callocr.c libc/machine/nvptx/mallocr.c libc/machine/nvptx/misc.c libc/machine/nvptx/reallocr.c libc/machine/nvptx/write.c Copyright: 2014-2018 Mentor Graphics. License: Other-7 Files: libc/machine/nvptx/assert.c libc/machine/nvptx/free.c libc/machine/nvptx/malloc.c libc/machine/nvptx/realloc.c Copyright: 2016-2018 Mentor Graphics. License: Other-7 Files: libc/machine/nvptx/printf.c libc/machine/nvptx/putchar.c libc/machine/nvptx/puts.c Copyright: 2015-2018 Mentor Graphics. License: Other-7 Files: libc/machine/cris/include/pthread.h libc/machine/cris/sys/errno.h libc/machine/cris/sys/fcntl.h libc/machine/cris/sys/signal.h Copyright: 2001, 2004, 2005 Axis Communications AB. License: Other-8 Files: libc/machine/cris/libcdtor.c Copyright: 1999, 2000, 2003, 2004, 2005 Axis Communications. License: Other-8 Files: libc/machine/cris/memcpy.c Copyright: 1994-2005 Axis Communications. License: Other-8 Files: libc/machine/cris/memmove.c Copyright: 2000-2005 Axis Communications. License: Other-8 Files: libc/machine/cris/memset.c Copyright: 1999-2005 Axis Communications. License: Other-8 Files: libc/machine/cris/setjmp.c Copyright: 1993-2005 Axis Communications. License: Other-8 Files: test/testsuite/newlib.string/memmove1.c Copyright: 2005 Axis Communications. License: Other-8 Files: libc/machine/hppa/memchr.S libc/machine/hppa/memcmp.S libc/machine/hppa/memcpy.S libc/machine/hppa/memset.S libc/machine/hppa/pcc_prefix.s libc/machine/hppa/strcat.S libc/machine/hppa/strcmp.S libc/machine/hppa/strcpy.S libc/machine/hppa/strlen.S libc/machine/hppa/strncat.S libc/machine/hppa/strncmp.S libc/machine/hppa/strncpy.S Copyright: 1986 HEWLETT-PACKARD COMPANY License: Other-9 Files: libc/machine/i960/memccpy.S libc/machine/i960/memccpy_ca.S libc/machine/i960/memchr.S libc/machine/i960/memchr_ca.S libc/machine/i960/memcmp.S libc/machine/i960/memcmp_ca.S libc/machine/i960/memcpy.S libc/machine/i960/memcpy_ca.S libc/machine/i960/memset.S libc/machine/i960/setjmp.S libc/machine/i960/strchr.S libc/machine/i960/strchr_ca.S libc/machine/i960/strcmp.S libc/machine/i960/strcmp_ca.S libc/machine/i960/strcpy.S libc/machine/i960/strcpy_ca.S libc/machine/i960/strcspn.S libc/machine/i960/strdup.S libc/machine/i960/strlen.S libc/machine/i960/strlen_ca.S libc/machine/i960/strncat.S libc/machine/i960/strncat_ca.S libc/machine/i960/strncmp.S libc/machine/i960/strncmp_ca.S libc/machine/i960/strncpy.S libc/machine/i960/strncpy_ca.S libc/machine/i960/strpbrk.S libc/machine/i960/strrchr.S Copyright: 1993 Intel Corporation License: Other-10 Files: libc/machine/msp430/setjmp.S Copyright: 2013 Red Hat, Inc. License: Other-11 Files: libc/machine/tic4x/setjmp.S Copyright: 2004 Michael Hayes . License: Other-12 Files: libc/machine/xc16x/putchar.c libc/machine/xc16x/puts.c libc/machine/xc16x/setjmp.S Copyright: 2006 KPIT Cummins 2009 Conny Marco Menebröcker License: Other-13 Files: libc/machine/xtensa/machine/core-isa.h Copyright: 1999-2010 Tensilica Inc. License: Other-14 Files: libc/machine/xtensa/memcpy.S Copyright: 2002-2008 Tensilica Inc. License: Other-14 Files: libc/machine/xtensa/memset.S libc/machine/xtensa/strcpy.S libc/machine/xtensa/strlen.S libc/machine/xtensa/strncpy.S Copyright: 2001-2008 Tensilica Inc. License: Other-14 Files: libc/machine/xtensa/setjmp.S Copyright: 2001-2006 Tensilica Inc. License: Other-14 Files: libc/machine/xtensa/strcmp.S Copyright: 2001-20012 Tensilica Inc. License: Other-14 Files: libc/machine/xtensa/xtensa-asm.h Copyright: 2006 Tensilica Inc. License: Other-14 Files: libc/string/strverscmp.c libm/common/nexttowardf.c Copyright: 2005-2014 Rich Felker, et al. License: Other-14 Files: test/libc-testsuite/basename.c test/libc-testsuite/dirname.c test/libc-testsuite/fnmatch.c test/libc-testsuite/qsort.c test/libc-testsuite/snprintf.c test/libc-testsuite/sscanf.c test/libc-testsuite/string.c test/libc-testsuite/strtod.c test/libc-testsuite/strtol.c test/libc-testsuite/wcstol.c Copyright: 2005-2020 Rich Felker License: Other-14 Files: libc/machine/z8k/memcmp.S libc/machine/z8k/memcpy.S libc/machine/z8k/memmove.S libc/machine/z8k/memset.S Copyright: 2004 Christian Groessler License: Other-15 Files: libc/misc/fini.c Copyright: 2010 CodeSourcery, Inc. License: Other-15 Files: libc/misc/init.c Copyright: 2004 CodeSourcery, LLC License: Other-15 Files: libc/signal/signal.c libc/signal/signal.tex libc/string/bcmp.c libc/string/bcopy.c libc/string/bzero.c libc/string/index.c libc/string/memchr.c libc/string/memcmp.c libc/string/memcpy.c libc/string/memmove.c libc/string/memset.c libc/string/rindex.c libc/string/strcasecmp.c libc/string/strcat.c libc/string/strchr.c libc/string/strcmp.c libc/string/strcoll.c libc/string/strcpy.c libc/string/strcspn.c libc/string/strerror.c libc/string/strings.tex libc/string/strlen.c libc/string/strlwr.c libc/string/strncasecmp.c libc/string/strncat.c libc/string/strncmp.c libc/string/strncpy.c libc/string/strpbrk.c libc/string/strrchr.c libc/string/strspn.c libc/string/strtok.c libc/string/strupr.c libc/string/strxfrm.c libc/time/asctime.c libc/time/asctime_r.c libc/time/clock.c libc/time/ctime.c libc/time/ctime_r.c libc/time/difftime.c libc/time/gmtime.c libc/time/gmtime_r.c libc/time/lcltime.c libc/time/lcltime_buf.c libc/time/lcltime_r.c libc/time/mktime.c libc/time/time.c libc/time/time.tex libm/test/acos_vec.c libm/test/acosf_vec.c libm/test/acosh_vec.c libm/test/acoshf_vec.c libm/test/asin_vec.c libm/test/asinf_vec.c libm/test/asinh_vec.c libm/test/asinhf_vec.c libm/test/atan2_vec.c libm/test/atan2f_vec.c libm/test/atan_vec.c libm/test/atanf_vec.c libm/test/atanh_vec.c libm/test/atanhf_vec.c libm/test/ceil_vec.c libm/test/ceilf_vec.c libm/test/conv_vec.c libm/test/convert.c libm/test/cos_vec.c libm/test/cosf_vec.c libm/test/cosh_vec.c libm/test/coshf_vec.c libm/test/dcvt.c libm/test/dvec.c libm/test/erf_vec.c libm/test/erfc_vec.c libm/test/erfcf_vec.c libm/test/erff_vec.c libm/test/exp_vec.c libm/test/expf_vec.c libm/test/fabs_vec.c libm/test/fabsf_vec.c libm/test/floor_vec.c libm/test/floorf_vec.c libm/test/fmod_vec.c libm/test/fmodf_vec.c libm/test/gamma_vec.c libm/test/gammaf_vec.c libm/test/hypot_vec.c libm/test/hypotf_vec.c libm/test/iconv_vec.c libm/test/j0_vec.c libm/test/j0f_vec.c libm/test/j1_vec.c libm/test/j1f_vec.c libm/test/jn_vec.c libm/test/jnf_vec.c libm/test/log10_vec.c libm/test/log10f_vec.c libm/test/log1p_vec.c libm/test/log1pf_vec.c libm/test/log2_vec.c libm/test/log2f_vec.c libm/test/log_vec.c libm/test/logf_vec.c libm/test/math.c libm/test/math2.c libm/test/sin_vec.c libm/test/sinf_vec.c libm/test/sinh_vec.c libm/test/sinhf_vec.c libm/test/sprint_ivec.c libm/test/sprint_vec.c libm/test/sqrt_vec.c libm/test/sqrtf_vec.c libm/test/string.c libm/test/tan_vec.c libm/test/tanf_vec.c libm/test/tanh_vec.c libm/test/tanhf_vec.c libm/test/test.c libm/test/test.h libm/test/test_ieee.c libm/test/test_is.c libm/test/trunc_vec.c libm/test/truncf_vec.c libm/test/y0_vec.c libm/test/y0f_vec.c libm/test/y1_vec.c libm/test/y1f_vec.c libm/test/yn_vec.c libm/test/ynf_vec.c Copyright: 1994 Cygnus Support. License: Other-16 Files: libc/stdio/atod_ryu.c libc/stdio/atof_ryu.c libc/stdio/ryu/ryu_parse.h Copyright: 2019 Ulf Adams License: Other-17 Files: libc/stdio/dtoa_ryu.c libc/stdio/ftoa_ryu.c libc/stdio/ryu/common.h libc/stdio/ryu/d2s_intrinsics.h libc/stdio/ryu/digit_table.h libc/stdio/ryu/f2s_intrinsics.h libc/stdio/ryu/ryu.h libc/stdio/ryu_divpow2.c libc/stdio/ryu_log10.c libc/stdio/ryu_log2pow5.c libc/stdio/ryu_pow5bits.c libc/stdio/ryu_table.c libc/stdio/ryu_umul128.c Copyright: 2018 Ulf Adams License: Other-17 Files: libc/stdlib/drand48.c libc/stdlib/erand48.c libc/stdlib/jrand48.c libc/stdlib/lcong48.c libc/stdlib/lrand48.c libc/stdlib/mrand48.c libc/stdlib/nrand48.c libc/stdlib/rand48.c libc/stdlib/rand48.h libc/stdlib/seed48.c libc/stdlib/srand48.c Copyright: 1993 Martin Birgmeier License: Other-18 Files: libc/stdlib/gdtoa.h Copyright: 1998 Lucent Technologies License: Other-19 Files: libc/stdlib/getopt.c Copyright: 1997 Gregory Pietsch License: Other-20 Files: libc/stdlib/mprec.h Copyright: 1991 AT&T. License: Other-21 Files: libc/string/wcsnlen.c Copyright: 2003, Artem B. Bityuckiy (dedekind@mail.ru). License: Other-22 Files: libc/xdr/xdr_private.c libc/xdr/xdr_private.h Copyright: 2009 Charles S. Wilson License: Other-23 Files: libm/common/fdlibm.h libm/common/isgreater.c libm/common/s_cbrt.c libm/common/s_copysign.c libm/common/s_exp10.c libm/common/s_expm1.c libm/common/s_finite.c libm/common/s_ilogb.c libm/common/s_infinity.c libm/common/s_isinf.c libm/common/s_isnan.c libm/common/s_llrint.c libm/common/s_llround.c libm/common/s_log1p.c libm/common/s_log2.c libm/common/s_logb.c libm/common/s_lrint.c libm/common/s_lround.c libm/common/s_modf.c libm/common/s_nan.c libm/common/s_nearbyint.c libm/common/s_nextafter.c libm/common/s_pow10.c libm/common/s_rint.c libm/common/s_round.c libm/common/s_scalbln.c libm/common/s_scalbn.c libm/common/s_trunc.c libm/common/sf_cbrt.c libm/common/sf_copysign.c libm/common/sf_exp10.c libm/common/sf_expm1.c libm/common/sf_finite.c libm/common/sf_ilogb.c libm/common/sf_infinity.c libm/common/sf_isinf.c libm/common/sf_isnan.c libm/common/sf_llrint.c libm/common/sf_llround.c libm/common/sf_log1p.c libm/common/sf_logb.c libm/common/sf_lrint.c libm/common/sf_lround.c libm/common/sf_modf.c libm/common/sf_nan.c libm/common/sf_nearbyint.c libm/common/sf_nextafter.c libm/common/sf_pow10.c libm/common/sf_rint.c libm/common/sf_round.c libm/common/sf_scalbln.c libm/common/sf_scalbn.c libm/common/sf_trunc.c libm/ld/common/s_atanl.c libm/ld/common/s_ilogbl.c libm/ld/common/s_logbl.c libm/ld/common/s_scalbnl.c libm/ld/ld128/e_acoshl.c libm/ld/ld128/e_atanhl.c libm/ld/ld128/e_coshl.c libm/ld/ld128/e_fmodl.c libm/ld/ld128/e_hypotl.c libm/ld/ld128/e_powl.c libm/ld/ld128/e_sinhl.c libm/ld/ld128/s_asinhl.c libm/ld/ld128/s_ceill.c libm/ld/ld128/s_copysignl.c libm/ld/ld128/s_erfl.c libm/ld/ld128/s_floorl.c libm/ld/ld128/s_modfl.c libm/ld/ld128/s_nextafterl.c libm/ld/ld128/s_nexttoward.c libm/ld/ld128/s_nexttowardf.c libm/ld/ld128/s_tanhl.c libm/ld/ld128/s_truncl.c libm/ld/ld80/e_acoshl.c libm/ld/ld80/e_atanhl.c libm/ld/ld80/e_coshl.c libm/ld/ld80/e_hypotl.c libm/ld/ld80/e_lgammal_r.c libm/ld/ld80/e_sinhl.c libm/ld/ld80/s_asinhl.c libm/ld/ld80/s_ceill.c libm/ld/ld80/s_copysignl.c libm/ld/ld80/s_erfl.c libm/ld/ld80/s_floorl.c libm/ld/ld80/s_modfl.c libm/ld/ld80/s_nextafterl.c libm/ld/ld80/s_nexttoward.c libm/ld/ld80/s_nexttowardf.c libm/ld/ld80/s_tanhl.c libm/ld/ld80/s_truncl.c libm/ld/math_private_openbsd.h libm/math/k_cos.c libm/math/k_rem_pio2.c libm/math/k_sin.c libm/math/k_tan.c libm/math/kf_cos.c libm/math/kf_sin.c libm/math/kf_tan.c libm/math/math.tex libm/math/s_acos.c libm/math/s_acosh.c libm/math/s_asin.c libm/math/s_asinh.c libm/math/s_atan.c libm/math/s_atan2.c libm/math/s_atanh.c libm/math/s_ceil.c libm/math/s_cos.c libm/math/s_cosh.c libm/math/s_drem.c libm/math/s_erf.c libm/math/s_exp.c libm/math/s_exp2.c libm/math/s_fabs.c libm/math/s_floor.c libm/math/s_fmod.c libm/math/s_frexp.c libm/math/s_gamma.c libm/math/s_hypot.c libm/math/s_j0.c libm/math/s_j1.c libm/math/s_jn.c libm/math/s_log.c libm/math/s_log10.c libm/math/s_pow.c libm/math/s_rem_pio2.c libm/math/s_remainder.c libm/math/s_scalb.c libm/math/s_signif.c libm/math/s_sin.c libm/math/s_sinh.c libm/math/s_sqrt.c libm/math/s_tan.c libm/math/s_tanh.c libm/math/s_tgamma.c libm/math/sf_acos.c libm/math/sf_acosh.c libm/math/sf_asin.c libm/math/sf_asinh.c libm/math/sf_atan.c libm/math/sf_atan2.c libm/math/sf_atanh.c libm/math/sf_ceil.c libm/math/sf_cos.c libm/math/sf_cosh.c libm/math/sf_drem.c libm/math/sf_erf.c libm/math/sf_exp.c libm/math/sf_exp2.c libm/math/sf_fabs.c libm/math/sf_floor.c libm/math/sf_fmod.c libm/math/sf_frexp.c libm/math/sf_gamma.c libm/math/sf_hypot.c libm/math/sf_j0.c libm/math/sf_j1.c libm/math/sf_jn.c libm/math/sf_lgamma.c libm/math/sf_log.c libm/math/sf_log10.c libm/math/sf_log2.c libm/math/sf_pow.c libm/math/sf_remainder.c libm/math/sf_scalb.c libm/math/sf_signif.c libm/math/sf_sin.c libm/math/sf_sinh.c libm/math/sf_sqrt.c libm/math/sf_tan.c libm/math/sf_tanh.c libm/math/sf_tgamma.c libm/math/sr_lgamma.c libm/math/srf_lgamma.c Copyright: 1993 Sun Microsystems, Inc. License: Other-24 Files: libm/common/s_remquo.c libm/common/sf_remquo.c libm/ld/common/e_acosl.c libm/ld/common/e_asinl.c libm/ld/common/e_atan2l.c libm/ld/common/e_lgammal.c libm/ld/common/k_rem_pio2.c libm/ld/ld128/s_remquol.c libm/ld/ld80/e_fmodl.c libm/ld/ld80/s_remquol.c Copyright: 1993 Sun Microsystems, Inc. License: Other-25 Files: libm/ld/ld128/k_cosl.c libm/ld/ld128/k_sinl.c libm/ld/ld80/k_cosl.c libm/ld/ld80/k_sinl.c Copyright: 1993 Sun Microsystems, Inc. 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. License: Other-25 Files: libm/ld/common/s_cbrtl.c Copyright: 1993 Sun Microsystems, Inc. 2009-2011, Bruce D. Evans, Steven G. Kargl, David Schultz. License: Other-26 Files: libm/ld/ld128/e_rem_pio2l.h libm/ld/ld80/e_rem_pio2l.h Copyright: 1993 Sun Microsystems, Inc. 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. License: Other-27 Files: libm/machine/x86/f_llrint.c libm/machine/x86/f_llrintf.c libm/machine/x86/f_llrintl.c libm/machine/x86/f_lrint.c libm/machine/x86/f_lrintf.c libm/machine/x86/f_lrintl.c libm/machine/x86/f_rint.c libm/machine/x86/f_rintf.c libm/machine/x86/f_rintl.c Copyright: 2007 Dave Korn License: Other-28 Files: libc/machine/d10v/setjmp.S libc/machine/d30v/setjmp.S libc/machine/fr30/setjmp.S libc/machine/h8300/defines.h libc/machine/h8300/memcpy.S libc/machine/h8300/memset.S libc/machine/h8300/reg_memcpy.S libc/machine/h8300/reg_memset.S libc/machine/h8300/setjmp.S libc/machine/h8300/strcmp.S libc/machine/h8500/cmpsi.c libc/machine/h8500/divhi3.S libc/machine/h8500/divsi3.c libc/machine/h8500/mulhi3.c libc/machine/h8500/mulsi3.c libc/machine/h8500/negsi2.c libc/machine/h8500/psi.S libc/machine/h8500/setjmp.S libc/machine/h8500/shifts.c libc/machine/hppa/DEFS.h libc/machine/m32r/setjmp.S libc/machine/m68k/setjmp.S libc/machine/m68k/strcpy.c libc/machine/m68k/strlen.c libc/machine/m88k/setjmp.S libc/machine/mips/setjmp.S libc/machine/mn10200/setjmp.S libc/machine/mn10300/memchr.S libc/machine/mn10300/memcmp.S libc/machine/mn10300/memcpy.S libc/machine/mn10300/memset.S libc/machine/mn10300/setjmp.S libc/machine/mn10300/strchr.S libc/machine/mn10300/strcmp.S libc/machine/mn10300/strcpy.S libc/machine/mn10300/strlen.S libc/machine/necv70/fastmath.S libc/machine/necv70/machine/registers.h libc/machine/necv70/setjmp.S libc/machine/powerpc/setjmp.S libc/machine/sh/asm.h libc/machine/sh/setjmp.S libc/machine/sparc/machine/sparclet.h libc/machine/sparc/scan.c libc/machine/sparc/shuffle.c libc/machine/tic80/setjmp.S libc/machine/v850/setjmp.S libc/machine/w65/cmpsi.c libc/machine/w65/divsi3.c libc/machine/w65/lshrhi.S libc/machine/w65/mulsi3.c libc/machine/w65/sdivhi3.S libc/machine/w65/smulhi3.S libc/machine/w65/udivhi3.S libc/machine/w65/umodhi3.S libc/machine/x86/i386mach.h libc/machine/z8k/args.h libc/machine/z8k/setjmp.S libc/stdio/fgetpos.c libc/stdio/fsetpos.c Copyright: 1990 The Regents of the University of California. License: UCB-1 Files: libc/stdio/sflags.c Copyright: 1990 Regents of the University of California. License: UCB-1 Files: libc/stdio/mktemp.c libc/stdlib/setenv.c Copyright: 1987 Regents of the University of California. License: UCB-2 Files: libc/stdlib/getenv.c Copyright: 1987, 2000 Regents of the University of California. License: UCB-2 Files: libc/stdlib/putenv.c Copyright: 1988 The Regents of the University of California. License: UCB-2 License: AGPL3-1 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. . This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. . You should have received a copy of the GNU Affero General Public License along with this program. If not, see . License: BSD2-1 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must 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. License: BSD2-2 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD2-3 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD2-4 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD2-5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD2-6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must 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 License: BSD2-7 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TENSILICA INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD2-8 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD2-9 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD2-10 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD2-11 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice unmodified, this list of conditions, and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD2-12 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must 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 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 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. License: BSD3-1 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-2 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-3 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-4 All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. . Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 4. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of Sun Microsystems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-7 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-8 All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. . Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 4. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-9 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the company may not be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-10 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-11 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the company nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-12 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-13 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . Neither the name of Linaro Limited nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-14 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of Adapteva nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-15 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-16 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . 1. Redistributions source code must retain the above copyright notice, this list of conditions and the following disclaimer. . 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . 3. Neither the name of Xilinx nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-17 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of MIPS Technologies Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-18 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the MIPS Technologies, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-19 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the MIPS Technologies, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY IMAGINATION TECHNOLOGIES LIMITED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IMAGINATION TECHNOLOGIES LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-20 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . The name of the company may not be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-21 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . o Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. o Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. o Neither the name of Altera Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY ALTERA CORPORATION, THE COPYRIGHT HOLDER, AND ITS CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-22 This software was developed by the Computer Systems Engineering group at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and contributed to Berkeley. . Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-23 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-24 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the names of Toshiba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-25 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-26 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . Neither the name of Texas Instruments Incorporated nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-27 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of Rolls-Royce Controls and Data Services Limited nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-28 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-29 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-30 Rewritten in C by Soren Kuula Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-31 SPDX-License-Identifier: BSD-3-Clause . Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the company may not be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-32 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . 3. Neither the name of KTH nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-33 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of Mentor Graphics nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY CODESOURCERY, INC. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CODESOURCERY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-34 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer in this position and unchanged. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD3-35 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . Neither the name of IBM Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: Default-1 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: FreeBSD-1 This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. License: FreeBSD-2 This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. . Changes from Qualcomm Technologies, Inc. are provided under the following license: Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. SPDX-License-Identifier: BSD-3-Clause-Clear License: GPL2-1 This program is licensed under the GPL version 2 or later. Please see the file COPYING.GPL2 in this distribution for license terms. License: Other-1 Permission to use, copy, modify, and distribute this software is freely granted, provided that this notice is preserved. License: Other-2 Public domain. License: Other-3 This file and the accompanying getopt.c implementation file are hereby placed in the public domain without restrictions. Just give the author credit, don't claim you wrote it or prevent anyone else from using it. . Gregory Pietsch's current e-mail address: gpietsch@comcast.net License: Other-4 Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. . THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. License: Other-5 Redistribution, modification, and use in source and binary forms is permitted provided that the above copyright notice and following paragraph are duplicated in all such forms. . This file is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. License: Other-6 Permission to use, copy, modify, and distribute this software for any purpose without fee is hereby granted, provided that this entire notice is included in all copies of any software which is or includes a copy or modification of this software. . THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. License: Other-7 The authors hereby grant permission to use, copy, modify, distribute, and license this software and its documentation for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions. No written agreement, license, or royalty fee is required for any of the authorized uses. Modifications to this software may be copyrighted by their authors and need not follow the licensing terms described here, provided that the new terms are clearly indicated on the first page of each file where they apply. License: Other-8 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . 2. Neither the name of Axis Communications nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS CONTRIBUTORS AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AXIS COMMUNICATIONS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: Other-9 To anyone who acknowledges that this file is provided "AS IS" without any express or implied warranty: permission to use, copy, modify, and distribute this file for any purpose is hereby granted without fee, provided that the above copyright notice and this notice appears in all copies, and that the name of Hewlett-Packard Company not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Hewlett-Packard Company makes no representations about the suitability of this software for any purpose. License: Other-10 Intel hereby grants you permission to copy, modify, and distribute this software and its documentation. Intel grants this permission provided that the above copyright notice appears in all copies and that both the copyright notice and this permission notice appear in supporting documentation. In addition, Intel grants this permission provided that you prominently mark as "not part of the original" any modifications made to this software or documentation, and that the name of Intel Corporation not be used in advertising or publicity pertaining to distribution of the software or the documentation without specific, written prior permission. . Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY License: Other-11 This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the BSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. Any Red Hat trademarks that are incorporated in the source code or documentation are not subject to the BSD License and may only be used or replicated with the express permission of Red Hat, Inc. License: Other-12 The author hereby grant permission to use, copy, modify, distribute, and license this software and its documentation for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions. No written agreement, license, or royalty fee is required for any of the authorized uses. Modifications to this software may be copyrighted by their authors and need not follow the licensing terms described here, provided that the new terms are clearly indicated on the first page of each file where they apply. License: Other-13 Redistribution and use in source and binary forms is permitted provided that the above copyright notice and following paragraph are duplicated in all such forms. . This file is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. License: Other-14 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: . The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. . THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. License: Other-15 Permission to use, copy, modify, and distribute this file for any purpose is hereby granted without fee, provided that the above copyright notice and this notice appears in all copies. . This file is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. License: Other-16 Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. License: Other-17 The contents of this file may be used under the terms of the Apache License, Version 2.0. . See accompanying file LICENSE-Apache or copy at http://www.apache.org/licenses/LICENSE-2.0) . Alternatively, the contents of this file may be used under the terms of the Boost Software License, Version 1.0. See accompanying file LICENSE-Boost or copy at https://www.boost.org/LICENSE_1_0.txt) . Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. License: Other-18 You may redistribute unmodified or modified versions of this source code provided that the above copyright notice and this and the following conditions are retained. . This software is provided ``as is'', and comes with no warranties of any kind. I shall in no event be liable for anything that happens to anyone/anything when using this software. License: Other-19 Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that the copyright notice and this permission notice and warranty disclaimer appear in supporting documentation, and that the name of Lucent or any of its entities not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. . LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. License: Other-20 This file and the accompanying getopt.h header file are hereby placed in the public domain without restrictions. Just give the author credit, don't claim you wrote it or prevent anyone else from using it. . Gregory Pietsch's current e-mail address: gpietsch@comcast.net License: Other-21 Permission to use, copy, modify, and distribute this software for any purpose without fee is hereby granted, provided that this entire notice is included in all copies of any software which is or includes a copy or modification of this software and in all copies of the supporting documentation for such software. . THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. License: Other-22 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the above copyright notice, this condition statement, and the following disclaimer are retained in any redistributions of the source code. . 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. License: Other-23 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: . The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. . THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. License: Other-24 Developed at SunPro, a Sun Microsystems, Inc. business. Permission to use, copy, modify, and distribute this software is freely granted, provided that this notice is preserved. License: Other-25 Developed at SunSoft, a Sun Microsystems, Inc. business. Permission to use, copy, modify, and distribute this software is freely granted, provided that this notice is preserved. License: Other-26 Developed at SunPro, a Sun Microsystems, Inc. business. Permission to use, copy, modify, and distribute this software is freely granted, provided that this notice is preserved. . . The argument reduction and testing for exceptional cases was written by Steven G. Kargl with input from Bruce D. Evans and David A. Schultz. License: Other-27 Developed at SunSoft, a Sun Microsystems, Inc. business. Permission to use, copy, modify, and distribute this software is freely granted, provided that this notice is preserved. . . Optimized by Bruce D. Evans. License: Other-28 x87 FP implementation contributed to Newlib by Dave Korn, November 2007. This file is placed in the public domain. Permission to use, copy, modify, and distribute this software is freely granted. License: UCB-1 Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. License: UCB-2 Redistribution and use in source and binary forms are permitted provided that: (1) source distributions retain this entire copyright notice and comment, and (2) distributions including binaries display the following acknowledgement: ``This product includes software developed by the University of California, Berkeley and its contributors'' in the documentation or other materials provided with the distribution. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. picolibc-1.8.11/README.md000066400000000000000000001512531513574234600146660ustar00rootroot00000000000000# Picolibc Copyright © 2018-2023 Keith Packard Picolibc is library offering standard C library APIs that targets small embedded systems with limited RAM. Picolibc was formed by blending code from [Newlib](http://sourceware.org/newlib/) and [AVR Libc](https://www.nongnu.org/avr-libc/). Build status: * [![Linux](https://github.com/picolibc/picolibc/actions/workflows/linux.yml/badge.svg)](https://github.com/picolibc/picolibc/actions/workflows/linux.yml) * [![Zephyr](https://github.com/picolibc/picolibc/actions/workflows/zephyr.yml/badge.svg)](https://github.com/picolibc/picolibc/actions/workflows/zephyr.yml) * [![Coreboot](https://github.com/picolibc/picolibc/actions/workflows/coreboot.yml/badge.svg?branch=main)](https://github.com/picolibc/picolibc/actions/workflows/coreboot.yml) ## License Picolibc source comes from a variety of places and has a huge variety of copyright holders and license texts. While much of the code comes from Newlib, none of the GPL-related bits used to build the library are left in the repository, so all of the source code uses BSD-like licenses, a mixture of 2- and 3- clause BSD itself and a variety of other (mostly older) licenses with similar terms. There are two files used for testing printf, test/printf-tests.c and test/testcases.c which are licensed under the GPL version 2 or later. There is also a shell script, GeneratePicolibcCrossFile.sh which is licensed under the AGPL version 3 or later which is provided as a helper for people building the library, but not used by picolibc otherwise. The file COPYING.picolibc contains all of the current copyright and license information in the Debian standard machine-readable format. It was generated using the make-copyrights and find-copyright scripts. ## Supported Architectures Picolibc has integrated testing support for many architectures which is used to validate the code for all patch integration: * ARC (32- and 64- bit) * ARM (32- and 64- bit) * i386 (Native and Linux hosted, for testing) * LatticeMico32 * LoongArch * Motorola 68000 (m68k) * MIPS * MSP430 * Nios II * OpenRisc * Power9 * Renesas RX * RISC-V (both 32- and 64- bit) * SparcV8 (32 bit) * SuperH * x86_64 (Native and Linux hosted, for testing) * Xtensa ESP32 There is also build infrastructure and continuous build validation, but no integrated testing available for additional architectures: * Microblaze (32-bit, big and little endian) * Sparc64 * Xtensa (ESP8266, LX106) Supporting new architectures requires: 1. Add libc/machine/_architecture_ for architecture-specific libc bits. This should at least include setjmp/longjmp support as these cannot be performed in architecture independent code and are needed by libstdc++. If available, it should also include thread local storage setup code as libc/machine/_architecture_/tls.c; the build system looks for that file by name when determining if TLS is available. 2. Checking for atomic support for stdio. Picolibc requires atomics for ungetc to work correctly in a reentrant environment. By default, it stores them in 16-bit values, but some architectures only have 32-bit atomics. To avoid ABI issues, the size selected isn't detected automatically, instead it must be configured in libc/include/stdio.h. 3. If necessary, add libm/machine/_architecture_ for any architecture-specific math bits 4. picocrt/machine/_architecture_ source code and build bits for startup code needed for the architecture. Useful in all cases, but this is necessary to run tests under emulation if your platform can do that. 5. cross-_gcc-triple_.txt to configure the meson cross-compilation mechanism to use the right tools 6. do-_architecture_-configure to make testing the cross-compilation setup easier. 7. run-_architecture_ script to run tests under QEMU. Look at the ARM and RISC-V examples to get a sense of what this needs to do and how it gets invoked from the cross-_gcc-triple_.txt configuration file. ## Relation to newlib Picolibc includes a lot of code originally from newlib. However, it has been reformatted and restructured to make it easier to read and maintain going forward. Here's a list of some differences between picolibc and newlib: 1. Designed for and tested on 32- and 64- bit embedded systems. Newlib (and newlib-nano) are used on both embedded systems and Cygwin, with the bulk of the development focused on improving the Cygwin support. Because the Cygwin version needs to be very careful about ABI stability, many parts of the newlib code base are very difficult to change. Picolibc has no such constraints, so much work has been done to improve the ABI and API for use in embedded systems. 2. Stdio. Picolibc's stdio implementation borrows some code from AVR-Libc along with substantial new code. The goal is to remain compatible with relevant C and POSIX standards while using a very narrow API to the underlying system (it only requires getc and putc) along with doing no internal allocation and using a minimal amount of RAM. 3. Thread-local-storage support. Instead of creating a large data structure containing all possible thread-specific data, Picolibc uses the underlying TLS support from the compiler which only allocates the amount of per-thread storage needed to support the API called by the application. Typically, this means you use only 4 bytes for errno. 4. Integrated test suite. Along with dozens of new tests, picolibc includes tests from newlib and musl. These tests are run as a part of the patch review process and new code or bugfixes are expected to include tests that verify functionality and keep bugs from recurring. 5. Bare-metal startup code and linker scripts for many architectures. These may not support precisely what your application requires, but these provide a good basis for writing your own startup code and linker scripts. These are used to create bare-metal versions of the test suite which can then be run using QEMU. 6. Meson-based build system. This is largely used to avoid conflicts with the newlib autotools build system files, but a side effect is that the library builds very quickly. 7. Narrow and well-defined POSIX OS requirements. Portions of Picolibc which require underlying OS support are documented so that you will know which functions are necessary based on the API in use. In particular, picolibc requires no POSIX functions to support stdin/stdout/stderr, and instead requires only functions to get and put single characters to the target device. 8. Built-in semihosting support for many architectures. This allows you to take advantage of existing gdb, openocd and qemu semihosting support for things like debugging output even before you have a serial port working. 9. Clear BSD licensing. All non-BSD compatible library source code has been removed so that the status of the resulting library is not in question. ## Documentation Introductory documentation. Read these first: * [Building Picolibc](doc/build.md). Explains how to compile picolibc yourself. * [Using Picolibc](doc/using.md). Shows how to compile and link applications once you have picolibc built and installed. * [Linking with Picolibc.ld](doc/linking.md). Provides more details about the linking process. * [Hello World](hello-world/README.md). Build and run a stand-alone C application by following step-by-step instructions Detailed documentation. Use these to learn more details about how to use Picolibc: * [Picolibc initialization](doc/init.md) * [Operating System Support](doc/os.md). * [Printf and Scanf in Picolibc](doc/printf.md) * [Thread Local Storage](doc/tls.md) * [Re-entrancy and Locking](doc/locking.md) * [Selecting ctype implementation](doc/ctype.md) * [Picolibc as embedded source](doc/embedsource.md) * [Releasing Picolibc](doc/releasing.md) * [Copyright and license information](COPYING.picolibc) ## Releases ### Picolibc release 1.8.11 * Use __math_inexact to generate FE_INEXACT in several math functions. Thanks to Gergely Futo. * Support riscv '-mlarge' model in asm code. * Initialize riscv vector unit in startup code when present. * Improve arm32 A-profile operation in Thumb state. Thanks to Victor Campos. * Remove duplicate isinf and isnan declarations that were visible even when building with C++. Thanks to Mostafa Salman. * Improve accuracy of cacoshf for real inputs. Thanks to Ahmed Shehab. * Avoid use of float types in vfprintf to avoid unnecessary fpu register use. * Add missing pid_t and getdate_err declarations to time.h. * Implement getdate and getdate_r as required by POSIX. * Fix numerous minor bugs in strptime. * Test exception handling on m68k * Add Hexagon architecture support. Thanks to Kushal Pal. * Clean up RISC-V asm code integration. Thanks to Venkata Ramanaiah Nalamothu. * Add more math tests, including exhaustive binary 32 testing. * Improve cbrtf precision to within 1ulp. * Fix lgammaf for values between -0x1p-70 and -0x1p-64. * Add some missing stdint.h bits that are new in C23. * Improve accuracy of erfcf for values between 1.25 and 28. Improve performance for values between 0x1p-56 and 0x1p-26. * Fix memchr on targets with 16-bit int and 32-bit long (MSP430). * Mask needle with 0xff on rx version of memchr. * Add missing POSIX functionality in fnmatch to support character classes, equivalence classes and collating sequences. Limit fnmatch recursion for '*' operators to 16 levels. * Rename cross compile property 'libgcc' to 'librt' since we can now specify either libgcc or compiler-rt as run-time library. However, 'libgcc' is still supported for backward compatibility. * Fix bug in 32-bit riscv stpcpy which returned the wrong value. Improve performance slightly by avoiding duplicate memory reads of the tail of the string. * Make sure `__STDC_LIB_EXT1__` gets defined as appropriate. Thanks to Mostafa Salman. * Fix -long_option parsing in getopt_long_only. * Add strfmon and strfmon_l as required by POSIX. * Add dprintf and vdprintf as required by POSIX. * Improve JIS transcoding performance by building translation tables in both directions. * Fix a bunch of iconv bugs and improve POSIX conformance by supporting //IGNORE, //DISCARD and //TRANSLIT modes. * Reformat code with clang-format * Restructure directories, moving libc and libm to the top level and moving all tests under tests/. Remove stdio and malloc variants. * Add 'no-flash' crt0 variant, thanks to Kushal Pal. * Update minimum required meson version from 0.53 to 0.61. * Add -Dfstat-bufsiz option that uses fstat to select stdio buffer sizes. Thanks to Alexey Lapshin. * Rewrite __rem_pio2f. This new version is faster than the old while remaining API compatible and not using double datatypes. * Update libc/machine/riscv. Thanks to Yuriy Kolerov. * Fix the way the zicsr extension is enabled while building the crt0 code. Thanks to Yuriy Kolerov. * Avoid linking in malloc when using bufio with static FILEs. ### Picolibc release 1.8.10 * Add missing POSIX constants to limits.h. * Add Renesas RX support. Thanks to Duy Dguyen. * Update to Unicode 16.0. This matches glibc 2.41. * Add TLS support and testing on loongarch, m68k, or1k, powerpc and superh. * Fix a couple of strncpy bugs in ARC assembly code. * Clean up preprocessor symbols: remove unused symbols, rename picolibc.h symbols to use a __ prefix and not include PICOLIBC or NEWLIB in the names. * Detect compiler attributes and builtins at compile time rather than configure time where possible. Delete attributes and builtins not used within the library implementation. * Remove non-standard elf.h and mstats API. * Clean up float predicates to make sure we provide implementations of isinf, isnan and finite for all three types, both with and without __ prefixes. Use symbol aliases to share the same function implementation. Use the __ versions for the type generic macros instead of fpclassify. Switch users of these within the math library to use the type-generic versions. * Start SuperH FPU in single mode when required. * Test sh1 and sh2 targets using the binutils simulator. * Initialize PowerPC IPLT table at startup. * Switch printf/scanf aliases to prefer --printf=/--scanf= compiler options * Control UCS-2 and UCS-4 locales with mb-ucs-charsets configuration option. * Add stdio-locking option to provide full POSIX re-entrancy support in tinystdio. Thanks to Alexey Lapshin. * Add wcsto* string to number functions using tinystdio conversion code. Avoids malloc call for float conversions. * Add TLS API support for x86 targets. Thanks to TK Chia. * Add -fsanitize=undefined handlers and make library build with that enabled. ### Picolibc release 1.8.9 * Use common clang/gcc feature detection macros on arm. * Additional clang/compiler-rt work-arounds for arm which is less consistent in handling exceptions. * Use clang multilib support for aarch64 * Build fix on arc which would build two strchr versions in release mode. * Add picocrt and semihost support for xtensa. Test xtensa dc233c. * Add C11's header and implementation. * Add nano-malloc-clear-freed option to erase memory released in free or realloc. * Add memset_explicit from C23. * Work around broken clang builtin malloc which fails to set errno. * Widen C++ _CTYPE_DATA array to fix mis-classification of \t; C++ requires bitmasks for all ctype operations, and 8 bits is not enough. Thanks to M-Moawad. * Update case conversion tables to Unicode 15.1.0 * Fix documentation formatting. Thanks to Eduard Tanase. * Fix support for using long-long vfprintf version by default. Thanks to Louis Peens. * Remove arm unaligned memcpy asm code. This couldn't support targets that only supported unaligned access. Use a new faster C version for this case. * Add asnprintf and vasnprintf as provided by newlib * Support ARM's FVP emulator. Thanks to Oliver Stannard. * Remove arc strlen asm code as it would access memory *before* the provided buffer and fall afoul of the stack bounds checking hardware. * Support --printf={d,f,l,i,m} in place of -DPICOLIBC_*_PRINTF_SCANF. This is the syntax proposed in the patches submitted to gcc for picolibc support. * Add LoongArch support, including testing. Thanks to Jiaxun Yang. * Use new picolibc-ci-tools project which builds custom toolchain bits automatically. Thanks to Jiaxun Yang. * Add OpenRisc support, including testing. Thanks to Joel Holdsworth. * Add Lattic3Mico32 support, including testing. Thanks to Jiaxun Yang. * Add MIPS semihosting support. Thanks to Jiaxun Yang. * Add older GCC compiler support, including versions < 4.4. Thanks to Joel Holdsworth. * Add coreboot configurations and tests. Thanks to Jeremy Bettis and Jon Murphy. * Fix numerous charset conversion errors for non-Unicode locales. * Make sure malloc return is aligned by using max_align_t. Thanks to Alex Richardson. * Replace iconv and locale implementations with smaller code offering the same locale functionality as before while the iconv code shares the same charset support as the locale code instead of having a completely separate implementation. ### Picolibc release 1.8.8 * Fixed 3 bugs in the powf computation. Thanks to Fabian Schriever. * Fixed a bunch of build issues found by Zephyr. * Improve C++ testing and compatibility. ### Picolibc release 1.8.7 * Support ARM v8.1-m BTI and PAC features * Fix stdio buffered backend automatic flushing of stdout when reading stdin. * Support _FORTIFY_SOURCE=3 * Fix several fesetround implementations to return an error when passed an invalid argument. Thanks to Abdallah Abdelhafeez. * Document headers which the compiler must provide. Thanks to Alexey Brodkin. * Generate mktemp/tmpnam filenames using random() so they don't repeat even if they aren't used before another name is generated. * Set error flag when fgetc is called on an file without read mode. Thanks to Mohamed Moawad. * Add type casting to CMPLX, CMPLXF and CMPLXL macros (as glibc does). Thanks to Mostafa Salman. * Add mips64 support and build the library during CI. * Make fgets return any accumulated string on EOF instead of always returning NULL. Thanks to Hana Ashour. * Use C99 minimum array size in asctime_r and ctime_r API declarations ('[static 26]'). Bounds check the generated value and return NULL/EOVERFLOW on overflow. * Make Zephyr's -Oz cmake option enable PREFER_SIZE_OVER_SPEED. Thanks to Jonathon Penix. * Add funopen to tinystdio. * Validate all public headers with a C++ compiler to make sure they at least compile successfully. Fix time.h. * Stop using -include picolibc.h during library build. * Add -Wmissing-declarations and -Wmissing-prototypes to library build flags. Fix a rather large pile of missing prototypes caused by source files failing to add _GNU_SOURCE or _DEFAULT_SOURCE definitions. * Add POSIX "unlocked" I/O functions to tinystdio. These don't actually do anything because tinystdio doesn't do any locking. However, flockfile/funlockfile grab the global C library lock so applications synchronizing with that API will "work". * Fix wide orientation handling in tinystdio. Thanks to Ahmed Shehab. * Add aarch64 soft float support for armv8. Clang allows this with -march=armv8-a+nofp -mabi=aapcs-soft. This required building a custom toolchain that included a compiler-rt library built with the right options. * Add fgetpos and fsetpos to tinystdio. Thanks to Hana Ashour. * Restore missing members of 'struct sigevent'. Over eager removal of _POSIX_THREADS support caused these to be accidentally deleted some time ago. * Test on i386 native target. * Fix hex float scanning and printing. Thanks to Hana Ashour and Ahmed Shehab. * Fix double rounding in %f printf. Thanks to Ahmed Shehab for constructing a test case that identified the issue. * Add mem_align to the "big" malloc version. Thanks to Simon Tatham. * Adjust POSIX and C headers to limit symbol exposure to that specified in the standards. * Fix rounding in float scanf. This does round twice for input longer than the required number of digits, but that's permitted by the C specification. * Support %a/%A in scanf. Support arbitrary precision in %a/%A printf. Fix NaN/INF formatting in %a/%A printf. Thanks to Ahmed Shehab. * Provide a build-time option to enable %n in printf. This is disabled by default for security concerns, but supported in case someone needs strict C conformance. Thanks to Ahmed Shehab. * Make freopen clear the unget buffer. Thanks to Mostafa Salman. * Fix wide and multi-byte character support in printf and scanf. For strict standards conformance, there's now an option that enables %lc/%ls in printf even if multi-byte support is not enabled. * Enable MMU in picocrt on A profile ARM and AARCH64 targets when present. This is required by the latest qemu which now more accurately emulates this hardware. Thanks to Alex Richardson. * Fix AARCH64 asm code in ILP32 mode. * Parse NaN() in sscanf. This is required by the standard, although picolibc doesn't do anything with . Thanks to Mohamed Moawad. * Clean up header files. Picolibc tries to limit symbol definitions to those specified in the C and POSIX specs. * Add support for C's Annex K functions. These are bounds-checking versions of various memory and string functions. Thanks to Mostafa Salman. * Perform locale string validation in newlocale even when _MB_CAPABLE isn't defined. Thanks to Mostafa Salman. * Place compiler-rt library after C library when linking tests. Thanks to Oliver Stannard. ### Picolibc version 1.8.6 * Fix some FORTITY_SOURCE issues with tinystdio * Add __eh_* symbols to picolibc.ld for LLVM libunwind. Thanks Alex Richardson. * Merge in newlib annual release (4.4.0). Some minor updates to aarch64 assembly code formatting (thanks to Sebastian Huber) and a few other fixes. * Enable 32-bit SPARC for testing. * Fix a bunch of fmemopen bugs and add some tests. Thanks to Alex Richardson. * Finish support for targets with unusual float types, mapping target types to 32-, 64-, 80- and 128- bit picolibc code. * Add SuperH support, including testing infrastructure. Thanks to Adrian Siekierka for help with this. * Improve debugger stack trace in risc-v exception code. Thanks to Alex Richardson. * Add an option (-Dfast-bufio=true) for more efficient fread/fwrite implementations when layered atop bufio. Thanks for the suggestion from Zachary Yedidia. * Fix cmake usage of FORMAT_ variables (note the lack of a leading underscore). * Remove explicit _POSIX_C_SOURCE definition in zephyr/zephr.cmake. * Clean up public inline functions to share a common mechanism for using gnu_inline semantics. Fix isblank. This ensures that no static inline declarations exist in public API headers which are required to be external linkage ("real") symbols. * Create an alternate ctype implementation that avoids using the _ctype_ array and just does direct value comparisons. This only works when picolibc is limited to ASCII. Applications can select whether they want this behavior at application compilation time without needing to rebuild the C library. Thanks to P. Frost for the suggestion. * Unify most fenv implementations to use gnu_inline instead of regular functions to improve performance. x86 was left out because those fenv functions are complicated by the mix of 8087 and modern FPU support. * Add a separate FILE for stderr when using POSIX I/O. Split stdin/stdout/stderr into three files to avoid pulling in those which aren't used. Thanks to Zachary Yedidia. ### Picolibc version 1.8.5 * Detect clang multi-lib support correctly by passing compiler flags. Thanks to xbjfk for identifying the problem. * Create a new 'long-long' printf variant. This provides enough variety to satisfy the Zephyr cbprintf options without needing to build the library from scratch. * Adjust use of custom binary to decimal conversion code so that it is only enabled for types beyond the register size of the target. This avoids the cost of this code when the application is already likely to be using the soft division routines. ### Picolibc version 1.8.4 * Make math overflow and underflow handlers respect rounding modes. * Add full precision fma/fmaf fallbacks by adapting the long-double code which uses two floats/doubles and some careful exponent management to ensure that only a single rounding operation occurs. * Fix more m68k 80-bit float bugs * Fix m68k asm ABI by returning pointers in %a0 and %d0 * Use an m68k-unknown-elf toolchain for m68k testing, including multi-lib to check various FPU configurations on older and more modern 68k targets. * Improve CI speed by using ccache on zephyr and mac tests, compressing the docker images and automatically canceling jobs when the related PR is updated. Thanks to Peter Jonsson. * Move a bunch of read-only data out of RAM and into flash by adding 'const' attributes in various places. * Add a new linker symbol, `__heap_size_min`, which specifies a minimum heap size. The linker will emit an error if this much space is not available between the end of static data and the stack. * Fix a bunch of bugs on targets with 16-bit int type. Thanks to Peter Jonsson for many of these. * Work around a handful of platform bugs on MSP430. I think these are compiler bugs as they occur using both the binutils simulator and mspsim. * Run tests on MSP430 using the simulator that comes with gdb. Thanks to Peter Jonsson for spliting tests apart to make them small enough to link in under 1MB. This requires a patch adding primitive semihosting to the simulator. * Provide a division-free binary to decimal conversion option for printf at friends. This is useful on targets without hardware divide as it avoids pulling in a (usually large) software implementation. This is controlled with the 'printf-small-ultoa' meson option and is 'false' by default. * Add 'minimal' printf and scanf variants. These reduce functionality by removing code that acts on most data modifers including width and precision fields and alternate presentation modes. A new config variable, minimal-io-long-long, controls whether that code supports long long types. * Add a 'assert-verbose' option which controls whether the assert macro is chatty by default. It is 'true' by default, which preserves the existing code, but when set to 'false', then a failing assert calls __assert_no_msg with no arguments, saving the memory usually occupied by the filename, function name and expression. * Fix arm asm syntax for mrc/mcr instructions to make clang happy. Thanks to Radovan Blažek for this patch. ### Picolibc version 1.8.3 * Fix bugs in floor and ceil implementations. * Use -fanalyzer to find and fix a range of issues. * Add __ubsan_handle_out_of_bounds implementation. This enables building applications with -fsanitize=bounds and -fno-sanitize-undefined-trap-on-error. * Validate exception configuration on targets with mixed exception support where some types have exceptions and others don't. Right now, that's only arm platforms where any soft float implementations don't build with exception support. * Fix bugs in nexttowards/nextafter on clang caused by the compiler re-ordering code and causing incorrect exception generation. * Use the small/slow string code when -fsanitize=address is used while building the library. This avoids reading beyond the end of strings and triggering faults. * Handle soft float on x86 and sparc targets. That mostly required disabling the hardware exception API, along with a few other minor bug fixes. * Add runtime support for arc, mips, nios2 and m68k. This enables CI testing on these architectures using qemu. * Fix 80-bit floating math library support for m68k targets. * Fix arm testing infra to use various qemu models that expand testing to all standard multi-lib configurations. * Adjust floating exception stubs to return success when appropriate, instead of always returning ENOSYS. * Make sure sNaN raises FE_INVALID and is converted to qNaN in truncl, frexpl and roundl * Avoid NaN result from fmal caused by multiply overflow when addend is infinity (-inf + inf results in NaN in that case). ### Picolibc version 1.8.2 * Support _ZEPHYR_SOURCE macro which, like _POSIX_SOURCE et al, controls whether the library expresses the Zephyr C library API. This is also automatically selected when the __ZEPHYR__ macro is defined and no other _*_SOURCE macro is defined. * Add another cross compile property, 'libgcc', which specifies the library containing soft float and other compiler support routines. * Fix a couple of minor imprecisions in pow and 80-bit powl. * Merge newlib changes that included an update to the ARM assembly code. * Replace inexact float/string conversion code with smaller code that doesn't use floating point operations to save additional space on soft float targets. * More cmake fixes, including making the inexact printf and locale options work. ### Picolibc version 1.8.1 * Fix cmake build system to auto-detect compiler characteristics instead of assuming the compiler is a recent version of GCC. This allows building using cmake with clang. * Fix cmake build system to leave out TLS support when TLS is disabled on the cmake command line. * Replace inline asm with attributes for __weak_reference macro * Add allocation attributes to malloc and stdio functions. This allows the compiler to detect allocation related mistakes as well as perform some additional optimizations. Bugs found by this change were also addressed. * Add wchar_t support to tinystdio, eliminating the last missing feature compared with the legacy stdio bits from newlib. With this, libstdc++ can be built with wide char I/O support, eliminating the last missing feature there as well. * Eliminate use of command line tools when building with a new enough version of meson. Thanks to Michael Platings. * Add Microblaze support. Thanks to Alp Sayin. * Switch semihosting to use binary mode when opening files. Thanks to Hardy Griech. * Build and install static library versions of the crt0 startup code. These allows developers to reference them as libraries on the command line instead of needing special compiler support to locate the different variants, which is useful when using clang. Thanks to Simon Tatham. * Simplify the signal/raise implementation to use a single global array of signal handlers and to not use getpid and kill, instead raise now directly invokes _exit. This makes using assert and abort simpler and doesn't cause a large TLS block to be allocated. Thanks to Joe Nelson for discovering the use of a TLS variable here. ### Picolibc version 1.8 With the addition of nearly complete long double support in the math library, it seems like it's time to declare a larger version increment than usual. * Improve arc and xtensa support, adding TLS helpers and other build fixes * Fix FPSCR state for Arm8.1-M low overhead loops (thanks to David Green) * Add -Werror=double-promotion to default error set and fix related errors. (thanks to Ryan McClelland) * Fix locking bug in malloc out-of-memory path and freeing a locked mutex in the tinystdio bufio code. These were found with lock debugging code in Zephyr. * Add some missing functions in tinystdio, strto*l_l, remove, tmpname/tmpfile which were published in stdio.h but not included in the library. * Switch read/write functions to use POSIX types instead of legacy cygwin types. This makes mapping to existing an POSIX api work right. * Add %b support to tinystdio printf and scanf. These are disabled by default as they aren't yet standardized. * Fix avr math function support. The avr version of gcc has modes where double and long double are 32 or 64 bits, so the math library code now detects all of that at compile time rather than build time and reconfigures the functions to match the compiler types. * Add nearly complete long double support from openlibm for 80-bit Intel and 128-bit IEEE values (in addition to supporting 64-bit long doubles). Still missing are Bessel functions and decimal printf/scanf support. * Add limited long double support for IBM 'double double' form. This is enough to run some simple tests, but doesn't have any significant math functions yet. * Get Power9 code running under qemu with OPAL. This was mostly needed to validate the big-endian and exception code for 128-bit long doubles, but was also used to validate the double double support. * Provide times() and sysconf() implementations in semihosting. You can now build and run the dhrystone benchmark without any further code. * Fix use of TLS variables with stricter alignment requirements in the default linker script and startup code. (thanks to Joakim Nohlgård and Alexander Richardson who found this issue while working on lld support). ### Picolibc version 1.7.9 * Support all Zephyr SDK targets * Support relocating the toolchain by using GCC_EXEC_PREFIX for sysroot-install when compiler doesn't use sysroot. * Add MIPS, SPARC and ARC support * Deal with RISC-V changes in gcc that don't reliably include zicsr * Support Picolibc as default C library with -Dsystem-libc option. With this, you can use picolibc without any extra compiler options. * Merge current newlib bits to get code that doesn't use struct _reent * Get rid of struct _reent in legacy stdio code * Support 16-bit int targets by fixing a few places assuming sizeof(int) == 4, object sizes not using size_t, wint_t for ucs-4 values * Add MSP430 support * Fix a couple of clang bugs (one on Cortex M0) * Support libc++ by adding non-standard mbstate_t.h * Merge i686 and x86_64 code to allow x86 multilib builds * Merge Xtensa newlib bits * Support Xtensa ESP32 targets * Add Nios II support ### Picolibc version 1.7.8 1. Fix el/ix level 4 code type errors 2. Fix out-of-source CMake build (thanks Max Behensky) 3. Improve build.md docs (thanks Kalle Raiskila) 4. Fix cmake build for various architectures 5. Initialize lock in fdopen 6. Remove %M from linker paths in single-arch builds 7. Shrink tinystdio vfprintf and vfscanf a bit 8. Use -fno-builtin-malloc -fno-builtin-free (GCC 12 compat) 9. Use -fno-builtin-copysignl (GCC 12 compat) 10. Add _zicsr to -march for risc-v picocrt (binutils 2.38 compat) 11. Add -no-warn-rwx-segments to link spec (binutils 2.38 compat) ### Picolibc version 1.7.7 1. Fix semihost gettimeofday, add a test. 2. Fix config option documentation. (Thanks to rdiez) 3. Document how re-entrant locking APIs are used. (Thanks to rdiez) 4. Fix some 16-bit int issues in tinystdio. (Thanks to Ayke van Laethem) 5. Make header files a bit more POSIX compliant, installing rpc headers, moving byte swapping macros to arpa/inet.h 6. Fix some stdio bugs found by Zephyr test suite: snprintf return value on buffer overflow, add ftello/fseeko, fputc return value, %0a formatting, clear EOF status after ungetc/fseek. 7. Re-do buffered I/O support to handle mixed read/write files correctly. This adds setbuf, setbuffer, setlinebuf, setvbuf. 8. Add fmemopen and freopen. 9. Add enough cmake support to allow Zephyr to build picolibc as a module using that, rather than meson. 10. Merge current newlib bits 11. Fix %p printf/scanf on ILP64 targets. ### Picolibc version 1.7.6 1. Fix use with C++ applications caused by a syntax error in picolibc.specs 2. Automatically include '-nostdlib' to options used while evaluating build rules to ensure tests work as expected. 3. Publish aarch64 inline math functions, ensure that inline fma functions work in installed applications for arm and risc-v. ### Picolibc version 1.7.5 1. Fix build on big-endian systems (thanks to Thomas Daede) 2. Add m68k support (thanks to Thomas Daede). 3. Fix build issues with ARM Cortex-a9 target (thanks to Ilia Sergachev). 4. Fix fwrite(x,0,y,z) in both tinystdio and legacy stdio. tinystdio returned the wrong value and legacy stdio caused a divide-by-zero fault. 5. Update Ryu code to match upstream (minor fixes) 6. Fix various __NEWLIB and __PICOLIBC macros; they were using a single leading underscore instead of two (thanks to Vincent Palatin). 7. Fix tinystdio error-handling bugs 8. Merge recent newlib changes (fixed ltdoa in legacy stdio) 9. Speed improvements for github CI system 10. Big-endian PowerPC support 11. Fail builds if most 'run_command' uses fail (thanks to Johan de Claville Christiansen) 12. Positional parameters in tinystdio. With this, I think tinystdio is feature complete. 13. Support for multiple build-styles of picolibc (minsize/release) in one binary package. This still requires separate meson runs. 14. Testing with glibc test code. This uncovered numerous bugs, mostly math errno/exception mistakes, but also a few serious bugs, including a couple of places where the nano-malloc failed to check for out-of-memory. Picolibc now passes all of the glibc math tests except for jn, yn, lgamma and tgamma. The picolibc versions of those functions are too inaccurate. Picolibc also passes most other relevant glibc tests, including stdio, string and stdlib areas. 15. Tinystdio version of fcvt now has a static buffer large enough to hold the maximum return size. 16. Tinystdio versions of ecvtbuf and fcvtbuf have been replaced with ecvt_r and fcvt_r equivalents, which take a 'len' parameter to prevent buffer overruns. 17. Add the GeneratePicolibcCrossFile.sh script which provides a way to isolate picolibc build scripts from the vagaries of meson version shifts (thanks to R. Diez). 18. Add 'semihost' version of crt0 that calls 'exit' after main returns. The ARM and RISC-V versions of this also include trap handlers for exceptions that print out information and exit when an exception occurs. ### Picolibc version 1.7.4 1. Clean up meson build bits, including use of 'fs module (thanks to Yasushi Shoji). 2. Speed up github actions by sharing Debian docker image (thanks to Yasushi Shoji). 3. Reduce use of intermediate static libraries during build 4. Use standard Meson architecture names everywhere (thanks to Yasushi Shoji). 5. Support building with -D_FORTIFY_SOURCE enabled. 6. Clean up 32-bit arm assembly code, eliminating __aeabi wrappers where possible. 7. Add basename, dirname and fnmatch back. 8. Fix all old-style (K&R) function definitions. 9. Enable lots more compiler warning flags. 10. Remove last uses of alloca in legacy stdio code. 11. Add tests from musl libc-testsuite. There aren't many tests, but these identified a few bugs. 12. Add lots more exception and errno tests for the math functions. 13. Restructure math library to always use the `__math_err` functions to raise exceptions and set errno. This removes the w_*.c wrapper functions and eliminates the `__ieee names`. This centralizes compiler work-arounds to ensure run-time evaluation of expressions intended to raise exceptions. In the process, all of the libm/math files were reformatted with clang-format. 14. Make tinystdio '%a' compatible with glibc, including supporting rounding and trimming trailing zeros when possible. 15. Remove floating point exception generation code on targets without floating point exception support. This reduces code size on soft float machines without affecting results. ### Picolibc version 1.7.3 1. Add -Wall -Wextra to default builds. Fixed warnings this raised. 2. Add htonl and friends (based on __htonl). Thanks to Johan de Claville Christiansen 3. Set errno in scalbn and scalbnf (patch forwarded to newlib). 4. Merge newlib recent changes which includes a couple of libm fixes. ### Picolibc version 1.7.2 1. Fix picolibc.ld to split C++ exceptions back apart (thanks to Khalil Estell) 2. Add vsscanf to tinystdio (required for libstdc++). 3. Also stick -isystem in C++ compile command to try and get picolibc headers to be used instead of newlib. ### Picolibc version 1.7.1 1. Add __cxa_atexit implementation to 'picoexit' path as required by C++ 2. Fix lack of 'hh' support in integer-only tinystdio printf path. 3. Fix tinystdio __file flag initialization for C++ apps ### Picolibc version 1.7 1. Merge libc and libm into a single library. Having them split doesn't offer any advantages while requiring that applications add '-lm' to link successfully. Having them merged allows use of libm calls from libc code. 2. Add hex float format to *printf, *scanf and strto{d,f,ld}. This is required for C99 support. 3. Unify strto{d,f,ld} and *scanf floating point parsing code. This ensures that the library is consistent in how floats are parsed. 4. Make strto{d,f,ld} set errno to ERANGE on overflow/underflow, including when the result is a subnormal number. ### Picolibc version 1.6.2 1. Change `restrict` keyword in published headers to `__restrict` to restore compatibility with applications building with --std=c18. 2. Additional cleanups in time conversion funcs (Thanks to R. Riez) ### Picolibc version 1.6.1 1. Code cleanups for time conversion funcs (Thanks to R. Diez) 2. Add '-fno-stack-protector' when supported by the C compiler to avoid trouble building with native Ubuntu GCC. 3. Bug fix for converting denorms with sscanf and strto{d,f,ld}. 4. Use __asm__ for inline asm code to allow building applications with --std=c18 5. Fix exit code for semihosting 'abort' call to make it visible to the hosting system. 6. Add strfromf and strfromd implementations. These are simple wrappers around sscanf, but strfromf handles float conversions without requiring a pass through 'double' or special linker hacks. ### Picolibc version 1.6 1. Bugfix for snprintf(buf, 0) and vsnprintf(buf, 0) to avoid smashing memory 2. Support building libstdc++ on top of picolibc 3. Add 'hosted' crt0 variant that calls exit when main returns. This makes testing easier without burdening embedded apps with unused exit processing code. 4. Add 'minimal' crt0 variant that skips constructors to save space on systems known to not use any. 5. Fix HW floating point initialization on 32-bit ARM processors to perform 'dsb' and 'isb' instructions to ensure the FPU enabling write is complete before executing any FPU instructions. 6. Create a new '--picolibc-prefix' GCC command line parameter that sets the base of all picolibc file names. 7. Add bare-metal i386 and x86_64 initializatiton code (thanks to Mike Haertel). These initalize the processor from power up to running code without requiring any BIOS. 8. Merge newlib as of late April, 2021 9. Add 'timegm' function (thanks to R. Diez). 10. Fix a number of tinystdio bugs: handle fread with size==0, parse 'NAN' and 'INF' in fscanf in a case-insensitive manner, fix negative precision to '*' arguments in printf, fix handling of 'j', 'z' and 't' argument size specifiers (thanks to Sebastian Meyer). 11. Make the fenv API more consistent and more conformant with the spec. All architectures now fall back to the default code for soft float versions, which avoids having the various exception and rounding modes get defined when not supported. ### Picolibc version 1.5.1 1. Make riscv crt0 '_exit' symbol 'weak' to allow linking without this function. ### Picolibc version 1.5 1. Make picolibc more compatible with C++ compilers. 2. Add GCC specs file and linker script for building C++ applications with G++ that enable exception handling by linking in call stack information. 3. A few clang build fixes, including libm exception generation 4. Nano malloc fixes, especially for 'unusual' arguments 5. Merge in newlib 4.1.0 code 6. More libm exception/errno/infinity fixes, mostly in the gamma funcs. 7. Add tests for all semihost v2.0 functions. 8. A few RISC-V assembly fixes and new libm code. 9. Build fixes to reliably replace generic code with architecture-specific implementations. With a patch which is pending for GCC 11, we'll be able to build C++ applications that use picolibc with exceptions and iostream. ### Picolibc version 1.4.7 1. Fix numerous libm exception and errno bugs. The math functions are all now verified to match the C19 and Posix standards in this area. 2. Change behavior of 'gamma' function to match glibc which returns lgamma for this function. Applications should not use this function, they should pick either lgamma or tgamma as appropriate. 3. Fix fma/fmaf on arm and RISC-V so that the machine-specific versions are used when the hardware has support. Also fix the math library to only use fma/fmaf when it is supported by the hardware. 4. Fix numerous nano-malloc bugs, especially with unusual parameters. 5. Change nano-malloc to always clear returned memory. 6. Improve nano-realloc to perform better in various ways, including merging adjacent free blocks and expanding the heap. 7. Add malloc tests, both a basic functional test and a stress test. 8. Improve build portability to Windows. Picolibc should now build using mingw. 9. Use hardware TLS register on ARM when available. 10. Support clang compiler. Thanks to Denis Feklushkin and Joakim Nohlgård . 11. Avoid implicit float/double conversions. Check this by having clang builds use -Wdouble-promotion -Werror=double-promotion flags 12. Have portable code check for machine-specific overrides by matching filenames. This avoids building libraries with duplicate symbols and retains compatibility with newlib (which uses a different mechanism for this effect). 13. Patches to support building with [CompCert](http://compcert.inria.fr/), a formally verified compiler. Thanks to Sebastian Meyer . ### Picolibc version 1.4.6 1. Install 'ssp' (stack smashing protection) header files. This fixes compiling with -D_FORTIFY_SOURCE. 2. Make getc/ungetc re-entrant. This feature, which is enabled by default, uses atomic instruction sequences that do not require OS support. 3. Numerous iconv fixes, including enabling testing and switching external CCS file loading to use stdio. By default, iconv provides built-in CCS data for all of the supported encodings, which takes a fairly large amount of read-only memory. Iconv is now always included in picolibc as it isn't included in applications unless explicitly referenced by them. 4. Add __getauxval stub implementation to make picolibc work with GCC version 10 compiled for aarch64-linux-gnu. 5. Change how integer- and float- only versions of printf and scanf are selected. Instead of re-defining the symbols using the C preprocessor, picolibc now re-defines the symbols at link time. This avoids having applications compiled with a mixture of modes link in multiple versions of the underlying functions, while still preserving the smallest possible integer-only implementation. 6. Document how to use picolibc on a native POSIX system for testing. Check out the [os.md](doc/os.md) file for details. 7. Merge current newlib bits in. This includes better fenv support, for which tests are now included in the picolibc test suite. ### Picolibc version 1.4.5 1. Fix section order in picolibc.ld to give applications correct control over the layout of .preserve, .init and .fini regions. 2. Add startup and TLS support for aarch64 and non Cortex-M 32-bit arm. ### Picolibc version 1.4.4 1. Fix floating point 'g' format output in tinystdio. (e.g., for 10.0, print '10' instead of '1e+01'). There are tests which verify a range of 'g' cases like these now. 2. Merge current newlib bits. The only thing which affects picolibc is the addition of fenv support for arm. ### Picolibc version 1.4.3 1. Make fix for CVE 2019-14871 - CVE 2019-14878 in original newlib stdio code not call 'abort'. Allocation failures are now reported back to the application. 2. Add 'exact' floating point print/scan code to tinystdio. Thanks to Sreepathi Pai for pointing me at the Ryu code by Ulf Adams. 3. Add regular expression functions from newlib. These were removed by accident while removing POSIX filesystem-specific code. 4. Make tinystdio versions of [efg]cvt functions. This means that the default tinystdio version of picolibc no longer calls malloc from these functions. 5. More clang-compatibility fixes. (Thanks to Denis Feklushkin) 6. Remove stdatomic.h and tgmath.h. (they should not be provide by picolibc) ### Picolibc version 1.4.2 1. Clang source compatibility. Clang should now be able to compile the library. Thanks to Denis Feklushkin for figuring out how to make this work. 2. aarch64 support. This enables the existing aarch64 code and provides an example configuration file for getting it built. Thanks for Anthony Anderson for this feature. 3. Testing on github on push and pull-request. For now, this is limited to building the library due to a bug in qemu. 4. Get newlib stdio working again. You can now usefully use Newlib's stdio. This requires a working malloc and is substantially larger than tinystdio, but has more accurate floating point input. This requires POSIX functions including read, write and a few others. 5. Fix long double strtold. The working version is only available when using tinystdio; if using newlib stdio, strtold is simply not available. 6. Improve tinystdio support for C99 printf/scanf additions. 7. Check for correct prefix when sysroot-install option is selected. The value of this option depends on how gcc was configured, and (alas) meson won't let us set it at runtime, so instead we complain if the wrong value was given and display the correct value. 8. Sync up with current newlib head. ### Picolibc version 1.4.1 This release contains an important TLS fix for ARM along with a few minor compatibility fixes 1. Make __aeabi_read_tp respect ARM ABI register requirements to avoid clobbering register contents during TLS variable use. 2. Use cpu_family instead of cpu in meson config, which is 'more correct' when building for a single cpu instead of multilib. 3. Make arm sample interrupt vector work with clang 4. Use __inline instead of inline in published headers to allow compiling with -ansi 5. Make 'naked' RISC-V _start function contain only asm statements as required by clang (and recommended by gcc). 6. Use -msave-restore in sample RISC-V cross-compile configuration. This saves text space. ### Picolibc version 1.4 This release was focused on cleaning up the copyright and license information. 1. Copyright information should now be present in every source file. 2. License information, where it could be inferred from the repository, was added to many files. 3. 4-clause BSD licenses were changed (with permission) to 3-clause 4. Fix RISC-V ieeefp.h exception bits 5. Merge past newlib 3.2.0 6. Add PICOLIBC_TLS preprocessor define when the library has TLS support ### Picolibc version 1.3 This release now includes tests, and fixes bugs found by them. 1. ESP8266 support added, thanks to Jonathan McDowell. 2. Numerous test cases from newlib have been fixed, and precision requirements adjusted so that the library now passes its own test suite on x86, RISC-V and ARM. 3. String/number conversion bug fixes. This includes fcvt/ecvt/gcvt shared with newlib and tinystdio printf/scanf 4. A few RISC-V ABI fixes, including setting the TLS base correctly, compiling with -mcmodel=medany, and enabling the FPU for libraries built to use it. 5. Semihosting updates, including adding unlink, kill and getpid (which are used by some tests). ### Picolibc version 1.2 This release includes important fixes in picolibc.ld and more semihosting support. 1. File I/O and clock support for semihosting. This enables fopen/fdopen support in tinystdio along with an API to fetch a real time clock value. 2. Fix picolibc.ld to not attempt to use redefined symbols for memory space definitions. These re-definitions would fail and the default values be used for system memory definitions. Instead, just use the ? : operators each place the values are needed. Linker scripts continue to mystify. 3. Expose library definitions in 'picolibc.h', instead of 'newlib.h' and '_newlib_version.h' 4. Define HAVE_SEMIHOST when semihosting support is available. This lets the 'hello-world' example do some semihost specific things. ### Picolibc version 1.1 A minor update from 1.0, this release includes: 1. semihost support. This adds console I/O and exit(3) support on ARM and RISC-V hosts using the standard semihosting interfaces. 2. Posix I/O support in tinystdio. When -Dposix-io=true is included in the meson command line (which is the default), tinystdio adds support for fopen and fdopen by using malloc, open, close, read, write and lseek. If -Dposix-console=true is also passed to meson, then picolibc will direct stdin/stdout/stderr to the posix standard file descriptors (0, 1, 2). 3. Merge recent upstream newlib code. This brings picolibc up to date with current newlib sources. 4. Hello world example. This uses a simple Makefile to demonstrate how to us picolibc when installed for ARM and RISC-V embedded processors. The resulting executables can be run under qemu. 5. Remove libm/mathfp directory. This experimental code never worked correctly anyways. ### Picolibc version 1.0 This is the first release of picolibc. Major changes from newlib include: 1. Remove all non-BSD licensed code. None of it was used in building the embedded library, and removing it greatly simplifies the license situation. 2. Move thread-local values to native TLS mechanism 3. Add smaller stdio from avr-libc, which is enabled by default 4. Switch build system to meson. This has two notable benefits; the first is that building the library is much faster, the second is that it isolates build system changes from newlib making merging of newlib changes much easier. 5. Add simple startup code. This can be used in environments that don't have complicated requirements, allowing small applications to avoid needing to figure this out. picolibc-1.8.11/cmake/000077500000000000000000000000001513574234600144605ustar00rootroot00000000000000picolibc-1.8.11/cmake/TC-arm-none-eabi.ld000066400000000000000000000165501513574234600177260ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ __flash = 0x00000000; __flash_size = 0x00400000; __ram = 0x20000000; __ram_size = 0x00200000; __stack_size = 4k; ENTRY(_start) /* * These values should be provided by the application. We'll include * some phony values here to make things link for testing */ MEMORY { flash (rxai!w) : ORIGIN = DEFINED(__flash) ? __flash : 0x10000000, LENGTH = DEFINED(__flash_size) ? __flash_size : 0x10000 ram (wxa!ri) : ORIGIN = DEFINED(__ram ) ? __ram : 0x20000000, LENGTH = DEFINED(__ram_size ) ? __ram_size : 0x08000 } PHDRS { text PT_LOAD; ram PT_LOAD; ram_init PT_LOAD; tls PT_TLS; } SECTIONS { PROVIDE(__stack = ORIGIN(ram) + LENGTH(ram)); .init : { KEEP (*(.text.init.enter)) KEEP (*(.data.init.enter)) KEEP (*(SORT_BY_NAME(.init) SORT_BY_NAME(.init.*))) } >flash AT>flash :text .text : { /* code */ *(.text.unlikely .text.unlikely.*) *(.text.startup .text.startup.*) *(.text .text.*) *(.gnu.linkonce.t.*) KEEP (*(.fini .fini.*)) __text_end = .; PROVIDE (__etext = __text_end); PROVIDE (_etext = __text_end); PROVIDE (etext = __text_end); /* read-only data */ *(.rdata) *(.rodata .rodata.*) *(.gnu.linkonce.r.*) *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata .srodata.*) *(.data.rel.ro .data.rel.ro.*) *(.got .got.*) /* Need to pre-align so that the symbols come after padding */ . = ALIGN(8); /* lists of constructors and destructors */ PROVIDE_HIDDEN ( __preinit_array_start = . ); KEEP (*(.preinit_array)) PROVIDE_HIDDEN ( __preinit_array_end = . ); PROVIDE_HIDDEN ( __init_array_start = . ); KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) KEEP (*(.init_array .ctors)) PROVIDE_HIDDEN ( __init_array_end = . ); PROVIDE_HIDDEN ( __fini_array_start = . ); KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) KEEP (*(.fini_array .dtors)) KEEP (*(.fini_array*)) PROVIDE_HIDDEN ( __fini_array_end = . ); } >flash AT>flash :text /* * Data values which are preserved across reset */ .preserve (NOLOAD) : { PROVIDE(__preserve_start__ = .); KEEP(*(SORT_BY_NAME(.preserve.*))) KEEP(*(.preserve)) PROVIDE(__preserve_end__ = .); } >ram AT>ram :ram .data : ALIGN_WITH_INPUT { *(.data .data.*) *(.gnu.linkonce.d.*) /* Need to pre-align so that the symbols come after padding */ . = ALIGN(8); PROVIDE( __global_pointer$ = . + 0x800 ); *(.sdata .sdata.* .sdata2.*) *(.gnu.linkonce.s.*) } >ram AT>flash :ram_init PROVIDE(__data_start = ADDR(.data)); PROVIDE(__data_source = LOADADDR(.data)); /* Thread local initialized data. This gets * space allocated as it is expected to be placed * in ram to be used as a template for TLS data blocks * allocated at runtime. We're slightly abusing that * by placing the data in flash where it will be copied * into the allocate ram addresses by the existing * data initialization code in crt0 */ .tdata : ALIGN_WITH_INPUT { *(.tdata .tdata.* .gnu.linkonce.td.*) PROVIDE(__data_end = .); PROVIDE(__tdata_end = .); } >ram AT>flash :tls :ram_init PROVIDE( __tls_base = ADDR(.tdata)); PROVIDE( __tdata_start = ADDR(.tdata)); PROVIDE( __tdata_source = LOADADDR(.tdata) ); PROVIDE( __tdata_source_end = LOADADDR(.tdata) + SIZEOF(.tdata) ); PROVIDE( __data_source_end = __tdata_source_end ); PROVIDE( __tdata_size = SIZEOF(.tdata) ); PROVIDE( __edata = __data_end ); PROVIDE( _edata = __data_end ); PROVIDE( edata = __data_end ); PROVIDE( __data_size = __data_end - __data_start ); PROVIDE( __data_source_size = __data_source_end - __data_source ); .tbss (NOLOAD) : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) PROVIDE( __tls_end = . ); PROVIDE( __tbss_end = . ); } >ram AT>ram :tls :ram PROVIDE( __bss_start = ADDR(.tbss)); PROVIDE( __tbss_start = ADDR(.tbss)); PROVIDE( __tbss_offset = ADDR(.tbss) - ADDR(.tdata) ); PROVIDE( __tbss_size = SIZEOF(.tbss) ); PROVIDE( __tls_size = __tls_end - __tls_base ); PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); PROVIDE( __arm64_tls_tcb_offset = MAX(16, __tls_align) ); /* * The linker special cases .tbss segments which are * identified as segments which are not loaded and are * thread_local. * * For these segments, the linker does not advance 'dot' * across them. We actually need memory allocated for tbss, * so we create a special segment here just to make room */ .tbss_space (NOLOAD) : { . = ADDR(.tbss); . = . + SIZEOF(.tbss); } >ram AT>ram :ram .bss (NOLOAD) : { *(.sbss*) *(.gnu.linkonce.sb.*) *(.bss .bss.*) *(.gnu.linkonce.b.*) *(COMMON) /* Align the heap */ . = ALIGN(8); __bss_end = .; } >ram AT>ram :ram PROVIDE( __non_tls_bss_start = ADDR(.bss) ); PROVIDE( __end = __bss_end ); PROVIDE( _end = __bss_end ); PROVIDE( end = __bss_end ); PROVIDE( __bss_size = __bss_end - __bss_start ); /* Make the rest of memory available for heap storage */ PROVIDE (__heap_start = __end); PROVIDE (__heap_end = __stack - (DEFINED(__stack_size) ? __stack_size : 0x800)); PROVIDE (__heap_size = __heap_end - __heap_start); /* Define a stack region to make sure it fits in memory */ .stack (NOLOAD) : { . += (DEFINED(__stack_size) ? __stack_size : 0x800); } >ram :ram /* Throw away C++ exception handling information */ /DISCARD/ : { *(.note .note.*) *(.eh_frame .eh_frame.*) *(.ARM.extab* .gnu.linkonce.armextab.*) *(.ARM.exidx*) } } /* * Check that sections that are copied from flash to RAM have matching * padding, so that a single memcpy() of __data_size copies the correct bytes. */ ASSERT( __data_size == __data_source_size, "ERROR: .data/.tdata flash size does not match RAM size"); picolibc-1.8.11/cmake/TC-clang-thumbv6m.cmake000066400000000000000000000020101513574234600206110ustar00rootroot00000000000000# the name of the target operating system set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_SYSTEM_PROCESSOR arm) # which compilers to use for C set(TARGET_COMPILE_OPTIONS -m32 -target thumbv6m-none-eabi -mfloat-abi=soft -nostdlib) set(CMAKE_C_COMPILER clang) # where is the target environment located set(CMAKE_FIND_ROOT_PATH /usr/bin) # adjust the default behavior of the FIND_XXX() commands: # search programs in the host environment set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # search headers and libraries in the target environment set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(__THREAD_LOCAL_STORAGE_API TRUE) set(TEST_RUNNER run-arm) set(PICOLIBC_LINK_FLAGS --ld-path=/usr/bin/arm-none-eabi-ld -L/usr/lib/gcc/arm-none-eabi/14.2.1/thumb/v6-m/nofp/ -L/usr/lib/gcc/arm-none-eabi/13.3.1/thumb/v6-m/nofp/ -L/usr/lib/gcc/arm-none-eabi/13.2.1/thumb/v6-m/nofp/ -Wl,-z,noexecstack -Wl,-no-enum-size-warning -T ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TC-arm-none-eabi.ld -lgcc) picolibc-1.8.11/cmake/TC-clang-thumbv7m.cmake000066400000000000000000000020101513574234600206120ustar00rootroot00000000000000# the name of the target operating system set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_SYSTEM_PROCESSOR arm) # which compilers to use for C set(TARGET_COMPILE_OPTIONS -m32 -target thumbv7m-none-eabi -mfloat-abi=soft -nostdlib) set(CMAKE_C_COMPILER clang) # where is the target environment located set(CMAKE_FIND_ROOT_PATH /usr/bin) # adjust the default behavior of the FIND_XXX() commands: # search programs in the host environment set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # search headers and libraries in the target environment set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(__THREAD_LOCAL_STORAGE_API TRUE) set(TEST_RUNNER run-arm) set(PICOLIBC_LINK_FLAGS --ld-path=/usr/bin/arm-none-eabi-ld -L/usr/lib/gcc/arm-none-eabi/14.2.1/thumb/v7-m/nofp/ -L/usr/lib/gcc/arm-none-eabi/13.3.1/thumb/v7-m/nofp/ -L/usr/lib/gcc/arm-none-eabi/13.2.1/thumb/v7-m/nofp/ -Wl,-z,noexecstack -Wl,-no-enum-size-warning -T ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TC-arm-none-eabi.ld -lgcc) picolibc-1.8.11/cmake/TC-microbit.ld000066400000000000000000000165501513574234600171240ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ __flash = 0x00000000; __flash_size = 0x00400000; __ram = 0x20000000; __ram_size = 0x00004000; __stack_size = 2k; ENTRY(_start) /* * These values should be provided by the application. We'll include * some phony values here to make things link for testing */ MEMORY { flash (rxai!w) : ORIGIN = DEFINED(__flash) ? __flash : 0x10000000, LENGTH = DEFINED(__flash_size) ? __flash_size : 0x10000 ram (wxa!ri) : ORIGIN = DEFINED(__ram ) ? __ram : 0x20000000, LENGTH = DEFINED(__ram_size ) ? __ram_size : 0x08000 } PHDRS { text PT_LOAD; ram PT_LOAD; ram_init PT_LOAD; tls PT_TLS; } SECTIONS { PROVIDE(__stack = ORIGIN(ram) + LENGTH(ram)); .init : { KEEP (*(.text.init.enter)) KEEP (*(.data.init.enter)) KEEP (*(SORT_BY_NAME(.init) SORT_BY_NAME(.init.*))) } >flash AT>flash :text .text : { /* code */ *(.text.unlikely .text.unlikely.*) *(.text.startup .text.startup.*) *(.text .text.*) *(.gnu.linkonce.t.*) KEEP (*(.fini .fini.*)) __text_end = .; PROVIDE (__etext = __text_end); PROVIDE (_etext = __text_end); PROVIDE (etext = __text_end); /* read-only data */ *(.rdata) *(.rodata .rodata.*) *(.gnu.linkonce.r.*) *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata .srodata.*) *(.data.rel.ro .data.rel.ro.*) *(.got .got.*) /* Need to pre-align so that the symbols come after padding */ . = ALIGN(8); /* lists of constructors and destructors */ PROVIDE_HIDDEN ( __preinit_array_start = . ); KEEP (*(.preinit_array)) PROVIDE_HIDDEN ( __preinit_array_end = . ); PROVIDE_HIDDEN ( __init_array_start = . ); KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) KEEP (*(.init_array .ctors)) PROVIDE_HIDDEN ( __init_array_end = . ); PROVIDE_HIDDEN ( __fini_array_start = . ); KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) KEEP (*(.fini_array .dtors)) KEEP (*(.fini_array*)) PROVIDE_HIDDEN ( __fini_array_end = . ); } >flash AT>flash :text /* * Data values which are preserved across reset */ .preserve (NOLOAD) : { PROVIDE(__preserve_start__ = .); KEEP(*(SORT_BY_NAME(.preserve.*))) KEEP(*(.preserve)) PROVIDE(__preserve_end__ = .); } >ram AT>ram :ram .data : ALIGN_WITH_INPUT { *(.data .data.*) *(.gnu.linkonce.d.*) /* Need to pre-align so that the symbols come after padding */ . = ALIGN(8); PROVIDE( __global_pointer$ = . + 0x800 ); *(.sdata .sdata.* .sdata2.*) *(.gnu.linkonce.s.*) } >ram AT>flash :ram_init PROVIDE(__data_start = ADDR(.data)); PROVIDE(__data_source = LOADADDR(.data)); /* Thread local initialized data. This gets * space allocated as it is expected to be placed * in ram to be used as a template for TLS data blocks * allocated at runtime. We're slightly abusing that * by placing the data in flash where it will be copied * into the allocate ram addresses by the existing * data initialization code in crt0 */ .tdata : ALIGN_WITH_INPUT { *(.tdata .tdata.* .gnu.linkonce.td.*) PROVIDE(__data_end = .); PROVIDE(__tdata_end = .); } >ram AT>flash :tls :ram_init PROVIDE( __tls_base = ADDR(.tdata)); PROVIDE( __tdata_start = ADDR(.tdata)); PROVIDE( __tdata_source = LOADADDR(.tdata) ); PROVIDE( __tdata_source_end = LOADADDR(.tdata) + SIZEOF(.tdata) ); PROVIDE( __data_source_end = __tdata_source_end ); PROVIDE( __tdata_size = SIZEOF(.tdata) ); PROVIDE( __edata = __data_end ); PROVIDE( _edata = __data_end ); PROVIDE( edata = __data_end ); PROVIDE( __data_size = __data_end - __data_start ); PROVIDE( __data_source_size = __data_source_end - __data_source ); .tbss (NOLOAD) : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) PROVIDE( __tls_end = . ); PROVIDE( __tbss_end = . ); } >ram AT>ram :tls :ram PROVIDE( __bss_start = ADDR(.tbss)); PROVIDE( __tbss_start = ADDR(.tbss)); PROVIDE( __tbss_offset = ADDR(.tbss) - ADDR(.tdata) ); PROVIDE( __tbss_size = SIZEOF(.tbss) ); PROVIDE( __tls_size = __tls_end - __tls_base ); PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); PROVIDE( __arm64_tls_tcb_offset = MAX(16, __tls_align) ); /* * The linker special cases .tbss segments which are * identified as segments which are not loaded and are * thread_local. * * For these segments, the linker does not advance 'dot' * across them. We actually need memory allocated for tbss, * so we create a special segment here just to make room */ .tbss_space (NOLOAD) : { . = ADDR(.tbss); . = . + SIZEOF(.tbss); } >ram AT>ram :ram .bss (NOLOAD) : { *(.sbss*) *(.gnu.linkonce.sb.*) *(.bss .bss.*) *(.gnu.linkonce.b.*) *(COMMON) /* Align the heap */ . = ALIGN(8); __bss_end = .; } >ram AT>ram :ram PROVIDE( __non_tls_bss_start = ADDR(.bss) ); PROVIDE( __end = __bss_end ); PROVIDE( _end = __bss_end ); PROVIDE( end = __bss_end ); PROVIDE( __bss_size = __bss_end - __bss_start ); /* Make the rest of memory available for heap storage */ PROVIDE (__heap_start = __end); PROVIDE (__heap_end = __stack - (DEFINED(__stack_size) ? __stack_size : 0x800)); PROVIDE (__heap_size = __heap_end - __heap_start); /* Define a stack region to make sure it fits in memory */ .stack (NOLOAD) : { . += (DEFINED(__stack_size) ? __stack_size : 0x800); } >ram :ram /* Throw away C++ exception handling information */ /DISCARD/ : { *(.note .note.*) *(.eh_frame .eh_frame.*) *(.ARM.extab* .gnu.linkonce.armextab.*) *(.ARM.exidx*) } } /* * Check that sections that are copied from flash to RAM have matching * padding, so that a single memcpy() of __data_size copies the correct bytes. */ ASSERT( __data_size == __data_source_size, "ERROR: .data/.tdata flash size does not match RAM size"); picolibc-1.8.11/cmake/TC-rx.cmake000066400000000000000000000014451513574234600164230ustar00rootroot00000000000000# the name of the target operating system set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_SYSTEM_PROCESSOR rx) # which compilers to use for C set(TARGET_COMPILE_OPTIONS -ffinite-math-only) set(CMAKE_C_COMPILER rx-zephyr-elf-gcc -nostdlib) # where is the target environment located set(CMAKE_FIND_ROOT_PATH /opt/rx-zephyr-elf) # adjust the default behavior of the FIND_XXX() commands: # search programs in the host environment set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # search headers and libraries in the target environment set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(__THREAD_LOCAL_STORAGE_API FALSE) set(__THREAD_LOCAL_STORAGE FALSE) set(TEST_RUNNER run-rx) set(PICOLIBC_LINK_FLAGS -nostartfiles -T ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TC-rx.ld -lgcc) picolibc-1.8.11/cmake/TC-rx.ld000066400000000000000000000257041513574234600157460ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ ENTRY(__start) /* * These values should be provided by the application. We'll include * some phony values here to make things link for testing */ MEMORY { fvector (rx!w) : ORIGIN = DEFINED(__fvector) ? __fvector : 0xffffff80, LENGTH = DEFINED(__fvector_size) ? __fvector_size : 0x00000080 flash (rx!w) : ORIGIN = DEFINED(___flash) ? ___flash : 0x01000000, LENGTH = DEFINED(___flash_size) ? ___flash_size : 0x00800000 ram (w!rx) : ORIGIN = DEFINED(___ram) ? ___ram : 0x01800000, LENGTH = DEFINED(___ram_size) ? ___ram_size : 0x00800000 } PHDRS { text_fvector PT_LOAD; text PT_LOAD; ram_init PT_LOAD; ram PT_LOAD; tls_init PT_TLS; tls PT_TLS; } SECTIONS { PROVIDE(___stack = ORIGIN(ram) + LENGTH(ram)); .fvector : { KEEP (*(.rodata.fvector*)) } >fvector AT>fvector :text_fvector .text : { /* code */ *(.literal.unlikely .text.unlikely .literal.unlikely.* .text.unlikely.*) *(.literal.startup .text.startup .literal.startup.* .text.startup.*) *(.literal .text .literal.* .text.* .opd .opd.* P P.*) *(.gnu.linkonce.t.*) KEEP (*(.fini .fini.*)) ___text_end = .; PROVIDE (___etext = ___text_end); PROVIDE (__etext = ___text_end); PROVIDE (_etext = ___text_end); /* Need to pre-align so that the symbols come after padding */ . = ALIGN(8); /* lists of constructors and destructors */ PROVIDE_HIDDEN ( ___preinit_array_start = . ); KEEP (*(.preinit_array)) PROVIDE_HIDDEN ( ___preinit_array_end = . ); PROVIDE_HIDDEN ( ___init_array_start = . ); KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) KEEP (*(.init_array .ctors)) PROVIDE_HIDDEN ( ___init_array_end = . ); PROVIDE_HIDDEN ( ___fini_array_start = . ); KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) KEEP (*(.fini_array .dtors)) KEEP (*(.fini_array*)) PROVIDE_HIDDEN ( ___fini_array_end = . ); } >flash AT>flash :text .rodata : { /* read-only data */ *(.rdata) *(.rodata .rodata.* C C.*) *(.gnu.linkonce.r.*) *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata .srodata.*) } >flash AT>flash :text PROVIDE(__pid_base = ADDR(.rodata)); .data.rel.ro : { /* data that needs relocating */ *(.data.rel.ro .data.rel.ro.*) } >flash AT>flash :text /* * Needs to be in its own segment with the PLT entries first * so that the linker will compute the offsets to those * entries correctly. */ .got : { *(.got.plt) *(.got) } >flash AT>flash :text .toc : { *(.toc .toc.*) } >flash AT>flash :text /* additional sections when compiling with C++ exception support */ /* .except_ordered : { *(.gcc_except_table *.gcc_except_table.*) *(.ARM.extab* .gnu.linkonce.armextab.*) } >flash AT>flash :text .eh_frame_hdr : { PROVIDE_HIDDEN ( ___eh_frame_hdr_start = . ); *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) PROVIDE_HIDDEN ( ___eh_frame_hdr_end = . ); } >flash AT>flash :text .eh_frame : { PROVIDE_HIDDEN ( ___eh_frame_start = . ); KEEP (*(.eh_frame .eh_frame.*)) PROVIDE_HIDDEN ( ___eh_frame_end = . ); } >flash AT>flash :text .except_unordered : { . = ALIGN(8); PROVIDE(___exidx_start = .); *(.ARM.exidx*) PROVIDE(___exidx_end = .); } >flash AT>flash :text */ /* * Data values which are preserved across reset */ .preserve (NOLOAD) : { PROVIDE(___preserve_start__ = .); KEEP(*(SORT_BY_NAME(.preserve.*))) KEEP(*(.preserve)) PROVIDE(___preserve_end__ = .); } >ram AT>ram :ram .data : ALIGN_WITH_INPUT { *(.data .data.* D D_1 D.* D_1.*) *(.gnu.linkonce.d.*) /* Need to pre-align so that the symbols come after padding */ . = ALIGN(8); PROVIDE( ___global_pointer$ = . + 0x800 ); PROVIDE( __gp = . + 0x8000); *(.sdata .sdata.* .sdata2.* D_2 D_2.*) *(.gnu.linkonce.s.*) } >ram AT>flash :ram_init PROVIDE(___data_start = ADDR(.data)); PROVIDE(___data_source = LOADADDR(.data)); /* Thread local initialized data. This gets * space allocated as it is expected to be placed * in ram to be used as a template for TLS data blocks * allocated at runtime. We're slightly abusing that * by placing the data in flash where it will be copied * into the allocate ram addresses by the existing * data initialization code in crt0. * BFD includes .tbss alignment when computing .tdata * alignment, but for ld.lld we have to explicitly pad * as it only guarantees usage as a TLS template works * rather than supporting this use case. */ .tdata : /* For ld.lld: ALIGN(___tls_align) */ ALIGN_WITH_INPUT { *(.tdata .tdata.* .gnu.linkonce.td.*) PROVIDE(___data_end = .); PROVIDE(___tdata_end = .); } >ram AT>flash :tls_init :ram_init PROVIDE( ___tls_base = ADDR(.tdata)); PROVIDE( ___tdata_start = ADDR(.tdata)); PROVIDE( ___tdata_source = LOADADDR(.tdata) ); PROVIDE( ___tdata_source_end = LOADADDR(.tdata) + SIZEOF(.tdata) ); PROVIDE( ___data_source_end = ___tdata_source_end ); PROVIDE( ___tdata_size = SIZEOF(.tdata) ); PROVIDE( ___edata = ___data_end ); PROVIDE( __edata = ___data_end ); PROVIDE( _edata = ___data_end ); PROVIDE( ___data_size = ___data_end - ___data_start ); PROVIDE( ___data_source_size = ___data_source_end - ___data_source ); .tbss (NOLOAD) : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) PROVIDE( ___tls_end = . ); PROVIDE( ___tbss_end = . ); } >ram AT>ram :tls :ram PROVIDE( ___bss_start = ADDR(.tbss)); PROVIDE( ___tbss_start = ADDR(.tbss)); PROVIDE( ___tbss_offset = ADDR(.tbss) - ADDR(.tdata) ); PROVIDE( ___tbss_size = SIZEOF(.tbss) ); PROVIDE( ___tls_size = ___tls_end - ___tls_base ); PROVIDE( ___tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); PROVIDE( ___tls_size_align = (___tls_size + ___tls_align - 1) & ~(___tls_align - 1)); PROVIDE( ___arm32_tls_tcb_offset = MAX(8, ___tls_align) ); PROVIDE( ___arm64_tls_tcb_offset = MAX(16, ___tls_align) ); /* * Unlike ld.lld, ld.bfd does not advance the location counter for * .tbss, but we actually need memory allocated for .tbss as we use * it for the initial TLS storage. * Create special section here just to make room. */ .tbss_space (NOLOAD) : { . = ADDR(.tbss); . = . + SIZEOF(.tbss); } >ram AT>ram :ram .bss (NOLOAD) : { *(.sbss* B_2 B_2.*) *(.gnu.linkonce.sb.*) *(.bss .bss.* B B_1 B.* B_1.*) *(.gnu.linkonce.b.*) *(COMMON) /* Align the heap */ . = ALIGN(8); ___bss_end = .; } >ram AT>ram :ram PROVIDE( ___non_tls_bss_start = ADDR(.bss) ); PROVIDE( ___end = ___bss_end ); __end = ___bss_end; PROVIDE( _end = ___bss_end ); PROVIDE( ___bss_size = ___bss_end - ___bss_start ); /* Make the rest of memory available for heap storage */ PROVIDE (___heap_start = ___end); PROVIDE (___heap_end = ___stack - (DEFINED(___stack_size) ? ___stack_size : 0x00001000)); PROVIDE (___heap_size = ___heap_end - ___heap_start); /* Allow a minimum heap size to be specified */ .heap (NOLOAD) : { . += (DEFINED(___heap_size_min) ? ___heap_size_min : 0); } >ram :ram /* Define a stack region to make sure it fits in memory */ .stack (NOLOAD) : { . += (DEFINED(___stack_size) ? ___stack_size : 0x00001000); } >ram :ram /* Throw away C++ exception handling information */ /DISCARD/ : { *(.note .note.*) *(.eh_frame .eh_frame.*) *(.ARM.extab* .gnu.linkonce.armextab.*) *(.ARM.exidx*) } /* Stabs debugging sections. */ .stab 0 : { *(.stab) } .stabstr 0 : { *(.stabstr) } .stab.excl 0 : { *(.stab.excl) } .stab.exclstr 0 : { *(.stab.exclstr) } .stab.index 0 : { *(.stab.index) } .stab.indexstr 0 : { *(.stab.indexstr) } .comment 0 : { *(.comment) } .gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) } /* DWARF debug sections. Symbols in the DWARF debugging sections are relative to the beginning of the section so we begin them at 0. */ /* DWARF 1. */ .debug 0 : { *(.debug) } .line 0 : { *(.line) } /* GNU DWARF 1 extensions. */ .debug_srcinfo 0 : { *(.debug_srcinfo) } .debug_sfnames 0 : { *(.debug_sfnames) } /* DWARF 1.1 and DWARF 2. */ .debug_aranges 0 : { *(.debug_aranges) } .debug_pubnames 0 : { *(.debug_pubnames) } /* DWARF 2. */ .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } .debug_abbrev 0 : { *(.debug_abbrev) } .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) } .debug_frame 0 : { *(.debug_frame) } .debug_str 0 : { *(.debug_str) } .debug_loc 0 : { *(.debug_loc) } .debug_macinfo 0 : { *(.debug_macinfo) } /* SGI/MIPS DWARF 2 extensions. */ .debug_weaknames 0 : { *(.debug_weaknames) } .debug_funcnames 0 : { *(.debug_funcnames) } .debug_typenames 0 : { *(.debug_typenames) } .debug_varnames 0 : { *(.debug_varnames) } /* DWARF 3. */ .debug_pubtypes 0 : { *(.debug_pubtypes) } .debug_ranges 0 : { *(.debug_ranges) } /* DWARF 5. */ .debug_addr 0 : { *(.debug_addr) } .debug_line_str 0 : { *(.debug_line_str) } .debug_loclists 0 : { *(.debug_loclists) } .debug_macro 0 : { *(.debug_macro) } .debug_names 0 : { *(.debug_names) } .debug_rnglists 0 : { *(.debug_rnglists) } .debug_str_offsets 0 : { *(.debug_str_offsets) } .debug_sup 0 : { *(.debug_sup) } .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) } } /* * Check that sections that are copied from flash to RAM have matching * padding, so that a single memcpy() of __data_size copies the correct bytes. */ ASSERT( ___data_size == ___data_source_size, "ERROR: .data/.tdata flash size does not match RAM size"); picolibc-1.8.11/cmake/TC-thumbv6m.cmake000066400000000000000000000014251513574234600175400ustar00rootroot00000000000000# the name of the target operating system set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_SYSTEM_PROCESSOR arm) # which compilers to use for C set(TARGET_COMPILE_OPTIONS -mthumb -march=armv6-m -mfloat-abi=soft) set(CMAKE_C_COMPILER arm-none-eabi-gcc -nostdlib) # where is the target environment located set(CMAKE_FIND_ROOT_PATH /usr/bin) # adjust the default behavior of the FIND_XXX() commands: # search programs in the host environment set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # search headers and libraries in the target environment set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(__THREAD_LOCAL_STORAGE_API TRUE) set(TEST_RUNNER run-arm) set(PICOLIBC_LINK_FLAGS -nostartfiles -T ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TC-microbit.ld -lgcc) picolibc-1.8.11/cmake/TC-thumbv7m.cmake000066400000000000000000000014321513574234600175370ustar00rootroot00000000000000# the name of the target operating system set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_SYSTEM_PROCESSOR arm) # which compilers to use for C set(TARGET_COMPILE_OPTIONS -mthumb -march=armv7-m -mfloat-abi=soft) set(CMAKE_C_COMPILER arm-none-eabi-gcc -nostdlib) # where is the target environment located set(CMAKE_FIND_ROOT_PATH /usr/bin) # adjust the default behavior of the FIND_XXX() commands: # search programs in the host environment set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # search headers and libraries in the target environment set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(__THREAD_LOCAL_STORAGE_API TRUE) set(TEST_RUNNER run-arm) set(PICOLIBC_LINK_FLAGS -nostartfiles -T ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TC-arm-none-eabi.ld -lgcc) picolibc-1.8.11/cmake/have-bitfields-in-packed-structs.c000066400000000000000000000003011513574234600230420ustar00rootroot00000000000000struct test { int part : 24; } __attribute__((packed)); static unsigned int foo(const struct test *p) { return p->part; } int main() { struct test x = { 12 }; return foo(&x); } picolibc-1.8.11/cmake/have-cc-inhibit-loop-to-libcall.c000066400000000000000000000002551513574234600225470ustar00rootroot00000000000000__attribute__((__optimize__("-fno-tree-loop-distribute-patterns"))) static int foo(int x) { return x + 1; } volatile int aa = 42; int main(void) { return foo(aa); } picolibc-1.8.11/cmake/have-complex.c000066400000000000000000000000231513574234600172070ustar00rootroot00000000000000double _Complex x; picolibc-1.8.11/cmake/picolibc.cmake000066400000000000000000000126771513574234600172630ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # # Add sources to libc, eliding any duplicate basenames function(picolibc_sources_flags flags) # Get current sources get_property(current_sources_real TARGET c PROPERTY SOURCES) get_property(current_sources_fake TARGET c PROPERTY SOURCES_FAKE) set(current_sources ${current_sources_real} ${current_sources_fake}) set(sources ${ARGN}) foreach(source IN LISTS ARGN) # Compare desired addition to existing sources using basenames get_filename_component(source_base "${source}" NAME_WLE) foreach(current IN LISTS current_sources) get_filename_component(current_base "${current}" NAME_WLE) if("${source_base}" STREQUAL "${current_base}") list(REMOVE_ITEM sources "${source}") endif() endforeach() endforeach() # Add all files that aren't duplicated target_sources(c PRIVATE ${sources}) # Set flags if specified if(flags) foreach(flag ${flags}) foreach(source ${sources}) set_property(SOURCE ${source} TARGET_DIRECTORY c APPEND PROPERTY COMPILE_OPTIONS ${flag}) endforeach() endforeach() endif() endfunction() function(picolibc_sources) picolibc_sources_flags(0 ${ARGN}) endfunction() function(picolibc_sources_fake) get_property(current_sources_fake TARGET c PROPERTY SOURCES_FAKE) list(APPEND current_sources_fake ${ARGN}) set_property(TARGET c PROPERTY SOURCES_FAKE ${current_sources_fake}) endfunction() function(picolibc_headers subdir) # Get current headers get_property(current_headers GLOBAL PROPERTY PICOLIBC_HEADERS) set(orig_headers ${ARGN}) foreach(header IN LISTS ARGN) set(rel_header "${subdir}/${header}") set(include 1) foreach(current IN LISTS current_headers) if("${rel_header}" STREQUAL "${current}") list(REMOVE_ITEM orig_headers "${header}") set(include 0) endif() endforeach() if(include) list(APPEND current_headers "${rel_header}") configure_file("${header}" "${PROJECT_BINARY_DIR}/picolibc/include/${rel_header}") endif() endforeach() set_property(GLOBAL PROPERTY PICOLIBC_HEADERS ${current_headers}) install(FILES ${orig_headers} DESTINATION "include/${subdir}") endfunction() function(_picolibc_supported_compile_options var) set(picolibc_compile_options) set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) foreach(flag ${ARGN}) string(MAKE_C_IDENTIFIER ${flag} flag_under) try_compile(${flag_under} "${PROJECT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/simple-main.c" COMPILE_DEFINITIONS "${PICOLIBC_TEST_COMPILE_OPTIONS};${PICOLIBC_FLAG_OPTIONS};${flag}" ) if(${${flag_under}}) list(APPEND picolibc_compile_options ${flag}) endif() endforeach() set(${var} ${picolibc_compile_options} PARENT_SCOPE) endfunction() # These flags are needed to generate errors for invalid command line flags # instead of just warnings _picolibc_supported_compile_options(PICOLIBC_FLAG_OPTIONS -Werror=missing-declarations -Werror=unknown-attributes -Werror=attributes -Werror=unsupported-floating-point-opt -Werror=ignored-optimization-argument -Werror=attribute-optimize -Werror=implicit-function-declaration -Wno-unused-command-line-argument ) function(picolibc_supported_compile_options) _picolibc_supported_compile_options(options ${ARGN}) set(PICOLIBC_COMPILE_OPTIONS ${PICOLIBC_COMPILE_OPTIONS} ${options} PARENT_SCOPE) endfunction() function(picolibc_flag flag) string(REPLACE "_" "-" flag_dash ${flag}) string(REGEX REPLACE "^-" "" flag_trim ${flag_dash}) string(TOLOWER ${flag_trim} flag_lower) set(flag_file "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${flag_lower}.c") if (NOT EXISTS "${flag_file}") message(ERROR " Missing compiler test file ${flag_file}") endif() set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) try_compile(${flag} "${PROJECT_BINARY_DIR}" "${flag_file}" COMPILE_DEFINITIONS "${PICOLIBC_FLAG_OPTIONS}" ) if (${flag}) set(${flag} ${flag} PARENT_SCOPE) endif() endfunction() picolibc-1.8.11/cmake/simple-main.c000066400000000000000000000000411513574234600170320ustar00rootroot00000000000000int main(void) { return 0; } picolibc-1.8.11/doc/000077500000000000000000000000001513574234600141455ustar00rootroot00000000000000picolibc-1.8.11/doc/build.md000066400000000000000000000535731513574234600156030ustar00rootroot00000000000000# Building Picolibc Picolibc is designed to be cross-compiled for embedded systems on a Linux host using GCC. There is some support for Clang, but that doesn't include the built-in multilib support. Picolibc uses the meson build system, which is a slightly quirky build system designed to replace autotools with a single language. Picolibc requires meson version 0.61 or newer. If your operating system provides an older version, you can get the latest using pip. For example, on a Debian or Ubuntu system, you would do: $ sudo apt install pip $ pip install meson On POSIX systems, meson uses the low-level 'ninja' build tool and currently requires at least ninja version 1.5. If your operating system doesn't provide at least this version, head over to [ninja-build.org](https://ninja-build.org) to find out how to download and install the latest bits. ## Selecting build options Use -D= on the meson command line to change from the default value. Many of these options set configuration values for the newlib code base and should match that configuration system. The defaults should be reasonable for small embedded systems. ### General build options These options control some general build configuration values. | Option | Default | Description | | ------ | ------- | ----------- | | multilib | true | Build every multilib configuration supported by the compiler | | multilib-list | | If non-empty, the set of multilib configurations to compile for | | multilib-exclude | | Multilib configurations containing any of these strings will not be built | | b_sanitize=_option list_ | false | Build the library -fsanitize set to the provided list, e.g. -Db_sanitize=undefined | | sanitize-trap-on-error | false | Build the library with -fsanitize-undefined-trap-on-error | | sanitize-allow-missing | false | Don't bail if the selected sanitize option is not supported by the compiler | | profile | false | Enable profiling by adding -pg -no-pie to compile flags | | analyzer | false | Enable the analyzer while compiling with -fanalyzer | | assert-verbose | false | Display file, line and expression in assert() messages | | fast-strcmp | true | Always optimize strcmp for performance (to make Dhrystone happy) | ### Installation options These options select where to install the library. Picolibc supports installing multiple versions of the library into the same destination root with the build-type-subdir option. This can be used to install both space and speed optimized versions of the library. Users can select which version with the | Option | Default | Description | | ------ | ------- | ----------- | | build-type-subdir | specsdir | auto | Where to install the .specs file (default is in the GCC directory).
If set to `none`, then picolibc.specs will not be installed at all.| | sysroot-install | false | Install in GCC sysroot location | | sysroot-install-skip-checks | false | Skip sysroot path check when using sysroot-install. | | system-libc | false | Install as system C library. Requires compiler support for picolibc | ### Testing options Use these options to configure the library for testing. This includes testing the library using the host compiler and host C library. | Option | Default | Description | | ------ | ------- | ----------- | | tests | false | Enable tests | | tests-cdefs | auto | Ensure every public header ends up including sys/cdefs.h. When set to auto, follows tests value | | tests-enable-stack-protector| true | Build tests with stack protector enabled using -fstack-protector-all -fstack-protector-strong | | tests-enable-full-malloc-stress | false | Also enable malloc stress testing when building full malloc. This is always enabled for nano-malloc | | tests-enable-posix-io | true | Include tests which require full POSIX API | | test-long-double | true | Enable long double tests. | | split-large-tests | false | For tests which generate large executables, split them apart for smaller targets | | test-stdin | false | Include tests which require working stdin | | fortify-source | 3 | Use this for _FORTIFY_SOURCE value when building tests | | test-machine | qemu | Target machine type for tests. AArch64 also supports 'fvp' | | freestanding | false | Build entire library with -ffreestanding. Used to be useful for Zephyr testing | | native-tests | false | Build tests against host libc (used to validate tests) | | native-math-tests | true | Also build math tests against host libc when native-tests is enabled | | use-stdlib | false | Do not link tests with -nostdlib. Useful for native testing. | | picolib | true | Include 'picolib' bits. Disable when doing native testing. | | semihost | true | Build semihost libary. Disable when doing native testing. | | fake-semihost | false | Create a fake semihost library to allow tests to link | ### Stdio options For stdin/stdout/stderr, the application will need to provide `stdin`, `stdout` and `stderr`, which are three pointers to FILE structures (which can all reference a single shared FILE structure, and which can be aliases to the same underlying global pointer). Note that while posix-io support is enabled by default, using it will require that the underlying system offer the required functions. POSIX console support offers built-in `stdin`, `stdout` and `stderr` definitions which use the same POSIX I/O functions. | Option | Default | Description | | ------ | ------- | ----------- | | io-c99-formats | true | Enable C99 support in IO functions like printf/scanf | | io-long-long | false | Enable long long type support in IO functions like printf/scanf. This only affects the integer-only versions, the double and float versions always include long long support. | | io-pos-args | false | Enable printf-family positional arg support. This only affects the integer-only versions, the double and float versions always include positional argument support. | | io-long-double | false | Enable long double support in printf/scanf. | | io-float-exact | true | Provide round-trip support in float/string conversions | | atomic-ungetc | true | Make getc/ungetc re-entrant using atomic operations | | posix-console | false | Use POSIX I/O for stdin/stdout/stderr | | format-default | double | Sets the default printf/scanf style ('d, 'f', 'l', 'i' or 'm') | | printf-aliases | true | Support link-time printf aliases to set the default printf/scanf variant | | io-percent-b | false | Support the C23 %b printf specifier for binary formatted integers | | printf-small-ultoa | false | Avoid soft division routine during integer binary to decimal conversion in printf | | printf-percent-n | false | Support the dangerous %n format specifier in printf | | minimal-io-long-long | false | Support long long values in the minimal ('m') printf and scanf variants | | fast-bufio | false | Improve performance of some I/O operations when using bufio | | io-wchar | false | Enable wide character support in printf and scanf when mb-capable is not set | ### Internationalization options These options control how much internationalization support is included in the library. Picolibc supports locale names of the form '' or '.'; e.g. POSIX or C.UTF-8. When no charset is specified, picolibc selects ASCII when multi-byte support is disabled or locale is C. Otherwise, picolibc selects UTF-8. Picolibc supports the same charsets for locales and iconv. | Option | Default | Description | | ------ | ------- | ----------- | | mb-capable | false | Enable multibyte support including UTF-8 | | mb-extended-charsets | false | Enable all additional UCS, ISO, Windows and JIS charsets | | mb-ucs-charsets | false | Enable additional UCS charsets (UCS-2 and UCS-4) | | mb-iso-charsets | false | Enable ISO-8859 charsets (ISO 8859-1 through ISO 8859-16) | | mb-jis-charsets | false | Enable JIS charsets (JIS X 0208, EUC-JP and Shift-JIS) | | mb-windows-charsets | false | Enable various code-page based charsets | ### Startup/shutdown options These control how much support picolibc includes for calling functions at startup and shutdown times. | Option | Default | Description | | ------ | ------- | ----------- | | picocrt | true | Build crt0.o (C startup function) | | picocrt-enable-mmu | true | Enable memory management unit in picocrt where supported by the hardware | | picocrt-lib | true | Also wrap crt0.o into a library -lcrt0, which is easier to find via the library path | | initfini-array | true | Use .init_array and .fini_array sections in picocrt | | initfini | false | Support _init() and _fini() functions in picocrt | | crt-runtime-size | false | Compute .data/.bss sizes at runtime rather than linktime.
This option exists for targets where the linker can't handle a symbol that is the difference between two other symbols | ### Malloc options Picolibc offers two malloc implementations, the larger version offers better performance on large memory systems and for applications doing a lot of variable-sized allocations and deallocations. The smaller, default, implementation works best when applications perform few, persistent allocations. | Option | Default | Description | | ------ | ------- | ----------- | | newlib-nano-malloc | true | Use small-footprint nano-malloc implementation | | nano-malloc-clear-freed | false | Set contents of freed memory to zero when using nano-malloc | ### Locking options This option selects whether to disable locking support within the library. By default, locking support is enabled, but the default locking functions are just stubs which don't do anything. Applications can replace these stubs with their own implementation and enable full locking as described in [locking.md](locking.md). | Option | Default | Description | | ------ | ------- | ----------- | | single-thread | false | Disable support for locks | ### Thread local storage options By default, Picolibc can uses native TLS support as provided by the compiler, this allows re-entrancy into the library if the run-time environment supports that. A TLS model is specified only when TLS is enabled. The default TLS model is local-exec. As a separate option, you can make `errno` not use TLS if necessary. | Option | Default | Description | | ------ | ------- | ----------- | | thread-local-storage | auto | Use TLS for global variables. Default is automatic based on compiler support | | tls-model | local-exec | Select TLS model (global-dynamic, local-dynamic, initial-exec or local-exec) | | newlib-global-errno | false | Use single global errno even when thread-local-storage=true | | errno-function | | If set, names a function which returns the address of errno. 'auto' will try to auto-detect. | | tls-rp2040 | false | Use Raspberry PI RP2040 CPUID register to index thread local storage value | | stack-protector-guard | auto | Select stack protection canary type (global, tls or auto) | ### Math options There are two versions of many libm functions, old ones from SunPro and new ones from ARM. The new ones are generally faster for targets with hardware double support, except that the new float-valued functions use double-precision computations. On sytems without hardware double support, that's going to pull in soft double code. Measurements show the old routines are generally more accurate, which is why they are enabled by default. POSIX requires many of the math functions to set errno when exceptions occur; disabling that makes them only support fenv() exception reporting, which is what IEEE floating point and ANSI C standards require. | Option | Default | Description | | ------ | ------- | ----------- | | newlib-obsolete-math | true | Use old code for both float and double valued functions | | newlib-obsolete-math-float | auto | Use old code for float-valued functions | | newlib-obsolete-math-double | auto | Use old code for double-valued functions | | want-math-errno | false | Set errno when exceptions occur | newlib-obsolete-math provides the default value for the newlib-obsolete-math-float and newlib-obsolete-math-double parameters; those control the compilation of the individual fucntions. ## Building for embedded RISC-V and ARM systems Meson sticks all of the cross-compilation build configuration bits in a separate configuration file. There are a bunch of things you need to set, which the build system really shouldn't care about. Example configuration settings for RISC-V processors are in cross-riscv64-unknown-elf.txt: [binaries] c = 'riscv64-unknown-elf-gcc' ar = 'riscv64-unknown-elf-ar' as = 'riscv64-unknown-elf-as' ld = 'riscv64-unknown-elf-ld' strip = 'riscv64-unknown-elf-strip' [host_machine] system = 'unknown' cpu_family = 'riscv' cpu = 'riscv' endian = 'little' [properties] c_args = [ '-nostdlib', '-msave-restore', '-fno-common' ] # default multilib is 64 bit c_args_ = [ '-mcmodel=medany' ] needs_exe_wrapper = true skip_sanity_check = true Settings for ARM processors are in cross-arm-none-eabi.txt: [binaries] c = 'arm-none-eabi-gcc' ar = 'arm-none-eabi-ar' as = 'arm-none-eabi-as' ld = 'arm-none-eabi-ld' strip = 'arm-none-eabi-strip' [host_machine] system = 'none' cpu_family = 'arm' cpu = 'arm' endian = 'little' [properties] c_args = [ '-nostdlib', '-fno-common' ] needs_exe_wrapper = true skip_sanity_check = true If those programs aren't in your path, you can edit the file to point wherever they may be. ### Auto-detecting the compiler multi-lib configurations The PicoLibc configuration detects the processor configurations supported by the compiler using the `--print-multi-lib` command-line option: $ riscv64-unknown-elf-gcc --print-multi-lib .; rv32e/ilp32e;@march=rv32e@mabi=ilp32e rv32ea/ilp32e;@march=rv32ea@mabi=ilp32e rv32em/ilp32e;@march=rv32em@mabi=ilp32e rv32eac/ilp32e;@march=rv32eac@mabi=ilp32e rv32emac/ilp32e;@march=rv32emac@mabi=ilp32e rv32i/ilp32;@march=rv32i@mabi=ilp32 rv32if/ilp32f;@march=rv32if@mabi=ilp32f rv32ifd/ilp32d;@march=rv32ifd@mabi=ilp32d rv32ia/ilp32;@march=rv32ia@mabi=ilp32 rv32iaf/ilp32f;@march=rv32iaf@mabi=ilp32f rv32imaf/ilp32f;@march=rv32imaf@mabi=ilp32f rv32iafd/ilp32d;@march=rv32iafd@mabi=ilp32d rv32im/ilp32;@march=rv32im@mabi=ilp32 rv32imf/ilp32f;@march=rv32imf@mabi=ilp32f rv32imfc/ilp32f;@march=rv32imfc@mabi=ilp32f rv32imfd/ilp32d;@march=rv32imfd@mabi=ilp32d rv32iac/ilp32;@march=rv32iac@mabi=ilp32 rv32imac/ilp32;@march=rv32imac@mabi=ilp32 rv32imafc/ilp32f;@march=rv32imafc@mabi=ilp32f rv32imafdc/ilp32d;@march=rv32imafdc@mabi=ilp32d rv64i/lp64;@march=rv64i@mabi=lp64 rv64if/lp64f;@march=rv64if@mabi=lp64f rv64ifd/lp64d;@march=rv64ifd@mabi=lp64d rv64ia/lp64;@march=rv64ia@mabi=lp64 rv64iaf/lp64f;@march=rv64iaf@mabi=lp64f rv64imaf/lp64f;@march=rv64imaf@mabi=lp64f rv64iafd/lp64d;@march=rv64iafd@mabi=lp64d rv64im/lp64;@march=rv64im@mabi=lp64 rv64imf/lp64f;@march=rv64imf@mabi=lp64f rv64imfc/lp64f;@march=rv64imfc@mabi=lp64f rv64imfd/lp64d;@march=rv64imfd@mabi=lp64d rv64iac/lp64;@march=rv64iac@mabi=lp64 rv64imac/lp64;@march=rv64imac@mabi=lp64 rv64imafc/lp64f;@march=rv64imafc@mabi=lp64f rv64imafdc/lp64d;@march=rv64imafdc@mabi=lp64d $ arm-none-eabi-gcc --print-multi-lib .; thumb;@mthumb hard;@mfloat-abi=hard thumb/v6-m;@mthumb@march=armv6s-m thumb/v7-m;@mthumb@march=armv7-m thumb/v7e-m;@mthumb@march=armv7e-m thumb/v7-ar;@mthumb@march=armv7 thumb/v8-m.base;@mthumb@march=armv8-m.base thumb/v8-m.main;@mthumb@march=armv8-m.main thumb/v7e-m/fpv4-sp/softfp;@mthumb@march=armv7e-m@mfpu=fpv4-sp-d16@mfloat-abi=softfp thumb/v7e-m/fpv4-sp/hard;@mthumb@march=armv7e-m@mfpu=fpv4-sp-d16@mfloat-abi=hard thumb/v7e-m/fpv5/softfp;@mthumb@march=armv7e-m@mfpu=fpv5-d16@mfloat-abi=softfp thumb/v7e-m/fpv5/hard;@mthumb@march=armv7e-m@mfpu=fpv5-d16@mfloat-abi=hard thumb/v7-ar/fpv3/softfp;@mthumb@march=armv7@mfpu=vfpv3-d16@mfloat-abi=softfp thumb/v7-ar/fpv3/hard;@mthumb@march=armv7@mfpu=vfpv3-d16@mfloat-abi=hard thumb/v7-ar/fpv3/hard/be;@mthumb@march=armv7@mfpu=vfpv3-d16@mfloat-abi=hard@mbig-endian thumb/v8-m.main/fpv5-sp/softfp;@mthumb@march=armv8-m.main@mfpu=fpv5-sp-d16@mfloat-abi=softfp thumb/v8-m.main/fpv5-sp/hard;@mthumb@march=armv8-m.main@mfpu=fpv5-sp-d16@mfloat-abi=hard thumb/v8-m.main/fpv5/softfp;@mthumb@march=armv8-m.main@mfpu=fpv5-d16@mfloat-abi=softfp thumb/v8-m.main/fpv5/hard;@mthumb@march=armv8-m.main@mfpu=fpv5-d16@mfloat-abi=hard On RISC-V, PicoLibc is compiled 36 times, while on ARM, the library is compiled 20 times with the specified compiler options (replace the '@'s with '-' to see what they will be). ### Running meson Because Picolibc targets smaller systems like the SiFive FE310 or ARM Cortex-M0 parts with only a few kB of RAM and flash, the default values for all of the configuration options are designed to minimize the library code size. Here's the [do-riscv-configure](../scripts/do-riscv-configure) script from the repository that configures the library for small RISC-V systems: ```sh #!/bin/sh ARCH=riscv64-unknown-elf DIR=`dirname $0` meson "$DIR" \ -Dincludedir=picolibc/$ARCH/include \ -Dlibdir=picolibc/$ARCH/lib \ --cross-file "$DIR"/cross-$ARCH.txt \ "$@" ``` This script is designed to be run from a build directory, so you'd do: $ mkdir build-riscv64-unknown-elf $ cd build-riscv64-unknown-elf $ ../scripts/do-riscv-configure You can select the installation directory by passing it to the meson script: $ ../scripts/do-riscv-configure -Dprefix=/path/to/install/dir/ ### Compiling Once configured, you can compile the libraries with $ ninja ... $ ninja install ... $ picolibc-1.8.11/doc/ctype.md000066400000000000000000000017701513574234600156200ustar00rootroot00000000000000# Ctype in Picolibc The Ctype family of functions provide a convenient way to process character data. The traditional implementation of these is to build a table of per-character classification data and have the individual functions index the table and extract the relevant data. This is quite efficient in code space and time for each indivdual test, but the table introduces a fairly large fixed cost. Picolibc provides an alternate implementation, selectable when compiling files using the API, where each function directly implements the necessary comparison operations. These are implemented as inline functions. In many cases, the resulting code is no larger than the table indexing operations and without the overhead of the table. When building with the 'optimize for size' option enabled (-Os), the new direct implementation is selected by default. You can also force a particular mode by defining `_PICOLIBC_CTYPE_SMALL` to `1` (select direct implementation) or `0` (select array-based implementation). picolibc-1.8.11/doc/embedsource.md000066400000000000000000000055041513574234600167700ustar00rootroot00000000000000# Using picolibc as an embedded source For projects where deterministic builds, reproduceability and traceability is important, it is possible to embed the entire picolibc library as a meson subproject into the source directory of the main project. The benefit is that git submodules and meson subprojects work nicely together, and it is possible to lock down the libc version together with the source tree. For more information on the meson subproject feature, refer to the documentation at : https://mesonbuild.com/Subprojects.html ## Adding picolibc as a subproject First you need to add picolibc as a git submodule: ``` mkdir subprojects git submodule add https://github.com/keith-packard/picolibc subprojects/picolibc ``` Your source directory could now look something like this: ``` subprojects/ picolibc/ otherlib/ src/ main.c meson.build ``` ## Add dependency to meson.build First of all, when using picolibc as an embedded source, you should not specify -specs=picolibc.specs in the c_args. Next you will need to include the dependency in your meson.build file: ``` dependencies += dependency('picolibc', fallback: ['picolibc', 'picolibc_dep']) ``` In order to avoid linker conflicts with any compiler bundled c-library, use the following link flags (also see the warning below): ``` link_args += '-nolibc' link_args += '-lgcc' ``` Finally use the dependency and linker arguments on your executable ``` exec = executable('myproject.elf', sources, dependencies: dependencies, link_args: link_args) ``` ## Warning: Remove bundled libc (newlib) As of today there is no option in gcc to ignore the bundled c-library. The development version GCC 9.0 will have an `-nolibc` option that we are waiting for. So currently the only way to avoid including the headers of the bundled library is to use the `-nostdinc` option. However, this also removes all the include directories, including the headers for libgcc, which we want. And i have found no good poartable way of re-adding the libgcc include header path. So until a better solution appears, it is best to uninstall the c-library if possible. On Debian/Ubuntu, the gcc-arm-none-eabi and libnewlib-arm-none-eabi are separate packages, so just uninstall libnewlib and any conflict is avoided. You can run a command in order to check which standard paths are included with your GCC: ``` echo | arm-none-eabi-gcc -E -Wp,-v - /usr/lib/gcc/arm-none-eabi/7.3.1/include /usr/lib/gcc/arm-none-eabi/7.3.1/include-fixed /usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/include <-- This is newlib (configured through ubuntu /etc/alternatives) sudo apt remove libnewlib-arm-none-eabi libnewlib-dev echo | arm-none-eabi-gcc -E -Wp,-v - /usr/lib/gcc/arm-none-eabi/7.3.1/include /usr/lib/gcc/arm-none-eabi/7.3.1/include-fixed picolibc-1.8.11/doc/init.md000066400000000000000000000045251513574234600154400ustar00rootroot00000000000000# Initializers/Constructors and Finalizers/Destructors in Picolibc The `__libc_init_array` and `__libc_fini_array` functions in Picolibc are called by Picocrt during application startup and shutdown. If you have custom start up code that replaces Picocrt, you probably want to call these as well. ## `__libc_init_array` This function performs application initialization by calling: 1) Functions listed in the preinit array 2) _init function 3) Functions listed in the init array ### _init function Your program may declare an optional initialization function called `_init`. If such a function is included in the binary it will be called before the init array contents are evaluated. ## `__libc_fini_array` Most embedded applications never return from main, but if yours does, Picocrt will call: 1) Functions listed in the fini array 2) _fini function ### _fini function Your program may declare an optional finalization function called `_fini`. If such a function is included in the binary it will be called after the fini array contents are evaluated. ## Automatically generated arrays of function pointers The `.preinit_array`, `.init_array` and `.fini_array` segments are built by the linker using data generated by the compiler. When you decorate a function with `__attribute__((constructor))`, the compiler places the address of the function into the `.init_array` segment. Decorate a function with `__attribute__((destructor))` and the compiler will place its address in the `.fini_array` segment. The `.preinit_array` segment is generated internally by the compiler for things like C++ vtable validation The linker script should collect all of the data from these segments into memory (probably flash as it doesn't change) so that the image ends up with arrays of function pointers. For data from the `.init_array` segment, the array should start with the symbol `__init_array_start` and ending with `__init_array_end`. For data from the `.fini_array` segment, the array should start with the symbol `__fini_array_start` and end with `__fini_array_end`. Finally, for data from the `.preinit_array` segment, the array starts with `__preinit_array_start` and ends with `__preinit_array_end`. Each of these arrays are complicated by the optional priority assigned to destructors and constructors, and the presense of the deprecated `.ctors` and `.dtors` segments. picolibc-1.8.11/doc/linking.md000066400000000000000000000176051513574234600161330ustar00rootroot00000000000000# Linking Picolibc applications Linking embedded applications requires significant target-specific information, including the location of various memory sections along with a range of application-specific memory settings. You can create your own custom linker script, or you can use the linker script provided by Picolibc. This document describes how to do either. ## Creating a Custom Linker Script Aside from the application and hardware specific aspects of creating a linker script, if your application is using the Picolib startup code, then you need to define the addresses used in that code, and set up the data as required. Checkout the [Initializers in Picolibc](init.md) document for details on what names to declare. To use a custom linker script when linking with gcc using `-specs=picolibc.specs`, you'll need to use the gcc `-T` option instead of using the `-Wl,-T` linker pass through option. This causes `picolibc.specs` to not add the picolibc linker script along with your custom one: gcc -specs=picolibc.specs -Tcustom.ld ## Using picolibc.ld Picolibc provides a default linker script which can often be used to link applications, providing that your linking requirements are fairly straightforward. To use picolibc.ld, you'll create a custom linker script that sets up some variables and then INCLUDE's picolibc.ld. Here's a sample custom linker script `sample.ld`: __flash = 0x08000000; __flash_size = 128K; __ram = 0x20000000; __ram_size = 16k; __stack_size = 512; INCLUDE picolibc.ld This is for an STM32L151 SoC with 128kB of flash and 16kB of RAM. We want to make sure there's space for at least 512 bytes of stack. To use this with gcc, the command line would look like this: gcc -specs=picolibc.specs -Tsample.ld Alternatively, you can specify those values using `--defsym` and use picolibc.ld as the linker script: cc -Wl,--defsym=__flash=0x08000000 -Wl,--defsym=__flash_size=128K ... -Tpicolibc.ld ### Defining Memory Regions Picolibc.ld defines only two memory regions: `flash` and `ram`. Flash is an addressable region of read-only memory which holds program text, constant data and initializers for read-write data. Ram is read-write memory which needs to be initialized before your application starts. As shown above, you declare the base and size of both memory regions in your linker script: * `__flash` specifies the lowest address in read-only memory used by your application. This needs to be in flash, but need not be the start of actual flash in the device. * `__flash_size` specifies the amount of read-only memory you want to allow the application to fill. This need not be all of the available memory. * `__ram` specifies the lowest address you want the linker to allocate to read-write data for the application. * `__ram_size` specifies the maximum amount of read-write memory you want to permit the application to use. * `__stack_size` reserves this much space at the top of ram for the initial stack. * `__heap_size_min` is an optional value that you can set to ensure there is at least this much memory available for the heap used by malloc. Malloc will still be able to use all memory between the end of pre-allocate data and the bottom of the stack area. ### Arranging Code and Data in Memory Where bits of code and data land in memory can be controlled to some degree by placing variables and functions in various sections by decorating them with `__attribute__ ((section(`*name*`)))`. You'll find '*' used in the following defintions; that can be replaced with any string. For instance, when you use -ffunction-sections or -fdata-sections with gcc, that creates a section named `.text.`*function-name* for each function and `.data.`*variable-name* for each variable. Here are all of the section names used in picolibc.ld: #### Flash contents These are stored in flash and used directly from flash. 1. Contents located first in flash. These can be used for interrupt vectors or startup code. * `.text.init.enter` * `.data.init.enter` * `.init`, `.init.*` 2. The bulk of the application code * `.text.unlikely`, `.text.unlikely.*` * `.text.startup`, `.text.startup.*` * `.text`, `.text.*` * `.gnu.linkonce.t.*` 3. Cleanup routines * `.fini`, `.fini.*` 4. Read-only data * `.rdata` * `.rodata`, `.rodata.*` * `.gnu.linkonce.r.*` * `.srodata.cst16` * `.srodata.cst8` * `.srodata.cst4` * `.srodata.cst2` * `.srodata`, `.srodata.*` * `.data.rel.ro`, `.data.rel.ro.*` * `.got`, `.got.*` 5. Addresses of pre-initialization functions. Each of the addresses in the list is called during program initialization, before `_init()`. * `.preinit_array` 6. Addresses of initializer/constructor functions. Each of the addresses in the list is called during program initialization, before `main()`. * `.init_array`, `.ctors` 7. Addresses of de-initializer/destructor functions. Each of the addresses in the list is called after the program finishes, after `main()`. * `.fini_array`, `.dtors` #### Uninitialized ram contents You can place items in RAM that is *not* initialized by picolibc. These can be handy if you need values in memory to survive reset, perhaps as a way to communicate from the application to a boot loader or similar. These are placed first in RAM and are sorted by name so that the order is consistent across linking operations: 1. `.preserve.*` 2. `.preserve` #### Initialized ram contents picolibc.ld places values for variables with explicit initializers in flash and marks the location in flash and in RAM. At application startup, picocrt uses those recorded addresses to copy data from flash to RAM. As a result, any initialized data takes twice as much memory; the initialization values stored in flash and the runtime values stored in ram. Making values read-only where possible saves the RAM. 1) `.data`, `.data.*` 2) `.gnu.linkonce.d.*` 3) `.sdata`, `.sdata.*`, `.sdata2.*` 4) `.gnu.linkonce.s.*` Picolibc uses native toolchain TLS support for values which should be per-thread. This means that variables like `errno` will be referenced using TLS mechanisms. To make these work even when the application doesn't support threading, Picolibc allocates a static copy of the TLS data in RAM. Picocrt initializes the architecture TLS mechanism to reference this static copy. By arranging the static copy of initialized and zero'd TLS data right at the data/bss boundary, picolibc can initialize the TLS block as a part of initializing RAM with no additional code. This requires a bit of a trick as the linker doesn't allocate any memory for TLS bss segments; picolibc.ld makes space by simply advancing the memory location by the size of the TLS bss segment. 1) `.tdata`, `.tdata.*`, `.gnu.linkonce.td.*` #### Cleared ram contents Variables without any explicit initializers are set to zero by picocrt at startup time. The first chunk of these is part of the TLS block: 1) `.tbss`, `.tbss.*`, `.gnu.linkonce.tb.*` 2) `.tcommon` After the TLS bss section comes the regular BSS variables: 1) `.sbss*` 2) `.gnu.linkonce.sb.*` 3) `.bss`, `.bss.*` 4) `.gnu.linkonce.b.*` 5) `COMMON` #### Stack area The stack is placed at the end of RAM; the `__stack_size` value in the linker script specifies how much space to reserve for it. If there isn't enough available RAM, linking will fail. #### Heap area Memory between the end of the cleared ram contents and the stack is available for malloc. If you need to ensure that there is at least a certain amount of heap space available, you can set the `__heap_size_min` value in the linker script. ## Using picolibc_inittls.ld This is an alternate to picolibc.ld which is used with --crt0=inittls and places the TLS variables in a separately allocated chunk of memory, rather than in between the data and bss variables. No changes to the application are needed, but application initialization now includes a call to `_init_tls`. picolibc-1.8.11/doc/locking.md000066400000000000000000000074611513574234600161250ustar00rootroot00000000000000# Locking in Picolibc Picolibc uses locking and atomics to protect global state between re-entrant calls. The amount of global state protected by locks has been minimized so that applications can avoid needing them for most common operations. ## Where Picolibc uses locking Picolibc has a single global lock for APIs that share global data. That includes: * malloc family * onexit/atexit * arc4random * getenv/setenv * functions using timezones (localtime, et al) * legacy stdio globals Picolibc uses per-file locks for the buffered POSIX file backend, but it doesn't require any locks for the bulk of the implementation. You can enable POSIX-compliant locking in stdio with -Dstdio-locking-true. That will prevent I/O from stdio operations from interleaving between threads. ## Where Picolibc uses atomics Picolibc also uses atomics to protect other data structures while avoiding the need for locking: * getc/ungetc in stdio * signal handling ## Configuration options controlling locking There is only one configuration option related to locking: * single-thread. When 'true', all locking operations are elided from the library. Re-entrant usage of the library will result in undefined behavior. Atomics will still be used as defined above, so disabling locking will still allow safe re-entrancy for those parts of the library. ## Retargetable locking API When -Dsingle-thread is not selected, Picolibc uses the following interface. Picolibc provides stubs for all of these functions that do not perform locking, so a single threaded application can still use a library compiled to enable locking. An application needing locking would provide a real implementation of the API. This API requires recursive mutexes; if the underlying implementation only provides non-recursive mutexes, a suitable wrapper implementing recursive mutexes will be required for the recursive APIs. All APIs involving recursive mutexes contain `recursive` in their names. In this section, *the locking implementation* refers to the external implementation of this API. When implementing this API every function and variable must be defined. If not, the application will fail to link as the default implementation will be used to satisfy any missing symbol and other symbols will collide with the application versions. ### `struct __lock; typedef struct __lock *_LOCK_T;` This struct is only referenced by picolibc, not defined. The locking implementation may define it as necessary. ### `extern struct __lock __libc_recursive_mutex;` This is the single global lock used for most libc locking. It must be defined in the locking implementation in such a way as to not require any runtime initialization. ### `void __retarget_lock_init(_LOCK_T *lock)` This is used by stdio to initialize the lock in a newly allocated FILE. ### `void __retarget_lock_acquire(_LOCK_T lock)` Acquire a non-recursive mutex. A thread will only acquire the mutex once. ### `void __retarget_lock_release(_LOCK_T lock)` Release a non-recursive mutex. ### `void __retarget_lock_close(_LOCK_T lock)` This is used by stdio to de-initialize a lock from a FILE which is being closed. ### `void __retarget_lock_init_recursive(_LOCK_T *lock)` Initialize a recursive mutex. This function isn't currently used by picolibc; the only recursive mutex is the global C library one which is statically initialized. ### `void __retarget_lock_acquire_recursive(_LOCK_T lock)` Acquire a recursive mutex. A thread may acquire a recursive mutex multiple times. ### `void __retarget_lock_release_recursive(_LOCK_T lock)` Release a recursive mutex. A thread thread must release the mutex as many times as it has acquired it before the mutex is unlocked. ### `void __retarget_lock_close_recursive(_LOCK_T lock)` This is used by the legacy stdio code to de-initialize a lock from a FILE which is being closed. picolibc-1.8.11/doc/os.md000066400000000000000000000276321513574234600151220ustar00rootroot00000000000000# Picolibc and Operating Systems Picolibc is designed to be operating-system independent, so it doesn't embed any operating system support into libc. Some portions of Picolibc need system support, like I/O and task termination. Picolibc expects these interfaces to conform to POSIX, both as a way to simplify integration into POSIX-conforming operating system and as a way to provide a well defined interface between picolibc and the target system. When using picolibc in a non-POSIX environment, applications may constrain themselves to portions of picolibc which do not rely upon these functions, provide wrapping functions which expose POSIX apis on top of their native implementation or replace portions of picolibc with code designed atop their interfaces. ## stdin/stdout/stderr Picolibc stdio splits support for simple console input/output and more complex file operations so that a minimal system can easily support the former with only a few functions. To get stdin/stdout/stderr working, the application needs to define the `stdin`, `stdout` and `stderr` globals, which contain pointers to FILE objects. The pointers may reside in read-only memory, but the FILE objects may not. A single FILE object may be used for all three pointers, and linker aliases may be used to make all three pointers be stored in the same location. The FILE object contains function pointers for putc, getc, which might be defined as follows: ```c static int sample_putc(char c, FILE *file) { (void) file; /* Not used in this function __uart_putc(c); /* Defined by underlying system */ return c; } static int sample_getc(FILE *file) { unsigned char c; (void) file; /* Not used in this function */ c = __uart_getc(); /* Defined by underlying system */ return c; } ``` It also contains a pointer to an optional `flush` function, which, if provide, will be called to flush pending output to the file, e.g., when the `fflush()` function is called: ```c static int sample_flush(FILE *file) { /* This function doesn't need to do anything */ (void) file; /* Not used in this function */ return 0; } ``` These functions are used to initialize a FILE structure: ```c static FILE __stdio = FDEV_SETUP_STREAM(sample_putc, sample_getc, NULL, _FDEV_SETUP_RW); ``` This defines a FILE which can read and write characters using the putc and getc functions described above, but not using any flush function. The final paramter, which specifies the operations supported, can be one of the following: | Mode | Operations | Required Functions | |-------------------|------------|--------------------| | _FDEV_SETUP_READ | Read | getc | | _FDEV_SETUP_WRITE | Write | putc | | _FDEV_SETUP_RW | Read/Write | putc, getc | Finally, the FILE is used to initialize the `stdin`, `stdout` and `stderr` values, the latter two of which are simply aliases to `stdin`: ```c FILE *const stdin = &__stdio; __strong_reference(stdin, stdout); __strong_reference(stdin, stderr); ``` ## Operating System Interfaces used by Picolibc Here's the full list of external operating system functions used by Picolibc and which source files reference them. * int close(int fd) + libc/search/hash.c + libc/stdio/fdopen.c + libc/stdio/fopen.c + libc/stdio/freopen.c + libc/stdio/mktemp.c + libc/stdio/tmpfile.c * void _exit(int status) + libc/signal/signal.c + libc/stdlib/abort.c + libc/stdlib/exit.c + libc/stdlib/_Exit.c * int fstat(int fd, struct stat *statbuf) + libc/search/hash.c * int getentropy(void *buffer, size_t length) + libc/ssp/stack/protector.c + libc/stdlib/arc4random.c * int gettimeofday(struct timeval *tv, sruct timezone *tz) + libc/time/time.c * off_t lseek(int fd, off_t offset, int whence) + libc/search/hash.c + libc/search/hash_page.c + libc/stdio/fdopen.c + libc/stdio/freopen.c + libc/xdr/xdr_rec.c * int open(char *path, int flags, ...) + libc/search/hash.c + libc/stdio/fopen.c + libc/stdio/freopen.c + libc/stdio/mktemp.c * ssize_t read(int fd, void *buf, size_t count) + libc/search/hash.c + libc/search/hash_page.c + libc/stdio/fdopen.c + libc/stdio/freopen.c * int sigprocmask(int how, sigset_t *set, sigset_t *oldset) + libc/search/hash_page.c * int stat(char *path, struct stat *statbuf) + libc/search/hash.c * clock_t times(struct tms *buf) + libc/time/clock.c * int unlink(char *path) + libc/search/hash_page.c + libc/stdio/remove.c + libc/stdio/tmpfile.c * ssize_t write(int fd, void *buf, size_t count) + libc/search/hash.c + libc/search/hash_page.c + libc/stdio/fdopen.c + libc/stdio/freopen.c + libc/stdio/vdprintf.c ### fopen, fdopen and freopen Support for these requires malloc/free along with a handful of POSIX-compatible functions: ```c int close (int fd); off_t lseek (int fd, off_t offset, int whence); int open (const char *, int, ...); ssize_t read (int fd, void *buf, size_t nbyte); ssize_t write (int fd, const void *buf, size_t nbyte); ``` ### dprintf, vdprintf These functions directly operate on file descriptors, so they use `write`: ```c ssize_t write (int fd, const void *buf, size_t nbyte); ``` ### mktemp, mkstemp, mkostemp, mkstemps, mkostemps, tmpnam and tmpfile All of these functions share a common implementation which operates on file descriptors, so they all need a selection of POSIX functions: ```c int close (int fd); int open (const char *, int, ...); int unlink(char *path) ``` ### exit and _Exit `_Exit` is a trivial wrapper around `_exit`; `exit` is a wrapper around `_exit` that also calls destructors and callbacks registered with `atexit` or `on_exit`. To make these work, you'll need to implement the `_exit` function: ```c void _exit (int status); ``` ### malloc, free (and friends) Picolibc's `malloc` implementation relies on `sbrk`. Malloc can handle sbrk returning dis-continuous memory. ```c void *sbrk(intptr_t incr); ``` ### sbrk Picolibc includes a simple version of sbrk that can return chunks of memory from a pre-defined contiguous heap. You can either specify `-Dinternal-heap=` while building picolibc to declare a fixed-size pre-allocated heap, or have the linker script define symbols that provide the bounds of the heap: * `__heap_start` — points at the start of the heap available for sbrk. * `__heap_end` — points at the end of the heap available for sbrk. The sample linker script provided with picolibc defines these two symbols to enclose all RAM which is not otherwise used by the application. ### abort and raise Posix says that `abort` sends `SIGABRT` to the calling process as if the process called `raise(SIGABRT)`. It also says `abort` shall not return. The picolibc implementation of `abort` calls `raise`; if that returns, it then calls `_exit`. The picolibc version of `raise` also calls `_exit` for uncaught and un-ignored signals. ```c __noreturn void _exit (int status); ``` ### ndbm Picolibc provides the BSD ndbm APIs and those operate directly via a POSIX OS interface, not through stdio. Support for this API set require all of the functions required by `fopen` along a few additional ones: ```c int close (int fd); off_t lseek (int fd, off_t offset, int whence); int open (const char *, int, ...); ssize_t read (int fd, void *buf, size_t nbyte); int sigprocmask(int how, sigset_t *set, sigset_t *oldset); int stat(char *path, struct stat *statbuf); int unlink(char *path); ssize_t write (int fd, const void *buf, size_t nbyte); ``` ### xdr The Sun XDR APIs are generally abstracted away from OS interfaces except that when using xdrrec_create. As that interface provides no seek interface, the underlying implementation assumes that the provided handle actually contains a POSIX file descriptor and directly calls lseek for xdr_setpos and xdr_getpos. This provides compatibility with glibc which does the same thing. ```c off_t lseek(int fd, off_t offset, int whence); ``` ### arc4random, arc4random_buf To generate secure random numbers, picolibc's arc4random implementation is seeded from system entropy: ```c int getentropy(void *buffer, size_t length); ``` ### clock The clock API returns a total of all values returned from the times API. ```c clock_t times(struct tms *buf); ``` ## Linking with System Library To get Picolibc to use a system library, that library needs to be specified *after* libc on the linker command line. The picolibc.specs file provides a way to specify a library after libc using the `--oslib=` parameter: ```console $ gcc -o program.elf program.o --oslib=myos ``` This will include -lmyos after -lc so that the linker can resolve functions used by picolibc from libmyos.a. You can, alternatively, include the functions in object files with the rest of your application, which avoids the problem with libraries. Note that this mechanism requires the definition of _exit in the myos library. ## Semihosting support For RISC-V and ARM processors, Picolibc provides an implementation of all of the above functions along with a couple more POSIX APIs used by the Picolibc test suite. This implementation relies on semihosting support from the execution environment, which is available when running under qemu or when using openocd and gdb. Link this into your application using `--oslib=semihost` in your link command line. Please note that this will replace the default `crt0` with a variant calling `exit` upon return from `main`. The default is to enter an infinite loop, and the change ensure a clean return to the execution environment. ## POSIX console support As a build-time option, Picolibc can be configured to use POSIX read and write APIs to support stdin, stdout and stderr. Add `-Dposix-console=true` to enable this. This is incompatible with semihosting support above. ## Building picolibc on native POSIX systems To allow for testing of picolibc and applications using picolibc, you can actually build picolibc on a full POSIX system. In this configuration, picolibc provides the non-POSIX libc APIs while the underlying system C library is used for the POSIX functions described above. To build in this mode, you'll need to override a few default picolibc configuration parameters: ```console $ meson \ -Dtls-model=global-dynamic \ -Dmultilib=false \ -Dpicocrt=false \ -Dsemihost=false \ -Duse-stdlib=true \ -Dposix-console=true \ -Dthread-local-storage=true \ -Dthread-local-storage-api=false \ -Dinternal-heap=8388608 \ -Derrno-function=auto \ -Dinitfini-array=false\ -Dincludedir=lib/picolibc/include \ -Dlibdir=lib/picolibc/lib \ -Dspecsdir=none \ ``` * -Dtls-model=global-dynamic makes picolibc use the default TLS model for GCC. * -Dmultilib=false makes picolibc build only a single library for the default GCC configuration. * -Dpicocrt=false disables building the C startup code as that is provided by the underlying system. * -Dsemihost=false disables building semihosting support as OS interfaces are provided by the underlying system. * -Duse-stdlib=true removes -nostdlib from the compile and link command lines so that the native C library will be used. * -Dposix-console=true uses POSIX I/O read/write APIs for stdin, stdout and stderr. * -Dthread-local-storage=true and -Dthread-local-storage-api=false set up the library to enable TLS but not attempt to provide the picolibc-specific TLS apis as those don't work with the system C library. * -Dinternal-heap=8388608 allocates a stack chunk of memory for use by the picolibc `sbrk` implementation. * -Derrno-function=auto detects the native C library errno implementation. * -Dinitfini-array=false skips the picolibc constructor bits and lets the native C library do that initialization step. * -Dincludedir, -Dlibdir and -Dspecsdir set up the installation so it doesn't conflict with the native system. Once built, you can install and use picolibc on the host: ```console $ cc -I/usr/local/lib/picolibc/include hello-world.c \ /usr/local/lib/picolibc/lib/libc.a ``` picolibc-1.8.11/doc/picolibc.svg000066400000000000000000000065221513574234600164570ustar00rootroot00000000000000 image/svg+xml c -12 picolibc-1.8.11/doc/printf-sample/000077500000000000000000000000001513574234600167265ustar00rootroot00000000000000picolibc-1.8.11/doc/printf-sample/Makefile000066400000000000000000000061411513574234600203700ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2023 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # CFLAGS=-Os \ -march=armv7-m \ --specs=picolibc.specs \ --oslib=semihost \ --crt0=hosted \ -Wl,--defsym=__flash=0 \ -Wl,--defsym=__flash_size=0x00200000 \ -Wl,--defsym=__ram=0x20000000 \ -Wl,--defsym=__ram_size=0x200000 QEMU=qemu-system-arm -chardev stdio,id=stdio0 -semihosting-config enable=on,chardev=stdio0 -monitor none -serial none -machine mps2-an385,accel=tcg -nographic -kernel DCFLAGS=$(CFLAGS) -DPICOLIBC_DOUBLE_PRINTF_SCANF FCFLAGS=$(CFLAGS) -DPICOLIBC_FLOAT_PRINTF_SCANF LCFLAGS=$(CFLAGS) -DPICOLIBC_LONG_LONG_PRINTF_SCANF ICFLAGS=$(CFLAGS) -DPICOLIBC_INTEGER_PRINTF_SCANF MCFLAGS=$(CFLAGS) -DPICOLIBC_MINIMAL_PRINTF_SCANF CC=arm-none-eabi-gcc LOG=printf.log printf-float.log printf-long-long.log printf-integer.log printf-minimal.log ALL=printf.elf printf-float.elf printf-long-long.elf printf-integer.elf printf-minimal.elf all: $(LOG) printf.log: printf.elf (arm-none-eabi-size $^; $(QEMU) $^) > $@ printf.elf: printf.c $(CC) $(DCFLAGS) -o $@ $^ printf-float.log: printf-float.elf (arm-none-eabi-size $^; $(QEMU) $^) > $@ printf-float.elf: printf.c $(CC) $(FCFLAGS) -o $@ $^ printf-long-long.log: printf-long-long.elf (arm-none-eabi-size $^; $(QEMU) $^) > $@ printf-long-long.elf: printf.c $(CC) $(LCFLAGS) -o $@ $^ printf-integer.log: printf-integer.elf (arm-none-eabi-size $^; $(QEMU) $^) > $@ printf-integer.elf: printf.c $(CC) $(ICFLAGS) -o $@ $^ printf-minimal.log: printf-minimal.elf (arm-none-eabi-size $^; $(QEMU) $^) > $@ printf-minimal.elf: printf.c $(CC) $(MCFLAGS) -o $@ $^ clean: rm -f $(ALL) $(LOG) picolibc-1.8.11/doc/printf-sample/printf.c000066400000000000000000000033361513574234600204010ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2023 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include int main(void) { printf(" 2⁶¹ = %lld π ≃ %.17g\n", 1ll << 61, printf_float(3.141592653589793)); return 0; } picolibc-1.8.11/doc/printf.md000066400000000000000000000310731513574234600157750ustar00rootroot00000000000000# Printf and Scanf in Picolibc Embedded systems are often tightly constrained on code space, which makes it important to be able to only include code and data actually needed by the application. The format-string based interface to printf and scanf makes it very difficult to determine which conversion operations might be needed by the application. Picolibc handles this by providing multiple printf and scanf implementations in the library with varying levels of conversion support. The application developer selects among these at compile and link time based on knowledge of the requirements of the application. The selection is done using compiler command line options, `--printf` and `--scanf` which map the public printf and scanf names to internal names in the linker. These both take one of the available variants as the option value: cc --printf=i --scanf=i The function name mapping happens in picolibc.specs file which uses these options to add --defsym options when linking. These options also set a preprocessor symbol which handles the 'f' variant, so you need to pass these options during both compilation and linking. Using the defsym approach, rather than renaming the functions with the C preprocessor has a couple of benefits: * Printf uses within picolibc (which are all integer-only) now share whichever printf the application needs, avoiding including both integer-only and float versions * Printf optimizations in the compiler which map to puts or fputs now work even when using integer-only or float printf functions. Make sure you use only the option associated with the desired function as --defsym will force the underlying code to be included in the output even if unused. The defsym approach does not work with link-time optimization. In that case, applications can only use the default. The library must be compiled with the desired variant as the default (using the `-Dformat-default` configuration option). ## Printf and Scanf levels in Picolibc There are five levels of printf support provided by Picolibc that can be selected when building applications. One of these is the default used when no symbol definitions are applied; that is selected using the picolibc built-time option, `-Dformat-default`, which defaults to `double`. The picolibc specs for GCC includes support for --printf and --scanf options which set both the preprocessor defines as well as configuring the linker to alias vfprintf and vfscanf to the desired function using the --defsym linker command line option. For instance, if you use cc --printf=d --scanf=l, the compiler will see -D_PICOLIBC_PRINTF='d' -D_PICOLIBC_SCANF='l' and the linker will see --defsym=vfprintf=__d_vfprintf --defsym=vfscanf=__l_vfscanf A linker that supports -alias instead of --defsym would see -alias,__d_vfprintf,vfprintf -alias,__l_vfscanf,vfscanf When not using the picolibc specs, you can manually specify these on the compiler command line These are listed in order of decreasing functionality and size. * 'd' format (default when `-Dformat-default=d`). This offers full printf functionality, including both float and double conversions along with the C99 extensions and POSIX positional parameters. There is optional support for the C23 %b format specifier via the `io-percent-b` setting and optional support for long double values via the `io-long-double` setting. * 'f' format (default when `-Dformat-default=f`). This is the same as 'd' format except that it supports only float for scanf and supports float instead of double for printf. It also doesn't support long double conversions. * 'l' format (default when `-Dformat-default=l`). This removes support for all float and double conversions and makes support for C99 extensions and POSIX positional parameters optional via the `io-c99-formats` and `io-pos-args` settings. * 'i' format (default when `-Dformat-default=i`). This removes support for long long conversions where those values are larger than long values. * 'm' format (default when`-Dformat-default=m`). This removes support for width and precision, alternate presentation modes and alternate sign presentation. All of these are still parsed correctly, so applications needn't adjust format strings in most cases, but the output will not be the same. It also disables any support for positional arguments and %b formats that might be selected with `io-pos-args` or `io-percent-b`. 'f' format requires a special macro for float values: `printf_float`. To make it easier to switch between that and the default level, that macro is also correctly defined for the other two levels. Here's an example program to experiment with these options: ```c #include void main(void) { printf(" 2⁶¹ = %lld π ≃ %.17g\n", 1ll << 61, printf_float(3.141592653589793)); } ``` Now we can build and run it with the double options: $ arm-none-eabi-gcc --printf=d -Os -march=armv7-m --specs=picolibc.specs --oslib=semihost --crt0=hosted -Wl,--defsym=__flash=0 -Wl,--defsym=__flash_size=0x00200000 -Wl,--defsym=__ram=0x20000000 -Wl,--defsym=__ram_size=0x200000 -o printf.elf printf.c $ arm-none-eabi-size printf.elf text data bss dec hex filename 7748 80 4104 11932 2e9c printf.elf $ qemu-system-arm -chardev stdio,id=stdio0 -semihosting-config enable=on,chardev=stdio0 -monitor none -serial none -machine mps2-an385,accel=tcg -kernel printf.elf -nographic 2⁶¹ = 2305843009213693952 π ≃ 3.141592653589793 Switching to float-only reduces the size but lets this still work, although the floating point value has reduced precision: $ arm-none-eabi-gcc --printf=f -Os -march=armv7-m --specs=picolibc.specs --oslib=semihost --crt0=hosted -Wl,--defsym=__flash=0 -Wl,--defsym=__flash_size=0x00200000 -Wl,--defsym=__ram=0x20000000 -Wl,--defsym=__ram_size=0x200000 -o printf-float.elf printf.c $ arm-none-eabi-size printf-float.elf text data bss dec hex filename 6284 80 4104 10468 28e4 printf-float.elf $ qemu-system-arm -chardev stdio,id=stdio0 -semihosting-config enable=on,chardev=stdio0 -monitor none -serial none -machine mps2-an385,accel=tcg -kernel printf-float.elf -nographic 2⁶¹ = 2305843009213693952 π ≃ 3.1415927 Selecting the long-long variant reduces the size further, but now the floating point value is not displayed correctly: $ arm-none-eabi-gcc --printf=l -Os -march=armv7-m --specs=picolibc.specs --oslib=semihost --crt0=hosted -Wl,--defsym=__flash=0 -Wl,--defsym=__flash_size=0x00200000 -Wl,--defsym=__ram=0x20000000 -Wl,--defsym=__ram_size=0x200000 -o printf-long-long.elf printf.c $ arm-none-eabi-size printf-long-long.elf text data bss dec hex filename 2188 80 4104 6372 18e4 printf-long-long.elf $ qemu-system-arm -chardev stdio,id=stdio0 -semihosting-config enable=on,chardev=stdio0 -monitor none -serial none -machine mps2-an385,accel=tcg -kernel printf-long-long.elf -nographic 2⁶¹ = 2305843009213693952 π ≃ *float* Going to integer-only reduces the size even further, but now it doesn't output the long long value correctly: $ arm-none-eabi-gcc --printf=i -Os -march=armv7-m --specs=picolibc.specs --oslib=semihost --crt0=hosted -Wl,--defsym=__flash=0 -Wl,--defsym=__flash_size=0x00200000 -Wl,--defsym=__ram=0x20000000 -Wl,--defsym=__ram_size=0x200000 -o printf-int.elf printf.c $ arm-none-eabi-size printf-int.elf text data bss dec hex filename 2028 80 4104 6212 1844 printf-int.elf $ qemu-system-arm -chardev stdio,id=stdio0 -semihosting-config enable=on,chardev=stdio0 -monitor none -serial none -machine mps2-an385,accel=tcg -kernel printf-int.elf -nographic 2⁶¹ = 0 π ≃ *float* To shrink things still further, use the 'minimal' variant. This doesn't even look at the %g formatting instruction, so that value displays as '%g'. $ arm-none-eabi-gcc --printf=m -Os -march=armv7-m --specs=picolibc.specs --oslib=semihost --crt0=hosted -Wl,--defsym=__flash=0 -Wl,--defsym=__flash_size=0x00200000 -Wl,--defsym=__ram=0x20000000 -Wl,--defsym=__ram_size=0x200000 -o printf-min.elf printf.c $ arm-none-eabi-size printf-min.elf text data bss dec hex filename 1508 80 4104 5692 163c printf-min.elf $ qemu-system-arm -chardev stdio,id=stdio0 -semihosting-config enable=on,chardev=stdio0 -monitor none -serial none -machine mps2-an385,accel=tcg -kernel printf-min.elf -nographic 2⁶¹ = 0 π ≃ %g There's a build-time option available that enables long-long support in the minimal printf variant, `-Dminimal-io-long-long=true`. Building with that increases the size modestly while fixing the long long output: $ arm-none-eabi-size printf-min.elf text data bss dec hex filename 1632 80 4104 5816 16b8 printf-min.elf $ qemu-system-arm -chardev stdio,id=stdio0 -semihosting-config enable=on,chardev=stdio0 -monitor none -serial none -machine mps2-an385,accel=tcg -kernel printf-min.elf -nographic 2⁶¹ = 2305843009213693952 π ≃ %g ## Picolibc build options for stdio In addition to the application build-time options, picolibc includes a number of picolibc build-time options to control the feature set (and hence the size) of the library: * `-Dio-c99-formats=true` This option controls whether support for the C99 type-specific format modifiers 'j', 'z' and 't' and the hex float format 'a' are included in the long-long, integer and minimal printf and scanf variants. Support for the C99 format specifiers like PRId8 is always provided. This option is enabled by default. * `-Dio-long-long=true` This deprecated option controls whether support for long long types is included in the integer variant of printf and scanf. Instead of using this option, applications should select the long long printf and scanf variants. This option is disabled by default. * `-Dio-pos-args=true` This option add support for C99 positional arguments to the long long and integer printf and scanf variant (e.g. "%1$"). Positional arguments are always supported in the double and float variants and never supported in the minimal variant. This option is disabled by default. * `-Dio-long-double=true` This option add support for long double parameters. That is limited to systems using 80- and 128- bit long doubles, or systems for which long double is the same as double. This option is disabled by default * `-Dio-float-exact=true` This option, which is enabled by default, controls whether the stdio code uses exact algorithms for printf and scanf. When enabled, printing at least 9 digits (e.g. "%.9g") for 32-bit floats and 17 digits (e.g. "%.17g") for 64-bit floats ensures that passing the output back to scanf will exactly re-create the original value. * `-Datomic-ungetc=true` This option, which is enabled by default, controls whether getc/ungetc use atomic instruction sequences to make them re-entrant. Without this option, multiple threads using getc and ungetc may corrupt the state of the input buffer. * `-Dposix-console=true` This option provides stdin/stdout/stderr support using the picolibc POSIX I/O support. * `-Dformat=default={d,f,l,i,m}` Selects which printf and scanf variant is used by default. * `-Dprintf-aliases=true` This option, which is enabled by default, provides for linker alias support for the --printf and --scanf compiler options. * `-Dio-percent-b=true` This option, which is disabled by default, supports the C23 %b format specifier. * `-Dprintf-small-ultoa=true` This option, which is enabled by default, switches printf's binary-to-decimal conversion code to a version which avoids soft division for values larger than the machine registers as those functions are often quite large and slow. Applications using soft division on large values elsewhere will save space by disabling this option as that avoids including custom divide-and-modulus-by-ten implementations. * `-Dprintf-percent-n=true` This option, which is disabled by default, provides support for the dangerous %n printf format specifier. * `-Dminimal-io-long-long=true` This option controls whether support for long long types is included in the minimal variant of printf and scanf. This option is disabled by default. * `-Dfast-bufio=true` This option directly calls the read and write hooks from fread and fwrite when interacting with buffered streams. * `-Dio-wchar=true` This option enables wide character input and output even when picolibc is built without multi-byte character support. Picolibc also allows use of the legacy newlib stdio library, but that is outside the scope of this documentation. picolibc-1.8.11/doc/releasing.md000066400000000000000000000065721513574234600164520ustar00rootroot00000000000000# Releasing Picolibc Here are the current steps to perform when releasing a new version of picolibc: 1. Make sure the current code builds on all supported architectures: ** native ** 32-bit x86 ** RISC-V ** ARM 32-bit ** ARM 64-bit (aarch64) ** Xtensa (ESP8266, ESP32) 2. Test on architectures that can do so * native * 64-bit x86 * 32-bit x86 * RISC-V, all targets (qemu) * ARM 32-bit, almost all targets (qemu) * ARM 64-bit 3. Use glibc test suite for RISC-V and ARM: $ ./scripts/test-picolibc * Enables errno in the math functions using -Dwant-math-errno=true * Enables long-double io for RISC-V compiles using -Dio-long-double=true * Enables full locale support with -Dmb-capable=true and -Dmb-extended-charsets=true * Builds and installs minsize and release builds * Builds and runs glibc test suite against all four builds 4. Test c++ builds using hello-world example on ARM 5. Verify that COPYING.picolibc includes information about the current source files 6. Add release notes to README.md 7. Update meson.build, CMakeLists.txt and README.md with new version number 8. Commit release notes and meson.build $ git commit -m'Version ' README.md meson.build CMakeLists.txt 9. Use native configuration to build release: $ mkdir -p builds/build-native $ cd builds/build-native $ ../../scripts/do-native-configure $ ninja dist 10. Tag release $ git tag -s -m'Version ' main 11. Use arm configuration to build bits for the Arm embedded toolkit: $ ./scripts/do-arm-tk $ scp builds/dist/picolibc--.zip keithp.com:/var/www/picolibc/dist/gnu-arm-embedded 12. Push tag and branch to repositories $ git push origin main 13. Upload release to web site: $ scp build-native/meson-dist/* keithp.com:/var/www/picolibc/dist 14. Create new release on picolibc wiki pasting in relevant README.md section. 15. Create new release on github site, pasting in relevant README.md section. Upload release tar and arm embedded toolkit zip files. 16. Email release message to mailing list. Paste in README.md section about the new release. ## Debian Packages Debian packaging information is contained on the 'debian' branch in the main picolibc repository. It's designed to be build using 'gbp buildpackage', the git-based debian package building system. Here's how to build debian packages: 1. Release upstream picolibc first 2. Checkout debian branch $ git checkout debian 3. Merge in main at the release tag $ git merge 4. Update debian packaging to current standards 5. Update debian/copyright from COPYING.picolibc $ cp COPYING.picolibc 6. Add new Debian change log entry $ dch -v -1 -D unstable 7. Commit debian changes to repository $ git commit -m'debian: Version -1' debian/changelog 8. Build debian packages $ gbp buildpackage 9. Verify package results remain lintian-clean: $ lintian --info --display-info --pedantic picolibc_-1_amd64.changes 10. Tag release $ git tag -s -m'debian: Version -1' -1 debian 11. Push tags and branches to salsa $ git push salsa main debian -1 12. Sign and upload source changes: $ debsign picolibc_-1_source.changes $ dput picolibc_-1_source.changes picolibc-1.8.11/doc/testing.md000066400000000000000000000017631513574234600161530ustar00rootroot00000000000000## Building for the local processor If you want to compile the library for your local processor to test changes in the library, the meson configuration is happy to do that for you. You won't need a meson cross compilation configuration file, so all you need is the right compile options. They're mostly the same as the embedded version, but you don't want the multi-architecture stuff and I prefer plain debug to an -Os, as that makes debugging the library easier. The do-native-configure script has an example: ```sh #!/bin/sh DIR=`dirname $0` meson $DIR \ -Dmultilib=false \ -Dnewlib-wide-orient=false\ -Dincludedir=lib/picolibc/include \ -Dlibdir=lib/picolibc/lib \ -Dtests=true \ --buildtype debug ``` Again, create a directory and build there: $ mkdir build-native $ cd build-native $ ../do-native-configure $ ninja This will also build a test case for printf and scanf in the 'test' directory, which I used to fix up the floating point input and output code. picolibc-1.8.11/doc/tls.md000066400000000000000000000071011513574234600152700ustar00rootroot00000000000000# Thread Local Storage in Picolibc Copyright © 2019 Keith Packard The standard C library API includes many functions that use persistent state held by the library not the application. One obvious example is 'errno', a global variable originall designed to hold error status from the Unix kernel, but which was co-opted by libc to provide additional error status values from the library itself. There are numerous other examples of this kind of state. To permit multiple threads sharing a single address space to use the library without conflicting over this data, each thread needs a private copy of data that it uses. Newlib did this by creating a global structure holding all thread-specific values and then defining an API for the library to get the global structure for the current thread. Picolibc does this by using the built-in thread-local-storage mechanisms in the toolchain. This has several benefits: 1) Source code is simpler as thread-local variables are accessed directly by name. 2) Thread local storage contains only values used by the application. 3) Generated code is smaller and faster. ## TLS model used by Picolibc Picolibc is normally compiled with -ftls-model=local-exec. The selected model is included in the .specs file so applications should not include -ftls-model in their compile commands. Local-exec defines a single block of storage for all TLS variables. Each TLS variable is assigned an offset within this block and those values are placed in the binary during relocation. ## Initial TLS block The sample Picolibc linker script (picolibc.ld) allocates RAM for an initial TLS block and arranges for it to be initialized as a part of the normal data/bss initialization process for the application. | flash | symbol | | ----- | ------ | | code | | | rodata | | | data initializers | __data_source | | TLS data initializers | __tdata_source | | RAM | symbol | | ---- | ------ | | data | __data_start | | TLS data | __tls_base | | | __data_end | | | __tdata_size = . - __tls_base | | TLS bss | __bss_start | | | __tbss_size = . - __bss_start | | | __tls_size = . - __tls_base | | bss | | | | __bss_end The crt0 code copies __data_end - __data_start bytes from _data_source to _data_start. This initializes the regular data segment *and* the initial TLS data segment. Then, it clears memory from __bss_start to __bss_end, initializing the TLS bss segment *and* the regular bss segment. Finally, it sets the architecture-specific TLS data pointer to __tls_base. Once that is set, access to TLS variables will reference this initial TLS block. ## Creating more TLS blocks If the application is multi-threaded and wants to allow these threads to have separate TLS data, it may allocate memory for additional TLS blocks: 1) Allocate a block of size __tls_size 2) Copy __tdata_size bytes from __tdata_source to the new block to set the initial TLS values. 3) Clear __tbss_size bytes starting _tdata_size bytes into the new block 4) Set the TLS pointer as necessary ## Picolibc APIs related to TLS Picolib provides a couple of helper APIs for TLS: * _set_tls ```c void _set_tls(void *tls); ``` This is an architecture-specific function which sets the TLS block pointer for the processor to `tls`. * _init_tls ```c void _init_tls(void *tls); ``` This function initializes the specified TLS block, copying values into the initialized data portion and clearing values in the uninitialized data portion. Picolib also provides architecture-specific internal GCC APIs as necessary, for example, __aeabi_read_tp for ARM processors. picolibc-1.8.11/doc/using.md000066400000000000000000000174361513574234600156270ustar00rootroot00000000000000# Using Picolibc in Embedded Systems Picolibc is designed to be used in deeply embedded systems, those running either no operating system or a small RTOS. It is designed to be linked statically along with any operating system and application code. ### Prerequisites It is expected that the toolchain used for compilation of applicatons against Picolibc provides the following headers in its default search paths: * float.h * iso646.h * stdalign.h * stdarg.h * stdbool.h * stddef.h * tgmath.h Vanilla GCC & Clang/LLVM toolchains take care of that so most of the users have everything in place. But some third-party toolchains may expect these headers to be provided by the C library. Unfortunately it is not possible as these headers have compiler-specific parts and so whatever version could be imported in the Picolibc, it won't work nicely with certain compilers. Moreover even different versions of the same compiler may not work well with the same version of one of the headers mentioned above. ## Compiling with Picolibc To compile source code to use Picolibc, you can use the GCC .specs file delivered with Picolibc. This will set the system header file path and the linker library path to point at Picolibc. For example, to compile a single file and generate a .o file: $ gcc --specs=picolibc.specs -c foo.c When installed directly into the system, picolibc.specs is placed in the gcc directory so that it will be found using just the base name of the file. If installed in a separate location, you will need to provide an absolute pathname to the picolibc.specs file: $ gcc --specs=/usr/local/picolibc/picolibc.specs -c foo.c When building for an embedded system, you'll probably need to use a longer name for the compiler, something like `riscv-unknown-elf-gcc` or `arm-none-eabi-gcc`. ## Picolibc startup Initializing an embedded system usually requires a combination of hardware, run-time, library and application setup. You may want to perform all of these in your own code, or you be able to use the Picolibc startup code. Either works fine, using the Picolibc code means writing less of your own. ### Picocrt — Picolibc startup code Picocrt is the crt0.o code provided by Picolibc. This is enabled by default when using -specs=picolibc.specs: $ gcc -specs=picolibc.specs -o foo.elf foo.c Picocrt goes through a sequence of initialization steps, many of which you can plug your own code into: 1) Architecture-specific runtime initialization. For instance, RISC-V needs the `gp` register initialized for quick access to global variables while ARM with hardware floating point needs to have the FPSCR register set up to match C semantics for rounding. 2) Data initialization. Here's the code inside Picocrt:\ \ `memcpy(__data_start, __data_source, (uintptr_t) __data_size);`\ \ For this to work, the linker script must assign correct values to each of these symbols: * __data_start points to the RAM location where the .data segment starts. * __data_source points to the Flash location where the .data segment initialization values are stored. * __data_size is an absolute symbol noting the size of the initialized data segment 3) BSS initialization. Here's the code inside Picocrt:\ \ `memset(__bss_start, '\0', (uintptr_t) __bss_size);`\ \ Assign these symbols in the linker script as follows: * __bss_start points to the RAM location where the .bss segment starts. * __bss_size is an absolute symbol noting the size of the cleared data segment 4) Optionally call constructors: * The default and hosted crt0 variants call [initializers/constructors](init.md) using `__libc_init_array()` * The minimal crt0 variant doesn't call any constructors 5) Call `main()` 6) After main returns: * The default and minimal crt0 variants run an infinite loop if main returns. * The hosted crt0 variant calls `exit`, passing it the value returned from main. ## Linking Picolibc provides two sample linker scripts: `picolibc.ld` for C applications and `picolibcpp.ld` for C++ applications. These are designed to be useful for fairly simple applications running on embedded hardware which need read-only code and data stored in flash and read-write data allocated in RAM and initialized by picolibc at boot time. You can read more about this on the [linking](linking.md) page. ## Semihosting “Semihosting” is a mechanism used when the application is run under a debugger or emulation environment that provides access to some functionality of the OS running the debugger or emulator. Picolibc has semihosting support for console I/O and the exit() call. One common use for semihosting is to generate debug messages before any of the target hardware has been set up. Picolibc distributes the semihosting implementation as a separate library, `libsemihost.a`. Because it provides interfaces that are used by libc itself, it must be included in the linker command line *after* libc. You can do this by using the GCC --oslib=semihost command line flag defined by picolibc.specs: $ gcc --specs=picolibc.specs --oslib=semihost -o program.elf program.o You can also list libc and libsemihost in the correct order explicitly: $ gcc --specs=picolibc.specs -o program.elf program.o -lc -lsemihost ## Crt0 variants The default `crt0` version provided by Picolibc calls any constructors before it calls main and then goes into an infinite loop after main returns to avoid requiring an `_exit` function. In an environment which provides a useful `_exit` implementation, applications may want to use the `crt0-hosted` variant that calls `exit` when main returns, resulting in a clean return to the hosting environment (this conforms to a hosted execution environment as per the C specification). Select this using the `--crt0=hosted` flag: $ gcc --specs=picolibc.specs --crt0=hosted -o program.elf program.o In a smaller environment which is not using any constructors (or any Picolibc code which requires constructors) may want to use the `crt0-minimal` variant that removes the call to `__libc_init_array()`. This variant also runs an infinite loop in case main returns. Select this using the `--crt0=minimal` flag: $ gcc --specs=picolibc.specs --crt0=minimal -o program.elf program.o To avoid the complexity of arranging the TLS segments between the .data and .bss segments in your linker script, use the `crt0-inittls` variant along with the `picolibc-inittls.ld` linker script. This allocates space for TLS data above the regular `.bss` data and initializes it at program startup time. Select this using the `--crt0=inittls` flag along with the modified linker script: $ gcc --specs=picolibc.specs --crt0=inittls -Tpicolibc_inittls -o program.elf program.o To modify an existing linker script for use with `--crt0=inittls`, add lines like this any place within the read-only data sections: .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } >flash PROVIDE( __tdata_source = LOADADDR(.tdata) ); PROVIDE( __tdata_size = SIZEOF(.tdata) ); .tbss (NOLOAD) : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } >flash .tls_space (NOLOAD) : { . = ALIGN(@PREFIX@__tls_align); PROVIDE( @PREFIX@__tls_space = .); . = . + @PREFIX@__tls_data_size; } >ram AT>ram :ram PROVIDE( __tbss_offset = ADDR(.tbss) - ADDR(.tdata) ); PROVIDE( __tbss_size = SIZEOF(.tbss) ); PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); PROVIDE( __tls_size = ALIGN(ADDR(.tbss) + SIZEOF(.tbss) - ADDR(.tdata), __tls_align) ); PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); PROVIDE( __arm64_tls_tcb_offset = MAX(16, __tls_align) ); PROVIDE( __or1k_tls_tcb_offset = MAX(16, __tls_align) ); PROVIDE( __sh32_tls_tcb_offset = MAX(8, __tls_align) ); The last few symbols are for specific architectures, so you only need add those relevant to your project. picolibc-1.8.11/empty-libs/000077500000000000000000000000001513574234600154655ustar00rootroot00000000000000picolibc-1.8.11/empty-libs/empty.c000066400000000000000000000031171513574234600167710ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2021 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ picolibc-1.8.11/empty-libs/meson.build000066400000000000000000000047621513574234600176400ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2026 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # # Build a set of empty libraries for compatibility with # existing build scripts empty_lib_names = ['g', 'm', 'nosys'] foreach params : targets target = params['name'] target_dir = params['dir'] target_c_args = params['c_args'] instdir = join_paths(lib_dir, target_dir) foreach lib_name : empty_lib_names if meson.version().version_compare('>=1.10') static_library(lib_name, ['empty.c'], build_subdir : target_dir, install : really_install, install_dir : instdir, pic: false, c_args: target_c_args + c_args, objects : []) else target_lib_prefix = params['lib_prefix'] static_library(join_paths(target_dir, target_lib_prefix + lib_name), ['empty.c'], install : really_install, install_dir : instdir, pic: false, c_args: target_c_args + c_args, objects : []) endif endforeach endforeach picolibc-1.8.11/find-copyright000077500000000000000000000446451513574234600162710ustar00rootroot00000000000000#!/usr/bin/python3 import sys import fileinput import magic import re from comment_parser import comment_parser end_pats = (r'This implementation just', r'Synopsis of public', r'The SPU must have', r'This is a simple version', r'This is a dummy', r'stdio_ext\.h', r'python script to', r'libgen\.h', r'Id:.*Exp', r'sccs\.', r'Tests gleaned', r'tar\.h', r'tzcalc_limits\.c', r'dummy file', r'Rearranged for general', r'sincos', r'POSIX', r'Reentrant', r'Copied', r'These are', r'creat', r'ARM configuration', r'Place holder', r'local header', r'GNU variant', r'default reentrant', r'A replacement', r'The signgam', r'dummy header', r'Uniset', r'wcsftime\.c', r'month_lengths\.c', r'Static instance', r'Conversion is performed', r'Common routine', r'l64a') end_pats_s = (r'FUNCTION',) end_res = [] for pat in end_pats: regex = re.compile(pat, re.I) end_res += [regex] for pat in end_pats_s: regex = re.compile(pat) end_res += [regex] left_res = re.compile(r'^[^A-Za-z0-9]*(.*)') right_res = re.compile(r'(.*)[ /*\t]$') def clean_copyright(string): copyright = [] have_cpr = False cpr_line = re.compile(r'copyright.*(20[0-5][0-9]|19[7-9][0-9])', re.I) upper = re.compile(r'[A-Z]') lower = re.compile(r'[a-z]') modified = re.compile(r'Modified') derived = re.compile(r'code is derived from software', re.I) skipping = False only_upper = False for line in string.splitlines(): m = cpr_line.search(line) if m: line = line[m.start():] m = re.match(r'(.*<[^>]+>).*', line) if m: line = line[:m.end()] have_cpr = True if not have_cpr: continue end = False for regex in end_res: if regex.search(line): end = True break if end: break if modified.search(line): skipping = True continue if derived.search(line): skipping = True continue if only_upper: if lower.search(line): break elif upper.search(line) and not lower.search(line): only_upper = True line = left_res.match(line).group(1) while True: m = right_res.match(line) if not m: break line = m.group(1) if skipping: if len(line) == 0: skipping = False continue copyright += [line] t = '\n'.join(copyright).strip() return t def get_license_type(copyright): if re.match(r'^no support for.*', copyright): return "Default" if copyright == 'none' or copyright == '': return "Default" if re.search(r'NetBSD', copyright): return "NetBSD" if (re.search(r'Redistributions *(of)? *source +code', copyright) and re.search(r'Redistributions +in +binary +form', copyright)): if re.search(r'[tT]he +names? of', copyright): return "BSD3" else: return "BSD2" if (re.search(r'University', copyright) and re.search(r'California', copyright) and re.search(r'Berkeley', copyright)): return "UCB" if re.search(r'FreeBSD', copyright): return "FreeBSD" if (re.search(r'AGPL', copyright) or re.search(r'Affero General Public License', copyright)): if re.search(r'version 3', copyright): return "AGPL3" return "AGPL" if re.search(r'the GPL', copyright): if re.search(r'version 2', copyright): return "GPL2" if re.search(r'version 3', copyright): return "GPL3" return "GPL" return "Other" def find_copyright_source(name, mime): with open(name, 'rb') as f: text = f.read().decode('utf-8', errors='ignore') try: comments = comment_parser.extract_comments_from_str(text, mime) except: return None tog = re.compile(r'.*Open Group Base Specification', re.I | re.S) m = re.compile(r'.*copyright.*', re.I | re.S) for i in range(len(comments)): comment = comments[i] if tog.match(comment.text()): continue if m.match(comment.text()): bits = comment.text() line = comments[i].line_number() + 1 i += 1 while i < len(comments): if comments[i].line_number() != line: break bits += '\n' + comments[i].text() i += 1 line += 1 return clean_copyright(bits) return None # Copyright holder is generally the first paragraph of the text def pick_split(split,match,use_end): if not match: return split start = match.start() end = match.start() if use_end: end = match.end() if not split: return (start, end) if start < split[0]: return (start, end) return split def get_split(copyright): lastcopy = None for lastcopy in re.finditer(r'copyright (\(c\))? *(19[7-9][0-9]|20[0-5][0-9])[^A-Z]*[A-Z][^\n]*', copyright, re.I|re.S): pass if lastcopy: para = None for para in re.finditer(r'\n\n', copyright, re.S): if para.start() >= lastcopy.end(): break all = None for a in re.finditer(r'all rights reserved\.?', copyright, re.I | re.S): if a.start() >= lastcopy.end(): all = a break else: para = re.search(r'\n\n', copyright, re.S) all = re.search(r'all rights reserved\.?', copyright, re.I | re.S) allorsome = re.search(r'all or some portions', copyright, re.I | re.S) licensed = re.search(r'This ', copyright, re.I | re.S) portions = re.search(r'Portions', copyright, re.I | re.S) mod = re.search(r'modification', copyright, re.I | re.S) perm = re.search(r'permission to', copyright, re.I | re.S) public = re.search(r'public domain', copyright, re.I | re.S) split = None split = pick_split(split, all, True) if not split: split = pick_split(split, para, True) split = pick_split(split, allorsome, False) split = pick_split(split, licensed, False) split = pick_split(split, portions, False) split = pick_split(split, mod, False) split = pick_split(split, perm, False) split = pick_split(split, public, False) return split def get_holder(copyright): split = get_split(copyright) if split: return copyright[:split[0]] return copyright def get_license(copyright): split = get_split(copyright) if split: copyright = copyright[split[1]:] m = re.match(r'^[ \t]*\n[ \t]*\n*', copyright, re.I|re.S) if m: copyright = copyright[m.end():] return copyright if copyright == "unknown file type": return copyright return "" def pound_comments(name): l = re.compile(r'^#[ \t]*(.*)$') comments = [] comment = [] for line in open(name).readlines(): m = l.match(line) if m: after = m.group(1) comment += [after] elif comment: comments += ['\n'.join(comment)] comment = [] if comment: comments += ['\n'.join(comment)] return comments def find_copyright_pound(name): comments = pound_comments(name) m = re.compile(r'.*copyright.*', re.I | re.S) for comment in comments: if m.match(comment): return clean_copyright(comment) return None def semi_comments(name): l = re.compile(r'^;;*[ \t]*(.*)$') comments = [] comment = [] for line in open(name).readlines(): m = l.match(line) if m: after = m.group(1) comment += [after] elif comment: comments += ['\n'.join(comment)] comment = [] if comment: comments += ['\n'.join(comment)] return comments def find_copyright_semi(name): comments = semi_comments(name) m = re.compile(r'.*copyright.*', re.I | re.S) for comment in comments: if m.match(comment): return clean_copyright(comment) return None def troff_comments(name): l = re.compile(r'^\.\\"[ \t]*(.*)$') comments = [] comment = [] for line in open(name).readlines(): m = l.match(line) if m: after = m.group(1) comment += [after] elif comment: comments += ['\n'.join(comment)] comment = [] if comment: comments += ['\n'.join(comment)] return comments def find_copyright_troff(name): comments = troff_comments(name) m = re.compile(r'.*copyright.*', re.I | re.S) for comment in comments: if m.match(comment): return clean_copyright(comment) return None def clean(str,chars): out = "" for c in str: if c not in chars: out += c.lower() return out def pack_copyright(copyright): return clean(copyright, " .,!*\n\t") def num_lines(name): with open(name, 'rb') as f: text = f.read().decode('utf-8', errors='ignore').splitlines() return len(text) def starts_with(pattern, name): with open(name, 'rb') as f: text = f.read().decode('utf-8', errors='ignore') m = re.search(pattern, text) return m and m.start() == 0 def file_contains(pattern, name): with open(name, 'rb') as f: text = f.read().decode('utf-8', errors='ignore') return re.search(pattern, text) def main(): names = [] for name in sys.argv[1:]: if name == '-': for line in sys.stdin: names += [line.strip()] else: names += [name] copyright_users = {} copyrights = {} copyright_files = {} for name in names: copyright = None # Data files don't need a license if re.match(r'.*\.t$', name): continue if re.match(r'.*\.cct$', name): continue if re.match(r'.*ChangeLog.*', name): continue if re.match(r'.*COPYING.*', name): continue if re.match(r'.*NEWS.*', name): continue if re.match(r'.*MAINTAINERS', name): continue if re.match(r'CODE_OF_CONDUCT.*', name): continue if re.match(r'CONTRIBUTING.*', name): continue if re.match(r'.*\.[ch]$', name) or re.match(r'.*\.ld$', name) or re.match(r'.*\.[ch]\.in$', name): copyright = find_copyright_source(name, 'text/x-c') elif re.match(r'.*\.[sS]$', name): copyright = find_copyright_semi(name) if not copyright: copyright = find_copyright_source(name, 'text/x-c') elif re.match(r'.*meson.*', name) or re.match(r'.*Makefile.*', name): copyright = find_copyright_pound(name) elif re.match(r'.*\.[123]$', name): copyright = find_copyright_troff(name) if not copyright: m = magic.from_file(name) if m is None: copyright = 'unknown file type' else: if re.search(r'troff', m): copyright = find_copyright_troff(name) elif re.search(r'C source', m): copyright = find_copyright_source(name, 'text/x-c') elif (re.search(r'POSIX shell script', m) or re.search(r'Bourne-Again shell script', m) or re.search(r'Python script', m) or re.search(r'Perl script', m) or starts_with(r'#', name)): copyright = find_copyright_pound(name) if not copyright: # Skip very short files without a copyright if num_lines(name) < 10: continue # Skip generated files if (file_contains(r'generated automatically', name) or file_contains(r'automatically generated', name)): continue copyright = '' i = pack_copyright(copyright) if i not in copyrights: copyrights[i] = copyright copyright_users[i] = [name] else: copyright_users[i] += [name] license_map = {} licenses = {} license_ids = {} license_name = {} holders = {} copyright_map = {} for i in copyrights: holder = get_holder(copyrights[i]) license = get_license(copyrights[i]) license_key = pack_copyright(license) type = get_license_type(license) if license_key in license_name: name = license_name[license_key] else: if type in license_ids: id = license_ids[type] else: id = 1 license_ids[type] = id + 1 name = "%s-%d" % (type, id) licenses[name] = license holders[name] = holder license_name[license_key] = name if name in copyright_map: copyright_map[name] += [i] else: copyright_map[name] = [i] for type in sorted(license_ids.keys()): for id in range(1,license_ids[type]): name = "%s-%d" % (type, id) for i in copyright_map[name]: holder = get_holder(copyrights[i]) license = get_license(copyrights[i]) print("Files:", end='') for file in copyright_users[i]: print(" %s" % file) print("Copyright:", end='') done = False for line in holder.splitlines(): for pat in (r'(.*)copyright(.*)', r'(.*)©(.*)', r'(.*)\(c\)(.*)', r'(.*) by (.*)', r'(.*)all rights reserved\.?(.*)'): m = re.match(pat, line, re.I) if m: line = m.group(1).strip() + ' ' + m.group(2).strip() line = line.strip() if re.match(r'(19[89][0-9]|2[0-2][0-9][0-9]).*', line): if done: print() print(' %s' % line, end='') done = True print() print("License: %s" % name) print() started = False for type in sorted(license_ids.keys()): for id in range(1,license_ids[type]): if started: print() started = True name = "%s-%d" % (type, id) print("License: %s" % name) for line in licenses[name].splitlines(): if len(line) == 0: line = '.' print(" %s" % line) main() picolibc-1.8.11/hello-world/000077500000000000000000000000001513574234600156305ustar00rootroot00000000000000picolibc-1.8.11/hello-world/.gitignore000066400000000000000000000000131513574234600176120ustar00rootroot00000000000000*.elf *.mappicolibc-1.8.11/hello-world/Makefile000066400000000000000000000060021513574234600172660ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # CFLAGS=--oslib=semihost --crt0=semihost -O2 CC_RISCV=riscv64-unknown-elf-gcc $(CFLAGS) CXX_RISCV=riscv64-unknown-elf-g++ $(CFLAGS) CC_ARM=arm-none-eabi-gcc $(CFLAGS) CXX_ARM=arm-none-eabi-g++ $(CFLAGS) CC_AARCH64=aarch64-none-elf-gcc $(CFLAGS) CXX_AARCH64=aarch64-none-elf-g++ $(CFLAGS) all: \ hello-world-arm.elf hello-world-aarch64.elf \ hello-world-riscv.elf hello-world-native.elf \ printf.elf printf-int.elf printf-float.elf all-cpp: \ hello-worldpp-arm.elf hello-worldpp-aarch64.elf \ hello-worldpp-riscv.elf hello-worldpp-native.elf hello-world-arm.elf: hello-world.c $(CC_ARM) -o $@ $^ -Wl,-Map=hello-world-arm.map hello-world-aarch64.elf: hello-world.c $(CC_AARCH64) -o $@ $^ -Wl,-Map=hello-world-aarch64.map hello-world-riscv.elf: hello-world.c $(CC_RISCV) -o $@ $^ -Wl,-Map=hello-world-riscv.map hello-world-native.elf: hello-world.c cc -o $@ $^ printf.elf: printf.c $(CC_ARM) -o $@ $^ -Wl,-Map=printf.map printf-int.elf: printf.c $(CC_ARM) --printf=i -o $@ $^ -Wl,-Map=printf-int.map printf-float.elf: printf.c $(CC_ARM) --printf=f -o $@ $^ -Wl,-Map=printf-float.map hello-worldpp-native.elf: hello-worldpp.cpp c++ -o $@ $^ hello-worldpp-arm.elf: hello-worldpp.cpp $(CXX_ARM) -Wl,-Map=hello-worldpp-arm.map -o $@ $^ hello-worldpp-aarch64.elf: hello-worldpp.cpp $(CXX_AARCH64) -Wl,-Map=hello-worldpp-aarch64.map -o $@ $^ hello-worldpp-riscv.elf: hello-worldpp.cpp $(CXX_RISCV) -Wl,-Map=hello-worldpp-riscv.map -o $@ $^ clean: rm -f *.elf *.map picolibc-1.8.11/hello-world/README.md000066400000000000000000000120151513574234600171060ustar00rootroot00000000000000# Hello World Building embedded applications is tricky in part because of the huge number of configuration settings necessary to get something that works. This example shows how to use the installed version of picolibc, and uses 'make' instead of 'meson' to try and make the operations as clear as possible. Here's our fine program: #include int main(void) { printf("hello, world\n"); return 0; } ## Selecting picolibc headers and C library Picolibc provides a GCC '.specs' file _(generated from picolibc.specs.in)_ which sets the search path for header files and picolibc libraries. gcc -specs=picolibc.specs ## Semihosting Our example program wants to display a string to stdout; because there aren't drivers for the serial ports emulated by qemu provided, the example uses Picolibc's semihosting support (`--oslib=semihost`) to direct stdout to the QEMU console: gcc -specs=picolibc.specs --oslib=semihost ## Target processor For ARM, QEMU emulates a "mps2-an385" board which has a Cortex-M3 processor: arm-none-eabi-gcc -specs=picolibc.specs --oslib=semihost -mcpu=cortex-m3 64-bit ARM (aarch64) processors are pretty much the same, so the default target code will run fine on a cortex-a57 processor as supported by QEMU: aarch64-linux-gnu-gcc -specs=picolibc.specs --oslib-semihost For RISC-V, QEMU lets you specify which CPU core you want, so we'll use something that looks like a SiFive E31 chip. That's a 32-bit processor with the 'imac' options (integer, multiply, atomics, compressed) and uses the 'ilp32' ABI (32-bit integer, long and pointer) riscv64-unknown-elf-gcc -specs=picolibc.specs --oslib-semihost -march=rv32imac -mabi=ilp32 ## Target Memory Layout The application needs to be linked at addresses which correspond to where the target memories are addressed. The default linker script provided with picolibc, `picolibc.ld`, assumes that the target device will have two kinds of memory, one for code and read-only data and another kind for read-write data. However, the linker script has no idea where those memories are placed in the address space. The example specifies those by setting a few values before including `picolibc.ld`. The mps2-an385 has at least 16kB of flash starting at 0. Picolibc places a small interrupt vector there which points at the first instruction of _start. The mps2-an385 also has 64kB of RAM starting at 0x20000000, so arm.ld looks like this: __flash = 0x00000000; __flash_size = 0x00004000; __ram = 0x20000000; __ram_size = 0x00010000; __stack_size = 1k; INCLUDE picolibc.ld The aarch64 virt model lets you define whatever memory spaces you like,so we'll just stick things at 0x40000000 (aarch64.ld): __flash = 0x40000000; __flash_size = 0x00400000; __ram = 0x40400000; __ram_size = 0x00200000; __stack_size = 8k; INCLUDE picolibc.ld For the RISC-V 'spike' model, you can have as much memory as you like, but execution starts at 0x80000000 so the first instruction in the application needs to land there. Picolibc on RISC-V puts _start at the first location in read-only memory, so we set things up like this (this is riscv.ld): __flash = 0x80000000; __flash_size = 0x00080000; __ram = 0x80080000; __ram_size = 0x40000; __stack_size = 1k; INCLUDE picolibc.ld The `-T` flag is used to specify the linker script in the compile line: arm-none-eabi-gcc -specs=picolibc.specs --oslib=semihost -mcpu=cortex-m3 -Tarm.ld aarch64-linux-gnu-gcc -specs=picolibc.specs --oslib=semihost -Taarch64.ld ## Final Commands The rest of the command line tells GCC what file to compile (hello-world.c) and where to put the output (hello-world-riscv.elf and hello-world-arm.elf): riscv64-unknown-elf-gcc --specs=picolibc.specs --oslib=semihost -march=rv32imac -mabi=ilp32 -Thello-world-riscv.ld -o hello-world-riscv.elf hello-world.c arm-none-eabi-gcc --specs=picolibc.specs --oslib=semihost -mcpu=cortex-m3 -Thello-world-arm.ld -o hello-world-arm.elf hello-world.c ## Running Under QEMU To run the hello-world example under qemu, we need to construct a virtual machine suitable for this. That means enabling semihosting (`-semihosting-config enable=on`), disabling the monitor interface (-monitor none), the emulated UART (-serial none) and the graphical interface (`-nographic). For arm, we're using the mps2-an385 qemu-system-arm -semihosting-config enable=on -monitor none -serial none -nographic -machine mps2-an385,accel=tcg -kernel hello-world-arm.elf On aarch64, we use the 'virt' machine, which lets us plug in any processor we want. In this case, we'll use the cortex-a57: qemu-system-aarch64 -semihosting-config enable=on -monitor none -serial none -nographic -machine virt -cpu cortex-a57 -kernel hello-world-aarch64.elf Risc-V is similar to aarch64 in providing a virtual host into which you can install any virtual processor you want, in our case, an rv32: qemu-system-riscv32 -semihosting-config enable=on -monitor none -serial none -nographic -machine virt,accel=tcg -cpu rv32 -bios none -kernel hello-world-riscv.elf picolibc-1.8.11/hello-world/aarch64-cpp.ld000066400000000000000000000002261513574234600201610ustar00rootroot00000000000000__flash = 0x40000000; __flash_size = 0x00400000; __ram = 0x40400000; __ram_size = 0x00200000; __stack_size = 8k; INCLUDE picolibcpp.ld picolibc-1.8.11/hello-world/aarch64.ld000066400000000000000000000002241513574234600173770ustar00rootroot00000000000000__flash = 0x40000000; __flash_size = 0x00400000; __ram = 0x40400000; __ram_size = 0x00200000; __stack_size = 8k; INCLUDE picolibc.ld picolibc-1.8.11/hello-world/arm-cpp.ld000066400000000000000000000002261513574234600175100ustar00rootroot00000000000000__flash = 0x00000000; __flash_size = 0x00100000; __ram = 0x20000000; __ram_size = 0x00010000; __stack_size = 1k; INCLUDE picolibcpp.ld picolibc-1.8.11/hello-world/arm.ld000066400000000000000000000002241513574234600167260ustar00rootroot00000000000000__flash = 0x00000000; __flash_size = 0x00100000; __ram = 0x20000000; __ram_size = 0x00010000; __stack_size = 1k; INCLUDE picolibc.ld picolibc-1.8.11/hello-world/hello-world.c000066400000000000000000000032661513574234600202330ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include int main(void) { printf("hello, world\n"); exit(0); } picolibc-1.8.11/hello-world/hello-worldpp.cpp000066400000000000000000000034371513574234600211330ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include int main() { std::cout << "Hello, world!\n"; try { throw 20; } catch (int param) { std::cout << "int exception " << param << '\n'; } std::cout << "Goodbye, world!\n"; exit(0); } picolibc-1.8.11/hello-world/printf.c000066400000000000000000000034541513574234600173040ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #ifndef printf_float #define printf_float(x) (x) #endif void main(void) { printf(" 2⁶¹ = %lld π ≃ %.17g\n", 1ll << 61, printf_float(3.141592653589793)); _Exit(0); } picolibc-1.8.11/hello-world/riscv-cpp.ld000066400000000000000000000002051513574234600200540ustar00rootroot00000000000000__flash = 0x80000000; __flash_size = 0x00080000; __ram = 0x80080000; __ram_size = 0x40000; __stack_size = 1k; INCLUDE picolibcpp.ld picolibc-1.8.11/hello-world/riscv.ld000066400000000000000000000002031513574234600172720ustar00rootroot00000000000000__flash = 0x80000000; __flash_size = 0x00080000; __ram = 0x80080000; __ram_size = 0x40000; __stack_size = 1k; INCLUDE picolibc.ld picolibc-1.8.11/hello-world/run-aarch64000077500000000000000000000035451513574234600176170ustar00rootroot00000000000000#!/bin/sh # # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # qemu="qemu-system-aarch64" # select the program elf=hello-world-aarch64.elf case $1 in *.elf) elf="$1" shift; ;; esac # Set the target machine machine=virt cpu=cortex-a57 $qemu -semihosting-config enable=on -monitor none -serial none -nographic -machine $machine -cpu $cpu -kernel $elf "$@" picolibc-1.8.11/hello-world/run-aarch64++000077500000000000000000000041661513574234600177450ustar00rootroot00000000000000#!/bin/sh # # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # qemu="qemu-system-aarch64" # select the program elf=hello-world++-aarch64.elf # Set the target machine machine=virt cpu=cortex-a57 # Map stdio to a multiplexed character device so we can use it # for the monitor and semihosting output chardev=stdio,mux=on,id=stdio0 # Point the semihosting driver at our new chardev semi=enable=on,chardev=stdio0,arg="test-file" # Disable monitor mon=none # Disable the serial port serial=none $qemu -chardev $chardev -semihosting-config $semi -monitor $mon -serial $serial -machine $machine -cpu $cpu -kernel $elf -nographic "$@" picolibc-1.8.11/hello-world/run-arm000077500000000000000000000035431513574234600171440ustar00rootroot00000000000000#!/bin/sh # # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # qemu="qemu-system-arm" # select the program elf=hello-world-arm.elf case $1 in *.elf) elf="$1" shift; ;; esac # Set the target machine machine=mps2-an385,accel=tcg cpu=cortex-m3 $qemu -semihosting-config enable=on -monitor none -serial none -nographic -machine $machine -kernel $elf "$@" picolibc-1.8.11/hello-world/run-riscv000077500000000000000000000035621513574234600175140ustar00rootroot00000000000000#!/bin/sh # # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # qemu="qemu-system-riscv32" # select the program elf=hello-world-riscv.elf case $1 in *.elf) elf="$1" shift; ;; esac # Set the target machine machine=virt,accel=tcg cpu=rv32 $qemu -semihosting-config enable=on -monitor none -serial none -nographic -machine $machine -cpu $cpu -bios none -kernel $elf "$@" picolibc-1.8.11/hello-world/run-riscv++000077500000000000000000000043251513574234600176400ustar00rootroot00000000000000#!/bin/sh # # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # qemu="qemu-system-riscv32" # select the program #elf=hello-world-riscv.elf elf=hello-world++-riscv.elf # Set the target machine machine=virt,accel=tcg cpu=rv32 # Map stdio to a multiplexed character device so we can use it # for the monitor and semihosting output chardev=stdio,mux=on,id=stdio0 # Point the semihosting driver at our new chardev semi=enable=on,chardev=stdio0,arg="test-file" # Point the monitor at the new chardev too mon=chardev=stdio0,mode=readline # Disable the serial port serial=chardev:stdio0 $qemu -chardev $chardev -semihosting-config $semi -mon $mon -serial $serial -machine $machine -cpu $cpu -kernel $elf -bios none -nographic "$@" picolibc-1.8.11/hello-world/test-file000066400000000000000000000000261513574234600174450ustar00rootroot00000000000000Data from a test file picolibc-1.8.11/libc/000077500000000000000000000000001513574234600143115ustar00rootroot00000000000000picolibc-1.8.11/libc/CMakeLists.txt000066400000000000000000000037711513574234600170610ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # add_subdirectory(machine) add_subdirectory(include) add_subdirectory(argz) add_subdirectory(ctype) add_subdirectory(errno) add_subdirectory(iconv) add_subdirectory(misc) add_subdirectory(posix) add_subdirectory(search) add_subdirectory(signal) add_subdirectory(ssp) add_subdirectory(stdio) add_subdirectory(stdlib) add_subdirectory(string) add_subdirectory(time) add_subdirectory(uchar) add_subdirectory(xdr) add_subdirectory(locale) add_subdirectory(ubsan) picolibc-1.8.11/libc/argz/000077500000000000000000000000001513574234600152545ustar00rootroot00000000000000picolibc-1.8.11/libc/argz/CMakeLists.txt000066400000000000000000000035531513574234600200220ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources( argz_add.c argz_add_sep.c argz_append.c argz_count.c argz_create.c argz_create_sep.c argz_delete.c argz_extract.c argz_insert.c argz_next.c argz_replace.c argz_stringify.c buf_findstr.c envz_add.c envz_entry.c envz_get.c envz_merge.c envz_remove.c envz_strip.c ) picolibc-1.8.11/libc/argz/argz_add.c000066400000000000000000000012371513574234600171760ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include #include #include error_t argz_add(char **argz, size_t *argz_len, const char *str) { size_t len_to_add = 0; size_t last = *argz_len; if (str == NULL) return 0; len_to_add = strlen(str) + 1; *argz_len += len_to_add; if (!(*argz = (char *)realloc(*argz, *argz_len))) return ENOMEM; memcpy(*argz + last, str, len_to_add); return 0; } picolibc-1.8.11/libc/argz/argz_add_sep.c000066400000000000000000000013561513574234600200470ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include #include #include error_t argz_add_sep(char **argz, size_t *argz_len, const char *str, int sep) { char *str_argz = 0; size_t str_argz_len = 0; size_t last = *argz_len; argz_create_sep(str, sep, &str_argz, &str_argz_len); if (str_argz_len) { *argz_len += str_argz_len; if (!(*argz = (char *)realloc(*argz, *argz_len))) return ENOMEM; memcpy(*argz + last, str_argz, str_argz_len); } return 0; } picolibc-1.8.11/libc/argz/argz_append.c000066400000000000000000000011641513574234600177140ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include #include #include error_t argz_append(char **argz, size_t *argz_len, const char *buf, size_t buf_len) { if (buf_len) { size_t last = *argz_len; *argz_len += buf_len; if (!(*argz = (char *)realloc(*argz, *argz_len))) return ENOMEM; memcpy(*argz + last, buf, buf_len); } return 0; } picolibc-1.8.11/libc/argz/argz_count.c000066400000000000000000000007301513574234600175730ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include size_t argz_count(const char *argz, size_t argz_len) { size_t i; size_t count = 0; for (i = 0; i < argz_len; i++) { if (argz[i] == '\0') count++; } return count; } picolibc-1.8.11/libc/argz/argz_create.c000066400000000000000000000016431513574234600177120ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include #include #include error_t argz_create(char * const argv[], char **argz, size_t *argz_len) { int argc = 0; int i = 0; size_t len = 0; char *iter; *argz_len = 0; if (*argv == NULL) { *argz = NULL; return 0; } while (argv[argc]) { *argz_len += (strlen(argv[argc]) + 1); argc++; } /* There are argc strings to copy into argz. */ if (!(*argz = (char *)malloc(*argz_len))) return ENOMEM; iter = *argz; for (i = 0; i < argc; i++) { len = strlen(argv[i]) + 1; memcpy(iter, argv[i], len); iter += len; } return 0; } picolibc-1.8.11/libc/argz/argz_create_sep.c000066400000000000000000000024701513574234600205600ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #define _DEFAULT_SOURCE #include #include #include #include #include error_t argz_create_sep(const char *string, int sep, char **argz, size_t *argz_len) { size_t len = 0; int i = 0; int num_strings = 0; char delim[2]; char *running = 0; char *old_running = 0; char *token = 0; char *iter = 0; *argz_len = 0; if (!string || string[0] == '\0') { *argz = NULL; return 0; } delim[0] = (char)sep; delim[1] = '\0'; running = strdup(string); old_running = running; while ((token = strsep(&running, delim))) { len = strlen(token); *argz_len += (len + 1); num_strings++; } free(old_running); if (!(*argz = (char *)malloc(*argz_len))) return ENOMEM; running = strdup(string); old_running = running; iter = *argz; for (i = 0; i < num_strings; i++) { token = strsep(&running, delim); len = strlen(token) + 1; memcpy(iter, token, len); iter += len; } free(old_running); return 0; } picolibc-1.8.11/libc/argz/argz_delete.c000066400000000000000000000014111513574234600177020ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include #include #include error_t argz_delete(char **argz, size_t *argz_len, char *entry) { int len = 0; char *moveto = entry; if (entry) { len = strlen(entry) + 1; entry += len; memmove(moveto, entry, *argz + *argz_len - entry); *argz_len -= len; if (!(*argz = (char *)realloc(*argz, *argz_len))) return ENOMEM; if (*argz_len <= 0) { free(*argz); *argz = NULL; } } return 0; } picolibc-1.8.11/libc/argz/argz_extract.c000066400000000000000000000012441513574234600201160ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include void argz_extract(char *argz, size_t argz_len, char **argv) { size_t i = 0; size_t j = 0; const size_t count = argz_count(argz, argz_len); if (argz_len > 1) for (i = argz_len - 2; i > 0; i--) { if (argz[i] == '\0') { j++; argv[count - j] = &argz[i + 1]; } } argv[0] = &argz[0]; argv[count] = NULL; } picolibc-1.8.11/libc/argz/argz_insert.c000066400000000000000000000020341513574234600177460ustar00rootroot00000000000000/* Copyright (C) 2002, 2005 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include #include #include #define __need_ptrdiff_t #include error_t argz_insert(char **argz, size_t *argz_len, char *before, const char *entry) { int len = 0; ptrdiff_t delta; if (before == NULL) return argz_add(argz, argz_len, entry); if (before < *argz || before >= *argz + *argz_len) return EINVAL; while (before != *argz && before[-1]) before--; /* delta will always be non-negative, and < *argz_len */ delta = before - *argz; len = strlen(entry) + 1; if (!(*argz = (char *)realloc(*argz, *argz_len + len))) return ENOMEM; memmove(*argz + delta + len, *argz + delta, *argz_len - delta); memcpy(*argz + delta, entry, len); *argz_len += len; return 0; } picolibc-1.8.11/libc/argz/argz_next.c000066400000000000000000000012601513574234600174200ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include #include #include char * argz_next(char *argz, size_t argz_len, const char *entry) { if (entry) { while (*entry != '\0') entry++; entry++; if (entry >= argz + argz_len) return NULL; else return (char *)entry; } else { if (argz_len > 0) return (char *)argz; else return NULL; } } picolibc-1.8.11/libc/argz/argz_replace.c000066400000000000000000000046061513574234600200640ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include #include #include #include "buf_findstr.h" error_t argz_replace(char **argz, size_t *argz_len, const char *str, const char *with, unsigned *replace_count) { const size_t str_len = strlen(str); const size_t with_len = strlen(with); const ssize_t len_diff = with_len - str_len; char *buf_iter = *argz; size_t buf_len = *argz_len; char *last_iter = NULL; char *new_argz = NULL; size_t new_argz_len = 0; char *new_argz_iter = NULL; char *argz_realloc = NULL; *replace_count = 0; new_argz_len = *argz_len; while (buf_len) { if (_buf_findstr(str, &buf_iter, &buf_len)) { *replace_count += 1; new_argz_len += len_diff; } } if (*replace_count) { if (!(new_argz = (char *)malloc(new_argz_len))) return ENOMEM; buf_iter = *argz; buf_len = *argz_len; last_iter = buf_iter; new_argz_iter = new_argz; while (buf_len) { if (_buf_findstr(str, &buf_iter, &buf_len)) { /* copy everything up to, but not including str, from old argz to new argz. */ memcpy(new_argz_iter, last_iter, buf_iter - last_iter - str_len); new_argz_iter += (buf_iter - last_iter - str_len); /* copy replacement string. */ memcpy(new_argz_iter, with, with_len); new_argz_iter += with_len; last_iter = buf_iter; } } /* copy everything after last occurrence of str. */ memcpy(new_argz_iter, last_iter, *argz + *argz_len - last_iter); /* reallocate argz, and copy over the new value. */ if (!(argz_realloc = (char *)realloc(*argz, new_argz_len))) { free(new_argz); return ENOMEM; } *argz = argz_realloc; memcpy(*argz, new_argz, new_argz_len); *argz_len = new_argz_len; if (*argz_len == 0) { free(*argz); *argz = NULL; } free(new_argz); } return 0; } picolibc-1.8.11/libc/argz/argz_stringify.c000066400000000000000000000010571513574234600204640ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include void argz_stringify(char *argz, size_t argz_len, int sep) { size_t i; /* len includes trailing \0, which we don't want to replace. */ if (argz_len > 1) for (i = 0; i < argz_len - 1; i++) { if (argz[i] == '\0') argz[i] = (char)sep; } } picolibc-1.8.11/libc/argz/buf_findstr.c000066400000000000000000000017621513574234600177330ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include #include #include "buf_findstr.h" /* Find string str in buffer buf of length buf_len. Point buf to character after string, or set it to NULL if end of buffer is reached. Return 1 if found, 0 if not. */ int _buf_findstr(const char *str, char **buf, size_t *buf_len) { size_t i = 0; size_t j = 0; for (i = 0; i < *buf_len; i++) { if (str[0] == (*buf)[i]) { j = i; while (str[j - i] && (str[j - i] == (*buf)[j])) j++; if (str[j - i] == '\0') { *buf += j; *buf_len -= j; return 1; } } } if (i == *buf_len) { *buf += *buf_len; *buf_len = 0; } return 0; } picolibc-1.8.11/libc/argz/buf_findstr.h000066400000000000000000000007251513574234600177360ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include /* Find string str in buffer buf of length buf_len. Point buf to character after string, or set it to NULL if end of buffer is reached. Return 1 if found, 0 if not. */ int _buf_findstr(const char *str, char **buf, size_t *buf_len); picolibc-1.8.11/libc/argz/envz_add.c000066400000000000000000000017671513574234600172250ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include #include #include #include error_t envz_add(char **envz, size_t *envz_len, const char *name, const char *value) { char *concat = NULL; int name_len = 0; int val_len = 0; int retval = 0; envz_remove(envz, envz_len, name); if (value) { name_len = strlen(name); val_len = strlen(value); if (!(concat = (char *)malloc(name_len + val_len + 2))) return ENOMEM; memcpy(concat, name, name_len); concat[name_len] = '='; memcpy(concat + name_len + 1, value, val_len + 1); retval = argz_add(envz, envz_len, concat); free(concat); } else { retval = argz_add(envz, envz_len, name); } return retval; } picolibc-1.8.11/libc/argz/envz_entry.c000066400000000000000000000017671513574234600176360ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include #include #include #include "buf_findstr.h" char * envz_entry(const char *envz, size_t envz_len, const char *name) { char *buf_ptr = (char *)envz; size_t buf_len = envz_len; while (buf_len) { if (_buf_findstr(name, &buf_ptr, &buf_len)) { if (buf_ptr) { if (*buf_ptr == '=' || *buf_ptr == '\0') { buf_ptr--; /* Move buf_ptr back to start of entry. */ while (*buf_ptr != '\0' && buf_ptr != envz) buf_ptr--; if (*buf_ptr == '\0') buf_ptr++; return (char *)buf_ptr; } } } } return 0; } picolibc-1.8.11/libc/argz/envz_get.c000066400000000000000000000015401513574234600172410ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include #include #include #include "buf_findstr.h" char * envz_get(const char *envz, size_t envz_len, const char *name) { char *buf_ptr = (char *)envz; size_t buf_len = envz_len; while (buf_len) { if (_buf_findstr(name, &buf_ptr, &buf_len)) { if (*buf_ptr == '=') { buf_ptr++; return (char *)buf_ptr; } else { if (*buf_ptr == '\0') /* NULL entry. */ return NULL; } } } /* No matching entries found. */ return NULL; } picolibc-1.8.11/libc/argz/envz_merge.c000066400000000000000000000027471513574234600175730ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #define _DEFAULT_SOURCE #include #include #include #include #include #include error_t envz_merge(char **envz, size_t *envz_len, const char *envz2, size_t envz2_len, int override) { char *entry = NULL; char *name_str = NULL; char *val_str = NULL; char *name_iter = NULL; int retval = 0; while ((entry = argz_next((char *)envz2, envz2_len, entry)) && !retval) { if (!override) { name_str = strdup(entry); if (!name_str) return ENOMEM; name_iter = strchr(name_str, '='); if (name_iter) *name_iter = '\0'; if (!envz_entry(*envz, *envz_len, name_str)) { retval = argz_add(envz, envz_len, entry); } free(name_str); } else { name_str = strdup(entry); if (!name_str) return ENOMEM; name_iter = strchr(name_str, '='); if (name_iter) { *name_iter = '\0'; val_str = name_iter + 1; } else { val_str = NULL; } retval = envz_add(envz, envz_len, name_str, val_str); free(name_str); } } return retval; } picolibc-1.8.11/libc/argz/envz_remove.c000066400000000000000000000014371513574234600177640ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include #include #include #include void envz_remove(char **envz, size_t *envz_len, const char *name) { char *entry = NULL; size_t len = 0; entry = envz_entry(*envz, *envz_len, name); if (entry) { len = strlen(entry) + 1; /* Not the last entry. */ if (*envz + *envz_len != entry + len - 1) { memmove(entry, entry + len, *envz + *envz_len - entry - len); } *envz = (char *)realloc(*envz, *envz_len - len); *envz_len -= len; } } picolibc-1.8.11/libc/argz/envz_strip.c000066400000000000000000000017561513574234600176340ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #include #include #include #include void envz_strip(char **envz, size_t *envz_len) { char *entry = 0; int len = 0; int null_found = 0; while ((entry = argz_next(*envz, *envz_len, entry))) { if (!strchr(entry, '=')) { null_found = 1; len = strlen(entry) + 1; /* Make sure this is not the last entry in envz. If it is, it will be chopped off by the realloc anyway.*/ if (*envz + *envz_len != entry + len - 1) { memmove(entry, entry + len, *envz + *envz_len - entry - len); } *envz_len -= len; } } if (null_found) { *envz = (char *)realloc(*envz, *envz_len); } } picolibc-1.8.11/libc/argz/meson.build000066400000000000000000000045221513574234600174210ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_argz = [ 'argz_add.c', 'argz_add_sep.c', 'argz_append.c', 'argz_count.c', 'argz_create.c', 'argz_create_sep.c', 'argz_delete.c', 'argz_extract.c', 'argz_insert.c', 'argz_next.c', 'argz_replace.c', 'argz_stringify.c', 'buf_findstr.c', 'envz_add.c', 'envz_entry.c', 'envz_get.c', 'envz_merge.c', 'envz_remove.c', 'envz_strip.c', ] hdrs_argz = [ 'buf_findstr.h', ] srcs_argz_use = [] foreach file : srcs_argz s_file = fs.replace_suffix(file, '.S') if file in srcs_machine message('libc/argz/' + file + ': machine overrides generic') elif s_file in srcs_machine message('libc/argz/' + s_file + ': machine overrides generic') else srcs_argz_use += file endif endforeach src_argz = files(srcs_argz_use) picolibc-1.8.11/libc/ctype/000077500000000000000000000000001513574234600154355ustar00rootroot00000000000000picolibc-1.8.11/libc/ctype/CMakeLists.txt000066400000000000000000000050411513574234600201750ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources( caseconv.c ctype_.c ctype_class.c ctype_table.c ctype_wide.c isalnum.c isalnum_l.c isalpha.c isalpha_l.c isascii.c isascii_l.c isblank.c isblank_l.c iscntrl.c iscntrl_l.c isdigit.c isdigit_l.c isgraph.c isgraph_l.c islower.c islower_l.c isprint.c isprint_l.c ispunct.c ispunct_l.c isspace.c isspace_l.c isupper.c isupper_l.c iswalnum.c iswalnum_l.c iswalpha.c iswalpha_l.c iswblank.c iswblank_l.c iswcntrl.c iswcntrl_l.c iswctype.c iswctype_l.c iswdigit.c iswdigit_l.c iswgraph.c iswgraph_l.c iswlower.c iswlower_l.c iswprint.c iswprint_l.c iswpunct.c iswpunct_l.c iswspace.c iswspace_l.c iswupper.c iswupper_l.c iswxdigit.c iswxdigit_l.c isxdigit.c isxdigit_l.c toascii.c toascii_l.c tolower.c tolower_l.c toupper.c toupper_l.c towctrans.c towctrans_l.c towlower.c towlower_l.c towupper.c towupper_l.c wctrans.c wctrans_l.c wctype.c wctype_l.c ) picolibc-1.8.11/libc/ctype/caseconv.c000066400000000000000000000021711513574234600174030ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _GNU_SOURCE #include #include #include #include "local.h" static const struct caseconv_entry table[] = { #include "caseconv.t" }; #define first(ce) ((wint_t)ce.first) #define last(ce) ((wint_t)(ce.first + ce.diff)) #define NCASECONV (sizeof table / sizeof table[0]) /* auxiliary function for binary search in interval properties table */ const struct caseconv_entry * __caseconv_lookup(wint_t ucs, locale_t locale) { size_t min = 0; size_t max = NCASECONV - 1; size_t mid; if (ucs >= 0x80 && __locale_is_C(locale)) return 0; if (ucs < first(table[0]) || ucs > last(table[max])) return 0; while (max >= min) { mid = (min + max) / 2; if (ucs > last(table[mid])) min = mid + 1; else if (ucs < first(table[mid])) max = mid - 1; else return &table[mid]; } return 0; } picolibc-1.8.11/libc/ctype/caseconv.t000066400000000000000000000215421513574234600174270ustar00rootroot00000000000000 {0x0041, 25, TOLO, 32}, {0x0061, 25, TOUP, -32}, {0x00B5, 0, TOUP, 743}, {0x00C0, 22, TOLO, 32}, {0x00D8, 6, TOLO, 32}, {0x00E0, 22, TOUP, -32}, {0x00F8, 6, TOUP, -32}, {0x00FF, 0, TOUP, 121}, {0x0100, 47, TO1, EVENCAP}, {0x0130, 0, TOLO, -199}, {0x0131, 0, TOUP, -232}, {0x0132, 5, TO1, EVENCAP}, {0x0139, 15, TO1, ODDCAP}, {0x014A, 45, TO1, EVENCAP}, {0x0178, 0, TOLO, -121}, {0x0179, 5, TO1, ODDCAP}, {0x017F, 0, TOUP, -300}, {0x0180, 0, TOUP, 195}, {0x0181, 0, TOLO, 210}, {0x0182, 3, TO1, EVENCAP}, {0x0186, 0, TOLO, 206}, {0x0187, 1, TO1, ODDCAP}, {0x0189, 1, TOLO, 205}, {0x018B, 1, TO1, ODDCAP}, {0x018E, 0, TOLO, 79}, {0x018F, 0, TOLO, 202}, {0x0190, 0, TOLO, 203}, {0x0191, 1, TO1, ODDCAP}, {0x0193, 0, TOLO, 205}, {0x0194, 0, TOLO, 207}, {0x0195, 0, TOUP, 97}, {0x0196, 0, TOLO, 211}, {0x0197, 0, TOLO, 209}, {0x0198, 1, TO1, EVENCAP}, {0x019A, 0, TOUP, 163}, {0x019B, 0, TOUP, 42561}, {0x019C, 0, TOLO, 211}, {0x019D, 0, TOLO, 213}, {0x019E, 0, TOUP, 130}, {0x019F, 0, TOLO, 214}, {0x01A0, 5, TO1, EVENCAP}, {0x01A6, 0, TOLO, 218}, {0x01A7, 1, TO1, ODDCAP}, {0x01A9, 0, TOLO, 218}, {0x01AC, 1, TO1, EVENCAP}, {0x01AE, 0, TOLO, 218}, {0x01AF, 1, TO1, ODDCAP}, {0x01B1, 1, TOLO, 217}, {0x01B3, 3, TO1, ODDCAP}, {0x01B7, 0, TOLO, 219}, {0x01B8, 1, TO1, EVENCAP}, {0x01BC, 1, TO1, EVENCAP}, {0x01BF, 0, TOUP, 56}, {0x01C4, 0, TOLO, 2}, {0x01C5, 0, TOBOTH, 0}, {0x01C6, 0, TOUP, -2}, {0x01C7, 0, TOLO, 2}, {0x01C8, 0, TOBOTH, 0}, {0x01C9, 0, TOUP, -2}, {0x01CA, 0, TOLO, 2}, {0x01CB, 0, TOBOTH, 0}, {0x01CC, 0, TOUP, -2}, {0x01CD, 15, TO1, ODDCAP}, {0x01DD, 0, TOUP, -79}, {0x01DE, 17, TO1, EVENCAP}, {0x01F1, 0, TOLO, 2}, {0x01F2, 0, TOBOTH, 0}, {0x01F3, 0, TOUP, -2}, {0x01F4, 1, TO1, EVENCAP}, {0x01F6, 0, TOLO, -97}, {0x01F7, 0, TOLO, -56}, {0x01F8, 39, TO1, EVENCAP}, {0x0220, 0, TOLO, -130}, {0x0222, 17, TO1, EVENCAP}, {0x023A, 0, TOLO, 10795}, {0x023B, 1, TO1, ODDCAP}, {0x023D, 0, TOLO, -163}, {0x023E, 0, TOLO, 10792}, {0x023F, 1, TOUP, 10815}, {0x0241, 1, TO1, ODDCAP}, {0x0243, 0, TOLO, -195}, {0x0244, 0, TOLO, 69}, {0x0245, 0, TOLO, 71}, {0x0246, 9, TO1, EVENCAP}, {0x0250, 0, TOUP, 10783}, {0x0251, 0, TOUP, 10780}, {0x0252, 0, TOUP, 10782}, {0x0253, 0, TOUP, -210}, {0x0254, 0, TOUP, -206}, {0x0256, 1, TOUP, -205}, {0x0259, 0, TOUP, -202}, {0x025B, 0, TOUP, -203}, {0x025C, 0, TOUP, 42319}, {0x0260, 0, TOUP, -205}, {0x0261, 0, TOUP, 42315}, {0x0263, 0, TOUP, -207}, {0x0264, 0, TOUP, 42343}, {0x0265, 0, TOUP, 42280}, {0x0266, 0, TOUP, 42308}, {0x0268, 0, TOUP, -209}, {0x0269, 0, TOUP, -211}, {0x026A, 0, TOUP, 42308}, {0x026B, 0, TOUP, 10743}, {0x026C, 0, TOUP, 42305}, {0x026F, 0, TOUP, -211}, {0x0271, 0, TOUP, 10749}, {0x0272, 0, TOUP, -213}, {0x0275, 0, TOUP, -214}, {0x027D, 0, TOUP, 10727}, {0x0280, 0, TOUP, -218}, {0x0282, 0, TOUP, 42307}, {0x0283, 0, TOUP, -218}, {0x0287, 0, TOUP, 42282}, {0x0288, 0, TOUP, -218}, {0x0289, 0, TOUP, -69}, {0x028A, 1, TOUP, -217}, {0x028C, 0, TOUP, -71}, {0x0292, 0, TOUP, -219}, {0x029D, 0, TOUP, 42261}, {0x029E, 0, TOUP, 42258}, {0x0345, 0, TOUP, 84}, {0x0370, 3, TO1, EVENCAP}, {0x0376, 1, TO1, EVENCAP}, {0x037B, 2, TOUP, 130}, {0x037F, 0, TOLO, 116}, {0x0386, 0, TOLO, 38}, {0x0388, 2, TOLO, 37}, {0x038C, 0, TOLO, 64}, {0x038E, 1, TOLO, 63}, {0x0391, 16, TOLO, 32}, {0x03A3, 8, TOLO, 32}, {0x03AC, 0, TOUP, -38}, {0x03AD, 2, TOUP, -37}, {0x03B1, 16, TOUP, -32}, {0x03C2, 0, TOUP, -31}, {0x03C3, 8, TOUP, -32}, {0x03CC, 0, TOUP, -64}, {0x03CD, 1, TOUP, -63}, {0x03CF, 0, TOLO, 8}, {0x03D0, 0, TOUP, -62}, {0x03D1, 0, TOUP, -57}, {0x03D5, 0, TOUP, -47}, {0x03D6, 0, TOUP, -54}, {0x03D7, 0, TOUP, -8}, {0x03D8, 23, TO1, EVENCAP}, {0x03F0, 0, TOUP, -86}, {0x03F1, 0, TOUP, -80}, {0x03F2, 0, TOUP, 7}, {0x03F3, 0, TOUP, -116}, {0x03F4, 0, TOLO, -60}, {0x03F5, 0, TOUP, -96}, {0x03F7, 1, TO1, ODDCAP}, {0x03F9, 0, TOLO, -7}, {0x03FA, 1, TO1, EVENCAP}, {0x03FD, 2, TOLO, -130}, {0x0400, 15, TOLO, 80}, {0x0410, 31, TOLO, 32}, {0x0430, 31, TOUP, -32}, {0x0450, 15, TOUP, -80}, {0x0460, 33, TO1, EVENCAP}, {0x048A, 53, TO1, EVENCAP}, {0x04C0, 0, TOLO, 15}, {0x04C1, 13, TO1, ODDCAP}, {0x04CF, 0, TOUP, -15}, {0x04D0, 95, TO1, EVENCAP}, {0x0531, 37, TOLO, 48}, {0x0561, 37, TOUP, -48}, {0x10A0, 37, TOLO, 7264}, {0x10C7, 0, TOLO, 7264}, {0x10CD, 0, TOLO, 7264}, {0x10D0, 42, TOUP, 3008}, {0x10FD, 2, TOUP, 3008}, {0x13A0, 79, TOLO, 38864}, {0x13F0, 5, TOLO, 8}, {0x13F8, 5, TOUP, -8}, {0x1C80, 0, TOUP, -6254}, {0x1C81, 0, TOUP, -6253}, {0x1C82, 0, TOUP, -6244}, {0x1C83, 1, TOUP, -6242}, {0x1C85, 0, TOUP, -6243}, {0x1C86, 0, TOUP, -6236}, {0x1C87, 0, TOUP, -6181}, {0x1C88, 0, TOUP, 35266}, {0x1C89, 1, TO1, ODDCAP}, {0x1C90, 42, TOLO, -3008}, {0x1CBD, 2, TOLO, -3008}, {0x1D79, 0, TOUP, 35332}, {0x1D7D, 0, TOUP, 3814}, {0x1D8E, 0, TOUP, 35384}, {0x1E00, 149, TO1, EVENCAP}, {0x1E9B, 0, TOUP, -59}, {0x1E9E, 0, TOLO, -7615}, {0x1EA0, 95, TO1, EVENCAP}, {0x1F00, 7, TOUP, 8}, {0x1F08, 7, TOLO, -8}, {0x1F10, 5, TOUP, 8}, {0x1F18, 5, TOLO, -8}, {0x1F20, 7, TOUP, 8}, {0x1F28, 7, TOLO, -8}, {0x1F30, 7, TOUP, 8}, {0x1F38, 7, TOLO, -8}, {0x1F40, 5, TOUP, 8}, {0x1F48, 5, TOLO, -8}, {0x1F51, 0, TOUP, 8}, {0x1F53, 0, TOUP, 8}, {0x1F55, 0, TOUP, 8}, {0x1F57, 0, TOUP, 8}, {0x1F59, 0, TOLO, -8}, {0x1F5B, 0, TOLO, -8}, {0x1F5D, 0, TOLO, -8}, {0x1F5F, 0, TOLO, -8}, {0x1F60, 7, TOUP, 8}, {0x1F68, 7, TOLO, -8}, {0x1F70, 1, TOUP, 74}, {0x1F72, 3, TOUP, 86}, {0x1F76, 1, TOUP, 100}, {0x1F78, 1, TOUP, 128}, {0x1F7A, 1, TOUP, 112}, {0x1F7C, 1, TOUP, 126}, {0x1F80, 7, TOUP, 8}, {0x1F88, 7, TOLO, -8}, {0x1F90, 7, TOUP, 8}, {0x1F98, 7, TOLO, -8}, {0x1FA0, 7, TOUP, 8}, {0x1FA8, 7, TOLO, -8}, {0x1FB0, 1, TOUP, 8}, {0x1FB3, 0, TOUP, 9}, {0x1FB8, 1, TOLO, -8}, {0x1FBA, 1, TOLO, -74}, {0x1FBC, 0, TOLO, -9}, {0x1FBE, 0, TOUP, -7205}, {0x1FC3, 0, TOUP, 9}, {0x1FC8, 3, TOLO, -86}, {0x1FCC, 0, TOLO, -9}, {0x1FD0, 1, TOUP, 8}, {0x1FD8, 1, TOLO, -8}, {0x1FDA, 1, TOLO, -100}, {0x1FE0, 1, TOUP, 8}, {0x1FE5, 0, TOUP, 7}, {0x1FE8, 1, TOLO, -8}, {0x1FEA, 1, TOLO, -112}, {0x1FEC, 0, TOLO, -7}, {0x1FF3, 0, TOUP, 9}, {0x1FF8, 1, TOLO, -128}, {0x1FFA, 1, TOLO, -126}, {0x1FFC, 0, TOLO, -9}, {0x2126, 0, TOLO, -7517}, {0x212A, 0, TOLO, -8383}, {0x212B, 0, TOLO, -8262}, {0x2132, 0, TOLO, 28}, {0x214E, 0, TOUP, -28}, {0x2160, 15, TOLO, 16}, {0x2170, 15, TOUP, -16}, {0x2183, 1, TO1, ODDCAP}, {0x24B6, 25, TOLO, 26}, {0x24D0, 25, TOUP, -26}, {0x2C00, 47, TOLO, 48}, {0x2C30, 47, TOUP, -48}, {0x2C60, 1, TO1, EVENCAP}, {0x2C62, 0, TOLO, -10743}, {0x2C63, 0, TOLO, -3814}, {0x2C64, 0, TOLO, -10727}, {0x2C65, 0, TOUP, -10795}, {0x2C66, 0, TOUP, -10792}, {0x2C67, 5, TO1, ODDCAP}, {0x2C6D, 0, TOLO, -10780}, {0x2C6E, 0, TOLO, -10749}, {0x2C6F, 0, TOLO, -10783}, {0x2C70, 0, TOLO, -10782}, {0x2C72, 1, TO1, EVENCAP}, {0x2C75, 1, TO1, ODDCAP}, {0x2C7E, 1, TOLO, -10815}, {0x2C80, 99, TO1, EVENCAP}, {0x2CEB, 3, TO1, ODDCAP}, {0x2CF2, 1, TO1, EVENCAP}, {0x2D00, 37, TOUP, -7264}, {0x2D27, 0, TOUP, -7264}, {0x2D2D, 0, TOUP, -7264}, {0xA640, 45, TO1, EVENCAP}, {0xA680, 27, TO1, EVENCAP}, {0xA722, 13, TO1, EVENCAP}, {0xA732, 61, TO1, EVENCAP}, {0xA779, 3, TO1, ODDCAP}, {0xA77D, 0, TOLO, -35332}, {0xA77E, 9, TO1, EVENCAP}, {0xA78B, 1, TO1, ODDCAP}, {0xA78D, 0, TOLO, -42280}, {0xA790, 3, TO1, EVENCAP}, {0xA794, 0, TOUP, 48}, {0xA796, 19, TO1, EVENCAP}, {0xA7AA, 0, TOLO, -42308}, {0xA7AB, 0, TOLO, -42319}, {0xA7AC, 0, TOLO, -42315}, {0xA7AD, 0, TOLO, -42305}, {0xA7AE, 0, TOLO, -42308}, {0xA7B0, 0, TOLO, -42258}, {0xA7B1, 0, TOLO, -42282}, {0xA7B2, 0, TOLO, -42261}, {0xA7B3, 0, TOLO, 928}, {0xA7B4, 15, TO1, EVENCAP}, {0xA7C4, 0, TOLO, -48}, {0xA7C5, 0, TOLO, -42307}, {0xA7C6, 0, TOLO, -35384}, {0xA7C7, 3, TO1, ODDCAP}, {0xA7CB, 0, TOLO, -42343}, {0xA7CC, 1, TO1, EVENCAP}, {0xA7D0, 1, TO1, EVENCAP}, {0xA7D6, 5, TO1, EVENCAP}, {0xA7DC, 0, TOLO, -42561}, {0xA7F5, 1, TO1, ODDCAP}, {0xAB53, 0, TOUP, -928}, {0xAB70, 79, TOUP, -38864}, {0xFF21, 25, TOLO, 32}, {0xFF41, 25, TOUP, -32}, {0x10400, 39, TOLO, 40}, {0x10428, 39, TOUP, -40}, {0x104B0, 35, TOLO, 40}, {0x104D8, 35, TOUP, -40}, {0x10570, 10, TOLO, 39}, {0x1057C, 14, TOLO, 39}, {0x1058C, 6, TOLO, 39}, {0x10594, 1, TOLO, 39}, {0x10597, 10, TOUP, -39}, {0x105A3, 14, TOUP, -39}, {0x105B3, 6, TOUP, -39}, {0x105BB, 1, TOUP, -39}, {0x10C80, 50, TOLO, 64}, {0x10CC0, 50, TOUP, -64}, {0x10D50, 21, TOLO, 32}, {0x10D70, 21, TOUP, -32}, {0x118A0, 31, TOLO, 32}, {0x118C0, 31, TOUP, -32}, {0x16E40, 31, TOLO, 32}, {0x16E60, 31, TOUP, -32}, {0x1E900, 33, TOLO, 34}, {0x1E922, 33, TOUP, -34}, picolibc-1.8.11/libc/ctype/categories.h000066400000000000000000000003161513574234600177330ustar00rootroot00000000000000/* Copyright (c) 2017 Thomas Wolff towo@towo.net */ /* category data */ #include enum category { #include "categories.cat" CAT_error = -1, }; extern enum category category(uint32_t ucs); picolibc-1.8.11/libc/ctype/ctype.tex000066400000000000000000000127511513574234600173110ustar00rootroot00000000000000/* Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @node Ctype @chapter Character Type Macros and Functions (@file{ctype.h}) This chapter groups macros (which are also available as subroutines) to classify characters into several categories (alphabetic, numeric, control characters, whitespace, and so on), or to perform simple character mappings. The header file @file{ctype.h} defines the macros. @menu * Function isalnum:: Alphanumeric character predicate (isalnum, isalnum_l) * Function isalpha:: Alphabetic character predicate (isalpha, isalpha_l) * Function isascii:: ASCII character predicate (isascii, isascii_l) * Function isblank:: Blank character predicate (isblank, isblank_l) * Function iscntrl:: Control character predicate (iscntrl, iscntrl_l) * Function isdigit:: Decimal digit predicate (isdigit, isdigit_l) * Function islower:: Lowercase character predicate (islower, islower_l) * Function isprint:: Printable character predicates (isprint, isprint_l. isgraph, isgraph_l) * Function ispunct:: Punctuation character predicate (ispunct, ispunct_l) * Function isspace:: Whitespace character predicate (isspace, isspace_l) * Function isupper:: Uppercase character predicate (isupper, isupper_l) * Function isxdigit:: Hexadecimal digit predicate (isxdigit, isxdigit_l) * Function toascii:: Force integers to ASCII range (toascii, toascii_l) * Function tolower:: Translate characters to lowercase (tolower, tolower_l) * Function toupper:: Translate characters to uppercase (toupper, toupper_l) * Function iswalnum:: Alphanumeric wide character predicate (iswalnum, iswalnum_l) * Function iswalpha:: Alphabetic wide character predicate (iswalpha, iswalpha_l) * Function iswblank:: Blank wide character predicate (iswblank, iswblank_l) * Function iswcntrl:: Control wide character predicate (iswcntrl, iswcntrl_l) * Function iswdigit:: Decimal digit wide character predicate (iswdigit, iswdigit_l) * Function iswgraph:: Graphic wide character predicate (iswgraph, iswgraph_l) * Function iswlower:: Lowercase wide character predicate (iswlower, iswlower_l) * Function iswprint:: Printable wide character predicate (iswprint, iswprint_l) * Function iswpunct:: Punctuation wide character predicate (iswpunct, iswpunct_l) * Function iswspace:: Whitespace wide character predicate (iswspace, iswspace_l) * Function iswupper:: Uppercase wide character predicate (iswupper, iswupper_l) * Function iswxdigit:: Hexadecimal digit wide character predicate (iswxdigit, iswxdigit_l) * Function iswctype:: Extensible wide-character test (iswctype, iswctype_l) * Function wctype:: Compute wide-character test type (wctype, wctype_l) * Function towlower:: Translate wide characters to lowercase (towlower, towlower_l) * Function towupper:: Translate wide characters to uppercase (towupper, towupper_l) * Function towctrans:: Extensible wide-character translation (towctrans, towctrans_l) * Function wctrans:: Compute wide-character translation type (wctrans, wctrans_l) @end menu @page @include ctype/isalnum.def @page @include ctype/isalpha.def @page @include ctype/isascii.def @page @include ctype/isblank.def @page @include ctype/iscntrl.def @page @include ctype/isdigit.def @page @include ctype/islower.def @page @include ctype/isprint.def @page @include ctype/ispunct.def @page @include ctype/isspace.def @page @include ctype/isupper.def @page @include ctype/isxdigit.def @page @include ctype/toascii.def @page @include ctype/tolower.def @page @include ctype/toupper.def @page @include ctype/iswalnum.def @page @include ctype/iswalpha.def @page @include ctype/iswcntrl.def @page @include ctype/iswblank.def @page @include ctype/iswdigit.def @page @include ctype/iswgraph.def @page @include ctype/iswlower.def @page @include ctype/iswprint.def @page @include ctype/iswpunct.def @page @include ctype/iswspace.def @page @include ctype/iswupper.def @page @include ctype/iswxdigit.def @page @include ctype/iswctype.def @page @include ctype/wctype.def @page @include ctype/towlower.def @page @include ctype/towupper.def @page @include ctype/towctrans.def @page @include ctype/wctrans.def picolibc-1.8.11/libc/ctype/ctype_.c000066400000000000000000000065721513574234600170760ustar00rootroot00000000000000/* * Copyright (c) 1989 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #define _DEFAULT_SOURCE /* Make sure we're using fast ctype */ #define _PICOLIBC_CTYPE_SMALL 0 #include "ctype_.h" #include "locale_private.h" #include "../stdlib/local.h" const char _ctype_b[128 + 256] = { _CTYPE_DATA_128_255, _CTYPE_DATA_0_127, _CTYPE_DATA_128_255 }; #ifdef __MB_EXTENDED_CHARSETS_NON_UNICODE #include "ctype_extended.h" #define __CTYPE(base) \ [locale_##base - locale_EXTENDED_BASE] = { _CTYPE_##base##_128_254, 0, _CTYPE_DATA_0_127, \ _CTYPE_##base##_128_254, _CTYPE_##base##_255 } const char __ctype[locale_END - locale_EXTENDED_BASE][_CTYPE_OFFSET + 1 + 256] = { #ifdef __MB_EXTENDED_CHARSETS_ISO __CTYPE(ISO_8859_1), __CTYPE(ISO_8859_2), __CTYPE(ISO_8859_3), __CTYPE(ISO_8859_4), __CTYPE(ISO_8859_5), __CTYPE(ISO_8859_6), __CTYPE(ISO_8859_7), __CTYPE(ISO_8859_8), __CTYPE(ISO_8859_9), __CTYPE(ISO_8859_10), __CTYPE(ISO_8859_11), __CTYPE(ISO_8859_13), __CTYPE(ISO_8859_14), __CTYPE(ISO_8859_15), __CTYPE(ISO_8859_16), #endif #ifdef __MB_EXTENDED_CHARSETS_WINDOWS __CTYPE(CP437), __CTYPE(CP720), __CTYPE(CP737), __CTYPE(CP775), __CTYPE(CP850), __CTYPE(CP852), __CTYPE(CP855), __CTYPE(CP857), __CTYPE(CP858), __CTYPE(CP862), __CTYPE(CP866), __CTYPE(CP874), __CTYPE(CP1125), __CTYPE(CP1250), __CTYPE(CP1251), __CTYPE(CP1252), __CTYPE(CP1253), __CTYPE(CP1254), __CTYPE(CP1255), __CTYPE(CP1256), __CTYPE(CP1257), __CTYPE(CP1258), __CTYPE(KOI8_R), __CTYPE(KOI8_U), __CTYPE(GEORGIAN_PS), __CTYPE(PT154), __CTYPE(KOI8_T), #endif #ifdef __MB_EXTENDED_CHARSETS_JIS __CTYPE(EUCJP), __CTYPE(SJIS), #endif }; #endif /* __MB_EXTENDED_CHARSETS_NON_UNICODE */ picolibc-1.8.11/libc/ctype/ctype_.h000066400000000000000000000046171513574234600171010ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen */ #include #include #include "locale_private.h" #ifdef __MB_EXTENDED_CHARSETS_NON_UNICODE extern const char __ctype[locale_END - locale_EXTENDED_BASE][_CTYPE_OFFSET + 1 + 256]; static inline const char * __get_ctype(enum locale_id id) { if (id < locale_EXTENDED_BASE) return _ctype_; return __ctype[id - locale_EXTENDED_BASE] + _CTYPE_OFFSET; } #endif #define _U __CTYPE_UPPER #define _L __CTYPE_LOWER #define _N __CTYPE_DIGIT #define _S __CTYPE_SPACE #define _P __CTYPE_PUNCT #define _C __CTYPE_CNTRL #define _X __CTYPE_HEX #define _B __CTYPE_BLANK #define _T __CTYPE_TAB /* clang-format off */ #define _CTYPE_DATA_0_127 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _S|_B, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _N, _N, _N, _N, _N, _N, _N, _N, \ _N, _N, _P, _P, _P, _P, _P, _P, \ _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _P, _P, _P, _P, _P, \ _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _P, _P, _P, _P, _C #define _CTYPE_DATA_0_127_WIDE \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C|_S|_T, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _S|_B, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _N, _N, _N, _N, _N, _N, _N, _N, \ _N, _N, _P, _P, _P, _P, _P, _P, \ _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _P, _P, _P, _P, _P, \ _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _P, _P, _P, _P, _C #define _CTYPE_DATA_128_255 \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0 picolibc-1.8.11/libc/ctype/ctype_class.c000066400000000000000000000032761513574234600201220ustar00rootroot00000000000000/* * Copyright (c) 1989 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include #include "local.h" const wctype_t _ctype_class[+1256] = { 0, #include "ctype_class.h" }; picolibc-1.8.11/libc/ctype/ctype_class.h000066400000000000000000000221061513574234600201200ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2026 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This file is auto-generated from mkctype_class.py */ /* clang-format off */ /* 0x00 */ CLASS_cntrl, /* 0x01 */ CLASS_cntrl, /* 0x02 */ CLASS_cntrl, /* 0x03 */ CLASS_cntrl, /* 0x04 */ CLASS_cntrl, /* 0x05 */ CLASS_cntrl, /* 0x06 */ CLASS_cntrl, /* 0x07 */ CLASS_cntrl, /* 0x08 */ CLASS_cntrl, /* 0x09 */ CLASS_blank|CLASS_cntrl|CLASS_space, /* 0x0a */ CLASS_cntrl|CLASS_space, /* 0x0b */ CLASS_cntrl|CLASS_space, /* 0x0c */ CLASS_cntrl|CLASS_space, /* 0x0d */ CLASS_cntrl|CLASS_space, /* 0x0e */ CLASS_cntrl, /* 0x0f */ CLASS_cntrl, /* 0x10 */ CLASS_cntrl, /* 0x11 */ CLASS_cntrl, /* 0x12 */ CLASS_cntrl, /* 0x13 */ CLASS_cntrl, /* 0x14 */ CLASS_cntrl, /* 0x15 */ CLASS_cntrl, /* 0x16 */ CLASS_cntrl, /* 0x17 */ CLASS_cntrl, /* 0x18 */ CLASS_cntrl, /* 0x19 */ CLASS_cntrl, /* 0x1a */ CLASS_cntrl, /* 0x1b */ CLASS_cntrl, /* 0x1c */ CLASS_cntrl, /* 0x1d */ CLASS_cntrl, /* 0x1e */ CLASS_cntrl, /* 0x1f */ CLASS_cntrl, /* 0x20 */ CLASS_blank|CLASS_print|CLASS_space, /* 0x21 */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x22 */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x23 */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x24 */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x25 */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x26 */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x27 */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x28 */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x29 */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x2a */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x2b */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x2c */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x2d */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x2e */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x2f */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x30 */ CLASS_alnum|CLASS_digit|CLASS_graph|CLASS_print|CLASS_xdigit, /* 0x31 */ CLASS_alnum|CLASS_digit|CLASS_graph|CLASS_print|CLASS_xdigit, /* 0x32 */ CLASS_alnum|CLASS_digit|CLASS_graph|CLASS_print|CLASS_xdigit, /* 0x33 */ CLASS_alnum|CLASS_digit|CLASS_graph|CLASS_print|CLASS_xdigit, /* 0x34 */ CLASS_alnum|CLASS_digit|CLASS_graph|CLASS_print|CLASS_xdigit, /* 0x35 */ CLASS_alnum|CLASS_digit|CLASS_graph|CLASS_print|CLASS_xdigit, /* 0x36 */ CLASS_alnum|CLASS_digit|CLASS_graph|CLASS_print|CLASS_xdigit, /* 0x37 */ CLASS_alnum|CLASS_digit|CLASS_graph|CLASS_print|CLASS_xdigit, /* 0x38 */ CLASS_alnum|CLASS_digit|CLASS_graph|CLASS_print|CLASS_xdigit, /* 0x39 */ CLASS_alnum|CLASS_digit|CLASS_graph|CLASS_print|CLASS_xdigit, /* 0x3a */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x3b */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x3c */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x3d */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x3e */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x3f */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x40 */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x41 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper|CLASS_xdigit, /* 0x42 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper|CLASS_xdigit, /* 0x43 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper|CLASS_xdigit, /* 0x44 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper|CLASS_xdigit, /* 0x45 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper|CLASS_xdigit, /* 0x46 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper|CLASS_xdigit, /* 0x47 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x48 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x49 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x4a */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x4b */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x4c */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x4d */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x4e */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x4f */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x50 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x51 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x52 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x53 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x54 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x55 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x56 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x57 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x58 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x59 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x5a */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper, /* 0x5b */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x5c */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x5d */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x5e */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x5f */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x60 */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x61 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower|CLASS_xdigit, /* 0x62 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower|CLASS_xdigit, /* 0x63 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower|CLASS_xdigit, /* 0x64 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower|CLASS_xdigit, /* 0x65 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower|CLASS_xdigit, /* 0x66 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower|CLASS_xdigit, /* 0x67 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x68 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x69 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x6a */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x6b */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x6c */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x6d */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x6e */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x6f */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x70 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x71 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x72 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x73 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x74 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x75 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x76 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x77 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x78 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x79 */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x7a */ CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower, /* 0x7b */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x7c */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x7d */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x7e */ CLASS_graph|CLASS_print|CLASS_punct, /* 0x7f */ CLASS_cntrl, picolibc-1.8.11/libc/ctype/ctype_extended.h000066400000000000000000001617311513574234600206230ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This file is auto-generated from mkctype-extended.py */ /* clang-format off */ #define _CTYPE_ISO_8859_1_128_254 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _L, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _L, _P, _P, \ _P, _P, _L, _P, _P, _P, _P, _P, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _P, \ _U, _U, _U, _U, _U, _U, _U, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _P, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_ISO_8859_1_255 _L #define _CTYPE_ISO_8859_2_128_254 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _P, _U, _P, _U, _P, _U, _U, _P, \ _P, _U, _U, _U, _U, _P, _U, _U, \ _P, _L, _P, _L, _P, _L, _L, _U|_L, \ _P, _L, _L, _L, _L, _P, _L, _L, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _P, \ _U, _U, _U, _U, _U, _U, _U, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _P, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_ISO_8859_2_255 _P #define _CTYPE_ISO_8859_3_128_254 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _P, _U, _P, _P, _P, 0, _U, _P, \ _P, _U, _U, _U, _U, _P, 0, _U, \ _P, _L, _P, _P, _P, _L, _L, _P, \ _P, _L, _L, _L, _L, _P, 0, _L, \ _U, _U, _U, 0, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ 0, _U, _U, _U, _U, _U, _U, _P, \ _U, _U, _U, _U, _U, _U, _U, _L, \ _L, _L, _L, 0, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ 0, _L, _L, _L, _L, _L, _L, _P, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_ISO_8859_3_255 _P #define _CTYPE_ISO_8859_4_128_254 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _P, _U, _L, _U, _P, _U, _U, _P, \ _P, _U, _U, _U, _U, _P, _U, _P, \ _P, _L, _P, _L, _P, _L, _L, _U|_L, \ _P, _L, _L, _L, _L, _U, _L, _L, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _P, \ _U, _U, _U, _U, _U, _U, _U, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _P, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_ISO_8859_4_255 _P #define _CTYPE_ISO_8859_5_128_254 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _P, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _P, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _P, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _P, _L #define _CTYPE_ISO_8859_5_255 _L #define _CTYPE_ISO_8859_6_128_254 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _P, 0, 0, 0, _P, 0, 0, 0, \ 0, 0, 0, 0, _P, _P, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, _P, 0, 0, 0, _P, \ 0, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, 0, 0, 0, 0, 0, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0 #define _CTYPE_ISO_8859_6_255 0 #define _CTYPE_ISO_8859_7_128_254 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _L, _P, _P, _P, 0, _P, \ _P, _P, _P, _P, _P, _P, _U, _P, \ _U, _U, _U, _P, _U, _P, _U, _U, \ _L, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, 0, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_ISO_8859_7_255 0 #define _CTYPE_ISO_8859_8_128_254 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _P, 0, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _L, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, _P, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, 0, 0, _P, _P #define _CTYPE_ISO_8859_8_255 0 #define _CTYPE_ISO_8859_9_128_254 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _L, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _L, _P, _P, \ _P, _P, _L, _P, _P, _P, _P, _P, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _P, \ _U, _U, _U, _U, _U, _U, _U, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _P, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_ISO_8859_9_255 _L #define _CTYPE_ISO_8859_10_128_254 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _P, _U, _U, _U, _U, _U, _U, _P, \ _U, _U, _U, _U, _U, _P, _U, _U, \ _P, _L, _L, _L, _L, _L, _L, _P, \ _L, _L, _L, _L, _L, _P, _L, _L, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_ISO_8859_10_255 _L #define _CTYPE_ISO_8859_11_128_254 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _P, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, 0, 0, 0, 0, _P, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _P, \ _P, _P, _P, _P, _P, _U|_L, _P, _P, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _P, _P, 0, 0, 0 #define _CTYPE_ISO_8859_11_255 0 #define _CTYPE_ISO_8859_13_128_254 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _U, _P, _U, _P, _P, _P, _P, _U, \ _P, _P, _P, _P, _P, _L, _P, _P, \ _L, _P, _L, _P, _P, _P, _P, _L, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _P, \ _U, _U, _U, _U, _U, _U, _U, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _P, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_ISO_8859_13_255 _P #define _CTYPE_ISO_8859_14_128_254 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _P, _U, _L, _P, _U, _L, _U, _P, \ _U, _P, _U, _L, _U, _P, _P, _U, \ _U, _L, _U, _L, _U, _L, _P, _U, \ _L, _L, _L, _U, _L, _U, _L, _L, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_ISO_8859_14_255 _L #define _CTYPE_ISO_8859_15_128_254 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _P, _P, _P, _P, _P, _P, _U, _P, \ _L, _P, _L, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _U, _L, _P, _P, \ _L, _P, _L, _P, _U, _L, _U, _P, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _P, \ _U, _U, _U, _U, _U, _U, _U, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _P, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_ISO_8859_15_255 _L #define _CTYPE_ISO_8859_16_128_254 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _P, _U, _L, _U, _P, _P, _U, _P, \ _L, _P, _U, _P, _U, _P, _L, _U, \ _P, _P, _U, _L, _U, _P, _P, _P, \ _L, _L, _L, _P, _U, _L, _U, _L, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_ISO_8859_16_255 _L #define _CTYPE_SJIS_128_254 \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, _P, _P, _P, _P, _P, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0 #define _CTYPE_SJIS_255 0 #define _CTYPE_EUCJP_128_254 \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, 0, 0, \ _C, _C, _C, _C, _C, _C, _C, _C, \ _C, _C, _C, _C, _C, _C, _C, _C, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0 #define _CTYPE_EUCJP_255 0 #define _CTYPE_GEORGIAN_PS_128_254 \ _C, _C, _P, _L, _P, _P, _P, _P, \ _U|_L, _P, _U, _P, _U, _C, _C, _C, \ _C, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _L, _P, _L, _C, _C, _U, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _L, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _L, _P, _P, \ _P, _P, _L, _P, _P, _P, _P, _P, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _P, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_GEORGIAN_PS_255 _L #define _CTYPE_PT154_128_254 \ _U, _U, _U, _L, _P, _P, _U, _U, \ _U, _L, _U, _U, _U, _U, _U, _U, \ _L, _P, _P, _P, _P, _P, _P, _P, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _P, _U, _L, _U, _U, _U, _U, _P, \ _U, _P, _U, _P, _P, _L, _P, _U, \ _P, _L, _U, _L, _L, _L, _P, _P, \ _L, _P, _L, _P, _L, _U, _L, _L, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_PT154_255 _L #define _CTYPE_KOI8_T_128_254 \ _L, _L, _P, _U, _P, _P, _P, _P, \ 0, _P, _L, _P, _U, _L, _U, 0, \ _U, _P, _P, _P, _P, _P, _P, _P, \ 0, _P, 0, _P, 0, 0, 0, 0, \ 0, _L, _U, _L, _P, _L, _P, _P, \ 0, 0, 0, _P, _P, _P, _P, 0, \ _P, _P, _P, _U, 0, _U, _P, _P, \ 0, _P, 0, _P, 0, 0, 0, _P, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U #define _CTYPE_KOI8_T_255 _U #define _CTYPE_CP437_128_254 \ _U, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _U, _U, \ _U, _L, _U, _L, _L, _L, _L, _L, \ _L, _U, _U, _P, _P, _P, _P, _L, \ _L, _L, _L, _L, _L, _U, _L, _L, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _L, _L, _U, _L, _U, _L, _L, _L, \ _U, _U, _U, _L, _P, _L, _L, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _L, _P, _P #define _CTYPE_CP437_255 _P #define _CTYPE_CP720_128_254 \ _C, _C, _L, _L, _C, _L, _C, _L, \ _L, _L, _L, _L, _L, _C, _C, _C, \ _C, _U|_L, _U|_L, _L, _P, _U|_L, _L, _L, \ _U|_L, _U|_L, _U|_L, _U|_L, _P, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _P, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _P, \ _P, _P, _P, _P, _L, _P, _P #define _CTYPE_CP720_255 _P #define _CTYPE_CP737_128_254 \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _U, _U, _U, _U, _U, _U, \ _U, _P, _P, _P, _U, _U, _P, _P, \ _P, _P, _P, _P, _L, _P, _P #define _CTYPE_CP737_255 _P #define _CTYPE_CP775_128_254 \ _U, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _U, _L, _L, _U, _U, _U, \ _U, _L, _U, _L, _L, _U, _P, _U, \ _L, _U, _U, _L, _P, _U, _P, _P, \ _U, _U, _L, _U, _L, _L, _P, _P, \ _P, _P, _P, _P, _P, _U, _P, _P, \ _P, _P, _P, _P, _P, _U, _U, _U, \ _U, _P, _P, _P, _P, _U, _U, _P, \ _P, _P, _P, _P, _P, _P, _U, _U, \ _P, _P, _P, _P, _P, _P, _P, _U, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _P, _P, _P, _P, _P, _P, _P, \ _U, _L, _U, _U, _L, _U, _L, _L, \ _U, _L, _U, _L, _L, _U, _U, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P #define _CTYPE_CP775_255 _P #define _CTYPE_CP850_128_254 \ _U, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _U, _U, \ _U, _L, _U, _L, _L, _L, _L, _L, \ _L, _U, _U, _L, _P, _U, _P, _L, \ _L, _L, _L, _L, _L, _U, _L, _L, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _U, _U, _U, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _L, _U, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _L, _U, _U, _U, _U, _L, _U, _U, \ _U, _P, _P, _P, _P, _P, _U, _P, \ _U, _L, _U, _U, _L, _U, _L, _L, \ _U, _U, _U, _U, _L, _U, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P #define _CTYPE_CP850_255 _P #define _CTYPE_CP852_128_254 \ _U, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _U, _L, _L, _U, _U, _U, \ _U, _U, _L, _L, _L, _U, _L, _U, \ _L, _U, _U, _U, _L, _U, _P, _L, \ _L, _L, _L, _L, _U, _L, _U, _L, \ _U, _L, _P, _L, _U, _L, _P, _P, \ _P, _P, _P, _P, _P, _U, _U, _U, \ _U, _P, _P, _P, _P, _U, _L, _P, \ _P, _P, _P, _P, _P, _P, _U, _L, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _L, _U, _U, _U, _L, _U, _U, _U, \ _L, _P, _P, _P, _P, _U, _U, _P, \ _U, _L, _U, _U, _L, _L, _U, _L, \ _U, _U, _L, _U, _L, _U, _L, _P, \ _P, _P, _P, _U|_L, _P, _P, _P, _P, \ _P, _P, _P, _L, _U, _L, _P #define _CTYPE_CP852_255 _P #define _CTYPE_CP855_128_254 \ _L, _U, _L, _U, _L, _U, _L, _U, \ _L, _U, _L, _U, _L, _U, _L, _U, \ _L, _U, _L, _U, _L, _U, _L, _U, \ _L, _U, _L, _U, _L, _U, _L, _U, \ _L, _U, _L, _U, _L, _U, _L, _U, \ _L, _U, _L, _U, _L, _U, _P, _P, \ _P, _P, _P, _P, _P, _L, _U, _L, \ _U, _P, _P, _P, _P, _L, _U, _P, \ _P, _P, _P, _P, _P, _P, _L, _U, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _L, _U, _L, _U, _L, _U, _L, _U, \ _L, _P, _P, _P, _P, _U, _L, _P, \ _U, _L, _U, _L, _U, _L, _U, _L, \ _U, _L, _U, _L, _U, _L, _U, _P, \ _P, _L, _U, _L, _U, _L, _U, _L, \ _U, _L, _U, _L, _U, _P, _P #define _CTYPE_CP855_255 _P #define _CTYPE_CP857_128_254 \ _U, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _U, _U, \ _U, _L, _U, _L, _L, _L, _L, _L, \ _U, _U, _U, _L, _P, _U, _U, _L, \ _L, _L, _L, _L, _L, _U, _U, _L, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _U, _U, _U, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _L, _U, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _L, _L, _U, _U, _U, 0, _U, _U, \ _U, _P, _P, _P, _P, _P, _U, _P, \ _U, _L, _U, _U, _L, _U, _L, 0, \ _P, _U, _U, _U, _L, _L, _P, _P, \ _P, _P, 0, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P #define _CTYPE_CP857_255 _P #define _CTYPE_CP858_128_254 \ _U, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _U, _U, \ _U, _L, _U, _L, _L, _L, _L, _L, \ _L, _U, _U, _L, _P, _U, _P, _L, \ _L, _L, _L, _L, _L, _U, _L, _L, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _U, _U, _U, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _L, _U, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _L, _U, _U, _U, _U, _P, _U, _U, \ _U, _P, _P, _P, _P, _P, _U, _P, \ _U, _L, _U, _U, _L, _U, _L, _L, \ _U, _U, _U, _U, _L, _U, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P #define _CTYPE_CP858_255 _P #define _CTYPE_CP862_128_254 \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _P, _P, _P, _P, _L, \ _L, _L, _L, _L, _L, _U, _L, _L, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _L, _L, _U, _L, _U, _L, _L, _L, \ _U, _U, _U, _L, _P, _L, _L, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _L, _P, _P #define _CTYPE_CP862_255 _P #define _CTYPE_CP866_128_254 \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _U, _L, _U, _L, _U, _L, _U, _L, \ _P, _P, _P, _P, _P, _P, _P #define _CTYPE_CP866_255 _P #define _CTYPE_CP874_128_254 \ _P, 0, 0, 0, 0, _P, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, \ 0, _P, _P, _P, _P, _P, _P, _P, \ 0, 0, 0, 0, 0, 0, 0, 0, \ _P, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, 0, 0, 0, 0, _P, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _P, \ _P, _P, _P, _P, _P, _U|_L, _P, _P, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _P, _P, 0, 0, 0 #define _CTYPE_CP874_255 0 #define _CTYPE_CP1125_128_254 \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _U, _L, _U, _L, _U, _L, _U, _L, \ _U, _L, _P, _P, _P, _P, _P #define _CTYPE_CP1125_255 _P #define _CTYPE_CP1250_128_254 \ _P, 0, _P, 0, _P, _P, _P, _P, \ 0, _P, _U, _P, _U, _U, _U, _U, \ 0, _P, _P, _P, _P, _P, _P, _P, \ 0, _P, _L, _P, _L, _L, _L, _L, \ _P, _U|_L, _P, _U, _P, _U, _P, _P, \ _P, _P, _U, _P, _P, _P, _P, _U, \ _P, _P, _P, _L, _P, _L, _P, _P, \ _P, _L, _L, _P, _U, _P, _L, _L, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _P, \ _U, _U, _U, _U, _U, _U, _U, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _P, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_CP1250_255 _P #define _CTYPE_CP1251_128_254 \ _U, _U, _P, _L, _P, _P, _P, _P, \ _P, _P, _U, _P, _U, _U, _U, _U, \ _L, _P, _P, _P, _P, _P, _P, _P, \ 0, _P, _L, _P, _L, _L, _L, _L, \ _P, _U, _L, _U, _P, _U, _P, _P, \ _U, _P, _U, _P, _P, _P, _P, _U, \ _P, _P, _U, _L, _L, _L, _P, _P, \ _L, _P, _L, _P, _L, _U, _L, _L, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_CP1251_255 _L #define _CTYPE_CP1252_128_254 \ _P, 0, _P, _L, _P, _P, _P, _P, \ _U|_L, _P, _U, _P, _U, 0, _U, 0, \ 0, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _L, _P, _L, 0, _L, _U, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _L, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _L, _P, _P, \ _P, _P, _L, _P, _P, _P, _P, _P, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _P, \ _U, _U, _U, _U, _U, _U, _U, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _P, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_CP1252_255 _L #define _CTYPE_CP1253_128_254 \ _P, 0, _P, _L, _P, _P, _P, _P, \ 0, _P, 0, _P, 0, 0, 0, 0, \ 0, _P, _P, _P, _P, _P, _P, _P, \ 0, _P, 0, _P, 0, 0, 0, 0, \ _P, _P, _U, _P, _P, _P, _P, _P, \ _P, _P, 0, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _L, _P, _P, \ _U, _U, _U, _P, _U, _P, _U, _U, \ _L, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, 0, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_CP1253_255 0 #define _CTYPE_CP1254_128_254 \ _P, 0, _P, _L, _P, _P, _P, _P, \ _U|_L, _P, _U, _P, _U, 0, 0, 0, \ 0, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _L, _P, _L, 0, 0, _U, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _L, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _L, _P, _P, \ _P, _P, _L, _P, _P, _P, _P, _P, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _P, \ _U, _U, _U, _U, _U, _U, _U, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _P, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_CP1254_255 _L #define _CTYPE_CP1255_128_254 \ _P, 0, _P, _L, _P, _P, _P, _P, \ _U|_L, _P, 0, _P, 0, 0, 0, 0, \ 0, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, 0, _P, 0, 0, 0, 0, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _L, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, 0, _U|_L, _U|_L, _U|_L, _P, _U|_L, \ _P, _U|_L, _U|_L, _P, _U|_L, _U|_L, _U|_L, _P, \ _P, 0, 0, 0, 0, 0, 0, 0, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, 0, 0, _P, _P #define _CTYPE_CP1255_255 0 #define _CTYPE_CP1256_128_254 \ _P, _U|_L, _P, _L, _P, _P, _P, _P, \ _U|_L, _P, _U|_L, _P, _U, _U|_L, _U|_L, _U|_L, \ _U|_L, _P, _P, _P, _P, _P, _P, _P, \ _U|_L, _P, _U|_L, _P, _L, _P, _P, _U|_L, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _U|_L, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _L, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _P, \ _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, _U|_L, \ _L, _U|_L, _L, _U|_L, _U|_L, _U|_L, _U|_L, _L, \ _L, _L, _L, _L, _U|_L, _U|_L, _L, _L, \ _U|_L, _U|_L, _U|_L, _U|_L, _L, _U|_L, _U|_L, _P, \ _U|_L, _L, _U|_L, _L, _L, _P, _P #define _CTYPE_CP1256_255 _U|_L #define _CTYPE_CP1257_128_254 \ _P, 0, _P, 0, _P, _P, _P, _P, \ 0, _P, 0, _P, 0, _P, _U|_L, _P, \ 0, _P, _P, _P, _P, _P, _P, _P, \ 0, _P, 0, _P, 0, _P, _P, 0, \ _P, 0, _P, _P, _P, 0, _P, _P, \ _U, _P, _U, _P, _P, _P, _P, _U, \ _P, _P, _P, _P, _P, _L, _P, _P, \ _L, _P, _L, _P, _P, _P, _P, _L, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _P, \ _U, _U, _U, _U, _U, _U, _U, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _P, \ _L, _L, _L, _L, _L, _L, _L #define _CTYPE_CP1257_255 _P #define _CTYPE_CP1258_128_254 \ _P, 0, _P, _L, _P, _P, _P, _P, \ _U|_L, _P, 0, _P, _U, 0, 0, 0, \ 0, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, 0, _P, _L, 0, 0, _U, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _L, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _L, _P, _P, \ _P, _P, _L, _P, _P, _P, _P, _P, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _P, _U, _U, _U, \ _U, _U, _P, _U, _U, _U, _U, _P, \ _U, _U, _U, _U, _U, _U, _P, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _P, _L, _L, _L, \ _L, _L, _P, _L, _L, _L, _L, _P, \ _L, _L, _L, _L, _L, _L, _P #define _CTYPE_CP1258_255 _L #define _CTYPE_KOI8_R_128_254 \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _L, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _U, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U #define _CTYPE_KOI8_R_255 _U #define _CTYPE_KOI8_U_128_254 \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _P, _P, _P, _P, _P, \ _P, _P, _P, _L, _L, _P, _L, _L, \ _P, _P, _P, _P, _P, _L, _P, _P, \ _P, _P, _P, _U, _U, _P, _U, _U, \ _P, _P, _P, _P, _P, _U, _P, _P, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _L, _L, _L, _L, _L, _L, _L, _L, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U, _U, \ _U, _U, _U, _U, _U, _U, _U #define _CTYPE_KOI8_U_255 _U picolibc-1.8.11/libc/ctype/ctype_table.c000066400000000000000000000074341513574234600201040ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _GNU_SOURCE #include #include #include #include "local.h" #ifdef __MB_CAPABLE static const struct { wchar_t code; wctype_t category; } ctype_table[] = { #include "ctype_table.h" }; #define N_CAT_TABLE (sizeof(ctype_table) / sizeof(ctype_table[0])) wctype_t __ctype_table_lookup(wint_t ic, locale_t locale, wctype_t mask) { size_t low = 0; size_t high = N_CAT_TABLE - 1; size_t mid; wchar_t c; if (ic == WEOF) return CLASS_none; c = (wchar_t)ic; /* Be compatible with glibc where the C locale has no classes outside of ASCII */ if (c >= 0x80 && __locale_is_C(locale)) return CLASS_none; while (low < high) { mid = (low + high) >> 1; if (c < ctype_table[mid].code) { high = mid - 1; } else if (mid >= N_CAT_TABLE || c >= ctype_table[mid + 1].code) { low = mid + 1; } else { high = mid; break; } } wctype_t ret = ctype_table[high].category; /* Map CLASS_case to either CLASS_lower or CLASS_upper */ if ((mask & (CLASS_lower | CLASS_upper)) && (ret & CLASS_case)) { const struct caseconv_entry *cce = __caseconv_lookup(ic, locale); if (cce) { switch (cce->mode) { case TO1: switch (cce->delta) { case EVENCAP: if (!(c & 1)) ret |= CLASS_upper; else ret |= CLASS_lower; break; case ODDCAP: if (c & 1) ret |= CLASS_upper; else ret |= CLASS_lower; break; default: break; } break; case TOLO: ret |= CLASS_upper; break; case TOUP: ret |= CLASS_lower; break; case TOBOTH: ret |= CLASS_upper | CLASS_lower; break; default: break; } } } return ret & mask; } #endif /* __MB_CAPABLE */ picolibc-1.8.11/libc/ctype/ctype_table.h000066400000000000000000003251641513574234600201140ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This file is auto-generated from mkctype.py */ /* clang-format off */ { 0x0000, CLASS_cntrl }, { 0x0009, CLASS_blank|CLASS_cntrl|CLASS_space }, { 0x000a, CLASS_cntrl|CLASS_space }, { 0x000e, CLASS_cntrl }, { 0x0020, CLASS_blank|CLASS_print|CLASS_space }, { 0x0021, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0030, CLASS_alnum|CLASS_digit|CLASS_graph|CLASS_print|CLASS_xdigit }, { 0x003a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0041, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case|CLASS_xdigit }, { 0x0047, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x005b, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0061, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case|CLASS_xdigit }, { 0x0067, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x007b, CLASS_graph|CLASS_print|CLASS_punct }, { 0x007f, CLASS_cntrl }, { 0x00a0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x00aa, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x00ab, CLASS_graph|CLASS_print|CLASS_punct }, { 0x00b5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x00b6, CLASS_graph|CLASS_print|CLASS_punct }, { 0x00ba, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x00bb, CLASS_graph|CLASS_print|CLASS_punct }, { 0x00c0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x00d7, CLASS_graph|CLASS_print|CLASS_punct }, { 0x00d8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x00df, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x00e0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x00f7, CLASS_graph|CLASS_print|CLASS_punct }, { 0x00f8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0138, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0139, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0149, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x014a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x018d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x018e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x01aa, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x01ac, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x01ba, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x01bb, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x01bc, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x01be, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x01bf, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x01c0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x01c4, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x01c5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case|CLASS_case }, { 0x01c6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x01c8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case|CLASS_case }, { 0x01c9, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x01cb, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case|CLASS_case }, { 0x01cc, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x01f0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x01f1, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x01f2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case|CLASS_case }, { 0x01f3, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0221, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0222, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0234, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x023a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0255, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0256, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0258, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0259, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x025a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x025b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x025d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0260, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0262, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0263, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0267, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0268, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x026d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x026f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0270, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0271, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0273, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0275, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0276, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x027d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x027e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0280, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0281, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0282, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0284, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0287, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x028d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0292, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0293, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0294, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0295, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x029d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x029f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x02b9, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x02c0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x02c2, CLASS_graph|CLASS_print|CLASS_punct }, { 0x02c6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x02d2, CLASS_graph|CLASS_print|CLASS_punct }, { 0x02e0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x02e5, CLASS_graph|CLASS_print|CLASS_punct }, { 0x02ec, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x02ed, CLASS_graph|CLASS_print|CLASS_punct }, { 0x02ee, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x02ef, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0345, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0346, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0363, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0370, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0374, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0375, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0376, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0378, CLASS_none }, { 0x037a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x037b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x037e, CLASS_graph|CLASS_print|CLASS_punct }, { 0x037f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0380, CLASS_none }, { 0x0384, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0386, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0387, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0388, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x038b, CLASS_none }, { 0x038c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x038d, CLASS_none }, { 0x038e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0390, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0391, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x03a2, CLASS_none }, { 0x03a3, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x03b0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x03b1, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x03d2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x03d5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x03f6, CLASS_graph|CLASS_print|CLASS_punct }, { 0x03f7, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x03fc, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x03fd, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0482, CLASS_graph|CLASS_print|CLASS_punct }, { 0x048a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0530, CLASS_none }, { 0x0531, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0557, CLASS_none }, { 0x0559, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x055a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0560, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0561, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x0587, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x0589, CLASS_graph|CLASS_print|CLASS_punct }, { 0x058b, CLASS_none }, { 0x058d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0590, CLASS_none }, { 0x0591, CLASS_graph|CLASS_print|CLASS_punct }, { 0x05b0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x05be, CLASS_graph|CLASS_print|CLASS_punct }, { 0x05bf, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x05c0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x05c1, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x05c3, CLASS_graph|CLASS_print|CLASS_punct }, { 0x05c4, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x05c6, CLASS_graph|CLASS_print|CLASS_punct }, { 0x05c7, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x05c8, CLASS_none }, { 0x05d0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x05eb, CLASS_none }, { 0x05ef, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x05f3, CLASS_graph|CLASS_print|CLASS_punct }, { 0x05f5, CLASS_none }, { 0x0600, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0610, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x061b, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0620, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0658, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0659, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x066a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x066e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x06d4, CLASS_graph|CLASS_print|CLASS_punct }, { 0x06d5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x06dd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x06e1, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x06e9, CLASS_graph|CLASS_print|CLASS_punct }, { 0x06ed, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x06fd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x06ff, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0700, CLASS_graph|CLASS_print|CLASS_punct }, { 0x070e, CLASS_none }, { 0x070f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0710, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0740, CLASS_graph|CLASS_print|CLASS_punct }, { 0x074b, CLASS_none }, { 0x074d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x07b2, CLASS_none }, { 0x07c0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x07eb, CLASS_graph|CLASS_print|CLASS_punct }, { 0x07f4, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x07f6, CLASS_graph|CLASS_print|CLASS_punct }, { 0x07fa, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x07fb, CLASS_none }, { 0x07fd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0800, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0818, CLASS_graph|CLASS_print|CLASS_punct }, { 0x081a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x082d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x082e, CLASS_none }, { 0x0830, CLASS_graph|CLASS_print|CLASS_punct }, { 0x083f, CLASS_none }, { 0x0840, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0859, CLASS_graph|CLASS_print|CLASS_punct }, { 0x085c, CLASS_none }, { 0x085e, CLASS_graph|CLASS_print|CLASS_punct }, { 0x085f, CLASS_none }, { 0x0860, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x086b, CLASS_none }, { 0x0870, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0888, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0889, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x088f, CLASS_none }, { 0x0890, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0892, CLASS_none }, { 0x0897, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0898, CLASS_graph|CLASS_print|CLASS_punct }, { 0x08a0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x08ca, CLASS_graph|CLASS_print|CLASS_punct }, { 0x08d4, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x08e0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x08e3, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x08ea, CLASS_graph|CLASS_print|CLASS_punct }, { 0x08f0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x093c, CLASS_graph|CLASS_print|CLASS_punct }, { 0x093d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x094d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x094e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0951, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0955, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0964, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0966, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0970, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0971, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0984, CLASS_none }, { 0x0985, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x098d, CLASS_none }, { 0x098f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0991, CLASS_none }, { 0x0993, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x09a9, CLASS_none }, { 0x09aa, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x09b1, CLASS_none }, { 0x09b2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x09b3, CLASS_none }, { 0x09b6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x09ba, CLASS_none }, { 0x09bc, CLASS_graph|CLASS_print|CLASS_punct }, { 0x09bd, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x09c5, CLASS_none }, { 0x09c7, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x09c9, CLASS_none }, { 0x09cb, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x09cd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x09ce, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x09cf, CLASS_none }, { 0x09d7, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x09d8, CLASS_none }, { 0x09dc, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x09de, CLASS_none }, { 0x09df, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x09e4, CLASS_none }, { 0x09e6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x09f2, CLASS_graph|CLASS_print|CLASS_punct }, { 0x09fc, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x09fd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x09ff, CLASS_none }, { 0x0a01, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a04, CLASS_none }, { 0x0a05, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a0b, CLASS_none }, { 0x0a0f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a11, CLASS_none }, { 0x0a13, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a29, CLASS_none }, { 0x0a2a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a31, CLASS_none }, { 0x0a32, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a34, CLASS_none }, { 0x0a35, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a37, CLASS_none }, { 0x0a38, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a3a, CLASS_none }, { 0x0a3c, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0a3d, CLASS_none }, { 0x0a3e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a43, CLASS_none }, { 0x0a47, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a49, CLASS_none }, { 0x0a4b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a4d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0a4e, CLASS_none }, { 0x0a51, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a52, CLASS_none }, { 0x0a59, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a5d, CLASS_none }, { 0x0a5e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a5f, CLASS_none }, { 0x0a66, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a76, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0a77, CLASS_none }, { 0x0a81, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a84, CLASS_none }, { 0x0a85, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a8e, CLASS_none }, { 0x0a8f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0a92, CLASS_none }, { 0x0a93, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0aa9, CLASS_none }, { 0x0aaa, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ab1, CLASS_none }, { 0x0ab2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ab4, CLASS_none }, { 0x0ab5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0aba, CLASS_none }, { 0x0abc, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0abd, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ac6, CLASS_none }, { 0x0ac7, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0aca, CLASS_none }, { 0x0acb, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0acd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0ace, CLASS_none }, { 0x0ad0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ad1, CLASS_none }, { 0x0ae0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ae4, CLASS_none }, { 0x0ae6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0af0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0af2, CLASS_none }, { 0x0af9, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0afd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0b00, CLASS_none }, { 0x0b01, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b04, CLASS_none }, { 0x0b05, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b0d, CLASS_none }, { 0x0b0f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b11, CLASS_none }, { 0x0b13, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b29, CLASS_none }, { 0x0b2a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b31, CLASS_none }, { 0x0b32, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b34, CLASS_none }, { 0x0b35, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b3a, CLASS_none }, { 0x0b3c, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0b3d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b45, CLASS_none }, { 0x0b47, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b49, CLASS_none }, { 0x0b4b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b4d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0b4e, CLASS_none }, { 0x0b55, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0b56, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b58, CLASS_none }, { 0x0b5c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b5e, CLASS_none }, { 0x0b5f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b64, CLASS_none }, { 0x0b66, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b70, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0b71, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b72, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0b78, CLASS_none }, { 0x0b82, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b84, CLASS_none }, { 0x0b85, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b8b, CLASS_none }, { 0x0b8e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b91, CLASS_none }, { 0x0b92, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b96, CLASS_none }, { 0x0b99, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b9b, CLASS_none }, { 0x0b9c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0b9d, CLASS_none }, { 0x0b9e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ba0, CLASS_none }, { 0x0ba3, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ba5, CLASS_none }, { 0x0ba8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0bab, CLASS_none }, { 0x0bae, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0bba, CLASS_none }, { 0x0bbe, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0bc3, CLASS_none }, { 0x0bc6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0bc9, CLASS_none }, { 0x0bca, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0bcd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0bce, CLASS_none }, { 0x0bd0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0bd1, CLASS_none }, { 0x0bd7, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0bd8, CLASS_none }, { 0x0be6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0bf0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0bfb, CLASS_none }, { 0x0c00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0c0d, CLASS_none }, { 0x0c0e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0c11, CLASS_none }, { 0x0c12, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0c29, CLASS_none }, { 0x0c2a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0c3a, CLASS_none }, { 0x0c3c, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0c3d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0c45, CLASS_none }, { 0x0c46, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0c49, CLASS_none }, { 0x0c4a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0c4d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0c4e, CLASS_none }, { 0x0c55, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0c57, CLASS_none }, { 0x0c58, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0c5b, CLASS_none }, { 0x0c5d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0c5e, CLASS_none }, { 0x0c60, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0c64, CLASS_none }, { 0x0c66, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0c70, CLASS_none }, { 0x0c77, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0c80, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0c84, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0c85, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0c8d, CLASS_none }, { 0x0c8e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0c91, CLASS_none }, { 0x0c92, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ca9, CLASS_none }, { 0x0caa, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0cb4, CLASS_none }, { 0x0cb5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0cba, CLASS_none }, { 0x0cbc, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0cbd, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0cc5, CLASS_none }, { 0x0cc6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0cc9, CLASS_none }, { 0x0cca, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ccd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0cce, CLASS_none }, { 0x0cd5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0cd7, CLASS_none }, { 0x0cdd, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0cdf, CLASS_none }, { 0x0ce0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ce4, CLASS_none }, { 0x0ce6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0cf0, CLASS_none }, { 0x0cf1, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0cf4, CLASS_none }, { 0x0d00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0d0d, CLASS_none }, { 0x0d0e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0d11, CLASS_none }, { 0x0d12, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0d3b, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0d3d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0d45, CLASS_none }, { 0x0d46, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0d49, CLASS_none }, { 0x0d4a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0d4d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0d4e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0d4f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0d50, CLASS_none }, { 0x0d54, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0d58, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0d5f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0d64, CLASS_none }, { 0x0d66, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0d70, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0d7a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0d80, CLASS_none }, { 0x0d81, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0d84, CLASS_none }, { 0x0d85, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0d97, CLASS_none }, { 0x0d9a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0db2, CLASS_none }, { 0x0db3, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0dbc, CLASS_none }, { 0x0dbd, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0dbe, CLASS_none }, { 0x0dc0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0dc7, CLASS_none }, { 0x0dca, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0dcb, CLASS_none }, { 0x0dcf, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0dd5, CLASS_none }, { 0x0dd6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0dd7, CLASS_none }, { 0x0dd8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0de0, CLASS_none }, { 0x0de6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0df0, CLASS_none }, { 0x0df2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0df4, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0df5, CLASS_none }, { 0x0e01, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0e3b, CLASS_none }, { 0x0e3f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0e40, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0e47, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0e4d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0e4e, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0e50, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0e5a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0e5c, CLASS_none }, { 0x0e81, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0e83, CLASS_none }, { 0x0e84, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0e85, CLASS_none }, { 0x0e86, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0e8b, CLASS_none }, { 0x0e8c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ea4, CLASS_none }, { 0x0ea5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ea6, CLASS_none }, { 0x0ea7, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0eba, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0ebb, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ebe, CLASS_none }, { 0x0ec0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ec5, CLASS_none }, { 0x0ec6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ec7, CLASS_none }, { 0x0ec8, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0ecd, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ece, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0ecf, CLASS_none }, { 0x0ed0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0eda, CLASS_none }, { 0x0edc, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0ee0, CLASS_none }, { 0x0f00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0f01, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0f20, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0f2a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0f40, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0f48, CLASS_none }, { 0x0f49, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0f6d, CLASS_none }, { 0x0f71, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0f84, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0f88, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0f98, CLASS_none }, { 0x0f99, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x0fbd, CLASS_none }, { 0x0fbe, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0fcd, CLASS_none }, { 0x0fce, CLASS_graph|CLASS_print|CLASS_punct }, { 0x0fdb, CLASS_none }, { 0x1000, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1037, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1038, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1039, CLASS_graph|CLASS_print|CLASS_punct }, { 0x103b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x104a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1050, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x109e, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10a0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x10c6, CLASS_none }, { 0x10c7, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x10c8, CLASS_none }, { 0x10cd, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x10ce, CLASS_none }, { 0x10d0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x10fb, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10fc, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x10fd, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1100, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1249, CLASS_none }, { 0x124a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x124e, CLASS_none }, { 0x1250, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1257, CLASS_none }, { 0x1258, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1259, CLASS_none }, { 0x125a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x125e, CLASS_none }, { 0x1260, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1289, CLASS_none }, { 0x128a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x128e, CLASS_none }, { 0x1290, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x12b1, CLASS_none }, { 0x12b2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x12b6, CLASS_none }, { 0x12b8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x12bf, CLASS_none }, { 0x12c0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x12c1, CLASS_none }, { 0x12c2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x12c6, CLASS_none }, { 0x12c8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x12d7, CLASS_none }, { 0x12d8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1311, CLASS_none }, { 0x1312, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1316, CLASS_none }, { 0x1318, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x135b, CLASS_none }, { 0x135d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x137d, CLASS_none }, { 0x1380, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1390, CLASS_graph|CLASS_print|CLASS_punct }, { 0x139a, CLASS_none }, { 0x13a0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x13f6, CLASS_none }, { 0x13f8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x13fe, CLASS_none }, { 0x1400, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1401, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x166d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x166f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1680, CLASS_blank|CLASS_print|CLASS_space }, { 0x1681, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x169b, CLASS_graph|CLASS_print|CLASS_punct }, { 0x169d, CLASS_none }, { 0x16a0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16eb, CLASS_graph|CLASS_print|CLASS_punct }, { 0x16ee, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16f9, CLASS_none }, { 0x1700, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1714, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1716, CLASS_none }, { 0x171f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1734, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1737, CLASS_none }, { 0x1740, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1754, CLASS_none }, { 0x1760, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x176d, CLASS_none }, { 0x176e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1771, CLASS_none }, { 0x1772, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1774, CLASS_none }, { 0x1780, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x17b4, CLASS_graph|CLASS_print|CLASS_punct }, { 0x17b6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x17c9, CLASS_graph|CLASS_print|CLASS_punct }, { 0x17d7, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x17d8, CLASS_graph|CLASS_print|CLASS_punct }, { 0x17dc, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x17dd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x17de, CLASS_none }, { 0x17e0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x17ea, CLASS_none }, { 0x17f0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x17fa, CLASS_none }, { 0x1800, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1810, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x181a, CLASS_none }, { 0x1820, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1879, CLASS_none }, { 0x1880, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x18ab, CLASS_none }, { 0x18b0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x18f6, CLASS_none }, { 0x1900, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x191f, CLASS_none }, { 0x1920, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x192c, CLASS_none }, { 0x1930, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1939, CLASS_graph|CLASS_print|CLASS_punct }, { 0x193c, CLASS_none }, { 0x1940, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1941, CLASS_none }, { 0x1944, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1946, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x196e, CLASS_none }, { 0x1970, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1975, CLASS_none }, { 0x1980, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x19ac, CLASS_none }, { 0x19b0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x19ca, CLASS_none }, { 0x19d0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x19da, CLASS_graph|CLASS_print|CLASS_punct }, { 0x19db, CLASS_none }, { 0x19de, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1a00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1a1c, CLASS_none }, { 0x1a1e, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1a20, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1a5f, CLASS_none }, { 0x1a60, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1a61, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1a75, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1a7d, CLASS_none }, { 0x1a7f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1a80, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1a8a, CLASS_none }, { 0x1a90, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1a9a, CLASS_none }, { 0x1aa0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1aa7, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1aa8, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1aae, CLASS_none }, { 0x1ab0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1abf, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ac1, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1acc, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1acf, CLASS_none }, { 0x1b00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1b34, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1b35, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1b44, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1b45, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1b4d, CLASS_none }, { 0x1b4e, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1b50, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1b5a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1b80, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1baa, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1bac, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1be6, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1be7, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1bf2, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1bf4, CLASS_none }, { 0x1bfc, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1c00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1c37, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1c38, CLASS_none }, { 0x1c3b, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1c40, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1c4a, CLASS_none }, { 0x1c4d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1c7e, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1c80, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1c8b, CLASS_none }, { 0x1c90, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1cbb, CLASS_none }, { 0x1cbd, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1cc0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1cc8, CLASS_none }, { 0x1cd0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1ce9, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ced, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1cee, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1cf4, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1cf5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1cf7, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1cfa, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1cfb, CLASS_none }, { 0x1d00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d79, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1d7a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d7d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1d7e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d8e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1d8f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1dc0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1dd3, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1df5, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1e00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1e96, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1e9b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1e9c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1e9e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1e9f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1ea0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1f16, CLASS_none }, { 0x1f18, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1f1e, CLASS_none }, { 0x1f20, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1f46, CLASS_none }, { 0x1f48, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1f4e, CLASS_none }, { 0x1f50, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1f51, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1f52, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1f53, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1f54, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1f55, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1f56, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1f57, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1f58, CLASS_none }, { 0x1f59, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1f5a, CLASS_none }, { 0x1f5b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1f5c, CLASS_none }, { 0x1f5d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1f5e, CLASS_none }, { 0x1f5f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1f7e, CLASS_none }, { 0x1f80, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1fb2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1fb3, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1fb4, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1fb5, CLASS_none }, { 0x1fb6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1fb8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1fbd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1fbe, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1fbf, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1fc2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1fc3, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1fc4, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1fc5, CLASS_none }, { 0x1fc6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1fc8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1fcd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1fd0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1fd2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1fd4, CLASS_none }, { 0x1fd6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1fd8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1fdc, CLASS_none }, { 0x1fdd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1fe0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1fe2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1fe5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1fe6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1fe8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1fed, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1ff0, CLASS_none }, { 0x1ff2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1ff3, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1ff4, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1ff5, CLASS_none }, { 0x1ff6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1ff8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1ffd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1fff, CLASS_none }, { 0x2000, CLASS_blank|CLASS_print|CLASS_space }, { 0x2007, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2008, CLASS_blank|CLASS_print|CLASS_space }, { 0x200b, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2028, CLASS_cntrl|CLASS_space }, { 0x202a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x205f, CLASS_blank|CLASS_print|CLASS_space }, { 0x2060, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2065, CLASS_none }, { 0x2066, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2071, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x2072, CLASS_none }, { 0x2074, CLASS_graph|CLASS_print|CLASS_punct }, { 0x207f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x2080, CLASS_graph|CLASS_print|CLASS_punct }, { 0x208f, CLASS_none }, { 0x2090, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x209d, CLASS_none }, { 0x20a0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x20c1, CLASS_none }, { 0x20d0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x20f1, CLASS_none }, { 0x2100, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2102, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x2103, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2107, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x2108, CLASS_graph|CLASS_print|CLASS_punct }, { 0x210a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x210b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x210e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x2110, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x2113, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x2114, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2115, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x2116, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2119, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x211e, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2124, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x2125, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2126, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x2127, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2128, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x2129, CLASS_graph|CLASS_print|CLASS_punct }, { 0x212a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x212c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x212e, CLASS_graph|CLASS_print|CLASS_punct }, { 0x212f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x2130, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x2132, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x2133, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x2134, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x2135, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2139, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x213a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x213c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x213e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x2140, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2145, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x2146, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x214a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x214e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x214f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2160, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x2180, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2183, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x2185, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2189, CLASS_graph|CLASS_print|CLASS_punct }, { 0x218c, CLASS_none }, { 0x2190, CLASS_graph|CLASS_print|CLASS_punct }, { 0x242a, CLASS_none }, { 0x2440, CLASS_graph|CLASS_print|CLASS_punct }, { 0x244b, CLASS_none }, { 0x2460, CLASS_graph|CLASS_print|CLASS_punct }, { 0x24b6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x24ea, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2b74, CLASS_none }, { 0x2b76, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2b96, CLASS_none }, { 0x2b97, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2c00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x2c71, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x2c72, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x2c74, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x2c75, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x2c77, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x2c7e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x2ce4, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x2ce5, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2ceb, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x2cef, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2cf2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x2cf4, CLASS_none }, { 0x2cf9, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2d00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x2d26, CLASS_none }, { 0x2d27, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x2d28, CLASS_none }, { 0x2d2d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x2d2e, CLASS_none }, { 0x2d30, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2d68, CLASS_none }, { 0x2d6f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2d70, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2d71, CLASS_none }, { 0x2d7f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2d80, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2d97, CLASS_none }, { 0x2da0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2da7, CLASS_none }, { 0x2da8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2daf, CLASS_none }, { 0x2db0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2db7, CLASS_none }, { 0x2db8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2dbf, CLASS_none }, { 0x2dc0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2dc7, CLASS_none }, { 0x2dc8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2dcf, CLASS_none }, { 0x2dd0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2dd7, CLASS_none }, { 0x2dd8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2ddf, CLASS_none }, { 0x2de0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2e00, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2e2f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2e30, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2e5e, CLASS_none }, { 0x2e80, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2e9a, CLASS_none }, { 0x2e9b, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2ef4, CLASS_none }, { 0x2f00, CLASS_graph|CLASS_print|CLASS_punct }, { 0x2fd6, CLASS_none }, { 0x2ff0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x3000, CLASS_blank|CLASS_print|CLASS_space }, { 0x3001, CLASS_graph|CLASS_print|CLASS_punct }, { 0x3005, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x3008, CLASS_graph|CLASS_print|CLASS_punct }, { 0x3021, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x302a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x3031, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x3036, CLASS_graph|CLASS_print|CLASS_punct }, { 0x3038, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x303d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x3040, CLASS_none }, { 0x3041, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x3097, CLASS_none }, { 0x3099, CLASS_graph|CLASS_print|CLASS_punct }, { 0x309d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x30a0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x30a1, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x30fb, CLASS_graph|CLASS_print|CLASS_punct }, { 0x30fc, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x3100, CLASS_none }, { 0x3105, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x3130, CLASS_none }, { 0x3131, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x318f, CLASS_none }, { 0x3190, CLASS_graph|CLASS_print|CLASS_punct }, { 0x31a0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x31c0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x31e6, CLASS_none }, { 0x31ef, CLASS_graph|CLASS_print|CLASS_punct }, { 0x31f0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x3200, CLASS_graph|CLASS_print|CLASS_punct }, { 0x321f, CLASS_none }, { 0x3220, CLASS_graph|CLASS_print|CLASS_punct }, { 0x3400, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x4dc0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x4e00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa48d, CLASS_none }, { 0xa490, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa4c7, CLASS_none }, { 0xa4d0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa4fe, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa500, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa60d, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa610, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa62c, CLASS_none }, { 0xa640, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0xa66e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa66f, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa674, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa67c, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa67f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa680, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0xa69c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0xa69e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa6f0, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa6f8, CLASS_none }, { 0xa700, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa717, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa720, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa722, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0xa730, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0xa732, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0xa770, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0xa779, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0xa788, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa789, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa78b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0xa78e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0xa78f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa790, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0xa795, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0xa796, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0xa7af, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0xa7b0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0xa7ce, CLASS_none }, { 0xa7d0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0xa7d2, CLASS_none }, { 0xa7d3, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0xa7d4, CLASS_none }, { 0xa7d5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0xa7d6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0xa7dd, CLASS_none }, { 0xa7f2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0xa7f5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0xa7f7, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa7f8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0xa7fb, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa806, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa807, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa828, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa82d, CLASS_none }, { 0xa830, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa83a, CLASS_none }, { 0xa840, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa874, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa878, CLASS_none }, { 0xa880, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa8c4, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa8c5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa8c6, CLASS_none }, { 0xa8ce, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa8d0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa8da, CLASS_none }, { 0xa8e0, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa8f2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa8f8, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa8fb, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa8fc, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa8fd, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa92b, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa930, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa953, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa954, CLASS_none }, { 0xa95f, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa960, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa97d, CLASS_none }, { 0xa980, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa9b3, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa9b4, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa9c0, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa9ce, CLASS_none }, { 0xa9cf, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa9da, CLASS_none }, { 0xa9de, CLASS_graph|CLASS_print|CLASS_punct }, { 0xa9e0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xa9ff, CLASS_none }, { 0xaa00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xaa37, CLASS_none }, { 0xaa40, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xaa4e, CLASS_none }, { 0xaa50, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xaa5a, CLASS_none }, { 0xaa5c, CLASS_graph|CLASS_print|CLASS_punct }, { 0xaa60, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xaa77, CLASS_graph|CLASS_print|CLASS_punct }, { 0xaa7a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xaabf, CLASS_graph|CLASS_print|CLASS_punct }, { 0xaac0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xaac1, CLASS_graph|CLASS_print|CLASS_punct }, { 0xaac2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xaac3, CLASS_none }, { 0xaadb, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xaade, CLASS_graph|CLASS_print|CLASS_punct }, { 0xaae0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xaaf0, CLASS_graph|CLASS_print|CLASS_punct }, { 0xaaf2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xaaf6, CLASS_graph|CLASS_print|CLASS_punct }, { 0xaaf7, CLASS_none }, { 0xab01, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xab07, CLASS_none }, { 0xab09, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xab0f, CLASS_none }, { 0xab11, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xab17, CLASS_none }, { 0xab20, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xab27, CLASS_none }, { 0xab28, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xab2f, CLASS_none }, { 0xab30, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0xab53, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0xab54, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0xab5b, CLASS_graph|CLASS_print|CLASS_punct }, { 0xab5c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0xab6a, CLASS_graph|CLASS_print|CLASS_punct }, { 0xab6c, CLASS_none }, { 0xab70, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0xabc0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xabeb, CLASS_graph|CLASS_print|CLASS_punct }, { 0xabee, CLASS_none }, { 0xabf0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xabfa, CLASS_none }, { 0xac00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xd7a4, CLASS_none }, { 0xd7b0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xd7c7, CLASS_none }, { 0xd7cb, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xd7fc, CLASS_none }, { 0xe000, CLASS_graph|CLASS_print|CLASS_punct }, { 0xf900, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xfa6e, CLASS_none }, { 0xfa70, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xfada, CLASS_none }, { 0xfb00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0xfb07, CLASS_none }, { 0xfb13, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0xfb18, CLASS_none }, { 0xfb1d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xfb29, CLASS_graph|CLASS_print|CLASS_punct }, { 0xfb2a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xfb37, CLASS_none }, { 0xfb38, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xfb3d, CLASS_none }, { 0xfb3e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xfb3f, CLASS_none }, { 0xfb40, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xfb42, CLASS_none }, { 0xfb43, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xfb45, CLASS_none }, { 0xfb46, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xfbb2, CLASS_graph|CLASS_print|CLASS_punct }, { 0xfbc3, CLASS_none }, { 0xfbd3, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xfd3e, CLASS_graph|CLASS_print|CLASS_punct }, { 0xfd50, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xfd90, CLASS_none }, { 0xfd92, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xfdc8, CLASS_none }, { 0xfdcf, CLASS_graph|CLASS_print|CLASS_punct }, { 0xfdd0, CLASS_none }, { 0xfdf0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xfdfc, CLASS_graph|CLASS_print|CLASS_punct }, { 0xfe1a, CLASS_none }, { 0xfe20, CLASS_graph|CLASS_print|CLASS_punct }, { 0xfe53, CLASS_none }, { 0xfe54, CLASS_graph|CLASS_print|CLASS_punct }, { 0xfe67, CLASS_none }, { 0xfe68, CLASS_graph|CLASS_print|CLASS_punct }, { 0xfe6c, CLASS_none }, { 0xfe70, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xfe75, CLASS_none }, { 0xfe76, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xfefd, CLASS_none }, { 0xfeff, CLASS_graph|CLASS_print|CLASS_punct }, { 0xff00, CLASS_none }, { 0xff01, CLASS_graph|CLASS_print|CLASS_punct }, { 0xff10, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xff1a, CLASS_graph|CLASS_print|CLASS_punct }, { 0xff21, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0xff3b, CLASS_graph|CLASS_print|CLASS_punct }, { 0xff41, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0xff5b, CLASS_graph|CLASS_print|CLASS_punct }, { 0xff66, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xffbf, CLASS_none }, { 0xffc2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xffc8, CLASS_none }, { 0xffca, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xffd0, CLASS_none }, { 0xffd2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xffd8, CLASS_none }, { 0xffda, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0xffdd, CLASS_none }, { 0xffe0, CLASS_graph|CLASS_print|CLASS_punct }, { 0xffe7, CLASS_none }, { 0xffe8, CLASS_graph|CLASS_print|CLASS_punct }, { 0xffef, CLASS_none }, { 0xfff9, CLASS_graph|CLASS_print|CLASS_punct }, #if __SIZEOF_WCHAR_T__ == 2 { 0xfffe, CLASS_none }, #else { 0xfffe, CLASS_none }, { 0x10000, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1000c, CLASS_none }, { 0x1000d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10027, CLASS_none }, { 0x10028, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1003b, CLASS_none }, { 0x1003c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1003e, CLASS_none }, { 0x1003f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1004e, CLASS_none }, { 0x10050, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1005e, CLASS_none }, { 0x10080, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x100fb, CLASS_none }, { 0x10100, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10103, CLASS_none }, { 0x10107, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10134, CLASS_none }, { 0x10137, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10140, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10175, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1018f, CLASS_none }, { 0x10190, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1019d, CLASS_none }, { 0x101a0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x101a1, CLASS_none }, { 0x101d0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x101fe, CLASS_none }, { 0x10280, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1029d, CLASS_none }, { 0x102a0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x102d1, CLASS_none }, { 0x102e0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x102fc, CLASS_none }, { 0x10300, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10320, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10324, CLASS_none }, { 0x1032d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1034b, CLASS_none }, { 0x10350, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1037b, CLASS_none }, { 0x10380, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1039e, CLASS_none }, { 0x1039f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x103a0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x103c4, CLASS_none }, { 0x103c8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x103d0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x103d1, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x103d6, CLASS_none }, { 0x10400, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x10450, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1049e, CLASS_none }, { 0x104a0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x104aa, CLASS_none }, { 0x104b0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x104d4, CLASS_none }, { 0x104d8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x104fc, CLASS_none }, { 0x10500, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10528, CLASS_none }, { 0x10530, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10564, CLASS_none }, { 0x1056f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10570, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1057b, CLASS_none }, { 0x1057c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1058b, CLASS_none }, { 0x1058c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x10593, CLASS_none }, { 0x10594, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x10596, CLASS_none }, { 0x10597, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x105a2, CLASS_none }, { 0x105a3, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x105b2, CLASS_none }, { 0x105b3, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x105ba, CLASS_none }, { 0x105bb, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x105bd, CLASS_none }, { 0x105c0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x105f4, CLASS_none }, { 0x10600, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10737, CLASS_none }, { 0x10740, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10756, CLASS_none }, { 0x10760, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10768, CLASS_none }, { 0x10780, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x10781, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10783, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x10786, CLASS_none }, { 0x10787, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x107b1, CLASS_none }, { 0x107b2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x107bb, CLASS_none }, { 0x10800, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10806, CLASS_none }, { 0x10808, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10809, CLASS_none }, { 0x1080a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10836, CLASS_none }, { 0x10837, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10839, CLASS_none }, { 0x1083c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1083d, CLASS_none }, { 0x1083f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10856, CLASS_none }, { 0x10857, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10860, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10877, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10880, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1089f, CLASS_none }, { 0x108a7, CLASS_graph|CLASS_print|CLASS_punct }, { 0x108b0, CLASS_none }, { 0x108e0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x108f3, CLASS_none }, { 0x108f4, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x108f6, CLASS_none }, { 0x108fb, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10900, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10916, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1091c, CLASS_none }, { 0x1091f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10920, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1093a, CLASS_none }, { 0x1093f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10940, CLASS_none }, { 0x10980, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x109b8, CLASS_none }, { 0x109bc, CLASS_graph|CLASS_print|CLASS_punct }, { 0x109be, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x109c0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x109d0, CLASS_none }, { 0x109d2, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10a00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10a04, CLASS_none }, { 0x10a05, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10a07, CLASS_none }, { 0x10a0c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10a14, CLASS_none }, { 0x10a15, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10a18, CLASS_none }, { 0x10a19, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10a36, CLASS_none }, { 0x10a38, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10a3b, CLASS_none }, { 0x10a3f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10a49, CLASS_none }, { 0x10a50, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10a59, CLASS_none }, { 0x10a60, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10a7d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10a80, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10a9d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10aa0, CLASS_none }, { 0x10ac0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10ac8, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10ac9, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10ae5, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10ae7, CLASS_none }, { 0x10aeb, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10af7, CLASS_none }, { 0x10b00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10b36, CLASS_none }, { 0x10b39, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10b40, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10b56, CLASS_none }, { 0x10b58, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10b60, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10b73, CLASS_none }, { 0x10b78, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10b80, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10b92, CLASS_none }, { 0x10b99, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10b9d, CLASS_none }, { 0x10ba9, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10bb0, CLASS_none }, { 0x10c00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10c49, CLASS_none }, { 0x10c80, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x10cb3, CLASS_none }, { 0x10cc0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x10cf3, CLASS_none }, { 0x10cfa, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10d00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10d28, CLASS_none }, { 0x10d30, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10d3a, CLASS_none }, { 0x10d40, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10d50, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x10d66, CLASS_none }, { 0x10d69, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10d6a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10d6f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10d70, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x10d86, CLASS_none }, { 0x10d8e, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10d90, CLASS_none }, { 0x10e60, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10e7f, CLASS_none }, { 0x10e80, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10eaa, CLASS_none }, { 0x10eab, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10ead, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10eae, CLASS_none }, { 0x10eb0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10eb2, CLASS_none }, { 0x10ec2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10ec5, CLASS_none }, { 0x10efc, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10efd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10f00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10f1d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10f27, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10f28, CLASS_none }, { 0x10f30, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10f46, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10f5a, CLASS_none }, { 0x10f70, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10f82, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10f8a, CLASS_none }, { 0x10fb0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10fc5, CLASS_graph|CLASS_print|CLASS_punct }, { 0x10fcc, CLASS_none }, { 0x10fe0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x10ff7, CLASS_none }, { 0x11000, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11046, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1104e, CLASS_none }, { 0x11052, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11066, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11070, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11071, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11076, CLASS_none }, { 0x1107f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11080, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x110b9, CLASS_graph|CLASS_print|CLASS_punct }, { 0x110c2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x110c3, CLASS_none }, { 0x110cd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x110ce, CLASS_none }, { 0x110d0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x110e9, CLASS_none }, { 0x110f0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x110fa, CLASS_none }, { 0x11100, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11133, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11135, CLASS_none }, { 0x11136, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11140, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11144, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11148, CLASS_none }, { 0x11150, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11173, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11176, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11177, CLASS_none }, { 0x11180, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x111c0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x111c1, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x111c5, CLASS_graph|CLASS_print|CLASS_punct }, { 0x111ce, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x111db, CLASS_graph|CLASS_print|CLASS_punct }, { 0x111dc, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x111dd, CLASS_graph|CLASS_print|CLASS_punct }, { 0x111e0, CLASS_none }, { 0x111e1, CLASS_graph|CLASS_print|CLASS_punct }, { 0x111f5, CLASS_none }, { 0x11200, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11212, CLASS_none }, { 0x11213, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11235, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11237, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11238, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1123e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11242, CLASS_none }, { 0x11280, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11287, CLASS_none }, { 0x11288, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11289, CLASS_none }, { 0x1128a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1128e, CLASS_none }, { 0x1128f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1129e, CLASS_none }, { 0x1129f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x112a9, CLASS_graph|CLASS_print|CLASS_punct }, { 0x112aa, CLASS_none }, { 0x112b0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x112e9, CLASS_graph|CLASS_print|CLASS_punct }, { 0x112eb, CLASS_none }, { 0x112f0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x112fa, CLASS_none }, { 0x11300, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11304, CLASS_none }, { 0x11305, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1130d, CLASS_none }, { 0x1130f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11311, CLASS_none }, { 0x11313, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11329, CLASS_none }, { 0x1132a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11331, CLASS_none }, { 0x11332, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11334, CLASS_none }, { 0x11335, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1133a, CLASS_none }, { 0x1133b, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1133d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11345, CLASS_none }, { 0x11347, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11349, CLASS_none }, { 0x1134b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1134d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1134e, CLASS_none }, { 0x11350, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11351, CLASS_none }, { 0x11357, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11358, CLASS_none }, { 0x1135d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11364, CLASS_none }, { 0x11366, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1136d, CLASS_none }, { 0x11370, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11375, CLASS_none }, { 0x11380, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1138a, CLASS_none }, { 0x1138b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1138c, CLASS_none }, { 0x1138e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1138f, CLASS_none }, { 0x11390, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x113b6, CLASS_none }, { 0x113b7, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x113c1, CLASS_none }, { 0x113c2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x113c3, CLASS_none }, { 0x113c5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x113c6, CLASS_none }, { 0x113c7, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x113cb, CLASS_none }, { 0x113cc, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x113ce, CLASS_graph|CLASS_print|CLASS_punct }, { 0x113d1, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x113d2, CLASS_graph|CLASS_print|CLASS_punct }, { 0x113d3, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x113d4, CLASS_graph|CLASS_print|CLASS_punct }, { 0x113d6, CLASS_none }, { 0x113d7, CLASS_graph|CLASS_print|CLASS_punct }, { 0x113d9, CLASS_none }, { 0x113e1, CLASS_graph|CLASS_print|CLASS_punct }, { 0x113e3, CLASS_none }, { 0x11400, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11442, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11443, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11446, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11447, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1144b, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11450, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1145a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1145c, CLASS_none }, { 0x1145d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1145f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11462, CLASS_none }, { 0x11480, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x114c2, CLASS_graph|CLASS_print|CLASS_punct }, { 0x114c4, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x114c6, CLASS_graph|CLASS_print|CLASS_punct }, { 0x114c7, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x114c8, CLASS_none }, { 0x114d0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x114da, CLASS_none }, { 0x11580, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x115b6, CLASS_none }, { 0x115b8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x115bf, CLASS_graph|CLASS_print|CLASS_punct }, { 0x115d8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x115de, CLASS_none }, { 0x11600, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1163f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11640, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11641, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11644, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11645, CLASS_none }, { 0x11650, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1165a, CLASS_none }, { 0x11660, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1166d, CLASS_none }, { 0x11680, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x116b6, CLASS_graph|CLASS_print|CLASS_punct }, { 0x116b8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x116b9, CLASS_graph|CLASS_print|CLASS_punct }, { 0x116ba, CLASS_none }, { 0x116c0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x116ca, CLASS_none }, { 0x116d0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x116e4, CLASS_none }, { 0x11700, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1171b, CLASS_none }, { 0x1171d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1172b, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1172c, CLASS_none }, { 0x11730, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1173a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11740, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11747, CLASS_none }, { 0x11800, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11839, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1183c, CLASS_none }, { 0x118a0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x118e0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x118ea, CLASS_graph|CLASS_print|CLASS_punct }, { 0x118f3, CLASS_none }, { 0x118ff, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11907, CLASS_none }, { 0x11909, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1190a, CLASS_none }, { 0x1190c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11914, CLASS_none }, { 0x11915, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11917, CLASS_none }, { 0x11918, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11936, CLASS_none }, { 0x11937, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11939, CLASS_none }, { 0x1193b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1193d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1193f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11943, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11947, CLASS_none }, { 0x11950, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1195a, CLASS_none }, { 0x119a0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x119a8, CLASS_none }, { 0x119aa, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x119d8, CLASS_none }, { 0x119da, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x119e0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x119e1, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x119e2, CLASS_graph|CLASS_print|CLASS_punct }, { 0x119e3, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x119e5, CLASS_none }, { 0x11a00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11a33, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11a35, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11a3f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11a48, CLASS_none }, { 0x11a50, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11a98, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11a9d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11a9e, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11aa3, CLASS_none }, { 0x11ab0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11af9, CLASS_none }, { 0x11b00, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11b0a, CLASS_none }, { 0x11bc0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11be1, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11be2, CLASS_none }, { 0x11bf0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11bfa, CLASS_none }, { 0x11c00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11c09, CLASS_none }, { 0x11c0a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11c37, CLASS_none }, { 0x11c38, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11c3f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11c40, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11c41, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11c46, CLASS_none }, { 0x11c50, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11c5a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11c6d, CLASS_none }, { 0x11c70, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11c72, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11c90, CLASS_none }, { 0x11c92, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11ca8, CLASS_none }, { 0x11ca9, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11cb7, CLASS_none }, { 0x11d00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11d07, CLASS_none }, { 0x11d08, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11d0a, CLASS_none }, { 0x11d0b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11d37, CLASS_none }, { 0x11d3a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11d3b, CLASS_none }, { 0x11d3c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11d3e, CLASS_none }, { 0x11d3f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11d42, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11d43, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11d44, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11d46, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11d48, CLASS_none }, { 0x11d50, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11d5a, CLASS_none }, { 0x11d60, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11d66, CLASS_none }, { 0x11d67, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11d69, CLASS_none }, { 0x11d6a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11d8f, CLASS_none }, { 0x11d90, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11d92, CLASS_none }, { 0x11d93, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11d97, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11d98, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11d99, CLASS_none }, { 0x11da0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11daa, CLASS_none }, { 0x11ee0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11ef7, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11ef9, CLASS_none }, { 0x11f00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11f11, CLASS_none }, { 0x11f12, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11f3b, CLASS_none }, { 0x11f3e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11f41, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11f50, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11f5a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11f5b, CLASS_none }, { 0x11fb0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x11fb1, CLASS_none }, { 0x11fc0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x11ff2, CLASS_none }, { 0x11fff, CLASS_graph|CLASS_print|CLASS_punct }, { 0x12000, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1239a, CLASS_none }, { 0x12400, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1246f, CLASS_none }, { 0x12470, CLASS_graph|CLASS_print|CLASS_punct }, { 0x12475, CLASS_none }, { 0x12480, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x12544, CLASS_none }, { 0x12f90, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x12ff1, CLASS_graph|CLASS_print|CLASS_punct }, { 0x12ff3, CLASS_none }, { 0x13000, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x13430, CLASS_graph|CLASS_print|CLASS_punct }, { 0x13441, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x13447, CLASS_graph|CLASS_print|CLASS_punct }, { 0x13456, CLASS_none }, { 0x13460, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x143fb, CLASS_none }, { 0x14400, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x14647, CLASS_none }, { 0x16100, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1612f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x16130, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1613a, CLASS_none }, { 0x16800, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16a39, CLASS_none }, { 0x16a40, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16a5f, CLASS_none }, { 0x16a60, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16a6a, CLASS_none }, { 0x16a6e, CLASS_graph|CLASS_print|CLASS_punct }, { 0x16a70, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16abf, CLASS_none }, { 0x16ac0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16aca, CLASS_none }, { 0x16ad0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16aee, CLASS_none }, { 0x16af0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x16af6, CLASS_none }, { 0x16b00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16b30, CLASS_graph|CLASS_print|CLASS_punct }, { 0x16b40, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16b44, CLASS_graph|CLASS_print|CLASS_punct }, { 0x16b46, CLASS_none }, { 0x16b50, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16b5a, CLASS_none }, { 0x16b5b, CLASS_graph|CLASS_print|CLASS_punct }, { 0x16b62, CLASS_none }, { 0x16b63, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16b78, CLASS_none }, { 0x16b7d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16b90, CLASS_none }, { 0x16d40, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16d6d, CLASS_graph|CLASS_print|CLASS_punct }, { 0x16d70, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16d7a, CLASS_none }, { 0x16e40, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x16e80, CLASS_graph|CLASS_print|CLASS_punct }, { 0x16e9b, CLASS_none }, { 0x16f00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16f4b, CLASS_none }, { 0x16f4f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16f88, CLASS_none }, { 0x16f8f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16fa0, CLASS_none }, { 0x16fe0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16fe2, CLASS_graph|CLASS_print|CLASS_punct }, { 0x16fe3, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16fe4, CLASS_graph|CLASS_print|CLASS_punct }, { 0x16fe5, CLASS_none }, { 0x16ff0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x16ff2, CLASS_none }, { 0x17000, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x187f8, CLASS_none }, { 0x18800, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x18cd6, CLASS_none }, { 0x18cff, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x18d09, CLASS_none }, { 0x1aff0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1aff4, CLASS_none }, { 0x1aff5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1affc, CLASS_none }, { 0x1affd, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1afff, CLASS_none }, { 0x1b000, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1b123, CLASS_none }, { 0x1b132, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1b133, CLASS_none }, { 0x1b150, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1b153, CLASS_none }, { 0x1b155, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1b156, CLASS_none }, { 0x1b164, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1b168, CLASS_none }, { 0x1b170, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1b2fc, CLASS_none }, { 0x1bc00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1bc6b, CLASS_none }, { 0x1bc70, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1bc7d, CLASS_none }, { 0x1bc80, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1bc89, CLASS_none }, { 0x1bc90, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1bc9a, CLASS_none }, { 0x1bc9c, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1bc9e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1bc9f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1bca4, CLASS_none }, { 0x1cc00, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1ccf0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ccfa, CLASS_none }, { 0x1cd00, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1ceb4, CLASS_none }, { 0x1cf00, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1cf2e, CLASS_none }, { 0x1cf30, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1cf47, CLASS_none }, { 0x1cf50, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1cfc4, CLASS_none }, { 0x1d000, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d0f6, CLASS_none }, { 0x1d100, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d127, CLASS_none }, { 0x1d129, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d1eb, CLASS_none }, { 0x1d200, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d246, CLASS_none }, { 0x1d2c0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d2d4, CLASS_none }, { 0x1d2e0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d2f4, CLASS_none }, { 0x1d300, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d357, CLASS_none }, { 0x1d360, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d379, CLASS_none }, { 0x1d400, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d41a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d434, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d44e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d455, CLASS_none }, { 0x1d456, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d468, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d482, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d49c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d49d, CLASS_none }, { 0x1d49e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d4a0, CLASS_none }, { 0x1d4a2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d4a3, CLASS_none }, { 0x1d4a5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d4a7, CLASS_none }, { 0x1d4a9, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d4ad, CLASS_none }, { 0x1d4ae, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d4b6, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d4ba, CLASS_none }, { 0x1d4bb, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d4bc, CLASS_none }, { 0x1d4bd, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d4c4, CLASS_none }, { 0x1d4c5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d4d0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d4ea, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d504, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d506, CLASS_none }, { 0x1d507, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d50b, CLASS_none }, { 0x1d50d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d515, CLASS_none }, { 0x1d516, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d51d, CLASS_none }, { 0x1d51e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d538, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d53a, CLASS_none }, { 0x1d53b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d53f, CLASS_none }, { 0x1d540, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d545, CLASS_none }, { 0x1d546, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d547, CLASS_none }, { 0x1d54a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d551, CLASS_none }, { 0x1d552, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d56c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d586, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d5a0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d5ba, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d5d4, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d5ee, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d608, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d622, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d63c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d656, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d670, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d68a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d6a6, CLASS_none }, { 0x1d6a8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d6c1, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d6c2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d6db, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d6dc, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d6e2, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d6fb, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d6fc, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d715, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d716, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d71c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d735, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d736, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d74f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d750, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d756, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d76f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d770, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d789, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d78a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d790, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d7a9, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d7aa, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d7c3, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1d7c4, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d7ca, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1d7cb, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1d7cc, CLASS_none }, { 0x1d7ce, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1d800, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1da8c, CLASS_none }, { 0x1da9b, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1daa0, CLASS_none }, { 0x1daa1, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1dab0, CLASS_none }, { 0x1df00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1df0a, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1df0b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1df1f, CLASS_none }, { 0x1df25, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1df2b, CLASS_none }, { 0x1e000, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e007, CLASS_none }, { 0x1e008, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e019, CLASS_none }, { 0x1e01b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e022, CLASS_none }, { 0x1e023, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e025, CLASS_none }, { 0x1e026, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e02b, CLASS_none }, { 0x1e030, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_lower }, { 0x1e06e, CLASS_none }, { 0x1e08f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e090, CLASS_none }, { 0x1e100, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e12d, CLASS_none }, { 0x1e130, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1e137, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e13e, CLASS_none }, { 0x1e140, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e14a, CLASS_none }, { 0x1e14e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e14f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1e150, CLASS_none }, { 0x1e290, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e2ae, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1e2af, CLASS_none }, { 0x1e2c0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e2ec, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1e2f0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e2fa, CLASS_none }, { 0x1e2ff, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1e300, CLASS_none }, { 0x1e4d0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e4ec, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1e4f0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e4fa, CLASS_none }, { 0x1e5d0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e5ee, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1e5f0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e5fb, CLASS_none }, { 0x1e5ff, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1e600, CLASS_none }, { 0x1e7e0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e7e7, CLASS_none }, { 0x1e7e8, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e7ec, CLASS_none }, { 0x1e7ed, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e7ef, CLASS_none }, { 0x1e7f0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e7ff, CLASS_none }, { 0x1e800, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e8c5, CLASS_none }, { 0x1e8c7, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1e8d7, CLASS_none }, { 0x1e900, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_case }, { 0x1e944, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1e947, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e948, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1e94b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e94c, CLASS_none }, { 0x1e950, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1e95a, CLASS_none }, { 0x1e95e, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1e960, CLASS_none }, { 0x1ec71, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1ecb5, CLASS_none }, { 0x1ed01, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1ed3e, CLASS_none }, { 0x1ee00, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee04, CLASS_none }, { 0x1ee05, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee20, CLASS_none }, { 0x1ee21, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee23, CLASS_none }, { 0x1ee24, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee25, CLASS_none }, { 0x1ee27, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee28, CLASS_none }, { 0x1ee29, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee33, CLASS_none }, { 0x1ee34, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee38, CLASS_none }, { 0x1ee39, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee3a, CLASS_none }, { 0x1ee3b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee3c, CLASS_none }, { 0x1ee42, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee43, CLASS_none }, { 0x1ee47, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee48, CLASS_none }, { 0x1ee49, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee4a, CLASS_none }, { 0x1ee4b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee4c, CLASS_none }, { 0x1ee4d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee50, CLASS_none }, { 0x1ee51, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee53, CLASS_none }, { 0x1ee54, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee55, CLASS_none }, { 0x1ee57, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee58, CLASS_none }, { 0x1ee59, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee5a, CLASS_none }, { 0x1ee5b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee5c, CLASS_none }, { 0x1ee5d, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee5e, CLASS_none }, { 0x1ee5f, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee60, CLASS_none }, { 0x1ee61, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee63, CLASS_none }, { 0x1ee64, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee65, CLASS_none }, { 0x1ee67, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee6b, CLASS_none }, { 0x1ee6c, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee73, CLASS_none }, { 0x1ee74, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee78, CLASS_none }, { 0x1ee79, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee7d, CLASS_none }, { 0x1ee7e, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee7f, CLASS_none }, { 0x1ee80, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee8a, CLASS_none }, { 0x1ee8b, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1ee9c, CLASS_none }, { 0x1eea1, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1eea4, CLASS_none }, { 0x1eea5, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1eeaa, CLASS_none }, { 0x1eeab, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1eebc, CLASS_none }, { 0x1eef0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1eef2, CLASS_none }, { 0x1f000, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f02c, CLASS_none }, { 0x1f030, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f094, CLASS_none }, { 0x1f0a0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f0af, CLASS_none }, { 0x1f0b1, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f0c0, CLASS_none }, { 0x1f0c1, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f0d0, CLASS_none }, { 0x1f0d1, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f0f6, CLASS_none }, { 0x1f100, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f130, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1f14a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f150, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1f16a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f170, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print|CLASS_upper }, { 0x1f18a, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f1ae, CLASS_none }, { 0x1f1e6, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f203, CLASS_none }, { 0x1f210, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f23c, CLASS_none }, { 0x1f240, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f249, CLASS_none }, { 0x1f250, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f252, CLASS_none }, { 0x1f260, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f266, CLASS_none }, { 0x1f300, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f6d8, CLASS_none }, { 0x1f6dc, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f6ed, CLASS_none }, { 0x1f6f0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f6fd, CLASS_none }, { 0x1f700, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f777, CLASS_none }, { 0x1f77b, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f7da, CLASS_none }, { 0x1f7e0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f7ec, CLASS_none }, { 0x1f7f0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f7f1, CLASS_none }, { 0x1f800, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f80c, CLASS_none }, { 0x1f810, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f848, CLASS_none }, { 0x1f850, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f85a, CLASS_none }, { 0x1f860, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f888, CLASS_none }, { 0x1f890, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f8ae, CLASS_none }, { 0x1f8b0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f8bc, CLASS_none }, { 0x1f8c0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1f8c2, CLASS_none }, { 0x1f900, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1fa54, CLASS_none }, { 0x1fa60, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1fa6e, CLASS_none }, { 0x1fa70, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1fa7d, CLASS_none }, { 0x1fa80, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1fa8a, CLASS_none }, { 0x1fa8f, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1fac7, CLASS_none }, { 0x1face, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1fadd, CLASS_none }, { 0x1fadf, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1faea, CLASS_none }, { 0x1faf0, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1faf9, CLASS_none }, { 0x1fb00, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1fb93, CLASS_none }, { 0x1fb94, CLASS_graph|CLASS_print|CLASS_punct }, { 0x1fbf0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x1fbfa, CLASS_none }, { 0x20000, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2a6e0, CLASS_none }, { 0x2a700, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2b73a, CLASS_none }, { 0x2b740, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2b81e, CLASS_none }, { 0x2b820, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2cea2, CLASS_none }, { 0x2ceb0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2ebe1, CLASS_none }, { 0x2ebf0, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2ee5e, CLASS_none }, { 0x2f800, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x2fa1e, CLASS_none }, { 0x30000, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x3134b, CLASS_none }, { 0x31350, CLASS_alnum|CLASS_alpha|CLASS_graph|CLASS_print }, { 0x323b0, CLASS_none }, { 0xe0001, CLASS_graph|CLASS_print|CLASS_punct }, { 0xe0002, CLASS_none }, { 0xe0020, CLASS_graph|CLASS_print|CLASS_punct }, { 0xe0080, CLASS_none }, { 0xe0100, CLASS_graph|CLASS_print|CLASS_punct }, { 0xe01f0, CLASS_none }, #endif picolibc-1.8.11/libc/ctype/ctype_wide.c000066400000000000000000000034331513574234600177400ustar00rootroot00000000000000/* * Copyright (c) 1989 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #define _DEFAULT_SOURCE /* Make sure we're using fast ctype */ #define _PICOLIBC_CTYPE_SMALL 0 #include "ctype_.h" #include "locale_private.h" const short _ctype_wide[1 + 256] = { 0, _CTYPE_DATA_0_127_WIDE, _CTYPE_DATA_128_255 }; picolibc-1.8.11/libc/ctype/isalnum.c000066400000000000000000000054171513574234600172600ustar00rootroot00000000000000/* Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---alphanumeric character predicate INDEX isalnum INDEX isalnum_l SYNOPSIS #include int isalnum(int <[c]>); #include int isalnum_l(int <[c]>, locale_t <[locale]>); DESCRIPTION <> is a macro which classifies singlebyte charset values by table lookup. It is a predicate returning non-zero for alphabetic or numeric ASCII characters, and <<0>> for other arguments. It is defined only if <[c]> is representable as an unsigned char or if <[c]> is EOF. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef isalnum>>' or `<<#undef isalnum_l>>'. RETURNS <>,<> return non-zero if <[c]> is a letter or a digit. PORTABILITY <> is ANSI C. <> is POSIX-1.2008. No OS subroutines are required. */ #include #undef isalnum int isalnum(int c) { #if _PICOLIBC_CTYPE_SMALL return isalpha(c) || isdigit(c); #else return __CTYPE_PTR[c + 1] & (__CTYPE_UPPER | __CTYPE_LOWER | __CTYPE_DIGIT); #endif } picolibc-1.8.11/libc/ctype/isalnum_l.c000066400000000000000000000006341513574234600175670ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #undef isalnum_l int isalnum_l(int c, locale_t locale) { #if _PICOLIBC_CTYPE_SMALL (void)locale; return isalnum(c); #else return __CTYPE_PTR_L(locale)[c + 1] & (__CTYPE_UPPER | __CTYPE_LOWER | __CTYPE_DIGIT); #endif } picolibc-1.8.11/libc/ctype/isalpha.c000066400000000000000000000053711513574234600172300ustar00rootroot00000000000000/* Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---alphabetic character predicate INDEX isalpha INDEX isalpha_l SYNOPSIS #include int isalpha(int <[c]>); #include int isalpha_l(int <[c]>, locale_t <[locale]>); DESCRIPTION <> is a macro which classifies singlebyte charset values by table lookup. It is a predicate returning non-zero when <[c]> represents an alphabetic ASCII character, and 0 otherwise. It is defined only if <[c]> is representable as an unsigned char or if <[c]> is EOF. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef isalpha>>' or `<<#undef isalpha_l>>'. RETURNS <>, <> return non-zero if <[c]> is a letter. PORTABILITY <> is ANSI C. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #include #undef isalpha int isalpha(int c) { #if _PICOLIBC_CTYPE_SMALL return isupper(c) || islower(c); #else return __CTYPE_PTR[c + 1] & (__CTYPE_UPPER | __CTYPE_LOWER); #endif } picolibc-1.8.11/libc/ctype/isalpha_l.c000066400000000000000000000006141513574234600175360ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #undef isalpha_l int isalpha_l(int c, locale_t locale) { #if _PICOLIBC_CTYPE_SMALL (void)locale; return isalpha(c); #else return __CTYPE_PTR_L(locale)[c + 1] & (__CTYPE_UPPER | __CTYPE_LOWER); #endif } picolibc-1.8.11/libc/ctype/isascii.c000066400000000000000000000051141513574234600172260ustar00rootroot00000000000000/* Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---ASCII character predicate INDEX isascii INDEX isascii_l SYNOPSIS #include int isascii(int <[c]>); #include int isascii_l(int <[c]>, locale_t <[locale]>); DESCRIPTION <> is a macro which returns non-zero when <[c]> is an ASCII character, and 0 otherwise. It is defined for all integer values. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef isascii>>' or `<<#undef isascii_l>>'. RETURNS <>, <> return non-zero if the low order byte of <[c]> is in the range 0 to 127 (<<0x00>>--<<0x7F>>). PORTABILITY <> is ANSI C. <> is a GNU extension. No supporting OS subroutines are required. */ #define _DEFAULT_SOURCE #include #undef isascii int isascii(int c) { return (unsigned)c <= 0177; } picolibc-1.8.11/libc/ctype/isascii_l.c000066400000000000000000000004431513574234600175410ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #undef isascii_l int isascii_l(int c, locale_t locale) { (void)locale; return (unsigned)c <= 0177; } picolibc-1.8.11/libc/ctype/isblank.c000066400000000000000000000022731513574234600172300ustar00rootroot00000000000000/* Copyright (c) 2002 Thomas Fitzsimmons */ /* FUNCTION <>, <>---blank character predicate INDEX isblank INDEX isblank_l SYNOPSIS #include int isblank(int <[c]>); #include int isblank_l(int <[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which classifies singlebyte charset values by table lookup. It is a predicate returning non-zero for blank characters, and 0 for other characters. It is defined only if <[c]> is representable as an unsigned char or if <[c]> is EOF. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return non-zero if <[c]> is a blank character. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #include #undef isblank int isblank(int c) { #if _PICOLIBC_CTYPE_SMALL return c == ' ' || c == '\t'; #else return (__CTYPE_PTR[c + 1] & __CTYPE_BLANK) || c == '\t'; #endif } picolibc-1.8.11/libc/ctype/isblank_l.c000066400000000000000000000006131513574234600175370ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #undef isblank_l int isblank_l(int c, locale_t locale) { #if _PICOLIBC_CTYPE_SMALL (void)locale; return isblank(c); #else return (__CTYPE_PTR_L(locale)[c + 1] & __CTYPE_BLANK) || (c == '\t'); #endif } picolibc-1.8.11/libc/ctype/iscntrl.c000066400000000000000000000054111513574234600172600ustar00rootroot00000000000000/* Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---control character predicate INDEX iscntrl INDEX iscntrl_l SYNOPSIS #include int iscntrl(int <[c]>); #include int iscntrl_l(int <[c]>, locale_t <[locale]>); DESCRIPTION <> is a macro which classifies singlebyte charset values by table lookup. It is a predicate returning non-zero for control characters, and 0 for other characters. It is defined only if <[c]> is representable as an unsigned char or if <[c]> is EOF. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef iscntrl>>' or `<<#undef iscntrl_l>>'. RETURNS <>, <> return non-zero if <[c]> is a delete character or ordinary control character. PORTABILITY <> is ANSI C. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #include #undef iscntrl int iscntrl(int c) { #if _PICOLIBC_CTYPE_SMALL return (0x00 <= c && c <= 0x1f) || c == 0x7f; #else return (__CTYPE_PTR[c + 1] & __CTYPE_CNTRL); #endif } picolibc-1.8.11/libc/ctype/iscntrl_l.c000066400000000000000000000006251513574234600175750ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #undef iscntrl_l int iscntrl_l(int c, locale_t locale) { (void)locale; #if _PICOLIBC_CTYPE_SMALL return (0x00 <= c && c <= 0x1f) || c == 0x7f; #else return __CTYPE_PTR_L(locale)[c + 1] & __CTYPE_CNTRL; #endif } picolibc-1.8.11/libc/ctype/isdigit.c000066400000000000000000000053341513574234600172420ustar00rootroot00000000000000/* Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---decimal digit predicate INDEX isdigit INDEX isdigit_l SYNOPSIS #include int isdigit(int <[c]>); #include int isdigit_l(int <[c]>, locale_t <[locale]>); DESCRIPTION <> is a macro which classifies singlebyte charset values by table lookup. It is a predicate returning non-zero for decimal digits, and 0 for other characters. It is defined only if <[c]> is representable as an unsigned char or if <[c]> is EOF. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef isdigit>>' or `<<#undef isdigit_l>>'. RETURNS <>, <> return non-zero if <[c]> is a decimal digit (<<0>>--<<9>>). PORTABILITY <> is ANSI C. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #include #undef isdigit int isdigit(int c) { #if _PICOLIBC_CTYPE_SMALL return '0' <= c && c <= '9'; #else return __CTYPE_PTR[c + 1] & __CTYPE_DIGIT; #endif } picolibc-1.8.11/libc/ctype/isdigit_l.c000066400000000000000000000005721513574234600175540ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #undef isdigit_l int isdigit_l(int c, locale_t locale) { #if _PICOLIBC_CTYPE_SMALL (void)locale; return isdigit(c); #else return __CTYPE_PTR_L(locale)[c + 1] & __CTYPE_DIGIT; #endif } picolibc-1.8.11/libc/ctype/isgraph.c000066400000000000000000000051311513574234600172360ustar00rootroot00000000000000/* Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---printable character predicates INDEX isgraph INDEX isgraph_l SYNOPSIS #include int isgraph(int <[c]>); #include int isgraph_l(int <[c]>, locale_t <[locale]>); DESCRIPTION <> behaves identically to <>, except that space characters are excluded. <> is like <> but perform the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. You can use a compiled subroutine instead of the macro definition by undefining either macro using `<<#undef isgraph>>', or `<<#undef isgraph_l>>'. RETURNS <>, <> return non-zero if <[c]> is a printing character except spaces. PORTABILITY <> is ANSI C. No supporting OS subroutines are required. */ #include #undef isgraph int isgraph(int c) { #if _PICOLIBC_CTYPE_SMALL return '!' <= c && c <= '~'; #else return __CTYPE_PTR[c + 1] & (__CTYPE_PUNCT | __CTYPE_UPPER | __CTYPE_LOWER | __CTYPE_DIGIT); #endif } picolibc-1.8.11/libc/ctype/isgraph_l.c000066400000000000000000000006651513574234600175600ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #undef isgraph_l int isgraph_l(int c, locale_t locale) { #if _PICOLIBC_CTYPE_SMALL (void)locale; return isgraph(c); #else return __CTYPE_PTR_L(locale)[c + 1] & (__CTYPE_PUNCT | __CTYPE_UPPER | __CTYPE_LOWER | __CTYPE_DIGIT); #endif } picolibc-1.8.11/libc/ctype/islower.c000066400000000000000000000054311513574234600172700ustar00rootroot00000000000000/* Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---lowercase character predicate INDEX islower INDEX islower_l SYNOPSIS #include int islower(int <[c]>); #include int islower_l(int <[c]>, locale_t <[locale]>); DESCRIPTION <> is a macro which classifies singlebyte charset values by table lookup. It is a predicate returning non-zero for minuscules (lowercase alphabetic characters), and 0 for other characters. It is defined only if <[c]> is representable as an unsigned char or if <[c]> is EOF. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef islower>>' or `<<#undef islower_l>>'. RETURNS <>, <> return non-zero if <[c]> is a lowercase letter. PORTABILITY <> is ANSI C. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #include #undef islower int islower(int c) { #if _PICOLIBC_CTYPE_SMALL return 'a' <= c && c <= 'z'; #else return ((__CTYPE_PTR[c + 1] & (__CTYPE_UPPER | __CTYPE_LOWER)) == __CTYPE_LOWER); #endif } picolibc-1.8.11/libc/ctype/islower_l.c000066400000000000000000000006371513574234600176060ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #undef islower_l int islower_l(int c, locale_t locale) { #if _PICOLIBC_CTYPE_SMALL (void)locale; return islower(c); #else return (__CTYPE_PTR_L(locale)[c + 1] & (__CTYPE_UPPER | __CTYPE_LOWER)) == __CTYPE_LOWER; #endif } picolibc-1.8.11/libc/ctype/isprint.c000066400000000000000000000063201513574234600172720ustar00rootroot00000000000000/* Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>, <>, <>---printable character predicates INDEX isprint INDEX isgraph INDEX isprint_l INDEX isgraph_l SYNOPSIS #include int isprint(int <[c]>); int isgraph(int <[c]>); #include int isprint_l(int <[c]>, locale_t <[locale]>); int isgraph_l(int <[c]>, locale_t <[locale]>); DESCRIPTION <> is a macro which classifies singlebyte charset values by table lookup. It is a predicate returning non-zero for printable characters, and 0 for other character arguments. It is defined only if <[c]> is representable as an unsigned char or if <[c]> is EOF. <> behaves identically to <>, except that space characters are excluded. <>, <> are like <>, <> but perform the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. You can use a compiled subroutine instead of the macro definition by undefining either macro using `<<#undef isprint>>' or `<<#undef isgraph>>', or `<<#undef isprint_l>>' or `<<#undef isgraph_l>>'. RETURNS <>, <> return non-zero if <[c]> is a printing character. <>, <> return non-zero if <[c]> is a printing character except spaces. PORTABILITY <> and <> are ANSI C. No supporting OS subroutines are required. */ #include #undef isprint int isprint(int c) { #if _PICOLIBC_CTYPE_SMALL return ' ' <= c && c <= '~'; #else return __CTYPE_PTR[c + 1] & (__CTYPE_PUNCT | __CTYPE_UPPER | __CTYPE_LOWER | __CTYPE_DIGIT | __CTYPE_BLANK); #endif } picolibc-1.8.11/libc/ctype/isprint_l.c000066400000000000000000000007051513574234600176060ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #undef isprint_l int isprint_l(int c, locale_t locale) { #if _PICOLIBC_CTYPE_SMALL (void)locale; return isprint(c); #else return __CTYPE_PTR_L(locale)[c + 1] & (__CTYPE_PUNCT | __CTYPE_UPPER | __CTYPE_LOWER | __CTYPE_DIGIT | __CTYPE_BLANK); #endif } picolibc-1.8.11/libc/ctype/ispunct.c000066400000000000000000000055311513574234600172720ustar00rootroot00000000000000/* Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---punctuation character predicate INDEX ispunct INDEX ispunct_l SYNOPSIS #include int ispunct(int <[c]>); #include int ispunct_l(int <[c]>, locale_t <[locale]>); DESCRIPTION <> is a macro which classifies singlebyte charset values by table lookup. It is a predicate returning non-zero for printable punctuation characters, and 0 for other characters. It is defined only if <[c]> is representable as an unsigned char or if <[c]> is EOF. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef ispunct>>' or `<<#undef ispunct_l>>'. RETURNS <>, <> return non-zero if <[c]> is a printable punctuation character. PORTABILITY <> is ANSI C. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #include #undef ispunct int ispunct(int c) { #if _PICOLIBC_CTYPE_SMALL return (('!' <= c && c <= '/') || (':' <= c && c <= '@') || ('[' <= c && c <= '`') || ('{' <= c && c <= '~')); #else return (__CTYPE_PTR[c + 1] & __CTYPE_PUNCT); #endif } picolibc-1.8.11/libc/ctype/ispunct_l.c000066400000000000000000000005721513574234600176050ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #undef ispunct_l int ispunct_l(int c, locale_t locale) { #if _PICOLIBC_CTYPE_SMALL (void)locale; return ispunct(c); #else return __CTYPE_PTR_L(locale)[c + 1] & __CTYPE_PUNCT; #endif } picolibc-1.8.11/libc/ctype/isspace.c000066400000000000000000000055511513574234600172360ustar00rootroot00000000000000/* Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---whitespace character predicate INDEX isspace INDEX isspace_l SYNOPSIS #include int isspace(int <[c]>); #include int isspace_l(int <[c]>, locale_t <[locale]>); DESCRIPTION <> is a macro which classifies singlebyte charset values by table lookup. It is a predicate returning non-zero for whitespace characters, and 0 for other characters. It is defined only when <>(<[c]>) is true or <[c]> is EOF. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef isspace>>' or `<<#undef isspace_l>>'. RETURNS <>, <> return non-zero if <[c]> is a space, tab, carriage return, new line, vertical tab, or formfeed (<<0x09>>--<<0x0D>>, <<0x20>>), or one of the other space characters in non-ASCII charsets. PORTABILITY <> is ANSI C. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #include #undef isspace int isspace(int c) { #if _PICOLIBC_CTYPE_SMALL return c == ' ' || ('\t' <= c && c <= '\r'); #else return (__CTYPE_PTR[c + 1] & __CTYPE_SPACE); #endif } picolibc-1.8.11/libc/ctype/isspace_l.c000066400000000000000000000005721513574234600175470ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #undef isspace_l int isspace_l(int c, locale_t locale) { (void)locale; #if _PICOLIBC_CTYPE_SMALL return isspace(c); #else return __CTYPE_PTR_L(locale)[c + 1] & __CTYPE_SPACE; #endif } picolibc-1.8.11/libc/ctype/isupper.c000066400000000000000000000052711513574234600172750ustar00rootroot00000000000000/* Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---uppercase character predicate INDEX isupper INDEX isupper_l SYNOPSIS #include int isupper(int <[c]>); #include int isupper_l(int <[c]>, locale_t <[locale]>); DESCRIPTION <> is a macro which classifies singlebyte charset values by table lookup. It is a predicate returning non-zero for uppercase letters (<>--<>), and 0 for other characters. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef isupper>>' or `<<#undef isupper_l>>'. RETURNS <>, <> return non-zero if <[c]> is an uppercase letter. PORTABILITY <> is ANSI C. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #include #undef isupper int isupper(int c) { #if _PICOLIBC_CTYPE_SMALL return 'A' <= c && c <= 'Z'; #else return ((__CTYPE_PTR[c + 1] & (__CTYPE_UPPER | __CTYPE_LOWER)) == __CTYPE_UPPER); #endif } picolibc-1.8.11/libc/ctype/isupper_l.c000066400000000000000000000006371513574234600176110ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #undef isupper_l int isupper_l(int c, locale_t locale) { #if _PICOLIBC_CTYPE_SMALL (void)locale; return isupper(c); #else return (__CTYPE_PTR_L(locale)[c + 1] & (__CTYPE_UPPER | __CTYPE_LOWER)) == __CTYPE_UPPER; #endif } picolibc-1.8.11/libc/ctype/iswalnum.c000066400000000000000000000050121513574234600174360ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---alphanumeric wide character test INDEX iswalnum INDEX iswalnum_l SYNOPSIS #include int iswalnum(wint_t <[c]>); #include int iswalnum_l(wint_t <[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which classifies wide-character values that are alphanumeric. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return non-zero if <[c]> is a alphanumeric wide character. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswalnum(wint_t c) { #ifdef __MB_CAPABLE return __ctype_table_lookup(c, 0, CLASS_alnum); #else return c < (wint_t)0x100 ? isalnum(c) : 0; #endif } picolibc-1.8.11/libc/ctype/iswalnum_l.c000066400000000000000000000010101513574234600177430ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswalnum_l(wint_t c, locale_t locale) { (void)locale; #ifdef __MB_CAPABLE return __ctype_table_lookup(c, locale, CLASS_alnum); #else return c < (wint_t)0x100 ? isalnum(c) : 0; #endif /* __MB_CAPABLE */ } picolibc-1.8.11/libc/ctype/iswalpha.c000066400000000000000000000051311513574234600174110ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---alphabetic wide character test INDEX iswalpha INDEX iswalpha_l SYNOPSIS #include int iswalpha(wint_t <[c]>); #include int iswalpha_l(wint_t <[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which classifies wide-character values that are alphabetic. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return non-zero if <[c]> is an alphabetic wide character. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswalpha(wint_t c) { #ifdef __MB_CAPABLE return __ctype_table_lookup(c, 0, CLASS_alpha); #else return c < (wint_t)0x100 ? isalpha(c) : 0; #endif } picolibc-1.8.11/libc/ctype/iswalpha_l.c000066400000000000000000000010101513574234600177140ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswalpha_l(wint_t c, locale_t locale) { (void)locale; #ifdef __MB_CAPABLE return __ctype_table_lookup(c, locale, CLASS_alpha); #else return c < (wint_t)0x100 ? isalpha(c) : 0; #endif /* __MB_CAPABLE */ } picolibc-1.8.11/libc/ctype/iswblank.c000066400000000000000000000051301513574234600174120ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---blank wide character test INDEX iswblank INDEX iswblank_l SYNOPSIS #include int iswblank(wint_t <[c]>); #include int iswblank_l(wint_t <[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which classifies wide-character values that are categorized as blank. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return non-zero if <[c]> is a blank wide character. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswblank(wint_t c) { #ifdef __MB_CAPABLE return __ctype_table_lookup(c, 0, CLASS_blank); #else return c < (wint_t)0x100 ? isblank(c) : 0; #endif } picolibc-1.8.11/libc/ctype/iswblank_l.c000066400000000000000000000010001513574234600177150ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswblank_l(wint_t c, locale_t locale) { (void)locale; #ifdef __MB_CAPABLE return __ctype_table_lookup(c, locale, CLASS_blank); #else return c < 0x100 ? isblank(c) : 0; #endif /* __MB_CAPABLE */ } picolibc-1.8.11/libc/ctype/iswcntrl.c000066400000000000000000000051511513574234600174500ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---control wide character test INDEX iswcntrl INDEX iswcntrl_l SYNOPSIS #include int iswcntrl(wint_t <[c]>); #include int iswcntrl_l(wint_t <[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which classifies wide-character values that are categorized as control characters. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return non-zero if <[c]> is a control wide character. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswcntrl(wint_t c) { #ifdef __MB_CAPABLE return __ctype_table_lookup(c, 0, CLASS_cntrl); #else return c < (wint_t)0x100 ? iscntrl(c) : 0; #endif } picolibc-1.8.11/libc/ctype/iswcntrl_l.c000066400000000000000000000010001513574234600177500ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswcntrl_l(wint_t c, locale_t locale) { (void)locale; #ifdef __MB_CAPABLE return __ctype_table_lookup(c, locale, CLASS_cntrl); #else return c < 0x100 ? iscntrl(c) : 0; #endif /* __MB_CAPABLE */ } picolibc-1.8.11/libc/ctype/iswctype.c000066400000000000000000000050571513574234600174570ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---extensible wide-character test INDEX iswctype INDEX iswctype_l SYNOPSIS #include int iswctype(wint_t <[c]>, wctype_t <[desc]>); #include int iswctype_l(wint_t <[c]>, wctype_t <[desc]>, locale_t <[locale]>); DESCRIPTION <> is a function which classifies wide-character values using the wide-character test specified by <[desc]>. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return non-zero if and only if <[c]> matches the test specified by <[desc]>. If <[desc]> is unknown, zero is returned. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #define _DEFAULT_SOURCE #include #include "local.h" int iswctype(wint_t c, wctype_t desc) { return __ctype_table_lookup(c, 0, desc); } picolibc-1.8.11/libc/ctype/iswctype_l.c000066400000000000000000000004761513574234600177720ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen */ /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #include "local.h" int iswctype_l(wint_t c, wctype_t desc, locale_t locale) { return __ctype_table_lookup(c, locale, desc); } picolibc-1.8.11/libc/ctype/iswdigit.c000066400000000000000000000046711513574234600174340ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---decimal digit wide character test INDEX iswdigit INDEX iswdigit_l SYNOPSIS #include int iswdigit(wint_t <[c]>); #include int iswdigit_l(wint_t <[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which classifies wide-character values that are decimal digits. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return non-zero if <[c]> is a decimal digit wide character. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #include int iswdigit(wint_t c) { return c >= (wint_t)'0' && c <= (wint_t)'9'; // category (c) == CAT_Nd not to be included as of C-99 } picolibc-1.8.11/libc/ctype/iswdigit_l.c000066400000000000000000000004501513574234600177360ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include int iswdigit_l(wint_t c, locale_t locale) { (void)locale; return c >= (wint_t)'0' && c <= (wint_t)'9'; } picolibc-1.8.11/libc/ctype/iswgraph.c000066400000000000000000000051171513574234600174310ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---graphic wide character test INDEX iswgraph INDEX iswgraph_l SYNOPSIS #include int iswgraph(wint_t <[c]>); #include int iswgraph_l(wint_t <[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which classifies wide-character values that are graphic. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return non-zero if <[c]> is a graphic wide character. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswgraph(wint_t c) { #ifdef __MB_CAPABLE return __ctype_table_lookup(c, 0, CLASS_graph); #else return c < (wint_t)0x100 ? isgraph(c) : 0; #endif } picolibc-1.8.11/libc/ctype/iswgraph_l.c000066400000000000000000000010101513574234600177300ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswgraph_l(wint_t c, locale_t locale) { (void)locale; #ifdef __MB_CAPABLE return __ctype_table_lookup(c, locale, CLASS_graph); #else return c < (wint_t)0x100 ? isgraph(c) : 0; #endif /* __MB_CAPABLE */ } picolibc-1.8.11/libc/ctype/iswlower.c000066400000000000000000000050201513574234600174510ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---lowercase wide character test INDEX iswlower INDEX iswlower_l SYNOPSIS #include int iswlower(wint_t <[c]>); #include int iswlower_l(wint_t <[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which classifies wide-character values that are categorized as lowercase. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return non-zero if <[c]> is a lowercase wide character. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswlower(wint_t c) { #ifdef __MB_CAPABLE return __ctype_table_lookup(c, 0, CLASS_lower); #else return c < (wint_t)0x100 ? islower(c) : 0; #endif } picolibc-1.8.11/libc/ctype/iswlower_l.c000066400000000000000000000010001513574234600177560ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswlower_l(wint_t c, locale_t locale) { (void)locale; #ifdef __MB_CAPABLE return __ctype_table_lookup(c, locale, CLASS_lower); #else return c < 0x100 ? islower(c) : 0; #endif /* __MB_CAPABLE */ } picolibc-1.8.11/libc/ctype/iswprint.c000066400000000000000000000051251513574234600174630ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---printable wide character test INDEX iswprint INDEX iswprint_l SYNOPSIS #include int iswprint(wint_t <[c]>); #include int iswprint_l(wint_t <[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which classifies wide-character values that are printable. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return non-zero if <[c]> is a printable wide character. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswprint(wint_t c) { #ifdef __MB_CAPABLE return __ctype_table_lookup(c, 0, CLASS_print); #else return c < (wint_t)0x100 ? isprint(c) : 0; #endif } picolibc-1.8.11/libc/ctype/iswprint_l.c000066400000000000000000000010101513574234600177630ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswprint_l(wint_t c, locale_t locale) { (void)locale; #ifdef __MB_CAPABLE return __ctype_table_lookup(c, locale, CLASS_print); #else return c < (wint_t)0x100 ? isprint(c) : 0; #endif /* __MB_CAPABLE */ } picolibc-1.8.11/libc/ctype/iswpunct.c000066400000000000000000000051331513574234600174570ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---punctuation wide character test INDEX iswpunct INDEX iswpunct_l SYNOPSIS #include int iswpunct(wint_t <[c]>); #include int iswpunct_l(wint_t <[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which classifies wide-character values that are punctuation. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return non-zero if <[c]> is a punctuation wide character. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswpunct(wint_t c) { #ifdef __MB_CAPABLE return __ctype_table_lookup(c, 0, CLASS_punct); #else return c < (wint_t)0x100 ? ispunct(c) : 0; #endif } picolibc-1.8.11/libc/ctype/iswpunct_l.c000066400000000000000000000010101513574234600177600ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswpunct_l(wint_t c, locale_t locale) { (void)locale; #ifdef __MB_CAPABLE return __ctype_table_lookup(c, locale, CLASS_punct); #else return c < (wint_t)0x100 ? ispunct(c) : 0; #endif /* __MB_CAPABLE */ } picolibc-1.8.11/libc/ctype/iswspace.c000066400000000000000000000050751513574234600174260ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---whitespace wide character test INDEX iswspace INDEX iswspace_l SYNOPSIS #include int iswspace(wint_t <[c]>); #include int iswspace_l(wint_t <[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which classifies wide-character values that are categorized as whitespace. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return non-zero if <[c]> is a whitespace wide character. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #define _DEFAULT_SOURCE #include #include int iswspace(wint_t c) { #ifdef __MB_CAPABLE return iswspace_l(c, 0); #else return c < (wint_t)0x100 ? isspace(c) : 0; #endif } picolibc-1.8.11/libc/ctype/iswspace_l.c000066400000000000000000000043211513574234600177320ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswspace_l(wint_t c, locale_t locale) { (void)locale; #ifdef __MB_CAPABLE /* * This is used by scanf, so avoid the table * to save space */ if (!__locale_is_C(locale)) { switch (c) { case 0x01680: case 0x02028: case 0x02029: case 0x0205f: case 0x03000: return 1; default: if (0x2000 <= c && c <= 0x200a && c != 0x2007) return 1; break; } } #endif /* __MB_CAPABLE */ return c < 0x100 ? isspace(c) : 0; } picolibc-1.8.11/libc/ctype/iswupper.c000066400000000000000000000050211513574234600174550ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---uppercase wide character test INDEX iswupper INDEX iswupper_l SYNOPSIS #include int iswupper(wint_t <[c]>); #include int iswupper_l(wint_t <[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which classifies wide-character values that are categorized as uppercase. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return non-zero if <[c]> is an uppercase wide character. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswupper(wint_t c) { #ifdef __MB_CAPABLE return __ctype_table_lookup(c, 0, CLASS_upper); #else return c < (wint_t)0x100 ? isupper(c) : 0; #endif } picolibc-1.8.11/libc/ctype/iswupper_l.c000066400000000000000000000010001513574234600177610ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #include #include "local.h" int iswupper_l(wint_t c, locale_t locale) { (void)locale; #ifdef __MB_CAPABLE return __ctype_table_lookup(c, locale, CLASS_upper); #else return c < 0x100 ? isupper(c) : 0; #endif /* __MB_CAPABLE */ } picolibc-1.8.11/libc/ctype/iswxdigit.c000066400000000000000000000047651513574234600176300ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---hexadecimal digit wide character test INDEX iswxdigit INDEX iswxdigit_l SYNOPSIS #include int iswxdigit(wint_t <[c]>); #include int iswxdigit_l(wint_t <[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which classifies wide character values that are hexadecimal digits. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return non-zero if <[c]> is a hexadecimal digit wide character. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #include int iswxdigit(wint_t c) { return (c >= (wint_t)'0' && c <= (wint_t)'9') || (c >= (wint_t)'a' && c <= (wint_t)'f') || (c >= (wint_t)'A' && c <= (wint_t)'F'); } picolibc-1.8.11/libc/ctype/iswxdigit_l.c000066400000000000000000000006151513574234600201310ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include int iswxdigit_l(wint_t c, locale_t locale) { (void)locale; return ((c >= (wint_t)'0' && c <= (wint_t)'9') || (c >= (wint_t)'a' && c <= (wint_t)'f') || (c >= (wint_t)'A' && c <= (wint_t)'F')); } picolibc-1.8.11/libc/ctype/isxdigit.c000066400000000000000000000055331513574234600174330ustar00rootroot00000000000000/* Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---hexadecimal digit predicate INDEX isxdigit INDEX isxdigit_l SYNOPSIS #include int isxdigit(int <[c]>); #include int isxdigit_l(int <[c]>, locale_t <[locale]>); DESCRIPTION <> is a macro which classifies singlebyte charset values by table lookup. It is a predicate returning non-zero for hexadecimal digits, and <<0>> for other characters. It is defined only if <[c]> is representable as an unsigned char or if <[c]> is EOF. <> is like <> but performs the check based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef isxdigit>>' or `<<#undef isxdigit_l>>'. RETURNS <>, <> return non-zero if <[c]> is a hexadecimal digit (<<0>>--<<9>>, <>--<>, or <>--<>). PORTABILITY <> is ANSI C. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #include #undef isxdigit int isxdigit(int c) { #if _PICOLIBC_CTYPE_SMALL return (isdigit(c) || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f')); #else return __CTYPE_PTR[c + 1] & ((__CTYPE_HEX) | (__CTYPE_DIGIT)); #endif } picolibc-1.8.11/libc/ctype/isxdigit_l.c000066400000000000000000000006221513574234600177400ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #undef isxdigit_l int isxdigit_l(int c, locale_t locale) { (void)locale; #if _PICOLIBC_CTYPE_SMALL return isxdigit(c); #else return __CTYPE_PTR_L(locale)[c + 1] & ((__CTYPE_HEX) | (__CTYPE_DIGIT)); #endif } picolibc-1.8.11/libc/ctype/local.h000066400000000000000000000105471513574234600167070ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Modified (m) 2017 Thomas Wolff: fixed locale/wchar handling */ /* wctrans constants */ #include #include #include #include #include "locale_private.h" /* valid values for wctrans_t */ #define WCT_TOLOWER 1 #define WCT_TOUPPER 2 #define CLASS_none 0 #define CLASS_alnum (1 << 0) #define CLASS_alpha (1 << 1) #define CLASS_blank (1 << 2) #define CLASS_cntrl (1 << 3) #define CLASS_digit (1 << 4) #define CLASS_graph (1 << 5) #define CLASS_lower (1 << 6) #define CLASS_print (1 << 7) #define CLASS_punct (1 << 8) #define CLASS_space (1 << 9) #define CLASS_upper (1 << 10) #define CLASS_xdigit (1 << 11) #define CLASS_case (1 << 12) #define CLASS_all ((1 << 13) - 1) extern const wctype_t _ctype_class[]; #ifdef __MB_CAPABLE wctype_t __ctype_table_lookup(wint_t ic, locale_t locale, wctype_t mask); #else static inline wctype_t __ctype_table_lookup(wint_t ic, locale_t locale, wctype_t mask) { (void)locale; if (ic >= (wint_t)0x100) return 0; return (_ctype_class + 1)[(int)(ic)] & mask; } #endif /* struct caseconv_entry describes the case conversion behaviour of a range of Unicode characters. It was designed to be compact for a minimal table size. The range is first...first + diff. Conversion behaviour for a character c in the respective range: mode == TOLO towlower (c) = c + delta mode == TOUP towupper (c) = c + delta mode == TOBOTH (titling case characters) towlower (c) = c + 1 towupper (c) = c - 1 mode == TO1 capital/small letters are alternating delta == EVENCAP even codes are capital delta == ODDCAP odd codes are capital (this correlates with an even/odd first range value as of Unicode 10.0 but we do not rely on this) As of Unicode 10.0, the following field lengths are sufficient first: 17 bits diff: 8 bits delta: 17 bits mode: 2 bits The reserve of 4 bits (to limit the struct to 6 bytes) is currently added to the 'first' field; should a future Unicode version make it necessary to expand the others, the 'first' field could be reduced as needed, or larger ranges could be split up (reduce limit max=255 e.g. to max=127 or max=63 in script mkcaseconv, check increasing table size). */ enum { TO1, TOLO, TOUP, TOBOTH }; enum { EVENCAP, ODDCAP }; struct caseconv_entry { uint_least32_t first : 21; uint_least32_t diff : 8; uint_least32_t mode : 2; #ifdef __MSP430__ /* * MSP430 has 20-bit integers which the compiler attempts to use and * fails. Waste some memory to fix that. */ int_least32_t delta; #else int_least32_t delta : 17; #endif } #ifdef __HAVE_BITFIELDS_IN_PACKED_STRUCTS __attribute__((packed)) #endif ; const struct caseconv_entry *__caseconv_lookup(wint_t c, locale_t locale); picolibc-1.8.11/libc/ctype/meson.build000066400000000000000000000063671513574234600176130ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_ctype = [ 'caseconv.c', 'ctype_.c', 'ctype_class.c', 'ctype_table.c', 'ctype_wide.c', 'isalnum.c', 'isalnum_l.c', 'isalpha.c', 'isalpha_l.c', 'isascii.c', 'isascii_l.c', 'isblank.c', 'isblank_l.c', 'iscntrl.c', 'iscntrl_l.c', 'isdigit.c', 'isdigit_l.c', 'isgraph.c', 'isgraph_l.c', 'islower.c', 'islower_l.c', 'isprint.c', 'isprint_l.c', 'ispunct.c', 'ispunct_l.c', 'isspace.c', 'isspace_l.c', 'isupper.c', 'isupper_l.c', 'iswalnum.c', 'iswalnum_l.c', 'iswalpha.c', 'iswalpha_l.c', 'iswblank.c', 'iswblank_l.c', 'iswcntrl.c', 'iswcntrl_l.c', 'iswctype.c', 'iswctype_l.c', 'iswdigit.c', 'iswdigit_l.c', 'iswgraph.c', 'iswgraph_l.c', 'iswlower.c', 'iswlower_l.c', 'iswprint.c', 'iswprint_l.c', 'iswpunct.c', 'iswpunct_l.c', 'iswspace.c', 'iswspace_l.c', 'iswupper.c', 'iswupper_l.c', 'iswxdigit.c', 'iswxdigit_l.c', 'isxdigit.c', 'isxdigit_l.c', 'toascii.c', 'toascii_l.c', 'tolower.c', 'tolower_l.c', 'toupper.c', 'toupper_l.c', 'towctrans.c', 'towctrans_l.c', 'towlower.c', 'towlower_l.c', 'towupper.c', 'towupper_l.c', 'wctrans.c', 'wctrans_l.c', 'wctype.c', 'wctype_l.c', ] srcs_ctype_use = [] foreach file : srcs_ctype s_file = fs.replace_suffix(file, '.S') if file in srcs_machine message('libc/ctype/' + file + ': machine overrides generic') elif s_file in srcs_machine message('libc/ctype/' + s_file + ': machine overrides generic') else srcs_ctype_use += file endif endforeach src_ctype = files(srcs_ctype_use) picolibc-1.8.11/libc/ctype/mkcaseconv000077500000000000000000000070031513574234600175140ustar00rootroot00000000000000#! /bin/sh -f # Copyright (c) 2018 Thomas Wolff # generate a table for Unicode case conversion; entries: # struct caseconv_entry defined in towctrans_l.c if [ -r UnicodeData.txt ] then UnicodeData=UnicodeData.txt elif [ -r /usr/share/unicode/ucd/UnicodeData.txt ] then UnicodeData=/usr/share/unicode/ucd/UnicodeData.txt else echo UnicodeData.txt not found >&2 exit 1 fi LC_ALL=C export LC_ALL compact=true #0041;LATIN CAPITAL LETTER A;Lu;0;L;;;;;N;;;;0061; #0061;LATIN SMALL LETTER A;Ll;0;L;;;;;N;;;0041;;0041 #0130;LATIN CAPITAL LETTER I WITH DOT ABOVE;Lu;0;L;0049 0307;;;;N;LATIN CAPITAL LETTER I DOT;;;0069; #01C4;LATIN CAPITAL LETTER DZ WITH CARON;Lu;0;L; 0044 017D;;;;N;LATIN CAPITAL LETTER D Z HACEK;;;01C6;01C5 #01C5;LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON;Lt;0;L; 0044 017E;;;;N;LATIN LETTER CAPITAL D SMALL Z HACEK;;01C4;01C6;01C5 #01C6;LATIN SMALL LETTER DZ WITH CARON;Ll;0;L; 0064 017E;;;;N;LATIN SMALL LETTER D Z HACEK;;01C4;;01C5 tr -d '\015' < $UnicodeData | sed \ -e 's,^\([^;]*\);[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;\([^;][^;]*\);\([^;]*\);\([^;]*\)$,src \1 upper "\2" lower "\3" title "\4",' \ -e t \ -e 's,^\([^;]*\);[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;\([^;]*\);\([^;][^;]*\);\([^;]*\)$,src \1 upper "\2" lower "\3" title "\4",' \ -e t \ -e 's,^\([^;]*\);[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;\([^;]*\);\([^;]*\);\([^;][^;]*\)$,src \1 upper "\2" lower "\3" title "\4",' \ -e t \ -e d | (#src 01C5 upper "01C4" lower "01C6" title "01C5" if $compact then ( cat <<\/EOS src () { if [ -n "$3" ] then tohi=$(( 0x0$3 - 0x0$1 )) else tohi=0 fi if [ -n "$5" ] then tolo=$(( 0x0$5 - 0x0$1 )) else tolo=0 fi case "$tolo.$tohi" in 0.0) true;; 0.*) case "$1.$tohi" in *[02468ACE].1) echo "'#error' U+$1 ODDSML";; *[02468ACE].-1) echo " 0x$1 TO1 ODDCAP";; *[13579BDF].1) echo "'#error' U+$1 EVENSML";; *[13579BDF].-1) echo " 0x$1 TO1 EVENCAP";; *) echo " 0x$1 TOUP $tohi";; esac;; *.0) case "$1.$tolo" in *[02468ACE].1) echo " 0x$1 TO1 EVENCAP";; *[02468ACE].-1) echo "'#error' U+$1 EVENSML";; *[13579BDF].1) echo " 0x$1 TO1 ODDCAP";; *[13579BDF].-1) echo "'#error' U+$1 ODDSML";; *) echo " 0x$1 TOLO $tolo";; esac;; *) case "$tolo.$tohi" in 1.-1) echo " 0x$1 TOBOTH 0";; *) echo "'#error' U+$1";; esac;; esac } /EOS cat ) | sh | uniq -f1 --group=append | sed -e "s,^$,range," -e t -e "s,^,item ," | ( cat <<\/EOS first= diff=-1 max=255 range () { # $diff == $(($last - $first)) if [ "$diff" -ge 0 ] then # we have items at all echo " {$first, $diff, $v2, $v3}," fi first= diff=-1 } item () { if [ "$1" = "#error" ] then echo "$*" return fi if [ $diff -eq $max ] then range elif [ -n "$first" ] then if [ $(( $1 )) -ne $(( ${last-0} + 1 )) ] then range fi fi if [ -z "$first" ] then first=$1 v2=$2 v3=$3 fi last=$1 diff=$(( $diff + 1 )) } /EOS cat ) | sh elif false then sed -e 's/src \([^ ]*\) upper "\([^ ]*\)" lower "\([^ ]*\)" title "\([^ ]*\)"/ {0x\1, 0x\2 - 0x\1, 0x\3 - 0x\1},/' \ -e 's/0x - 0x[^ ,}]*/0/g' -e 's/0x}/0}/' \ -e 's/\(0x[0-9A-F][0-9A-F]*\) - \(0x[0-9A-F][0-9A-F]*\)/$((`printf %d \1` - `printf %d \2`))/g' \ -e 's/^/echo "/' -e 's/$/"/' | sh else sed -e 's/src \([^ ]*\) upper "\([^ ]*\)" lower "\([^ ]*\)" title "\([^ ]*\)"/ {0x\1, 0x\2 - 0x\1, 0x\3 - 0x\1},/' \ -e 's/0x - 0x[^ ,}]*/0/g' -e 's/0x}/0}/' fi ) > caseconv.t picolibc-1.8.11/libc/ctype/mkcategories000077500000000000000000000037771513574234600200560ustar00rootroot00000000000000#! /bin/sh # Copyright (c) 2018 Thomas Wolff # generate table of Unicode character category ranges; # note: undefined characters between two characters of the same category # are associated to the same category, e.g. #0A0A;GURMUKHI LETTER UU;Lo #0A0B..0A0E -> Lo #0A0F;GURMUKHI LETTER EE;Lo if [ -r UnicodeData.txt ] then UnicodeData=UnicodeData.txt elif [ -r /usr/share/unicode/ucd/UnicodeData.txt ] then UnicodeData=/usr/share/unicode/ucd/UnicodeData.txt else echo UnicodeData.txt not found >&2 exit 1 fi # the code assumes foldall=false, foldcase=true foldall=false foldcase=true ( cat <<\/EOS first= item () { if [ -n "$first" ] then if [ "$2" != "isRangeLast" \ -a $(( 0x$1 )) -ne $(( 0x${last-0} + 1 )) ] then range fi fi if [ -z "$first" ] then first=$1 val=$3 fi last=$1 } range () { # echo " {0x$first, 0x$last, CAT_$val}," # echo " {0x$first, $((0x$last - 0x$first)), CAT_$val}," # echo " {0x$first | (CAT_$val << 24), $((0x$last - 0x$first))}," echo " {CAT_$val, 0x$first, $((0x$last - 0x$first))}," first= } /EOS cat "$UnicodeData" | if $foldall then sed -e "s,;L[lu];,;LC;," -e "s,;C[fs];,;Cfs;," \ -e "s,;L[mo];,;Lmo;," -e "s,;Nl;,;Lmo;," \ -e "s,;P.;,;P;," -e "s,;No;,;P;," \ -e "s,;S.;,;S;," -e "s,;Z[lp];,;Zlp;," \ -e "s,;C[no];,;X;," -e "s,;M[cen];,;M;," elif $foldcase then # fold Lu/Ll to LC only if lower/upper conversion is available sed -e '/^\([^;]*\);[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;\([^;]*\);\([^;][^;]*\);.*/ s/;Lu;/;LC;/' \ -e '/^\([^;]*\);[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;[^;]*;\([^;][^;]*\);\([^;]*\);.*/ s/;Ll;/;LC;/' \ -e '/;Co;/ d' else cat fi | sed -e "s,^\([^;]*\);<[^;]*\, Last>;\([^;]*\);.*,\1 isRangeLast \2," \ -e "s,^\([^;]*\);[^;]*;\([^;]*\);.*,\1 isNormalOrRangeFirst \2," | uniq -f2 --group=append | sed -e "s,^$,range," -e t -e "s,^,item ," ) | sh > categories.t sed -e "s/.*\(CAT_[A-Za-z]*\).*/ \1,/" categories.t | sort | uniq > categories.cat picolibc-1.8.11/libc/ctype/mkctype-extended.py000066400000000000000000000422751513574234600212730ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2025 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # ''' Translate Unicode data files into ctype data for ISO encodings ''' import copy import re class DerivedCoreProperty: def __init__(self, line): fields = line.split() codepoints = fields[0].split('..') self.first = int(codepoints[0], 16) if len(codepoints) > 1: self.last = int(codepoints[1], 16) else: self.last = self.first self.value = fields[2] class CodePoint: def case_value(self, field): if field: return int(field, 16) return self.code def __init__(self, line): fields = line.split(';') self.code = int(fields[0], 16) self.name = fields[1] self.category = fields[2] self.canonical_combining = fields[3] self.bidirectional = fields[4] self.decomposition = fields[5] self.decimal = fields[6] self.digit = fields[7] self.numeric = fields[8] self.mirrored = fields[9] self.name_1_0 = fields[10] self.comment = fields[11] self.uppercase = self.case_value(fields[12]) self.lowercase = self.case_value(fields[13]) self.titlecase = self.case_value(fields[14]) def new_code(self, code): new = copy.copy(self) new.code = code new.uppercase = code new.lowercase = code new.titlecase = code return new def load_derived_properties(name): ret = {} with open(name) as f: for line in f: line = line.strip() if re.search('^[0-9A-F]+.*;', line): d = DerivedCoreProperty(line) for c in range(d.first, d.last+1): if c not in ret: ret[c] = [] ret[c] += [d.value] return ret def derived_properties(code): global DerivedProperties if not code in DerivedProperties: return () return DerivedProperties[code] def load_unicode_data(name): ret = {} first = None with open(name) as file: for line in file: ud = CodePoint(line.strip()) if ud.category == 'Cs': continue match = re.fullmatch('<([^,]*), ([^>]*)>', ud.name) if match: if match.group(2) == 'First': first = ud first.name = match.group(1) elif match.group(2) == 'Last': if first: for code in range(first.code, ud.code+1): ret[code] = first.new_code(code) else: ret[ud.code] = ud return ret def to_upper(code): global CodePoints if code in CodePoints: return CodePoints[code].uppercase return code def to_lower(code): global CodePoints if code in CodePoints: return CodePoints[code].lowercase return code def is_alnum(code): return is_alpha(code) or is_digit(code) def is_alpha(code): global CodePoints if 'Alphabetic' in derived_properties(code): return True if code in CodePoints: cp = CodePoints[code] if cp.category == 'Nd' and not is_digit(code): return True return False def is_blank(code): global CodePoints # Tab if code == 0x0009: return True # Category is space separator except for no-break space if code in CodePoints: cp = CodePoints[code] if cp.category == 'Zs' and '' not in cp.decomposition: return True return False def is_cntrl(code): global CodePoints if code in CodePoints: cp = CodePoints[code] if not cp.name: return False # char name is if cp.name == '': return True # Line separator, paragraph separator if cp.category in ['Zl', 'Zp']: return True return False def is_digit(code): # C says only the ASCII digits need apply here return 0x0030 <= code and code <= 0x0039 def is_graph(code): global CodePoints if code in CodePoints: cp = CodePoints[code] if not cp.name: return False if cp.name == '': return False return not is_space(code) return False def is_lower(code): if to_upper(code) != code: return True if 'Lowercase' in derived_properties(code): return True return False def is_print(code): global CodePoints if code in CodePoints: cp = CodePoints[code] if not cp.name: return False if cp.name == '': return False if cp.category not in ['Zl', 'Zp']: return True return False def is_punct(code): return is_graph(code) and not is_alpha(code) and not is_digit(code) def is_space(code): global CodePoints # ASCII blanks if code in [0x0020, 0x000c, 0x000a, 0x000d, 0x0009, 0x000b]: return True # Line separator, paragraph separator if code in CodePoints: cp = CodePoints[code] if cp.name and cp.category in ['Zl', 'Zp']: return True # Space separator, but not no-break space if cp.name and cp.category == 'Zs' and '' not in cp.decomposition: return True return False def is_upper(code): if to_lower(code) != code: return True if 'Uppercase' in derived_properties(code): return True return False def is_xdigit(code): if is_digit(code): return True # Upper case A-F if 0x0041 <= code and code <= 0x0046: return True # Lower case a-f if 0x0061 <= code and code <= 0x0066: return True return False def classes(code): ret = "" add = "" if is_upper(code): ret += add + '_U' add = '|' elif is_lower(code): ret += add + '_L' add = '|' elif is_alpha(code): ret += add + '_U|_L' add = '|' if is_digit(code): ret += add + '_N' add = '|' if is_space(code): ret += add + '_S' add = '|' if is_punct(code): ret += add + '_P' add = '|' if is_cntrl(code): ret += add + '_C' add = '|' if is_xdigit(code) and not is_digit(code): ret += add + '_X' add = '|' if is_blank(code) and code != 0x0009: ret += add + '_B' add = '|' if not ret: ret = ' 0' return ret georgian_ps = { 0x00: 0x0000, 0x01: 0x0001, 0x02: 0x0002, 0x03: 0x0003, 0x04: 0x0004, 0x05: 0x0005, 0x06: 0x0006, 0x07: 0x0007, 0x08: 0x0008, 0x09: 0x0009, 0x0a: 0x000A, 0x0b: 0x000B, 0x0c: 0x000C, 0x0d: 0x000D, 0x0e: 0x000E, 0x0f: 0x000F, 0x10: 0x0010, 0x11: 0x0011, 0x12: 0x0012, 0x13: 0x0013, 0x14: 0x0014, 0x15: 0x0015, 0x16: 0x0016, 0x17: 0x0017, 0x18: 0x0018, 0x19: 0x0019, 0x1a: 0x001A, 0x1b: 0x001B, 0x1c: 0x001C, 0x1d: 0x001D, 0x1e: 0x001E, 0x1f: 0x001F, 0x20: 0x0020, 0x21: 0x0021, 0x22: 0x0022, 0x23: 0x0023, 0x24: 0x0024, 0x25: 0x0025, 0x26: 0x0026, 0x27: 0x0027, 0x28: 0x0028, 0x29: 0x0029, 0x2a: 0x002A, 0x2b: 0x002B, 0x2c: 0x002C, 0x2d: 0x002D, 0x2e: 0x002E, 0x2f: 0x002F, 0x30: 0x0030, 0x31: 0x0031, 0x32: 0x0032, 0x33: 0x0033, 0x34: 0x0034, 0x35: 0x0035, 0x36: 0x0036, 0x37: 0x0037, 0x38: 0x0038, 0x39: 0x0039, 0x3a: 0x003A, 0x3b: 0x003B, 0x3c: 0x003C, 0x3d: 0x003D, 0x3e: 0x003E, 0x3f: 0x003F, 0x40: 0x0040, 0x41: 0x0041, 0x42: 0x0042, 0x43: 0x0043, 0x44: 0x0044, 0x45: 0x0045, 0x46: 0x0046, 0x47: 0x0047, 0x48: 0x0048, 0x49: 0x0049, 0x4a: 0x004A, 0x4b: 0x004B, 0x4c: 0x004C, 0x4d: 0x004D, 0x4e: 0x004E, 0x4f: 0x004F, 0x50: 0x0050, 0x51: 0x0051, 0x52: 0x0052, 0x53: 0x0053, 0x54: 0x0054, 0x55: 0x0055, 0x56: 0x0056, 0x57: 0x0057, 0x58: 0x0058, 0x59: 0x0059, 0x5a: 0x005A, 0x5b: 0x005B, 0x5c: 0x005C, 0x5d: 0x005D, 0x5e: 0x005E, 0x5f: 0x005F, 0x60: 0x0060, 0x61: 0x0061, 0x62: 0x0062, 0x63: 0x0063, 0x64: 0x0064, 0x65: 0x0065, 0x66: 0x0066, 0x67: 0x0067, 0x68: 0x0068, 0x69: 0x0069, 0x6a: 0x006A, 0x6b: 0x006B, 0x6c: 0x006C, 0x6d: 0x006D, 0x6e: 0x006E, 0x6f: 0x006F, 0x70: 0x0070, 0x71: 0x0071, 0x72: 0x0072, 0x73: 0x0073, 0x74: 0x0074, 0x75: 0x0075, 0x76: 0x0076, 0x77: 0x0077, 0x78: 0x0078, 0x79: 0x0079, 0x7a: 0x007A, 0x7b: 0x007B, 0x7c: 0x007C, 0x7d: 0x007D, 0x7e: 0x007E, 0x7f: 0x007F, 0x80: 0x0080, 0x81: 0x0081, 0x82: 0x201A, 0x83: 0x0192, 0x84: 0x201E, 0x85: 0x2026, 0x86: 0x2020, 0x87: 0x2021, 0x88: 0x02C6, 0x89: 0x2030, 0x8a: 0x0160, 0x8b: 0x2039, 0x8c: 0x0152, 0x8d: 0x008D, 0x8e: 0x008E, 0x8f: 0x008F, 0x90: 0x0090, 0x91: 0x2018, 0x92: 0x2019, 0x93: 0x201C, 0x94: 0x201D, 0x95: 0x2022, 0x96: 0x2013, 0x97: 0x2014, 0x98: 0x02DC, 0x99: 0x2122, 0x9a: 0x0161, 0x9b: 0x203A, 0x9c: 0x0153, 0x9d: 0x009D, 0x9e: 0x009E, 0x9f: 0x0178, 0xa0: 0x00A0, 0xa1: 0x00A1, 0xa2: 0x00A2, 0xa3: 0x00A3, 0xa4: 0x00A4, 0xa5: 0x00A5, 0xa6: 0x00A6, 0xa7: 0x00A7, 0xa8: 0x00A8, 0xa9: 0x00A9, 0xaa: 0x00AA, 0xab: 0x00AB, 0xac: 0x00AC, 0xad: 0x00AD, 0xae: 0x00AE, 0xaf: 0x00AF, 0xb0: 0x00B0, 0xb1: 0x00B1, 0xb2: 0x00B2, 0xb3: 0x00B3, 0xb4: 0x00B4, 0xb5: 0x00B5, 0xb6: 0x00B6, 0xb7: 0x00B7, 0xb8: 0x00B8, 0xb9: 0x00B9, 0xba: 0x00BA, 0xbb: 0x00BB, 0xbc: 0x00BC, 0xbd: 0x00BD, 0xbe: 0x00BE, 0xbf: 0x00BF, 0xc0: 0x10D0, 0xc1: 0x10D1, 0xc2: 0x10D2, 0xc3: 0x10D3, 0xc4: 0x10D4, 0xc5: 0x10D5, 0xc6: 0x10D6, 0xc7: 0x10F1, 0xc8: 0x10D7, 0xc9: 0x10D8, 0xca: 0x10D9, 0xcb: 0x10DA, 0xcc: 0x10DB, 0xcd: 0x10DC, 0xce: 0x10F2, 0xcf: 0x10DD, 0xd0: 0x10DE, 0xd1: 0x10DF, 0xd2: 0x10E0, 0xd3: 0x10E1, 0xd4: 0x10E2, 0xd5: 0x10F3, 0xd6: 0x10E3, 0xd7: 0x10E4, 0xd8: 0x10E5, 0xd9: 0x10E6, 0xda: 0x10E7, 0xdb: 0x10E8, 0xdc: 0x10E9, 0xdd: 0x10EA, 0xde: 0x10EB, 0xdf: 0x10EC, 0xe0: 0x10ED, 0xe1: 0x10EE, 0xe2: 0x10F4, 0xe3: 0x10EF, 0xe4: 0x10F0, 0xe5: 0x10F5, 0xe6: 0x00E6, 0xe7: 0x00E7, 0xe8: 0x00E8, 0xe9: 0x00E9, 0xea: 0x00EA, 0xeb: 0x00EB, 0xec: 0x00EC, 0xed: 0x00ED, 0xee: 0x00EE, 0xef: 0x00EF, 0xf0: 0x00F0, 0xf1: 0x00F1, 0xf2: 0x00F2, 0xf3: 0x00F3, 0xf4: 0x00F4, 0xf5: 0x00F5, 0xf6: 0x00F6, 0xf7: 0x00F7, 0xf8: 0x00F8, 0xf9: 0x00F9, 0xfa: 0x00FA, 0xfb: 0x00FB, 0xfc: 0x00FC, 0xfd: 0x00FD, 0xfe: 0x00FE, 0xff: 0x00FF, } def print_classes(code, encoding, comma): c = classes(code) try: if encoding == 'GEORGIAN-PS': ucode = georgian_ps[code] elif encoding == 'EUC-JP': if 0x80 <= code <= 0x8d or 0x90 <= code <= 0x9f: ucode = code else: ucode = ord(bytes([code]).decode(encoding)) else: ucode = ord(bytes([code]).decode(encoding)) c = classes(ucode) except: ucode = 0 c = ' 0' if comma == '\n': end='' elif code & 7 == 7: end = ' \\\n' else: end = ' ' * (8 - len(c)) if code & 7 == 0: print(' ', end='') print('%s%s' % (c, comma), end=end) def dump_range(title, encoding, start, end): print(title, end='') for code in range(start, end + 1): if code == end: comma = '\n' else: comma = ',' print_classes(code, encoding, comma) def dump_table(): global prev_above print('''/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This file is auto-generated from mkctype-extended.py */ /* clang-format off */ ''') # for val in (10,): # encoding = 'iso8859-%d' % val # define = '#define _CTYPE_ISO_8859_%d_' % val # dump_range(define + '128_254 \\\n', encoding, 128, 254) # dump_range(define + '255 ', encoding, 255, 255) # return for val in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16): encoding = 'iso8859-%d' % val define = '#define _CTYPE_ISO_8859_%d_' % val dump_range(define + '128_254 \\\n', encoding, 128, 254) dump_range(define + '255 ', encoding, 255, 255) dump_range('#define _CTYPE_SJIS_128_254 \\\n', 'SHIFT-JIS', 128, 254) dump_range('#define _CTYPE_SJIS_255 ', 'SHIFT-JIS', 255, 255) dump_range('#define _CTYPE_EUCJP_128_254 \\\n', 'EUC-JP', 128, 254) dump_range('#define _CTYPE_EUCJP_255 ', 'EUC-JP', 255, 255) for cp in ('CP101', 'CP102', 'CP103', 'CP437', 'CP720', 'CP737', 'CP775', 'CP850', 'CP852', 'CP855', 'CP857', 'CP858', 'CP862', 'CP866', 'CP874', 'CP1125', 'CP1250', 'CP1251', 'CP1252', 'CP1253', 'CP1254', 'CP1255', 'CP1256', 'CP1257', 'CP1258', 'CP20866', 'CP21866'): if cp == 'CP101': encoding = 'GEORGIAN-PS' elif cp == 'CP102': encoding = 'PT154' elif cp == 'CP103': encoding = 'KOI8-T' elif cp == 'CP20866': encoding = 'KOI8-R' elif cp == 'CP21866': encoding = 'KOI8-U' else: encoding = cp if cp == 'CP101': name = 'GEORGIAN_PS' elif cp == 'CP102': name = 'PT154' elif cp == 'CP103': name = 'KOI8_T' elif cp == 'CP20866': name = 'KOI8_R' elif cp == 'CP21866': name = 'KOI8_U' else: name = cp define = '#define _CTYPE_%s_' % name dump_range(define + '128_254 \\\n', encoding, 128, 254) dump_range(define + '255 ', encoding, 255, 255) DerivedProperties = load_derived_properties('/usr/share/unicode/DerivedCoreProperties.txt') CodePoints = load_unicode_data('/usr/share/unicode/UnicodeData.txt') dump_table() picolibc-1.8.11/libc/ctype/mkctype.py000066400000000000000000000257631513574234600175000ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2024 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # ''' Translate Unicode data files into ctype data ''' import copy import re class DerivedCoreProperty: def __init__(self, line): fields = line.split() codepoints = fields[0].split('..') self.first = int(codepoints[0], 16) if len(codepoints) > 1: self.last = int(codepoints[1], 16) else: self.last = self.first self.value = fields[2] class CodePoint: def case_value(self, field): if field: return int(field, 16) return self.code def __init__(self, line): fields = line.split(';') self.code = int(fields[0], 16) self.name = fields[1] self.category = fields[2] self.canonical_combining = fields[3] self.bidirectional = fields[4] self.decomposition = fields[5] self.decimal = fields[6] self.digit = fields[7] self.numeric = fields[8] self.mirrored = fields[9] self.name_1_0 = fields[10] self.comment = fields[11] self.uppercase = self.case_value(fields[12]) self.lowercase = self.case_value(fields[13]) self.titlecase = self.case_value(fields[14]) def new_code(self, code): new = copy.copy(self) new.code = code new.uppercase = code new.lowercase = code new.titlecase = code return new def load_derived_properties(name): ret = {} with open(name) as f: for line in f: line = line.strip() if re.search('^[0-9A-F]+.*;', line): d = DerivedCoreProperty(line) for c in range(d.first, d.last+1): if c not in ret: ret[c] = [] ret[c] += [d.value] return ret def derived_properties(code): global DerivedProperties if not code in DerivedProperties: return () return DerivedProperties[code] def load_unicode_data(name): ret = {} first = None with open(name) as file: for line in file: ud = CodePoint(line.strip()) if ud.category == 'Cs': continue match = re.fullmatch('<([^,]*), ([^>]*)>', ud.name) if match: if match.group(2) == 'First': first = ud first.name = match.group(1) elif match.group(2) == 'Last': if first: for code in range(first.code, ud.code+1): ret[code] = first.new_code(code) else: ret[ud.code] = ud return ret def to_upper(code): global CodePoints if code in CodePoints: return CodePoints[code].uppercase return code def to_lower(code): global CodePoints if code in CodePoints: return CodePoints[code].lowercase return code def is_alnum(code): return is_alpha(code) or is_digit(code) def is_alpha(code): global CodePoints if 'Alphabetic' in derived_properties(code): return True if code in CodePoints: cp = CodePoints[code] if cp.category == 'Nd' and not is_digit(code): return True return False def is_blank(code): global CodePoints # Tab if code == 0x0009: return True # Category is space separator except for no-break space if code in CodePoints: cp = CodePoints[code] if cp.category == 'Zs' and '' not in cp.decomposition: return True return False def is_cntrl(code): global CodePoints if code in CodePoints: cp = CodePoints[code] if not cp.name: return False # char name is if cp.name == '': return True # Line separator, paragraph separator if cp.category in ['Zl', 'Zp']: return True return False def is_digit(code): # C says only the ASCII digits need apply here return 0x0030 <= code and code <= 0x0039 def is_graph(code): global CodePoints if code in CodePoints: cp = CodePoints[code] if not cp.name: return False if cp.name == '': return False return not is_space(code) return False def is_lower(code): if to_upper(code) != code: return True if 'Lowercase' in derived_properties(code): return True return False def is_print(code): global CodePoints if code in CodePoints: cp = CodePoints[code] if not cp.name: return False if cp.name == '': return False if cp.category not in ['Zl', 'Zp']: return True return False def is_punct(code): return is_graph(code) and not is_alpha(code) and not is_digit(code) def is_space(code): global CodePoints # ASCII blanks if code in [0x0020, 0x000c, 0x000a, 0x000d, 0x0009, 0x000b]: return True # Line separator, paragraph separator if code in CodePoints: cp = CodePoints[code] if cp.name and cp.category in ['Zl', 'Zp']: return True # Space separator, but not no-break space if cp.name and cp.category == 'Zs' and '' not in cp.decomposition: return True return False def is_upper(code): if to_lower(code) != code: return True if 'Uppercase' in derived_properties(code): return True return False def is_xdigit(code): if is_digit(code): return True # Upper case A-F if 0x0041 <= code and code <= 0x0046: return True # Lower case a-f if 0x0061 <= code and code <= 0x0066: return True return False def classes(code): ret = () if is_alnum(code): ret += ('alnum',) if is_alpha(code): ret += ('alpha',) if is_blank(code): ret += ('blank',) if is_cntrl(code): ret += ('cntrl',) if is_digit(code): ret += ('digit',) if is_graph(code): ret += ('graph',) if is_print(code): ret += ('print',) if is_punct(code): ret += ('punct',) if is_space(code): ret += ('space',) if is_lower(code): if to_upper(code) != code: ret += ('case',) else: ret += ('lower',) if is_upper(code): if to_lower(code) != code: ret += ('case',) else: ret += ('upper',) if is_xdigit(code): ret += ('xdigit',) return ret def classes_name(classes): ret = "" add = "" for c in classes: ret += add + 'CLASS_' + c add = "|" if not ret: ret = "CLASS_none" return ret prev_above = 0 def dump_result(code, above, classes): global prev_above if classes: if prev_above < code: print('{ 0x%04x, CLASS_none },' % prev_above) name = classes_name(classes) print('{ 0x%04x, %s },' % (code, name)) prev_above = above def dump_table(): global prev_above print('''/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This file is auto-generated from mkctype.py */ /* clang-format off */ ''') prev_above = 1 prev_c = None for code in range(0, 0x10000): c = classes(code) if c != prev_c: if prev_c: dump_result(first, code, prev_c) first = code prev_c = c code += 1 print('#if __SIZEOF_WCHAR_T__ == 2') if prev_above < code: print('{ 0x%04x, CLASS_none },' % prev_above) print('#else') for code in range(0x10000, 0xe01f0): c = classes(code) if c != prev_c: if prev_c: dump_result(first, code, prev_c) first = code prev_c = c code += 1 dump_result(first, code, c) print('{ 0x%04x, CLASS_none },' % code) print('#endif') DerivedProperties = load_derived_properties('/usr/share/unicode/DerivedCoreProperties.txt') CodePoints = load_unicode_data('/usr/share/unicode/UnicodeData.txt') dump_table() picolibc-1.8.11/libc/ctype/mkctype_class.py000066400000000000000000000244701513574234600206570ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2024 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # ''' Translate Unicode data files into ctype data ''' import copy import re class DerivedCoreProperty: def __init__(self, line): fields = line.split() codepoints = fields[0].split('..') self.first = int(codepoints[0], 16) if len(codepoints) > 1: self.last = int(codepoints[1], 16) else: self.last = self.first self.value = fields[2] class CodePoint: def case_value(self, field): if field: return int(field, 16) return self.code def __init__(self, line): fields = line.split(';') self.code = int(fields[0], 16) self.name = fields[1] self.category = fields[2] self.canonical_combining = fields[3] self.bidirectional = fields[4] self.decomposition = fields[5] self.decimal = fields[6] self.digit = fields[7] self.numeric = fields[8] self.mirrored = fields[9] self.name_1_0 = fields[10] self.comment = fields[11] self.uppercase = self.case_value(fields[12]) self.lowercase = self.case_value(fields[13]) self.titlecase = self.case_value(fields[14]) def new_code(self, code): new = copy.copy(self) new.code = code new.uppercase = code new.lowercase = code new.titlecase = code return new def load_derived_properties(name): ret = {} with open(name) as f: for line in f: line = line.strip() if re.search('^[0-9A-F]+.*;', line): d = DerivedCoreProperty(line) for c in range(d.first, d.last+1): if c not in ret: ret[c] = [] ret[c] += [d.value] return ret def derived_properties(code): global DerivedProperties if not code in DerivedProperties: return () return DerivedProperties[code] def load_unicode_data(name): ret = {} first = None with open(name) as file: for line in file: ud = CodePoint(line.strip()) if ud.category == 'Cs': continue match = re.fullmatch('<([^,]*), ([^>]*)>', ud.name) if match: if match.group(2) == 'First': first = ud first.name = match.group(1) elif match.group(2) == 'Last': if first: for code in range(first.code, ud.code+1): ret[code] = first.new_code(code) else: ret[ud.code] = ud return ret def to_upper(code): global CodePoints if code in CodePoints: return CodePoints[code].uppercase return code def to_lower(code): global CodePoints if code in CodePoints: return CodePoints[code].lowercase return code def is_alnum(code): return is_alpha(code) or is_digit(code) def is_alpha(code): global CodePoints if 'Alphabetic' in derived_properties(code): return True if code in CodePoints: cp = CodePoints[code] if cp.category == 'Nd' and not is_digit(code): return True return False def is_blank(code): global CodePoints # Tab if code == 0x0009: return True # Category is space separator except for no-break space if code in CodePoints: cp = CodePoints[code] if cp.category == 'Zs' and '' not in cp.decomposition: return True return False def is_cntrl(code): global CodePoints if code in CodePoints: cp = CodePoints[code] if not cp.name: return False # char name is if cp.name == '': return True # Line separator, paragraph separator if cp.category in ['Zl', 'Zp']: return True return False def is_digit(code): # C says only the ASCII digits need apply here return 0x0030 <= code and code <= 0x0039 def is_graph(code): global CodePoints if code in CodePoints: cp = CodePoints[code] if not cp.name: return False if cp.name == '': return False return not is_space(code) return False def is_lower(code): if to_upper(code) != code: return True if 'Lowercase' in derived_properties(code): return True return False def is_print(code): global CodePoints if code in CodePoints: cp = CodePoints[code] if not cp.name: return False if cp.name == '': return False if cp.category not in ['Zl', 'Zp']: return True return False def is_punct(code): return is_graph(code) and not is_alpha(code) and not is_digit(code) def is_space(code): global CodePoints # ASCII blanks if code in [0x0020, 0x000c, 0x000a, 0x000d, 0x0009, 0x000b]: return True # Line separator, paragraph separator if code in CodePoints: cp = CodePoints[code] if cp.name and cp.category in ['Zl', 'Zp']: return True # Space separator, but not no-break space if cp.name and cp.category == 'Zs' and '' not in cp.decomposition: return True return False def is_upper(code): if to_lower(code) != code: return True if 'Uppercase' in derived_properties(code): return True return False def is_xdigit(code): if is_digit(code): return True # Upper case A-F if 0x0041 <= code and code <= 0x0046: return True # Lower case a-f if 0x0061 <= code and code <= 0x0066: return True return False def classes(code): ret = () if is_alnum(code): ret += ('alnum',) if is_alpha(code): ret += ('alpha',) if is_blank(code): ret += ('blank',) if is_cntrl(code): ret += ('cntrl',) if is_digit(code): ret += ('digit',) if is_graph(code): ret += ('graph',) if is_print(code): ret += ('print',) if is_punct(code): ret += ('punct',) if is_space(code): ret += ('space',) if is_lower(code): ret += ('lower',) if is_upper(code): ret += ('upper',) if is_xdigit(code): ret += ('xdigit',) return ret def classes_name(classes): ret = "" add = "" for c in classes: ret += add + 'CLASS_' + c add = "|" if not ret: ret = "CLASS_none" return ret prev_above = 0 def dump_result(code, above, classes): global prev_above if classes: if prev_above < code: print('{ 0x%04x, CLASS_none },' % prev_above) name = classes_name(classes) print('{ 0x%04x, %s },' % (code, name)) prev_above = above def dump_table(): global prev_above print('''/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2026 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This file is auto-generated from mkctype_class.py */ /* clang-format off */ ''') prev_above = 1 prev_c = None for code in range(0, 0x80): c = classes(code) name = classes_name(c) print(' /* 0x%02x */ %s,' % (code, name)) DerivedProperties = load_derived_properties('/usr/share/unicode/DerivedCoreProperties.txt') CodePoints = load_unicode_data('/usr/share/unicode/UnicodeData.txt') dump_table() picolibc-1.8.11/libc/ctype/mkunidata000077500000000000000000000027541513574234600173500ustar00rootroot00000000000000#! /bin/sh # Copyright (c) 2018 Thomas Wolff echo Generating Unicode character properties data for libc/ctype cd `dirname $0` ############################################################################# # checks and (with option -u) download case "$1" in -h) echo "Usage: $0 [-h|-u|-i]" echo "Generate case conversion table caseconv.t and character category table categories.t" echo "from local Unicode file UnicodeData.txt." echo "" echo "Options:" echo " -u download file from unicode.org first" echo " -i copy file from /usr/share/unicode/ucd first" echo " -h show this" exit ;; -u) wget () { ref=`basename $1` ref=`ls "$ref" 2> /dev/null || echo 01-Jan-1970` curl -R -O --connect-timeout 55 -z "$ref" "$1" } echo downloading data from unicode.org for data in UnicodeData.txt do wget http://unicode.org/Public/UNIDATA/$data done ;; -i) echo copying data from /usr/share/unicode/ucd for data in UnicodeData.txt do cp /usr/share/unicode/ucd/$data . done ;; esac echo checking Unicode data file for data in UnicodeData.txt do if [ -r $data ] then true else echo $data not available, skipping table generation exit fi done ############################################################################# # table generation echo generating character category table for "isw*.c" sh ./mkcategories echo generating case conversion table for "tow*.c" sh ./mkcaseconv ############################################################################# # end picolibc-1.8.11/libc/ctype/toascii.c000066400000000000000000000050541513574234600172400ustar00rootroot00000000000000/* Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---force integers to ASCII range INDEX toascii INDEX toascii_l SYNOPSIS #include int toascii(int <[c]>); #include int toascii_l(int <[c]>, locale_t <[locale]>); DESCRIPTION <> is a macro which coerces integers to the ASCII range (0--127) by zeroing any higher-order bits. <> is like <> but performs the function based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. You can use a compiled subroutine instead of the macro definition by undefining this macro using `<<#undef toascii>>' or `<<#undef toascii_l>>'. RETURNS <>, <> return integers between 0 and 127. PORTABILITY <> is X/Open, BSD and POSIX-1.2001, but marked obsolete in POSIX-1.2008. <> is a GNU extension. No supporting OS subroutines are required. */ #define _GNU_SOURCE #include #undef toascii int toascii(int c) { return (c) & 0177; } picolibc-1.8.11/libc/ctype/toascii_l.c000066400000000000000000000004311513574234600175450ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #undef toascii_l int toascii_l(int c, locale_t locale) { (void)locale; return c & 0177; } picolibc-1.8.11/libc/ctype/tolower.c000066400000000000000000000073021513574234600172760ustar00rootroot00000000000000/* Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---translate characters to lowercase INDEX tolower INDEX tolower_l INDEX _tolower SYNOPSIS #include int tolower(int <[c]>); int _tolower(int <[c]>); #include int tolower_l(int <[c]>, locale_t <[locale]>); DESCRIPTION <> is a macro which converts uppercase characters to lowercase, leaving all other characters unchanged. It is only defined when <[c]> is an integer in the range <> to <<255>>. <> is like <> but performs the function based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. You can use a compiled subroutine instead of the macro definition by undefining this macro using `<<#undef tolower>>' or `<<#undef tolower_l>>'. <<_tolower>> performs the same conversion as <>, but should only be used when <[c]> is known to be an uppercase character (<>--<>). RETURNS <>, <> return the lowercase equivalent of <[c]> when <[c]> is an uppercase character, and <[c]> otherwise. <<_tolower>> returns the lowercase equivalent of <[c]> when it is a character between <> and <>. If <[c]> is not one of these characters, the behaviour of <<_tolower>> is undefined. PORTABILITY <> is ANSI C. <<_tolower>> is not recommended for portable programs. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #include #if defined(__MB_EXTENDED_CHARSETS_ISO) || defined(__MB_EXTENDED_CHARSETS_WINDOWS) #include #include #include #include #include #endif #undef tolower int tolower(int c) { #if defined(__MB_EXTENDED_CHARSETS_ISO) || defined(__MB_EXTENDED_CHARSETS_WINDOWS) if ((unsigned char)c <= 0x7f) return isupper(c) ? c - 'A' + 'a' : c; else if (c != EOF && MB_CUR_MAX == 1 && isupper(c)) { char s[MB_LEN_MAX] = { c, '\0' }; wchar_t wc; if (mbtowc(&wc, s, 1) >= 0 && wctomb(s, (wchar_t)towlower((wint_t)wc)) == 1) c = (unsigned char)s[0]; } return c; #else return isupper(c) ? (c) - 'A' + 'a' : c; #endif } picolibc-1.8.11/libc/ctype/tolower_l.c000066400000000000000000000021251513574234600176070ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #if defined(__MB_EXTENDED_CHARSETS_ISO) || defined(__MB_EXTENDED_CHARSETS_WINDOWS) #include #include #include #include #include #include "locale_private.h" #endif int tolower_l(int c, locale_t locale) { #if defined(__MB_EXTENDED_CHARSETS_ISO) || defined(__MB_EXTENDED_CHARSETS_WINDOWS) if ((unsigned char)c <= 0x7f) return isupper_l(c, locale) ? c - 'A' + 'a' : c; else if (c != EOF && __locale_mb_cur_max_l(locale) == 1 && isupper_l(c, locale)) { char s[MB_LEN_MAX] = { c, '\0' }; wchar_t wc; mbstate_t state; memset(&state, 0, sizeof state); if (__MBTOWC_L(locale)(&wc, s, 1, &state) >= 0 && __WCTOMB_L(locale)(s, (wchar_t)towlower_l((wint_t)wc, locale), &state) == 1) c = (unsigned char)s[0]; } return c; #else return isupper_l(c, locale) ? (c) - 'A' + 'a' : c; #endif } picolibc-1.8.11/libc/ctype/toupper.c000066400000000000000000000072761513574234600173130ustar00rootroot00000000000000/* Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---translate characters to uppercase INDEX toupper INDEX toupper_l INDEX _toupper SYNOPSIS #include int toupper(int <[c]>); int _toupper(int <[c]>); #include int toupper_l(int <[c]>, locale_t <[locale]>); DESCRIPTION <> is a macro which converts lowercase characters to uppercase, leaving all other characters unchanged. It is only defined when <[c]> is an integer in the range <> to <<255>>. <> is like <> but performs the function based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. You can use a compiled subroutine instead of the macro definition by undefining this macro using `<<#undef toupper>>' or `<<#undef toupper_l>>'. <<_toupper>> performs the same conversion as <>, but should only be used when <[c]> is known to be a lowercase character (<>--<>). RETURNS <>, <> return the uppercase equivalent of <[c]> when <[c]> is a lowercase character, and <[c]> otherwise. <<_toupper>> returns the uppercase equivalent of <[c]> when it is a character between <> and <>. If <[c]> is not one of these characters, the behaviour of <<_toupper>> is undefined. PORTABILITY <> is ANSI C. <<_toupper>> is not recommended for portable programs. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #include #if defined(__MB_EXTENDED_CHARSETS_ISO) || defined(__MB_EXTENDED_CHARSETS_WINDOWS) #include #include #include #include #include #endif #undef toupper int toupper(int c) { #if defined(__MB_EXTENDED_CHARSETS_ISO) || defined(__MB_EXTENDED_CHARSETS_WINDOWS) if ((unsigned char)c <= 0x7f) return islower(c) ? c - 'a' + 'A' : c; else if (c != EOF && MB_CUR_MAX == 1 && islower(c)) { char s[MB_LEN_MAX] = { c, '\0' }; wchar_t wc; if (mbtowc(&wc, s, 1) >= 0 && wctomb(s, (wchar_t)towupper((wint_t)wc)) == 1) c = (unsigned char)s[0]; } return c; #else return islower(c) ? c - 'a' + 'A' : c; #endif } picolibc-1.8.11/libc/ctype/toupper_l.c000066400000000000000000000021231513574234600176100ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #if defined(__MB_EXTENDED_CHARSETS_ISO) || defined(__MB_EXTENDED_CHARSETS_WINDOWS) #include #include #include #include #include #include "locale_private.h" #endif int toupper_l(int c, locale_t locale) { #if defined(__MB_EXTENDED_CHARSETS_ISO) || defined(__MB_EXTENDED_CHARSETS_WINDOWS) if ((unsigned char)c <= 0x7f) return islower_l(c, locale) ? c - 'a' + 'A' : c; else if (c != EOF && __locale_mb_cur_max_l(locale) == 1 && islower_l(c, locale)) { char s[MB_LEN_MAX] = { c, '\0' }; wchar_t wc; mbstate_t state; memset(&state, 0, sizeof state); if (__MBTOWC_L(locale)(&wc, s, 1, &state) >= 0 && __WCTOMB_L(locale)(s, (wchar_t)towupper_l((wint_t)wc, locale), &state) == 1) c = (unsigned char)s[0]; } return c; #else return islower_l(c, locale) ? c - 'a' + 'A' : c; #endif } picolibc-1.8.11/libc/ctype/towctrans.c000066400000000000000000000054051513574234600176310ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---extensible wide-character translation INDEX towctrans INDEX towctrans_l SYNOPSIS #include wint_t towctrans(wint_t <[c]>, wctrans_t <[w]>); #include wint_t towctrans_l(wint_t <[c]>, wctrans_t <[w]>, locale_t <[locale]>); DESCRIPTION <> is a function which converts wide characters based on a specified translation type <[w]>. If the translation type is invalid or cannot be applied to the current character, no change to the character is made. <> is like <> but performs the function based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return the translated equivalent of <[c]> when it is a valid for the given translation, otherwise, it returns the input character. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #define _DEFAULT_SOURCE #include #include "local.h" wint_t towctrans(wint_t c, wctrans_t w) { return towctrans_l(c, w, 0); } picolibc-1.8.11/libc/ctype/towctrans_l.c000066400000000000000000000010751513574234600201430ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #include #include "local.h" wint_t towctrans_l(wint_t u, wctrans_t w, locale_t locale) { switch (w) { case WCT_TOLOWER: u = towlower_l(u, locale); break; case WCT_TOUPPER: u = towupper_l(u, locale); break; default: break; } return u; } picolibc-1.8.11/libc/ctype/towlower.c000066400000000000000000000053271513574234600174720ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---translate wide characters to lowercase INDEX towlower INDEX towlower_l SYNOPSIS #include wint_t towlower(wint_t <[c]>); #include wint_t towlower_l(wint_t <[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which converts uppercase wide characters to lowercase, leaving all other characters unchanged. <> is like <> but performs the function based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return the lowercase equivalent of <[c]> when it is a uppercase wide character; otherwise, it returns the input character. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #define _DEFAULT_SOURCE #include #include #include "local.h" wint_t towlower(wint_t c) { #ifdef __MB_CAPABLE return towlower_l(c, 0); #else return c < 0x00ff ? (wint_t)(tolower((int)c)) : c; #endif /* __MB_CAPABLE */ } picolibc-1.8.11/libc/ctype/towlower_l.c000066400000000000000000000017631513574234600200050ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #include "local.h" wint_t towlower_l(wint_t c, locale_t locale) { #ifdef __MB_CAPABLE const struct caseconv_entry *cce = __caseconv_lookup(c, locale); if (cce) switch (cce->mode) { case TOLO: return c + cce->delta; case TOBOTH: return c + 1; case TO1: switch (cce->delta) { case EVENCAP: if (!(c & 1)) return c + 1; break; case ODDCAP: if (c & 1) return c + 1; break; default: break; } default: break; } return c; #else (void)locale; return towlower(c); #endif } picolibc-1.8.11/libc/ctype/towupper.c000066400000000000000000000053531513574234600174740ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Modified (m) 2017 Thomas Wolff to refer to generated Unicode data tables. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---translate wide characters to uppercase INDEX towupper INDEX towupper_l SYNOPSIS #include wint_t towupper(wint_t <[c]>); #include wint_t towupper_l(wint_t <[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which converts lowercase wide characters to uppercase, leaving all other characters unchanged. <> is like <> but performs the function based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return the uppercase equivalent of <[c]> when it is a lowercase wide character, otherwise, it returns the input character. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #define _DEFAULT_SOURCE #include #include #include #include "local.h" wint_t towupper(wint_t c) { #ifdef __MB_CAPABLE return towupper_l(c, 0); #else return c < 0x00ff ? (wint_t)(toupper((int)c)) : c; #endif /* __MB_CAPABLE */ } picolibc-1.8.11/libc/ctype/towupper_l.c000066400000000000000000000017631513574234600200100ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include #include "local.h" wint_t towupper_l(wint_t c, locale_t locale) { #ifdef __MB_CAPABLE const struct caseconv_entry *cce = __caseconv_lookup(c, locale); if (cce) switch (cce->mode) { case TOUP: return c + cce->delta; case TOBOTH: return c - 1; case TO1: switch (cce->delta) { case EVENCAP: if (c & 1) return c - 1; break; case ODDCAP: if (!(c & 1)) return c - 1; break; default: break; } default: break; } return c; #else (void)locale; return towupper(c); #endif } picolibc-1.8.11/libc/ctype/wctrans.c000066400000000000000000000054541513574234600172720ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---get wide-character translation type INDEX wctrans INDEX wctrans_l SYNOPSIS #include wctrans_t wctrans(const char *<[c]>); #include wctrans_t wctrans_l(const char *<[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which takes a string <[c]> and gives back the appropriate wctrans_t type value associated with the string, if one exists. The following values are guaranteed to be recognized: "tolower" and "toupper". <> is like <> but performs the function based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return 0 and sets <> to <> if the given name is invalid. Otherwise, it returns a valid non-zero wctrans_t value. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #include #include #include #include "local.h" wctrans_t wctrans(const char *c) { if (!strcmp(c, "tolower")) return WCT_TOLOWER; else if (!strcmp(c, "toupper")) return WCT_TOUPPER; else { errno = EINVAL; return 0; } } picolibc-1.8.11/libc/ctype/wctrans_l.c000066400000000000000000000006461513574234600176030ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include wctrans_t wctrans_l(const char *c, locale_t locale) { (void)locale; /* We're using a locale-independent representation of upper/lower case based on Unicode data. Thus, the locale doesn't matter. */ return wctrans(c); } picolibc-1.8.11/libc/ctype/wctype.c000066400000000000000000000074611513574234600171240ustar00rootroot00000000000000/* Copyright (c) 2002 Red Hat Incorporated. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---get wide-character classification type INDEX wctype INDEX wctype_l SYNOPSIS #include wctype_t wctype(const char *<[c]>); #include wctype_t wctype_l(const char *<[c]>, locale_t <[locale]>); DESCRIPTION <> is a function which takes a string <[c]> and gives back the appropriate wctype_t type value associated with the string, if one exists. The following values are guaranteed to be recognized: "alnum", "alpha", "blank", "cntrl", "digit", "graph", "lower", "print", "punct", "space", "upper", and "xdigit". <> is like <> but performs the function based on the locale specified by the locale object locale. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS <>, <> return 0 and sets <> to <> if the given name is invalid. Otherwise, it returns a valid non-zero wctype_t value. PORTABILITY <> is C99. <> is POSIX-1.2008. No supporting OS subroutines are required. */ #include "local.h" #include wctype_t wctype(const char *c) { switch (*c) { case 'a': if (!strcmp(c, "alnum")) return CLASS_alnum; else if (!strcmp(c, "alpha")) return CLASS_alpha; break; case 'b': if (!strcmp(c, "blank")) return CLASS_blank; break; case 'c': if (!strcmp(c, "cntrl")) return CLASS_cntrl; break; case 'd': if (!strcmp(c, "digit")) return CLASS_digit; break; case 'g': if (!strcmp(c, "graph")) return CLASS_graph; break; case 'l': if (!strcmp(c, "lower")) return CLASS_lower; break; case 'p': if (!strcmp(c, "print")) return CLASS_print; else if (!strcmp(c, "punct")) return CLASS_punct; break; case 's': if (!strcmp(c, "space")) return CLASS_space; break; case 'u': if (!strcmp(c, "upper")) return CLASS_upper; break; case 'x': if (!strcmp(c, "xdigit")) return CLASS_xdigit; break; } /* otherwise invalid */ errno = EINVAL; return CLASS_none; } picolibc-1.8.11/libc/ctype/wctype_l.c000066400000000000000000000004251513574234600174300ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ #define _DEFAULT_SOURCE #include wctype_t wctype_l(const char *c, locale_t locale) { (void)locale; return wctype(c); } picolibc-1.8.11/libc/errno/000077500000000000000000000000001513574234600154365ustar00rootroot00000000000000picolibc-1.8.11/libc/errno/CMakeLists.txt000066400000000000000000000031141513574234600201750ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources( errno.c ) picolibc-1.8.11/libc/errno/errno.c000066400000000000000000000032551513574234600167340ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #ifndef __PICOLIBC_ERRNO_FUNCTION __THREAD_LOCAL_ERRNO int errno; #endif picolibc-1.8.11/libc/errno/meson.build000066400000000000000000000036721513574234600176100ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_errno = [ 'errno.c', ] srcs_errno_use = [] foreach file : srcs_errno s_file = fs.replace_suffix(file, '.S') if file in srcs_machine message('libc/errno/' + file + ': machine overrides generic') elif s_file in srcs_machine message('libc/errno/' + s_file + ': machine overrides generic') else srcs_errno_use += file endif endforeach src_errno = files(srcs_errno_use) picolibc-1.8.11/libc/iconv/000077500000000000000000000000001513574234600154275ustar00rootroot00000000000000picolibc-1.8.11/libc/iconv/CMakeLists.txt000066400000000000000000000031531513574234600201710ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2025 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources( iconv.c iconv_close.c iconv_open.c ) picolibc-1.8.11/libc/iconv/iconv.c000066400000000000000000000113721513574234600167150ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "iconv_private.h" size_t iconv(iconv_t ic, char ** __restrict inbuf, size_t * __restrict inbytesleft, char ** __restrict outbuf, size_t * __restrict outbytesleft) { if (ic == (iconv_t)-1) { errno = EINVAL; return (size_t)-1; } if (!inbuf || !inbytesleft) return 0; char *in = *inbuf; char *out = *outbuf; size_t inbytes = *inbytesleft; size_t outbytes = *outbytesleft; size_t tocopy; #ifdef __MB_CAPABLE char *wc_out; int ret; wchar_t wc; size_t inexact_count = 0; while (outbytes) { if (ic->buf_len) { tocopy = ic->buf_len - ic->buf_off; if (tocopy > outbytes) tocopy = outbytes; memcpy(out, ic->buf + ic->buf_off, tocopy); out += tocopy; outbytes -= tocopy; ic->buf_off += tocopy; if (ic->buf_off == ic->buf_len) { ic->buf_off = ic->buf_len = 0; } } else if (inbytes && ic->buf_len == 0) { ret = ic->in_mbtowc(&wc, in, inbytes, &ic->in_state); switch (ret) { case 0: wc = L'\0'; in += inbytes; inbytes = 0; break; case -1: switch (ic->mode) { case iconv_ignore: in += 1; inbytes--; break; default: goto fail; } break; case -2: in += inbytes; inbytes = 0; goto done; default: in += ret; inbytes -= ret; break; } if (outbytes >= MB_LEN_MAX) { wc_out = out; } else { wc_out = ic->buf; } ret = ic->out_wctomb(wc_out, wc, &ic->out_state); if (ret == -1) { switch (ic->mode) { default: goto fail; case iconv_translit: ret = ic->out_wctomb(wc_out, L'?', &ic->out_state); if (ret == -1) goto fail; __fallthrough; case iconv_ignore: case iconv_discard: inexact_count++; break; } } if (outbytes >= MB_LEN_MAX) { out += ret; outbytes -= ret; } else { ic->buf_len = ret; } } else { break; } } done: *inbuf = in; *inbytesleft = inbytes; *outbuf = out; *outbytesleft = outbytes; return inexact_count; fail: *inbuf = in; *inbytesleft = inbytes; errno = EILSEQ; return (size_t)-1; #else (void)ic; tocopy = inbytes; if (tocopy > outbytes) tocopy = outbytes; memcpy(out, in, tocopy); in += tocopy; inbytes -= tocopy; out += tocopy; outbytes -= tocopy; *inbuf = in; *inbytesleft = inbytes; *outbuf = out; *outbytesleft = outbytes; return 0; #endif } picolibc-1.8.11/libc/iconv/iconv_close.c000066400000000000000000000034211513574234600200760ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "iconv_private.h" int iconv_close(iconv_t ic) { if (ic == (iconv_t)-1) { errno = EINVAL; return -1; } #ifdef __MB_CAPABLE free(ic); #endif return 0; } picolibc-1.8.11/libc/iconv/iconv_open.c000066400000000000000000000060651513574234600177410ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include "iconv_private.h" iconv_t iconv_open(const char *tocode, const char *fromcode) { if (!tocode || !fromcode) goto fail; enum locale_id toid = __find_charset(tocode); enum locale_id fromid = __find_charset(fromcode); if (toid == locale_INVALID || fromid == locale_INVALID) goto fail; #ifdef __MB_CAPABLE iconv_t ic; const char *mode_name; static const struct { const char *name; enum __iconv_mode mode; } modes[] = { { .name = "IGNORE", .mode = iconv_ignore }, { .name = "NON_IDENTICAL_DISCARD", .mode = iconv_discard }, { .name = "TRANSLIT", .mode = iconv_translit }, }; #define NMODE (sizeof(modes) / sizeof(modes[0])) size_t m; enum __iconv_mode mode = iconv_default; mode_name = strchr(tocode, '/'); if (mode_name) { if (mode_name[1] != '/') goto fail; mode_name = mode_name + 2; for (m = 0; m < NMODE; m++) { if (strcmp(modes[m].name, mode_name) == 0) { mode = modes[m].mode; break; } } if (m == NMODE) goto fail; } ic = calloc(1, sizeof(*ic)); if (!ic) goto fail; ic->in_mbtowc = __get_mbtowc(fromid); ic->out_wctomb = __get_wctomb(toid); ic->mode = mode; return ic; #else return NULL; #endif fail: errno = EINVAL; return (iconv_t)-1; } picolibc-1.8.11/libc/iconv/iconv_private.h000066400000000000000000000041411513574234600204500ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _ICONV_PRIVATE_H_ #define _ICONV_PRIVATE_H_ #include "../stdlib/local.h" #include "../ctype/ctype_.h" #include enum __iconv_mode { iconv_default, iconv_ignore, iconv_discard, iconv_translit }; struct __iconv_t { mbtowc_p in_mbtowc; wctomb_p out_wctomb; mbstate_t in_state; mbstate_t out_state; size_t buf_len; size_t buf_off; enum __iconv_mode mode; char buf[MB_LEN_MAX]; }; #endif /* _ICONV_PRIVATE_H_ */ picolibc-1.8.11/libc/iconv/meson.build000066400000000000000000000037361513574234600176020ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2025 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_iconv = [ 'iconv.c', 'iconv_close.c', 'iconv_open.c', ] srcs_iconv_use = [] foreach file : srcs_iconv s_file = fs.replace_suffix(file, '.S') if file in srcs_machine message('libc/iconv/' + file + ': machine overrides generic') elif s_file in srcs_machine message('libc/iconv/' + s_file + ': machine overrides generic') else srcs_iconv_use += file endif endforeach src_iconv = files(srcs_iconv_use) picolibc-1.8.11/libc/include/000077500000000000000000000000001513574234600157345ustar00rootroot00000000000000picolibc-1.8.11/libc/include/CMakeLists.txt000066400000000000000000000046171513574234600205040ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # add_subdirectory(sys) add_subdirectory(machine) add_subdirectory(ssp) add_subdirectory(rpc) add_subdirectory(arpa) picolibc_headers("" alloca.h argz.h ar.h assert.h byteswap.h cpio.h ctype.h devctl.h dirent.h endian.h envlock.h envz.h errno.h fastmath.h fcntl.h fenv.h fnmatch.h getopt.h glob.h grp.h iconv.h ieeefp.h inttypes.h langinfo.h libgen.h limits.h locale.h malloc.h math.h memory.h monetary.h ndbm.h newlib.h paths.h picotls.h pwd.h regdef.h regex.h sched.h search.h setjmp.h signal.h spawn.h stdio.h stdio-bufio.h stdint.h stdnoreturn.h stdlib.h string.h strings.h tar.h termios.h time.h uchar.h unctrl.h unistd.h utime.h utmp.h wchar.h wctype.h wordexp.h ) if(${__HAVE_COMPLEX}) picolibc_headers("" complex.h ) endif() picolibc-1.8.11/libc/include/_newlib_version.h000066400000000000000000000002341513574234600212700ustar00rootroot00000000000000/* Copyright (c) 2016 Jeff Johnston */ /* dummy file for external tools to use. Real file is created by newlib configuration. */ picolibc-1.8.11/libc/include/alloca.h000066400000000000000000000006241513574234600173420ustar00rootroot00000000000000/* libc/include/alloca.h - Allocate memory on stack */ /* Copyright (c) 2000 Werner Almesberger */ /* Rearranged for general inclusion by stdlib.h. 2001, Corinna Vinschen */ #ifndef _NEWLIB_ALLOCA_H #define _NEWLIB_ALLOCA_H #include #undef alloca #if __HAVE_BUILTIN_ALLOCA #define alloca(size) __builtin_alloca(size) #else void *alloca(size_t); #endif #endif picolibc-1.8.11/libc/include/ar.h000066400000000000000000000053131513574234600165110ustar00rootroot00000000000000/* $NetBSD: ar.h,v 1.4 1994/10/26 00:55:43 cgd Exp $ */ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph * Co. or Unix System Laboratories, Inc. and are reproduced herein with * the permission of UNIX System Laboratories, Inc. * * This code is derived from software contributed to Berkeley by * Hugh Smith at The University of Guelph. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)ar.h 8.2 (Berkeley) 1/21/94 */ #ifndef _AR_H_ #define _AR_H_ #include _BEGIN_STD_C /* Pre-4BSD archives had these magic numbers in them. */ #define OARMAG1 0177555 #define OARMAG2 0177545 #define ARMAG "!\n" /* ar "magic number" */ #define SARMAG 8 /* strlen(ARMAG); */ #define AR_EFMT1 "#1/" /* extended format #1 */ struct ar_hdr { char ar_name[16]; /* name */ char ar_date[12]; /* modification time */ char ar_uid[6]; /* user id */ char ar_gid[6]; /* group id */ char ar_mode[8]; /* octal file permissions */ char ar_size[10]; /* size in bytes */ #define ARFMAG "`\n" char ar_fmag[2]; /* consistency check */ }; _END_STD_C #endif /* !_AR_H_ */ picolibc-1.8.11/libc/include/argz.h000066400000000000000000000026371513574234600170600ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #ifndef _ARGZ_H_ #define _ARGZ_H_ #include #define __need_size_t #include _BEGIN_STD_C #ifndef _ERROR_T_DECLARED typedef int error_t; #define _ERROR_T_DECLARED #endif /* The newlib implementation of these functions assumes that sizeof(char) == 1. */ error_t argz_create(char * const argv[], char **argz, size_t *argz_len); error_t argz_create_sep(const char *string, int sep, char **argz, size_t *argz_len); size_t argz_count(const char *argz, size_t argz_len); void argz_extract(char *argz, size_t argz_len, char **argv); void argz_stringify(char *argz, size_t argz_len, int sep); error_t argz_add(char **argz, size_t *argz_len, const char *str); error_t argz_add_sep(char **argz, size_t *argz_len, const char *str, int sep); error_t argz_append(char **argz, size_t *argz_len, const char *buf, size_t buf_len); error_t argz_delete(char **argz, size_t *argz_len, char *entry); error_t argz_insert(char **argz, size_t *argz_len, char *before, const char *entry); char *argz_next(char *argz, size_t argz_len, const char *entry); error_t argz_replace(char **argz, size_t *argz_len, const char *str, const char *with, unsigned *replace_count); _END_STD_C #endif /* _ARGZ_H_ */ picolibc-1.8.11/libc/include/arpa/000077500000000000000000000000001513574234600166575ustar00rootroot00000000000000picolibc-1.8.11/libc/include/arpa/CMakeLists.txt000066400000000000000000000031201513574234600214130ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_headers(arpa inet.h ) picolibc-1.8.11/libc/include/arpa/inet.h000066400000000000000000000016151513574234600177720ustar00rootroot00000000000000/* Copyright (c) 2004 Jeff Johnston */ #ifndef __ARPA_INET_H__ #define __ARPA_INET_H__ #include /* byteorder(3) - simimlar to linux */ #ifndef __machine_host_to_from_network_defined #if _BYTE_ORDER == _LITTLE_ENDIAN #define __htonl(_x) __bswap32(_x) #define __htons(_x) __bswap16(_x) #define __ntohl(_x) __bswap32(_x) #define __ntohs(_x) __bswap16(_x) #define htonl(_x) __htonl(_x) #define htons(_x) __htons(_x) #define ntohl(_x) __htonl(_x) #define ntohs(_x) __htons(_x) #else #define __htonl(_x) ((__uint32_t)(_x)) #define __htons(_x) ((__uint16_t)(_x)) #define __ntohl(_x) ((__uint32_t)(_x)) #define __ntohs(_x) ((__uint16_t)(_x)) #define htonl(_x) __htonl(_x) #define htons(_x) __htons(_x) #define ntohl(_x) __ntohl(_x) #define ntohs(_x) __ntohs(_x) #endif #endif /* __machine_host_to_from_network_defined */ #endif /* __ARPA_INET_H__ */ picolibc-1.8.11/libc/include/arpa/meson.build000066400000000000000000000041171513574234600210240ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_arpa_headers = [ 'inet.h' ] if really_install install_headers(inc_arpa_headers, install_dir: include_dir / 'arpa') endif if enable_cdefs_tests ignore_headers = [] foreach header : inc_arpa_headers if not (header in ignore_headers) and not (header.startswith('_')) test_name = 'check-cdef-arpa-' + header test(test_name, validate_cdefs, args: [meson.current_source_dir() / header] + cc.cmd_array() + c_args + inc_args, suite: 'headers') endif endforeach endif picolibc-1.8.11/libc/include/assert.h000066400000000000000000000056231513574234600174140ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* assert.h */ #include _BEGIN_STD_C #undef assert #ifdef NDEBUG /* required by ANSI standard */ #define assert(__e) ((void)0) #else #if !defined(__ASSERT_VERBOSE) || defined(__ASSERT_QUIET) #define assert(__e) ((__e) ? (void)0 : __assert_no_args()) #else #ifndef __ASSERT_FUNC /* Use g++'s demangled names in C++. */ #if defined __cplusplus && defined __GNUC__ #define __ASSERT_FUNC __PRETTY_FUNCTION__ /* C99 requires the use of __func__. */ #elif __STDC_VERSION__ >= 199901L #define __ASSERT_FUNC __func__ /* Older versions of gcc don't have __func__ but can use __FUNCTION__. */ #elif __GNUC__ >= 2 #define __ASSERT_FUNC __FUNCTION__ /* failed to detect __func__ support. */ #else #define __ASSERT_FUNC ((char *)0) #endif #endif /* !__ASSERT_FUNC */ #define assert(__e) ((__e) ? (void)0 : __assert_func(__FILE__, __LINE__, __ASSERT_FUNC, #__e)) #endif #endif /* !NDEBUG */ __noreturn void __assert(const char *, const char *, int); __noreturn void __assert_func(const char *, int, const char *, const char *); __noreturn void __assert_no_args(void); #if __STDC_VERSION__ >= 201112L && !defined __cplusplus #define static_assert _Static_assert #endif _END_STD_C picolibc-1.8.11/libc/include/bits/000077500000000000000000000000001513574234600166755ustar00rootroot00000000000000picolibc-1.8.11/libc/include/bits/types/000077500000000000000000000000001513574234600200415ustar00rootroot00000000000000picolibc-1.8.11/libc/include/bits/types/mbstate_t.h000066400000000000000000000002711513574234600221740ustar00rootroot00000000000000#ifndef _PICOLIBC_BITS_TYPES_MBSTATE_T_H #define _PICOLIBC_BITS_TYPES_MBSTATE_T_H #include typedef _mbstate_t mbstate_t; #endif /* _PICOLIBC_BITS_TYPES_MBSTATE_T_H */ picolibc-1.8.11/libc/include/byteswap.h000066400000000000000000000051121513574234600177420ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __BYTESWAP_H__ #define __BYTESWAP_H__ #include _BEGIN_STD_C #ifdef __GNUC__ #define bswap_16(_x) __builtin_bswap16(_x) #define bswap_32(_x) __builtin_bswap32(_x) #define bswap_64(_x) __builtin_bswap64(_x) #else /* __GNUC__ */ static __inline __uint16_t bswap_16(__uint16_t _x) { return ((__uint16_t)((_x >> 8) | ((_x << 8) & 0xff00))); } static __inline __uint32_t bswap_32(__uint32_t _x) { return ((__uint32_t)((_x >> 24) | ((_x >> 8) & 0xff00) | ((_x << 8) & 0xff0000) | ((_x << 24) & 0xff000000))); } static __inline __uint64_t bswap_64(__uint64_t _x) { return ((__uint64_t)((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) | ((_x >> 8) & 0xff000000) | ((_x << 8) & ((__uint64_t)0xff << 32)) | ((_x << 24) & ((__uint64_t)0xff << 40)) | ((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56)))); } #endif /* !__GNUC__ */ _END_STD_C #endif /* __BYTESWAP_H__ */ picolibc-1.8.11/libc/include/complex.h000066400000000000000000000116351513574234600175620ustar00rootroot00000000000000/* $NetBSD: complex.h,v 1.3 2010/09/15 16:11:30 christos Exp $ */ /* * Copyright (c) 2010 Matthias Drochner. * Public domain. */ #ifndef _COMPLEX_H #define _COMPLEX_H #include #define complex _Complex #define _Complex_I 1.0fi #define I _Complex_I _BEGIN_STD_C /* 7.3.5 Trigonometric functions */ /* 7.3.5.1 The cacos functions */ double complex cacos(double complex); float complex cacosf(float complex); /* 7.3.5.2 The casin functions */ double complex casin(double complex); float complex casinf(float complex); /* 7.3.5.1 The catan functions */ double complex catan(double complex); float complex catanf(float complex); /* 7.3.5.1 The ccos functions */ double complex ccos(double complex); float complex ccosf(float complex); /* 7.3.5.1 The csin functions */ double complex csin(double complex); float complex csinf(float complex); /* 7.3.5.1 The ctan functions */ double complex ctan(double complex); float complex ctanf(float complex); /* 7.3.6 Hyperbolic functions */ /* 7.3.6.1 The cacosh functions */ double complex cacosh(double complex); float complex cacoshf(float complex); /* 7.3.6.2 The casinh functions */ double complex casinh(double complex); float complex casinhf(float complex); /* 7.3.6.3 The catanh functions */ double complex catanh(double complex); float complex catanhf(float complex); /* 7.3.6.4 The ccosh functions */ double complex ccosh(double complex); float complex ccoshf(float complex); /* 7.3.6.5 The csinh functions */ double complex csinh(double complex); float complex csinhf(float complex); /* 7.3.6.6 The ctanh functions */ double complex ctanh(double complex); float complex ctanhf(float complex); /* 7.3.7 Exponential and logarithmic functions */ /* 7.3.7.1 The cexp functions */ double complex cexp(double complex); float complex cexpf(float complex); /* 7.3.7.2 The clog functions */ double complex clog(double complex); float complex clogf(float complex); /* 7.3.8 Power and absolute-value functions */ /* 7.3.8.1 The cabs functions */ double cabs(double complex); float cabsf(float complex); /* 7.3.8.2 The cpow functions */ double complex cpow(double complex, double complex); float complex cpowf(float complex, float complex); /* 7.3.8.3 The csqrt functions */ double complex csqrt(double complex); float complex csqrtf(float complex); /* 7.3.9 Manipulation functions */ /* 7.3.9.1 The carg functions */ double carg(double complex); float cargf(float complex); /* 7.3.9.2 The cimag functions */ double cimag(double complex); float cimagf(float complex); /* 7.3.9.3 The conj functions */ double complex conj(double complex); float complex conjf(float complex); /* 7.3.9.4 The cproj functions */ double complex cproj(double complex); float complex cprojf(float complex); /* 7.3.9.5 The creal functions */ double creal(double complex); float crealf(float complex); #if __ISO_C_VISIBLE >= 2011 #if __HAVE_BUILTIN_COMPLEX #define CMPLX(r, i) __builtin_complex((double)(r), (double)(i)) #define CMPLXF(r, i) __builtin_complex((float)(r), (float)(i)) #define CMPLXL(r, i) __builtin_complex((long double)(r), (long double)(i)) #else #define CMPLX(r, i) ((double complex)((double)(r) + (double complex)I * (double)(i))) #define CMPLXF(r, i) ((float complex)((float)(r) + (float complex)I * (float)(i))) #define CMPLXL(r, i) \ ((long double complex)((long double)(r) + (long double complex)I * (long double)(i))) #endif #endif #if __GNU_VISIBLE double complex clog10(double complex); float complex clog10f(float complex); #endif #ifdef __HAVE_LONG_DOUBLE long double complex csqrtl(long double complex); long double cabsl(long double complex); long double complex cprojl(long double complex); long double creall(long double complex); long double complex conjl(long double complex); long double cimagl(long double complex); #ifdef __HAVE_LONG_DOUBLE_MATH long double cargl(long double complex); long double complex casinl(long double complex); long double complex cacosl(long double complex); long double complex catanl(long double complex); long double complex ccosl(long double complex); long double complex csinl(long double complex); long double complex ctanl(long double complex); long double complex cacoshl(long double complex); long double complex casinhl(long double complex); long double complex catanhl(long double complex); long double complex ccoshl(long double complex); long double complex csinhl(long double complex); long double complex ctanhl(long double complex); long double complex cexpl(long double complex); long double complex clogl(long double complex); long double complex cpowl(long double complex, long double complex); #if __GNU_VISIBLE long double complex clog10l(long double complex); #endif #endif /* __HAVE_LONG_DOUBLE_MATH */ #endif /* __HAVE_LONG_DOUBLE */ _END_STD_C #endif /* ! _COMPLEX_H */ picolibc-1.8.11/libc/include/cpio.h000066400000000000000000000021621513574234600170400ustar00rootroot00000000000000/* Copyright (c) 2016 Yaakov Selkowitz */ /* POSIX.1 symbolic constants for c_mode field of cpio archive format */ #ifndef _CPIO_H #define _CPIO_H #define C_IRUSR 0000400 /* Read by owner */ #define C_IWUSR 0000200 /* Write by owner */ #define C_IXUSR 0000100 /* Execute by owner */ #define C_IRGRP 0000040 /* Read by group */ #define C_IWGRP 0000020 /* Write by group */ #define C_IXGRP 0000010 /* Execute by group */ #define C_IROTH 0000004 /* Read by others */ #define C_IWOTH 0000002 /* Write by others */ #define C_IXOTH 0000001 /* Execute by others */ #define C_ISUID 0004000 /* Set user ID */ #define C_ISGID 0002000 /* Set group ID */ #define C_ISVTX 0001000 /* On directories, restricted deletion flag */ #define C_ISDIR 0040000 /* Directory */ #define C_ISFIFO 0010000 /* FIFO */ #define C_ISREG 0100000 /* Regular file */ #define C_ISBLK 0060000 /* Block special */ #define C_ISCHR 0020000 /* Character special */ #define C_ISCTG 0110000 /* Reserved */ #define C_ISLNK 0120000 /* Symbolic link */ #define C_ISSOCK 0140000 /* Socket */ #define MAGIC "070707" #endif /* _CPIO_H */ picolibc-1.8.11/libc/include/ctype.h000066400000000000000000000257521513574234600172440ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _CTYPE_H_ #define _CTYPE_H_ #include #if __POSIX_VISIBLE >= 200809 || __MISC_VISIBLE #include #endif _BEGIN_STD_C /* * The small ctype code does not support extended character sets. It also breaks * libstdc++'s ctype implementation, so just skip it for c++ */ #if defined(__MB_EXTENDED_CHARSETS_NON_UNICODE) || defined(__cplusplus) #undef _PICOLIBC_CTYPE_SMALL #define _PICOLIBC_CTYPE_SMALL 0 #endif /* * The default ctype style depends upon whether we are optimizing for * size and whether the library supports charset-specific ctype data */ #if !defined(_PICOLIBC_CTYPE_SMALL) #ifdef __OPTIMIZE_SIZE__ #define _PICOLIBC_CTYPE_SMALL 1 #else #define _PICOLIBC_CTYPE_SMALL 0 #endif #endif int isalnum(int c); int isalpha(int c); int iscntrl(int c); int isdigit(int c); int isgraph(int c); int islower(int c); int isprint(int c); int ispunct(int c); int isspace(int c); int isupper(int c); int isxdigit(int c); int tolower(int c); int toupper(int c); #if __ISO_C_VISIBLE >= 1999 int isblank(int c); #endif #if __MISC_VISIBLE || __XSI_VISIBLE int isascii(int c); int toascii(int c); #define _tolower(__c) ((__c) + ('a' - 'A')) #define _toupper(__c) ((__c) - ('a' - 'A')) #define isascii(__c) ((unsigned)(__c) <= 0177) #define toascii(__c) ((__c) & 0177) #endif #if __POSIX_VISIBLE >= 200809 int isalnum_l(int c, locale_t l); int isalpha_l(int c, locale_t l); int isblank_l(int c, locale_t l); int iscntrl_l(int c, locale_t l); int isdigit_l(int c, locale_t l); int isgraph_l(int c, locale_t l); int islower_l(int c, locale_t l); int isprint_l(int c, locale_t l); int ispunct_l(int c, locale_t l); int isspace_l(int c, locale_t l); int isupper_l(int c, locale_t l); int isxdigit_l(int c, locale_t l); int tolower_l(int c, locale_t l); int toupper_l(int c, locale_t l); #endif #if __MISC_VISIBLE int isascii_l(int c, locale_t l); int toascii_l(int c, locale_t l); #define isascii_l(__c, __l) ((void)(__l), (unsigned)(__c) <= 0177) #define toascii_l(__c, __l) ((void)(__l), (__c) & 0177) #endif #if _PICOLIBC_CTYPE_SMALL #ifdef __declare_extern_inline __declare_extern_inline(int) isblank(int c) { return c == ' ' || c == '\t'; } __declare_extern_inline(int) iscntrl(int c) { return (0x00 <= c && c <= 0x1f) || c == 0x7f; } __declare_extern_inline(int) isdigit(int c) { return '0' <= c && c <= '9'; } __declare_extern_inline(int) isgraph(int c) { return '!' <= c && c <= '~'; } __declare_extern_inline(int) islower(int c) { return 'a' <= c && c <= 'z'; } __declare_extern_inline(int) isprint(int c) { return ' ' <= c && c <= '~'; } __declare_extern_inline(int) ispunct(int c) { return (('!' <= c && c <= '/') || (':' <= c && c <= '@') || ('[' <= c && c <= '`') || ('{' <= c && c <= '~')); } __declare_extern_inline(int) isspace(int c) { return c == ' ' || ('\t' <= c && c <= '\r'); } __declare_extern_inline(int) isupper(int c) { return 'A' <= c && c <= 'Z'; } __declare_extern_inline(int) isxdigit(int c) { return (isdigit(c) || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f')); } __declare_extern_inline(int) isalpha(int c) { return isupper(c) || islower(c); } __declare_extern_inline(int) isalnum(int c) { return isalpha(c) || isdigit(c); } __declare_extern_inline(int) tolower(int c) { if (isupper(c)) c = c - 'A' + 'a'; return c; } __declare_extern_inline(int) toupper(int c) { if (islower(c)) c = c - 'a' + 'A'; return c; } #if __POSIX_VISIBLE >= 200809 __declare_extern_inline(int) isalnum_l(int c, locale_t l) { (void)l; return isalnum(c); } __declare_extern_inline(int) isalpha_l(int c, locale_t l) { (void)l; return isalpha(c); } __declare_extern_inline(int) isblank_l(int c, locale_t l) { (void)l; return isblank(c); } __declare_extern_inline(int) iscntrl_l(int c, locale_t l) { (void)l; return iscntrl(c); } __declare_extern_inline(int) isdigit_l(int c, locale_t l) { (void)l; return isdigit(c); } __declare_extern_inline(int) isgraph_l(int c, locale_t l) { (void)l; return isgraph(c); } __declare_extern_inline(int) islower_l(int c, locale_t l) { (void)l; return islower(c); } __declare_extern_inline(int) isprint_l(int c, locale_t l) { (void)l; return isprint(c); } __declare_extern_inline(int) ispunct_l(int c, locale_t l) { (void)l; return ispunct(c); } __declare_extern_inline(int) isspace_l(int c, locale_t l) { (void)l; return isspace(c); } __declare_extern_inline(int) isupper_l(int c, locale_t l) { (void)l; return isupper(c); } __declare_extern_inline(int) isxdigit_l(int c, locale_t l) { (void)l; return isxdigit(c); } __declare_extern_inline(int) tolower_l(int c, locale_t l) { (void)l; return tolower(c); } __declare_extern_inline(int) toupper_l(int c, locale_t l) { (void)l; return toupper(c); } #endif #endif /* __declare_extern_inline */ #else /* _PICOLIBC_CTYPE_SMALL */ #define _CTYPE_OFFSET 127 extern const char _ctype_b[]; extern const short _ctype_wide[]; #define _ctype_ (_ctype_b + _CTYPE_OFFSET) #define __CTYPE_UPPER 0x001 /* upper */ #define __CTYPE_LOWER 0x002 /* lower */ #define __CTYPE_DIGIT 0x004 /* digit */ #define __CTYPE_SPACE 0x008 /* space */ #define __CTYPE_PUNCT 0x010 /* punct */ #define __CTYPE_CNTRL 0x020 /* control */ #define __CTYPE_HEX 0x040 /* hex */ #define __CTYPE_BLANK 0x080 /* blank (but not tab) */ #define __CTYPE_TAB 0x100 /* tab (only in wide table) */ #ifdef __cplusplus /* We need these legacy symbols to build libstdc++ */ #define _U __CTYPE_UPPER #define _L __CTYPE_LOWER #define _N __CTYPE_DIGIT #define _S __CTYPE_SPACE #define _P __CTYPE_PUNCT #define _C __CTYPE_CNTRL #define _X __CTYPE_HEX #define _B __CTYPE_BLANK #endif #ifdef __MB_EXTENDED_CHARSETS_NON_UNICODE const char *__locale_ctype_ptr(void); #define __CTYPE_PTR __locale_ctype_ptr() #else #define __CTYPE_PTR _ctype_ #endif #ifndef __cplusplus #define __ctype_lookup(__c) (__CTYPE_PTR + 1)[(int)(__c)] #define isalpha(__c) (__ctype_lookup(__c) & (__CTYPE_UPPER | __CTYPE_LOWER)) #define isupper(__c) ((__ctype_lookup(__c) & (__CTYPE_UPPER | __CTYPE_LOWER)) == __CTYPE_UPPER) #define islower(__c) ((__ctype_lookup(__c) & (__CTYPE_UPPER | __CTYPE_LOWER)) == __CTYPE_LOWER) #define isdigit(__c) (__ctype_lookup(__c) & __CTYPE_DIGIT) #define isxdigit(__c) (__ctype_lookup(__c) & (__CTYPE_HEX | __CTYPE_DIGIT)) #define isspace(__c) (__ctype_lookup(__c) & __CTYPE_SPACE) #define ispunct(__c) (__ctype_lookup(__c) & __CTYPE_PUNCT) #define isalnum(__c) (__ctype_lookup(__c) & (__CTYPE_UPPER | __CTYPE_LOWER | __CTYPE_DIGIT)) #define isprint(__c) \ (__ctype_lookup(__c) \ & (__CTYPE_PUNCT | __CTYPE_UPPER | __CTYPE_LOWER | __CTYPE_DIGIT | __CTYPE_BLANK)) #define isgraph(__c) \ (__ctype_lookup(__c) & (__CTYPE_PUNCT | __CTYPE_UPPER | __CTYPE_LOWER | __CTYPE_DIGIT)) #define iscntrl(__c) (__ctype_lookup(__c) & __CTYPE_CNTRL) #if __ISO_C_VISIBLE >= 1999 && defined(__declare_extern_inline) __declare_extern_inline(int) isblank(int c) { return c == '\t' || __ctype_lookup(c) & __CTYPE_BLANK; } #endif #if __POSIX_VISIBLE >= 200809 #ifdef __MB_EXTENDED_CHARSETS_NON_UNICODE const char *__locale_ctype_ptr_l(locale_t); #define __CTYPE_PTR_L(__l) __locale_ctype_ptr_l(__l) #else #define __CTYPE_PTR_L(__l) ((void)(__l), _ctype_) #endif #define __ctype_lookup_l(__c, __l) ((__CTYPE_PTR_L(__l) + 1)[(int)(__c)]) #define isalpha_l(__c, __l) (__ctype_lookup_l(__c, __l) & (__CTYPE_UPPER | __CTYPE_LOWER)) #define isupper_l(__c, __l) \ ((__ctype_lookup_l(__c, __l) & (__CTYPE_UPPER | __CTYPE_LOWER)) == __CTYPE_UPPER) #define islower_l(__c, __l) \ ((__ctype_lookup_l(__c, __l) & (__CTYPE_UPPER | __CTYPE_LOWER)) == __CTYPE_LOWER) #define isdigit_l(__c, __l) (__ctype_lookup_l(__c, __l) & __CTYPE_DIGIT) #define isxdigit_l(__c, __l) (__ctype_lookup_l(__c, __l) & (__CTYPE_HEX | __CTYPE_DIGIT)) #define isspace_l(__c, __l) (__ctype_lookup_l(__c, __l) & __CTYPE_SPACE) #define ispunct_l(__c, __l) (__ctype_lookup_l(__c, __l) & __CTYPE_PUNCT) #define isalnum_l(__c, __l) \ (__ctype_lookup_l(__c, __l) & (__CTYPE_UPPER | __CTYPE_LOWER | __CTYPE_DIGIT)) #define isprint_l(__c, __l) \ (__ctype_lookup_l(__c, __l) \ & (__CTYPE_PUNCT | __CTYPE_UPPER | __CTYPE_LOWER | __CTYPE_DIGIT | __CTYPE_BLANK)) #define isgraph_l(__c, __l) \ (__ctype_lookup_l(__c, __l) & (__CTYPE_PUNCT | __CTYPE_UPPER | __CTYPE_LOWER | __CTYPE_DIGIT)) #define iscntrl_l(__c, __l) (__ctype_lookup_l(__c, __l) & __CTYPE_CNTRL) #ifdef __declare_extern_inline __declare_extern_inline(int) isblank_l(int c, locale_t l) { return c == '\t' || (__ctype_lookup_l(c, l) & __CTYPE_BLANK); } #endif #endif /* __POSIX_VISIBLE >= 200809 */ #endif /* !__cplusplus */ #endif /* else _PICOLIBC_CTYPE_SMALL */ _END_STD_C #endif /* _CTYPE_H_ */ picolibc-1.8.11/libc/include/devctl.h000066400000000000000000000047421513574234600173750ustar00rootroot00000000000000/* * Copyright (c) 2016,2019 Joel Sherrill . * 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. */ #ifndef _POSIX_DEVCTL_h_ #define _POSIX_DEVCTL_h_ #include /* * Nothing in this file should be visible unless _POSIX_26_C_SOURCE is * defined. */ #ifdef _POSIX_26_C_SOURCE _BEGIN_STD_C #if defined(__rtems__) /* * The FACE Technical Standard, Edition 3.0 and later require the * definition of the subcommand SOCKCLOSE in . * * Reference: https://www.opengroup.org/face * * Using 'D' should avoid the letters used by other users of */ #include #define SOCKCLOSE _IO('D', 1) /* socket close */ #endif /* * The posix_devctl() method is defined by POSIX 1003.26-2003. Aside * from the single method, it adds the following requirements: * * + define _POSIX_26_VERSION to 200312L * + add _SC_POSIX_26_VERSION in . Return _POSIX_26_VERSION * + application must define _POSIX_26_C_SOURCE to use posix_devctl(). * + posix_devctl() is prototyped in */ int posix_devctl(int fd, int dcmd, void * __restrict dev_data_ptr, size_t nbyte, int * __restrict dev_info_ptr); _END_STD_C #endif /* _POSIX_26_C_SOURCE */ #endif /*_POSIX_DEVCTL_h_ */ picolibc-1.8.11/libc/include/dirent.h000066400000000000000000000062271513574234600174010ustar00rootroot00000000000000/*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)dirent.h 8.3 (Berkeley) 8/10/94 * $FreeBSD: head/include/dirent.h 326024 2017-11-20 19:45:28Z pfg $ */ #ifndef _DIRENT_H_ #define _DIRENT_H_ #include #include #if !defined(MAXNAMLEN) && __BSD_VISIBLE #define MAXNAMLEN 1024 #endif _BEGIN_STD_C #if __MISC_VISIBLE || __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700 int alphasort(const struct dirent **, const struct dirent **); int dirfd(DIR *); #endif #if __BSD_VISIBLE int fdclosedir(DIR *); #endif DIR *opendir(const char *); DIR *fdopendir(int); struct dirent *readdir(DIR *); #if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE >= 500 int readdir_r(DIR * __restrict, struct dirent * __restrict, struct dirent ** __restrict); #endif void rewinddir(DIR *); #if __MISC_VISIBLE || __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700 int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **)); #endif #ifdef _LIBC void _seekdir(DIR *, long); #endif #if __MISC_VISIBLE || __XSI_VISIBLE #ifndef __INSIDE_CYGWIN__ void seekdir(DIR *, long); long telldir(DIR *); #endif #endif int closedir(DIR *); #if __GNU_VISIBLE int scandirat(int, const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **)); int versionsort(const struct dirent **, const struct dirent **); #endif #if __POSIX_VISIBLE >= 202405 ssize_t posix_getdents(int, void *, size_t, int); #endif /* __POSIX_VISIBLE >= 202405 */ _END_STD_C #endif /*_DIRENT_H_*/ picolibc-1.8.11/libc/include/endian.h000066400000000000000000000034011513574234600173410ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ /** * This is just a link to the real endian.h which is located in machine. * To be compatible with linux that has endian.h in include/endian.h */ #include picolibc-1.8.11/libc/include/envlock.h000066400000000000000000000033371513574234600175540ustar00rootroot00000000000000/* Copyright (c) 1992, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 4. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* envlock.h -- header file for env routines. */ #ifndef _INCLUDE_ENVLOCK_H_ #define _INCLUDE_ENVLOCK_H_ #include #include #define ENV_LOCK __LIBC_LOCK() #define ENV_UNLOCK __LIBC_UNLOCK() #endif /* _INCLUDE_ENVLOCK_H_ */ picolibc-1.8.11/libc/include/envz.h000066400000000000000000000017371513574234600170770ustar00rootroot00000000000000/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #ifndef _ENVZ_H_ #define _ENVZ_H_ #include #define __need_size_t #include _BEGIN_STD_C #ifndef _ERROR_T_DECLARED typedef int error_t; #define _ERROR_T_DECLARED #endif /* The newlib implementation of these functions assumes that sizeof(char) == 1. */ char *envz_entry(const char *envz, size_t envz_len, const char *name); char *envz_get(const char *envz, size_t envz_len, const char *name); error_t envz_add(char **envz, size_t *envz_len, const char *name, const char *value); error_t envz_merge(char **envz, size_t *envz_len, const char *envz2, size_t envz2_len, int override); void envz_remove(char **envz, size_t *envz_len, const char *name); void envz_strip(char **envz, size_t *envz_len); _END_STD_C #endif /* _ENVZ_H_ */ picolibc-1.8.11/libc/include/errno.h000066400000000000000000000040441513574234600172340ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __ERRNO_H__ #define __ERRNO_H__ #include #if __STDC_WANT_LIB_EXT1__ == 1 #ifndef __STDC_LIB_EXT1__ #define __STDC_LIB_EXT1__ 1 #endif #include #ifndef _ERRNO_T_DEFINED typedef __errno_t errno_t; #define _ERRNO_T_DEFINED #endif #endif #include #endif /* !__ERRNO_H__ */ picolibc-1.8.11/libc/include/fastmath.h000066400000000000000000000035531513574234600177220ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _FASTMATH_H_ #define _FASTMATH_H_ #include #include #include #endif /* _FASTMATH_H_ */ picolibc-1.8.11/libc/include/fcntl.h000066400000000000000000000033651513574234600172220ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include picolibc-1.8.11/libc/include/fenv.h000066400000000000000000000037451513574234600170540ustar00rootroot00000000000000/* Copyright (c) 2017 SiFive Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #ifndef _FENV_H #define _FENV_H #include _BEGIN_STD_C #include #ifndef FE_ALL_EXCEPT #define FE_ALL_EXCEPT 0 #endif /* Exception */ int feclearexcept(int excepts); int fegetexceptflag(fexcept_t *flagp, int excepts); int feraiseexcept(int excepts); int fesetexceptflag(const fexcept_t *flagp, int excepts); int fetestexcept(int excepts); /* Rounding mode */ int fegetround(void); int fesetround(int rounding_mode); /* Float environment */ int fegetenv(fenv_t *envp); int feholdexcept(fenv_t *envp); int fesetenv(const fenv_t *envp); int feupdateenv(const fenv_t *envp); #if __GNU_VISIBLE int feenableexcept(int); int fedisableexcept(int); int fegetexcept(void); #endif /* * Lastly, a FE_DFL_ENV macro must be defined, representing a pointer * to const fenv_t that contains the value of the default floating point * environment. * * NOTE: The extern'ed variable fe_default_env_p is an implementation * detail of this stub. FE_DFL_ENV must point to an instance of * fenv_t with the default fenv_t. The format of fenv_t and where * FE_DFL_ENV is are implementation specific. */ extern fenv_t _fe_dfl_env; #define FE_DFL_ENV ((const fenv_t *)&_fe_dfl_env) #ifdef __STDC_WANT_IEC_60559_BFP_EXT__ #ifndef FE_DFL_MODE typedef struct { int round, except; } femode_t; #define FE_DFL_MODE ((femode_t *)0) #endif int fegetmode(femode_t *modep); int fesetmode(femode_t *modep); int fesetexcept(int excepts); #endif _END_STD_C #endif picolibc-1.8.11/libc/include/fnmatch.h000066400000000000000000000044331513574234600175310ustar00rootroot00000000000000/*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD: src/include/fnmatch.h,v 1.10 2002/03/23 17:24:53 imp Exp $ * @(#)fnmatch.h 8.1 (Berkeley) 6/2/93 */ #ifndef _FNMATCH_H_ #define _FNMATCH_H_ #include #define FNM_NOMATCH 1 /* Match failed. */ #define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */ #define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */ #define FNM_PERIOD 0x04 /* Period must be matched by period. */ #if __GNU_VISIBLE #define FNM_LEADING_DIR 0x08 /* Ignore / after Imatch. */ #define FNM_CASEFOLD 0x10 /* Case insensitive search. */ #define FNM_IGNORECASE FNM_CASEFOLD #define FNM_FILE_NAME FNM_PATHNAME #endif _BEGIN_STD_C int fnmatch(const char *, const char *, int); _END_STD_C #endif /* !_FNMATCH_H_ */ picolibc-1.8.11/libc/include/getopt.h000066400000000000000000000150461513574234600174150ustar00rootroot00000000000000/**************************************************************************** getopt.h - Read command line options AUTHOR: Gregory Pietsch CREATED Thu Jan 09 22:37:00 1997 DESCRIPTION: The getopt() function parses the command line arguments. Its arguments argc and argv are the argument count and array as passed to the main() function on program invocation. The argument optstring is a list of available option characters. If such a character is followed by a colon (`:'), the option takes an argument, which is placed in optarg. If such a character is followed by two colons, the option takes an optional argument, which is placed in optarg. If the option does not take an argument, optarg is NULL. The external variable optind is the index of the next array element of argv to be processed; it communicates from one call to the next which element to process. The getopt_long() function works like getopt() except that it also accepts long options started by two dashes `--'. If these take values, it is either in the form --arg=value or --arg value It takes the additional arguments longopts which is a pointer to the first element of an array of type GETOPT_LONG_OPTION_T, defined below. The last element of the array has to be filled with NULL for the name field. The longind pointer points to the index of the current long option relative to longopts if it is non-NULL. The getopt() function returns the option character if the option was found successfully, `:' if there was a missing parameter for one of the options, `?' for an unknown option character, and EOF for the end of the option list. The getopt_long() function's return value is described below. The function getopt_long_only() is identical to getopt_long(), except that a plus sign `+' can introduce long options as well as `--'. Describe how to deal with options that follow non-option ARGV-elements. If the caller did not specify anything, the default is REQUIRE_ORDER if the environment variable POSIXLY_CORRECT is defined, PERMUTE otherwise. REQUIRE_ORDER means don't recognize them as options; stop option processing when the first non-option is seen. This is what Unix does. This mode of operation is selected by either setting the environment variable POSIXLY_CORRECT, or using `+' as the first character of the optstring parameter. PERMUTE is the default. We permute the contents of ARGV as we scan, so that eventually all the non-options are at the end. This allows options to be given in any order, even with programs that were not written to expect this. RETURN_IN_ORDER is an option available to programs that were written to expect options and other ARGV-elements in any order and that care about the ordering of the two. We describe each non-option ARGV-element as if it were the argument of an option with character code 1. Using `-' as the first character of the optstring parameter selects this mode of operation. The special argument `--' forces an end of option-scanning regardless of the value of `ordering'. In the case of RETURN_IN_ORDER, only `--' can cause getopt() and friends to return EOF with optind != argc. COPYRIGHT NOTICE AND DISCLAIMER: Copyright (C) 1997 Gregory Pietsch This file and the accompanying getopt.c implementation file are hereby placed in the public domain without restrictions. Just give the author credit, don't claim you wrote it or prevent anyone else from using it. Gregory Pietsch's current e-mail address: gpietsch@comcast.net ****************************************************************************/ /* This is a glibc-extension header file. */ #ifndef GETOPT_H #define GETOPT_H #include /* include files needed by this include file */ #define no_argument 0 #define required_argument 1 #define optional_argument 2 _BEGIN_STD_C /* types defined by this include file */ struct option { const char *name; /* the name of the long option */ int has_arg; /* one of the above macros */ int *flag; /* determines if getopt_long() returns a * value for a long option; if it is * non-NULL, 0 is returned as a function * value and the value of val is stored in * the area pointed to by flag. Otherwise, * val is returned. */ int val; /* determines the value to return if flag is * NULL. */ }; /* While getopt.h is a glibc extension, the following are newlib extensions. * They are optionally included via the __need_getopt_newlib flag. */ #ifdef __need_getopt_newlib /* macros defined by this include file */ #define NO_ARG no_argument #define REQUIRED_ARG required_argument #define OPTIONAL_ARG optional_argument /* The GETOPT_DATA_INITIALIZER macro is used to initialize a statically- allocated variable of type struct getopt_data. */ #define GETOPT_DATA_INITIALIZER { 0, 0, 0, 0, 0, 0, 0 } /* These #defines are to make accessing the reentrant functions easier. */ #define getopt_r __getopt_r #define getopt_long_r __getopt_long_r #define getopt_long_only_r __getopt_long_only_r /* The getopt_data structure is for reentrancy. Its members are similar to the externally-defined variables. */ typedef struct getopt_data { char *optarg; int optind, opterr, optopt, optwhere; int permute_from, num_nonopts; } getopt_data; #endif /* __need_getopt_newlib */ /* externally-defined variables */ extern char *optarg; extern int optind; extern int opterr; extern int optopt; /* function prototypes */ int getopt(int __argc, char *const __argv[], const char *__optstring); int getopt_long(int __argc, char *const __argv[], const char *__shortopts, const struct option *__longopts, int *__longind); int getopt_long_only(int __argc, char *const __argv[], const char *__shortopts, const struct option *__longopts, int *__longind); #ifdef __need_getopt_newlib int __getopt_r(int __argc, char * const __argv[], const char *__optstring, struct getopt_data *__data); int __getopt_long_r(int __argc, char * const __argv[], const char *__shortopts, const struct option *__longopts, int *__longind, struct getopt_data *__data); int __getopt_long_only_r(int __argc, char * const __argv[], const char *__shortopts, const struct option *__longopts, int *__longind, struct getopt_data *__data); #endif /* __need_getopt_newlib */ _END_STD_C #endif /* GETOPT_H */ picolibc-1.8.11/libc/include/glob.h000066400000000000000000000077671513574234600170510ustar00rootroot00000000000000/* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Guido van Rossum. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)glob.h 8.1 (Berkeley) 6/2/93 * $FreeBSD: src/include/glob.h,v 1.6 2002/03/23 17:24:53 imp Exp $ */ #ifndef _GLOB_H_ #define _GLOB_H_ #include struct stat; typedef struct { int gl_pathc; /* Count of total paths so far. */ int gl_matchc; /* Count of paths matching pattern. */ int gl_offs; /* Reserved at beginning of gl_pathv. */ int gl_flags; /* Copy of flags parameter to glob. */ char **gl_pathv; /* List of paths matching pattern. */ /* Copy of errfunc parameter to glob. */ int (*gl_errfunc)(const char *, int); /* * Alternate filesystem access methods for glob; replacement * versions of closedir(3), readdir(3), opendir(3), stat(2) * and lstat(2). */ void (*gl_closedir)(void *); struct dirent *(*gl_readdir)(void *); void *(*gl_opendir)(const char *); int (*gl_lstat)(const char *, struct stat *); int (*gl_stat)(const char *, struct stat *); } glob_t; #define GLOB_APPEND 0x0001 /* Append to output from previous call. */ #define GLOB_DOOFFS 0x0002 /* Use gl_offs. */ #define GLOB_ERR 0x0004 /* Return on error. */ #define GLOB_MARK 0x0008 /* Append / to matching directories. */ #define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */ #define GLOB_NOSORT 0x0020 /* Don't sort. */ #define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ #define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ #define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ #define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */ #define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ #define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ #define GLOB_LIMIT 0x1000 /* limit number of returned paths */ /* backwards compatibility, this is the old name for this option */ #define GLOB_MAXPATH GLOB_LIMIT #define GLOB_NOSPACE (-1) /* Malloc call failed. */ #define GLOB_ABEND (-2) /* Unignored error. */ #define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */ _BEGIN_STD_C int glob(const char *__restrict, int, int (*)(const char *, int), glob_t *__restrict); void globfree(glob_t *); _END_STD_C #endif /* !_GLOB_H_ */ picolibc-1.8.11/libc/include/grp.h000066400000000000000000000056121513574234600167010ustar00rootroot00000000000000/* $NetBSD: grp.h,v 1.7 1995/04/29 05:30:40 cgd Exp $ */ /*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph * Co. or Unix System Laboratories, Inc. and are reproduced herein with * the permission of UNIX System Laboratories, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)grp.h 8.2 (Berkeley) 1/21/94 */ #ifndef _GRP_H_ #define _GRP_H_ #include #include #if __BSD_VISIBLE #define _PATH_GROUP "/etc/group" #endif _BEGIN_STD_C struct group { char *gr_name; /* group name */ char *gr_passwd; /* group password */ gid_t gr_gid; /* group id */ char **gr_mem; /* group members */ }; #ifndef __INSIDE_CYGWIN__ struct group *getgrgid(gid_t); struct group *getgrnam(const char *); #if __MISC_VISIBLE || __POSIX_VISIBLE int getgrnam_r(const char *, struct group *, char *, size_t, struct group **); int getgrgid_r(gid_t, struct group *, char *, size_t, struct group **); #endif /* __MISC_VISIBLE || __POSIX_VISIBLE */ #if __MISC_VISIBLE || __XSI_VISIBLE >= 4 struct group *getgrent(void); void setgrent(void); void endgrent(void); #endif /* __MISC_VISIBLE || __XSI_VISIBLE >= 4 */ #if __BSD_VISIBLE int initgroups(const char *, gid_t); #endif /* __BSD_VISIBLE */ #endif /* !__INSIDE_CYGWIN__ */ _END_STD_C #endif /* !_GRP_H_ */ picolibc-1.8.11/libc/include/iconv.h000066400000000000000000000035341513574234600172300ustar00rootroot00000000000000/* * Copyright (c) 2003-2004, Artem B. Bityuckiy, SoftMine Corporation. * Rights transferred to Franklin Electronic Publishers. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must 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. */ #ifndef _ICONV_H_ #define _ICONV_H_ #include #define __need_size_t #include #include /* iconv_t: charset conversion descriptor type */ typedef _iconv_t iconv_t; _BEGIN_STD_C iconv_t iconv_open(const char *, const char *); size_t iconv(iconv_t, char **__restrict, size_t *__restrict, char **__restrict, size_t *__restrict); int iconv_close(iconv_t); _END_STD_C #endif /* #ifndef _ICONV_H_ */ picolibc-1.8.11/libc/include/ieeefp.h000066400000000000000000000054331513574234600173470ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _IEEEFP_H_ #define _IEEEFP_H_ #include #include #include _BEGIN_STD_C #if __BSD_VISIBLE /* FLOATING ROUNDING */ typedef int fp_rnd; #define FP_RN 0 /* Round to nearest */ #define FP_RM 1 /* Round down */ #define FP_RP 2 /* Round up */ #define FP_RZ 3 /* Round to zero (trunate) */ fp_rnd fpgetround(void); fp_rnd fpsetround(fp_rnd); /* EXCEPTIONS */ typedef int fp_except; #define FP_X_INV 0x10 /* Invalid operation */ #define FP_X_DX 0x80 /* Divide by zero */ #define FP_X_OFL 0x04 /* Overflow exception */ #define FP_X_UFL 0x02 /* Underflow exception */ #define FP_X_IMP 0x01 /* imprecise exception */ fp_except fpgetmask(void); fp_except fpsetmask(fp_except); fp_except fpgetsticky(void); fp_except fpsetsticky(fp_except); /* INTEGER ROUNDING */ typedef int fp_rdi; #define FP_RDI_TOZ 0 /* Round to Zero */ #define FP_RDI_RD 1 /* Follow float mode */ fp_rdi fpgetroundtoi(void); fp_rdi fpsetroundtoi(fp_rdi); #endif /* __BSD_VISIBLE */ _END_STD_C #endif /* _IEEEFP_H_ */ picolibc-1.8.11/libc/include/inttypes.h000066400000000000000000000227101513574234600177660ustar00rootroot00000000000000/* * Copyright (c) 2004, 2005 by * Ralf Corsepius, Ulm/Germany. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ /** * @file inttypes.h */ #ifndef _INTTYPES_H #define _INTTYPES_H #include #include #include _BEGIN_STD_C #if __BSD_VISIBLE #include #endif typedef struct { intmax_t quot; intmax_t rem; } imaxdiv_t; /* * Try to avoid defining wchar_t by using __WCHAR_TYPE__ when * available. */ #ifdef __WCHAR_TYPE__ typedef __WCHAR_TYPE__ _wchar_t; #else #define __need_wchar_t #include typdef wchar_t _wchar_t; #endif #define __STRINGIFY(a) #a /* 8-bit types */ #define __PRI8(x) __INT8 __STRINGIFY(x) #define __PRI8LEAST(x) __LEAST8 __STRINGIFY(x) #define __PRI8FAST(x) __FAST8 __STRINGIFY(x) /* NOTICE: scanning 8-bit types requires use of the hh specifier * which is only supported on picolibc platforms that * are built with C99 I/O format support enabled. If the flag in * picolibc.h hasn't been set during configuration to indicate this, the 8-bit * scanning format macros are disabled here as they result in undefined * behaviour which can include memory overwrite. Overriding the flag after the * library has been built is not recommended as it will expose the underlying * undefined behaviour. */ #if defined(__IO_C99_FORMATS) #define __SCN8(x) __INT8 __STRINGIFY(x) #define __SCN8LEAST(x) __LEAST8 __STRINGIFY(x) #define __SCN8FAST(x) __FAST8 __STRINGIFY(x) #endif /* __IO_C99_FORMATS */ #define PRId8 __PRI8(d) #define PRIi8 __PRI8(i) #define PRIo8 __PRI8(o) #define PRIu8 __PRI8(u) #define PRIx8 __PRI8(x) #define PRIX8 __PRI8(X) /* Macros below are only enabled for a newlib built with C99 I/O format support. */ #if defined(__IO_C99_FORMATS) #define SCNd8 __SCN8(d) #define SCNi8 __SCN8(i) #define SCNo8 __SCN8(o) #define SCNu8 __SCN8(u) #define SCNx8 __SCN8(x) #endif /* __IO_C99_FORMATS */ #define PRIdLEAST8 __PRI8LEAST(d) #define PRIiLEAST8 __PRI8LEAST(i) #define PRIoLEAST8 __PRI8LEAST(o) #define PRIuLEAST8 __PRI8LEAST(u) #define PRIxLEAST8 __PRI8LEAST(x) #define PRIXLEAST8 __PRI8LEAST(X) /* Macros below are only enabled for a newlib built with C99 I/O format support. */ #if defined(__IO_C99_FORMATS) #define SCNdLEAST8 __SCN8LEAST(d) #define SCNiLEAST8 __SCN8LEAST(i) #define SCNoLEAST8 __SCN8LEAST(o) #define SCNuLEAST8 __SCN8LEAST(u) #define SCNxLEAST8 __SCN8LEAST(x) #endif /* __IO_C99_FORMATS */ #define PRIdFAST8 __PRI8FAST(d) #define PRIiFAST8 __PRI8FAST(i) #define PRIoFAST8 __PRI8FAST(o) #define PRIuFAST8 __PRI8FAST(u) #define PRIxFAST8 __PRI8FAST(x) #define PRIXFAST8 __PRI8FAST(X) /* Macros below are only enabled for a newlib built with C99 I/O format support. */ #if defined(__IO_C99_FORMATS) #define SCNdFAST8 __SCN8FAST(d) #define SCNiFAST8 __SCN8FAST(i) #define SCNoFAST8 __SCN8FAST(o) #define SCNuFAST8 __SCN8FAST(u) #define SCNxFAST8 __SCN8FAST(x) #endif /* __IO_C99_FORMATS */ /* 16-bit types */ #define __PRI16(x) __INT16 __STRINGIFY(x) #define __PRI16LEAST(x) __LEAST16 __STRINGIFY(x) #define __PRI16FAST(x) __FAST16 __STRINGIFY(x) #define __SCN16(x) __INT16 __STRINGIFY(x) #define __SCN16LEAST(x) __LEAST16 __STRINGIFY(x) #define __SCN16FAST(x) __FAST16 __STRINGIFY(x) #define PRId16 __PRI16(d) #define PRIi16 __PRI16(i) #define PRIo16 __PRI16(o) #define PRIu16 __PRI16(u) #define PRIx16 __PRI16(x) #define PRIX16 __PRI16(X) #define SCNd16 __SCN16(d) #define SCNi16 __SCN16(i) #define SCNo16 __SCN16(o) #define SCNu16 __SCN16(u) #define SCNx16 __SCN16(x) #define PRIdLEAST16 __PRI16LEAST(d) #define PRIiLEAST16 __PRI16LEAST(i) #define PRIoLEAST16 __PRI16LEAST(o) #define PRIuLEAST16 __PRI16LEAST(u) #define PRIxLEAST16 __PRI16LEAST(x) #define PRIXLEAST16 __PRI16LEAST(X) #define SCNdLEAST16 __SCN16LEAST(d) #define SCNiLEAST16 __SCN16LEAST(i) #define SCNoLEAST16 __SCN16LEAST(o) #define SCNuLEAST16 __SCN16LEAST(u) #define SCNxLEAST16 __SCN16LEAST(x) #define PRIdFAST16 __PRI16FAST(d) #define PRIiFAST16 __PRI16FAST(i) #define PRIoFAST16 __PRI16FAST(o) #define PRIuFAST16 __PRI16FAST(u) #define PRIxFAST16 __PRI16FAST(x) #define PRIXFAST16 __PRI16FAST(X) #define SCNdFAST16 __SCN16FAST(d) #define SCNiFAST16 __SCN16FAST(i) #define SCNoFAST16 __SCN16FAST(o) #define SCNuFAST16 __SCN16FAST(u) #define SCNxFAST16 __SCN16FAST(x) /* 32-bit types */ #define __PRI32(x) __INT32 __STRINGIFY(x) #define __SCN32(x) __INT32 __STRINGIFY(x) #define __PRI32LEAST(x) __LEAST32 __STRINGIFY(x) #define __SCN32LEAST(x) __LEAST32 __STRINGIFY(x) #define __PRI32FAST(x) __FAST32 __STRINGIFY(x) #define __SCN32FAST(x) __FAST32 __STRINGIFY(x) #define PRId32 __PRI32(d) #define PRIi32 __PRI32(i) #define PRIo32 __PRI32(o) #define PRIu32 __PRI32(u) #define PRIx32 __PRI32(x) #define PRIX32 __PRI32(X) #define SCNd32 __SCN32(d) #define SCNi32 __SCN32(i) #define SCNo32 __SCN32(o) #define SCNu32 __SCN32(u) #define SCNx32 __SCN32(x) #define PRIdLEAST32 __PRI32LEAST(d) #define PRIiLEAST32 __PRI32LEAST(i) #define PRIoLEAST32 __PRI32LEAST(o) #define PRIuLEAST32 __PRI32LEAST(u) #define PRIxLEAST32 __PRI32LEAST(x) #define PRIXLEAST32 __PRI32LEAST(X) #define SCNdLEAST32 __SCN32LEAST(d) #define SCNiLEAST32 __SCN32LEAST(i) #define SCNoLEAST32 __SCN32LEAST(o) #define SCNuLEAST32 __SCN32LEAST(u) #define SCNxLEAST32 __SCN32LEAST(x) #define PRIdFAST32 __PRI32FAST(d) #define PRIiFAST32 __PRI32FAST(i) #define PRIoFAST32 __PRI32FAST(o) #define PRIuFAST32 __PRI32FAST(u) #define PRIxFAST32 __PRI32FAST(x) #define PRIXFAST32 __PRI32FAST(X) #define SCNdFAST32 __SCN32FAST(d) #define SCNiFAST32 __SCN32FAST(i) #define SCNoFAST32 __SCN32FAST(o) #define SCNuFAST32 __SCN32FAST(u) #define SCNxFAST32 __SCN32FAST(x) /* 64-bit types */ #define __PRI64(x) __INT64 __STRINGIFY(x) #define __SCN64(x) __INT64 __STRINGIFY(x) #define __PRI64LEAST(x) __LEAST64 __STRINGIFY(x) #define __SCN64LEAST(x) __LEAST64 __STRINGIFY(x) #define __PRI64FAST(x) __FAST64 __STRINGIFY(x) #define __SCN64FAST(x) __FAST64 __STRINGIFY(x) #if __int64_t_defined #define PRId64 __PRI64(d) #define PRIi64 __PRI64(i) #define PRIo64 __PRI64(o) #define PRIu64 __PRI64(u) #define PRIx64 __PRI64(x) #define PRIX64 __PRI64(X) #define SCNd64 __SCN64(d) #define SCNi64 __SCN64(i) #define SCNo64 __SCN64(o) #define SCNu64 __SCN64(u) #define SCNx64 __SCN64(x) #endif #if __int_least64_t_defined #define PRIdLEAST64 __PRI64LEAST(d) #define PRIiLEAST64 __PRI64LEAST(i) #define PRIoLEAST64 __PRI64LEAST(o) #define PRIuLEAST64 __PRI64LEAST(u) #define PRIxLEAST64 __PRI64LEAST(x) #define PRIXLEAST64 __PRI64LEAST(X) #define SCNdLEAST64 __SCN64LEAST(d) #define SCNiLEAST64 __SCN64LEAST(i) #define SCNoLEAST64 __SCN64LEAST(o) #define SCNuLEAST64 __SCN64LEAST(u) #define SCNxLEAST64 __SCN64LEAST(x) #endif #if __int_fast64_t_defined #define PRIdFAST64 __PRI64FAST(d) #define PRIiFAST64 __PRI64FAST(i) #define PRIoFAST64 __PRI64FAST(o) #define PRIuFAST64 __PRI64FAST(u) #define PRIxFAST64 __PRI64FAST(x) #define PRIXFAST64 __PRI64FAST(X) #define SCNdFAST64 __SCN64FAST(d) #define SCNiFAST64 __SCN64FAST(i) #define SCNoFAST64 __SCN64FAST(o) #define SCNuFAST64 __SCN64FAST(u) #define SCNxFAST64 __SCN64FAST(x) #endif /* max-bit types */ #if __have_long64 #define __PRIMAX(x) __STRINGIFY(l##x) #define __SCNMAX(x) __STRINGIFY(l##x) #elif __have_longlong64 #define __PRIMAX(x) __STRINGIFY(ll##x) #define __SCNMAX(x) __STRINGIFY(ll##x) #else #define __PRIMAX(x) __STRINGIFY(x) #define __SCNMAX(x) __STRINGIFY(x) #endif #define PRIdMAX __PRIMAX(d) #define PRIiMAX __PRIMAX(i) #define PRIoMAX __PRIMAX(o) #define PRIuMAX __PRIMAX(u) #define PRIxMAX __PRIMAX(x) #define PRIXMAX __PRIMAX(X) #define SCNdMAX __SCNMAX(d) #define SCNiMAX __SCNMAX(i) #define SCNoMAX __SCNMAX(o) #define SCNuMAX __SCNMAX(u) #define SCNxMAX __SCNMAX(x) /* ptr types */ #if defined(_INTPTR_EQ_LONGLONG) #define __PRIPTR(x) __STRINGIFY(ll##x) #define __SCNPTR(x) __STRINGIFY(ll##x) #elif defined(_INTPTR_EQ_LONG) #define __PRIPTR(x) __STRINGIFY(l##x) #define __SCNPTR(x) __STRINGIFY(l##x) #else #define __PRIPTR(x) __STRINGIFY(x) #define __SCNPTR(x) __STRINGIFY(x) #endif #define PRIdPTR __PRIPTR(d) #define PRIiPTR __PRIPTR(i) #define PRIoPTR __PRIPTR(o) #define PRIuPTR __PRIPTR(u) #define PRIxPTR __PRIPTR(x) #define PRIXPTR __PRIPTR(X) #define SCNdPTR __SCNPTR(d) #define SCNiPTR __SCNPTR(i) #define SCNoPTR __SCNPTR(o) #define SCNuPTR __SCNPTR(u) #define SCNxPTR __SCNPTR(x) intmax_t imaxabs(intmax_t); imaxdiv_t imaxdiv(intmax_t __numer, intmax_t __denomer); intmax_t strtoimax(const char *__restrict, char **__restrict, int); uintmax_t strtoumax(const char * __restrict, char ** __restrict, int); intmax_t wcstoimax(const _wchar_t *__restrict, _wchar_t **__restrict, int); uintmax_t wcstoumax(const _wchar_t * __restrict, _wchar_t ** __restrict, int); #if __BSD_VISIBLE intmax_t strtoimax_l(const char *__restrict, char **_restrict, int, locale_t); uintmax_t strtoumax_l(const char * __restrict, char **_restrict, int, locale_t); intmax_t wcstoimax_l(const _wchar_t *__restrict, _wchar_t **_restrict, int, locale_t); uintmax_t wcstoumax_l(const _wchar_t * __restrict, _wchar_t **_restrict, int, locale_t); #endif _END_STD_C #endif picolibc-1.8.11/libc/include/langinfo.h000066400000000000000000000112321513574234600177010ustar00rootroot00000000000000/*- * Copyright (c) 2001 Alexey Zelkin * 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/include/langinfo.h,v 1.5 2002/03/23 17:24:53 imp Exp $ */ #ifndef _LANGINFO_H_ #define _LANGINFO_H_ #include #include #if __POSIX_VISIBLE >= 200809 #include #endif #ifndef _NL_ITEM_DECLARED typedef __nl_item nl_item; #define _NL_ITEM_DECLARED #endif enum { /* POSIX and BSD defined items have to stick to the original values to maintain backward compatibility. */ _NL_CTYPE_CODESET_NAME = 0, /* codeset name */ #define CODESET _NL_CTYPE_CODESET_NAME D_T_FMT, /* string for formatting date and time */ #define D_T_FMT D_T_FMT D_FMT, /* date format string */ #define D_FMT D_FMT T_FMT, /* time format string */ #define T_FMT T_FMT T_FMT_AMPM, /* a.m. or p.m. time formatting string */ #define T_FMT_AMPM T_FMT_AMPM AM_STR, /* Ante Meridian affix */ #define AM_STR AM_STR PM_STR, /* Post Meridian affix */ #define PM_STR PM_STR /* week day names */ DAY_1, #define DAY_1 DAY_1 DAY_2, #define DAY_2 DAY_2 DAY_3, #define DAY_3 DAY_3 DAY_4, #define DAY_4 DAY_4 DAY_5, #define DAY_5 DAY_5 DAY_6, #define DAY_6 DAY_6 DAY_7, #define DAY_7 DAY_7 /* abbreviated week day names */ ABDAY_1, #define ABDAY_1 ABDAY_1 ABDAY_2, #define ABDAY_2 ABDAY_2 ABDAY_3, #define ABDAY_3 ABDAY_3 ABDAY_4, #define ABDAY_4 ABDAY_4 ABDAY_5, #define ABDAY_5 ABDAY_5 ABDAY_6, #define ABDAY_6 ABDAY_6 ABDAY_7, #define ABDAY_7 ABDAY_7 /* month names */ MON_1, #define MON_1 MON_1 MON_2, #define MON_2 MON_2 MON_3, #define MON_3 MON_3 MON_4, #define MON_4 MON_4 MON_5, #define MON_5 MON_5 MON_6, #define MON_6 MON_6 MON_7, #define MON_7 MON_7 MON_8, #define MON_8 MON_8 MON_9, #define MON_9 MON_9 MON_10, #define MON_10 MON_10 MON_11, #define MON_11 MON_11 MON_12, #define MON_12 MON_12 /* abbreviated month names */ ABMON_1, #define ABMON_1 ABMON_1 ABMON_2, #define ABMON_2 ABMON_2 ABMON_3, #define ABMON_3 ABMON_3 ABMON_4, #define ABMON_4 ABMON_4 ABMON_5, #define ABMON_5 ABMON_5 ABMON_6, #define ABMON_6 ABMON_6 ABMON_7, #define ABMON_7 ABMON_7 ABMON_8, #define ABMON_8 ABMON_8 ABMON_9, #define ABMON_9 ABMON_9 ABMON_10, #define ABMON_10 ABMON_10 ABMON_11, #define ABMON_11 ABMON_11 ABMON_12, #define ABMON_12 ABMON_12 ERA, /* era description segments */ #define ERA ERA ERA_D_FMT, /* era date format string */ #define ERA_D_FMT ERA_D_FMT ERA_D_T_FMT, /* era date and time format string */ #define ERA_D_T_FMT ERA_D_T_FMT ERA_T_FMT, /* era time format string */ #define ERA_T_FMT ERA_T_FMT ALT_DIGITS, /* alternative symbols for digits */ #define ALT_DIGITS ALT_DIGITS RADIXCHAR, /* radix char */ #define RADIXCHAR RADIXCHAR THOUSEP, /* separator for thousands */ #define THOUSEP THOUSEP YESEXPR, /* affirmative response expression */ #define YESEXPR YESEXPR NOEXPR, /* negative response expression */ #define NOEXPR NOEXPR YESSTR, /* affirmative response for yes/no queries */ #define YESSTR YESSTR NOSTR, /* negative response for yes/no queries */ #define NOSTR NOSTR CRNCYSTR, /* currency symbol */ #define CRNCYSTR CRNCYSTR }; _BEGIN_STD_C char *nl_langinfo(nl_item); #if __POSIX_VISIBLE >= 200809 char *nl_langinfo_l(nl_item, locale_t); #endif _END_STD_C #endif /* !_LANGINFO_H_ */ picolibc-1.8.11/libc/include/libgen.h000066400000000000000000000014621513574234600173500ustar00rootroot00000000000000/* Copyright (c) 2005 Jeff Johnston */ /* * libgen.h - defined by XPG4 */ #ifndef _LIBGEN_H_ #define _LIBGEN_H_ #include _BEGIN_STD_C /* There are two common basename variants. If you do NOT #include and you do #define _GNU_SOURCE #include you get the GNU version. Otherwise you get the POSIX versionfor which you should #include i for the function prototype. POSIX requires that #undef basename will still let you invoke the underlying function. However, this also implies that the POSIX version is used in this case. That's made sure here. */ #undef basename #define basename __xpg_basename char *basename(char *) __asm__(__ASMNAME("basename")); char *dirname(char *); _END_STD_C #endif /* _LIBGEN_H_ */ picolibc-1.8.11/libc/include/limits.h000066400000000000000000000071271513574234600174150ustar00rootroot00000000000000/* Copyright (c) 2002 Jeff Johnston */ #ifndef _LIBC_LIMITS_H_ #define _LIBC_LIMITS_H_ 1 #include #include #ifndef __MB_LEN_MAX #ifdef __MB_CAPABLE #define __MB_LEN_MAX 8 #else #define __MB_LEN_MAX 1 #endif #endif #define MB_LEN_MAX __MB_LEN_MAX /* Maximum number of positional arguments, if __IO_POS_ARGS. */ #ifndef NL_ARGMAX #define NL_ARGMAX 32 #endif /* if do not have #include_next support, then we have to define the limits here. */ #if !defined __GNUC__ || __GNUC__ < 2 #ifndef _LIMITS_H #define _LIMITS_H 1 /* Number of bits in a `char'. */ #undef CHAR_BIT #define CHAR_BIT 8 /* Minimum and maximum values a `signed char' can hold. */ #undef SCHAR_MIN #define SCHAR_MIN (-128) #undef SCHAR_MAX #define SCHAR_MAX 127 /* Maximum value an `unsigned char' can hold. (Minimum is 0). */ #undef UCHAR_MAX #define UCHAR_MAX 255 /* Minimum and maximum values a `char' can hold. */ #ifdef __CHAR_UNSIGNED__ #undef CHAR_MIN #define CHAR_MIN 0 #undef CHAR_MAX #define CHAR_MAX 255 #else #undef CHAR_MIN #define CHAR_MIN (-128) #undef CHAR_MAX #define CHAR_MAX 127 #endif /* Minimum and maximum values a `signed short int' can hold. */ #undef SHRT_MIN /* For the sake of 16 bit hosts, we may not use -32768 */ #define SHRT_MIN (-32767 - 1) #undef SHRT_MAX #define SHRT_MAX 32767 /* Maximum value an `unsigned short int' can hold. (Minimum is 0). */ #undef USHRT_MAX #define USHRT_MAX 65535 /* Minimum and maximum values a `signed int' can hold. */ #ifndef __INT_MAX__ #define __INT_MAX__ 2147483647 #endif #undef INT_MIN #define INT_MIN (-INT_MAX - 1) #undef INT_MAX #define INT_MAX __INT_MAX__ /* Maximum value an `unsigned int' can hold. (Minimum is 0). */ #undef UINT_MAX #define UINT_MAX (INT_MAX * 2U + 1) /* Minimum and maximum values a `signed long int' can hold. (Same as `int'). */ #ifndef __LONG_MAX__ #if defined(__alpha__) || (defined(__sparc__) && defined(__arch64__)) || defined(__sparcv9) #define __LONG_MAX__ 9223372036854775807L #else #define __LONG_MAX__ 2147483647L #endif /* __alpha__ || sparc64 */ #endif #undef LONG_MIN #define LONG_MIN (-LONG_MAX - 1) #undef LONG_MAX #define LONG_MAX __LONG_MAX__ /* Maximum value an `unsigned long int' can hold. (Minimum is 0). */ #undef ULONG_MAX #define ULONG_MAX (LONG_MAX * 2UL + 1) #ifndef __LONG_LONG_MAX__ #define __LONG_LONG_MAX__ 9223372036854775807LL #endif #if __ISO_C_VISIBLE >= 1999 /* Minimum and maximum values a `signed long long int' can hold. */ #undef LLONG_MIN #define LLONG_MIN (-LLONG_MAX - 1) #undef LLONG_MAX #define LLONG_MAX __LONG_LONG_MAX__ /* Maximum value an `unsigned long long int' can hold. (Minimum is 0). */ #undef ULLONG_MAX #define ULLONG_MAX (LLONG_MAX * 2ULL + 1) #endif #if __GNU_VISIBLE /* Minimum and maximum values a `signed long long int' can hold. */ #undef LONG_LONG_MIN #define LONG_LONG_MIN (-LONG_LONG_MAX - 1) #undef LONG_LONG_MAX #define LONG_LONG_MAX __LONG_LONG_MAX__ /* Maximum value an `unsigned long long int' can hold. (Minimum is 0). */ #undef ULONG_LONG_MAX #define ULONG_LONG_MAX (LONG_LONG_MAX * 2ULL + 1) #endif #endif /* _LIMITS_H */ #endif /* GCC 2. */ #endif /* !_LIBC_LIMITS_H_ */ /* * Placing this outside of the above condition means that this will * get run even from another picolibc provided limits.h file down the * include chain. This also to see if the compiler limits.h has * already been included as some clang configurations do that. */ #if defined __GNUC__ && !defined _GCC_LIMITS_H_ #ifdef __clang__ #ifndef __GLIBC_USE #define __GLIBC_USE(x) 1 #endif #endif #include_next #endif /* __GNUC__ && !_GCC_LIMITS_H_ */ picolibc-1.8.11/libc/include/locale.h000066400000000000000000000073421513574234600173520ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* locale.h Values appropriate for the formatting of monetary and other numberic quantities. */ #ifndef _LOCALE_H_ #define _LOCALE_H_ #include #define __need_NULL #include #define LC_ALL 0 #define LC_COLLATE 1 #define LC_CTYPE 2 #define LC_MONETARY 3 #define LC_NUMERIC 4 #define LC_TIME 5 #define _LC_MESSAGES 6 #define _LC_LAST 7 _BEGIN_STD_C struct lconv { char *decimal_point; char *thousands_sep; char *grouping; char *int_curr_symbol; char *currency_symbol; char *mon_decimal_point; char *mon_thousands_sep; char *mon_grouping; char *positive_sign; char *negative_sign; char int_frac_digits; char frac_digits; char p_cs_precedes; char p_sep_by_space; char n_cs_precedes; char n_sep_by_space; char p_sign_posn; char n_sign_posn; char int_n_cs_precedes; char int_n_sep_by_space; char int_n_sign_posn; char int_p_cs_precedes; char int_p_sep_by_space; char int_p_sign_posn; }; char *setlocale(int, const char *); struct lconv *localeconv(void); #if __POSIX_VISIBLE >= 200809 || defined(_LIBC) #include #define LC_MESSAGES _LC_MESSAGES #define LC_COLLATE_MASK (1 << LC_COLLATE) #define LC_CTYPE_MASK (1 << LC_CTYPE) #define LC_MONETARY_MASK (1 << LC_MONETARY) #define LC_NUMERIC_MASK (1 << LC_NUMERIC) #define LC_TIME_MASK (1 << LC_TIME) #define LC_MESSAGES_MASK (1 << LC_MESSAGES) #define LC_ALL_MASK \ (LC_COLLATE_MASK | LC_CTYPE_MASK | LC_MONETARY_MASK | LC_NUMERIC_MASK | LC_TIME_MASK \ | LC_MESSAGES_MASK) #define LC_GLOBAL_LOCALE ((locale_t) - 1) locale_t newlocale(int, const char *, locale_t); void freelocale(locale_t); locale_t duplocale(locale_t); locale_t uselocale(locale_t); #endif #if __POSIX_VISIBLE >= 202405 || __MISC_VISIBLE const char *getlocalename_l(int, locale_t); #endif _END_STD_C #endif /* _LOCALE_H_ */ picolibc-1.8.11/libc/include/machine/000077500000000000000000000000001513574234600173405ustar00rootroot00000000000000picolibc-1.8.11/libc/include/machine/CMakeLists.txt000066400000000000000000000034501513574234600221020ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_headers(machine ansi.h _arc4random.h _default_types.h _endian.h endian.h fastmath.h fenv.h fenv-softfloat.h ieeefp.h malloc.h math.h param.h setjmp.h stdlib.h termios.h _time.h time.h _types.h types.h ) picolibc-1.8.11/libc/include/machine/_arc4random.h000066400000000000000000000020721513574234600217030ustar00rootroot00000000000000/* $OpenBSD: arc4random.c,v 1.52 2015/01/16 16:48:51 deraadt Exp $ */ /* * Copyright (c) 1996, David Mazieres * Copyright (c) 2008, Damien Miller * Copyright (c) 2013, Markus Friedl * Copyright (c) 2014, Theo de Raadt * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* Use default implementation, see arc4random.h */ picolibc-1.8.11/libc/include/machine/_default_types.h000066400000000000000000000211131513574234600225160ustar00rootroot00000000000000/* * Copyright (c) 2007 Patrick Mansfield */ #ifndef _MACHINE__DEFAULT_TYPES_H #define _MACHINE__DEFAULT_TYPES_H #include /* * Guess on types by examining *_MIN / *_MAX defines. */ #if defined(__INT_MAX__) && defined(__LONG_MAX__) && defined(__SCHAR_MAX__) && defined(__SHRT_MAX__) /* GCC >= 3.3.0 has ____ implicitly defined. */ #define __EXP(x) __##x##__ #else /* Fall back to POSIX versions from */ #define __EXP(x) x #include #endif /* Check if "long long" is 64bit wide */ /* Modern GCCs provide __LONG_LONG_MAX__, SUSv3 wants LLONG_MAX */ #if (defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff)) \ || (defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff)) #define __have_longlong64 1 #endif /* Check if "long" is 64bit or 32bit wide */ #if __EXP(LONG_MAX) > 0x7fffffff #define __have_long64 1 #elif __EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__) #define __have_long32 1 #endif /* Determine the width of integers if the compiler doesn't provide __X_WIDTH__ macros. */ #if !defined(__SCHAR_WIDTH__) #if __EXP(SCHAR_MAX) == 0x7f #define __SCHAR_WIDTH__ 8 #elif __EXP(SCHAR_MAX) == 0x7fff #define __SCHAR_WIDTH__ 16 #elif __EXP(SCHAR_MAX) == 0x7fffffffL #define __SCHAR_WIDTH__ 32 #endif #endif #if !defined(__SHRT_WIDTH__) #if __EXP(SHRT_MAX) == 0x7fff #define __SHRT_WIDTH__ 16 #elif __EXP(SHRT_MAX) == 0x7fffffffL #define __SHRT_WIDTH__ 32 #endif #endif #if !defined(__INT_WIDTH__) #if __EXP(INT_MAX) == 0x7fff #define __INT_WIDTH__ 16 #elif __EXP(INT_MAX) == 0x7fffffffL #define __INT_WIDTH__ 32 #elif __EXP(INT_MAX) > 0x7fffffffL #define __INT_WIDTH__ 64 #endif #endif #if !defined(__LONG_WIDTH__) #if __have_long32 #define __LONG_WIDTH__ 32 #elif __have_long64 #define __LONG_WIDTH__ 64 #endif #endif #if !defined(__LONG_LONG_WIDTH__) #if __have_longlong64 #define __LONG_LONG_WIDTH__ 64 #endif #endif /* Determine the size of types if the compiler doesn't provide __SIZEOF_X__ macros. */ #if !defined(__SIZEOF_SHORT__) #if __SHRT_WIDTH__ == 16 #define __SIZEOF_SHORT__ 2 #elif __SHRT_WIDTH__ == 32 #define __SIZEOF_SHORT__ 4 #endif #endif #if !defined(__SIZEOF_INT__) #if __INT_WIDTH__ == 16 #define __SIZEOF_INT__ 2 #elif __INT_WIDTH__ == 32 #define __SIZEOF_INT__ 4 #elif __INT_WIDTH__ == 64 #define __SIZEOF_INT__ 8 #endif #endif #ifndef __SIZEOF_LONG__ #if __LONG_WIDTH__ == 32 #define __SIZEOF_LONG__ 4 #elif __LONG_WIDTH__ == 64 #define __SIZEOF_LONG__ 8 #endif #endif #if (!defined(__SIZEOF_LONG_LONG__) && __LONG_LONG_WIDTH__ == 64) #define __SIZEOF_LONG_LONG__ 8 #endif #if (!defined(__SIZEOF_FLOAT__) && defined(__FLT_MANT_DIG__)) #if __FLT_MANT_DIG__ == 24 #define __SIZEOF_FLOAT__ 4 #else #error "unexpected __FLT_MANT_DIG__ value" #endif #endif #if (!defined(__SIZEOF_DOUBLE__) && defined(__DBL_MANT_DIG__)) #if __DBL_MANT_DIG__ == 53 #define __SIZEOF_DOUBLE__ 8 #else #error "unexpected __DBL_MANT_DIG__ value" #endif #endif #if (!defined(__HAVE_LONG_DOUBLE) && defined(__LDBL_MANT_DIG__)) #if __LDBL_MANT_DIG__ == 53 #define __SIZEOF_LONG_DOUBLE__ 8 #elif __LDBL_MANT_DIG__ == 64 || __LDBL_MANT_DIG__ == 113 #define __SIZEOF_LONG_DOUBLE__ 16 #else #error "unexpected __LDBL_MANT_DIG__ values" #endif #endif #ifdef __cplusplus extern "C" { #endif /* Select type of fixed width integers if the compiler doesn't specify them. */ #if !defined(__INT8_TYPE__) && __SCHAR_WIDTH__ == 8 #define __INT8_TYPE__ signed char #endif #if !defined(__UINT8_TYPE__) && __SCHAR_WIDTH__ == 8 #define __UINT8_TYPE__ unsigned char #endif #if !defined(__INT16_TYPE__) #if __INT_WIDTH__ == 16 #define __INT16_TYPE__ int #elif __SHRT_WIDTH__ == 16 #define __INT16_TYPE__ short #elif __SCHAR_WIDTH__ == 16 #define __INT16_TYPE__ signed char #if !defined(__UINT16_TYPE__) #define __UINT16_TYPE__ unsigned char #endif #endif #endif #if !defined(__UINT16_TYPE__) && defined(__INT16_TYPE__) #define __UINT16_TYPE__ unsigned __INT16_TYPE__ #endif #if !defined(__INT32_TYPE__) #if __INT_WIDTH__ == 32 #define __INT32_TYPE__ int #elif __LONG_WIDTH__ == 32 #define __INT32_TYPE__ long #elif __SHRT_WIDTH__ == 32 #define __INT32_TYPE__ short #elif __SCHAR_WIDTH__ == 32 #define __INT32_TYPE__ signed char #if !defined(__UINT32_TYPE__) #define __UINT32_TYPE__ unsigned char #endif #endif #endif #if !defined(__UINT32_TYPE__) && defined(__INT32_TYPE__) #define __UINT32_TYPE__ unsigned __INT32_TYPE__ #endif #if !defined(__INT64_TYPE__) #if __LONG_WIDTH__ == 64 #define __INT64_TYPE__ long #elif __LONG_LONG_WIDTH__ == 64 #define __INT64_TYPE__ long long #endif #endif #if !defined(__UINT64_TYPE__) && defined(__INT64_TYPE__) #define __UINT64_TYPE__ unsigned __INT64_TYPE__ #endif #if defined(__GNUC__) && !__GNUC_PREREQ(4, 5) #ifndef __INTPTR_TYPE__ #define __INTPTR_TYPE__ long int #endif #ifndef __UINTPTR_TYPE__ #define __UINTPTR_TYPE__ long unsigned int #endif #endif #ifdef __INT8_TYPE__ typedef __INT8_TYPE__ __int8_t; #define ___int8_t_defined 1 #endif #ifdef __UINT8_TYPE__ typedef __UINT8_TYPE__ __uint8_t; #endif #ifdef __INT16_TYPE__ typedef __INT16_TYPE__ __int16_t; #define ___int16_t_defined 1 #endif #ifdef __UINT16_TYPE__ typedef __UINT16_TYPE__ __uint16_t; #endif #ifdef __INT32_TYPE__ typedef __INT32_TYPE__ __int32_t; #define ___int32_t_defined 1 #endif #ifdef __UINT32_TYPE__ typedef __UINT32_TYPE__ __uint32_t; #endif #ifdef __INT64_TYPE__ typedef __INT64_TYPE__ __int64_t; #define ___int64_t_defined 1 #endif #ifdef __UINT64_TYPE__ typedef __UINT64_TYPE__ __uint64_t; #endif #ifdef __INT_LEAST8_TYPE__ typedef __INT_LEAST8_TYPE__ __int_least8_t; #ifdef __UINT_LEAST8_TYPE__ typedef __UINT_LEAST8_TYPE__ __uint_least8_t; #else typedef unsigned __INT_LEAST8_TYPE__ __uint_least8_t; #endif #define ___int_least8_t_defined 1 #elif defined(___int8_t_defined) typedef __int8_t __int_least8_t; typedef __uint8_t __uint_least8_t; #define ___int_least8_t_defined 1 #elif defined(___int16_t_defined) typedef __int16_t __int_least8_t; typedef __uint16_t __uint_least8_t; #define ___int_least8_t_defined 1 #elif defined(___int32_t_defined) typedef __int32_t __int_least8_t; typedef __uint32_t __uint_least8_t; #define ___int_least8_t_defined 1 #elif defined(___int64_t_defined) typedef __int64_t __int_least8_t; typedef __uint64_t __uint_least8_t; #define ___int_least8_t_defined 1 #endif #ifdef __INT_LEAST16_TYPE__ typedef __INT_LEAST16_TYPE__ __int_least16_t; #ifdef __UINT_LEAST16_TYPE__ typedef __UINT_LEAST16_TYPE__ __uint_least16_t; #else typedef unsigned __INT_LEAST16_TYPE__ __uint_least16_t; #endif #define ___int_least16_t_defined 1 #elif defined(___int16_t_defined) typedef __int16_t __int_least16_t; typedef __uint16_t __uint_least16_t; #define ___int_least16_t_defined 1 #elif defined(___int32_t_defined) typedef __int32_t __int_least16_t; typedef __uint32_t __uint_least16_t; #define ___int_least16_t_defined 1 #elif defined(___int64_t_defined) typedef __int64_t __int_least16_t; typedef __uint64_t __uint_least16_t; #define ___int_least16_t_defined 1 #endif #ifdef __INT_LEAST32_TYPE__ typedef __INT_LEAST32_TYPE__ __int_least32_t; #ifdef __UINT_LEAST32_TYPE__ typedef __UINT_LEAST32_TYPE__ __uint_least32_t; #else typedef unsigned __INT_LEAST32_TYPE__ __uint_least32_t; #endif #define ___int_least32_t_defined 1 #elif defined(___int32_t_defined) typedef __int32_t __int_least32_t; typedef __uint32_t __uint_least32_t; #define ___int_least32_t_defined 1 #elif defined(___int64_t_defined) typedef __int64_t __int_least32_t; typedef __uint64_t __uint_least32_t; #define ___int_least32_t_defined 1 #endif #ifdef __INT_LEAST64_TYPE__ typedef __INT_LEAST64_TYPE__ __int_least64_t; #ifdef __UINT_LEAST64_TYPE__ typedef __UINT_LEAST64_TYPE__ __uint_least64_t; #else typedef unsigned __INT_LEAST64_TYPE__ __uint_least64_t; #endif #define ___int_least64_t_defined 1 #elif defined(___int64_t_defined) typedef __int64_t __int_least64_t; typedef __uint64_t __uint_least64_t; #define ___int_least64_t_defined 1 #endif #if defined(__INTMAX_TYPE__) typedef __INTMAX_TYPE__ __intmax_t; #elif __have_longlong64 typedef signed long long __intmax_t; #else typedef signed long __intmax_t; #endif #if defined(__UINTMAX_TYPE__) typedef __UINTMAX_TYPE__ __uintmax_t; #elif __have_longlong64 typedef unsigned long long __uintmax_t; #else typedef unsigned long __uintmax_t; #endif #ifdef __INTPTR_TYPE__ typedef __INTPTR_TYPE__ __intptr_t; #ifdef __UINTPTR_TYPE__ typedef __UINTPTR_TYPE__ __uintptr_t; #else typedef unsigned __INTPTR_TYPE__ __uintptr_t; #endif #elif defined(__PTRDIFF_TYPE__) typedef __PTRDIFF_TYPE__ __intptr_t; typedef unsigned __PTRDIFF_TYPE__ __uintptr_t; #else typedef long __intptr_t; typedef unsigned long __uintptr_t; #endif #undef __EXP #ifdef __cplusplus } #endif #endif /* _MACHINE__DEFAULT_TYPES_H */ picolibc-1.8.11/libc/include/machine/_endian.h000066400000000000000000000013161513574234600211070ustar00rootroot00000000000000/* Copyright (c) 2016 Sebastian Huber */ #ifndef __MACHINE_ENDIAN_H__ #error "must be included via " #endif /* !__MACHINE_ENDIAN_H__ */ #ifdef __PPC__ /* Get rid of GCC builtin defines on PowerPC */ #ifdef _BIG_ENDIAN #undef _BIG_ENDIAN #endif #ifdef _LITTLE_ENDIAN #undef _LITTLE_ENDIAN #endif #endif /* __PPC__ */ #ifndef _LITTLE_ENDIAN #define _LITTLE_ENDIAN 1234 #endif #ifndef _BIG_ENDIAN #define _BIG_ENDIAN 4321 #endif #ifndef _PDP_ENDIAN #define _PDP_ENDIAN 3412 #endif #ifndef _BYTE_ORDER #if defined(__IEEE_LITTLE_ENDIAN) || defined(__IEEE_BYTES_LITTLE_ENDIAN) #define _BYTE_ORDER _LITTLE_ENDIAN #else #define _BYTE_ORDER _BIG_ENDIAN #endif #endif picolibc-1.8.11/libc/include/machine/_time.h000066400000000000000000000002511513574234600206040ustar00rootroot00000000000000/* Copyright (c) 2016 Sebastian Huber */ #ifndef _SYS_TIME_H_ #error "must be included via " #endif /* !_SYS_TIME_H_ */ picolibc-1.8.11/libc/include/machine/_types.h000066400000000000000000000002521513574234600210130ustar00rootroot00000000000000/* * Copyright (c) 2005 Ralf Corsepious */ #ifndef _MACHINE__TYPES_H #define _MACHINE__TYPES_H #include #endif picolibc-1.8.11/libc/include/machine/ansi.h000066400000000000000000000001561513574234600204450ustar00rootroot00000000000000/* Copyright (c) 2001 Jeff Johnston */ /* dummy header file to support BSD compiler */ picolibc-1.8.11/libc/include/machine/endian.h000066400000000000000000000045561513574234600207610ustar00rootroot00000000000000/* Copyright (c) 2004 Jeff Johnston */ #ifndef __MACHINE_ENDIAN_H__ #define __MACHINE_ENDIAN_H__ #include #include #include #if _BYTE_ORDER == _LITTLE_ENDIAN #define _QUAD_HIGHWORD 1 #define _QUAD_LOWWORD 0 #else #define _QUAD_HIGHWORD 0 #define _QUAD_LOWWORD 1 #endif #if __BSD_VISIBLE #define LITTLE_ENDIAN _LITTLE_ENDIAN #define BIG_ENDIAN _BIG_ENDIAN #define PDP_ENDIAN _PDP_ENDIAN #define BYTE_ORDER _BYTE_ORDER #endif #ifdef __GNUC__ #define __bswap16(_x) __builtin_bswap16(_x) #define __bswap32(_x) __builtin_bswap32(_x) #define __bswap64(_x) __builtin_bswap64(_x) #else /* __GNUC__ */ static __inline __uint16_t __bswap16(__uint16_t _x) { return ((__uint16_t)((_x >> 8) | ((_x << 8) & 0xff00))); } static __inline __uint32_t __bswap32(__uint32_t _x) { return ((__uint32_t)((_x >> 24) | ((_x >> 8) & 0xff00) | ((_x << 8) & 0xff0000) | ((_x << 24) & 0xff000000))); } static __inline __uint64_t __bswap64(__uint64_t _x) { return ((__uint64_t)((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) | ((_x >> 8) & 0xff000000) | ((_x << 8) & ((__uint64_t)0xff << 32)) | ((_x << 24) & ((__uint64_t)0xff << 40)) | ((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56)))); } #endif /* !__GNUC__ */ /* endian(3) - similar to linux */ #if _BYTE_ORDER == _LITTLE_ENDIAN #define htobe16(_x) __bswap16(_x) #define htole16(_x) ((__uint16_t)(_x)) #define be16toh(_x) __bswap16(_x) #define le16toh(_x) ((__uint16_t)(_x)) #define htobe32(_x) __bswap32(_x) #define htole32(_x) ((__uint32_t)(_x)) #define be32toh(_x) __bswap32(_x) #define le32toh(_x) ((__uint32_t)(_x)) #define htobe64(_x) __bswap64(_x) #define htole64(_x) ((__uint64_t)(_x)) #define be64toh(_x) __bswap64(_x) #define le64toh(_x) ((__uint64_t)(_x)) #else #define htobe16(_x) ((__uint16_t)(_x)) #define htole16(_x) __bswap16(_x) #define be16toh(_x) ((__uint16_t)(_x)) #define le16toh(_x) __bswap16(_x) #define htobe32(_x) ((__uint32_t)(_x)) #define htole32(_x) __bswap32(_x) #define be32toh(_x) ((__uint32_t)(_x)) #define le32toh(_x) __bswap32(_x) #define htobe64(_x) ((__uint64_t)(_x)) #define htole64(_x) __bswap64(_x) #define be64toh(_x) ((__uint64_t)(_x)) #define le64toh(_x) __bswap64(_x) #endif #endif /* __MACHINE_ENDIAN_H__ */ picolibc-1.8.11/libc/include/machine/fastmath.h000066400000000000000000000062431513574234600213250ustar00rootroot00000000000000/* Copyright (C) 1991 DJ Delorie All rights reserved. Redistribution, modification, and use in source and binary forms is permitted provided that the above copyright notice and following paragraph are duplicated in all such forms. This file is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #ifdef __sysvnecv70_target double EXFUN(fast_sin, (double)); double EXFUN(fast_cos, (double)); double EXFUN(fast_tan, (double)); double EXFUN(fast_asin, (double)); double EXFUN(fast_acos, (double)); double EXFUN(fast_atan, (double)); double EXFUN(fast_sinh, (double)); double EXFUN(fast_cosh, (double)); double EXFUN(fast_tanh, (double)); double EXFUN(fast_asinh, (double)); double EXFUN(fast_acosh, (double)); double EXFUN(fast_atanh, (double)); double EXFUN(fast_abs, (double)); double EXFUN(fast_sqrt, (double)); double EXFUN(fast_exp2, (double)); double EXFUN(fast_exp10, (double)); double EXFUN(fast_expe, (double)); double EXFUN(fast_log10, (double)); double EXFUN(fast_log2, (double)); double EXFUN(fast_loge, (double)); #define sin(x) fast_sin(x) #define cos(x) fast_cos(x) #define tan(x) fast_tan(x) #define asin(x) fast_asin(x) #define acos(x) fast_acos(x) #define atan(x) fast_atan(x) #define sinh(x) fast_sinh(x) #define cosh(x) fast_cosh(x) #define tanh(x) fast_tanh(x) #define asinh(x) fast_asinh(x) #define acosh(x) fast_acosh(x) #define atanh(x) fast_atanh(x) #define abs(x) fast_abs(x) #define sqrt(x) fast_sqrt(x) #define exp2(x) fast_exp2(x) #define exp10(x) fast_exp10(x) #define expe(x) fast_expe(x) #define log10(x) fast_log10(x) #define log2(x) fast_log2(x) #define loge(x) fast_loge(x) /* These functions are in assembler, they really do take floats. This can only be used with a real ANSI compiler */ float EXFUN(fast_sinf, (float)); float EXFUN(fast_cosf, (float)); float EXFUN(fast_tanf, (float)); float EXFUN(fast_asinf, (float)); float EXFUN(fast_acosf, (float)); float EXFUN(fast_atanf, (float)); float EXFUN(fast_sinhf, (float)); float EXFUN(fast_coshf, (float)); float EXFUN(fast_tanhf, (float)); float EXFUN(fast_asinhf, (float)); float EXFUN(fast_acoshf, (float)); float EXFUN(fast_atanhf, (float)); float EXFUN(fast_absf, (float)); float EXFUN(fast_sqrtf, (float)); float EXFUN(fast_exp2f, (float)); float EXFUN(fast_exp10f, (float)); float EXFUN(fast_expef, (float)); float EXFUN(fast_log10f, (float)); float EXFUN(fast_log2f, (float)); float EXFUN(fast_logef, (float)); #define sinf(x) fast_sinf(x) #define cosf(x) fast_cosf(x) #define tanf(x) fast_tanf(x) #define asinf(x) fast_asinf(x) #define acosf(x) fast_acosf(x) #define atanf(x) fast_atanf(x) #define sinhf(x) fast_sinhf(x) #define coshf(x) fast_coshf(x) #define tanhf(x) fast_tanhf(x) #define asinhf(x) fast_asinhf(x) #define acoshf(x) fast_acoshf(x) #define atanhf(x) fast_atanhf(x) #define absf(x) fast_absf(x) #define sqrtf(x) fast_sqrtf(x) #define exp2f(x) fast_exp2f(x) #define exp10f(x) fast_exp10f(x) #define expef(x) fast_expef(x) #define log10f(x) fast_log10f(x) #define log2f(x) fast_log2f(x) #define logef(x) fast_logef(x) /* Override the functions defined in math.h */ #endif /* __sysvnecv70_target */ picolibc-1.8.11/libc/include/machine/fenv-softfloat.h000066400000000000000000000101011513574234600224370ustar00rootroot00000000000000/*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2004-2011 David Schultz * 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$ */ /* * This file implements the functionality of on platforms that * lack an FPU and use softfloat in libc for floating point. To use it, * you must write an that provides the following: * * - a typedef for fenv_t, which may be an integer or struct type * - a typedef for fexcept_t (XXX This file assumes fexcept_t is a * simple integer type containing the exception mask.) * - definitions of FE_* constants for the five exceptions and four * rounding modes in IEEE 754, as described in fenv(3) * - a definition, and the corresponding external symbol, for FE_DFL_ENV * - a macro __set_env(env, flags, mask, rnd), which sets the given fenv_t * from the exception flags, mask, and rounding mode * - macros __env_flags(env), __env_mask(env), and __env_round(env), which * extract fields from an fenv_t * - a definition of __fenv_static * * If the architecture supports an optional FPU, it's recommended that you * define fenv_t and fexcept_t to match the hardware ABI. Otherwise, it * doesn't matter how you define them. */ #include __declare_fenv_inline(int) feclearexcept(int excepts) { (void)excepts; return (0); } __declare_fenv_inline(int) fegetexceptflag(fexcept_t *flagp, int excepts) { (void)excepts; (void)flagp; return (0); } __declare_fenv_inline(int) fesetexceptflag(const fexcept_t *flagp, int excepts) { (void)excepts; (void)flagp; return (0); } __declare_fenv_inline(int) feraiseexcept(int excepts) { return (excepts != 0); } __declare_fenv_inline(int) fesetexcept(int excepts) { return (excepts != 0); } __declare_fenv_inline(int) fetestexcept(int excepts) { (void)excepts; return (0); } __declare_fenv_inline(int) fegetround(void) { return FE_TONEAREST; } __declare_fenv_inline(int) fesetround(int rounding_mode) { if (rounding_mode == FE_TONEAREST) return 0; return 1; } __declare_fenv_inline(int) fegetenv(fenv_t *envp) { (void)envp; return (0); } __declare_fenv_inline(int) feholdexcept(fenv_t *envp) { (void)envp; return (0); } __declare_fenv_inline(int) fesetenv(const fenv_t *envp) { (void)envp; return (0); } __declare_fenv_inline(int) feupdateenv(const fenv_t *envp) { (void)envp; #if defined FE_NOMASK_ENV && FE_ALL_EXCEPT != 0 if (envp == FE_NOMASK_ENV) return 1; #endif return (0); } #if __BSD_VISIBLE __declare_fenv_inline(int) feenableexcept(int __mask) { (void)__mask; return (0); } __declare_fenv_inline(int) fedisableexcept(int __mask) { (void)__mask; return (0); } __declare_fenv_inline(int) fegetexcept(void) { return (0); } #endif /* __BSD_VISIBLE */ picolibc-1.8.11/libc/include/machine/fenv.h000066400000000000000000000077021513574234600204550ustar00rootroot00000000000000/* (c) Copyright 2019 Joel Sherrill 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 COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MACHINE_FENV_H_ #define _MACHINE_FENV_H_ _BEGIN_STD_C /******************************************************************************* * THIS FILE IS A TEMPLATE, INTENDED TO BE USED AS A STARTING POINT FOR * TARGET-SPECIFIC FLOATING-POINT IMPLEMENTATIONS. NOTES BELOW HIGHLIGHT THE * BASICS OF WHAT NEEDS TO BE DEFINED. THE DEFAULT IMPLEMTATION IS * DEGENERATE, WITH ALL FUNCTIONS RETURNING ERROR AND NO EXCEPTIONS AND NO * ROUNDING MODES DEFINED (SINCE NONE ARE SUPPORTED). * THE MACRO VALUES ARE EXAMPLES ONLY, ALTHOUGH TAKEN FROM A WORKING * IMPLEMENTATION. * REMOVE THIS NOTICE WHEN COPYING TO A REAL IMPLEMENTATION, REPLACING IT WITH * ANY TARGET-SPECIFIC NOTES OF INTEREST. THE FENV FUNCTION MAN PAGES POINT TO * THIS FILE AS A MEANS OF DETERMINING A FUNCTIONAL VS. NON-FUNCTIONAL * IMPLEMENTATION. ******************************************************************************/ /* * The following macros are to be defined if the respective exception is * supported by the implementation, each with a unique bit mask: * * FE_DIVBYZERO * FE_INEXACT * FE_INVALID * FE_OVERFLOW * FE_UNDERFLOW * * Other implementation-specific exceptions may be defined, and must start * with FE_ followed by a capital letter. * * FE_ALL_EXCEPT must be defined as the logical OR of all exceptions. */ /* #define FE_DIVBYZERO 0x00000001 #define FE_INEXACT 0x00000002 #define FE_INVALID 0x00000004 #define FE_OVERFLOW 0x00000008 #define FE_UNDERFLOW 0x00000010 #define FE_ALL_EXCEPT \ (FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW) */ /* * The following macros are to be defined if the respective rounding * direction is supported by the implementation via the fegetround() and * fesetround() functions, each with a unique positive value. * * FE_DOWNWARD * FE_TONEAREST * FE_TOWARDZERO * FE_UPWARD * * Other implementation-specific rounding modes may be defined, and must start * with FE_ followed by a capital letter. */ #define FE_TONEAREST 0 /* #define FE_DOWNWARD 1 #define FE_TOWARDZERO 2 #define FE_UPWARD 3 */ /* * The following typedefs are required. These should be defined properly * to support the architecture specific implementation. See the C and * POSIX standards for details: * * fenv_t * fexcept_t */ typedef int fenv_t; typedef int fexcept_t; _END_STD_C #if !defined(__declare_fenv_inline) && defined(__declare_extern_inline) #define __declare_fenv_inline(type) __declare_extern_inline(type) #endif #ifdef __declare_fenv_inline #include #endif #endif /* _MACHINE_FENV_H_ */ picolibc-1.8.11/libc/include/machine/ieeefp.h000066400000000000000000000361271513574234600207570ustar00rootroot00000000000000/* Copyright (C) 1991 DJ Delorie All rights reserved. Redistribution, modification, and use in source and binary forms is permitted provided that the above copyright notice and following paragraph are duplicated in all such forms. This file is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include #ifndef __IEEE_BIG_ENDIAN #ifndef __IEEE_LITTLE_ENDIAN /* This file can define macros to choose variations of the IEEE float format: _FLT_LARGEST_EXPONENT_IS_NORMAL Defined if the float format uses the largest exponent for finite numbers rather than NaN and infinity representations. Such a format cannot represent NaNs or infinities at all, but it's FLT_MAX is twice the IEEE value. _FLT_NO_DENORMALS Defined if the float format does not support IEEE denormals. Every float with a zero exponent is taken to be a zero representation. ??? At the moment, there are no equivalent macros above for doubles and the macros are not fully supported by --enable-newlib-hw-fp. __IEEE_BIG_ENDIAN Defined if the float format is big endian. This is mutually exclusive with __IEEE_LITTLE_ENDIAN. __IEEE_LITTLE_ENDIAN Defined if the float format is little endian. This is mutually exclusive with __IEEE_BIG_ENDIAN. Note that one of __IEEE_BIG_ENDIAN or __IEEE_LITTLE_ENDIAN must be specified for a platform or error will occur. __IEEE_BYTES_LITTLE_ENDIAN This flag is used in conjunction with __IEEE_BIG_ENDIAN to describe a situation whereby multiple words of an IEEE floating point are in big endian order, but the words themselves are little endian with respect to the bytes. _DOUBLE_IS_32BITS This is used on platforms that support double by using the 32-bit IEEE float type. _FLOAT_ARG This represents what type a float arg is passed as. It is used when the type is not promoted to double. __OBSOLETE_MATH_DEFAULT Default value for __OBSOLETE_MATH if that's not set by the user. It should be set here based on predefined feature macros. __OBSOLETE_MATH If set to 1 then some new math code will be disabled and older libm code will be used instead. This is necessary because the new math code does not support all targets, it assumes that the toolchain has ISO C99 support (hexfloat literals, standard fenv semantics), the target has IEEE-754 conforming binary32 float and binary64 double (not mixed endian) representation, standard SNaN representation, double and single precision arithmetics has similar latency and it has no legacy SVID matherr support, only POSIX errno and fenv exception based error handling. */ #if !defined(__IEEE_BIG_ENDIAN) && !defined(__IEEE_LITTLE_ENDIAN) #if defined(__ORDER_BIG_ENDIAN__) && defined(__ORDER_LITTLE_ENDIAN__) \ && defined(__FLOAT_WORD_ORDER__) #if __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__ #define __IEEE_BIG_ENDIAN #else #define __IEEE_LITTLE_ENDIAN #endif #endif #endif #if (defined(__arm__) || defined(__thumb__)) && !defined(__MAVERICK__) /* arm with hard fp and soft dp cannot use new float code */ #if (__ARM_FP & 4) && !(__ARM_FP & 8) #define __OBSOLETE_MATH_DEFAULT_FLOAT 1 #endif /* ARM traditionally used big-endian words; and within those words the byte ordering was big or little endian depending upon the target. Modern floating-point formats are naturally ordered; in this case __VFP_FP__ will be defined, even if soft-float. */ #if defined(__VFP_FP__) || __ARM_FP == 0 #ifdef __ARMEL__ #define __IEEE_LITTLE_ENDIAN #else #define __IEEE_BIG_ENDIAN #endif #else #define __IEEE_BIG_ENDIAN #ifdef __ARMEL__ #define __IEEE_BYTES_LITTLE_ENDIAN #endif #endif #if __ARM_FP != 0 #define _SUPPORTS_ERREXCEPT #endif /* As per ISO/IEC TS 18661 '__FLT_EVAL_METHOD__' will be defined to 16 (if compiling with +fp16 support) so it can't be used by math.h to define float_t and double_t. For values of '__FLT_EVAL_METHOD__' other than 0, 1, 2 the definition of float_t and double_t is implementation-defined. */ #define __DOUBLE_TYPE double #define __FLOAT_TYPE float #endif #if defined(__aarch64__) #if defined(__AARCH64EL__) #define __IEEE_LITTLE_ENDIAN #else #define __IEEE_BIG_ENDIAN #endif #if __ARM_FP != 0 #define _SUPPORTS_ERREXCEPT #else #ifdef __clang__ #include /* Clang accesses FPSR for FLT_ROUNDS with soft float target */ #undef FLT_ROUNDS #define FLT_ROUNDS 1 #endif #endif /* As per ISO/IEC TS 18661 '__FLT_EVAL_METHOD__' will be defined to 16 (if compiling with +fp16 support) so it can't be used by math.h to define float_t and double_t. For values of '__FLT_EVAL_METHOD__' other than 0, 1, 2 the definition of float_t and double_t is implementation-defined. */ #define __DOUBLE_TYPE double #define __FLOAT_TYPE float #endif #ifdef __epiphany__ #define __IEEE_LITTLE_ENDIAN #define Sudden_Underflow 1 #endif #ifdef __hppa__ #define __IEEE_BIG_ENDIAN #endif #ifdef __nds32__ #ifdef __big_endian__ #define __IEEE_BIG_ENDIAN #else #define __IEEE_LITTLE_ENDIAN #endif #endif #ifdef __SPU__ #define __IEEE_BIG_ENDIAN #define isfinite(__y) \ (__extension__({ \ int __cy; \ (sizeof(__y) == sizeof(float)) ? (1) \ : (__cy = fpclassify(__y)) != FP_INFINITE &&__cy != FP_NAN; \ })) #define isinf(__x) ((sizeof(__x) == sizeof(float)) ? (0) : __isinfd(__x)) #define isnan(__x) ((sizeof(__x) == sizeof(float)) ? (0) : __isnand(__x)) /* * Macros for use in ieeefp.h. We can't just define the real ones here * (like those above) as we have name space issues when this is *not* * included via generic the ieeefp.h. */ #define __ieeefp_isnanf(x) 0 #define __ieeefp_isinff(x) 0 #define __ieeefp_finitef(x) 1 #endif #ifdef __sparc__ #ifdef __LITTLE_ENDIAN_DATA__ #define __IEEE_LITTLE_ENDIAN #else #define __IEEE_BIG_ENDIAN #endif #endif #if defined(__m68k__) || defined(__mc68000__) #define __IEEE_BIG_ENDIAN #ifdef __HAVE_68881__ #define _SUPPORTS_ERREXCEPT #endif #endif #if defined(__mc68hc11__) || defined(__mc68hc12__) || defined(__mc68hc1x__) #define __IEEE_BIG_ENDIAN #ifdef __HAVE_SHORT_DOUBLE__ #define _DOUBLE_IS_32BITS #endif #endif #if defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) || defined(__H8500__) \ || defined(__H8300SX__) #define __IEEE_BIG_ENDIAN #define _FLOAT_ARG float #define _DOUBLE_IS_32BITS #endif #if defined(__xc16x__) || defined(__xc16xL__) || defined(__xc16xS__) #define __IEEE_LITTLE_ENDIAN #define _FLOAT_ARG float #define _DOUBLE_IS_32BITS #endif #ifdef __sh__ #define _IEEE_754_2008_SNAN 0 #if __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define __IEEE_LITTLE_ENDIAN #elif __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__ #define __IEEE_BIG_ENDIAN #endif #ifdef __SH_FPU_ANY__ #define _SUPPORTS_ERREXCEPT #endif #endif #ifdef _AM29K #define __IEEE_BIG_ENDIAN #endif #ifdef _WIN32 #define __IEEE_LITTLE_ENDIAN #endif #ifdef __i386__ #define __IEEE_LITTLE_ENDIAN #ifndef _SOFT_FLOAT #define _SUPPORTS_ERREXCEPT #endif #endif #ifdef __loongarch__ #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) #define __IEEE_BIG_ENDIAN #else #define __IEEE_LITTLE_ENDIAN #endif #ifndef __loongarch_soft_float #define _SUPPORTS_ERREXCEPT #endif #endif #ifdef __riscv #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) #define __IEEE_BIG_ENDIAN #else #define __IEEE_LITTLE_ENDIAN #endif #if defined(__riscv_flen) || defined(__riscv_zfinx) #define _SUPPORTS_ERREXCEPT #endif #endif #ifdef __powerpc__ #ifdef __LITTLE_ENDIAN__ #define __IEEE_LITTLE_ENDIAN #else #define __IEEE_BIG_ENDIAN #endif #ifndef _SOFT_FLOAT #define _SUPPORTS_ERREXCEPT #endif #endif #ifdef __i960__ #define __IEEE_LITTLE_ENDIAN #endif #ifdef __lm32__ #define __IEEE_BIG_ENDIAN #endif #ifdef __M32R__ #define __IEEE_BIG_ENDIAN #endif #ifdef __nvptx__ #define __IEEE_LITTLE_ENDIAN #endif #if defined(_C4x) || defined(_C3x) #define __IEEE_BIG_ENDIAN #define _DOUBLE_IS_32BITS #endif #ifdef __TMS320C6X__ #ifdef _BIG_ENDIAN #define __IEEE_BIG_ENDIAN #else #define __IEEE_LITTLE_ENDIAN #endif #endif #ifdef __TIC80__ #define __IEEE_LITTLE_ENDIAN #endif #ifdef __mips__ #ifndef __mips_nan2008 #define _IEEE_754_2008_SNAN 0 #endif #ifndef __mips_soft_float #define _SUPPORTS_ERREXCEPT #endif #endif #ifdef __MIPSEL__ #define __IEEE_LITTLE_ENDIAN #endif #ifdef __MIPSEB__ #define __IEEE_BIG_ENDIAN #endif #ifdef __MMIX__ #define __IEEE_BIG_ENDIAN #endif #ifdef __D30V__ #define __IEEE_BIG_ENDIAN #endif /* necv70 was __IEEE_LITTLE_ENDIAN. */ #ifdef __W65__ #define __IEEE_LITTLE_ENDIAN #define _DOUBLE_IS_32BITS #endif #if defined(__Z8001__) || defined(__Z8002__) #define __IEEE_BIG_ENDIAN #endif #ifdef __m88k__ #define __IEEE_BIG_ENDIAN #endif #ifdef __mn10300__ #define __IEEE_LITTLE_ENDIAN #endif #ifdef __mn10200__ #define __IEEE_LITTLE_ENDIAN #define _DOUBLE_IS_32BITS #endif #ifdef __v800 #define __IEEE_LITTLE_ENDIAN #endif #ifdef __v850 #define __IEEE_LITTLE_ENDIAN #endif #ifdef __D10V__ #define __IEEE_BIG_ENDIAN #if __DOUBLE__ == 32 #define _DOUBLE_IS_32BITS #endif #endif #ifdef __PPC__ #if (defined(_BIG_ENDIAN) && _BIG_ENDIAN) || (defined(_AIX) && _AIX) #define __IEEE_BIG_ENDIAN #else #if (defined(_LITTLE_ENDIAN) && _LITTLE_ENDIAN) || (defined(__sun__) && __sun__) \ || (defined(_WIN32) && _WIN32) #define __IEEE_LITTLE_ENDIAN #endif #endif #endif #ifdef __xstormy16__ #define __IEEE_LITTLE_ENDIAN #endif #ifdef __arc__ #ifdef __big_endian__ #define __IEEE_BIG_ENDIAN #else #define __IEEE_LITTLE_ENDIAN #endif #endif #ifdef __ARC64__ #define __IEEE_LITTLE_ENDIAN #endif #ifdef __CRX__ #define __IEEE_LITTLE_ENDIAN #endif #ifdef __CSKY__ #ifdef __CSKYBE__ #define __IEEE_BIG_ENDIAN #else #define __IEEE_LITTLE_ENDIAN #endif #endif #ifdef __fr30__ #define __IEEE_BIG_ENDIAN #endif #ifdef __FT32__ #define __IEEE_LITTLE_ENDIAN #endif #ifdef __mcore__ #define __IEEE_BIG_ENDIAN #endif #ifdef __mt__ #define __IEEE_BIG_ENDIAN #endif #ifdef __frv__ #define __IEEE_BIG_ENDIAN #endif #ifdef __moxie__ #ifdef __MOXIE_BIG_ENDIAN__ #define __IEEE_BIG_ENDIAN #else #define __IEEE_LITTLE_ENDIAN #endif #endif #ifdef __ia64__ #ifdef __BIG_ENDIAN__ #define __IEEE_BIG_ENDIAN #else #define __IEEE_LITTLE_ENDIAN #endif #endif #ifdef __AVR__ #define __IEEE_LITTLE_ENDIAN #if !defined(__SIZEOF_DOUBLE__) || __SIZEOF_DOUBLE__ == 4 #define _DOUBLE_IS_32BITS #endif #endif #if defined(__or1k__) || defined(__OR1K__) || defined(__OR1KND__) #define __IEEE_BIG_ENDIAN #endif #ifdef __IP2K__ #define __IEEE_BIG_ENDIAN #define __SMALL_BITFIELDS #define _DOUBLE_IS_32BITS #endif #ifdef __iq2000__ #define __IEEE_BIG_ENDIAN #endif #ifdef __MAVERICK__ #ifdef __ARMEL__ #define __IEEE_LITTLE_ENDIAN #else /* must be __ARMEB__ */ #define __IEEE_BIG_ENDIAN #endif /* __ARMEL__ */ #endif /* __MAVERICK__ */ #ifdef __m32c__ #define __IEEE_LITTLE_ENDIAN #define __SMALL_BITFIELDS #endif #ifdef __CRIS__ #define __IEEE_LITTLE_ENDIAN #endif #ifdef __BFIN__ #define __IEEE_LITTLE_ENDIAN #endif #ifdef __HEXAGON_ARCH__ #define __IEEE_LITTLE_ENDIAN #endif #ifdef __x86_64__ #define __IEEE_LITTLE_ENDIAN #ifndef _SOFT_FLOAT #define _SUPPORTS_ERREXCEPT #endif #endif #ifdef __mep__ #ifdef __LITTLE_ENDIAN__ #define __IEEE_LITTLE_ENDIAN #else #define __IEEE_BIG_ENDIAN #endif #endif #ifdef __MICROBLAZE__ #ifndef __MICROBLAZEEL__ #define __IEEE_BIG_ENDIAN #else #define __IEEE_LITTLE_ENDIAN #endif #endif #ifdef __MSP430__ #define __IEEE_LITTLE_ENDIAN #define __SMALL_BITFIELDS /* 16 Bit INT */ #endif #ifdef __PRU__ #define __IEEE_LITTLE_ENDIAN #endif #ifdef __RL78__ #define __IEEE_LITTLE_ENDIAN #define __SMALL_BITFIELDS /* 16 Bit INT */ #ifndef __RL78_64BIT_DOUBLES__ #define _DOUBLE_IS_32BITS #endif #endif #ifdef __RX__ #ifdef __RX_BIG_ENDIAN__ #define __IEEE_BIG_ENDIAN #else #define __IEEE_LITTLE_ENDIAN #endif #ifndef __RX_64BIT_DOUBLES__ #define _DOUBLE_IS_32BITS #endif #ifdef __RX_16BIT_INTS__ #define __SMALL_BITFIELDS #endif #endif #if (defined(__CR16__) || defined(__CR16C__) || defined(__CR16CP__)) #define __IEEE_LITTLE_ENDIAN #define __SMALL_BITFIELDS /* 16 Bit INT */ #endif #ifdef __NIOS2__ #ifdef __nios2_big_endian__ #define __IEEE_BIG_ENDIAN #else #define __IEEE_LITTLE_ENDIAN #endif #endif #ifdef __VISIUM__ #define __IEEE_BIG_ENDIAN #endif #if (defined(__XTENSA__)) #ifdef __XTENSA_EB__ #define __IEEE_BIG_ENDIAN #endif #ifdef __XTENSA_EL__ #define __IEEE_LITTLE_ENDIAN #endif #endif #ifdef __AMDGCN__ #define __IEEE_LITTLE_ENDIAN #endif #ifdef __TRICORE__ #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) #define __IEEE_BIG_ENDIAN #else #define __IEEE_LITTLE_ENDIAN #endif #endif /* Figure out if long double is the same size as double. If the system * doesn't provide long double, then those values will be undefined * and cpp will substitute 0 for them in the test */ #if __LDBL_MANT_DIG__ == __DBL_MANT_DIG__ && __LDBL_MIN_EXP__ == __DBL_MIN_EXP__ \ && __LDBL_MAX_EXP__ == __DBL_MAX_EXP__ #define _LDBL_EQ_DBL #endif #if __SIZEOF_DOUBLE__ == 4 #define _DOUBLE_IS_32BITS #endif /* * long double is supported for binary128 and 80-bit extended * precision for x86 and m68k. Targets with binary64 long double * are supported by al */ #if defined(_LDBL_EQ_DBL) || defined(__CYGWIN__) \ || (defined(__HAVE_LONG_DOUBLE) && __SIZEOF_LONG_DOUBLE__ <= 8) \ || (__LDBL_MANT_DIG__ == 64 || __LDBL_MANT_DIG__ == 113) #define __HAVE_LONG_DOUBLE_MATH #endif /* New math code requires 64-bit doubles */ #ifdef _DOUBLE_IS_32BITS #undef __OBSOLETE_MATH #undef __OBSOLETE_MATH_DOUBLE #undef __OBSOLETE_MATH_FLOAT #undef __OBSOLETE_MATH_DEFAULT_FLOAT #undef __OBSOLETE_MATH_DEFAULT_DOUBLE #define __OBSOLETE_MATH 1 #endif #ifdef __XTENSA_EB__ #define __IEEE_BIG_ENDIAN #endif #ifndef __OBSOLETE_MATH_DEFAULT #define __OBSOLETE_MATH_DEFAULT 1 #endif #ifndef __OBSOLETE_MATH #define __OBSOLETE_MATH __OBSOLETE_MATH_DEFAULT #endif #ifndef __OBSOLETE_MATH_FLOAT #ifdef __OBSOLETE_MATH_DEFAULT_FLOAT #define __OBSOLETE_MATH_FLOAT __OBSOLETE_MATH_DEFAULT_FLOAT #else #define __OBSOLETE_MATH_FLOAT __OBSOLETE_MATH #endif #endif #ifndef __OBSOLETE_MATH_DOUBLE #ifdef __OBSOLETE_MATH_DEFAULT_DOUBLE #define __OBSOLETE_MATH_DOUBLE __OBSOLETE_MATH_DEFAULT_DOUBLE #else #define __OBSOLETE_MATH_DOUBLE __OBSOLETE_MATH #endif #endif /* Use __FLOAT_WORD_ORDER__ if we don't have * more specific platform knowledge */ #ifndef __IEEE_BIG_ENDIAN #ifndef __IEEE_LITTLE_ENDIAN #ifdef __FLOAT_WORD_ORDER__ #if __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define __IEEE_LITTLE_ENDIAN #endif #if __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__ #define __IEEE_BIG_ENDIAN #endif #endif #endif #endif #ifndef __IEEE_BIG_ENDIAN #ifndef __IEEE_LITTLE_ENDIAN #error Endianess not declared!! #endif /* not __IEEE_LITTLE_ENDIAN */ #endif /* not __IEEE_BIG_ENDIAN */ #endif /* not __IEEE_LITTLE_ENDIAN */ #endif /* not __IEEE_BIG_ENDIAN */ picolibc-1.8.11/libc/include/machine/malloc.h000066400000000000000000000003061513574234600207570ustar00rootroot00000000000000/* Copyright (c) 2002 Jeff Johnston */ #ifndef _MACHMALLOC_H_ #define _MACHMALLOC_H_ /* place holder so platforms may add malloc.h extensions */ #endif /* _MACHMALLOC_H_ */ picolibc-1.8.11/libc/include/machine/math.h000066400000000000000000000032161513574234600204440ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* placeholder so that platforms may add math.h extensions */ picolibc-1.8.11/libc/include/machine/meson.build000066400000000000000000000043121513574234600215020ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_machine_headers_all = [ 'ansi.h', '_arc4random.h', '_default_types.h', '_endian.h', 'endian.h', 'fastmath.h', 'fenv.h', 'fenv-softfloat.h', 'ieeefp.h', 'malloc.h', 'math.h', 'param.h', 'setjmp.h', 'stdlib.h', 'termios.h', '_time.h', 'time.h', '_types.h', 'types.h', ] inc_machine_headers = [] foreach file : inc_machine_headers_all if not (file in inc_machine_headers_machine) inc_machine_headers += file else message('libc/include/machine/' + file + ': machine overrides generic') endif endforeach if really_install install_headers( inc_machine_headers, install_dir: include_dir / 'machine' ) endif picolibc-1.8.11/libc/include/machine/param.h000066400000000000000000000001601513574234600206060ustar00rootroot00000000000000/* Copyright (c) 2004 Jeff Johnston */ /* Place holder for machine-specific param.h. */ picolibc-1.8.11/libc/include/machine/setjmp.h000066400000000000000000000265201513574234600210200ustar00rootroot00000000000000/* Copyright (C) 1991 DJ Delorie All rights reserved. Redistribution, modification, and use in source and binary forms is permitted provided that the above copyright notice and following paragraph are duplicated in all such forms. This file is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include _BEGIN_STD_C #if defined(__HEXAGON_ARCH__) /* * r16 - r31 */ #define _JBLEN 16 #define _JBTYPE long #endif #if defined(__or1k__) || defined(__or1knd__) /* * r1, r2, r9, r14, r16 .. r30, SR. */ #define _JBLEN 13 #define _JBTYPE unsigned long #endif #if defined(__arm__) || defined(__thumb__) /* * All callee preserved registers: * core registers: * r4 - r10, fp, sp, lr * VFP registers (architectural support dependent): * d8 - d15 */ #define _JBLEN 20 #define _JBTYPE long long #endif #if defined(__aarch64__) #define _JBLEN 22 #define _JBTYPE long long #endif #if defined(__AVR__) #define _JBLEN 24 #endif #ifdef __sparc__ /* * onsstack,sigmask,sp,pc,npc,psr,g1,o0,wbcnt (sigcontext). * All else recovered by under/over(flow) handling. */ #define _JBLEN 13 #endif #ifdef __BFIN__ #define _JBLEN 40 #endif #ifdef __epiphany__ /* All callee preserved registers: r4-r10,fp, sp, lr,r15, r32-r39 */ #define _JBTYPE long long #define _JBLEN 10 #endif /* necv70 was 9 as well. */ #if defined(__m68k__) || defined(__mc68000__) /* * onsstack,sigmask,sp,pc,psl,d2-d7,a2-a6, * fp2-fp7 for 68881. * All else recovered by under/over(flow) handling. */ #define _JBLEN 34 #endif #if defined(__mc68hc11__) || defined(__mc68hc12__) || defined(__mc68hc1x__) /* * D, X, Y are not saved. * Only take into account the pseudo soft registers (max 32). */ #define _JBLEN 32 #endif #ifdef __nds32__ /* 17 words for GPRs, 1 word for $fpcfg.freg and 30 words for FPUs Reserved 2 words for aligement-adjustment. When storeing double-precision floating-point register into memory, the address has to be double-word-aligned. Check libc/machine/nds32/setjmp.S for more information. */ #if __NDS32_EXT_FPU_SP__ || __NDS32_EXT_FPU_DP__ #define _JBLEN 50 #else #define _JBLEN 18 #endif #endif #if defined(__Z8001__) || defined(__Z8002__) /* 16 regs + pc */ #define _JBLEN 20 #endif #ifdef _AM29K /* * onsstack,sigmask,sp,pc,npc,psr,g1,o0,wbcnt (sigcontext). * All else recovered by under/over(flow) handling. */ #define _JBLEN 9 #endif #ifdef __i386__ #if defined(__iamcu__) /* Intel MCU jmp_buf only covers callee-saved registers. */ #define _JBLEN 6 #else #define _JBLEN 9 #endif #endif #ifdef __x86_64__ #define _JBTYPE long long #define _JBLEN 8 #endif #ifdef __i960__ #define _JBLEN 35 #endif #ifdef __M32R__ /* Only 8 words are currently needed. 10 gives us some slop if we need to expand. */ #define _JBLEN 10 #endif #ifdef __mips__ #if defined(__mips64) #define _JBTYPE long long #endif #ifdef __mips_soft_float #define _JBLEN 11 #else #define _JBLEN 23 #endif #endif #ifdef __m88000__ #define _JBLEN 21 #endif #ifdef __H8300__ #define _JBLEN 5 #define _JBTYPE int #endif #ifdef __H8300H__ /* same as H8/300 but registers are twice as big */ #define _JBLEN 5 #define _JBTYPE long #endif #if defined(__H8300S__) || defined(__H8300SX__) /* same as H8/300 but registers are twice as big */ #define _JBLEN 5 #define _JBTYPE long #endif #ifdef __H8500__ #define _JBLEN 4 #endif #ifdef __sh__ #if __SH5__ #define _JBLEN 50 #define _JBTYPE long long #else #define _JBLEN 20 #endif /* __SH5__ */ #endif #ifdef __v800 #define _JBLEN 28 #endif #ifdef __PPC__ #ifdef __powerpc64__ #ifdef __ALTIVEC__ #define _JBLEN 70 #else #define _JBLEN 43 #endif #else #ifdef __ALTIVEC__ #define _JBLEN 64 #else #define _JBLEN 32 #endif #endif #define _JBTYPE double #endif #ifdef __MICROBLAZE__ #define _JBLEN 20 #define _JBTYPE unsigned int #endif #ifdef __hppa__ /* %r30, %r2-%r18, %r27, pad, %fr12-%fr15. Note space exists for the FP registers, but they are not saved. */ #define _JBLEN 28 #endif #if defined(__mn10300__) || defined(__mn10200__) #ifdef __AM33_2__ #define _JBLEN 26 #else /* A guess */ #define _JBLEN 10 #endif #endif #ifdef __v850 /* I think our setjmp is saving 15 regs at the moment. Gives us one word slop if we need to expand. */ #define _JBLEN 16 #endif #if defined(_C4x) #define _JBLEN 10 #endif #if defined(_C3x) #define _JBLEN 9 #endif #ifdef __TMS320C6X__ #define _JBLEN 13 #endif #ifdef __TIC80__ #define _JBLEN 13 #endif #ifdef __D10V__ #define _JBLEN 8 #endif #ifdef __D30V__ #define _JBLEN ((64 /* GPR */ + (2 * 2) /* ACs */ + 18 /* CRs */) / 2) #define _JBTYPE double #endif #ifdef __frv__ #define _JBLEN (68 / 2) /* room for 68 32-bit regs */ #define _JBTYPE double #endif #ifdef __moxie__ #define _JBLEN 10 #endif #ifdef __CRX__ #define _JBLEN 9 #endif #if (defined(__CR16__) || defined(__CR16C__) || defined(__CR16CP__)) /* r6, r7, r8, r9, r10, r11, r12 (r12L, r12H), * r13 (r13L, r13H), ra(raL, raH), sp(spL, spH) */ #define _JBLEN 14 #define _JBTYPE unsigned short #endif #ifdef __fr30__ #define _JBLEN 10 #endif #ifdef __FT32__ #define _JBLEN 27 #endif #ifdef __iq2000__ #define _JBLEN 32 #endif #ifdef __mcore__ #define _JBLEN 16 #endif #ifdef __arc__ #define _JBLEN 25 /* r13-r30,blink,lp_count,lp_start,lp_end,mlo,mhi,status32 */ #define _JBTYPE unsigned long #endif #ifdef __ARC64__ /* r14-r27,sp,ilink,r30,blink */ #define _JBLEN 18 #ifdef __ARC64_ARCH64__ #define _JBTYPE long long #else /* __ARC64_ARCH32__ */ #define _JBTYPE long #endif #endif /* __ARC64__ */ #ifdef __MMIX__ /* Using a layout compatible with GCC's built-in. */ #define _JBLEN 5 #define _JBTYPE unsigned long #endif #ifdef __mt__ #define _JBLEN 16 #endif #ifdef __SPU__ #define _JBLEN 50 #define _JBTYPE __vector signed int #endif #ifdef __xstormy16__ /* 4 GPRs plus SP plus PC. */ #define _JBLEN 8 #endif #ifdef __XTENSA__ #if __XTENSA_WINDOWED_ABI__ /* The jmp_buf structure for Xtensa windowed ABI holds the following (where "proc" is the procedure that calls setjmp): 4-12 registers from the window of proc, the 4 words from the save area at proc's $sp (in case a subsequent alloca in proc moves $sp), and the return address within proc. Everything else is saved on the stack in the normal save areas. The jmp_buf structure is: struct jmp_buf { int regs[12]; int save[4]; void *return_address; } See the setjmp code for details. */ /* sizeof(struct jmp_buf) */ #define _JBLEN 17 #else /* __XTENSA_CALL0_ABI__ */ /* a0, a1, a12, a13, a14, a15 */ #define _JBLEN 6 #endif /* __XTENSA_CALL0_ABI__ */ #endif /* __XTENSA__ */ #ifdef __mep__ /* 16 GPRs, pc, hi, lo */ #define _JBLEN 19 #endif #ifdef __CRIS__ #define _JBLEN 18 #endif #ifdef __ia64 #define _JBLEN 64 #endif #ifdef __lm32__ #define _JBLEN 19 #endif #ifdef __m32c__ #if defined(__r8c_cpu__) || defined(__m16c_cpu__) #define _JBLEN (22 / 2) #else #define _JBLEN (34 / 2) #endif #define _JBTYPE unsigned short #endif /* __m32c__ */ #ifdef __MSP430__ #define _JBLEN 9 #ifdef __MSP430X_LARGE__ #define _JBTYPE unsigned long #else #define _JBTYPE unsigned short #endif #endif #ifdef __RL78__ /* Three banks of registers, SP, CS, ES, PC */ #define _JBLEN (8 * 3 + 8) #define _JBTYPE unsigned char #endif /* * There are two versions of setjmp()/longjmp(): * 1) Compiler (gcc) built-in versions. * 2) Function-call versions. * * The built-in versions are used most of the time. When used, gcc replaces * calls to setjmp()/longjmp() with inline assembly code. The built-in * versions save/restore a variable number of registers. * _JBLEN is set to 40 to be ultra-safe with the built-in versions. * It only needs to be 12 for the function-call versions * but this data structure is used by both versions. */ #ifdef __NIOS2__ #define _JBLEN 40 #define _JBTYPE unsigned long #endif #ifdef __PRU__ #define _JBLEN 48 #define _JBTYPE unsigned int #endif #ifdef __RX__ #define _JBLEN 0x44 #endif #ifdef __VISIUM__ /* All call-saved GP registers: r11-r19,r21,r22,r23. */ #define _JBLEN 12 #endif #ifdef __riscv /* _JBTYPE using long long to make sure the alignment is align to 8 byte, otherwise in rv32imafd, store/restore FPR may mis-align. */ #define _JBTYPE long long #ifdef __riscv_32e #define _JBLEN ((4 * sizeof(long)) / sizeof(long)) #else #define _JBLEN ((14 * sizeof(long) + 12 * sizeof(double)) / sizeof(long)) #endif #endif #ifdef __CSKYABIV2__ #define _JBTYPE unsigned long #if defined(__CK801__) #define _JBLEN 7 #elif defined(__CK802__) #define _JBLEN 10 #else #define _JBLEN 18 #endif #endif #ifdef __loongarch__ #define _JBTYPE unsigned long #ifdef __loongarch_soft_float #define _JBLEN 13 #elif __loongarch_frlen > 32 && __loongarch_grlen <= 32 /* Extra padding for alignment */ #define _JBLEN (13 + 1 + (8 * (__loongarch_frlen / __loongarch_grlen))) #else #define _JBLEN (13 + (8 * (__loongarch_frlen / __loongarch_frlen))) #endif #endif #ifdef _JBLEN #ifdef _JBTYPE typedef _JBTYPE jmp_buf[_JBLEN]; #else typedef int jmp_buf[_JBLEN]; #endif #endif _END_STD_C #if (defined(__CYGWIN__) || defined(__rtems__)) && __POSIX_VISIBLE #include _BEGIN_STD_C /* POSIX sigsetjmp/siglongjmp macros */ #ifdef _JBTYPE typedef _JBTYPE sigjmp_buf[_JBLEN + 1 + ((sizeof(_JBTYPE) + sizeof(sigset_t) - 1) / sizeof(_JBTYPE))]; #else typedef int sigjmp_buf[_JBLEN + 1 + (sizeof(sigset_t) / sizeof(int))]; #endif #define _SAVEMASK _JBLEN #define _SIGMASK (_JBLEN + 1) #ifdef _POSIX_THREADS #define __SIGMASK_FUNC pthread_sigmask #else #define __SIGMASK_FUNC sigprocmask #endif #if defined(__GNUC__) #define sigsetjmp(env, savemask) \ __extension__({ \ sigjmp_buf *_sjbuf = &(env); \ ((*_sjbuf)[_SAVEMASK] = savemask, \ __SIGMASK_FUNC(SIG_SETMASK, 0, (sigset_t *)((*_sjbuf) + _SIGMASK)), setjmp(*_sjbuf)); \ }) #define siglongjmp(env, val) \ __extension__({ \ sigjmp_buf *_sjbuf = &(env); \ ((((*_sjbuf)[_SAVEMASK]) \ ? __SIGMASK_FUNC(SIG_SETMASK, (sigset_t *)((*_sjbuf) + _SIGMASK), 0) \ : 0), \ longjmp(*_sjbuf, val)); \ }) #else /* !__GNUC__ */ #define sigsetjmp(env, savemask) \ ((env)[_SAVEMASK] = savemask, __SIGMASK_FUNC(SIG_SETMASK, 0, (sigset_t *)((env) + _SIGMASK)), \ setjmp(env)) #define siglongjmp(env, val) \ ((((env)[_SAVEMASK]) ? __SIGMASK_FUNC(SIG_SETMASK, (sigset_t *)((env) + _SIGMASK), 0) : 0), \ longjmp(env, val)) #endif /* POSIX _setjmp/_longjmp, maintained for XSI compatibility. These are equivalent to sigsetjmp/siglongjmp when not saving the signal mask. New applications should use sigsetjmp/siglongjmp instead. */ #define _setjmp(env) sigsetjmp((env), 0) #define _longjmp(env, val) siglongjmp((env), (val)) _END_STD_C #endif /* (__CYGWIN__ or __rtems__) and __POSIX_VISIBLE */ picolibc-1.8.11/libc/include/machine/stdlib.h000066400000000000000000000003061513574234600207710ustar00rootroot00000000000000/* Copyright (c) 2002 Jeff Johnston */ #ifndef _MACHSTDLIB_H_ #define _MACHSTDLIB_H_ /* place holder so platforms may add stdlib.h extensions */ #endif /* _MACHSTDLIB_H_ */ picolibc-1.8.11/libc/include/machine/termios.h000066400000000000000000000001321513574234600211670ustar00rootroot00000000000000/* Copyright (c) 2002 Jeff Johnston */ #define __MAX_BAUD B4000000 picolibc-1.8.11/libc/include/machine/time.h000066400000000000000000000013651513574234600204540ustar00rootroot00000000000000/* Copyright (C) 1991 DJ Delorie All rights reserved. Redistribution, modification, and use in source and binary forms is permitted provided that the above copyright notice and following paragraph are duplicated in all such forms. This file is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef _MACHTIME_H_ #define _MACHTIME_H_ #if defined(__rtems__) || defined(__VISIUM__) || defined(__riscv) #define _CLOCKS_PER_SEC_ 1000000 #elif defined(__aarch64__) || defined(__arm__) || defined(__thumb__) #define _CLOCKS_PER_SEC_ 100 #endif #ifdef __SPU__ #include int nanosleep(const struct timespec *, struct timespec *); #endif #endif /* _MACHTIME_H_ */ picolibc-1.8.11/libc/include/machine/types.h000066400000000000000000000013551513574234600206610ustar00rootroot00000000000000/* Copyright (C) 1991 DJ Delorie All rights reserved. Redistribution, modification, and use in source and binary forms is permitted provided that the above copyright notice and following paragraph are duplicated in all such forms. This file is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /* * Newlib targets may provide an own version of this file in their machine * directory to add custom user types for . */ #ifndef _SYS_TYPES_H #error "must be included via " #endif /* !_SYS_TYPES_H */ #if defined(__XMK__) && defined(___int64_t_defined) typedef __uint64_t u_quad_t; typedef __int64_t quad_t; typedef quad_t *qaddr_t; #endif picolibc-1.8.11/libc/include/malloc.h000066400000000000000000000076251513574234600173660ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* malloc.h -- header file for memory routines. */ #ifndef _INCLUDE_MALLOC_H_ #define _INCLUDE_MALLOC_H_ #include #define __need_size_t #include /* include any machine-specific extensions */ #include _BEGIN_STD_C /* This version of struct mallinfo must match the one in libc/stdlib/mallocr.c. */ struct mallinfo { size_t arena; /* total space allocated from system */ size_t ordblks; /* number of non-inuse chunks */ size_t smblks; /* unused -- always zero */ size_t hblks; /* number of mmapped regions */ size_t hblkhd; /* total space in mmapped regions */ size_t usmblks; /* unused -- always zero */ size_t fsmblks; /* unused -- always zero */ size_t uordblks; /* total allocated space */ size_t fordblks; /* total non-inuse space */ size_t keepcost; /* top-most, releasable (via malloc_trim) space */ }; /* The routines. */ void free(void *) __nothrow; void * malloc(size_t) __malloc_like __warn_unused_result __alloc_size(1) __nothrow; void * calloc(size_t, size_t) __malloc_like __warn_unused_result __alloc_size2(1, 2) __nothrow; void * realloc(void *, size_t) __warn_unused_result __alloc_size(2) __nothrow; void *memalign(size_t __alignment, size_t __size) __malloc_like __warn_unused_result __alloc_size(2) __nothrow; struct mallinfo mallinfo(void); void malloc_stats(void); int mallopt(int, int); size_t malloc_usable_size(void *); /* These aren't too useful on an embedded system, but we define them anyhow. */ void *pvalloc(size_t); int malloc_trim(size_t); void __malloc_lock(void); void __malloc_unlock(void); /* SVID2/XPG mallopt options */ #define M_MXFAST 1 /* UNUSED in this malloc */ #define M_NLBLKS 2 /* UNUSED in this malloc */ #define M_GRAIN 3 /* UNUSED in this malloc */ #define M_KEEP 4 /* UNUSED in this malloc */ /* mallopt options that actually do something */ #define M_TRIM_THRESHOLD -1 #define M_TOP_PAD -2 #define M_MMAP_THRESHOLD -3 #define M_MMAP_MAX -4 /* Some systems provide this, so do too for compatibility. */ void cfree(void *); _END_STD_C #endif /* _INCLUDE_MALLOC_H_ */ picolibc-1.8.11/libc/include/math.h000066400000000000000000000657131513574234600170520ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MATH_H_ #define _MATH_H_ #include _BEGIN_STD_C /* Natural log of 2 */ #define _M_LN2 0.693147180559945309417 #define _M_LN2_LD 0.693147180559945309417232121458176568l #if __GNUC_PREREQ(3, 3) || defined(__clang__) || defined(__COMPCERT__) /* gcc >= 3.3 implicitly defines builtins for HUGE_VALx values. */ #ifndef HUGE_VAL #define HUGE_VAL (__builtin_huge_val()) #endif #ifndef HUGE_VALF #define HUGE_VALF (__builtin_huge_valf()) #endif #ifndef HUGE_VALL #define HUGE_VALL (__builtin_huge_vall()) #endif #ifndef INFINITY #define INFINITY (__builtin_inff()) #endif #ifndef NAN #define NAN (__builtin_nanf("")) #endif #else /* !gcc >= 3.3 */ /* No builtins. Use fixed defines instead. (All 3 HUGE plus the INFINITY * and NAN macros are required to be constant expressions. Using a variable-- * even a static const--does not meet this requirement, as it cannot be * evaluated at translation time.) * The infinities are done using numbers that are far in excess of * something that would be expected to be encountered in a floating-point * implementation. (A more certain way uses values from float.h, but that is * avoided because system includes are not supposed to include each other.) * This method might produce warnings from some compilers. (It does in * newer GCCs, but not for ones that would hit this #else.) If this happens, * please report details to the Newlib mailing list. */ #ifndef HUGE_VAL #define HUGE_VAL (1.0e999999999) #endif #ifndef HUGE_VALF #define HUGE_VALF (1.0e999999999F) #endif #if !defined(HUGE_VALL) && defined(__HAVE_LONG_DOUBLE) #define HUGE_VALL (1.0e999999999L) #endif #if !defined(INFINITY) #define INFINITY (HUGE_VALF) #endif #if !defined(NAN) #if defined(__GNUC__) && defined(__cplusplus) /* Exception: older g++ versions warn about the divide by 0 used in the * normal case (even though older gccs do not). This trick suppresses the * warning, but causes errors for plain gcc, so is only used in the one * special case. */ static const union { __ULong __i[1]; float __d; } __Nanf = { 0x7FC00000 }; #define NAN (__Nanf.__d) #else #define NAN (0.0F / 0.0F) #endif #endif #endif /* !gcc >= 3.3 */ extern double atan(double); extern double cos(double); extern double sin(double); extern double tan(double); extern double tanh(double); extern double frexp(double, int *); extern double modf(double, double *); extern double ceil(double); extern double fabs(double); extern double floor(double); extern double acos(double); extern double asin(double); extern double atan2(double, double); extern double cosh(double); extern double sinh(double); extern double exp(double); extern double ldexp(double, int); extern double log(double); extern double log10(double); extern double pow(double, double); extern double sqrt(double); extern double fmod(double, double); #if __MISC_VISIBLE extern int finite(double); extern int finitef(float); extern int isinff(float); extern int isnanf(float); #if defined(__HAVE_LONG_DOUBLE) extern int finitel(long double); extern int isinfl(long double); extern int isnanl(long double); #endif #if !defined(__cplusplus) || __cplusplus < 201103L extern int isinf(double); #endif #endif /* __MISC_VISIBLE */ #if (__MISC_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 600)) \ && (!defined(__cplusplus) || __cplusplus < 201103L) extern int isnan(double); #endif #if __ISO_C_VISIBLE >= 1999 /* ISO C99 types and macros. */ /* FIXME: FLT_EVAL_METHOD should somehow be gotten from float.h (which is hard, * considering that the standard says the includes it defines should not * include other includes that it defines) and that value used. (This can be * solved, but autoconf has a bug which makes the solution more difficult, so * it has been skipped for now.) */ #if !defined(FLT_EVAL_METHOD) && defined(__FLT_EVAL_METHOD__) #define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ #define __TMP_FLT_EVAL_METHOD #endif /* FLT_EVAL_METHOD */ #if defined FLT_EVAL_METHOD /* FLT_EVAL_METHOD == 16 has meaning as defined in ISO/IEC TS 18661-3, * which provides non-compliant extensions to C and POSIX (by adding * additional positive values for FLT_EVAL_METHOD). It effectively has * same meaning as the C99 and C11 definitions for value 0, while also * serving as a flag that the _Float16 (float16_t) type exists. * * FLT_EVAL_METHOD could be any number of bits of supported floating point * format (e.g. 32, 64, 128), but currently only AArch64 and few other targets * might define that as 16. */ #if (FLT_EVAL_METHOD == 0) || (FLT_EVAL_METHOD == 16) typedef float float_t; typedef double double_t; #elif FLT_EVAL_METHOD == 1 typedef double float_t; typedef double double_t; #elif FLT_EVAL_METHOD == 2 typedef long double float_t; typedef long double double_t; #else /* Implementation-defined. Assume float_t and double_t have been * defined previously for this configuration (e.g. config.h). */ /* If __DOUBLE_TYPE is defined (__FLOAT_TYPE is then supposed to be defined as well) float_t and double_t definition is suggested by an arch specific header. */ #ifdef __DOUBLE_TYPE typedef __DOUBLE_TYPE double_t; typedef __FLOAT_TYPE float_t; #endif /* Assume config.h has provided these types. */ #endif #else /* Assume basic definitions. */ typedef float float_t; typedef double double_t; #endif #if defined(__TMP_FLT_EVAL_METHOD) #undef FLT_EVAL_METHOD #endif #define FP_NAN 0 #define FP_INFINITE 1 #define FP_ZERO 2 #define FP_SUBNORMAL 3 #define FP_NORMAL 4 #ifndef FP_ILOGB0 #define FP_ILOGB0 (-__INT_MAX__) #endif #ifndef FP_ILOGBNAN #define FP_ILOGBNAN __INT_MAX__ #endif #if !defined(FP_FAST_FMA) && (__HAVE_FAST_FMA || defined(__FP_FAST_FMA)) #define FP_FAST_FMA #endif #if !defined(FP_FAST_FMAF) && (__HAVE_FAST_FMAF || defined(__FP_FAST_FMAF)) #define FP_FAST_FMAF #endif #if !defined(FP_FAST_FMAL) && (__HAVE_FAST_FMAL || defined(__FP_FAST_FMAL)) #define FP_FAST_FMAL #endif #ifndef MATH_ERRNO #define MATH_ERRNO 1 #endif #ifndef MATH_ERREXCEPT #define MATH_ERREXCEPT 2 #endif #ifndef math_errhandling #ifdef __IEEE_LIBM #define _MATH_ERRHANDLING_ERRNO 0 #else #define _MATH_ERRHANDLING_ERRNO MATH_ERRNO #endif #ifdef _SUPPORTS_ERREXCEPT #define _MATH_ERRHANDLING_ERREXCEPT MATH_ERREXCEPT #else #define _MATH_ERRHANDLING_ERREXCEPT 0 #endif #define math_errhandling (_MATH_ERRHANDLING_ERRNO | _MATH_ERRHANDLING_ERREXCEPT) #endif /* * Specifies whether the target uses the snan/nan discriminator * definition from IEEE 754 2008 (top bit of significand is 1 for qNaN * and 0 for sNaN). This is set to zero in machine/math.h for targets * that don't do this (such as MIPS). */ #ifndef _IEEE_754_2008_SNAN #define _IEEE_754_2008_SNAN 1 #endif extern int __isinff(float); extern int __isinfd(double); extern int __isnanf(float); extern int __isnand(double); extern int __fpclassifyf(float); extern int __fpclassifyd(double); extern int __signbitf(float); extern int __signbitd(double); extern int __finite(double); extern int __finitef(float); #if defined(__HAVE_LONG_DOUBLE) extern int __fpclassifyl(long double); extern int __isinfl(long double); extern int __isnanl(long double); extern int __finitel(long double); extern int __signbitl(long double); #endif /* Note: isinf and isnan were once functions in newlib that took double * arguments. C99 specifies that these names are reserved for macros * supporting multiple floating point types. Thus, they are * now defined as macros. Implementations of the old functions * taking double arguments still exist for compatibility purposes * (prototypes for them are earlier in this header). */ /* * GCC bug 66462 raises INVALID exception when __builtin_fpclassify is * passed snan, so we cannot use it when building with snan support. * clang doesn't appear to have an option to control snan behavior, and * it's builtin fpclassify also raises INVALID for snan, so always use * our version for that. */ #if __GNUC_PREREQ(4, 4) && !defined(__SUPPORT_SNAN__) && !defined(__clang__) #define fpclassify(__x) \ (__builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x)) #define isfinite(__x) (__builtin_isfinite(__x)) #define isinf(__x) (__builtin_isinf_sign(__x)) #define isnan(__x) (__builtin_isnan(__x)) #define isnormal(__x) (__builtin_isnormal(__x)) #define issubnormal(__x) (__builtin_issubnormal(__x)) #define iszero(__x) (__builtin_iszero(__x)) #else #if defined(__HAVE_LONG_DOUBLE) #define __float_generic3(__f, __d, __l, __x) \ ((sizeof(__x) == sizeof(float)) ? __f(__x) \ : (sizeof(__x) == sizeof(double)) ? __d((double)(__x)) \ : __l((long double)(__x))) #else #define __float_generic3(__f, __d, __l, __x) \ ((sizeof(__x) == sizeof(float)) ? __f(__x) : __d((double)(__x))) #endif #define __float_generic(__p, __x) __float_generic3(__p##f, __p##d, __p##l, __x) #define fpclassify(__x) __float_generic(__fpclassify, __x) #define isfinite(__x) __float_generic3(__finitef, __finite, __finitel, __x) #define isinf(__x) __float_generic(__isinf, __x) #define isnan(__x) __float_generic(__isnan, __x) #define isnormal(__x) (fpclassify(__x) == FP_NORMAL) #define issubnormal(__x) (fpclassify(__x) == FP_SUBNORMAL) #define iszero(__x) (fpclassify(__x) == FP_ZERO) #endif #define isfinitef(x) isfinite((float)(x)) #define isinff(x) isinf((float)(x)) #define isnanf(x) isnan((float)(x)) #define isnormalf(x) isnormal((float)(x)) #define iszerof(x) iszero((float)(x)) #ifdef __HAVE_LONG_DOUBLE #define isfinitel(x) isfinite((long double)(x)) #define isinfl(x) isinf((long double)(x)) #define isnanl(x) isnan((long double)(x)) #define isnormall(x) isnormal((long double)(x)) #define iszerol(x) iszero((long double)(x)) #endif #ifndef iseqsig int __iseqsigd(double x, double y); int __iseqsigf(float x, float y); #ifdef __HAVE_LONG_DOUBLE int __iseqsigl(long double x, long double y); #define iseqsig(__x, __y) \ ((sizeof(__x) == sizeof(float) && sizeof(__y) == sizeof(float)) ? __iseqsigf(__x, __y) \ : (sizeof(__x) == sizeof(double) && sizeof(__y) == sizeof(double)) \ ? __iseqsigd(__x, __y) \ : __iseqsigl(__x, __y)) #else #ifdef _DOUBLE_IS_32BITS #define iseqsig(__x, __y) __iseqsigf((float)(__x), (float)(__y)) #else #define iseqsig(__x, __y) \ ((sizeof(__x) == sizeof(float) && sizeof(__y) == sizeof(float)) ? __iseqsigf(__x, __y) \ : __iseqsigd(__x, __y)) #endif #endif #endif #ifndef issignaling int __issignalingf(float f); int __issignaling(double d); #if defined(__HAVE_LONG_DOUBLE) int __issignalingl(long double d); #define issignaling(__x) \ ((sizeof(__x) == sizeof(float)) ? __issignalingf(__x) \ : (sizeof(__x) == sizeof(double)) ? __issignaling((double)(__x)) \ : __issignalingl((long double)(__x))) #else #ifdef _DOUBLE_IS_32BITS #define issignaling(__x) __issignalingf((float)(__x)) #else #define issignaling(__x) \ ((sizeof(__x) == sizeof(float)) ? __issignalingf(__x) : __issignaling((double)(__x))) #endif /* _DOUBLE_IS_32BITS */ #endif /* __HAVE_LONG_DOUBLE */ #endif #if __GNUC_PREREQ(4, 0) #if defined(__HAVE_LONG_DOUBLE) #define signbit(__x) \ ((sizeof(__x) == sizeof(float)) \ ? __builtin_signbitf(__x) \ : ((sizeof(__x) == sizeof(double)) ? __builtin_signbit((double)(__x)) \ : __builtin_signbitl((long double)(__x)))) #else #define signbit(__x) \ ((sizeof(__x) == sizeof(float)) ? __builtin_signbitf(__x) : __builtin_signbit((double)(__x))) #endif #else #if defined(__HAVE_LONG_DOUBLE) #define signbit(__x) \ ((sizeof(__x) == sizeof(float)) \ ? __signbitf(__x) \ : ((sizeof(__x) == sizeof(double)) ? __signbit((double)(__x)) \ : __signbitl((long double)(__x)))) #else #define signbit(__x) ((sizeof(__x) == sizeof(float)) ? __signbitf(__x) : __signbitd((double)(__x))) #endif #endif #if __GNUC_PREREQ(2, 97) && !(defined(__riscv) && defined(__clang__)) #define isgreater(__x, __y) (__builtin_isgreater(__x, __y)) #define isgreaterequal(__x, __y) (__builtin_isgreaterequal(__x, __y)) #define isless(__x, __y) (__builtin_isless(__x, __y)) #define islessequal(__x, __y) (__builtin_islessequal(__x, __y)) #define islessgreater(__x, __y) (__builtin_islessgreater(__x, __y)) #define isunordered(__x, __y) (__builtin_isunordered(__x, __y)) #else #define isgreater(x, y) \ (__extension__({ \ __typeof__(x) __x = (x); \ __typeof__(y) __y = (y); \ !isunordered(__x, __y) && (__x > __y); \ })) #define isgreaterequal(x, y) \ (__extension__({ \ __typeof__(x) __x = (x); \ __typeof__(y) __y = (y); \ !isunordered(__x, __y) && (__x >= __y); \ })) #define isless(x, y) \ (__extension__({ \ __typeof__(x) __x = (x); \ __typeof__(y) __y = (y); \ !isunordered(__x, __y) && (__x < __y); \ })) #define islessequal(x, y) \ (__extension__({ \ __typeof__(x) __x = (x); \ __typeof__(y) __y = (y); \ !isunordered(__x, __y) && (__x <= __y); \ })) #define islessgreater(x, y) \ (__extension__({ \ __typeof__(x) __x = (x); \ __typeof__(y) __y = (y); \ !isunordered(__x, __y) && (__x < __y || __x > __y); \ })) #define isunordered(a, b) \ (__extension__({ \ __typeof__(a) __a = (a); \ __typeof__(b) __b = (b); \ fpclassify(__a) == FP_NAN || fpclassify(__b) == FP_NAN; \ })) #endif /* Non ANSI double precision functions. */ extern double infinity(void); extern double nan(const char *); extern double copysign(double, double); extern double logb(double); extern int ilogb(double); extern double asinh(double); extern double cbrt(double); extern double nextafter(double, double); extern double rint(double); extern double scalbn(double, int); extern double scalb(double, double); extern double getpayload(const double *x); extern double significand(double); extern double exp2(double); extern double scalbln(double, long int); extern double tgamma(double); extern double nearbyint(double); extern long int lrint(double); extern long long int llrint(double); extern double round(double); extern long int lround(double); extern long long int llround(double); extern double trunc(double); extern double remquo(double, double, int *); extern double fdim(double, double); extern double fmax(double, double); extern double fmin(double, double); extern double fma(double, double, double); extern double log1p(double); extern double expm1(double); extern double acosh(double); extern double atanh(double); extern double remainder(double, double); extern double gamma(double); extern double lgamma(double); extern double erf(double); extern double erfc(double); extern double log2(double); #if !defined(__cplusplus) #define log2(x) (log(x) / _M_LN2) #endif extern double hypot(double, double); /* Single precision versions of ANSI functions. */ extern float atanf(float); extern float cosf(float); extern float sinf(float); extern float tanf(float); extern float tanhf(float); extern float frexpf(float, int *); extern float modff(float, float *); extern float ceilf(float); extern float fabsf(float); extern float floorf(float); extern float acosf(float); extern float asinf(float); extern float atan2f(float, float); extern float coshf(float); extern float sinhf(float); extern float expf(float); extern float ldexpf(float, int); extern float logf(float); extern float log10f(float); extern float powf(float, float); extern float sqrtf(float); extern float fmodf(float, float); /* Other single precision functions. */ extern float exp2f(float); extern float scalblnf(float, long int); extern float tgammaf(float); extern float nearbyintf(float); extern long int lrintf(float); extern long long int llrintf(float); extern float roundf(float); extern long int lroundf(float); extern long long int llroundf(float); extern float truncf(float); extern float remquof(float, float, int *); extern float fdimf(float, float); extern float fmaxf(float, float); extern float fminf(float, float); extern float fmaf(float, float, float); extern float infinityf(void); extern float nanf(const char *); extern float copysignf(float, float); extern float logbf(float); extern int ilogbf(float); extern float asinhf(float); extern float cbrtf(float); extern float nextafterf(float, float); extern float rintf(float); extern float scalbnf(float, int); extern float scalbf(float, float); extern float log1pf(float); extern float expm1f(float); extern float getpayloadf(const float *x); extern float significandf(float); extern float acoshf(float); extern float atanhf(float); extern float remainderf(float, float); extern float gammaf(float); extern float lgammaf(float); extern float erff(float); extern float erfcf(float); extern float log2f(float); extern float hypotf(float, float); #ifdef __HAVE_LONG_DOUBLE /* These functions are always available for long double */ extern long double hypotl(long double, long double); extern long double infinityl(void); extern long double sqrtl(long double); extern long double frexpl(long double, int *); extern long double scalbnl(long double, int); extern long double scalblnl(long double, long); extern long double rintl(long double); extern long int lrintl(long double); extern long long int llrintl(long double); extern int ilogbl(long double); extern long double logbl(long double); extern long double ldexpl(long double, int); extern long double nearbyintl(long double); extern long double ceill(long double); extern long double fmaxl(long double, long double); extern long double fminl(long double, long double); extern long double roundl(long double); extern long lroundl(long double); extern long long int llroundl(long double); extern long double truncl(long double); extern long double nanl(const char *); extern long double floorl(long double); extern long double scalbl(long double, long double); extern long double significandl(long double); /* Compiler provides these */ extern long double fabsl(long double); extern long double copysignl(long double, long double); #ifdef __HAVE_LONG_DOUBLE_MATH extern long double atanl(long double); extern long double cosl(long double); extern long double sinl(long double); extern long double tanl(long double); extern long double tanhl(long double); extern long double modfl(long double, long double *); extern long double log1pl(long double); extern long double expm1l(long double); extern long double acosl(long double); extern long double asinl(long double); extern long double atan2l(long double, long double); extern long double coshl(long double); extern long double sinhl(long double); extern long double expl(long double); extern long double logl(long double); extern long double log10l(long double); extern long double powl(long double, long double); extern long double fmodl(long double, long double); extern long double asinhl(long double); extern long double cbrtl(long double); extern long double nextafterl(long double, long double); extern float nexttowardf(float, long double); extern double nexttoward(double, long double); extern long double nexttowardl(long double, long double); extern long double log2l(long double); extern long double exp2l(long double); extern long double tgammal(long double); extern long double remquol(long double, long double, int *); extern long double fdiml(long double, long double); extern long double fmal(long double, long double, long double); extern long double acoshl(long double); extern long double atanhl(long double); extern long double remainderl(long double, long double); extern long double lgammal(long double); extern long double gammal(long double); extern long double erfl(long double); extern long double erfcl(long double); extern long double j0l(long double); extern long double y0l(long double); extern long double j1l(long double); extern long double y1l(long double); extern long double jnl(int, long double); extern long double ynl(int, long double); extern long double getpayloadl(const long double *x); #endif /* __HAVE_LONG_DOUBLE_MATH */ #endif /* __HAVE_LONG_DOUBLE */ #endif /* __ISO_C_VISIBLE >= 1999 */ #if __MISC_VISIBLE extern double drem(double, double); extern float dremf(float, float); #ifdef __HAVE_LONG_DOUBLE_MATH extern long double dreml(long double, long double); extern long double lgammal_r(long double, int *); #endif extern double lgamma_r(double, int *); extern float lgammaf_r(float, int *); #endif #if __MISC_VISIBLE || __XSI_VISIBLE extern double y0(double); extern double y1(double); extern double yn(int, double); extern double j0(double); extern double j1(double); extern double jn(int, double); #endif #if __MISC_VISIBLE || __XSI_VISIBLE >= 600 extern float y0f(float); extern float y1f(float); extern float ynf(int, float); extern float j0f(float); extern float j1f(float); extern float jnf(int, float); #endif /* GNU extensions */ #if __GNU_VISIBLE extern void sincos(double, double *, double *); extern void sincosf(float, float *, float *); #ifdef __HAVE_LONG_DOUBLE_MATH extern void sincosl(long double, long double *, long double *); #endif extern double exp10(double); extern double pow10(double); extern float exp10f(float); extern float pow10f(float); #ifdef __HAVE_LONG_DOUBLE_MATH extern long double exp10l(long double); extern long double pow10l(long double); #endif #endif /* __GNU_VISIBLE */ #if __MISC_VISIBLE || __XSI_VISIBLE extern int signgam; #endif /* __MISC_VISIBLE || __XSI_VISIBLE */ /* Useful constants. */ #if __BSD_VISIBLE || __XSI_VISIBLE #define MAXFLOAT 3.40282347e+38F #define M_E 2.7182818284590452354 #define _M_E_L 2.718281828459045235360287471352662498L #define M_LOG2E 1.4426950408889634074 #define M_LOG10E 0.43429448190325182765 #define M_LN2 _M_LN2 #define M_LN10 2.30258509299404568402 #define M_PI 3.14159265358979323846 #define _M_PI_L 3.141592653589793238462643383279502884L #define M_PI_2 1.57079632679489661923 #define _M_PI_2 1.57079632679489661923 #define _M_PI_2L 1.570796326794896619231321691639751442L #define M_PI_4 0.78539816339744830962 #define _M_PI_4L 0.785398163397448309615660845819875721L #define M_1_PI 0.31830988618379067154 #define M_2_PI 0.63661977236758134308 #define M_2_SQRTPI 1.12837916709551257390 #define M_SQRT2 1.41421356237309504880 #define M_SQRT1_2 0.70710678118654752440 #ifdef __GNU_VISIBLE #define M_PIl _M_PI_L #define M_PI_2l _M_PI_2L #define M_PI_4l _M_PI_4L #define M_El _M_E_L #endif #endif #if __BSD_VISIBLE #define M_TWOPI (M_PI * 2.0) #define M_3PI_4 2.3561944901923448370E0 #define M_SQRTPI 1.77245385090551602792981 #define M_LN2LO 1.9082149292705877000E-10 #define M_LN2HI 6.9314718036912381649E-1 #define M_SQRT3 1.73205080756887719000 #define M_IVLN10 0.43429448190325182765 /* 1 / log(10) */ #define _M_IVLN10L 0.43429448190325182765112891891660508229439700580366656611445378316586464920887L #define M_LOG2_E _M_LN2 #define M_INVLN2 1.4426950408889633870E0 /* 1 / log(2) */ #endif /* __BSD_VISIBLE */ #include #ifdef __FAST_MATH__ #include #endif _END_STD_C #endif /* _MATH_H_ */ picolibc-1.8.11/libc/include/memory.h000066400000000000000000000002361513574234600174160ustar00rootroot00000000000000/* Copyright (c) 2016 Sebastian Huber */ #ifndef _MEMORY_H #define _MEMORY_H #include #endif /* !_MEMORY_H */ picolibc-1.8.11/libc/include/meson.build000066400000000000000000000063741513574234600201100ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # subdir('sys') subdir('machine') subdir('ssp') subdir('rpc') subdir('arpa') inc_headers = [ 'alloca.h', 'argz.h', 'ar.h', 'assert.h', 'byteswap.h', 'cpio.h', 'ctype.h', 'devctl.h', 'dirent.h', 'endian.h', 'envlock.h', 'envz.h', 'errno.h', 'fastmath.h', 'fcntl.h', 'fenv.h', 'fnmatch.h', 'getopt.h', 'glob.h', 'grp.h', 'iconv.h', 'ieeefp.h', 'inttypes.h', 'langinfo.h', 'libgen.h', 'limits.h', 'locale.h', 'malloc.h', 'math.h', 'memory.h', 'monetary.h', 'ndbm.h', 'newlib.h', 'paths.h', 'pwd.h', 'regdef.h', 'regex.h', 'sched.h', 'search.h', 'setjmp.h', 'signal.h', 'spawn.h', 'stdint.h', 'stdio.h', 'stdio-bufio.h', 'stdnoreturn.h', 'stdlib.h', 'string.h', 'strings.h', 'tar.h', 'termios.h', 'time.h', 'uchar.h', 'unctrl.h', 'unistd.h', 'utime.h', 'utmp.h', 'wchar.h', 'wctype.h', 'wordexp.h' ] if have_complex inc_headers += ['complex.h'] endif inc_headers += ['picotls.h'] if really_install install_headers(inc_headers, install_dir: include_dir) endif # For compatibility with libc++'s __mbstate_t.h: if really_install install_headers(['bits/types/mbstate_t.h'], install_dir: include_dir / 'bits/types') endif if enable_cdefs_tests ignore_headers = ['cpio.h', 'paths.h', 'termios.h', 'newlib.h', 'regdef.h', 'tar.h', 'utmp.h'] foreach header : inc_headers if not (header in ignore_headers) and not (header.startswith('_')) test_name = 'check-cdef-' + header test(test_name, validate_cdefs, args: [meson.current_source_dir() / header] + cc.cmd_array() + c_args + inc_args, suite: 'headers') endif endforeach endif picolibc-1.8.11/libc/include/monetary.h000066400000000000000000000040311513574234600177410ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MONETARY_H_ #define _MONETARY_H_ #include #include #define __need_size_t #include #include #ifndef _SSIZE_T_DECLARED typedef _ssize_t ssize_t; #define _SSIZE_T_DECLARED #endif _BEGIN_STD_C ssize_t strfmon(char * __restrict, size_t, const char * __restrict, ...); ssize_t strfmon_l(char * __restrict, size_t, locale_t, const char * __restrict, ...); _END_STD_C #endif /* _MONETARY_H_ */ picolibc-1.8.11/libc/include/ndbm.h000066400000000000000000000061741513574234600170350ustar00rootroot00000000000000/*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Margo Seltzer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)ndbm.h 8.1 (Berkeley) 6/2/93 * $FreeBSD$ : src/include/ndbm.h * Nov 20 19:45:28 2017 UTC by pfg * SVN Revision 326024 */ #ifndef _NDBM_H_ #define _NDBM_H_ #include /* For mode_t. */ /* #include */ /* * The above header-file is directly included in `libc/search/ndbm.c` * as `db.h` is present in form of `db_local.h`, inside `libc/search` * directory and not in `libc/include`. * Necessary data-types are mentioned in form of forward-declarations */ /* Map dbm interface onto db(3). */ #define DBM_RDONLY O_RDONLY /* Flags to dbm_store(). */ #define DBM_INSERT 0 #define DBM_REPLACE 1 /* * The db(3) support for ndbm always appends this suffix to the * file name to avoid overwriting the user's original database. */ #define DBM_SUFFIX ".db" typedef struct { void *dptr; int dsize; /* XXX Should be size_t according to 1003.1-2008. */ } datum; struct __db; /* Forward-declaration */ typedef struct __db DB; /* Forward-declaration */ typedef DB DBM; #define dbm_pagfno(a) DBM_PAGFNO_NOT_AVAILABLE _BEGIN_STD_C int dbm_clearerr(DBM *); void dbm_close(DBM *); int dbm_delete(DBM *, datum); int dbm_error(DBM *); datum dbm_fetch(DBM *, datum); datum dbm_firstkey(DBM *); datum dbm_nextkey(DBM *); DBM *dbm_open(const char *, int, mode_t); int dbm_store(DBM *, datum, datum, int); #if __BSD_VISIBLE int dbm_dirfno(DBM *); #endif _END_STD_C #endif /* !_NDBM_H_ */ picolibc-1.8.11/libc/include/newlib.h000066400000000000000000000031451513574234600173700ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include picolibc-1.8.11/libc/include/paths.h000066400000000000000000000036351513574234600172330ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _PATHS_H_ #define _PATHS_H_ #define _PATH_DEV "/dev/" #define _PATH_DEVNULL "/dev/null" #define _PATH_DEVZERO "/dev/zero" #define _PATH_BSHELL "/bin/sh" #endif /* _PATHS_H_ */ picolibc-1.8.11/libc/include/picotls.h000066400000000000000000000042611513574234600175650ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _PICOTLS_H_ #define _PICOTLS_H_ #include #ifdef __THREAD_LOCAL_STORAGE #include _BEGIN_STD_C extern char __tls_size[]; static inline size_t _tls_size(void) { return (size_t)(uintptr_t)__tls_size; } extern char __tls_align[]; static inline size_t _tls_align(void) { return (size_t)(uintptr_t)__tls_align; } /* * Initialize a TLS block, copying the data segment from flash and * zeroing the BSS segment. */ void _init_tls(void *tls); /* Set the TLS pointer to the specific block */ void _set_tls(void *tls); _END_STD_C #endif #endif /* _PICOTLS_H_ */ picolibc-1.8.11/libc/include/pwd.h000066400000000000000000000052741513574234600167070ustar00rootroot00000000000000/*- * Copyright (c) 1989 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)pwd.h 5.13 (Berkeley) 5/28/91 */ #ifndef _PWD_H_ #define _PWD_H_ #include #include _BEGIN_STD_C #if __BSD_VISIBLE #define _PATH_PASSWD "/etc/passwd" #define _PASSWORD_LEN 128 /* max length, not counting NULL */ #endif struct passwd { char *pw_name; /* user name */ char *pw_passwd; /* encrypted password */ uid_t pw_uid; /* user uid */ gid_t pw_gid; /* user gid */ char *pw_comment; /* comment */ char *pw_gecos; /* Honeywell login info */ char *pw_dir; /* home directory */ char *pw_shell; /* default shell */ }; struct passwd *getpwuid(uid_t); struct passwd *getpwnam(const char *); #ifndef __INSIDE_CYGWIN__ #if __MISC_VISIBLE || __POSIX_VISIBLE int getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **); int getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **); #endif #if __MISC_VISIBLE || __XSI_VISIBLE >= 4 struct passwd *getpwent(void); void setpwent(void); void endpwent(void); #endif #if __BSD_VISIBLE int setpassent(int); #endif #endif /*!__INSIDE_CYGWIN__*/ _END_STD_C #endif /* _PWD_H_ */ picolibc-1.8.11/libc/include/regdef.h000066400000000000000000000036721513574234600173510ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* regdef.h -- define register names. */ /* This is a standard include file for MIPS targets. Other target probably don't define it, and attempts to include this file will fail. */ #include picolibc-1.8.11/libc/include/regex.h000066400000000000000000000072311513574234600172220ustar00rootroot00000000000000/*- * Copyright (c) 1992 Henry Spencer. * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Henry Spencer of the University of Toronto. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)regex.h 8.2 (Berkeley) 1/3/94 * $FreeBSD: src/include/regex.h,v 1.4 2002/03/23 17:24:53 imp Exp $ */ #ifndef _REGEX_H_ #define _REGEX_H_ #include #define __need_ptrdiff_t #include /* types */ typedef ptrdiff_t regoff_t; typedef struct { unsigned int re_magic; size_t re_nsub; /* number of parenthesized subexpressions */ const char *re_endp; /* end pointer for REG_PEND */ struct re_guts *re_g; /* none of your business :-) */ } regex_t; typedef struct { regoff_t rm_so; /* start of match */ regoff_t rm_eo; /* end of match */ } regmatch_t; /* regcomp() flags */ #define REG_BASIC 0000 #define REG_EXTENDED 0001 #define REG_ICASE 0002 #define REG_NOSUB 0004 #define REG_NEWLINE 0010 #define REG_NOSPEC 0020 #define REG_PEND 0040 #define REG_DUMP 0200 /* regerror() flags */ #define REG_NOMATCH 1 #define REG_BADPAT 2 #define REG_ECOLLATE 3 #define REG_ECTYPE 4 #define REG_EESCAPE 5 #define REG_ESUBREG 6 #define REG_EBRACK 7 #define REG_EPAREN 8 #define REG_EBRACE 9 #define REG_BADBR 10 #define REG_ERANGE 11 #define REG_ESPACE 12 #define REG_BADRPT 13 #define REG_EMPTY 14 #define REG_ASSERT 15 #define REG_INVARG 16 #define REG_ATOI 255 /* convert name to number (!) */ #define REG_ITOA 0400 /* convert number to name (!) */ /* regexec() flags */ #define REG_NOTBOL 00001 #define REG_NOTEOL 00002 #define REG_STARTEND 00004 #define REG_TRACE 00400 /* tracing of execution */ #define REG_LARGE 01000 /* force large representation */ #define REG_BACKR 02000 /* force use of backref code */ _BEGIN_STD_C int regcomp(regex_t *__restrict, const char *__restrict, int); size_t regerror(int, const regex_t * __restrict, char * __restrict, size_t); int regexec(const regex_t * __restrict, const char * __restrict, size_t, regmatch_t[__restrict_arr], int); void regfree(regex_t *); _END_STD_C #endif /* !_REGEX_H_ */ picolibc-1.8.11/libc/include/rpc/000077500000000000000000000000001513574234600165205ustar00rootroot00000000000000picolibc-1.8.11/libc/include/rpc/CMakeLists.txt000066400000000000000000000031311513574234600212560ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_headers(rpc types.h xdr.h ) picolibc-1.8.11/libc/include/rpc/meson.build000066400000000000000000000041271513574234600206660ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_rpc_headers = [ 'types.h', 'xdr.h', ] if really_install install_headers(inc_rpc_headers, install_dir: include_dir / 'rpc') endif if enable_cdefs_tests ignore_headers = [] foreach header : inc_rpc_headers if not (header in ignore_headers) and not (header.startswith('_')) test_name = 'check-cdef-rpc-' + header test(test_name, validate_cdefs, args: [meson.current_source_dir() / header] + cc.cmd_array() + c_args + inc_args, suite: 'headers') endif endforeach endif picolibc-1.8.11/libc/include/rpc/types.h000066400000000000000000000051241513574234600200370ustar00rootroot00000000000000 /* * Copyright (c) 2009, Sun Microsystems, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * - Neither the name of Sun Microsystems, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * from: @(#)types.h 1.18 87/07/24 SMI * from: @(#)types.h 2.3 88/08/15 4.0 RPCSRC * $FreeBSD: src/include/rpc/types.h,v 1.10.6.1 2003/12/18 00:59:50 peter Exp $ * $NetBSD: types.h,v 1.13 2000/06/13 01:02:44 thorpej Exp $ */ /* * Rpc additions to */ #ifndef _RPC_TYPES_H #define _RPC_TYPES_H #include #include #define __need_NULL #include _BEGIN_STD_C #if defined(___int64_t_defined) typedef u_int64_t u_quad_t; typedef int64_t quad_t; #endif /* ___int64_t_defined */ typedef int32_t bool_t; typedef int32_t enum_t; typedef u_int32_t rpcprog_t; typedef u_int32_t rpcvers_t; typedef u_int32_t rpcproc_t; typedef u_int32_t rpcprot_t; typedef u_int32_t rpcport_t; typedef int32_t rpc_inline_t; #define __dontcare__ -1 #ifndef FALSE #define FALSE 0 #endif #ifndef TRUE #define TRUE 1 #endif #ifndef mem_alloc #define mem_alloc(bsize) calloc(1, bsize) #endif #ifndef mem_free #define mem_free(ptr, bsize) free(ptr) #endif _END_STD_C #endif /* !_RPC_TYPES_H */ picolibc-1.8.11/libc/include/rpc/xdr.h000066400000000000000000000334301513574234600174710ustar00rootroot00000000000000 /* * Copyright (c) 2009, Sun Microsystems, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * - Neither the name of Sun Microsystems, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * from: @(#)xdr.h 1.19 87/04/22 SMI * from: @(#)xdr.h 2.2 88/07/29 4.0 RPCSRC * $FreeBSD: src/include/rpc/xdr.h,v 1.23 2003/03/07 13:19:40 nectar Exp $ * $NetBSD: xdr.h,v 1.19 2000/07/17 05:00:45 matt Exp $ */ /* * xdr.h, External Data Representation Serialization Routines. * * Copyright (C) 1984, Sun Microsystems, Inc. */ #ifndef _RPC_XDR_H #define _RPC_XDR_H #include #include _BEGIN_STD_C /* * XDR provides a conventional way for converting between C data * types and an external bit-string representation. Library supplied * routines provide for the conversion on built-in C data types. These * routines and utility routines defined here are used to help implement * a type encode/decode routine for each user-defined type. * * Each data type provides a single procedure which takes two arguments: * * bool_t * xdrproc(XDR *xdrs, *argresp) * * xdrs is an instance of a XDR handle, to which or from which the data * type is to be converted. argresp is a pointer to the structure to be * converted. The XDR handle contains an operation field which indicates * which of the operations (ENCODE, DECODE * or FREE) is to be performed. * * XDR_DECODE may allocate space if the pointer argresp is null. This * data can be freed with the XDR_FREE operation. * * We write only one procedure per data type to make it easy * to keep the encode and decode procedures for a data type consistent. * In many cases the same code performs all operations on a user defined type, * because all the hard work is done in the component type routines. * decode as a series of calls on the nested data types. */ /* * Xdr operations. XDR_ENCODE causes the type to be encoded into the * stream. XDR_DECODE causes the type to be extracted from the stream. * XDR_FREE can be used to release the space allocated by an XDR_DECODE * request. */ enum xdr_op { XDR_ENCODE = 0, XDR_DECODE = 1, XDR_FREE = 2 }; /* * This is the number of bytes per unit of external data. */ #define BYTES_PER_XDR_UNIT (4) #if 1 /* faster version when BYTES_PER_XDR_UNIT is a power of two */ #define RNDUP(x) (((x) + BYTES_PER_XDR_UNIT - 1) & ~(BYTES_PER_XDR_UNIT - 1)) #else /* old version */ #define RNDUP(x) ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) * BYTES_PER_XDR_UNIT) #endif /* * The XDR handle. * Contains operation which is being applied to the stream, * an operations vector for the particular implementation (e.g. see xdr_mem.c), * and two private fields for the use of the particular implementation. */ typedef struct __rpc_xdr { enum xdr_op x_op; /* operation; fast additional param */ const struct xdr_ops { /* get a long from underlying stream */ bool_t (*x_getlong)(struct __rpc_xdr *, long *); /* put a long to " */ bool_t (*x_putlong)(struct __rpc_xdr *, const long *); /* get some bytes from " */ bool_t (*x_getbytes)(struct __rpc_xdr *, char *, u_int); /* put some bytes to " */ bool_t (*x_putbytes)(struct __rpc_xdr *, const char *, u_int); /* returns bytes off from beginning */ u_int (*x_getpostn)(struct __rpc_xdr *); /* lets you reposition the stream */ bool_t (*x_setpostn)(struct __rpc_xdr *, u_int); /* buf quick ptr to buffered data */ int32_t *(*x_inline)(struct __rpc_xdr *, u_int); /* free privates of this xdr_stream */ void (*x_destroy)(struct __rpc_xdr *); /* get an int32 from this xdr_stream */ bool_t (*x_getint32)(struct __rpc_xdr *, int32_t *); /* put an int32 to the underlying stream */ bool_t (*x_putint32)(struct __rpc_xdr *, const int32_t *); } *x_ops; char *x_public; /* users' data */ void *x_private; /* pointer to private data */ char *x_base; /* private used for position info */ u_int x_handy; /* extra private word */ } XDR; /* * A xdrproc_t exists for each data type which is to be encoded or decoded. * * The second argument to the xdrproc_t is a pointer to an opaque pointer. * The opaque pointer generally points to a structure of the data type * to be decoded. If this pointer is 0, then the type routines should * allocate dynamic storage of the appropriate size and return it. * bool_t (*xdrproc_t)(XDR *, some_type *) */ typedef bool_t (*xdrproc_t)(XDR *, ...); /* * Operations defined on a XDR handle * * XDR *xdrs; * long *longp; * char *addr; * u_int len; * u_int pos; */ #define XDR_GETINT32(xdrs, int32p) (*(xdrs)->x_ops->x_getint32)(xdrs, int32p) #define xdr_getint32(xdrs, int32p) (*(xdrs)->x_ops->x_getint32)(xdrs, int32p) #define XDR_PUTINT32(xdrs, int32p) (*(xdrs)->x_ops->x_putint32)(xdrs, int32p) #define xdr_putint32(xdrs, int32p) (*(xdrs)->x_ops->x_putint32)(xdrs, int32p) #define XDR_GETLONG(xdrs, longp) (*(xdrs)->x_ops->x_getlong)(xdrs, longp) #define xdr_getlong(xdrs, longp) (*(xdrs)->x_ops->x_getlong)(xdrs, longp) #define XDR_PUTLONG(xdrs, longp) (*(xdrs)->x_ops->x_putlong)(xdrs, longp) #define xdr_putlong(xdrs, longp) (*(xdrs)->x_ops->x_putlong)(xdrs, longp) #define XDR_GETBYTES(xdrs, addr, len) (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) #define xdr_getbytes(xdrs, addr, len) (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) #define XDR_PUTBYTES(xdrs, addr, len) (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) #define xdr_putbytes(xdrs, addr, len) (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) #define XDR_GETPOS(xdrs) (*(xdrs)->x_ops->x_getpostn)(xdrs) #define xdr_getpos(xdrs) (*(xdrs)->x_ops->x_getpostn)(xdrs) #define XDR_SETPOS(xdrs, pos) (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) #define xdr_setpos(xdrs, pos) (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) #define XDR_INLINE(xdrs, len) (*(xdrs)->x_ops->x_inline)(xdrs, len) #define xdr_inline(xdrs, len) (*(xdrs)->x_ops->x_inline)(xdrs, len) #define XDR_DESTROY(xdrs) \ do { \ if ((xdrs)->x_ops->x_destroy) \ (*(xdrs)->x_ops->x_destroy)(xdrs); \ } while (0) #define xdr_destroy(xdrs) \ do { \ if ((xdrs)->x_ops->x_destroy) \ (*(xdrs)->x_ops->x_destroy)(xdrs); \ } while (0) /* * Solaris strips the '_t' from these types -- not sure why. * But, let's be compatible. */ #define xdr_rpcvers(xdrs, versp) xdr_u_int32(xdrs, versp) #define xdr_rpcprog(xdrs, progp) xdr_u_int32(xdrs, progp) #define xdr_rpcproc(xdrs, procp) xdr_u_int32(xdrs, procp) #define xdr_rpcprot(xdrs, protp) xdr_u_int32(xdrs, protp) #define xdr_rpcport(xdrs, portp) xdr_u_int32(xdrs, portp) /* * Support struct for discriminated unions. * You create an array of xdrdiscrim structures, terminated with * an entry with a null procedure pointer. The xdr_union routine gets * the discriminant value and then searches the array of structures * for a matching value. If a match is found the associated xdr routine * is called to handle that part of the union. If there is * no match, then a default routine may be called. * If there is no match and no default routine it is an error. */ #define NULL_xdrproc_t ((xdrproc_t)0) struct xdr_discrim { int value; xdrproc_t proc; }; /* * In-line routines for fast encode/decode of primitive data types. * Caveat emptor: these use single memory cycles to get the * data from the underlying buffer, and will fail to operate * properly if the data is not aligned. The standard way to use these * is to say: * if ((buf = XDR_INLINE(xdrs, count)) == NULL) * return (FALSE); * <<< macro calls >>> * where ``count'' is the number of bytes of data occupied * by the primitive data types. * * N.B. and frozen for all time: each data type here uses 4 bytes * of external representation. */ #define IXDR_GET_INT32(buf) ((int32_t)ntohl((u_int32_t) * (buf)++)) #define IXDR_PUT_INT32(buf, v) (*(buf)++ = (int32_t)htonl((u_int32_t)v)) #define IXDR_GET_U_INT32(buf) ((uint32_t)IXDR_GET_INT32(buf)) #define IXDR_PUT_U_INT32(buf, v) IXDR_PUT_INT32((buf), ((int32_t)(v))) /* Warning: inline long routines are broken for 64 bit platforms. * Because the other inline routines below are implemented in terms * of them, they are all also broken for 64 bit platforms. */ #define IXDR_GET_LONG(buf) ((long)ntohl((u_int32_t) * (buf)++)) #define IXDR_PUT_LONG(buf, v) (*(buf)++ = (int32_t)htonl((u_int32_t)v)) #define IXDR_GET_U_LONG(buf) ((u_long)IXDR_GET_LONG(buf)) #define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG((buf), (v)) #define IXDR_GET_BOOL(buf) ((bool_t)IXDR_GET_LONG(buf)) #define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_LONG(buf)) #define IXDR_GET_SHORT(buf) ((short)IXDR_GET_LONG(buf)) #define IXDR_GET_U_SHORT(buf) ((u_short)IXDR_GET_LONG(buf)) #define IXDR_PUT_BOOL(buf, v) IXDR_PUT_LONG((buf), (v)) #define IXDR_PUT_ENUM(buf, v) IXDR_PUT_LONG((buf), (v)) #define IXDR_PUT_SHORT(buf, v) IXDR_PUT_LONG((buf), (v)) #define IXDR_PUT_U_SHORT(buf, v) IXDR_PUT_LONG((buf), (v)) /* * These are the "generic" xdr routines. */ extern bool_t xdr_void(void); extern bool_t xdr_short(XDR *, short *); extern bool_t xdr_u_short(XDR *, u_short *); extern bool_t xdr_int(XDR *, int *); extern bool_t xdr_u_int(XDR *, u_int *); extern bool_t xdr_long(XDR *, long *); extern bool_t xdr_u_long(XDR *, u_long *); extern bool_t xdr_int8_t(XDR *, int8_t *); extern bool_t xdr_uint8_t(XDR *, uint8_t *); extern bool_t xdr_u_int8_t(XDR *, u_int8_t *); extern bool_t xdr_int16_t(XDR *, int16_t *); extern bool_t xdr_uint16_t(XDR *, uint16_t *); extern bool_t xdr_u_int16_t(XDR *, u_int16_t *); extern bool_t xdr_int32_t(XDR *, int32_t *); extern bool_t xdr_uint32_t(XDR *, uint32_t *); extern bool_t xdr_u_int32_t(XDR *, u_int32_t *); #if defined(___int64_t_defined) extern bool_t xdr_int64_t(XDR *, int64_t *); extern bool_t xdr_uint64_t(XDR *, uint64_t *); extern bool_t xdr_u_int64_t(XDR *, u_int64_t *); #endif /* ___int64_t_defined */ extern bool_t xdr_bool(XDR *, bool_t *); extern bool_t xdr_enum(XDR *, enum_t *); extern bool_t xdr_array(XDR *, char **, u_int *, u_int, u_int, xdrproc_t); extern bool_t xdr_bytes(XDR *, char **, u_int *, u_int); extern bool_t xdr_opaque(XDR *, char *, u_int); extern bool_t xdr_string(XDR *, char **, u_int); extern bool_t xdr_union(XDR *, enum_t *, char *, const struct xdr_discrim *, xdrproc_t); extern bool_t xdr_char(XDR *, char *); extern bool_t xdr_u_char(XDR *, u_char *); extern bool_t xdr_vector(XDR *, char *, u_int, u_int, xdrproc_t); extern bool_t xdr_float(XDR *, float *); extern bool_t xdr_double(XDR *, double *); /* extern bool_t xdr_quadruple (XDR *, long double *); */ extern bool_t xdr_reference(XDR *, char **, u_int, xdrproc_t); extern bool_t xdr_pointer(XDR *, char **, u_int, xdrproc_t); extern bool_t xdr_wrapstring(XDR *, char **); #if defined(___int64_t_defined) extern bool_t xdr_hyper(XDR *, quad_t *); extern bool_t xdr_u_hyper(XDR *, u_quad_t *); extern bool_t xdr_longlong_t(XDR *, quad_t *); extern bool_t xdr_u_longlong_t(XDR *, u_quad_t *); #endif /* ___int64_t_defined */ extern u_long xdr_sizeof(xdrproc_t, void *); /* * Common opaque bytes objects used by many rpc protocols; * declared here due to commonality. */ #define MAX_NETOBJ_SZ 1024 struct netobj { u_int n_len; char *n_bytes; }; typedef struct netobj netobj; extern bool_t xdr_netobj(XDR *, struct netobj *); /* * These are the public routines for the various implementations of * xdr streams. */ /* XDR using memory buffers */ extern void xdrmem_create(XDR *, char *, u_int, enum xdr_op); /* XDR using stdio library */ #if defined(_STDIO_H_) extern void xdrstdio_create(XDR *, FILE *, enum xdr_op); #endif /* XDR pseudo records for tcp */ extern void xdrrec_create(XDR *, u_int, u_int, void *, int (*)(void *, void *, int), int (*)(void *, void *, int)); /* make end of xdr record */ extern bool_t xdrrec_endofrecord(XDR *, bool_t); /* move to beginning of next record */ extern bool_t xdrrec_skiprecord(XDR *); /* true if no more input */ extern bool_t xdrrec_eof(XDR *); extern u_int xdrrec_readbytes(XDR *, caddr_t, u_int); /* free memory buffers for xdr */ extern void xdr_free(xdrproc_t, void *); _END_STD_C #endif /* !_RPC_XDR_H */ picolibc-1.8.11/libc/include/sched.h000066400000000000000000000047211513574234600171770ustar00rootroot00000000000000/* * Written by Joel Sherrill . * * COPYRIGHT (c) 1989-2010. * On-Line Applications Research Corporation (OAR). * * Permission to use, copy, modify, and distribute this software for any * purpose without fee is hereby granted, provided that this entire notice * is included in all copies of any software which is or includes a copy * or modification of this software. * * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED * WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION * OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS * SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. * * $Id$ */ #ifndef _SCHED_H_ #define _SCHED_H_ #include #include #include _BEGIN_STD_C #if defined(_POSIX_PRIORITY_SCHEDULING) /* * XBD 13 - Set Scheduling Parameters, P1003.1b-2008, p. 1803 */ int sched_setparam(pid_t __pid, const struct sched_param *__param); /* * XBD 13 - Set Scheduling Parameters, P1003.1b-2008, p. 1800 */ int sched_getparam(pid_t __pid, struct sched_param *__param); /* * XBD 13 - Set Scheduling Policy and Scheduling Parameters, * P1003.1b-2008, p. 1805 */ int sched_setscheduler(pid_t __pid, int __policy, const struct sched_param *__param); /* * XBD 13 - Get Scheduling Policy, P1003.1b-2008, p. 1801 */ int sched_getscheduler(pid_t __pid); /* * XBD 13 - Get Scheduling Parameter Limits, P1003.1b-2008, p. 1799 */ int sched_get_priority_max(int __policy); int sched_get_priority_min(int __policy); /* * XBD 13 - Get Scheduling Parameter Limits, P1003.1b-2008, p. 1802 */ int sched_rr_get_interval(pid_t __pid, struct timespec *__interval); #endif /* _POSIX_PRIORITY_SCHEDULING */ #if defined(_POSIX_THREADS) || defined(_POSIX_PRIORITY_SCHEDULING) /* * XBD 13 - Yield Processor, P1003.1b-2008, p. 1807 */ int sched_yield(void); #endif /* _POSIX_THREADS or _POSIX_PRIORITY_SCHEDULING */ #if __GNU_VISIBLE int sched_getcpu(void); /* The following functions should only be declared if the type cpu_set_t is defined through indirect inclusion of sys/cpuset.h, only available on some targets. */ #ifdef _SYS_CPUSET_H_ int sched_getaffinity(pid_t, size_t, cpu_set_t *); int sched_get_thread_affinity(void *, size_t, cpu_set_t *); int sched_setaffinity(pid_t, size_t, const cpu_set_t *); int sched_set_thread_affinity(void *, size_t, const cpu_set_t *); #endif /* _SYS_CPUSET_H_ */ #endif _END_STD_C #endif /* _SCHED_H_ */ picolibc-1.8.11/libc/include/search.h000066400000000000000000000055271513574234600173630ustar00rootroot00000000000000/* Copyright (c) 1990, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $NetBSD: search.h,v 1.12 1999/02/22 10:34:28 christos Exp $ */ /* $FreeBSD: src/include/search.h,v 1.4 2002/03/23 17:24:53 imp Exp $ */ /* * Written by J.T. Conklin * Public domain. */ #ifndef _SEARCH_H_ #define _SEARCH_H_ #include #include #include typedef struct entry { char *key; void *data; } ENTRY; typedef enum { FIND, ENTER } ACTION; typedef enum { preorder, postorder, endorder, leaf } VISIT; #ifdef _SEARCH_PRIVATE typedef struct node { char *key; struct node *llink, *rlink; } node_t; #endif struct hsearch_data { struct internal_head *htable; size_t htablesize; }; #ifndef __compar_fn_t_defined #define __compar_fn_t_defined typedef int (*__compar_fn_t)(const void *, const void *); #endif _BEGIN_STD_C int hcreate(size_t); void hdestroy(void); ENTRY *hsearch(ENTRY, ACTION); int hcreate_r(size_t, struct hsearch_data *); void hdestroy_r(struct hsearch_data *); int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *); void *tdelete(const void *__restrict, void **__restrict, __compar_fn_t); void tdestroy(void *, void (*)(void *)); void *tfind(const void *, void **, __compar_fn_t); void *tsearch(const void *, void **, __compar_fn_t); void twalk(const void *, void (*)(const void *, VISIT, int)); _END_STD_C #endif /* !_SEARCH_H_ */ picolibc-1.8.11/libc/include/setjmp.h000066400000000000000000000040111513574234600174030ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* setjmp.h stubs for future use. */ #ifndef _SETJMP_H_ #define _SETJMP_H_ #include #include _BEGIN_STD_C __noreturn void longjmp(jmp_buf __jmpb, int __retval); __returns_twice int setjmp(jmp_buf __jmpb); _END_STD_C #endif /* _SETJMP_H_ */ picolibc-1.8.11/libc/include/signal.h000066400000000000000000000234661513574234600173750ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SIGNAL_H_ #define _SIGNAL_H_ #include #define __need_size_t #include #include #include #include _BEGIN_STD_C typedef int sig_atomic_t; /* Atomic entity type (ANSI) */ typedef void (*_sig_func_ptr)(int); #define SIG_DFL ((_sig_func_ptr)0) /* Default action */ #define SIG_IGN ((_sig_func_ptr)1) /* Ignore action */ #define SIG_ERR ((_sig_func_ptr) - 1) /* Error return */ #if __POSIX_VISIBLE #ifndef _UID_T_DECLARED typedef __uid_t uid_t; /* user id */ #define _UID_T_DECLARED #endif #if !defined(_SIGSET_T_DECLARED) #define _SIGSET_T_DECLARED typedef __sigset_t sigset_t; #endif union sigval { int sival_int; /* Integer signal value */ void *sival_ptr; /* Pointer signal value */ }; /* Signal Actions, P1003.1b-1993, p. 64 */ /* si_code values, p. 66 */ #define SI_USER 1 /* Sent by a user. kill(), abort(), etc */ #define SI_QUEUE 2 /* Sent by sigqueue() */ #define SI_TIMER 3 /* Sent by expiration of a timer_settime() timer */ #define SI_ASYNCIO 4 /* Indicates completion of asycnhronous IO */ #define SI_MESGQ 5 /* Indicates arrival of a message at an empty queue */ typedef struct { int si_signo; /* Signal number */ int si_code; /* Cause of the signal */ int si_errno; /* If non-zero, the errno */ __pid_t si_pid; /* Sending process ID */ uid_t si_uid; /* Real UID of sending process */ void *si_addr; /* Address of faulting instruction */ int si_status; /* Exit value or signal */ union sigval si_value; /* Signal value */ } siginfo_t; /* * Possible values for sa_flags in sigaction below. */ #define SA_NOCLDSTOP (1 << 0) #define SA_ONSTACK (1 << 1) #define SA_RESETHAND (1 << 2) #define SA_RESTART (1 << 3) #define SA_SIGINFO (1 << 4) #define SA_NOCLDWAIT (1 << 5) #define SA_NODEFER (1 << 6) struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, siginfo_t *, void *); }; sigset_t sa_mask; int sa_flags; }; /* * Possible values for ss_flags in stack_t below. */ #define SS_ONSTACK 0x1 #define SS_DISABLE 0x2 /* * Structure used in sigaltstack call. */ typedef struct sigaltstack { void *ss_sp; /* Stack base or pointer. */ int ss_flags; /* Flags. */ size_t ss_size; /* Stack size. */ } stack_t; #define SIG_SETMASK 0 /* set mask with sigprocmask() */ #define SIG_BLOCK 1 /* set of signals to block */ #define SIG_UNBLOCK 2 /* set of signals to unblock */ #endif /* __POSIX_VISIBLE */ #if defined(_POSIX_REALTIME_SIGNALS) || __POSIX_VISIBLE >= 199309 /* sigev_notify values NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD. */ #define SIGEV_NONE 1 /* No asynchronous notification shall be delivered */ /* when the event of interest occurs. */ #define SIGEV_SIGNAL 2 /* A queued signal, with an application defined */ /* value, shall be delivered when the event of */ /* interest occurs. */ #define SIGEV_THREAD 3 /* A notification function shall be called to */ /* perform notification. */ /* Signal Generation and Delivery, P1003.1b-1993, p. 63 NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and sigev_notify_attributes to the sigevent structure. */ struct sigevent { int sigev_notify; /* Notification type */ int sigev_signo; /* Signal number */ union sigval sigev_value; /* Signal value */ void (*sigev_notify_function)(union sigval); /* Notification function */ void *sigev_notify_attributes; /* Notification Attributes */ }; #endif /* defined(_POSIX_REALTIME_SIGNALS) || __POSIX_VISIBLE >= 199309 */ #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809 /* * Minimum and default signal stack constants. Allow for target overrides * from . */ #ifndef MINSIGSTKSZ #define MINSIGSTKSZ 2048 #endif #ifndef SIGSTKSZ #define SIGSTKSZ 8192 #endif #endif #define SIGHUP 1 /* hangup */ #define SIGINT 2 /* interrupt */ #define SIGQUIT 3 /* quit */ #define SIGILL 4 /* illegal instruction (not reset when caught) */ #define SIGTRAP 5 /* trace trap (not reset when caught) */ #define SIGIOT 6 /* IOT instruction */ #define SIGABRT 6 /* used by abort, replace SIGIOT in the future */ #define SIGEMT 7 /* EMT instruction */ #define SIGFPE 8 /* floating point exception */ #define SIGKILL 9 /* kill (cannot be caught or ignored) */ #define SIGBUS 10 /* bus error */ #define SIGSEGV 11 /* segmentation violation */ #define SIGSYS 12 /* bad argument to system call */ #define SIGPIPE 13 /* write on a pipe with no one to read it */ #define SIGALRM 14 /* alarm clock */ #define SIGTERM 15 /* software termination signal from kill */ #define SIGURG 16 /* urgent condition on IO channel */ #define SIGSTOP 17 /* sendable stop signal not from tty */ #define SIGTSTP 18 /* stop signal from tty */ #define SIGCONT 19 /* continue a stopped process */ #define SIGCHLD 20 /* to parent on child stop or exit */ #define SIGCLD 20 /* System V name for SIGCHLD */ #define SIGTTIN 21 /* to readers pgrp upon background tty read */ #define SIGTTOU 22 /* like TTIN for output if (tp->t_local<OSTOP) */ #define SIGIO 23 /* input/output possible signal */ #define SIGPOLL SIGIO /* System V name for SIGIO */ #define SIGXCPU 24 /* exceeded CPU time limit */ #define SIGXFSZ 25 /* exceeded file size limit */ #define SIGVTALRM 26 /* virtual time alarm */ #define SIGPROF 27 /* profiling time alarm */ #define SIGWINCH 28 /* window changed */ #define SIGLOST 29 /* resource lost (eg, record-lock lost) */ #define SIGUSR1 30 /* user defined signal 1 */ #define SIGUSR2 31 /* user defined signal 2 */ #define _NSIG 32 /* Using __MISC_VISIBLE until POSIX Issue 8 is officially released */ #if __MISC_VISIBLE #if __SIZEOF_INT__ >= 4 #define SIG2STR_MAX 17 /* (sizeof("RTMAX+") + sizeof("4294967295") - 1) */ #else #define SIG2STR_MAX 12 /* (sizeof("RTMAX+") + sizeof("65535") - 1) */ #endif #endif #if __BSD_VISIBLE typedef _sig_func_ptr sig_t; /* BSD naming */ #endif #if __GNU_VISIBLE typedef _sig_func_ptr sighandler_t; /* glibc naming */ #endif #if __POSIX_VISIBLE int kill(__pid_t pid, int sig); #endif #if __XSI_VISIBLE >= 500 int killpg(__pid_t pid, int sig); #endif #if __POSIX_VISIBLE >= 200809L void psiginfo(const siginfo_t *, const char *); #endif #if __BSD_VISIBLE || __SVID_VISIBLE void psignal(int, const char *); #endif int raise(int); #if __MISC_VISIBLE int sig2str(int, char *); #endif #if __POSIX_VISIBLE int sigaction(int, const struct sigaction * __restrict, struct sigaction * __restrict); int sigaddset(sigset_t *, const int); #define sigaddset(what, sig) (*(what) |= (1 << (sig)), 0) #endif #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809 int sigaltstack(const stack_t * __restrict, stack_t * __restrict); #endif #if __POSIX_VISIBLE int sigdelset(sigset_t *, const int); #define sigdelset(what, sig) (*(what) &= ~((sigset_t)1 << (sig)), 0) int sigemptyset(sigset_t *); #define sigemptyset(what) (*(what) = (sigset_t)0, 0) int sigfillset(sigset_t *); #define sigfillset(what) (*(what) = ~((sigset_t)0), 0) int sigismember(const sigset_t *, int); #define sigismember(what, sig) (((*(what)) & ((sigset_t)1 << (sig))) != 0) #endif _sig_func_ptr signal(int, _sig_func_ptr); #if __POSIX_VISIBLE int sigpending(sigset_t *); int sigprocmask(int, const sigset_t *, sigset_t *); #endif #if __POSIX_VISIBLE >= 199309L int sigqueue(__pid_t, int, const union sigval); #endif #if __POSIX_VISIBLE int sigsuspend(const sigset_t *); #endif #if __POSIX_VISIBLE >= 199309L int sigtimedwait(const sigset_t *, siginfo_t *, const struct timespec *); #endif #if __POSIX_VISIBLE >= 199506L int sigwait(const sigset_t *, int *); #endif #if __POSIX_VISIBLE >= 199309L int sigwaitinfo(const sigset_t *, siginfo_t *); #endif #if __MISC_VISIBLE int str2sig(const char * __restrict, int * __restrict); #endif _END_STD_C #endif /* _SIGNAL_H_ */ picolibc-1.8.11/libc/include/spawn.h000066400000000000000000000111621513574234600172360ustar00rootroot00000000000000/*- * Copyright (c) 2008 Ed Schouten * 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. */ #ifndef _SPAWN_H_ #define _SPAWN_H_ #include #include #include #define __need_sigset_t #include struct sched_param; typedef struct __posix_spawnattr *posix_spawnattr_t; typedef struct __posix_spawn_file_actions *posix_spawn_file_actions_t; #define POSIX_SPAWN_RESETIDS 0x01 #define POSIX_SPAWN_SETPGROUP 0x02 #define POSIX_SPAWN_SETSCHEDPARAM 0x04 #define POSIX_SPAWN_SETSCHEDULER 0x08 #define POSIX_SPAWN_SETSIGDEF 0x10 #define POSIX_SPAWN_SETSIGMASK 0x20 _BEGIN_STD_C /* * Spawn routines * * XXX both arrays should be __restrict, but this does not work when GCC * is invoked with -std=c99. */ int posix_spawn(pid_t * __restrict, const char * __restrict, const posix_spawn_file_actions_t *, const posix_spawnattr_t * __restrict, char * const[], char * const[]); int posix_spawnp(pid_t * __restrict, const char * __restrict, const posix_spawn_file_actions_t *, const posix_spawnattr_t * __restrict, char * const[], char * const[]); /* * File descriptor actions */ int posix_spawn_file_actions_init(posix_spawn_file_actions_t *); int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *); int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t * __restrict, int, const char * __restrict, int, mode_t); int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int, int); int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *, int); #if __POSIX_VISIBLE >= 202405 int posix_spawn_file_actions_addchdir(posix_spawn_file_actions_t * __restrict, const char * __restrict); int posix_spawn_file_actions_addfchdir(posix_spawn_file_actions_t * __restrict, int); #endif #if __MISC_VISIBLE || __GNU_VISIBLE int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t * __restrict, const char * __restrict); int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t * __restrict, int); #endif /* * Spawn attributes */ int posix_spawnattr_init(posix_spawnattr_t *); int posix_spawnattr_destroy(posix_spawnattr_t *); int posix_spawnattr_getflags(const posix_spawnattr_t * __restrict, short * __restrict); int posix_spawnattr_getpgroup(const posix_spawnattr_t * __restrict, pid_t * __restrict); int posix_spawnattr_getschedparam(const posix_spawnattr_t * __restrict, struct sched_param * __restrict); int posix_spawnattr_getschedpolicy(const posix_spawnattr_t * __restrict, int * __restrict); int posix_spawnattr_getsigdefault(const posix_spawnattr_t * __restrict, sigset_t * __restrict); int posix_spawnattr_getsigmask(const posix_spawnattr_t * __restrict, sigset_t * __restrict); int posix_spawnattr_setflags(posix_spawnattr_t *, short); int posix_spawnattr_setpgroup(posix_spawnattr_t *, pid_t); int posix_spawnattr_setschedparam(posix_spawnattr_t * __restrict, const struct sched_param * __restrict); int posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int); int posix_spawnattr_setsigdefault(posix_spawnattr_t * __restrict, const sigset_t * __restrict); int posix_spawnattr_setsigmask(posix_spawnattr_t * __restrict, const sigset_t * __restrict); _END_STD_C #endif /* !_SPAWN_H_ */ picolibc-1.8.11/libc/include/ssp/000077500000000000000000000000001513574234600165415ustar00rootroot00000000000000picolibc-1.8.11/libc/include/ssp/CMakeLists.txt000066400000000000000000000032201513574234600212760ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_headers("ssp" ssp.h stdio.h stdlib.h string.h strings.h unistd.h wchar.h ) picolibc-1.8.11/libc/include/ssp/meson.build000066400000000000000000000034371513574234600207120ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2020 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_ssp_headers = [ 'ssp.h', 'stdio.h', 'stdlib.h', 'string.h', 'strings.h', 'unistd.h', 'wchar.h', ] if really_install install_headers(inc_ssp_headers, install_dir: include_dir / 'ssp') endif picolibc-1.8.11/libc/include/ssp/ssp.h000066400000000000000000000070231513574234600175210ustar00rootroot00000000000000/* $NetBSD: ssp.h,v 1.13 2015/09/03 20:43:47 plunky Exp $ */ /*- * Copyright (c) 2006, 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SSP_SSP_H_ #define _SSP_SSP_H_ #include /* __ssp_real is used by the implementation in libc */ #if __SSP_FORTIFY_LEVEL == 0 #define __ssp_real_(fun) fun #else #define __ssp_real_(fun) __ssp_real_##fun #endif #define __ssp_real(fun) __ssp_real_(fun) #if __SSP_FORTIFY_LEVEL > 2 #define __ssp_bos(ptr) __builtin_dynamic_object_size(ptr, 1) #define __ssp_bos0(ptr) __builtin_dynamic_object_size(ptr, 0) #define __ssp_bos_known(ptr) \ (__builtin_object_size(ptr, 0) != (size_t)-1 || !__builtin_constant_p(__ssp_bos(ptr))) #else #define __ssp_bos(ptr) __builtin_object_size(ptr, __SSP_FORTIFY_LEVEL > 1) #define __ssp_bos0(ptr) __builtin_object_size(ptr, 0) #define __ssp_bos_known(ptr) (__ssp_bos0(ptr) != (size_t)-1) #endif #define __ssp_check(buf, len, bos) \ if (__ssp_bos_known(buf) && len > bos(buf)) \ __chk_fail() #define __ssp_decl(rtype, fun, args) \ rtype __ssp_real_(fun) \ args __asm__(__ASMNAME(#fun)); \ __declare_extern_inline(rtype) fun args #define __ssp_redirect_raw(rtype, fun, args, call, cond, bos) \ __ssp_decl(rtype, fun, args) \ { \ if (cond) \ __ssp_check(__buf, __len, bos); \ return __ssp_real_(fun) call; \ } #define __ssp_redirect(rtype, fun, args, call) \ __ssp_redirect_raw(rtype, fun, args, call, 1, __ssp_bos) #define __ssp_redirect0(rtype, fun, args, call) \ __ssp_redirect_raw(rtype, fun, args, call, 1, __ssp_bos0) #define __ssp_overlap(a, b, l) (((a) <= (b) && (b) < (a) + (l)) || ((b) <= (a) && (a) < (b) + (l))) _BEGIN_STD_C void __stack_chk_fail(void) __noreturn; void __chk_fail(void) __noreturn; void set_fortify_handler(void (*handler)(int sig)); _END_STD_C #endif /* _SSP_SSP_H_ */ picolibc-1.8.11/libc/include/ssp/stdio.h000066400000000000000000000072551513574234600200450ustar00rootroot00000000000000/* $NetBSD: stdio.h,v 1.5 2011/07/17 20:54:34 joerg Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SSP_STDIO_H_ #define _SSP_STDIO_H_ #include _BEGIN_STD_C int __sprintf_chk(char * __restrict, int, size_t, const char * __restrict, ...) __picolibc_format(__printf__, 4, 5); int __vsprintf_chk(char * __restrict, int, size_t, const char * __restrict, __gnuc_va_list) __picolibc_format(__printf__, 4, 0); int __snprintf_chk(char * __restrict, size_t, int, size_t, const char * __restrict, ...) __picolibc_format(__printf__, 5, 6); int __vsnprintf_chk(char * __restrict, size_t, int, size_t, const char * __restrict, __gnuc_va_list) __picolibc_format(__printf__, 5, 0); char *__gets_chk(char *, size_t); #if __SSP_FORTIFY_LEVEL > 0 #define sprintf(str, ...) __builtin___sprintf_chk(str, 0, __ssp_bos(str), __VA_ARGS__) #define vsprintf(str, fmt, ap) __builtin___vsprintf_chk(str, 0, __ssp_bos(str), fmt, ap) #define snprintf(str, len, ...) __builtin___snprintf_chk(str, len, 0, __ssp_bos(str), __VA_ARGS__) #define vsnprintf(str, len, fmt, ap) __builtin___vsnprintf_chk(str, len, 0, __ssp_bos(str), fmt, ap) #define gets(str) __gets_chk(str, __ssp_bos(str)) __ssp_decl(char *, fgets, (char * __restrict __buf, int __len, FILE *__fp)) { if (__len > 0) __ssp_check(__buf, (size_t)__len, __ssp_bos); return __ssp_real_fgets(__buf, __len, __fp); } #if __GNU_VISIBLE __ssp_decl(char *, fgets_unlocked, (char * __restrict __buf, int __len, FILE *__fp)) { if (__len > 0) __ssp_check(__buf, (size_t)__len, __ssp_bos); return __ssp_real_fgets_unlocked(__buf, __len, __fp); } #endif /* __GNU_VISIBLE */ __ssp_decl(size_t, fread, (void * __restrict __ptr, size_t __size, size_t __n, FILE * __restrict __fp)) { __ssp_check(__ptr, __size * __n, __ssp_bos0); return __ssp_real_fread(__ptr, __size, __n, __fp); } #if __MISC_VISIBLE __ssp_decl(size_t, fread_unlocked, (void * __restrict __ptr, size_t __size, size_t __n, FILE * __restrict __fp)) { __ssp_check(__ptr, __size * __n, __ssp_bos0); return __ssp_real_fread_unlocked(__ptr, __size, __n, __fp); } #endif /* __MISC_VISIBLE */ #endif /* __SSP_FORTIFY_LEVEL > 0 */ _END_STD_C #endif /* _SSP_STDIO_H_ */ picolibc-1.8.11/libc/include/ssp/stdlib.h000066400000000000000000000014451513574234600201770ustar00rootroot00000000000000/* Copyright (c) 2017 Yaakov Selkowitz */ #ifndef _SSP_STDLIB_H_ #define _SSP_STDLIB_H_ #include #if __SSP_FORTIFY_LEVEL > 0 _BEGIN_STD_C __ssp_decl(size_t, mbstowcs, (wchar_t * __buf, const char *__src, size_t __n)) { if (__buf != NULL) __ssp_check(__buf, __n * sizeof(wchar_t), __ssp_bos); return __ssp_real_mbstowcs(__buf, __src, __n); } __ssp_redirect_raw(size_t, wcstombs, (char *__buf, const wchar_t *__src, size_t __len), (__buf, __src, __len), __buf != NULL, __ssp_bos); __ssp_decl(int, wctomb, (char *__buf, wchar_t __wc)) { if (__buf != NULL) __ssp_check(__buf, MB_CUR_MAX, __ssp_bos); return __ssp_real_wctomb(__buf, __wc); } _END_STD_C #endif /* __SSP_FORTIFY_LEVEL > 0 */ #endif /* _SSP_STDLIB_H_ */ picolibc-1.8.11/libc/include/ssp/string.h000066400000000000000000000133271513574234600202260ustar00rootroot00000000000000/* $NetBSD: string.h,v 1.13 2014/11/29 13:23:48 pooka Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SSP_STRING_H_ #define _SSP_STRING_H_ #include #include _BEGIN_STD_C void *__memcpy_chk(void *, const void *, size_t, size_t); void *__memmove_chk(void *, const void *, size_t, size_t); void *__mempcpy_chk(void *, const void *, size_t, size_t); void *__memset_chk(void *, int, size_t, size_t); char *__stpcpy_chk(char *, const char *, size_t); char *__strcat_chk(char *, const char *, size_t); char *__strcpy_chk(char *, const char *, size_t); char *__strncat_chk(char *, const char *, size_t, size_t); char *__strncpy_chk(char *, const char *, size_t, size_t); _END_STD_C #if __SSP_FORTIFY_LEVEL > 0 #define __ssp_bos_check3(fun, dst, src, len) \ (__ssp_bos_known(dst) ? __builtin___##fun##_chk(dst, src, len, __ssp_bos0(dst)) \ : __##fun##_ichk(dst, src, len)) #define __ssp_bos_check2(fun, dst, src) \ (__ssp_bos_known(dst) ? __builtin___##fun##_chk(dst, src, __ssp_bos0(dst)) \ : __##fun##_ichk(dst, src)) #define __ssp_bos_icheck3_restrict(fun, type1, type2) \ __declare_extern_inline(type1) __##fun##_ichk(type1 __restrict, type2 __restrict, size_t); \ __declare_extern_inline(type1) __##fun##_ichk(type1 __restrict dst, type2 __restrict src, \ size_t len) \ { \ return __builtin___##fun##_chk(dst, src, len, __ssp_bos0(dst)); \ } #define __ssp_bos_icheck3(fun, type1, type2) \ __declare_extern_inline(type1) __##fun##_ichk(type1, type2, size_t); \ __declare_extern_inline(type1) __##fun##_ichk(type1 dst, type2 src, size_t len) \ { \ return __builtin___##fun##_chk(dst, src, len, __ssp_bos0(dst)); \ } #define __ssp_bos_icheck2_restrict(fun, type1, type2) \ __declare_extern_inline(type1) __##fun##_ichk(type1, type2); \ __declare_extern_inline(type1) __##fun##_ichk(type1 __restrict dst, type2 __restrict src) \ { \ return __builtin___##fun##_chk(dst, src, __ssp_bos0(dst)); \ } _BEGIN_STD_C __ssp_bos_icheck3_restrict(memcpy, void *, const void *) __ssp_bos_icheck3(memmove, void *, const void *) __ssp_bos_icheck3_restrict(mempcpy, void *, const void *) __ssp_bos_icheck3(memset, void *, int) __ssp_bos_icheck2_restrict(stpcpy, char *, const char *) #if __GNUC_PREREQ__(4, 8) || defined(__clang__) __ssp_bos_icheck3_restrict(stpncpy, char *, const char *) #endif __ssp_bos_icheck2_restrict(strcpy, char *, const char *) __ssp_bos_icheck2_restrict(strcat, char *, const char *) __ssp_bos_icheck3_restrict(strncpy, char *, const char *) __ssp_bos_icheck3_restrict(strncat, char *, const char *) _END_STD_C #define memcpy(dst, src, len) __ssp_bos_check3(memcpy, dst, src, len) #define memmove(dst, src, len) __ssp_bos_check3(memmove, dst, src, len) #if __GNU_VISIBLE #define mempcpy(dst, src, len) __ssp_bos_check3(mempcpy, dst, src, len) #endif #define memset(dst, val, len) __ssp_bos_check3(memset, dst, val, len) #if __POSIX_VISIBLE >= 200809 #define stpcpy(dst, src) __ssp_bos_check2(stpcpy, dst, src) #if __GNUC_PREREQ__(4, 8) || defined(__clang__) #define stpncpy(dst, src, len) __ssp_bos_check3(stpncpy, dst, src, len) #endif #endif #define strcpy(dst, src) __ssp_bos_check2(strcpy, dst, src) #define strcat(dst, src) __ssp_bos_check2(strcat, dst, src) #define strncpy(dst, src, len) __ssp_bos_check3(strncpy, dst, src, len) #define strncat(dst, src, len) __ssp_bos_check3(strncat, dst, src, len) #endif /* __SSP_FORTIFY_LEVEL > 0 */ #endif /* _SSP_STRING_H_ */ picolibc-1.8.11/libc/include/ssp/strings.h000066400000000000000000000044441513574234600204110ustar00rootroot00000000000000/* $NetBSD: strings.h,v 1.3 2008/04/28 20:22:54 martin Exp $ */ /*- * Copyright (c) 2007 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SSP_STRINGS_H_ #define _SSP_STRINGS_H_ #include #if __SSP_FORTIFY_LEVEL > 0 #if __BSD_VISIBLE || __POSIX_VISIBLE <= 200112 #define bcopy(src, dst, len) \ (__ssp_bos_known(dst) ? __builtin___memmove_chk(dst, src, len, __ssp_bos0(dst)) \ : __memmove_ichk(dst, src, len)) #define bzero(dst, len) \ (__ssp_bos_known(dst) ? __builtin___memset_chk(dst, 0, len, __ssp_bos0(dst)) \ : __memset_ichk(dst, 0, len)) #endif #if __BSD_VISIBLE __ssp_redirect0(void, explicit_bzero, (void *__buf, size_t __len), (__buf, __len)); #endif #endif /* __SSP_FORTIFY_LEVEL > 0 */ #endif /* _SSP_STRINGS_H_ */ picolibc-1.8.11/libc/include/ssp/unistd.h000066400000000000000000000066471513574234600202350ustar00rootroot00000000000000/* $NetBSD: unistd.h,v 1.7 2015/06/25 18:41:03 joerg Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SSP_UNISTD_H_ #define _SSP_UNISTD_H_ #include #if __SSP_FORTIFY_LEVEL > 0 _BEGIN_STD_C #if __POSIX_VISIBLE >= 199209 __ssp_redirect(size_t, confstr, (int __name, char *__buf, size_t __len), (__name, __buf, __len)); #endif __ssp_redirect_raw(char *, getcwd, (char *__buf, size_t __len), (__buf, __len), __buf != 0, __ssp_bos); #if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 500) __ssp_redirect(int, getdomainname, (char *__buf, size_t __len), (__buf, __len)); #endif __ssp_decl(int, getgroups, (int __n, gid_t __buf[])) { __ssp_check(__buf, __n * sizeof(gid_t), __ssp_bos); return __ssp_real_getgroups(__n, __buf); } #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500 #if !(defined(_WINSOCK_H) || defined(_WINSOCKAPI_) || defined(__USE_W32_SOCKETS)) __ssp_redirect(int, gethostname, (char *__buf, size_t __len), (__buf, __len)); #endif #endif __ssp_redirect(int, getlogin_r, (char *__buf, size_t __len), (__buf, __len)); #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 500 __ssp_redirect0(ssize_t, pread, (int __fd, void *__buf, size_t __len, off_t __off), (__fd, __buf, __len, __off)); #endif __ssp_redirect0(ssize_t, read, (int __fd, void *__buf, size_t __len), (__fd, __buf, __len)); #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 4 __ssp_redirect(ssize_t, readlink, (const char * __restrict __path, char * __restrict __buf, size_t __len), (__path, __buf, __len)); #endif #if __ATFILE_VISIBLE __ssp_redirect(ssize_t, readlinkat, (int __dirfd1, const char *__restrict __path, char *__restrict __buf, size_t __len), (__dirfd1, __path, __buf, __len)); #endif __ssp_redirect(int, ttyname_r, (int __fd, char *__buf, size_t __len), (__fd, __buf, __len)); _END_STD_C #endif /* __SSP_FORTIFY_LEVEL > 0 */ #endif /* _SSP_UNISTD_H_ */ picolibc-1.8.11/libc/include/ssp/wchar.h000066400000000000000000000101461513574234600200200ustar00rootroot00000000000000/* Copyright (c) 2017 Yaakov Selkowitz */ #ifndef _SSP_WCHAR_H_ #define _SSP_WCHAR_H_ #include #include #if __SSP_FORTIFY_LEVEL > 0 /* wide character variant, __wlen is number of wchar_t */ #define __ssp_redirect_wc(rtype, fun, args, call, cond, bos) \ __ssp_decl(rtype, fun, args) \ { \ if (cond) \ __ssp_check(__buf, __wlen * sizeof(wchar_t), bos); \ return __ssp_real_(fun) call; \ } #define __ssp_bos_wicheck3(fun) \ __ssp_redirect_wc(wchar_t *, fun, (wchar_t * __buf, const wchar_t *__src, size_t __wlen), \ (__buf, __src, __wlen), 1, __ssp_bos0) #define __ssp_bos_wicheck3_restrict(fun) \ __ssp_redirect_wc( \ wchar_t *, fun, \ (wchar_t * __restrict __buf, const wchar_t * __restrict __src, size_t __wlen), \ (__buf, __src, __wlen), 1, __ssp_bos0) #define __ssp_bos_wicheck2_restrict(fun) \ __ssp_decl(wchar_t *, fun, (wchar_t * __restrict __buf, const wchar_t * __restrict __src)) \ { \ __ssp_check(__buf, (wcslen(__src) + 1) * sizeof(wchar_t), __ssp_bos0); \ return __ssp_real_(fun)(__buf, __src); \ } _BEGIN_STD_C #if __POSIX_VISIBLE >= 200809 __ssp_bos_wicheck2_restrict(wcpcpy) __ssp_bos_wicheck3_restrict(wcpncpy) #endif __ssp_bos_wicheck2_restrict(wcscpy) __ssp_bos_wicheck2_restrict(wcscat) __ssp_bos_wicheck3_restrict(wcsncpy) __ssp_bos_wicheck3_restrict(wcsncat) __ssp_bos_wicheck3_restrict(wmemcpy) __ssp_bos_wicheck3(wmemmove) #if __GNU_VISIBLE __ssp_bos_wicheck3_restrict(wmempcpy) #endif __ssp_redirect_wc(wchar_t *, wmemset, (wchar_t * __buf, wchar_t __src, size_t __wlen), (__buf, __src, __wlen), 1, __ssp_bos0) #ifndef __MB_LEN_MAX #ifdef __MB_CAPABLE #define __MB_LEN_MAX 8 #else #define __MB_LEN_MAX 1 #endif #endif __ssp_decl(size_t, wcrtomb, (char *__buf, wchar_t __src, mbstate_t *__ps)) { if (__buf != NULL && __src != L'\0') __ssp_check(__buf, __MB_LEN_MAX, __ssp_bos); return __ssp_real_wcrtomb(__buf, __src, __ps); } __ssp_redirect_wc(size_t, mbsrtowcs, (wchar_t * __buf, const char **__src, size_t __wlen, mbstate_t *__ps), (__buf, __src, __wlen, __ps), __buf != NULL, __ssp_bos) __ssp_redirect_raw(size_t, wcsrtombs, (char *__buf, const wchar_t **__src, size_t __len, mbstate_t *__ps), (__buf, __src, __len, __ps), __buf != NULL, __ssp_bos) #if __POSIX_VISIBLE >= 200809 __ssp_redirect_wc(size_t, mbsnrtowcs, (wchar_t * __buf, const char **__src, size_t __nms, size_t __wlen, mbstate_t *__ps), (__buf, __src, __nms, __wlen, __ps), __buf != NULL, __ssp_bos) __ssp_redirect_raw(size_t, wcsnrtombs, (char *__buf, const wchar_t **__src, size_t __nwc, size_t __len, mbstate_t *__ps), (__buf, __src, __nwc, __len, __ps), __buf != NULL, __ssp_bos) #endif __ssp_decl(wchar_t *, fgetws, (wchar_t * __restrict __buf, int __wlen, __FILE * __restrict __fp)) { if (__wlen > 0) __ssp_check(__buf, (size_t)__wlen * sizeof(wchar_t), __ssp_bos); return __ssp_real_fgetws(__buf, __wlen, __fp); } #if __GNU_VISIBLE __ssp_decl(wchar_t *, fgetws_unlocked, (wchar_t * __buf, int __wlen, __FILE *__fp)) { if (__wlen > 0) __ssp_check(__buf, (size_t)__wlen * sizeof(wchar_t), __ssp_bos); return __ssp_real_fgetws_unlocked(__buf, __wlen, __fp); } #endif /* __GNU_VISIBLE */ _END_STD_C #endif /* __SSP_FORTIFY_LEVEL > 0 */ #endif /* _SSP_WCHAR_H_ */ picolibc-1.8.11/libc/include/stdint.h000066400000000000000000000446141513574234600174230ustar00rootroot00000000000000/* * Copyright (c) 2004, 2005 by * Ralf Corsepius, Ulm/Germany. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #ifndef _STDINT_H #define _STDINT_H #include #include #include #include _BEGIN_STD_C #if __ISO_C_VISIBLE >= 2023 #define __STDC_VERSION_STDINT_H__ 0x202311L #endif #ifdef ___int_least8_t_defined typedef __int_least8_t int_least8_t; typedef __uint_least8_t uint_least8_t; #define __int_least8_t_defined 1 #endif #ifdef ___int_least16_t_defined typedef __int_least16_t int_least16_t; typedef __uint_least16_t uint_least16_t; #define __int_least16_t_defined 1 #endif #ifdef ___int_least32_t_defined typedef __int_least32_t int_least32_t; typedef __uint_least32_t uint_least32_t; #define __int_least32_t_defined 1 #endif #ifdef ___int_least64_t_defined typedef __int_least64_t int_least64_t; typedef __uint_least64_t uint_least64_t; #define __int_least64_t_defined 1 #endif /* * Fastest minimum-width integer types * * Assume int to be the fastest type for all types with a width * less than __INT_MAX__ rsp. INT_MAX */ #ifdef __INT_FAST8_TYPE__ typedef __INT_FAST8_TYPE__ int_fast8_t; typedef __UINT_FAST8_TYPE__ uint_fast8_t; #define __int_fast8_t_defined 1 #elif __STDINT_EXP(INT_MAX) >= 0x7f typedef signed int int_fast8_t; typedef unsigned int uint_fast8_t; #define __int_fast8_t_defined 1 #endif #ifdef __INT_FAST16_TYPE__ typedef __INT_FAST16_TYPE__ int_fast16_t; typedef __UINT_FAST16_TYPE__ uint_fast16_t; #define __int_fast16_t_defined 1 #elif __STDINT_EXP(INT_MAX) >= 0x7fff typedef signed int int_fast16_t; typedef unsigned int uint_fast16_t; #define __int_fast16_t_defined 1 #endif #ifdef __INT_FAST32_TYPE__ typedef __INT_FAST32_TYPE__ int_fast32_t; typedef __UINT_FAST32_TYPE__ uint_fast32_t; #define __int_fast32_t_defined 1 #elif __STDINT_EXP(INT_MAX) >= 0x7fffffff typedef signed int int_fast32_t; typedef unsigned int uint_fast32_t; #define __int_fast32_t_defined 1 #endif #ifdef __INT_FAST64_TYPE__ typedef __INT_FAST64_TYPE__ int_fast64_t; typedef __UINT_FAST64_TYPE__ uint_fast64_t; #define __int_fast64_t_defined 1 #elif __STDINT_EXP(INT_MAX) > 0x7fffffff typedef signed int int_fast64_t; typedef unsigned int uint_fast64_t; #define __int_fast64_t_defined 1 #endif /* * Fall back to [u]int_least_t for [u]int_fast_t types * not having been defined, yet. * Leave undefined, if [u]int_least_t should not be available. */ #if !__int_fast8_t_defined #if __int_least8_t_defined typedef int_least8_t int_fast8_t; typedef uint_least8_t uint_fast8_t; #define __int_fast8_t_defined 1 #endif #endif #if !__int_fast16_t_defined #if __int_least16_t_defined typedef int_least16_t int_fast16_t; typedef uint_least16_t uint_fast16_t; #define __int_fast16_t_defined 1 #endif #endif #if !__int_fast32_t_defined #if __int_least32_t_defined typedef int_least32_t int_fast32_t; typedef uint_least32_t uint_fast32_t; #define __int_fast32_t_defined 1 #endif #endif #if !__int_fast64_t_defined #if __int_least64_t_defined typedef int_least64_t int_fast64_t; typedef uint_least64_t uint_fast64_t; #define __int_fast64_t_defined 1 #endif #endif #ifdef __INTPTR_TYPE__ #define INTPTR_MIN (-__INTPTR_MAX__ - 1) #define INTPTR_MAX (__INTPTR_MAX__) #define UINTPTR_MAX (__UINTPTR_MAX__) #elif defined(__PTRDIFF_TYPE__) #define INTPTR_MAX PTRDIFF_MAX #define INTPTR_MIN PTRDIFF_MIN #ifdef __UINTPTR_MAX__ #define UINTPTR_MAX (__UINTPTR_MAX__) #else #define UINTPTR_MAX (2UL * PTRDIFF_MAX + 1) #endif #else /* * Fallback to hardcoded values, * should be valid on cpu's with 32bit int/32bit void* */ #define INTPTR_MAX (__STDINT_EXP(LONG_MAX)) #define INTPTR_MIN (-__STDINT_EXP(LONG_MAX) - 1) #define UINTPTR_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1) #endif /* Limits of Specified-Width Integer Types */ #ifdef __INT8_MAX__ #define INT8_MIN (-__INT8_MAX__ - 1) #define INT8_MAX (__INT8_MAX__) #define UINT8_MAX (__UINT8_MAX__) #elif defined(__int8_t_defined) #define INT8_MIN (-128) #define INT8_MAX (127) #define UINT8_MAX (255) #endif #ifdef __INT_LEAST8_MAX__ #define INT_LEAST8_MIN (-__INT_LEAST8_MAX__ - 1) #define INT_LEAST8_MAX (__INT_LEAST8_MAX__) #define UINT_LEAST8_MAX (__UINT_LEAST8_MAX__) #elif defined(__int_least8_t_defined) #define INT_LEAST8_MIN (-128) #define INT_LEAST8_MAX (127) #define UINT_LEAST8_MAX (255) #else #error required type int_least8_t missing #endif #ifdef __INT16_MAX__ #define INT16_MIN (-__INT16_MAX__ - 1) #define INT16_MAX (__INT16_MAX__) #define UINT16_MAX (__UINT16_MAX__) #elif defined(__int16_t_defined) #define INT16_MIN (-32768) #define INT16_MAX (32767) #define UINT16_MAX (65535) #endif #ifdef __INT_LEAST16_MAX__ #define INT_LEAST16_MIN (-__INT_LEAST16_MAX__ - 1) #define INT_LEAST16_MAX (__INT_LEAST16_MAX__) #define UINT_LEAST16_MAX (__UINT_LEAST16_MAX__) #elif defined(__int_least16_t_defined) #define INT_LEAST16_MIN (-32768) #define INT_LEAST16_MAX (32767) #define UINT_LEAST16_MAX (65535) #else #error required type int_least16_t missing #endif #ifdef __INT32_MAX__ #define INT32_MIN (-__INT32_MAX__ - 1) #define INT32_MAX (__INT32_MAX__) #define UINT32_MAX (__UINT32_MAX__) #elif defined(__int32_t_defined) #if defined(_INT32_EQ_LONG) #define INT32_MIN (-2147483647L - 1) #define INT32_MAX (2147483647L) #define UINT32_MAX (4294967295UL) #else #define INT32_MIN (-2147483647 - 1) #define INT32_MAX (2147483647) #define UINT32_MAX (4294967295U) #endif #endif #ifdef __INT_LEAST32_MAX__ #define INT_LEAST32_MIN (-__INT_LEAST32_MAX__ - 1) #define INT_LEAST32_MAX (__INT_LEAST32_MAX__) #define UINT_LEAST32_MAX (__UINT_LEAST32_MAX__) #elif defined(__int_least32_t_defined) #if defined(_INT32_EQ_LONG) #define INT_LEAST32_MIN (-2147483647L - 1) #define INT_LEAST32_MAX (2147483647L) #define UINT_LEAST32_MAX (4294967295UL) #else #define INT_LEAST32_MIN (-2147483647 - 1) #define INT_LEAST32_MAX (2147483647) #define UINT_LEAST32_MAX (4294967295U) #endif #else #error required type int_least32_t missing #endif #ifdef __INT64_MAX__ #define INT64_MIN (-__INT64_MAX__ - 1) #define INT64_MAX (__INT64_MAX__) #define UINT64_MAX (__UINT64_MAX__) #elif defined(__int64_t_defined) #if __have_long64 #define INT64_MIN (-9223372036854775807L - 1L) #define INT64_MAX (9223372036854775807L) #define UINT64_MAX (18446744073709551615U) #elif __have_longlong64 #define INT64_MIN (-9223372036854775807LL - 1LL) #define INT64_MAX (9223372036854775807LL) #define UINT64_MAX (18446744073709551615ULL) #endif #endif #ifdef __INT_LEAST64_MAX__ #define INT_LEAST64_MIN (-__INT_LEAST64_MAX__ - 1) #define INT_LEAST64_MAX (__INT_LEAST64_MAX__) #define UINT_LEAST64_MAX (__UINT_LEAST64_MAX__) #elif defined(__int_least64_t_defined) #if __have_long64 #define INT_LEAST64_MIN (-9223372036854775807L - 1L) #define INT_LEAST64_MAX (9223372036854775807L) #define UINT_LEAST64_MAX (18446744073709551615U) #elif __have_longlong64 #define INT_LEAST64_MIN (-9223372036854775807LL - 1LL) #define INT_LEAST64_MAX (9223372036854775807LL) #define UINT_LEAST64_MAX (18446744073709551615ULL) #endif #endif #ifdef __INT_FAST8_MAX__ #define INT_FAST8_MIN (-__INT_FAST8_MAX__ - 1) #define INT_FAST8_MAX (__INT_FAST8_MAX__) #define UINT_FAST8_MAX (__UINT_FAST8_MAX__) #elif defined(__int_fast8_t_defined) #if __STDINT_EXP(INT_MAX) >= 0x7f #define INT_FAST8_MIN (-__STDINT_EXP(INT_MAX) - 1) #define INT_FAST8_MAX (__STDINT_EXP(INT_MAX)) #define UINT_FAST8_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) #else #define INT_FAST8_MIN INT_LEAST8_MIN #define INT_FAST8_MAX INT_LEAST8_MAX #define UINT_FAST8_MAX UINT_LEAST8_MAX #endif #endif #ifdef __INT_FAST16_MAX__ #define INT_FAST16_MIN (-__INT_FAST16_MAX__ - 1) #define INT_FAST16_MAX (__INT_FAST16_MAX__) #define UINT_FAST16_MAX (__UINT_FAST16_MAX__) #elif defined(__int_fast16_t_defined) #if __STDINT_EXP(INT_MAX) >= 0x7fff #define INT_FAST16_MIN (-__STDINT_EXP(INT_MAX) - 1) #define INT_FAST16_MAX (__STDINT_EXP(INT_MAX)) #define UINT_FAST16_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) #else #define INT_FAST16_MIN INT_LEAST16_MIN #define INT_FAST16_MAX INT_LEAST16_MAX #define UINT_FAST16_MAX UINT_LEAST16_MAX #endif #endif #ifdef __INT_FAST32_MAX__ #define INT_FAST32_MIN (-__INT_FAST32_MAX__ - 1) #define INT_FAST32_MAX (__INT_FAST32_MAX__) #define UINT_FAST32_MAX (__UINT_FAST32_MAX__) #elif defined(__int_fast32_t_defined) #if __STDINT_EXP(INT_MAX) >= 0x7fffffff #define INT_FAST32_MIN (-__STDINT_EXP(INT_MAX) - 1) #define INT_FAST32_MAX (__STDINT_EXP(INT_MAX)) #define UINT_FAST32_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) #else #define INT_FAST32_MIN INT_LEAST32_MIN #define INT_FAST32_MAX INT_LEAST32_MAX #define UINT_FAST32_MAX UINT_LEAST32_MAX #endif #endif #ifdef __INT_FAST64_MAX__ #define INT_FAST64_MIN (-__INT_FAST64_MAX__ - 1) #define INT_FAST64_MAX (__INT_FAST64_MAX__) #define UINT_FAST64_MAX (__UINT_FAST64_MAX__) #elif defined(__int_fast64_t_defined) #if __STDINT_EXP(INT_MAX) > 0x7fffffff #define INT_FAST64_MIN (-__STDINT_EXP(INT_MAX) - 1) #define INT_FAST64_MAX (__STDINT_EXP(INT_MAX)) #define UINT_FAST64_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) #else #define INT_FAST64_MIN INT_LEAST64_MIN #define INT_FAST64_MAX INT_LEAST64_MAX #define UINT_FAST64_MAX UINT_LEAST64_MAX #endif #endif #ifdef __INTMAX_MAX__ #define INTMAX_MAX (__INTMAX_MAX__) #define INTMAX_MIN (-INTMAX_MAX - 1) #elif defined(__INTMAX_TYPE__) /* All relevant GCC versions prefer long to long long for intmax_t. */ #define INTMAX_MAX INT64_MAX #define INTMAX_MIN INT64_MIN #endif #ifdef __UINTMAX_MAX__ #define UINTMAX_MAX (__UINTMAX_MAX__) #elif defined(__UINTMAX_TYPE__) /* All relevant GCC versions prefer long to long long for intmax_t. */ #define UINTMAX_MAX UINT64_MAX #endif /* This must match size_t in stddef.h, currently long unsigned int */ #ifdef __SIZE_MAX__ #define SIZE_MAX (__SIZE_MAX__) #else #define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1) #endif /* This must match sig_atomic_t in (currently int) */ #define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1) #define SIG_ATOMIC_MAX (__STDINT_EXP(INT_MAX)) /* This must match ptrdiff_t in (currently long int) */ #ifdef __PTRDIFF_MAX__ #define PTRDIFF_MAX (__PTRDIFF_MAX__) #else #define PTRDIFF_MAX (__STDINT_EXP(LONG_MAX)) #endif #define PTRDIFF_MIN (-PTRDIFF_MAX - 1) /* This must match definition in */ #ifndef WCHAR_MIN #ifdef __WCHAR_MIN__ #define WCHAR_MIN (__WCHAR_MIN__) #elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0) #define WCHAR_MIN (0 + L'\0') #else #define WCHAR_MIN (-0x7fffffff - 1 + L'\0') #endif #endif /* This must match definition in */ #ifndef WCHAR_MAX #ifdef __WCHAR_MAX__ #define WCHAR_MAX (__WCHAR_MAX__) #elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0) #define WCHAR_MAX (0xffffffffu + L'\0') #else #define WCHAR_MAX (0x7fffffff + L'\0') #endif #endif /* wint_t is unsigned int on almost all GCC targets. */ #ifdef __WINT_MAX__ #define WINT_MAX (__WINT_MAX__) #else #define WINT_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) #endif #ifdef __WINT_MIN__ #define WINT_MIN (__WINT_MIN__) #else #define WINT_MIN (0U) #endif /** Macros for minimum-width integer constant expressions */ #ifdef __INT8_C #define INT8_C(x) __INT8_C(x) #define UINT8_C(x) __UINT8_C(x) #else #define INT8_C(x) x #if __STDINT_EXP(INT_MAX) > 0x7f #define UINT8_C(x) x #else #define UINT8_C(x) x##U #endif #endif #ifdef __INT16_C #define INT16_C(x) __INT16_C(x) #define UINT16_C(x) __UINT16_C(x) #else #define INT16_C(x) x #if __STDINT_EXP(INT_MAX) > 0x7fff #define UINT16_C(x) x #else #define UINT16_C(x) x##U #endif #endif #ifdef __INT32_C #define INT32_C(x) __INT32_C(x) #define UINT32_C(x) __UINT32_C(x) #else #if defined(_INT32_EQ_LONG) #define INT32_C(x) x##L #define UINT32_C(x) x##UL #else #define INT32_C(x) x #define UINT32_C(x) x##U #endif #endif #ifdef __INT64_C #define INT64_C(x) __INT64_C(x) #define UINT64_C(x) __UINT64_C(x) #else #if __int64_t_defined #if __have_long64 #define INT64_C(x) x##L #define UINT64_C(x) x##UL #else #define INT64_C(x) x##LL #define UINT64_C(x) x##ULL #endif #endif #endif /** Macros for greatest-width integer constant expression */ #ifdef __INTMAX_C #define INTMAX_C(x) __INTMAX_C(x) #define UINTMAX_C(x) __UINTMAX_C(x) #else #if __have_long64 #define INTMAX_C(x) x##L #define UINTMAX_C(x) x##UL #else #define INTMAX_C(x) x##LL #define UINTMAX_C(x) x##ULL #endif #endif #if __STDC_WANT_LIB_EXT1__ == 1 #ifndef __STDC_LIB_EXT1__ #define __STDC_LIB_EXT1__ 1 #endif // could be defined by the user #ifndef RSIZE_MAX #define RSIZE_MAX SIZE_MAX #endif #endif #if __ISO_C_VISIBLE >= 2023 /* define INT8_WIDTH and UINT8_WIDTH if possible */ #ifdef __int8_t_defined #ifdef __INT8_WIDTH__ #define INT8_WIDTH __INT8_WIDTH__ #elif defined __UINT8_WIDTH__ #define INT8_WIDTH __UINT8_WIDTH__ #else #define INT8_WIDTH 8 #endif #ifdef __UINT8_WIDTH__ #define UINT8_WIDTH __UINT8_WIDTH__ #elif defined __INT8_WIDTH__ #define UINT8_WIDTH __INT8_WIDTH__ #else #define UINT8_WIDTH 8 #endif #endif /* define INT16_WIDTH and UINT16_WIDTH if possible */ #ifdef _int16_t_defined #ifdef __INT16_WIDTH__ #define INT16_WIDTH __INT16_WIDTH__ #elif defined __UINT16_WIDTH__ #define INT16_WIDTH __UINT16_WIDTH__ #else #define INT16_WIDTH 16 #endif #ifdef __UINT16_WIDTH__ #define UINT16_WIDTH __UINT16_WIDTH__ #elif defined __INT16_WIDTH__ #define UINT16_WIDTH __INT16_WIDTH__ #else #define UINT16_WIDTH 16 #endif #endif /* define INT32_WIDTH and UINT32_WIDTH if possible */ #ifdef __int32_t_defined #ifdef __INT32_WIDTH__ #define INT32_WIDTH __INT32_WIDTH__ #elif defined __UINT32_WIDTH__ #define INT32_WIDTH __UINT32_WIDTH__ #else #define INT32_WIDTH 32 #endif #ifdef __UINT32_WIDTH__ #define UINT32_WIDTH __UINT32_WIDTH__ #elif defined __INT32_WIDTH__ #define UINT32_WIDTH __INT32_WIDTH__ #else #define UINT32_WIDTH 32 #endif #endif /* define INT64_WIDTH and UINT64_WIDTH if possible */ #ifdef __int64_t_defined #ifdef __INT64_WIDTH__ #define INT64_WIDTH __INT64_WIDTH__ #elif defined __UINT64_WIDTH__ #define INT64_WIDTH __UINT64_WIDTH__ #else #define INT64_WIDTH 64 #endif #ifdef __UINT64_WIDTH__ #define UINT64_WIDTH __UINT64_WIDTH__ #elif defined __INT64_WIDTH__ #define UINT64_WIDTH __INT64_WIDTH__ #else #define UINT64_WIDTH 64 #endif #endif /* define INT_LEAST8_WIDTH and UINT_LEAST8_WIDTH if possible */ #ifdef __INT_LEAST8_WIDTH__ #define INT_LEAST8_WIDTH __INT_LEAST8_WIDTH__ #elif defined __UINT_LEAST8_WIDTH__ #define INT_LEAST8_WIDTH __UINT_LEAST8_WIDTH__ #endif #ifdef __UINT_LEAST8_WIDTH__ #define UINT_LEAST8_WIDTH __UINT_LEAST8_WIDTH__ #elif defined __INT_LEAST8_WIDTH__ #define UINT_LEAST8_WIDTH __INT_LEAST8_WIDTH__ #endif /* define INT_LEAST16_WIDTH and UINT_LEAST16_WIDTH if possible */ #ifdef __INT_LEAST16_WIDTH__ #define INT_LEAST16_WIDTH __INT_LEAST16_WIDTH__ #elif defined __UINT_LEAST16_WIDTH__ #define INT_LEAST16_WIDTH __UINT_LEAST16_WIDTH__ #endif #ifdef __UINT_LEAST16_WIDTH__ #define UINT_LEAST16_WIDTH __UINT_LEAST16_WIDTH__ #elif defined __INT_LEAST16_WIDTH__ #define UINT_LEAST16_WIDTH __INT_LEAST16_WIDTH__ #endif /* define INT_LEAST32_WIDTH and UINT_LEAST32_WIDTH if possible */ #ifdef __INT_LEAST32_WIDTH__ #define INT_LEAST32_WIDTH __INT_LEAST32_WIDTH__ #elif defined __UINT_LEAST32_WIDTH__ #define INT_LEAST32_WIDTH __UINT_LEAST32_WIDTH__ #endif #ifdef __UINT_LEAST32_WIDTH__ #define UINT_LEAST32_WIDTH __UINT_LEAST32_WIDTH__ #elif defined __INT_LEAST32_WIDTH__ #define UINT_LEAST32_WIDTH __INT_LEAST32_WIDTH__ #endif /* define INT_LEAST64_WIDTH and UINT_LEAST64_WIDTH if possible */ #ifdef __INT_LEAST64_WIDTH__ #define INT_LEAST64_WIDTH __INT_LEAST64_WIDTH__ #elif defined __UINT_LEAST64_WIDTH__ #define INT_LEAST64_WIDTH __UINT_LEAST64_WIDTH__ #endif #ifdef __UINT_LEAST64_WIDTH__ #define UINT_LEAST64_WIDTH __UINT_LEAST64_WIDTH__ #elif defined __INT_LEAST64_WIDTH__ #define UINT_LEAST64_WIDTH __INT_LEAST64_WIDTH__ #endif /* define INT_FAST8_WIDTH and UINT_FAST8_WIDTH if possible */ #ifdef __INT_FAST8_WIDTH__ #define INT_FAST8_WIDTH __INT_FAST8_WIDTH__ #elif defined __UINT_FAST8_WIDTH__ #define INT_FAST8_WIDTH __UINT_FAST8_WIDTH__ #endif #ifdef __UINT_FAST8_WIDTH__ #define UINT_FAST8_WIDTH __UINT_FAST8_WIDTH__ #elif defined __INT_FAST8_WIDTH__ #define UINT_FAST8_WIDTH __INT_FAST8_WIDTH__ #endif /* define INT_FAST16_WIDTH and UINT_FAST16_WIDTH if possible */ #ifdef __INT_FAST16_WIDTH__ #define INT_FAST16_WIDTH __INT_FAST16_WIDTH__ #elif defined __UINT_FAST16_WIDTH__ #define INT_FAST16_WIDTH __UINT_FAST16_WIDTH__ #endif #ifdef __UINT_FAST16_WIDTH__ #define UINT_FAST16_WIDTH __UINT_FAST16_WIDTH__ #elif defined __INT_FAST16_WIDTH__ #define UINT_FAST16_WIDTH __INT_FAST16_WIDTH__ #endif /* define INT_FAST32_WIDTH and UINT_FAST32_WIDTH if possible */ #ifdef __INT_FAST32_WIDTH__ #define INT_FAST32_WIDTH __INT_FAST32_WIDTH__ #elif defined __UINT_FAST32_WIDTH__ #define INT_FAST32_WIDTH __UINT_FAST32_WIDTH__ #endif #ifdef __UINT_FAST32_WIDTH__ #define UINT_FAST32_WIDTH __UINT_FAST32_WIDTH__ #elif defined __INT_FAST32_WIDTH__ #define UINT_FAST32_WIDTH __INT_FAST32_WIDTH__ #endif /* define INT_FAST64_WIDTH and UINT_FAST64_WIDTH if possible */ #ifdef __INT_FAST64_WIDTH__ #define INT_FAST64_WIDTH __INT_FAST64_WIDTH__ #elif defined __UINT_FAST64_WIDTH__ #define INT_FAST64_WIDTH __UINT_FAST64_WIDTH__ #endif #ifdef __UINT_FAST64_WIDTH__ #define UINT_FAST64_WIDTH __UINT_FAST64_WIDTH__ #elif defined __INT_FAST64_WIDTH__ #define UINT_FAST64_WIDTH __INT_FAST64_WIDTH__ #endif /* define INTPTR_WIDTH and UINTPTR_WIDTH if possible */ #ifdef __INTPTR_WIDTH__ #define INTPTR_WIDTH __INTPTR_WIDTH__ #elif defined __UINTPTR_WIDTH__ #define INTPTR_WIDTH __UINTPTR_WIDTH__ #endif #ifdef __UINTPTR_WIDTH__ #define UINTPTR_WIDTH __UINTPTR_WIDTH__ #elif defined __INTPTR_WIDTH__ #define UINTPTR_WIDTH __INTPTR_WIDTH__ #endif /* define INTMAX_WIDTH and UINTMAX_WIDTH if possible */ #ifdef __INTMAX_WIDTH__ #define INTMAX_WIDTH __INTMAX_WIDTH__ #elif defined __UINTMAX_WIDTH__ #define INTMAX_WIDTH __UINTMAX_WIDTH__ #endif #ifdef __UINTMAX_WIDTH__ #define UINTMAX_WIDTH __UINTMAX_WIDTH__ #elif defined __INTMAX_WIDTH__ #define UINTMAX_WIDTH __INTMAX_WIDTH__ #endif /* define PTRDIFF_WIDTH if possible */ #ifdef __PTRDIFF_WIDTH__ #define PTRDIFF_WIDTH __PTRDIFF_WIDTH__ #endif /* define SIG_ATOMIC_WIDTH if possible */ #ifdef __SIG_ATOMIC_WIDTH__ #define SIG_ATOMIC_WIDTH __SIG_ATOMIC_WIDTH__ #endif /* define SIZE_WIDTH if possible */ #ifdef __SIZE_WIDTH__ #define SIZE_WIDTH __SIZE_WIDTH__ #endif /* define WCHAR_WIDTH if possible */ #ifdef __WCHAR_WIDTH__ #define WCHAR_WIDTH __WCHAR_WIDTH__ #endif /* define WINT_WIDTH if possible */ #ifdef __WINT_WIDTH__ #define WINT_WIDTH __WINT_WIDTH__ #endif #endif /* __ISO_C_VISBLE >= 2023 */ _END_STD_C #endif /* _STDINT_H */ picolibc-1.8.11/libc/include/stdio-bufio.h000066400000000000000000000145451513574234600203420ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _STDIO_BUFIO_H_ #define _STDIO_BUFIO_H_ #include #include #include #define __BALL 0x0001 /* bufio buf is allocated by stdio */ #define __BLBF 0x0002 /* bufio is line buffered */ #define __BFALL 0x0004 /* FILE is allocated by stdio */ #define __BFPTR 0x0008 /* funcs need pointers instead of ints */ union __file_bufio_cookie { int fd; void *ptr; }; #if !defined(__SINGLE_THREAD) && !defined(__STDIO_LOCKING) #define __STDIO_BUFIO_LOCKING #endif struct __file_bufio { struct __file_ext xfile; const void *ptr; uint8_t dir; uint8_t bflags; __off_t pos; /* FD position */ char *buf; int size; /* sizeof buf */ int len; /* valid data in buf */ int off; /* offset of data in buf */ union { ssize_t (*read_int)(int fd, void *buf, size_t count); ssize_t (*read_ptr)(void *ptr, void *buf, size_t count); }; union { ssize_t (*write_int)(int fd, const void *buf, size_t count); ssize_t (*write_ptr)(void *ptr, const void *buf, size_t count); }; union { __off_t (*lseek_int)(int fd, __off_t offset, int whence); __off_t (*lseek_ptr)(void *ptr, __off_t offset, int whence); }; union { int (*close_int)(int fd); int (*close_ptr)(void *ptr); }; #ifdef __STDIO_BUFIO_LOCKING _LOCK_T lock; #endif }; #define FDEV_SETUP_BUFIO(_fd, _buf, _size, _read, _write, _lseek, _close, _rwflag, _bflags) \ { \ .xfile = FDEV_SETUP_EXT(__bufio_put, __bufio_get, __bufio_flush, \ (_bflags) & (__BALL | __BFALL) ? __bufio_close : __bufio_close_nf, \ __bufio_seek, NULL, (_rwflag) | __SBUF), \ .ptr = (void *)(intptr_t)(_fd), .dir = 0, .bflags = (_bflags), .pos = 0, .buf = _buf, \ .size = _size, .len = 0, .off = 0, { .read_int = _read }, { .write_int = _write }, \ { .lseek_int = _lseek }, \ { \ .close_int = _close \ } \ } #define FDEV_SETUP_BUFIO_PTR(_ptr, _buf, _size, _read, _write, _lseek, _close, _rwflag, _bflags) \ { \ .xfile = FDEV_SETUP_EXT(__bufio_put, __bufio_get, __bufio_flush, \ (_bflags) & (__BALL | __BFALL) ? __bufio_close : __bufio_close_nf, \ __bufio_seek, NULL, (_rwflag) | __SBUF), \ .ptr = _ptr, .dir = 0, .bflags = (_bflags) | __BFPTR, .pos = 0, .buf = _buf, \ .size = _size, .len = 0, .off = 0, { .read_ptr = _read }, { .write_ptr = _write }, \ { .lseek_ptr = _lseek }, \ { \ .close_ptr = _close \ } \ } #ifdef __STDIO_BUFIO_LOCKING void __bufio_lock_init(FILE *f); #endif static inline void __bufio_lock_close(FILE *f) { #ifdef __STDIO_BUFIO_LOCKING struct __file_bufio *bf = (struct __file_bufio *)f; if (bf->lock) { __lock_release(bf->lock); __lock_close(bf->lock); } #endif (void)f; } static inline void __bufio_lock(FILE *f) { #ifdef __STDIO_BUFIO_LOCKING struct __file_bufio *bf = (struct __file_bufio *)f; if (!bf->lock) __lock_init(bf->lock); __lock_acquire(bf->lock); #endif (void)f; } static inline void __bufio_unlock(FILE *f) { (void)f; #ifdef __STDIO_BUFIO_LOCKING struct __file_bufio *bf = (struct __file_bufio *)f; __lock_release(bf->lock); #endif } int __bufio_flush_locked(FILE *f); int __bufio_fill_locked(FILE *f); int __bufio_setdir_locked(FILE *f, uint8_t dir); int __bufio_flush(FILE *f); int __bufio_put(char c, FILE *f); int __bufio_get(FILE *f); off_t __bufio_seek(FILE *f, off_t offset, int whence); int __bufio_setvbuf(FILE *f, char *buf, int mode, size_t size); int __bufio_close(FILE *f); int __bufio_close_nf(FILE *f); #endif /* _STDIO_BUFIO_H_ */ picolibc-1.8.11/libc/include/stdio.h000066400000000000000000000457711513574234600172450ustar00rootroot00000000000000/* Copyright (c) 2002, 2005, 2007 Joerg Wunsch All rights reserved. Portions of documentation Copyright (c) 1990, 1991, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. $Id: stdio.h 2527 2016-10-27 20:41:22Z joerg_wunsch $ */ #ifndef _STDIO_H_ #define _STDIO_H_ 1 #include #define __need_NULL #define __need_size_t #include #define __need___va_list #include #include #include _BEGIN_STD_C #if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \ || (defined(__cplusplus) && __cplusplus >= 201402L)) // Provide this function for applications which use an earlier C standard before C11 and C++14 #define _PICOLIBC_USE_DEPRECATED_GETS #endif /* * This is an internal structure of the library that is subject to be * changed without warnings at any time. Please do *never* reference * elements of it beyond by using the official interfaces provided. */ #ifdef __ATOMIC_UNGETC #if defined(__riscv) || defined(__MICROBLAZE__) || (__loongarch__) /* * Use 32-bit ungetc storage when doing atomic ungetc on RISC-V and * MicroBlaze, which have 4-byte swap intrinsics but not 2-byte swap * intrinsics. This increases the size of the __file struct by four * bytes. */ #define __PICOLIBC_UNGETC_SIZE 4 #endif #endif #ifndef __PICOLIBC_UNGETC_SIZE #define __PICOLIBC_UNGETC_SIZE 2 #endif #if __PICOLIBC_UNGETC_SIZE == 4 typedef __uint32_t __ungetc_t; #endif #if __PICOLIBC_UNGETC_SIZE == 2 typedef __uint16_t __ungetc_t; #endif struct __file { __ungetc_t unget; /* ungetc() buffer */ __uint8_t flags; /* flags, see below */ #define __SRD 0x0001 /* OK to read */ #define __SWR 0x0002 /* OK to write */ #define __SERR 0x0004 /* found error */ #define __SEOF 0x0008 /* found EOF */ #define __SCLOSE 0x0010 /* struct is __file_close */ #define __SEXT 0x0020 /* struct is __file_ext */ #define __SBUF 0x0040 /* struct is __file_bufio */ #define __SWIDE 0x0080 /* wchar output mode */ int (*put)(char, struct __file *); /* function to write one char to device */ int (*get)(struct __file *); /* function to read one char from device */ int (*flush)(struct __file *); /* function to flush output to device */ #ifdef __STDIO_LOCKING _LOCK_RECURSIVE_T lock; #endif }; #ifdef __STDIO_LOCKING #define __STDIO_UNLOCKED(_fn) _fn##_unlocked #else #define __STDIO_UNLOCKED(_fn) _fn #endif /* * This variant includes a 'close' function which is * invoked from fclose when the __SCLOSE bit is set */ struct __file_close { struct __file file; /* main file struct */ int (*close)(struct __file *); /* function to close file */ }; #define FDEV_SETUP_CLOSE(__put, __get, __flush, __close, __flags) \ { \ .file = FDEV_SETUP_STREAM(__put, __get, __flush, (__flags) | __SCLOSE), \ .close = (__close), \ } struct __file_ext { struct __file_close cfile; /* close file struct */ __off_t (*seek)(struct __file *, __off_t offset, int whence); int (*setvbuf)(struct __file *, char *buf, int mode, size_t size); }; #define FDEV_SETUP_EXT(__put, __get, __flush, __close, __seek, __setvbuf, __flags) \ { \ .cfile = FDEV_SETUP_CLOSE(__put, __get, __flush, __close, (__flags) | __SEXT), \ .seek = (__seek), \ .setvbuf = (__setvbuf), \ } /*@{*/ /** \c FILE is the opaque structure that is passed around between the various standard IO functions. */ #ifndef ___FILE_DECLARED typedef struct __file __FILE; #define ___FILE_DECLARED #endif #ifndef _FILE_DECLARED typedef __FILE FILE; #define _FILE_DECLARED #endif /** This symbol is defined when stdin/stdout/stderr are global variables. When undefined, the old __iob array is used which contains the pointers instead */ #define __PICOLIBC_STDIO_GLOBALS extern FILE * const stdin; extern FILE * const stdout; extern FILE * const stderr; /* The stdin, stdout, and stderr symbols are described as macros in the C * standard. */ #define stdin stdin #define stdout stdout #define stderr stderr #define EOF (-1) #define _IOFBF 0 /* setvbuf should set fully buffered */ #define _IOLBF 1 /* setvbuf should set line buffered */ #define _IONBF 2 /* setvbuf should set unbuffered */ #define _FDEV_SETUP_READ __SRD /**< fdev_setup_stream() with read intent */ #define _FDEV_SETUP_WRITE __SWR /**< fdev_setup_stream() with write intent */ #define _FDEV_SETUP_RW (__SRD | __SWR) /**< fdev_setup_stream() with read/write intent */ /** * Return code for an error condition during device read. * * To be used in the get function of fdevopen(). */ #define _FDEV_ERR (-1) /** * Return code for an end-of-file condition during device read. * * To be used in the get function of fdevopen(). */ #define _FDEV_EOF (-2) #define FDEV_SETUP_STREAM(__put, __get, __flush, __flags) \ { \ .flags = (__flags), \ .put = (__put), \ .get = (__get), \ .flush = (__flush), \ } FILE *fdevopen(int (*__put)(char, FILE *), int (*__get)(FILE *), int (*__flush)(FILE *)); int fclose(FILE *__stream) __nonnull((1)); int fflush(FILE *stream) __nonnull((1)); #define fdev_close(f) (fflush(f)) /* Check for old-style printf selection symbols */ #define __IO_VARIANT_DOUBLE 'd' #define __IO_VARIANT_FLOAT 'f' #define __IO_VARIANT_LLONG 'l' #define __IO_VARIANT_INTEGER 'i' #define __IO_VARIANT_MINIMAL 'm' #ifndef _PICOLIBC_PRINTF #if defined(PICOLIBC_DOUBLE_PRINTF_SCANF) #define _PICOLIBC_PRINTF __IO_VARIANT_DOUBLE #elif defined(PICOLIBC_FLOAT_PRINTF_SCANF) #define _PICOLIBC_PRINTF __IO_VARIANT_FLOAT #elif defined(PICOLIBC_LONG_LONG_PRINTF_SCANF) #define _PICOLIBC_PRINTF __IO_VARIANT_LLONG #elif defined(PICOLIBC_INTEGER_PRINTF_SCANF) #define _PICOLIBC_PRINTF __IO_VARIANT_INTEGER #elif defined(PICOLIBC_MINIMAL_PRINTF_SCANF) #define _PICOLIBC_PRINTF __IO_VARIANT_MINIMAL #else #define _PICOLIBC_PRINTF __IO_DEFAULT #endif #endif /* Check for old-style scanf selection symbols */ #ifndef _PICOLIBC_SCANF #if defined(PICOLIBC_DOUBLE_PRINTF_SCANF) #define _PICOLIBC_SCANF __IO_VARIANT_DOUBLE #elif defined(PICOLIBC_FLOAT_PRINTF_SCANF) #define _PICOLIBC_SCANF __IO_VARIANT_FLOAT #elif defined(PICOLIBC_LONG_LONG_PRINTF_SCANF) #define _PICOLIBC_SCANF __IO_VARIANT_LLONG #elif defined(PICOLIBC_INTEGER_PRINTF_SCANF) #define _PICOLIBC_SCANF __IO_VARIANT_INTEGER #elif defined(PICOLIBC_MINIMAL_PRINTF_SCANF) #define _PICOLIBC_SCANF __IO_VARIANT_MINIMAL #else #define _PICOLIBC_SCANF __IO_DEFAULT #endif #endif #if _PICOLIBC_PRINTF == __IO_VARIANT_FLOAT #ifdef __GNUCLIKE_PRAGMA_DIAGNOSTIC #pragma GCC diagnostic ignored "-Wformat" #endif #define __FORMAT_ATTRIBUTE__(__a, __s, __f) __picolibc_format(__a, __s, 0) #else #define __FORMAT_ATTRIBUTE__(__a, __s, __f) __picolibc_format(__a, __s, __f) #endif #define __PRINTF_ATTRIBUTE__(__s, __f) __FORMAT_ATTRIBUTE__(printf, __s, __f) #define __SCANF_ATTRIBUTE__(__s, _f) __FORMAT_ATTRIBUTE__(scanf, __s, __f) int fputc(int __c, FILE *__stream) __nonnull((2)); int putc(int __c, FILE *__stream) __nonnull((2)); int putchar(int __c); #define putc(__c, __stream) fputc(__c, __stream) #define putchar(__c) fputc(__c, stdout) int printf(const char *__fmt, ...) __PRINTF_ATTRIBUTE__(1, 2); int fprintf(FILE *__stream, const char *__fmt, ...) __PRINTF_ATTRIBUTE__(2, 3) __nonnull((1)); int vprintf(const char *__fmt, __gnuc_va_list __ap) __PRINTF_ATTRIBUTE__(1, 0); int vfprintf(FILE *__stream, const char *__fmt, __gnuc_va_list __ap) __PRINTF_ATTRIBUTE__(2, 0) __nonnull((1)); int sprintf(char *__s, const char *__fmt, ...) __PRINTF_ATTRIBUTE__(2, 3); int snprintf(char *__s, size_t __n, const char *__fmt, ...) __PRINTF_ATTRIBUTE__(3, 4); int vsprintf(char *__s, const char *__fmt, __gnuc_va_list ap) __PRINTF_ATTRIBUTE__(2, 0); int vsnprintf(char *__s, size_t __n, const char *__fmt, __gnuc_va_list ap) __PRINTF_ATTRIBUTE__(3, 0); int asprintf(char **strp, const char *fmt, ...) __PRINTF_ATTRIBUTE__(2, 3); char *asnprintf(char *str, size_t *lenp, const char *fmt, ...) __PRINTF_ATTRIBUTE__(3, 4); int vasprintf(char **strp, const char *fmt, __gnuc_va_list ap) __PRINTF_ATTRIBUTE__(2, 0); char *vasnprintf(char *str, size_t *lenp, const char *fmt, __gnuc_va_list ap) __PRINTF_ATTRIBUTE__(3, 0); int fputs(const char *__str, FILE *__stream) __nonnull((2)); int puts(const char *__str); size_t fwrite(const void *__ptr, size_t __size, size_t __nmemb, FILE *__stream) __nonnull((4)); int fgetc(FILE *__stream) __nonnull((1)); int getc(FILE *__stream) __nonnull((1)); int getchar(void); #define getchar() getc(stdin) int ungetc(int __c, FILE *__stream) __nonnull((2)); int scanf(const char *__fmt, ...) __FORMAT_ATTRIBUTE__(scanf, 1, 2); int fscanf(FILE *__stream, const char *__fmt, ...) __FORMAT_ATTRIBUTE__(scanf, 2, 3) __nonnull((1)); int vscanf(const char *__fmt, __gnuc_va_list __ap) __FORMAT_ATTRIBUTE__(scanf, 1, 0); int vfscanf(FILE *__stream, const char *__fmt, __gnuc_va_list __ap) __FORMAT_ATTRIBUTE__(scanf, 2, 0) __nonnull((1)); int sscanf(const char *__buf, const char *__fmt, ...) __FORMAT_ATTRIBUTE__(scanf, 2, 3); int vsscanf(const char *__buf, const char *__fmt, __gnuc_va_list ap) __FORMAT_ATTRIBUTE__(scanf, 2, 0); char *fgets(char *__str, int __size, FILE *__stream) __nonnull((3)); #ifdef _PICOLIBC_USE_DEPRECATED_GETS char *gets(char *str); #endif size_t fread(void *__ptr, size_t __size, size_t __nmemb, FILE *__stream) __nonnull((4)); void clearerr(FILE *__stream) __nonnull((1)); int ferror(FILE *__stream) __nonnull((1)); int feof(FILE *__stream) __nonnull((1)); /* fast inlined versions */ #define __clearerr_unlocked(s) ((s)->flags &= ~(__SERR | __SEOF)) #define __ferror_unlocked(s) ((s)->flags & __SERR) #define __feof_unlocked(s) ((s)->flags & __SEOF) /* When locking is disabled, use the unlocked macros */ #ifndef __STDIO_LOCKING #define clearerr(s) __clearerr_unlocked(s) #define ferror(s) __ferror_unlocked(s) #define feof(s) __feof_unlocked(s) #endif /* Expose the unlocked symbols when requested */ #ifdef __MISC_VISIBLE void clearerr_unlocked(FILE *__stream) __nonnull((1)); int ferror_unlocked(FILE *__stream) __nonnull((1)); int feof_unlocked(FILE *__stream) __nonnull((1)); #define clearerr_unlocked(s) __clearerr_unlocked(s) #define ferror_unlocked(s) __ferror_unlocked(s) #define feof_unlocked(s) __feof_unlocked(s) #endif #ifndef SEEK_SET #define SEEK_SET 0 /* set file offset to offset */ #endif #ifndef SEEK_CUR #define SEEK_CUR 1 /* set file offset to current plus offset */ #endif #ifndef SEEK_END #define SEEK_END 2 /* set file offset to EOF plus offset */ #endif /* only mentioned for libstdc++ support, not implemented in library */ #ifndef BUFSIZ #define BUFSIZ 512 #endif /* * We don't have any way of knowing any underlying POSIX limits, * so just use a reasonably small values here */ #ifndef FOPEN_MAX #define FOPEN_MAX 32 #endif #ifndef FILENAME_MAX #define FILENAME_MAX 1024 #endif /* * Declare required C types * * size_t comes from stddef.h (included from cdefs.h) */ typedef _fpos_t fpos_t; #if __POSIX_VISIBLE /* * Declare required additional POSIX types. */ #ifndef _OFF_T_DECLARED typedef __off_t off_t; /* file offset */ #define _OFF_T_DECLARED #endif #ifndef _OFF64_T_DECLARED typedef __off64_t off64_t; /* 64-bit file offset */ #define _OFF64_T_DECLARED #endif #ifndef _SSIZE_T_DECLARED typedef _ssize_t ssize_t; #define _SSIZE_T_DECLARED #endif /* This needs to agree with */ #ifdef __GNUC__ #ifndef _VA_LIST_DEFINED typedef __gnuc_va_list va_list; #define _VA_LIST_DEFINED #endif #else #include #endif int dprintf(int fd, const char * __restrict fmt, ...); int vdprintf(int fd, const char * __restrict fmt, va_list ap); #endif int fgetpos(FILE *__restrict stream, fpos_t *__restrict pos) __nonnull((1)); FILE *fopen(const char *path, const char *mode) __malloc_like_with_free(fclose, 1); FILE *freopen(const char *path, const char *mode, FILE *stream) __nonnull((3)); FILE *fdopen(int, const char *) __malloc_like_with_free(fclose, 1); FILE *fmemopen(void *buf, size_t size, const char *mode) __malloc_like_with_free(fclose, 1); int fseek(FILE *stream, long offset, int whence) __nonnull((1)); int fseeko(FILE *stream, __off_t offset, int whence) __nonnull((1)); int fsetpos(FILE *stream, const fpos_t *pos) __nonnull((1)); long ftell(FILE *stream) __nonnull((1)); __off_t ftello(FILE *stream) __nonnull((1)); int fileno(FILE *stream) __nonnull((1)); void perror(const char *s); int remove(const char *pathname); int rename(const char *oldpath, const char *newpath); void rewind(FILE *stream) __nonnull((1)); void setbuf(FILE *stream, char *buf) __nonnull((1)); void setbuffer(FILE *stream, char *buf, size_t size) __nonnull((1)); void setlinebuf(FILE *stream) __nonnull((1)); int setvbuf(FILE *stream, char *buf, int mode, size_t size) __nonnull((1)); FILE *tmpfile(void); char *tmpnam(char *s); _ssize_t getline(char ** __restrict lineptr, size_t * __restrict n, FILE * __restrict stream) __nonnull((3)); _ssize_t getdelim(char ** __restrict lineptr, size_t * __restrict n, int delim, FILE * __restrict stream) __nonnull((4)); #if __BSD_VISIBLE FILE *funopen(const void *cookie, _ssize_t (*readfn)(void *cookie, void *buf, size_t n), _ssize_t (*writefn)(void *cookie, const void *buf, size_t n), __off_t (*seekfn)(void *cookie, __off_t off, int whence), int (*closefn)(void *cookie)); #define fropen(__cookie, __fn) funopen(__cookie, __fn, NULL, NULL, NULL) #define fwopen(__cookie, __fn) funopen(__cookie, NULL, __fn, NULL, NULL) #endif /*__BSD_VISIBLE */ #if __POSIX_VISIBLE >= 199309L int getc_unlocked(FILE *) __nonnull((1)); int getchar_unlocked(void); void flockfile(FILE *) __nonnull((1)); int ftrylockfile(FILE *) __nonnull((1)); void funlockfile(FILE *) __nonnull((1)); int putc_unlocked(int, FILE *) __nonnull((2)); int putchar_unlocked(int); #ifndef __STDIO_LOCKING #define getc_unlocked(f) getc(f) #define getchar_unlocked(f) getc(stdin) #define putc_unlocked(c, f) putc(c, f) #define putchar_unlocked(c, f) putc(c, stdout) #endif #endif #if __STDC_WANT_LIB_EXT1__ == 1 #ifndef __STDC_LIB_EXT1__ #define __STDC_LIB_EXT1__ 1 #endif #include #include #ifndef _ERRNO_T_DEFINED typedef __errno_t errno_t; #define _ERRNO_T_DEFINED #endif #ifndef _RSIZE_T_DEFINED typedef __rsize_t rsize_t; #define _RSIZE_T_DEFINED #endif int sprintf_s(char * __restrict __s, rsize_t __bufsize, const char * __restrict __format, ...); int vsnprintf_s(char * __restrict s, rsize_t n, const char * __restrict fmt, va_list arg); int vfprintf_s(FILE * __restrict stream, const char * __restrict fmt, va_list ap_orig); #endif /* * The format of tmpnam names is TXXXXXX, which works with mktemp */ #define L_tmpnam 8 /* * tmpnam files are created in the current directory */ #define P_tmpdir "" /* * We don't have any way of knowing any underlying POSIX limits, * so just use a reasonably small value here */ #ifndef TMP_MAX #define TMP_MAX 32 #endif /*@}*/ static __inline __uint32_t __printf_float(float f) { union { float f; __uint32_t u; } u = { .f = f }; return u.u; } /* Express printf capabilities to applications in the form of _HAS_IO values */ #if _PICOLIBC_PRINTF == __IO_VARIANT_MINIMAL #define printf_float(x) ((double)(x)) #if defined(__IO_MINIMAL_LONG_LONG) || __SIZEOF_LONG_LONG__ == __SIZEOF_LONG__ #define _HAS_IO_LONG_LONG #endif #ifdef __IO_C99_FORMATS #define _HAS_IO_C99_FORMATS #endif #elif _PICOLIBC_PRINTF == __IO_VARIANT_INTEGER #define printf_float(x) ((double)(x)) #if defined(__IO_LONG_LONG) || __SIZEOF_LONG_LONG__ == __SIZEOF_LONG__ #define _HAS_IO_LONG_LONG #endif #ifdef __IO_POS_ARGS #define _HAS_IO_POS_ARGS #endif #ifdef __IO_C99_FORMATS #define _HAS_IO_C99_FORMATS #endif #ifdef __IO_PERCENT_B #define _HAS_IO_PERCENT_B #endif #elif _PICOLIBC_PRINTF == __IO_VARIANT_LLONG #define printf_float(x) ((double)(x)) #define _HAS_IO_LONG_LONG #ifdef __IO_POS_ARGS #define _HAS_IO_POS_ARGS #endif #ifdef __IO_C99_FORMATS #define _HAS_IO_C99_FORMATS #endif #ifdef __IO_PERCENT_B #define _HAS_IO_PERCENT_B #endif #elif _PICOLIBC_PRINTF == __IO_VARIANT_FLOAT #define printf_float(x) __printf_float(x) #define _HAS_IO_LONG_LONG #define _HAS_IO_POS_ARGS #define _HAS_IO_C99_FORMATS #ifdef __IO_PERCENT_B #define _HAS_IO_PERCENT_B #endif #define _HAS_IO_FLOAT #else /* _PICOLIBC_PRINTF == __IO_VARIANT_DOUBLE */ #define printf_float(x) ((double)(x)) #define _HAS_IO_LONG_LONG #define _HAS_IO_POS_ARGS #define _HAS_IO_C99_FORMATS #define _HAS_IO_DOUBLE #if defined(__MB_CAPABLE) || defined(__IO_WCHAR) #define _HAS_IO_WCHAR #endif #ifdef __MB_CAPABLE #define _HAS_IO_MBCHAR #endif #ifdef __IO_PERCENT_B #define _HAS_IO_PERCENT_B #endif #ifdef __IO_LONG_DOUBLE #define _HAS_IO_LONG_DOUBLE #endif #endif _END_STD_C #if __SSP_FORTIFY_LEVEL > 0 #include #endif #endif /* _STDIO_H_ */ picolibc-1.8.11/libc/include/stdlib.h000066400000000000000000000322071513574234600173720ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * stdlib.h * * Definitions for common types, variables, and functions. */ #ifndef _STDLIB_H_ #define _STDLIB_H_ #include #include #define __need_size_t #define __need_wchar_t #define __need_NULL #include #include #ifndef __STRICT_ANSI__ #include #endif #if __GNU_VISIBLE #include #endif _BEGIN_STD_C #include typedef struct { int quot; /* quotient */ int rem; /* remainder */ } div_t; typedef struct { long quot; /* quotient */ long rem; /* remainder */ } ldiv_t; #if __ISO_C_VISIBLE >= 1999 typedef struct { long long int quot; /* quotient */ long long int rem; /* remainder */ } lldiv_t; #endif #ifndef __compar_fn_t_defined #define __compar_fn_t_defined typedef int (*__compar_fn_t)(const void *, const void *); #endif #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 #define RAND_MAX __RAND_MAX size_t __locale_mb_cur_max(void); #define MB_CUR_MAX __locale_mb_cur_max() /* Declare free up here so it can be used with __malloc_like */ void free(void *) __nothrow; #if __ISO_C_VISIBLE >= 1999 __noreturn void _Exit(int __status); #endif #if __SVID_VISIBLE || __XSI_VISIBLE >= 4 long a64l(const char *__input); #endif __noreturn void abort(void); int abs(int); #if __ISO_C_VISIBLE >= 2011 || __GNU_VISIBLE void * aligned_alloc(size_t, size_t) __malloc_like __alloc_align(1) __alloc_size(2) __warn_unused_result __nothrow; #endif #if __BSD_VISIBLE __uint32_t arc4random(void); __uint32_t arc4random_uniform(__uint32_t); void arc4random_buf(void *, size_t); #endif #if __ISO_C_VISIBLE >= 2011 int at_quick_exit(void (*)(void)); #endif int atexit(void (*__func)(void)); double atof(const char *__nptr); #if __MISC_VISIBLE float atoff(const char *__nptr); #endif int atoi(const char *__nptr); long atol(const char *__nptr); #if __ISO_C_VISIBLE >= 1999 long long atoll(const char *__nptr); #endif void *bsearch(const void *__key, const void *__base, size_t __nmemb, size_t __size, __compar_fn_t _compar); void * calloc(size_t, size_t) __malloc_like __warn_unused_result __alloc_size2(1, 2) __nothrow; div_t div(int __numer, int __denom); #if __SVID_VISIBLE || __XSI_VISIBLE struct _rand48; double drand48(void); double _drand48_r(struct _rand48 *); double erand48(unsigned short[3]); double _erand48_r(struct _rand48 *, unsigned short[3]); #endif __noreturn void exit(int __status); void free(void *) __nothrow; char *getenv(const char *__string); #if __GNU_VISIBLE char *secure_getenv(const char *__string); #endif #if __MISC_VISIBLE char *_findenv(const char *, int *); #endif #if __POSIX_VISIBLE >= 200809 extern char *suboptarg; /* getsubopt(3) external variable */ int getsubopt(char **, char *const *, char **); #endif #if __XSI_VISIBLE >= 500 int grantpt(int fd); #endif #if __SVID_VISIBLE || __XSI_VISIBLE >= 4 || __BSD_VISIBLE char *initstate(unsigned, char *, size_t); #endif #if __SVID_VISIBLE || __XSI_VISIBLE long jrand48(unsigned short[3]); long _jrand48_r(struct _rand48 *, unsigned short[3]); #endif long labs(long); #if __SVID_VISIBLE || __XSI_VISIBLE void lcong48(unsigned short[7]); void _lcong48_r(struct _rand48 *, unsigned short[7]); #endif ldiv_t ldiv(long __numer, long __denom); #if __ISO_C_VISIBLE >= 1999 long long llabs(long long); lldiv_t lldiv(long long __numer, long long __denom); #endif #if __SVID_VISIBLE || __XSI_VISIBLE long lrand48(void); long _lrand48_r(struct _rand48 *); #endif void * malloc(size_t) __malloc_like __warn_unused_result __alloc_size(1) __nothrow; int mblen(const char *, size_t); size_t mbstowcs(wchar_t * __restrict, const char * __restrict, size_t); int mbtowc(wchar_t *__restrict, const char *__restrict, size_t); #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 char *mkdtemp(char *); #endif #if __GNU_VISIBLE int mkostemp(char *, int); int mkostemps(char *, int, int); #endif #if __MISC_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 4 int mkstemp(char *); #endif #if __MISC_VISIBLE int mkstemps(char *, int); #endif #if __BSD_VISIBLE || (__XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112) char *mktemp(char *) __deprecated_m("the use of `mktemp' is dangerous; use `mkstemp' instead"); #endif #if __SVID_VISIBLE || __XSI_VISIBLE long mrand48(void); long _mrand48_r(struct _rand48 *); long nrand48(unsigned short[3]); long _nrand48_r(struct _rand48 *, unsigned short[3]); #endif #if __POSIX_VISIBLE >= 200112 int posix_memalign(void **, size_t, size_t) __nonnull((1)) __warn_unused_result; #endif #if __SVID_VISIBLE || __XSI_VISIBLE int putenv(char *__string); #endif #if __ISO_C_VISIBLE >= 2011 __noreturn void quick_exit(int); #endif /* __ISO_C_VISIBLE >= 2011 */ void qsort(void *__base, size_t __nmemb, size_t __size, __compar_fn_t _compar); /* There are two common qsort_r variants. If you request _BSD_SOURCE, you get the BSD version; otherwise you get the GNU version. We want that #undef qsort_r will still let you invoke the underlying function, but that requires gcc support. */ #if __GNU_VISIBLE void qsort_r(void *__base, size_t __nmemb, size_t __size, int (*_compar)(const void *, const void *, void *), void *__thunk); #elif __BSD_VISIBLE #ifdef __GNUC__ void qsort_r(void *__base, size_t __nmemb, size_t __size, void *__thunk, int (*_compar)(void *, const void *, const void *)) __asm__(__ASMNAME("__bsd_qsort_r")); #else void __bsd_qsort_r(void *__base, size_t __nmemb, size_t __size, void *__thunk, int (*_compar)(void *, const void *, const void *)); #define qsort_r __bsd_qsort_r #endif #endif int rand(void); #if __POSIX_VISIBLE int rand_r(unsigned *__seed); #endif #if __SVID_VISIBLE || __XSI_VISIBLE >= 4 || __BSD_VISIBLE long random(void); #endif void * realloc(void *, size_t) __warn_unused_result __alloc_size(2) __nothrow; #if __BSD_VISIBLE void * reallocarray(void *, size_t, size_t) __warn_unused_result __alloc_size2(2, 3); void * reallocf(void *, size_t) __warn_unused_result __alloc_size(2); #endif #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 char *realpath(const char * __restrict path, char * __restrict resolved_path); #endif #if __BSD_VISIBLE int rpmatch(const char *response); #endif #if __SVID_VISIBLE || __XSI_VISIBLE unsigned short *seed48(unsigned short[3]); unsigned short *_seed48_r(struct _rand48 *, unsigned short[3]); #endif /* __SVID_VISIBLE || __XSI_VISIBLE */ #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 int setenv(const char *__string, const char *__value, int __overwrite); #endif #if __XSI_VISIBLE void setkey(const char *__key); #endif #if __SVID_VISIBLE || __XSI_VISIBLE >= 4 || __BSD_VISIBLE char *setstate(char *); #endif void srand(unsigned __seed); #if __SVID_VISIBLE || __XSI_VISIBLE void srand48(long); void _srand48_r(struct _rand48 *, long); #endif /* __SVID_VISIBLE || __XSI_VISIBLE */ #if __SVID_VISIBLE || __XSI_VISIBLE >= 4 || __BSD_VISIBLE void srandom(unsigned); #endif double strtod(const char * __restrict __n, char ** __restrict __end_PTR); int strfromd(char *__restrict str, size_t n, const char *__restrict format, double fp); #if __ISO_C_VISIBLE >= 1999 float strtof(const char * __restrict __n, char ** __restrict __end_PTR); #ifdef __HAVE_LONG_DOUBLE long double strtold(const char * __restrict __n, char ** __restrict __end_PTR); #endif int strfromf(char * __restrict str, size_t n, const char * __restrict format, float fp); #ifdef __HAVE_LONG_DOUBLE int strfroml(char * __restrict str, size_t n, const char * __restrict format, long double fp); #endif #endif #if __MISC_VISIBLE /* the following strtodf interface is deprecated...use strtof instead */ #ifndef strtodf #define strtodf strtof #endif #endif long strtol(const char * __restrict __n, char ** __restrict __end_PTR, int __base); #ifdef __HAVE_LONG_DOUBLE #if __ISO_C_VISIBLE >= 1999 extern long double strtold(const char * __restrict, char ** __restrict); #endif #endif /* __HAVE_LONG_DOUBLE */ #if __ISO_C_VISIBLE >= 1999 long long strtoll(const char * __restrict __n, char ** __restrict __end_PTR, int __base); #endif unsigned long strtoul(const char * __restrict __n, char ** __restrict __end_PTR, int __base); #if __ISO_C_VISIBLE >= 1999 unsigned long long strtoull(const char * __restrict __n, char ** __restrict __end_PTR, int __base); #endif #if __GNU_VISIBLE double strtod_l(const char * __restrict, char ** __restrict, locale_t); float strtof_l(const char *__restrict, char **__restrict, locale_t); #ifdef __HAVE_LONG_DOUBLE extern long double strtold_l(const char * __restrict, char ** __restrict, locale_t); #endif /* __HAVE_LONG_DOUBLE */ long strtol_l(const char *__restrict, char **__restrict, int, locale_t); unsigned long strtoul_l(const char *__restrict, char **__restrict, int, locale_t __loc); long long strtoll_l(const char *__restrict, char **__restrict, int, locale_t); unsigned long long strtoull_l(const char * __restrict, char ** __restrict, int, locale_t __loc); #endif int system(const char *__string); #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 int unsetenv(const char *__string); #endif size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t); int wctomb(char *, wchar_t); void * valloc(size_t) __malloc_like __warn_unused_result __alloc_size(1) __nothrow; #if __SVID_VISIBLE || __XSI_VISIBLE >= 4 char *l64a(long __input); #endif #if __MISC_VISIBLE int on_exit(void (*__func)(int, void *), void *__arg); #endif /* XSI Legacy option group */ #if __XSI_VISIBLE >= 4 char *ecvt(double, int, int *, int *); int ecvt_r(double, int, int *, int *, char *, size_t); char *ecvtf(float, int, int *, int *); int ecvtf_r(float, int, int *, int *, char *, size_t); char *fcvt(double, int, int *, int *); int fcvt_r(double, int, int *, int *, char *, size_t); char *fcvtf(float, int, int *, int *); int fcvtf_r(float, int, int *, int *, char *, size_t); #if defined(__HAVE_LONG_DOUBLE) char *ecvtl(long double, int, int *, int *); int ecvtl_r(long double, int, int *, int *, char *, size_t); char *fcvtl(long double, int, int *, int *); int fcvtl_r(long double, int, int *, int *, char *, size_t); #endif char *gcvt(double, int, char *); char *gcvtf(float, int, char *); #if defined(__HAVE_LONG_DOUBLE) char *gcvtl(long double, int, char *); #endif #endif /* XSI_VISIBLE >= 4 */ /* Random newlib APIs */ #if __MISC_VISIBLE char *__itoa(int, char *, int); char *__utoa(unsigned, char *, int); char *itoa(int, char *, int); char *utoa(unsigned, char *, int); void cfree(void *); char *__dtoa(double, int, int, int *, int *, char **); char *__ldtoa(long double, int, int, int *, int *, char **); void __eprintf(const char *, const char *, unsigned int, const char *); #endif #if __STDC_WANT_LIB_EXT1__ == 1 #ifndef __STDC_LIB_EXT1__ #define __STDC_LIB_EXT1__ 1 #endif #include #ifndef _ERRNO_T_DEFINED typedef __errno_t errno_t; #define _ERRNO_T_DEFINED #endif #ifndef _RSIZE_T_DEFINED typedef __rsize_t rsize_t; #define _RSIZE_T_DEFINED #endif typedef void (*constraint_handler_t)(const char *__restrict msg, void *__restrict ptr, __errno_t error); constraint_handler_t set_constraint_handler_s(constraint_handler_t handler); void abort_handler_s(const char * __restrict msg, void * __restrict ptr, __errno_t error); void ignore_handler_s(const char * __restrict msg, void * __restrict ptr, __errno_t error); #endif _END_STD_C #if __SSP_FORTIFY_LEVEL > 0 #include #endif #endif /* _STDLIB_H_ */ picolibc-1.8.11/libc/include/stdnoreturn.h000066400000000000000000000032741513574234600205020ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _STDNORETURN_H_ #define _STDNORETURN_H_ #include #define noreturn _Noreturn #endif picolibc-1.8.11/libc/include/string.h000066400000000000000000000207011513574234600174130ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * string.h * * Definitions for memory and string functions. */ #ifndef _STRING_H_ #define _STRING_H_ #include #define __need_size_t #define __need_NULL #include #if __POSIX_VISIBLE >= 200809 #include #endif #if __BSD_VISIBLE #include #endif _BEGIN_STD_C /* There are two common basename variants. If you do NOT #include and you do #define _GNU_SOURCE #include you get the GNU version. Otherwise you get the POSIX versionfor which you should #include i for the function prototype. POSIX requires that #undef basename will still let you invoke the underlying function. However, this also implies that the POSIX version is used in this case. That's made sure here. */ #if __GNU_VISIBLE && !defined(basename) #ifdef __ASMNAME #define basename basename char * __nonnull((1)) basename(const char *) _ASMNAME("__gnu_basename"); #else #define basename(s) (__gnu_basename(s)) #endif #endif #if __MISC_VISIBLE || __POSIX_VISIBLE void *memccpy(void * __restrict, const void * __restrict, int, size_t); #endif void *memchr(const void *, int, size_t); int memcmp(const void *, const void *, size_t); void *memcpy(void * __restrict, const void * __restrict, size_t); #if __GNU_VISIBLE void *memmem(const void *, size_t, const void *, size_t); #endif void *memmove(void *, const void *, size_t); #if __GNU_VISIBLE void *mempcpy(void *, const void *, size_t); void *memrchr(const void *, int, size_t); #endif void *memset(void *, int, size_t); #if __ISO_C_VISIBLE >= 2023 void *memset_explicit(void *, int, size_t); #endif #if __GNU_VISIBLE void *rawmemchr(const void *, int); #endif #if __POSIX_VISIBLE >= 200809 char *stpcpy(char * __restrict, const char * __restrict); char *stpncpy(char * __restrict, const char * __restrict, size_t); #endif #if __GNU_VISIBLE char *strcasestr(const char *, const char *); #endif char *strcat(char * __restrict, const char * __restrict); char *strchr(const char *, int); #if __GNU_VISIBLE char *strchrnul(const char *, int); #endif int strcmp(const char *, const char *); int strcoll(const char *, const char *); #if __POSIX_VISIBLE >= 200809 int strcoll_l(const char *, const char *, locale_t); #endif char *strcpy(char *__restrict, const char *__restrict); size_t strcspn(const char *, const char *); #if __MISC_VISIBLE || __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 4 void free(void *) __nothrow; /* for __malloc_like */ char *strdup(const char *) __malloc_like __warn_unused_result; #endif #if __GNU_VISIBLE && defined(__GNUC__) #define strdupa(__s) \ (__extension__({ \ const char *__sin = (__s); \ size_t __len = strlen(__sin) + 1; \ char *__sout = (char *)__builtin_alloca(__len); \ (char *)memcpy(__sout, __sin, __len); \ })) #define strndupa(__s, __n) \ (__extension__({ \ const char *__sin = (__s); \ size_t __len = strnlen(__sin, (__n)) + 1; \ char *__sout = (char *)__builtin_alloca(__len); \ __sout[__len - 1] = '\0'; \ (char *)memcpy(__sout, __sin, __len - 1); \ })) #endif /* __GNU_VISIBLE && __GNUC__ */ char *strerror(int); #if __POSIX_VISIBLE >= 200809 char *strerror_l(int, locale_t); #endif /* There are two common strerror_r variants. If you request _GNU_SOURCE, you get the GNU version; otherwise you get the POSIX version. POSIX requires that #undef strerror_r will still let you invoke the underlying function, but that requires gcc support. */ #if __GNU_VISIBLE char *strerror_r(int, char *, size_t); #elif __POSIX_VISIBLE >= 200112 #ifdef __GNUC__ int strerror_r(int, char *, size_t) _ASMNAME("__xpg_strerror_r"); #else int __xpg_strerror_r(int, char *, size_t); #define strerror_r __xpg_strerror_r #endif #endif #if __GNU_VISIBLE const char *strerrorname_np(int errnum); const char *strerrordesc_np(int errnum); #endif #if __BSD_VISIBLE size_t strlcat(char *, const char *, size_t); #endif size_t strlen(const char *); #if __BSD_VISIBLE size_t strlcpy(char *, const char *, size_t); #endif #if __MISC_VISIBLE char *strlwr(char *); #endif char *strncat(char * __restrict, const char * __restrict, size_t); int strncmp(const char *, const char *, size_t); char *strncpy(char * __restrict, const char * __restrict, size_t); #if __POSIX_VISIBLE >= 200809 char * strndup(const char *, size_t) __malloc_like __warn_unused_result; #endif #if __POSIX_VISIBLE >= 200809 || __ZEPHYR_VISIBLE size_t strnlen(const char *, size_t); #endif #if __BSD_VISIBLE char *strnstr(const char *, const char *, size_t) __pure; #endif char *strpbrk(const char *, const char *); char *strrchr(const char *, int); #if __BSD_VISIBLE char *strsep(char **, const char *); #endif #if __POSIX_VISIBLE >= 200809 char *strsignal(int __signo); #endif size_t strspn(const char *, const char *); char *strstr(const char *, const char *); char *strtok(char *__restrict, const char *__restrict); #if __MISC_VISIBLE || __POSIX_VISIBLE || __ZEPHYR_VISIBLE char *strtok_r(char * __restrict, const char * __restrict, char ** __restrict); #endif #if __MISC_VISIBLE char *strupr(char *); #endif #if __GNU_VISIBLE int strverscmp(const char *, const char *); #endif size_t strxfrm(char * __restrict, const char * __restrict, size_t); #if __POSIX_VISIBLE >= 200809 size_t strxfrm_l(char * __restrict, const char * __restrict, size_t, locale_t); #endif #if __BSD_VISIBLE int timingsafe_bcmp(const void *, const void *, size_t); int timingsafe_memcmp(const void *, const void *, size_t); #endif #if __STDC_WANT_LIB_EXT1__ == 1 #ifndef __STDC_LIB_EXT1__ #define __STDC_LIB_EXT1__ 1 #endif #include #ifndef _ERRNO_T_DEFINED typedef __errno_t errno_t; #define _ERRNO_T_DEFINED #endif #ifndef _RSIZE_T_DEFINED typedef __rsize_t rsize_t; #define _RSIZE_T_DEFINED #endif errno_t memcpy_s(void * __restrict, rsize_t, const void * __restrict, rsize_t); errno_t memset_s(void *, rsize_t, int, rsize_t); errno_t memmove_s(void *, rsize_t, const void *, rsize_t); errno_t strcpy_s(char * __restrict, rsize_t, const char * __restrict); errno_t strcat_s(char * __restrict, rsize_t, const char * __restrict); errno_t strncpy_s(char * __restrict, rsize_t, const char * __restrict, rsize_t); errno_t strncat_s(char * __restrict, rsize_t, const char * __restrict, rsize_t); size_t strnlen_s(const char *, size_t); errno_t strerror_s(char *, rsize_t, errno_t); size_t strerrorlen_s(errno_t); #endif #include _END_STD_C #if __SSP_FORTIFY_LEVEL > 0 #include #endif #endif /* _STRING_H_ */ picolibc-1.8.11/libc/include/strings.h000066400000000000000000000056511513574234600176050ustar00rootroot00000000000000/*- * Copyright (c) 2002 Mike Barcroft * 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: head/include/strings.h 272673 2014-10-07 04:54:11Z delphij $ */ #ifndef _STRINGS_H_ #define _STRINGS_H_ #include #include #if __POSIX_VISIBLE >= 200809 #include #endif // As per the GCC source, _SIZE_T_DECLARD is FreeBSD 5 // So: Also check for _SIZE_T #if !defined(_SIZE_T_DECLARED) && !defined(_SIZE_T) typedef __size_t size_t; #endif #ifndef _SIZE_T_DECLARED #define _SIZE_T_DECLARED #endif #ifndef _SIZE_T #define _SIZE_T #endif _BEGIN_STD_C #if __BSD_VISIBLE || __POSIX_VISIBLE <= 200112 int bcmp(const void *, const void *, size_t) __pure; /* LEGACY */ void bcopy(const void *, void *, size_t); /* LEGACY */ void bzero(void *, size_t); /* LEGACY */ #endif #if __BSD_VISIBLE void explicit_bzero(void *, size_t); #endif #if __MISC_VISIBLE || __POSIX_VISIBLE < 200809 || __XSI_VISIBLE >= 700 int ffs(int) __const; #endif #if __BSD_VISIBLE int ffsl(long) __const; int ffsll(long long) __const; int fls(int) __const; int flsl(long) __const; int flsll(long long) __const; #endif #if __BSD_VISIBLE || __POSIX_VISIBLE <= 200112 char *index(const char *, int) __pure; /* LEGACY */ char *rindex(const char *, int) __pure; /* LEGACY */ #endif int strcasecmp(const char *, const char *) __pure; int strncasecmp(const char *, const char *, size_t) __pure; #if __POSIX_VISIBLE >= 200809 int strcasecmp_l(const char *, const char *, locale_t); int strncasecmp_l(const char *, const char *, size_t, locale_t); #endif _END_STD_C #if __SSP_FORTIFY_LEVEL > 0 #include #endif #endif /* _STRINGS_H_ */ picolibc-1.8.11/libc/include/sys/000077500000000000000000000000001513574234600165525ustar00rootroot00000000000000picolibc-1.8.11/libc/include/sys/CMakeLists.txt000066400000000000000000000040261513574234600213140ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_headers(sys auxv.h cdefs.h config.h custom_file.h _default_fcntl.h dirent.h dir.h errno.h fcntl.h features.h file.h iconvnls.h _initfini.h _intsup.h _locale.h lock.h param.h queue.h resource.h sched.h select.h _select.h _sigset.h stat.h _stdint.h string.h syslimits.h timeb.h time.h times.h _timespec.h timespec.h _timeval.h tree.h _types.h types.h _tz_structs.h unistd.h utime.h wait.h _wait.h ) picolibc-1.8.11/libc/include/sys/_default_fcntl.h000066400000000000000000000161641513574234600217040ustar00rootroot00000000000000/* Copyright (c) 2007 Jeff Johnston */ #ifndef _SYS__DEFAULT_FCNTL_H_ #define _SYS__DEFAULT_FCNTL_H_ #include #include _BEGIN_STD_C #ifndef _MODE_T_DECLARED typedef __mode_t mode_t; /* permissions */ #define _MODE_T_DECLARED #endif #ifndef _OFF_T_DECLARED typedef __off_t off_t; /* file offset */ #define _OFF_T_DECLARED #endif #ifndef _PID_T_DECLARED typedef __pid_t pid_t; /* process id */ #define _PID_T_DECLARED #endif #ifndef _OFF64_T_DECLARED typedef __off64_t off64_t; /* 64-bit file offset */ #define _OFF64_T_DECLARED #endif #define _FOPEN (-1) /* from sys/file.h, kernel use only */ #define _FREAD 0x0001 /* read enabled */ #define _FWRITE 0x0002 /* write enabled */ #define _FAPPEND 0x0400 /* append (writes guaranteed at the end) */ #define _FMARK 0x0010 /* internal; mark during gc() */ #define _FDEFER 0x0020 /* internal; defer for next gc pass */ #define _FASYNC 0x0008 /* signal pgrp when data ready */ #define _FSHLOCK 0x0080 /* BSD flock() shared lock present */ #define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */ #define _FCREAT 0x0040 /* open with file create */ #define _FTRUNC 0x0200 /* open with truncation */ #define _FEXCL 0x0800 /* error on open if file exists */ #define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */ #define _FSYNC 0x2000 /* do all writes synchronously */ #define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */ #define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */ #define _FNOCTTY 0x8000 /* don't assign a ctty on this open */ #define _FNOINHERIT 0x40000 #define _FDIRECT 0x80000 #define _FNOFOLLOW 0x100000 #define _FDIRECTORY 0x200000 #define _FEXECSRCH 0x400000 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR) /* * Flag values for open(2) and fcntl(2) * The kernel adds 1 to the open modes to turn it into some * combination of FREAD and FWRITE. */ #define O_RDONLY 0 /* +1 == FREAD */ #define O_WRONLY 1 /* +1 == FWRITE */ #define O_RDWR 2 /* +1 == FREAD|FWRITE */ #define O_APPEND _FAPPEND #define O_CREAT _FCREAT #define O_TRUNC _FTRUNC #define O_EXCL _FEXCL #define O_SYNC _FSYNC /* O_NDELAY _FNDELAY set in include/fcntl.h */ /* O_NDELAY _FNBIO set in include/fcntl.h */ #define O_NONBLOCK _FNONBLOCK #define O_NOCTTY _FNOCTTY /* POSIX-1.2008 specific flags */ #if __POSIX_VISIBLE >= 200809 #define O_CLOEXEC _FNOINHERIT #define O_NOFOLLOW _FNOFOLLOW #define O_DIRECTORY _FDIRECTORY #define O_EXEC _FEXECSRCH #define O_SEARCH _FEXECSRCH #endif #if __BSD_VISIBLE #define O_DIRECT _FDIRECT #endif #define O_DSYNC _FSYNC #define O_RSYNC _FSYNC #if __MISC_VISIBLE /* * Flags that work for fcntl(fd, F_SETFL, FXXXX) */ #define FAPPEND _FAPPEND #define FSYNC _FSYNC #define FASYNC _FASYNC #define FNBIO _FNBIO #define FNONBIO _FNONBLOCK /* XXX fix to be NONBLOCK everywhere */ #define FNDELAY _FNDELAY /* * Flags that are disallowed for fcntl's (FCNTLCANT); * used for opens, internal state, or locking. */ #define FREAD _FREAD #define FWRITE _FWRITE #define FMARK _FMARK #define FDEFER _FDEFER #define FSHLOCK _FSHLOCK #define FEXLOCK _FEXLOCK /* * The rest of the flags, used only for opens */ #define FOPEN _FOPEN #define FCREAT _FCREAT #define FTRUNC _FTRUNC #define FEXCL _FEXCL #define FNOCTTY _FNOCTTY #endif /* __MISC_VISIBLE */ #if __BSD_VISIBLE #define FNONBLOCK _FNONBLOCK #endif /* __BSD_VISIBLE */ /* XXX close on exec request; must match UF_EXCLOSE in user.h */ #define FD_CLOEXEC 1 /* posix */ /* fcntl(2) requests */ #define F_DUPFD 0 /* Duplicate fildes */ #define F_GETFD 1 /* Get fildes flags (close on exec) */ #define F_SETFD 2 /* Set fildes flags (close on exec) */ #define F_GETFL 3 /* Get file flags */ #define F_SETFL 4 /* Set file flags */ #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 #define F_GETOWN 5 /* Get owner - for ASYNC */ #define F_SETOWN 6 /* Set owner - for ASYNC */ #endif /* __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 */ #define F_GETLK 7 /* Get record-locking information */ #define F_SETLK 8 /* Set or Clear a record-lock (Non-Blocking) */ #define F_SETLKW 9 /* Set or Clear a record-lock (Blocking) */ #if __MISC_VISIBLE #define F_RGETLK 10 /* Test a remote lock to see if it is blocked */ #define F_RSETLK 11 /* Set or unlock a remote lock */ #define F_CNVT 12 /* Convert a fhandle to an open fd */ #define F_RSETLKW 13 /* Set or Clear remote record-lock(Blocking) */ #endif /* __MISC_VISIBLE */ #if __POSIX_VISIBLE >= 200809 #define F_DUPFD_CLOEXEC 14 /* As F_DUPFD, but set close-on-exec flag */ #endif /* fcntl(2) flags (l_type field of flock structure) */ #define F_RDLCK 1 /* read lock */ #define F_WRLCK 2 /* write lock */ #define F_UNLCK 3 /* remove lock(s) */ #if __MISC_VISIBLE #define F_UNLKSYS 4 /* remove remote locks for a given system */ #endif /* __MISC_VISIBLE */ #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 /* Special descriptor value to denote the cwd in calls to openat(2) etc. */ #define AT_FDCWD -2 /* Flag values for faccessat2) et al. */ #define AT_EACCESS 0x0001 #define AT_SYMLINK_NOFOLLOW 0x0002 #define AT_SYMLINK_FOLLOW 0x0004 #define AT_REMOVEDIR 0x0008 #if __GNU_VISIBLE #define AT_EMPTY_PATH 0x0010 #define _AT_NULL_PATHNAME_ALLOWED 0x4000 /* Internal flag used by futimesat */ #endif #endif #if __BSD_VISIBLE /* lock operations for flock(2) */ #define LOCK_SH 0x01 /* shared file lock */ #define LOCK_EX 0x02 /* exclusive file lock */ #define LOCK_NB 0x04 /* don't block when locking */ #define LOCK_UN 0x08 /* unlock file */ #endif /* file segment locking set data type - information passed to system by user */ struct flock { short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */ short l_whence; /* flag to choose starting offset */ long l_start; /* relative offset, in bytes */ long l_len; /* length, in bytes; 0 means lock to EOF */ short l_pid; /* returned with F_GETLK */ short l_xxx; /* reserved for future use */ }; #if __MISC_VISIBLE /* extended file segment locking set data type */ struct eflock { short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */ short l_whence; /* flag to choose starting offset */ long l_start; /* relative offset, in bytes */ long l_len; /* length, in bytes; 0 means lock to EOF */ short l_pid; /* returned with F_GETLK */ short l_xxx; /* reserved for future use */ long l_rpid; /* Remote process id wanting this lock */ long l_rsys; /* Remote system id wanting this lock */ }; #endif /* __MISC_VISIBLE */ extern int open(const char *, int, ...); #if __ATFILE_VISIBLE extern int openat(int, const char *, int, ...); #endif extern int creat(const char *, mode_t); extern int fcntl(int, int, ...); #if __BSD_VISIBLE extern int flock(int, int); #endif /* Provide _ prototypes for functions provided by some versions of newlib. */ #ifdef _LIBC extern int open(const char *, int, ...); extern int fcntl(int, int, ...); #ifdef __LARGE64_FILES extern int open64(const char *, int, ...); #endif #endif _END_STD_C #endif /* !_SYS__DEFAULT_FCNTL_H_ */ picolibc-1.8.11/libc/include/sys/_initfini.h000066400000000000000000000044311513574234600206750ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __INITFINI_H_ #define __INITFINI_H_ #include /* These magic symbols are provided by the linker. */ extern void (*__preinit_array_start[])(void) __weak; extern void (*__preinit_array_end[])(void) __weak; extern void (*__init_array_start[])(void) __weak; extern void (*__init_array_end[])(void) __weak; extern void (*__bothinit_array_start[])(void) __weak; extern void (*__bothinit_array_end[])(void) __weak; extern void (*__fini_array_start[])(void) __weak; extern void (*__fini_array_end[])(void) __weak; #ifdef __INIT_FINI_FUNCS extern void _init(void) __weak; extern void _fini(void) __weak; #endif void __libc_init_array(void); void __libc_fini_array(void); #endif /* __INITFINI_H_ */ picolibc-1.8.11/libc/include/sys/_intsup.h000066400000000000000000000133041513574234600204050ustar00rootroot00000000000000/* * Copyright (c) 2004, 2005 by * Ralf Corsepius, Ulm/Germany. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #ifndef _SYS__INTSUP_H #define _SYS__INTSUP_H #include #if __GNUC_PREREQ(3, 2) /* gcc > 3.2 implicitly defines the values we are interested */ #define __STDINT_EXP(x) __##x##__ #else #define __STDINT_EXP(x) x #include #endif /* Determine how intptr_t and intN_t fastN_t and leastN_t are defined by gcc for this target. This is used to determine the correct printf() constant in inttypes.h and other constants in stdint.h. So we end up with ?(signed|unsigned) char == 0 ?(signed|unsigned) short == 1 ?(signed|unsigned) int == 2 ?(signed|unsigned) short int == 3 ?(signed|unsigned) long == 4 ?(signed|unsigned) long int == 6 ?(signed|unsigned) long long == 8 ?(signed|unsigned) long long int == 10 */ #if __GNUC_PREREQ(4, 4) #pragma push_macro("signed") #pragma push_macro("unsigned") #pragma push_macro("char") #pragma push_macro("short") #pragma push_macro("__int20") #pragma push_macro("__int20__") #pragma push_macro("int") #pragma push_macro("long") #endif #undef signed #undef unsigned #undef char #undef short #undef int #undef __int20 #undef __int20__ #undef long #define signed +0 #define unsigned +0 #define char +0 #define short +1 #define __int20 +2 #define __int20__ +2 #define int +2 #define long +4 #if (__INTPTR_TYPE__ == 8 || __INTPTR_TYPE__ == 10) #define _INTPTR_EQ_LONGLONG #elif (__INTPTR_TYPE__ == 4 || __INTPTR_TYPE__ == 6) #define _INTPTR_EQ_LONG /* Note - the tests for _INTPTR_EQ_INT and _INTPTR_EQ_SHORT are currently redundant as the values are not used. But one day they may be needed and so the tests remain. */ #elif __INTPTR_TYPE__ == 2 #define _INTPTR_EQ_INT #elif (__INTPTR_TYPE__ == 1 || __INTPTR_TYPE__ == 3) #define _INTPTR_EQ_SHORT #else #error "Unable to determine type definition of intptr_t" #endif #if (__INT32_TYPE__ == 4 || __INT32_TYPE__ == 6) #define _INT32_EQ_LONG #elif __INT32_TYPE__ == 2 /* Nothing to define because int32_t is safe to print as an int. */ #else #error "Unable to determine type definition of int32_t" #endif #if (__INT8_TYPE__ == 0) #define __INT8 "hh" #elif (__INT8_TYPE__ == 1 || __INT8_TYPE__ == 3) #define __INT8 "h" #elif (__INT8_TYPE__ == 2) #define __INT8 #elif (__INT8_TYPE__ == 4 || __INT8_TYPE__ == 6) #define __INT8 "l" #elif (__INT8_TYPE__ == 8 || __INT8_TYPE__ == 10) #define __INT8 "ll" #endif #if (__INT16_TYPE__ == 1 || __INT16_TYPE__ == 3) #define __INT16 "h" #elif (__INT16_TYPE__ == 2) #define __INT16 #elif (__INT16_TYPE__ == 4 || __INT16_TYPE__ == 6) #define __INT16 "l" #elif (__INT16_TYPE__ == 8 || __INT16_TYPE__ == 10) #define __INT16 "ll" #endif #if (__INT32_TYPE__ == 2) #define __INT32 #elif (__INT32_TYPE__ == 4 || __INT32_TYPE__ == 6) #define __INT32 "l" #elif (__INT32_TYPE__ == 8 || __INT32_TYPE__ == 10) #define __INT32 "ll" #endif #if (__INT64_TYPE__ == 2) #define __INT64 #elif (__INT64_TYPE__ == 4 || __INT64_TYPE__ == 6) #define __INT64 "l" #elif (__INT64_TYPE__ == 8 || __INT64_TYPE__ == 10) #define __INT64 "ll" #endif #if (__INT_FAST8_TYPE__ == 0) #define __FAST8 "hh" #elif (__INT_FAST8_TYPE__ == 1 || __INT_FAST8_TYPE__ == 3) #define __FAST8 "h" #elif (__INT_FAST8_TYPE__ == 2) #define __FAST8 #elif (__INT_FAST8_TYPE__ == 4 || __INT_FAST8_TYPE__ == 6) #define __FAST8 "l" #elif (__INT_FAST8_TYPE__ == 8 || __INT_FAST8_TYPE__ == 10) #define __FAST8 "ll" #endif #if (__INT_FAST16_TYPE__ == 1 || __INT_FAST16_TYPE__ == 3) #define __FAST16 "h" #elif (__INT_FAST16_TYPE__ == 2) #define __FAST16 #elif (__INT_FAST16_TYPE__ == 4 || __INT_FAST16_TYPE__ == 6) #define __FAST16 "l" #elif (__INT_FAST16_TYPE__ == 8 || __INT_FAST16_TYPE__ == 10) #define __FAST16 "ll" #endif #if (__INT_FAST32_TYPE__ == 2) #define __FAST32 #elif (__INT_FAST32_TYPE__ == 4 || __INT_FAST32_TYPE__ == 6) #define __FAST32 "l" #elif (__INT_FAST32_TYPE__ == 8 || __INT_FAST32_TYPE__ == 10) #define __FAST32 "ll" #endif #if (__INT_FAST64_TYPE__ == 2) #define __FAST64 #elif (__INT_FAST64_TYPE__ == 4 || __INT_FAST64_TYPE__ == 6) #define __FAST64 "l" #elif (__INT_FAST64_TYPE__ == 8 || __INT_FAST64_TYPE__ == 10) #define __FAST64 "ll" #endif #if (__INT_LEAST8_TYPE__ == 0) #define __LEAST8 "hh" #elif (__INT_LEAST8_TYPE__ == 1 || __INT_LEAST8_TYPE__ == 3) #define __LEAST8 "h" #elif (__INT_LEAST8_TYPE__ == 2) #define __LEAST8 #elif (__INT_LEAST8_TYPE__ == 4 || __INT_LEAST8_TYPE__ == 6) #define __LEAST8 "l" #elif (__INT_LEAST8_TYPE__ == 8 || __INT_LEAST8_TYPE__ == 10) #define __LEAST8 "ll" #endif #if (__INT_LEAST16_TYPE__ == 1 || __INT_LEAST16_TYPE__ == 3) #define __LEAST16 "h" #elif (__INT_LEAST16_TYPE__ == 2) #define __LEAST16 #elif (__INT_LEAST16_TYPE__ == 4 || __INT_LEAST16_TYPE__ == 6) #define __LEAST16 "l" #elif (__INT_LEAST16_TYPE__ == 8 || __INT_LEAST16_TYPE__ == 10) #define __LEAST16 "ll" #endif #if (__INT_LEAST32_TYPE__ == 2) #define __LEAST32 #elif (__INT_LEAST32_TYPE__ == 4 || __INT_LEAST32_TYPE__ == 6) #define __LEAST32 "l" #elif (__INT_LEAST32_TYPE__ == 8 || __INT_LEAST32_TYPE__ == 10) #define __LEAST32 "ll" #endif #if (__INT_LEAST64_TYPE__ == 2) #define __LEAST64 #elif (__INT_LEAST64_TYPE__ == 4 || __INT_LEAST64_TYPE__ == 6) #define __LEAST64 "l" #elif (__INT_LEAST64_TYPE__ == 8 || __INT_LEAST64_TYPE__ == 10) #define __LEAST64 "ll" #endif #undef signed #undef unsigned #undef char #undef short #undef int #undef long #if __GNUC_PREREQ(4, 4) #pragma pop_macro("signed") #pragma pop_macro("unsigned") #pragma pop_macro("char") #pragma pop_macro("short") #pragma pop_macro("__int20") #pragma pop_macro("__int20__") #pragma pop_macro("int") #pragma pop_macro("long") #endif #endif /* _SYS__INTSUP_H */ picolibc-1.8.11/libc/include/sys/_locale.h000066400000000000000000000003501513574234600203170ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen */ /* Definition of opaque POSIX-1.2008 type locale_t for userspace. */ #ifndef _SYS__LOCALE_H #define _SYS__LOCALE_H typedef int locale_t; #endif /* _SYS__LOCALE_H */ picolibc-1.8.11/libc/include/sys/_select.h000066400000000000000000000061351513574234600203460ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SYS__SELECT_H #define _SYS__SELECT_H _BEGIN_STD_C #define _SYS_TYPES_FD_SET /* * Select uses bit masks of file descriptors in longs. * These macros manipulate such bit fields (the filesystem macros use chars). * FD_SETSIZE may be defined by the user, but the default here * should be enough for most uses. */ #ifndef FD_SETSIZE #if defined(__rtems__) #define FD_SETSIZE 256 #else #define FD_SETSIZE 64 #endif #endif typedef unsigned long __fd_mask; #if __BSD_VISIBLE typedef __fd_mask fd_mask; #endif #define __NFDBITS ((int)sizeof(__fd_mask) * 8) /* bits per mask */ #define __FD_ARRAY_SIZE ((FD_SETSIZE + __NFDBITS - 1) / __NFDBITS) #if __BSD_VISIBLE #define NFDBITS __NFDBITS #endif typedef struct fd_set { __fd_mask __fds_bits[__FD_ARRAY_SIZE]; } fd_set; #define __fdset_mask(n) ((__fd_mask)1 << ((n) % __NFDBITS)) #define FD_CLR(n, p) ((p)->__fds_bits[(n) / __NFDBITS] &= ~__fdset_mask(n)) #if __BSD_VISIBLE #define FD_COPY(f, t) (void)(*(t) = *(f)) #endif #define FD_ISSET(n, p) (((p)->__fds_bits[(n) / __NFDBITS] & __fdset_mask(n)) != 0) #define FD_SET(n, p) ((p)->__fds_bits[(n) / __NFDBITS] |= __fdset_mask(n)) #define FD_ZERO(p) \ do { \ fd_set *__p = (p); \ __size_t __i; \ for (__i = 0; __i < __FD_ARRAY_SIZE; __i++) \ __p->__fds_bits[__i] = 0; \ } while (0) int select(int __n, fd_set *__readfds, fd_set *__writefds, fd_set *__exceptfds, struct timeval *__timeout); _END_STD_C #endif /* sys/_select.h */ picolibc-1.8.11/libc/include/sys/_sigset.h000066400000000000000000000040011513574234600203530ustar00rootroot00000000000000/*- * Copyright (c) 1982, 1986, 1989, 1991, 1993 * The Regents of the University of California. All rights reserved. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph * Co. or Unix System Laboratories, Inc. and are reproduced herein with * the permission of UNIX System Laboratories, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)signal.h 8.4 (Berkeley) 5/4/95 * $FreeBSD$ */ #ifndef _SYS__SIGSET_H_ #define _SYS__SIGSET_H_ typedef unsigned long __sigset_t; #endif /* !_SYS__SIGSET_H_ */ picolibc-1.8.11/libc/include/sys/_stdint.h000066400000000000000000000033551513574234600203750ustar00rootroot00000000000000/* * Copyright (c) 2004, 2005 by * Ralf Corsepius, Ulm/Germany. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #ifndef _SYS__STDINT_H #define _SYS__STDINT_H #include _BEGIN_STD_C #ifdef ___int8_t_defined #ifndef _INT8_T_DECLARED typedef __int8_t int8_t; #define _INT8_T_DECLARED #endif #ifndef _UINT8_T_DECLARED typedef __uint8_t uint8_t; #define _UINT8_T_DECLARED #endif #define __int8_t_defined 1 #endif /* ___int8_t_defined */ #ifdef ___int16_t_defined #ifndef _INT16_T_DECLARED typedef __int16_t int16_t; #define _INT16_T_DECLARED #endif #ifndef _UINT16_T_DECLARED typedef __uint16_t uint16_t; #define _UINT16_T_DECLARED #endif #define __int16_t_defined 1 #endif /* ___int16_t_defined */ #ifdef ___int32_t_defined #ifndef _INT32_T_DECLARED typedef __int32_t int32_t; #define _INT32_T_DECLARED #endif #ifndef _UINT32_T_DECLARED typedef __uint32_t uint32_t; #define _UINT32_T_DECLARED #endif #define __int32_t_defined 1 #endif /* ___int32_t_defined */ #ifdef ___int64_t_defined #ifndef _INT64_T_DECLARED typedef __int64_t int64_t; #define _INT64_T_DECLARED #endif #ifndef _UINT64_T_DECLARED typedef __uint64_t uint64_t; #define _UINT64_T_DECLARED #endif #define __int64_t_defined 1 #endif /* ___int64_t_defined */ #ifndef _INTMAX_T_DECLARED typedef __intmax_t intmax_t; #define _INTMAX_T_DECLARED #endif #ifndef _UINTMAX_T_DECLARED typedef __uintmax_t uintmax_t; #define _UINTMAX_T_DECLARED #endif #ifndef _INTPTR_T_DECLARED typedef __intptr_t intptr_t; #define _INTPTR_T_DECLARED #endif #ifndef _UINTPTR_T_DECLARED typedef __uintptr_t uintptr_t; #define _UINTPTR_T_DECLARED #endif _END_STD_C #endif /* _SYS__STDINT_H */ picolibc-1.8.11/libc/include/sys/_timespec.h000066400000000000000000000040571513574234600207010ustar00rootroot00000000000000/*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1982, 1986, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)time.h 8.5 (Berkeley) 5/4/95 * from: FreeBSD: src/sys/sys/time.h,v 1.43 2000/03/20 14:09:05 phk Exp * $FreeBSD: head/sys/sys/_timespec.h 326023 2017-11-20 19:43:44Z pfg $ */ #ifndef _SYS__TIMESPEC_H_ #define _SYS__TIMESPEC_H_ #ifndef _TIME_T_DECLARED typedef __time_t time_t; #define _TIME_T_DECLARED #endif struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* and nanoseconds */ }; #endif /* !_SYS__TIMESPEC_H_ */ picolibc-1.8.11/libc/include/sys/_timeval.h000066400000000000000000000036531513574234600205320ustar00rootroot00000000000000/*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2002 Mike Barcroft * 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: head/sys/sys/_timeval.h 326256 2017-11-27 15:01:59Z pfg $ */ #ifndef _SYS__TIMEVAL_H_ #define _SYS__TIMEVAL_H_ #ifndef _SUSECONDS_T_DECLARED typedef __suseconds_t suseconds_t; #define _SUSECONDS_T_DECLARED #endif #ifndef _TIME_T_DECLARED typedef _TIME_T_ time_t; #define _TIME_T_DECLARED #endif /* * Structure returned by gettimeofday(2) system call, and used in other calls. */ struct timeval { time_t tv_sec; /* seconds */ suseconds_t tv_usec; /* and microseconds */ }; #endif /* !_SYS__TIMEVAL_H_ */ picolibc-1.8.11/libc/include/sys/_types.h000066400000000000000000000157571513574234600202450ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* ANSI C namespace clean utility typedefs */ /* This file defines various typedefs needed by the system calls that support the C library. Basically, they're just the POSIX versions with an '_' prepended. Targets shall use to define their own internal types if desired. There are three define patterns used for type definitions. Lets assume xyz_t is a user type. The internal type definition uses __machine_xyz_t_defined. It is defined by to disable a default definition in . It must not be used in other files. User type definitions are guarded by __xyz_t_defined in glibc and _XYZ_T_DECLARED in BSD compatible systems. */ #ifndef _SYS__TYPES_H #define _SYS__TYPES_H #define __need_size_t #define __need_wint_t #include /* The Arm Compiler doesn't define wint_t as part of stddef.h so * define it here. */ #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100) typedef __WINT_TYPE__ wint_t; #endif #include #ifndef __machine_blkcnt_t_defined typedef long __blkcnt_t; typedef __int64_t __blkcnt64_t; #endif #ifndef __machine_blksize_t_defined typedef long __blksize_t; #endif #ifndef __machine_fsblkcnt_t_defined typedef __uint64_t __fsblkcnt_t; #endif #ifndef __machine_fsfilcnt_t_defined typedef __uint32_t __fsfilcnt_t; #endif #ifndef __machine_off_t_defined #if __SIZEOF_SIZE_T__ == 8 && __SIZEOF_LONG__ < 8 typedef __uint64_t _off_t; #else typedef long _off_t; #endif #endif #if defined(__XMK__) typedef signed char __pid_t; #else typedef int __pid_t; #endif #ifndef __machine_dev_t_defined #ifdef __linux typedef __uint64_t __dev_t; #else typedef short __dev_t; #endif #endif #ifndef __machine_uid_t_defined #ifdef __linux typedef __uint32_t __uid_t; #else typedef unsigned short __uid_t; #endif #endif #ifndef __machine_gid_t_defined #ifdef __linux typedef __uint32_t __gid_t; #else typedef unsigned short __gid_t; #endif #endif #ifndef __machine_id_t_defined typedef __uint32_t __id_t; #endif #ifndef __machine_ino_t_defined #if (defined(__i386__) && (defined(GO32) || defined(__MSDOS__))) || defined(__sparc__) \ || defined(__SPU__) || defined(__linux) typedef unsigned long __ino_t; #else typedef unsigned short __ino_t; #endif typedef __uint64_t __ino64_t; #endif #ifndef __machine_mode_t_defined #if defined(__i386__) && (defined(GO32) || defined(__MSDOS__)) typedef int __mode_t; #else #if defined(__sparc__) && !defined(__sparc_v9__) #ifdef __svr4__ typedef unsigned long __mode_t; #else typedef unsigned short __mode_t; #endif #else typedef __uint32_t __mode_t; #endif #endif #endif #ifndef __machine_off64_t_defined __extension__ typedef long long _off64_t; #endif typedef _off_t __off_t; typedef __uint64_t __off64_t; typedef _off64_t __loff_t; #ifndef __machine_key_t_defined typedef long __key_t; #endif /* * We need fpos_t for the following, but it doesn't have a leading "_", * so we use _fpos_t instead. */ #ifndef __machine_fpos_t_defined typedef long _fpos_t; /* XXX must match off_t in */ /* (and must be `long' for now) */ #endif #ifndef __machine_fpos64_t_defined typedef _off64_t _fpos64_t; #endif /* Defined by GCC provided */ #undef __size_t #ifndef __machine_size_t_defined #ifdef __SIZE_TYPE__ typedef __SIZE_TYPE__ __size_t; #else #if defined(__INT_MAX__) && __INT_MAX__ == 2147483647 typedef unsigned int __size_t; #else typedef unsigned long __size_t; #endif #endif #endif #ifndef __machine_ssize_t_defined #ifdef __SIZE_TYPE__ /* If __SIZE_TYPE__ is defined (gcc) we define ssize_t based on size_t. We simply change "unsigned" to "signed" for this single definition to make sure ssize_t and size_t only differ by their signedness. */ #define unsigned signed typedef __SIZE_TYPE__ _ssize_t; #undef unsigned #else #if defined(__INT_MAX__) && __INT_MAX__ == 2147483647 typedef int _ssize_t; #else typedef long _ssize_t; #endif #endif #endif typedef _ssize_t __ssize_t; #ifndef __machine_mbstate_t_defined /* Conversion state information. */ typedef struct { int __count; union { wint_t __wch; unsigned char __wchb[4]; __uint32_t __ucs; __uint16_t __ucs2; } __value; /* Value so far. */ } _mbstate_t; #endif #ifndef __machine_iconv_t_defined /* Iconv descriptor type */ struct __iconv_t; typedef struct __iconv_t *_iconv_t; #endif #ifndef __machine_clock_t_defined #define _CLOCK_T_ unsigned long /* clock() */ #endif typedef _CLOCK_T_ __clock_t; #if __SIZEOF_LONG__ == 8 #define _TIME_T_ long #else #define _TIME_T_ __int_least64_t #endif typedef _TIME_T_ __time_t; #ifndef __machine_clockid_t_defined #define _CLOCKID_T_ unsigned long #endif typedef _CLOCKID_T_ __clockid_t; #ifndef __machine_daddr_t_defined typedef long __daddr_t; #endif #define _TIMER_T_ unsigned long typedef _TIMER_T_ __timer_t; #ifndef __machine_sa_family_t_defined typedef __uint8_t __sa_family_t; #endif #ifndef __machine_socklen_t_defined typedef __uint32_t __socklen_t; #endif typedef __int32_t __nl_item; typedef unsigned short __nlink_t; typedef long __suseconds_t; /* microseconds (signed) */ typedef unsigned long __useconds_t; /* microseconds (unsigned) */ #ifdef __STDC_WANT_LIB_EXT1__ #if (__STDC_WANT_LIB_EXT1__ != 0) && (__STDC_WANT_LIB_EXT1__ != 1) #error Please define __STDC_WANT_LIB_EXT__ as 0 or 1 #endif #if __STDC_WANT_LIB_EXT1__ == 1 #ifndef __STDC_LIB_EXT1__ #define __STDC_LIB_EXT1__ 1 #endif typedef size_t __rsize_t; typedef int __errno_t; #endif #endif typedef __uint16_t __wctype_t; #endif /* _SYS__TYPES_H */ picolibc-1.8.11/libc/include/sys/_tz_structs.h000066400000000000000000000011231513574234600213030ustar00rootroot00000000000000#ifndef _SYS__TZ_STRUCTS_H_ #define _SYS__TZ_STRUCTS_H_ typedef struct __tzrule_struct { char ch; int m; /* Month of year if ch=M */ int n; /* Week of month if ch=M */ int d; /* Day of week if ch=M, day of year if ch=J or ch=D */ int s; /* Time of day in seconds */ time_t change; long offset; /* Match type of _timezone. */ } __tzrule_type; typedef struct __tzinfo_struct { int __tznorth; int __tzyear; __tzrule_type __tzrule[2]; } __tzinfo_type; __tzinfo_type *__gettzinfo(void); #endif /* _SYS__TZ_STRUCTS_H_ */ picolibc-1.8.11/libc/include/sys/_wait.h000066400000000000000000000042741513574234600200350ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SYS__WAIT_H #define _SYS__WAIT_H /* Common defintions needed by both stdlib.h and sys/wait.h */ #define WNOHANG 1 #define WUNTRACED 2 /* A status looks like: <1 byte info> <1 byte code> == 0, child has exited, info is the exit value == 1..7e, child has exited, info is the signal number. == 7f, child has stopped, info was the signal number. == 80, there was a core dump. */ #define WIFEXITED(w) (((w) & 0xff) == 0) #define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f)) #define WIFSTOPPED(w) (((w) & 0xff) == 0x7f) #define WEXITSTATUS(w) (((w) >> 8) & 0xff) #define WTERMSIG(w) ((w) & 0x7f) #define WSTOPSIG WEXITSTATUS #endif picolibc-1.8.11/libc/include/sys/auxv.h000066400000000000000000000034351513574234600177130ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SYS_AUXV_H #define _SYS_AUXV_H #include _BEGIN_STD_C unsigned long getauxval(unsigned long type); #define AT_HWCAP 16 #define AT_HWCAP2 26 _END_STD_C #endif /* _SYS_AUXV_H */ picolibc-1.8.11/libc/include/sys/cdefs.h000066400000000000000000000501111513574234600200050ustar00rootroot00000000000000/* libc/sys/linux/sys/cdefs.h - Helper macros for K&R vs. ANSI C compat. */ /* Written 2000 by Werner Almesberger */ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Berkeley Software Design, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 * $FreeBSD$ */ #ifndef _SYS_CDEFS_H_ #define _SYS_CDEFS_H_ #include #include #define __PMT(args) args #define __DOTS , ... #ifdef __cplusplus #define __THROW throw() #else #define __THROW #endif #ifdef __GNUC__ #define __ASMNAME(cname) __XSTRING(__USER_LABEL_PREFIX__) cname #define _ASMNAME(cname) __asm__(__ASMNAME(cname)) #else #define _ASMNAME(cname) #endif #define __ptr_t void * #define __long_double_t long double #ifndef __BOUNDED_POINTERS__ #define __bounded /* nothing */ #define __unbounded /* nothing */ #define __ptrvalue /* nothing */ #endif /* * Compiler feature checks. */ #ifndef __has_attribute #define __has_attribute(x) 0 #endif #ifndef __has_feature #define __has_feature(x) 0 #endif #ifndef __has_builtin #define __has_builtin(x) 0 #endif /* * Attributes. * * For many of these, the attribute isn't strictly necessary, so they * can be safely replaced with nothing when not supported */ #if __has_attribute(__pure__) #define __pure __attribute__((__pure__)) #else #define __pure #endif #if __has_attribute(__format__) #define __picolibc_format(a, b, c) __attribute__((__format__(a, b, c))) #else #define __picolibc_format(a, b, c) #endif #if __has_attribute(__nonnull__) #define __nonnull(params) __attribute__((__nonnull__ params)) #else #define __nonnull(params) #endif #if __has_attribute(__returns_nonnull__) #define __returns_nonnull __attribute__((__returns_nonnull__)) #else #define __returns_nonnull #endif #if __has_attribute(__alloc_size__) #define __alloc_size(a) __attribute__((__alloc_size__(a))) #define __alloc_size2(a, b) __attribute__((__alloc_size__(a, b))) #else #define __alloc_size(a) #define __alloc_size2(a, b) #endif #if __has_attribute(__alloc_align__) #define __alloc_align(param) __attribute__((__alloc_align__(param))) #else #define __alloc_align(param) #endif #if defined(__cplusplus) && __cplusplus >= 201103L #define __noreturn [[noreturn]] #elif __has_attribute(__noreturn__) #define __noreturn __attribute__((__noreturn__)) #else #define __noreturn #endif #if __has_attribute(__const__) #define __const __attribute__((__const__)) #else #define __const #endif #if __has_attribute(__unused__) #define __unused __attribute__((__unused__)) #else #define __unused #endif #if __has_attribute(__used__) #define __used __attribute__((__used__)) #else #define __used #endif #if __has_attribute(__packed__) #define __packed __attribute__((__packed__)) #else #define __packed #endif #if __has_attribute(__aligned__) #define __aligned(x) __attribute__((__aligned__(x))) #else #define __aligned(x) #endif #if __has_attribute(__section__) #define __section(x) __attribute__((__section__(x))) #else #define __section(x) #endif #if __has_attribute(__naked__) #define __naked __attribute__((__naked__)) #else #define __naked #endif #if __has_attribute(__noinline__) #define __noinline __attribute__((__noinline__)) #else #define __noinline #endif #if __has_attribute(__always_inline__) #define __always_inline __inline __attribute__((__always_inline__)) #else #define __always_inline #endif #if __has_attribute(__warn_unused_result__) #define __warn_unused_result __attribute__((__warn_unused_result__)) #else #define __warn_unused_result #endif #if __has_attribute(__weak__) #define __weak __attribute__((__weak__)) #else #define __weak #endif #if __has_attribute(__nothrow__) #define __nothrow __attribute__((__nothrow__)) #else #define __nothrow #endif #if __has_attribute(__no_sanitize_address__) #define __no_sanitize_address __attribute__((__no_sanitize_address__)) #else #define __no_sanitize_address #endif #if __has_attribute(__no_sanitize__) #define __no_sanitize(s) __attribute__((__no_sanitize__(s))) #else #define __no_sanitize(s) #endif #if __has_attribute(__no_sanitize_undefined__) #define __no_sanitize_undefined __attribute__((__no_sanitize_undefined__)) #else #define __no_sanitize_undefined #endif #if __has_attribute(__disable_sanitizer_instrumentation__) #define __disable_sanitizer_instrumentation __attribute__((__disable_sanitizer_instrumentation__)) #else #define __disable_sanitizer_instrumentation #endif #define __disable_sanitizer \ __no_sanitize_address __no_sanitize_undefined __disable_sanitizer_instrumentation \ __no_sanitize("undefined") #if __has_attribute(__deprecated__) #if __GNUC_PREREQ__(4, 5) || defined(__clang__) #define __deprecated_m(m) __attribute__((__deprecated__(m))) #else #define __deprecated_m(m) __attribute__((__deprecated__)) #endif #define __deprecated __attribute__((__deprecated__)) #else #define __deprecated_m(m) #define __deprecated #endif #if __has_attribute(__no_builtin__) #define __no_builtin __attribute__((__no_builtin__)) #elif defined(__HAVE_CC_INHIBIT_LOOP_TO_LIBCALL) #define __no_builtin __attribute__((__optimize__("-fno-tree-loop-distribute-patterns"))) #else #define __no_builtin #endif #if __has_attribute(__malloc__) #if __GNUC_PREREQ__(11, 0) #define __malloc_like_with_free(_f, _a) __attribute__((__malloc__, __malloc__(_f, _a))) #else #define __malloc_like_with_free(_f, _a) __attribute__((__malloc__)) #endif #else #define __malloc_like_with_free(free, free_arg) #endif #define __malloc_like __malloc_like_with_free(free, 1) #if __has_attribute(always_inline) && __has_attribute(gnu_inline) /* * When this macro is defined, use it to declare inline versions of extern functions. */ #define __declare_extern_inline(type) extern __inline type __attribute((gnu_inline, always_inline)) #endif #if __has_attribute(__alias__) #define __strong_reference(sym, aliassym) \ extern __typeof(sym) aliassym __attribute__((__alias__(__STRING(sym)))) #define __strong_reference_dup(sym, aliassym) \ extern __typeof(aliassym) aliassym __attribute__((__alias__(__STRING(sym)))) #if __has_attribute(__weak__) #define __weak_reference(sym, aliassym) \ extern __typeof(sym) aliassym __attribute__((__weak__, __alias__(__STRING(sym)))) #endif #endif #if __has_attribute(__returns_twice__) #define __returns_twice __attribute__((__returns_twice__)) #else #define __returns_twice #endif /* * Builtins. * * When __has_builtin isn't available, these need to be detected * during configuration. */ #if __has_builtin(__builtin_add_overflow) #define __HAVE_BUILTIN_ADD_OVERFLOW 1 #endif #if __has_builtin(__builtin_alloca) #define __HAVE_BUILTIN_ALLOCA 1 #endif #if __has_builtin(__builtin_copysign) #define __HAVE_BUILTIN_COPYSIGN 1 #endif #if __has_builtin(__builtin_copysignl) #define __HAVE_BUILTIN_COPYSIGNL 1 #endif #if __has_builtin(__builtin_ctz) #define __HAVE_BUILTIN_CTZ 1 #endif #if __has_builtin(__builtin_ctzl) #define __HAVE_BUILTIN_CTZL 1 #endif #if __has_builtin(__builtin_ctzll) #define __HAVE_BUILTIN_CTZLL 1 #endif #if __has_builtin(__builtin_ffs) #define __HAVE_BUILTIN_FFS 1 #endif #if __has_builtin(__builtin_ffsl) #define __HAVE_BUILTIN_FFSL 1 #endif #if __has_builtin(__builtin_ffsll) #define __HAVE_BUILTIN_FFSLL 1 #endif #if __has_builtin(__builtin_finitel) #define __HAVE_BUILTIN_FINITEL 1 #endif #if __has_builtin(__builtin_isfinite) #define __HAVE_BUILTIN_ISFINITE 1 #endif #if __has_builtin(__builtin_isinf) #define __HAVE_BUILTIN_ISINF 1 #endif #if __has_builtin(__builtin_isinfl) #define __HAVE_BUILTIN_ISINFL 1 #endif #if __has_builtin(__builtin_isnan) #define __HAVE_BUILTIN_ISNAN 1 #endif #if __has_builtin(__builtin_isnanl) #define __HAVE_BUILTIN_ISNANL 1 #endif #if __has_builtin(__builtin_issignalingl) #define __HAVE_BUILTIN_ISSIGNALINGL 1 #endif #if __has_builtin(__builtin_mul_overflow) #define __HAVE_BUILTIN_MUL_OVERFLOW 1 #endif #if !__has_builtin(__builtin_expect) #define __builtin_expect(cond, exp) (cond) #endif #if !__has_builtin(__builtin_unreachable) #define __builtin_unreachable() #endif /* Alignment builtins for better type checking and improved code generation. */ /* Provide fallback versions for other compilers (GCC/Clang < 10): */ #if !__has_builtin(__builtin_is_aligned) #define __builtin_is_aligned(x, align) (((__uintptr_t)x & ((align) - 1)) == 0) #endif #if !__has_builtin(__builtin_align_up) #define __builtin_align_up(x, align) \ ((__typeof__(x))(((__uintptr_t)(x) + ((align) - 1)) & (~((align) - 1)))) #endif #if !__has_builtin(__builtin_align_down) #define __builtin_align_down(x, align) ((__typeof__(x))((x) & (~((align) - 1)))) #endif #define __align_up(x, y) __builtin_align_up(x, y) #define __align_down(x, y) __builtin_align_down(x, y) #define __is_aligned(x, y) __builtin_is_aligned(x, y) /* * When the address sanitizer is enabled, we must prevent the library * from even reading beyond the end of input data. This happens in * many optimized string functions. */ #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) #define _PICOLIBC_NO_OUT_OF_BOUNDS_READS #endif /* ISO C++. */ #ifdef __cplusplus #ifdef __HAVE_STD_CXX #define _BEGIN_STD_C \ namespace std { \ extern "C" { #define _END_STD_C \ } \ } #else #define _BEGIN_STD_C extern "C" { #define _END_STD_C } #endif #else #define _BEGIN_STD_C #define _END_STD_C #endif #if __GNUC_PREREQ(4, 2) || defined(__clang__) #define __GNUCLIKE_PRAGMA_DIAGNOSTIC 1 #endif #if defined(__cplusplus) #define __inline inline /* convert to C++ keyword */ #endif /* !__cplusplus */ /* * The __CONCAT macro is used to concatenate parts of symbol names, e.g. * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI * mode -- there must be no spaces between its arguments, and for nested * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also * concatenate double-quoted strings produced by the __STRING macro, but * this only works with ANSI C. * * __XSTRING is like __STRING, but it expands any macros in its argument * first. It is only available with ANSI C. */ #if defined(__STDC__) || defined(__cplusplus) #define __CONCAT1(x, y) x##y #define __CONCAT(x, y) __CONCAT1(x, y) #define __STRING(x) #x /* stringify without expanding x */ #else /* !(__STDC__ || __cplusplus) */ #define __CONCAT(x, y) x /**/ y #define __STRING(x) "x" #endif /* !(__STDC__ || __cplusplus) */ #define __XSTRING(x) __STRING(x) /* expand x, then stringify */ #if !__GNUC_PREREQ__(2, 95) #define __alignof(x) \ __offsetof( \ struct { \ char __a; \ x __b; \ }, \ __b) #endif /* * Keywords added in C11. */ #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L #if !__has_feature(c_alignas) #if (defined(__cplusplus) && __cplusplus >= 201103L) || __has_feature(cxx_alignas) #define _Alignas(x) alignas(x) #else /* XXX: Only emulates _Alignas(constant-expression); not _Alignas(type-name). */ #define _Alignas(x) __aligned(x) #endif #endif #if defined(__cplusplus) && __cplusplus >= 201103L #define _Alignof(x) alignof(x) #else #define _Alignof(x) __alignof(x) #endif #if !defined(__cplusplus) && !__has_feature(c_atomic) && !__has_feature(cxx_atomic) \ && !__GNUC_PREREQ__(4, 7) /* * No native support for _Atomic(). Place object in structure to prevent * most forms of direct non-atomic access. */ #define _Atomic(T) \ struct { \ T volatile __val; \ } #endif #if !__has_feature(c_static_assert) #if (defined(__cplusplus) && __cplusplus >= 201103L) || __has_feature(cxx_static_assert) #define _Static_assert(x, y) static_assert(x, y) #elif __GNUC_PREREQ__(4, 6) && !defined(__cplusplus) /* Nothing, gcc 4.6 and higher has _Static_assert built-in */ #elif defined(__COUNTER__) #define _Static_assert(x, y) __Static_assert(x, __COUNTER__) #define __Static_assert(x, y) ___Static_assert(x, y) #define ___Static_assert(x, y) typedef char __assert_##y[(x) ? 1 : -1] __unused #else #define _Static_assert(x, y) struct __hack #endif #endif #endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */ /* * Emulation of C11 _Generic(). Unlike the previously defined C11 * keywords, it is not possible to implement this using exactly the same * syntax. Therefore implement something similar under the name * __generic(). Unlike _Generic(), this macro can only distinguish * between a single type, so it requires nested invocations to * distinguish multiple cases. * * Note that the comma operator is used to force expr to decay in * order to match _Generic(). */ #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \ || __has_feature(c_generic_selections) #define __generic(expr, t, yes, no) _Generic(expr, t: yes, default: no) #elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus) #define __generic(expr, t, yes, no) \ __builtin_choose_expr(__builtin_types_compatible_p(__typeof((0, (expr))), t), yes, no) #endif /* * C99 Static array indices in function parameter declarations. Syntax such as: * void bar(int myArray[static 10]); * is allowed in C99 but not in C++. Define __min_size appropriately so * headers using it can be compiled in either language. Use like this: * void bar(int myArray[__min_size(10)]); */ #if !defined(__cplusplus) && (defined(__clang__) || __GNUC_PREREQ__(4, 6)) \ && (!defined(__STDC_VERSION__) || (__STDC_VERSION__ >= 199901)) #define __min_size(x) static(x) #else #define __min_size(x) (x) #endif /* XXX: should use `#if __STDC_VERSION__ < 199901'. */ #if !__GNUC_PREREQ__(2, 7) && !defined(__COMPCERT__) #define __func__ NULL #endif /* * We use `__restrict' as a way to define the `restrict' type qualifier * without disturbing older software that is unaware of C99 keywords. * GCC also provides `__restrict' as an extension to support C99-style * restricted pointers in other language modes. */ #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901 #define __restrict restrict #elif !__GNUC_PREREQ__(2, 95) #define __restrict #endif /* * Additionally, we allow to use `__restrict_arr' for declaring arrays as * non-overlapping per C99. It's not allowed in C++. */ #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L && !defined(__cplusplus) #define __restrict_arr restrict #else #define __restrict_arr #endif #define __offsetof(type, field) offsetof(type, field) #define __rangeof(type, start, end) (__offsetof(type, end) - __offsetof(type, start)) /* * Given the pointer x to the member m of the struct s, return * a pointer to the containing structure. When using GCC, we first * assign pointer x to a local variable, to check that its type is * compatible with member m. */ #if __GNUC_PREREQ__(3, 1) #define __containerof(x, s, m) \ ({ \ const volatile __typeof(((s *)0)->m) *__x = (x); \ ((s *)(uintptr_t)((const volatile char *)__x - __offsetof(s, m))); \ }) #else #define __containerof(x, s, m) ((s *)(uintptr_t)((const volatile char *)(x) - __offsetof(s, m))) #endif #if defined(__GNUC__) #ifndef __weak_reference #ifdef __ELF__ #ifdef __STDC__ #define __weak_reference(sym, alias) \ __asm__(".weak " #alias); \ __asm__(".equ " #alias ", " #sym) #else #define __weak_reference(sym, alias) \ __asm__(".weak alias"); \ __asm__(".equ alias, sym") #endif #elif __clang__ #ifdef __MACH__ /* Macos prefixes all C symbols with an underscore, this needs to be done manually in asm */ /* So far I have not been able to create on Macos an exported symbol that itself * is weak but aliases a strong symbol. A workaround is to make the original * symbol weak and the alias symbol will automatically become weak too. */ /* Hint: use `nm -m obj.o` to check the symbols weak/strong on Mac */ #define __weak_reference(sym, alias) \ __asm__(".weak_definition _" #sym); \ __asm__(".globl _" #alias); \ __asm__(".set _" #alias ", _" #sym) #elif defined(__STDC__) #define __weak_reference(sym, alias) \ __asm__(".weak_reference " #alias); \ __asm__(".globl " #alias); \ __asm__(".set " #alias ", " #sym) #else #define __weak_reference(sym, alias) \ __asm__(".weak_reference alias"); \ __asm__(".set alias, sym") #endif #else /* !__ELF__ && !__clang__ */ #ifdef __STDC__ #define __weak_reference(sym, alias) \ __asm__(".stabs \"_" #alias "\",11,0,0,0"); \ __asm__(".stabs \"_" #sym "\",1,0,0,0") #else #define __weak_reference(sym, alias) \ __asm__(".stabs \"_/**/alias\",11,0,0,0"); \ __asm__(".stabs \"_/**/sym\",1,0,0,0") #endif #endif #endif #endif /* __GNUC__ */ /* * fall-through case statement annotations */ #if __cplusplus >= 201703L || __STDC_VERSION__ > 201710L /* Standard C++17/C23 attribute */ #define __fallthrough [[fallthrough]] #elif __has_attribute(__fallthrough__) /* Non-standard but supported by at least gcc and clang */ #define __fallthrough __attribute__((__fallthrough__)) #else #define __fallthrough \ do { \ } while (0) #endif /* The traditional meaning of 'extern inline' for GCC is not to emit the function body unless the address is explicitly taken. However this behaviour is changing to match the C99 standard, which uses 'extern inline' to indicate that the function body *must* be emitted. Likewise, a function declared without either 'extern' or 'static' defaults to extern linkage (C99 6.2.2p5), and the compiler may choose whether to use the inline version or call the extern linkage version (6.7.4p6). If we are using GCC, but do not have the new behaviour, we need to use extern inline; if we are using a new GCC with the C99-compatible behaviour, or a non-GCC compiler (which we will have to hope is C99, since there is no other way to achieve the effect of omitting the function if it isn't referenced) we use 'static inline', which c99 defines to mean more-or-less the same as the Gnu C 'extern inline'. */ #if defined(__GNUC__) && !defined(__GNUC_STDC_INLINE__) /* We're using GCC, but without the new C99-compatible behaviour. */ #define __elidable_inline extern __always_inline #else /* We're using GCC in C99 mode, or an unknown compiler which we just have to hope obeys the C99 semantics of inline. */ #define __elidable_inline static __inline #endif #endif /* !_SYS_CDEFS_H_ */ picolibc-1.8.11/libc/include/sys/config.h000066400000000000000000000177421513574234600202030ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __SYS_CONFIG_H__ #define __SYS_CONFIG_H__ #include /* floating point macros */ #include /* POSIX defs */ #ifdef __aarch64__ #define MALLOC_ALIGNMENT 16 #endif /* exceptions first */ #if defined(__H8500__) || defined(__W65__) #define __SMALL_BITFIELDS /* ??? This conditional is true for the h8500 and the w65, defining H8300 in those cases probably isn't the right thing to do. */ #define H8300 1 #endif /* 16 bit integer machines */ #if defined(__Z8001__) || defined(__Z8002__) || defined(__H8500__) || defined(__W65__) \ || defined(__mn10200__) || defined(__AVR__) || defined(__MSP430__) #undef INT_MAX #undef UINT_MAX #define INT_MAX 32767 #define UINT_MAX 65535 #endif #if defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) #define __SMALL_BITFIELDS #define H8300 1 #undef INT_MAX #undef UINT_MAX #define INT_MAX __INT_MAX__ #define UINT_MAX (__INT_MAX__ * 2U + 1) #endif #if (defined(__CR16__) || defined(__CR16C__) || defined(__CR16CP__)) #ifndef __INT32__ #define __SMALL_BITFIELDS #undef INT_MAX #undef UINT_MAX #define INT_MAX 32767 #define UINT_MAX (__INT_MAX__ * 2U + 1) #else /* INT32 */ #undef INT_MAX #undef UINT_MAX #define INT_MAX 2147483647 #define UINT_MAX (__INT_MAX__ * 2U + 1) #endif /* INT32 */ #endif /* CR16C */ #if defined(__xc16x__) || defined(__xc16xL__) || defined(__xc16xS__) #define __SMALL_BITFIELDS #endif #ifdef __W65__ #define __SMALL_BITFIELDS #endif #if defined(__D10V__) #define __SMALL_BITFIELDS #undef INT_MAX #undef UINT_MAX #define INT_MAX __INT_MAX__ #define UINT_MAX (__INT_MAX__ * 2U + 1) #define _POINTER_INT short #endif #if defined(__mc68hc11__) || defined(__mc68hc12__) || defined(__mc68hc1x__) #undef INT_MAX #undef UINT_MAX #define INT_MAX __INT_MAX__ #define UINT_MAX (__INT_MAX__ * 2U + 1) #define _POINTER_INT short #endif #ifdef __i386__ #if defined(__linux__) || defined(__RDOS__) /* we want the reentrancy structure to be returned by a function */ #define HAVE_GETDATE #ifndef __LARGE64_FILES #define __LARGE64_FILES 1 #endif /* we use some glibc header files so turn on glibc large file feature */ #define _LARGEFILE64_SOURCE 1 #endif #endif #ifdef __mn10200__ #define __SMALL_BITFIELDS #endif #ifdef __AVR__ #define __SMALL_BITFIELDS #define _POINTER_INT short #endif #if defined(__MICROBLAZE__) && !defined(__rtems__) /* Xilinx XMK uses Unix98 mutex */ #ifdef __XMK__ #define _UNIX98_THREAD_MUTEX_ATTRIBUTES #endif #endif #ifdef __xstormy16__ #define __SMALL_BITFIELDS #undef INT_MAX #undef UINT_MAX #define INT_MAX __INT_MAX__ #define UINT_MAX (__INT_MAX__ * 2U + 1) #define MALLOC_ALIGNMENT 8 #define _POINTER_INT short #define __BUFSIZ__ 16 #endif #if defined __MSP430__ #define __BUFSIZ__ 256 #define __SMALL_BITFIELDS #ifdef __MSP430X_LARGE__ #define _POINTER_INT __int20 #else #define _POINTER_INT int #endif #endif #ifdef __m32c__ #define __SMALL_BITFIELDS #undef INT_MAX #undef UINT_MAX #define INT_MAX __INT_MAX__ #define UINT_MAX (__INT_MAX__ * 2U + 1) #define MALLOC_ALIGNMENT 8 #if defined(__r8c_cpu__) || defined(__m16c_cpu__) #define _POINTER_INT short #else #define _POINTER_INT long #endif #define __BUFSIZ__ 16 #endif /* __m32c__ */ #ifdef __SPU__ #define MALLOC_ALIGNMENT 16 #define __CUSTOM_FILE_IO__ #endif /* This block should be kept in sync with GCC's limits.h. The point of having these definitions here is to not include limits.h, which would pollute the user namespace, while still using types of the the correct widths when deciding how to define __int32_t and __int64_t. */ #ifndef __INT_MAX__ #ifdef INT_MAX #define __INT_MAX__ INT_MAX #else #define __INT_MAX__ 2147483647 #endif #endif #ifndef __LONG_MAX__ #ifdef LONG_MAX #define __LONG_MAX__ LONG_MAX #else #if defined(__alpha__) || (defined(__sparc__) && defined(__arch64__)) || defined(__sparcv9) #define __LONG_MAX__ 9223372036854775807L #else #define __LONG_MAX__ 2147483647L #endif /* __alpha__ || sparc64 */ #endif #endif /* End of block that should be kept in sync with GCC's limits.h. */ #ifndef _POINTER_INT #define _POINTER_INT long #endif #undef __RAND_MAX #if __INT_MAX__ == 32767 #define __RAND_MAX 32767 #else #define __RAND_MAX 0x7fffffff #endif #if defined(__rtems__) #define __FILENAME_MAX__ 255 #endif #ifndef __WCHAR_MAX__ #if __INT_MAX__ == 32767 || defined(_WIN32) #define __WCHAR_MAX__ 0xffffu #endif #endif #ifdef __THREAD_LOCAL_STORAGE #if (defined(__cplusplus) && (__cplusplus) >= 201103L) \ || (defined(__STDC_VERSION__) && (__STDC_VERSION__) >= 202311L) #define __THREAD_LOCAL thread_local #elif defined(__STDC_VERSION__) && (__STDC_VERSION__) >= 201112L #define __THREAD_LOCAL _Thread_local #else #define __THREAD_LOCAL __thread #endif #else #define __THREAD_LOCAL #endif #ifndef __MB_CAPABLE /* Make sure all of these are disabled if multi-byte is disabled*/ #undef __MB_EXTENDED_CHARSETS_ALL #undef __MB_EXTENDED_CHARSETS_ANY #undef __MB_EXTENDED_CHARSETS_UCS #undef __MB_EXTENDED_CHARSETS_ISO #undef __MB_EXTENDED_CHARSETS_WINDOWS #undef __MB_EXTENDED_CHARSETS_JIS #endif /* If __MB_EXTENDED_CHARSETS_ALL is set, we want all of the extended charsets. The extended charsets add a few functions and a couple of tables of a few K each. */ #ifdef __MB_EXTENDED_CHARSETS_ALL #define __MB_EXTENDED_CHARSETS_UCS 1 #define __MB_EXTENDED_CHARSETS_ISO 1 #define __MB_EXTENDED_CHARSETS_WINDOWS 1 #define __MB_EXTENDED_CHARSETS_JIS 1 #endif #if defined(__MB_EXTENDED_CHARSETS_ISO) || defined(__MB_EXTENDED_CHARSETS_WINDOWS) \ || defined(__MB_EXTENDED_CHARSETS_JIS) #define __MB_EXTENDED_CHARSETS_NON_UNICODE #endif #if defined(__MB_EXTENDED_CHARSETS_UCS) || defined(__MB_EXTENDED_CHARSETS_NON_UNICODE) #define __MB_EXTENDED_CHARSETS_ANY #endif /* Figure out if the compiler supports the long double type. */ #ifdef __SIZEOF_LONG_DOUBLE__ #define __HAVE_LONG_DOUBLE #endif /* Newlib doesn't fully support long double math functions so far. On platforms where long double equals double the long double functions simply call the double functions. On Cygwin the long double functions are implemented independently from newlib to be able to use optimized assembler functions despite using the Microsoft x86_64 ABI. */ #if defined(_LDBL_EQ_DBL) || defined(__CYGWIN__) \ || (defined(__HAVE_LONG_DOUBLE) && __SIZEOF_LONG_DOUBLE__ <= 8) \ || (__LDBL_MANT_DIG__ == 64 || __LDBL_MANT_DIG__ == 113) #define __HAVE_LONG_DOUBLE_MATH #endif #endif /* __SYS_CONFIG_H__ */ picolibc-1.8.11/libc/include/sys/custom_file.h000066400000000000000000000001571513574234600212370ustar00rootroot00000000000000/* Copyright (c) 2007 Jeff Johnston */ #error System-specific custom_file.h is missing. picolibc-1.8.11/libc/include/sys/dir.h000066400000000000000000000003531513574234600175020ustar00rootroot00000000000000/* Copyright (c) 2010 Yaakov Selkowitz */ /* BSD predecessor of POSIX.1 and struct dirent */ #ifndef _SYS_DIR_H_ #define _SYS_DIR_H_ #include #define direct dirent #endif /*_SYS_DIR_H_*/ picolibc-1.8.11/libc/include/sys/dirent.h000066400000000000000000000034551513574234600202170ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* includes , which is this file. On a system which supports , this file is overridden by dirent.h in the libc/sys/.../sys directory. On a system which does not support , we will get this file which uses #error to force an error. */ #error " not supported" picolibc-1.8.11/libc/include/sys/endian.h000066400000000000000000000122171513574234600201640ustar00rootroot00000000000000/*- * Copyright (c) 2002 Thomas Moestl * 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: head/sys/sys/endian.h 208331 2010-05-20 06:16:13Z phk $ */ #ifndef _SYS_ENDIAN_H_ #define _SYS_ENDIAN_H_ #include #include #include #ifndef _UINT8_T_DECLARED typedef __uint8_t uint8_t; #define _UINT8_T_DECLARED #endif #ifndef _UINT16_T_DECLARED typedef __uint16_t uint16_t; #define _UINT16_T_DECLARED #endif #ifndef _UINT32_T_DECLARED typedef __uint32_t uint32_t; #define _UINT32_T_DECLARED #endif #ifndef _UINT64_T_DECLARED typedef __uint64_t uint64_t; #define _UINT64_T_DECLARED #endif /* * General byte order swapping functions. */ #define bswap16(x) __bswap16(x) #define bswap32(x) __bswap32(x) #define bswap64(x) __bswap64(x) /* * Host to big endian, host to little endian, big endian to host, and little * endian to host byte order functions as detailed in byteorder(9). */ #if _BYTE_ORDER == _LITTLE_ENDIAN #define htobe16(x) bswap16((x)) #define htobe32(x) bswap32((x)) #define htobe64(x) bswap64((x)) #define htole16(x) ((uint16_t)(x)) #define htole32(x) ((uint32_t)(x)) #define htole64(x) ((uint64_t)(x)) #define be16toh(x) bswap16((x)) #define be32toh(x) bswap32((x)) #define be64toh(x) bswap64((x)) #define le16toh(x) ((uint16_t)(x)) #define le32toh(x) ((uint32_t)(x)) #define le64toh(x) ((uint64_t)(x)) #else /* _BYTE_ORDER != _LITTLE_ENDIAN */ #define htobe16(x) ((uint16_t)(x)) #define htobe32(x) ((uint32_t)(x)) #define htobe64(x) ((uint64_t)(x)) #define htole16(x) bswap16((x)) #define htole32(x) bswap32((x)) #define htole64(x) bswap64((x)) #define be16toh(x) ((uint16_t)(x)) #define be32toh(x) ((uint32_t)(x)) #define be64toh(x) ((uint64_t)(x)) #define le16toh(x) bswap16((x)) #define le32toh(x) bswap32((x)) #define le64toh(x) bswap64((x)) #endif /* _BYTE_ORDER == _LITTLE_ENDIAN */ /* Alignment-agnostic encode/decode bytestream to/from little/big endian. */ static __inline uint16_t be16dec(const void *pp) { uint8_t const *p = (uint8_t const *)pp; return (((unsigned)p[0] << 8) | p[1]); } static __inline uint32_t be32dec(const void *pp) { uint8_t const *p = (uint8_t const *)pp; return (((uint32_t)p[0] << 24) | ((uint32_t)p[1] << 16) | ((uint32_t)p[2] << 8) | p[3]); } static __inline uint64_t be64dec(const void *pp) { uint8_t const *p = (uint8_t const *)pp; return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4)); } static __inline uint16_t le16dec(const void *pp) { uint8_t const *p = (uint8_t const *)pp; return (((unsigned)p[1] << 8) | p[0]); } static __inline uint32_t le32dec(const void *pp) { uint8_t const *p = (uint8_t const *)pp; return (((uint32_t)p[3] << 24) | ((uint32_t)p[2] << 16) | ((uint32_t)p[1] << 8) | p[0]); } static __inline uint64_t le64dec(const void *pp) { uint8_t const *p = (uint8_t const *)pp; return (((uint64_t)le32dec(p + 4) << 32) | le32dec(p)); } static __inline void be16enc(void *pp, uint16_t u) { uint8_t *p = (uint8_t *)pp; p[0] = (u >> 8) & 0xff; p[1] = u & 0xff; } static __inline void be32enc(void *pp, uint32_t u) { uint8_t *p = (uint8_t *)pp; p[0] = (u >> 24) & 0xff; p[1] = (u >> 16) & 0xff; p[2] = (u >> 8) & 0xff; p[3] = u & 0xff; } static __inline void be64enc(void *pp, uint64_t u) { uint8_t *p = (uint8_t *)pp; be32enc(p, (uint32_t)(u >> 32)); be32enc(p + 4, (uint32_t)(u & 0xffffffffU)); } static __inline void le16enc(void *pp, uint16_t u) { uint8_t *p = (uint8_t *)pp; p[0] = u & 0xff; p[1] = (u >> 8) & 0xff; } static __inline void le32enc(void *pp, uint32_t u) { uint8_t *p = (uint8_t *)pp; p[0] = u & 0xff; p[1] = (u >> 8) & 0xff; p[2] = (u >> 16) & 0xff; p[3] = (u >> 24) & 0xff; } static __inline void le64enc(void *pp, uint64_t u) { uint8_t *p = (uint8_t *)pp; le32enc(p, (uint32_t)(u & 0xffffffffU)); le32enc(p + 4, (uint32_t)(u >> 32)); } #endif /* _SYS_ENDIAN_H_ */ picolibc-1.8.11/libc/include/sys/errno.h000066400000000000000000000232441513574234600200550ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* errno is not a global variable, because that would make using it non-reentrant. Instead, its address is returned by the function __errno. */ #ifndef _SYS_ERRNO_H_ #define _SYS_ERRNO_H_ #include _BEGIN_STD_C #if __GNU_VISIBLE char *_user_strerror(int errnum, int internal, int *errptr); #endif #ifdef __GLOBAL_ERRNO #define __THREAD_LOCAL_ERRNO #else #define __THREAD_LOCAL_ERRNO __THREAD_LOCAL #endif #ifdef __PICOLIBC_ERRNO_FUNCTION int *__PICOLIBC_ERRNO_FUNCTION(void); #define errno (*__PICOLIBC_ERRNO_FUNCTION()) #else extern __THREAD_LOCAL_ERRNO int errno; #define errno errno #endif #define EPERM 1 /* Not owner */ #define ENOENT 2 /* No such file or directory */ #define ESRCH 3 /* No such process */ #define EINTR 4 /* Interrupted system call */ #define EIO 5 /* I/O error */ #define ENXIO 6 /* No such device or address */ #define E2BIG 7 /* Arg list too long */ #define ENOEXEC 8 /* Exec format error */ #define EBADF 9 /* Bad file number */ #define ECHILD 10 /* No children */ #define EAGAIN 11 /* No more processes */ #define ENOMEM 12 /* Not enough space */ #define EACCES 13 /* Permission denied */ #define EFAULT 14 /* Bad address */ #define ENOTBLK 15 /* Block device required */ #define EBUSY 16 /* Device or resource busy */ #define EEXIST 17 /* File exists */ #define EXDEV 18 /* Cross-device link */ #define ENODEV 19 /* No such device */ #define ENOTDIR 20 /* Not a directory */ #define EISDIR 21 /* Is a directory */ #define EINVAL 22 /* Invalid argument */ #define ENFILE 23 /* Too many open files in system */ #define EMFILE 24 /* File descriptor value too large */ #define ENOTTY 25 /* Not a character device */ #define ETXTBSY 26 /* Text file busy */ #define EFBIG 27 /* File too large */ #define ENOSPC 28 /* No space left on device */ #define ESPIPE 29 /* Illegal seek */ #define EROFS 30 /* Read-only file system */ #define EMLINK 31 /* Too many links */ #define EPIPE 32 /* Broken pipe */ #define EDOM 33 /* Mathematics argument out of domain of function */ #define ERANGE 34 /* Result too large */ #define ENOMSG 35 /* No message of desired type */ #define EIDRM 36 /* Identifier removed */ #define ECHRNG 37 /* Channel number out of range */ #define EL2NSYNC 38 /* Level 2 not synchronized */ #define EL3HLT 39 /* Level 3 halted */ #define EL3RST 40 /* Level 3 reset */ #define ELNRNG 41 /* Link number out of range */ #define EUNATCH 42 /* Protocol driver not attached */ #define ENOCSI 43 /* No CSI structure available */ #define EL2HLT 44 /* Level 2 halted */ #define EDEADLK 45 /* Deadlock */ #define ENOLCK 46 /* No lock */ #define EBADE 50 /* Invalid exchange */ #define EBADR 51 /* Invalid request descriptor */ #define EXFULL 52 /* Exchange full */ #define ENOANO 53 /* No anode */ #define EBADRQC 54 /* Invalid request code */ #define EBADSLT 55 /* Invalid slot */ #define EDEADLOCK 56 /* File locking deadlock error */ #define EBFONT 57 /* Bad font file fmt */ #define ENOSTR 60 /* Not a stream */ #define ENODATA 61 /* No data (for no delay io) */ #define ETIME 62 /* Stream ioctl timeout */ #define ENOSR 63 /* No stream resources */ #define ENONET 64 /* Machine is not on the network */ #define ENOPKG 65 /* Package not installed */ #define EREMOTE 66 /* The object is remote */ #define ENOLINK 67 /* Virtual circuit is gone */ #define EADV 68 /* Advertise error */ #define ESRMNT 69 /* Srmount error */ #define ECOMM 70 /* Communication error on send */ #define EPROTO 71 /* Protocol error */ #define EMULTIHOP 74 /* Multihop attempted */ #define ELBIN 75 /* Inode is remote (not really error) */ #define EDOTDOT 76 /* Cross mount point (not really error) */ #define EBADMSG 77 /* Bad message */ #define EFTYPE 79 /* Inappropriate file type or format */ #define ENOTUNIQ 80 /* Given log. name not unique */ #define EBADFD 81 /* File descriptor in bad state */ #define EREMCHG 82 /* Remote address changed */ #define ELIBACC 83 /* Can't access a needed shared lib */ #define ELIBBAD 84 /* Accessing a corrupted shared lib */ #define ELIBSCN 85 /* .lib section in a.out corrupted */ #define ELIBMAX 86 /* Attempting to link in too many libs */ #define ELIBEXEC 87 /* Attempting to exec a shared library */ #define ENOSYS 88 /* Function not implemented */ #define ENOTEMPTY 90 /* Directory not empty */ #define ENAMETOOLONG 91 /* File or path name too long */ #define ELOOP 92 /* Too many symbolic links */ #define EOPNOTSUPP 95 /* Operation not supported on socket */ #define EPFNOSUPPORT 96 /* Protocol family not supported */ #define ECONNRESET 104 /* Connection reset by peer */ #define ENOBUFS 105 /* No buffer space available */ #define EAFNOSUPPORT 106 /* Address family not supported by protocol family */ #define EPROTOTYPE 107 /* Protocol wrong type for socket */ #define ENOTSOCK 108 /* Socket operation on non-socket */ #define ENOPROTOOPT 109 /* Protocol not available */ #define ESHUTDOWN 110 /* Can't send after socket shutdown */ #define ECONNREFUSED 111 /* Connection refused */ #define EADDRINUSE 112 /* Address already in use */ #define ECONNABORTED 113 /* Software caused connection abort */ #define ENETUNREACH 114 /* Network is unreachable */ #define ENETDOWN 115 /* Network interface is not configured */ #define ETIMEDOUT 116 /* Connection timed out */ #define EHOSTDOWN 117 /* Host is down */ #define EHOSTUNREACH 118 /* Host is unreachable */ #define EINPROGRESS 119 /* Connection already in progress */ #define EALREADY 120 /* Socket already connected */ #define EDESTADDRREQ 121 /* Destination address required */ #define EMSGSIZE 122 /* Message too long */ #define EPROTONOSUPPORT 123 /* Unknown protocol */ #define ESOCKTNOSUPPORT 124 /* Socket type not supported */ #define EADDRNOTAVAIL 125 /* Address not available */ #define ENETRESET 126 /* Connection aborted by network */ #define EISCONN 127 /* Socket is already connected */ #define ENOTCONN 128 /* Socket is not connected */ #define ETOOMANYREFS 129 /* Too many references: cannot splice */ #define EPROCLIM 130 /* Too many processes */ #define EUSERS 131 /* Too many users */ #define EDQUOT 132 /* Reserved */ #define ESTALE 133 /* Reserved */ #define ENOTSUP 134 /* Not supported */ #define ENOMEDIUM 135 /* No medium found */ #define EILSEQ 138 /* Illegal byte sequence */ #define EOVERFLOW 139 /* Value too large for defined data type */ #define ECANCELED 140 /* Operation canceled */ #define ENOTRECOVERABLE 141 /* State not recoverable */ #define EOWNERDEAD 142 /* Previous owner died */ #define ESTRPIPE 143 /* Streams pipe error */ #define EHWPOISON 144 /* Memory page has hardware error */ #define EISNAM 145 /* Is a named type file */ #define EKEYEXPIRED 146 /* Key has expired */ #define EKEYREJECTED 147 /* Key was rejected by service */ #define EKEYREVOKED 148 /* Key has been revoked */ #define EWOULDBLOCK EAGAIN /* Operation would block */ #define __ELASTERROR 2000 /* Users can add values starting here */ _END_STD_C #endif /* _SYS_ERRNO_H */ picolibc-1.8.11/libc/include/sys/fcntl.h000066400000000000000000000030701513574234600200310ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SYS_FCNTL_H_ #define _SYS_FCNTL_H_ #include #endif picolibc-1.8.11/libc/include/sys/features.h000066400000000000000000000331021513574234600205400ustar00rootroot00000000000000/* * Written by Joel Sherrill . * * COPYRIGHT (c) 1989-2014. * * On-Line Applications Research Corporation (OAR). * * Permission to use, copy, modify, and distribute this software for any * purpose without fee is hereby granted, provided that this entire notice * is included in all copies of any software which is or includes a copy * or modification of this software. * * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED * WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION * OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS * SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. * * $Id$ */ #ifndef _SYS_FEATURES_H #define _SYS_FEATURES_H #ifdef __cplusplus extern "C" { #endif #include /* Macro to test version of GCC. Returns 0 for non-GCC or too old GCC. */ #ifndef __GNUC_PREREQ #if defined __GNUC__ && defined __GNUC_MINOR__ #define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) #else #define __GNUC_PREREQ(maj, min) 0 #endif #endif /* __GNUC_PREREQ */ /* Version with trailing underscores for BSD compatibility. */ #define __GNUC_PREREQ__(ma, mi) __GNUC_PREREQ(ma, mi) /* * Feature test macros control which symbols are exposed by the system * headers. Any of these must be defined before including any headers. * * __STRICT_ANSI__ (defined by gcc -ansi, -std=c90, -std=c99, or -std=c11) * ISO C * * _POSIX_SOURCE (deprecated by _POSIX_C_SOURCE=1) * _POSIX_C_SOURCE >= 1 * POSIX.1-1990 * * _POSIX_C_SOURCE >= 2 * POSIX.2-1992 * * _POSIX_C_SOURCE >= 199309L * POSIX.1b-1993 Real-time extensions * * _POSIX_C_SOURCE >= 199506L * POSIX.1c-1995 Threads extensions * * _POSIX_C_SOURCE >= 200112L * POSIX.1-2001 and C99 * * _POSIX_C_SOURCE >= 200809L * POSIX.1-2008 * * _POSIX_C_SOURCE >= 202405L * POSIX.1-2024 * * _XOPEN_SOURCE * POSIX.1-1990 and XPG4 * * _XOPEN_SOURCE_EXTENDED * SUSv1 (POSIX.2-1992 plus XPG4v2) * * _XOPEN_SOURCE >= 500 * SUSv2 (POSIX.1c-1995 plus XSI) * * _XOPEN_SOURCE >= 600 * SUSv3 (POSIX.1-2001 plus XSI) and C99 * * _XOPEN_SOURCE >= 700 * SUSv4 (POSIX.1-2008 plus XSI) * * _ISOC99_SOURCE or gcc -std=c99 or g++ * ISO C99 * * _ISOC11_SOURCE or gcc -std=c11 or g++ -std=c++11 * ISO C11 * * _ISOC23_SOURCE or _ISOC2X_SOURCE or gcc -std=c23 or g++ -std=c++20 * ISO C23 * * _ISOC23_SOURCE or gcc -std=c2x or -std=c2x or g++ -std=c++20 * ISO C23 * * _ATFILE_SOURCE (implied by _POSIX_C_SOURCE >= 200809L) * "at" functions * * _LARGEFILE_SOURCE (deprecated by _XOPEN_SOURCE >= 500) * fseeko, ftello * * _GNU_SOURCE * All of the above plus GNU extensions * * _BSD_SOURCE (deprecated by _DEFAULT_SOURCE) * _SVID_SOURCE (deprecated by _DEFAULT_SOURCE) * _DEFAULT_SOURCE (or none of the above) * POSIX-1.2024 with BSD and SVr4 extensions * * _FORTIFY_SOURCE = 1, 2 or 3 * Object Size Checking function wrappers * * _ZEPHYR_SOURCE * Zephyr. ISO C + a small selection of other APIs. */ /* Remap the old name _ISOC2X_SOURCE to _ISOC23_SOURCE. */ #ifdef _ISOC2X_SOURCE #undef _ISOC2X_SOURCE #undef _ISOC23_SOURCE #define _ISOC23_SOURCE 1 #endif #ifdef _GNU_SOURCE #undef _ATFILE_SOURCE #define _ATFILE_SOURCE 1 #undef _DEFAULT_SOURCE #define _DEFAULT_SOURCE 1 #undef _ISOC99_SOURCE #define _ISOC99_SOURCE 1 #undef _ISOC11_SOURCE #define _ISOC11_SOURCE 1 #undef _ISOC23_SOURCE #define _ISOC23_SOURCE 1 #undef _POSIX_SOURCE #define _POSIX_SOURCE 1 #undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200809L #undef _XOPEN_SOURCE #define _XOPEN_SOURCE 700 #undef _XOPEN_SOURCE_EXTENDED #define _XOPEN_SOURCE_EXTENDED 1 #undef _LARGEFILE64_SOURCE #define _LARGEFILE64_SOURCE 1 #endif /* _GNU_SOURCE */ /* When building for Zephyr, set _ZEPHYR_SOURCE unless some other API * indicator is set by the application. Don't check __STRICT_ANSI__ as that * is set by the compiler for -std=cxx, or _POSIX_C_SOURCE as Zephyr defines * that for picolibc currently. */ #if defined(__ZEPHYR__) && !defined(_ZEPHYR_SOURCE) && !defined(_GNU_SOURCE) \ && !defined(_BSD_SOURCE) && !defined(_SVID_SOURCE) && !defined(_DEFAULT_SOURCE) #define _ZEPHYR_SOURCE 1 #endif #if defined(_BSD_SOURCE) || defined(_SVID_SOURCE) \ || (!defined(__STRICT_ANSI__) && !defined(_ANSI_SOURCE) && !defined(_ISOC99_SOURCE) \ && !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) \ && !defined(_ZEPHYR_SOURCE)) #undef _DEFAULT_SOURCE #define _DEFAULT_SOURCE 1 #endif #if defined(_DEFAULT_SOURCE) #undef _POSIX_SOURCE #define _POSIX_SOURCE 1 #undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 202405L #endif #if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) \ && ((!defined(__STRICT_ANSI__) && !defined(_ANSI_SOURCE)) || (_XOPEN_SOURCE - 0) >= 500) #define _POSIX_SOURCE 1 #if !defined(_XOPEN_SOURCE) || (_XOPEN_SOURCE - 0) >= 700 #define _POSIX_C_SOURCE 200809L #elif (_XOPEN_SOURCE - 0) >= 600 #define _POSIX_C_SOURCE 200112L #elif (_XOPEN_SOURCE - 0) >= 500 #define _POSIX_C_SOURCE 199506L #elif (_XOPEN_SOURCE - 0) < 500 #define _POSIX_C_SOURCE 2 #endif #endif #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809 #undef _ATFILE_SOURCE #define _ATFILE_SOURCE 1 #endif #ifdef _ZEPHYR_SOURCE #undef _ISOC99_SOURCE #define _ISOC99_SOURCE 1 #undef _ISOC11_SOURCE #define _ISOC11_SOURCE 1 #undef _ANSI_SOURCE #define _ANSI_SOURCE 1 #endif /* * The following private macros are used throughout the headers to control * which symbols should be exposed. They are for internal use only, as * indicated by the leading double underscore, and must never be used outside * of these headers. * * __POSIX_VISIBLE * any version of POSIX.1; enabled by default, or with _POSIX_SOURCE, * any value of _POSIX_C_SOURCE, or _XOPEN_SOURCE >= 500. * * __POSIX_VISIBLE >= 2 * POSIX.2-1992; enabled by default, with _POSIX_C_SOURCE >= 2, * or _XOPEN_SOURCE >= 500. * * __POSIX_VISIBLE >= 199309 * POSIX.1b-1993; enabled by default, with _POSIX_C_SOURCE >= 199309L, * or _XOPEN_SOURCE >= 500. * * __POSIX_VISIBLE >= 199506 * POSIX.1c-1995; enabled by default, with _POSIX_C_SOURCE >= 199506L, * or _XOPEN_SOURCE >= 500. * * __POSIX_VISIBLE >= 200112 * POSIX.1-2001; enabled by default, with _POSIX_C_SOURCE >= 200112L, * or _XOPEN_SOURCE >= 600. * * __POSIX_VISIBLE >= 200809 * POSIX.1-2008; enabled by default, with _POSIX_C_SOURCE >= 200809L, * or _XOPEN_SOURCE >= 700. * * __POSIX_VISIBLE >= 202405 * POSIX.1-2024; enabled by default, with _POSIX_C_SOURCE >= 202405L, * or _XOPEN_SOURCE >= 700. * * __XSI_VISIBLE * XPG4 XSI extensions; enabled with any version of _XOPEN_SOURCE. * * __XSI_VISIBLE >= 4 * SUSv1 XSI extensions; enabled with both _XOPEN_SOURCE and * _XOPEN_SOURCE_EXTENDED together. * * __XSI_VISIBLE >= 500 * SUSv2 XSI extensions; enabled with _XOPEN_SOURCE >= 500. * * __XSI_VISIBLE >= 600 * SUSv3 XSI extensions; enabled with _XOPEN_SOURCE >= 600. * * __XSI_VISIBLE >= 700 * SUSv4 XSI extensions; enabled with _XOPEN_SOURCE >= 700. * * __ISO_C_VISIBLE >= 1999 * ISO C99; enabled with gcc -std=c99 or newer (on by default since GCC 5), * any version of C++, or with _ISOC99_SOURCE, _POSIX_C_SOURCE >= 200112L, * or _XOPEN_SOURCE >= 600. * * __ISO_C_VISIBLE >= 2011 * ISO C11; enabled with gcc -std=c11 or newer (on by default since GCC 5), * g++ -std=c++11 or newer (on by default since GCC 6), or with * _ISOC11_SOURCE. * * __ISO_C_VISIBLE >= 2020 * ISO C23; enabled with gcc -std=c23 or newer, * g++ -std=c++20 or newer, or with * _ISOC23_SOURCE or _ISOC2x_SOURCE. * * __ATFILE_VISIBLE * "at" functions; enabled by default, with _ATFILE_SOURCE, * _POSIX_C_SOURCE >= 200809L, or _XOPEN_SOURCE >= 700. * * __LARGEFILE_VISIBLE * fseeko, ftello; enabled with _LARGEFILE_SOURCE or _XOPEN_SOURCE >= 500. * * __LARGEFILE64_VISIBLE * additional large file extensions; enabled with _LARGEFILE64_SOURCE. * * __BSD_VISIBLE * BSD extensions; enabled by default, or with _BSD_SOURCE. * * __SVID_VISIBLE * SVr4 extensions; enabled by default, or with _SVID_SOURCE. * * __MISC_VISIBLE * Extensions found in both BSD and SVr4 (shorthand for * (__BSD_VISIBLE || __SVID_VISIBLE)), or newlib-specific * extensions; enabled by default. * * __GNU_VISIBLE * GNU extensions; enabled with _GNU_SOURCE. * * __SSP_FORTIFY_LEVEL * Object Size Checking; defined to 0 (off), 1, 2 or 3. * * __ZEPHYR_VISIBLE * Zephyr extensions; enabled with _ZEPHYR_SOURCE. * * In all cases above, "enabled by default" means either by defining * _DEFAULT_SOURCE, or by not defining any of the public feature test macros. */ #ifdef _ATFILE_SOURCE #define __ATFILE_VISIBLE 1 #else #define __ATFILE_VISIBLE 0 #endif #ifdef _DEFAULT_SOURCE #define __BSD_VISIBLE 1 #else #define __BSD_VISIBLE 0 #endif #ifdef _GNU_SOURCE #define __GNU_VISIBLE 1 #else #define __GNU_VISIBLE 0 #endif #ifdef _ZEPHYR_SOURCE #define __ZEPHYR_VISIBLE 1 #else #define __ZEPHYR_VISIBLE 0 #endif #ifdef _ISOC2X_SOURCE #undef _ISOC2X_SOURCE #undef _ISOC23_SOURCE #define _ISOC23_SOURCE 1 #endif #if defined(_ISOC23_SOURCE) || (__STDC_VERSION__ - 0) > 201710L || (__cplusplus - 0) >= 202002L #define __ISO_C_VISIBLE 2023 #elif defined(_ISOC11_SOURCE) || (__STDC_VERSION__ - 0) >= 201112L || (__cplusplus - 0) >= 201103L #define __ISO_C_VISIBLE 2011 #elif defined(_ISOC99_SOURCE) || (_POSIX_C_SOURCE - 0) >= 200112L \ || (__STDC_VERSION__ - 0) >= 199901L || defined(__cplusplus) #define __ISO_C_VISIBLE 1999 #else #define __ISO_C_VISIBLE 1990 #endif #if defined(_LARGEFILE_SOURCE) || (_XOPEN_SOURCE - 0) >= 500 #define __LARGEFILE_VISIBLE 1 #else #define __LARGEFILE_VISIBLE 0 #endif #ifdef _LARGEFILE64_SOURCE #define __LARGEFILE64_VISIBLE 1 #else #define __LARGEFILE64_VISIBLE 0 #endif #ifdef _DEFAULT_SOURCE #define __MISC_VISIBLE 1 #else #define __MISC_VISIBLE 0 #endif #if (_POSIX_C_SOURCE - 0) >= 202405L #define __POSIX_VISIBLE 202405 #elif (_POSIX_C_SOURCE - 0) >= 200809L #define __POSIX_VISIBLE 200809 #elif (_POSIX_C_SOURCE - 0) >= 200112L #define __POSIX_VISIBLE 200112 #elif (_POSIX_C_SOURCE - 0) >= 199506L #define __POSIX_VISIBLE 199506 #elif (_POSIX_C_SOURCE - 0) >= 199309L #define __POSIX_VISIBLE 199309 #elif (_POSIX_C_SOURCE - 0) >= 2 || defined(_XOPEN_SOURCE) #define __POSIX_VISIBLE 199209 #elif defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) #define __POSIX_VISIBLE 199009 #else #define __POSIX_VISIBLE 0 #endif #ifdef _DEFAULT_SOURCE #define __SVID_VISIBLE 1 #else #define __SVID_VISIBLE 0 #endif #if (_XOPEN_SOURCE - 0) >= 700 #define __XSI_VISIBLE 700 #elif (_XOPEN_SOURCE - 0) >= 600 #define __XSI_VISIBLE 600 #elif (_XOPEN_SOURCE - 0) >= 500 #define __XSI_VISIBLE 500 #elif defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED) #define __XSI_VISIBLE 4 #elif defined(_XOPEN_SOURCE) #define __XSI_VISIBLE 1 #else #define __XSI_VISIBLE 0 #endif #if _FORTIFY_SOURCE > 0 && !defined(__cplusplus) && !defined(__lint__) \ && (__OPTIMIZE__ > 0 || defined(__clang__)) && __GNUC_PREREQ__(4, 1) && !defined(_LIBC) #if _FORTIFY_SOURCE > 2 && defined(__has_builtin) #if __has_builtin(__builtin_dynamic_object_size) #define __SSP_FORTIFY_LEVEL 3 #else #define __SSP_FORTIFY_LEVEL 2 #endif #elif _FORTIFY_SOURCE > 1 #define __SSP_FORTIFY_LEVEL 2 #else #define __SSP_FORTIFY_LEVEL 1 #endif #else #define __SSP_FORTIFY_LEVEL 0 #endif /* RTEMS adheres to POSIX -- 1003.1b with some features from annexes. */ #ifdef __rtems__ #define _POSIX_JOB_CONTROL 1 #define _POSIX_SAVED_IDS 1 #define _POSIX_VERSION 199309L #define _POSIX_ASYNCHRONOUS_IO 1 #define _POSIX_FSYNC 1 #define _POSIX_MAPPED_FILES 1 #define _POSIX_MEMLOCK 1 #define _POSIX_MEMLOCK_RANGE 1 #define _POSIX_MEMORY_PROTECTION 1 #define _POSIX_MESSAGE_PASSING 1 #define _POSIX_MONOTONIC_CLOCK 200112L #define _POSIX_CLOCK_SELECTION 200112L #define _POSIX_PRIORITIZED_IO 1 #define _POSIX_PRIORITY_SCHEDULING 1 #define _POSIX_REALTIME_SIGNALS 1 #define _POSIX_SEMAPHORES 1 #define _POSIX_SHARED_MEMORY_OBJECTS 1 #define _POSIX_SYNCHRONIZED_IO 1 #define _POSIX_TIMERS 1 #define _POSIX_BARRIERS 200112L #define _POSIX_READER_WRITER_LOCKS 200112L #define _POSIX_SPIN_LOCKS 200112L /* In P1003.1b but defined by drafts at least as early as P1003.1c/D10 */ #define _POSIX_THREADS 1 #define _POSIX_THREAD_ATTR_STACKADDR 1 #define _POSIX_THREAD_ATTR_STACKSIZE 1 #define _POSIX_THREAD_PRIORITY_SCHEDULING 1 #define _POSIX_THREAD_PRIO_INHERIT 1 #define _POSIX_THREAD_PRIO_PROTECT 1 #define _POSIX_THREAD_PROCESS_SHARED 1 #define _POSIX_THREAD_SAFE_FUNCTIONS 1 /* P1003.4b/D8 defines the constants below this comment. */ #define _POSIX_SPAWN 1 #define _POSIX_TIMEOUTS 1 #define _POSIX_CPUTIME 1 #define _POSIX_THREAD_CPUTIME 1 #define _POSIX_SPORADIC_SERVER 1 #define _POSIX_THREAD_SPORADIC_SERVER 1 #define _POSIX_DEVICE_CONTROL 1 #define _POSIX_DEVCTL_DIRECTION 1 #define _POSIX_INTERRUPT_CONTROL 1 #define _POSIX_ADVISORY_INFO 1 /* UNIX98 added some new pthread mutex attributes */ #define _UNIX98_THREAD_MUTEX_ATTRIBUTES 1 /* POSIX 1003.26-2003 defined device control method */ #define _POSIX_26_VERSION 200312L #endif /* XMK loosely adheres to POSIX -- 1003.1 */ #ifdef __XMK__ #define _POSIX_THREADS 1 #define _POSIX_THREAD_PRIORITY_SCHEDULING 1 #endif #ifdef __svr4__ #define _POSIX_JOB_CONTROL 1 #define _POSIX_SAVED_IDS 1 #define _POSIX_VERSION 199009L #endif #ifdef __cplusplus } #endif #endif /* _SYS_FEATURES_H */ picolibc-1.8.11/libc/include/sys/file.h000066400000000000000000000027751513574234600176550ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include picolibc-1.8.11/libc/include/sys/iconvnls.h000066400000000000000000000050571513574234600205650ustar00rootroot00000000000000/* * Copyright (c) 2003-2004, Artem B. Bityuckiy. * Rights transferred to Franklin Electronic Publishers. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must 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. */ /* * Funtions, macros, etc implimented in iconv library but used by other * NLS-related subsystems too. */ #ifndef __SYS_ICONVNLS_H__ #define __SYS_ICONVNLS_H__ #include #include #include /* Iconv data path environment variable name */ #define NLS_ENVVAR_NAME "NLSPATH" /* Default NLSPATH value */ #ifndef ICONV_DEFAULT_NLSPATH #define ICONV_DEFAULT_NLSPATH "/usr/locale" #endif /* Direction markers */ #define ICONV_NLS_FROM 0 #define ICONV_NLS_TO 1 void _iconv_nls_get_state(iconv_t cd, mbstate_t *ps, int direction); int _iconv_nls_set_state(iconv_t cd, mbstate_t *ps, int direction); int _iconv_nls_is_stateful(iconv_t cd, int direction); int _iconv_nls_get_mb_cur_max(iconv_t cd, int direction); size_t _iconv_nls_conv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); const char *_iconv_nls_construct_filename(const char *file, const char *dir, const char *ext); int _iconv_nls_open(const char *encoding, iconv_t *towc, iconv_t *fromwc, int flag); char *_iconv_resolve_encoding_name(const char *ca); #endif /* __SYS_ICONVNLS_H__ */ picolibc-1.8.11/libc/include/sys/lock.h000066400000000000000000000044141513574234600176560ustar00rootroot00000000000000/* Copyright (c) 2002 Jeff Johnston */ #ifndef __SYS_LOCK_H__ #define __SYS_LOCK_H__ #include #ifdef __SINGLE_THREAD /* dummy lock routines for single-threaded aps */ #define __LOCK_INIT(lock) #define __LOCK_INIT_RECURSIVE(lock) #define __lock_init(lock) ((void)0) #define __lock_init_recursive(lock) ((void)0) #define __lock_close(lock) ((void)0) #define __lock_close_recursive(lock) ((void)0) #define __lock_acquire(lock) ((void)0) #define __lock_acquire_recursive(lock) ((void)0) #define __lock_release(lock) ((void)0) #define __lock_release_recursive(lock) ((void)0) #else _BEGIN_STD_C struct __lock; typedef struct __lock *_LOCK_T; #define _LOCK_RECURSIVE_T _LOCK_T #define __LOCK_INIT(lock) extern struct __lock __lock_##lock; #define __LOCK_INIT_RECURSIVE(lock) __LOCK_INIT(lock) void __retarget_lock_init(_LOCK_T *lock); void __retarget_lock_init_recursive(_LOCK_T *lock); void __retarget_lock_close(_LOCK_T lock); void __retarget_lock_close_recursive(_LOCK_T lock); void __retarget_lock_acquire(_LOCK_T lock); void __retarget_lock_acquire_recursive(_LOCK_T lock); void __retarget_lock_release(_LOCK_T lock); void __retarget_lock_release_recursive(_LOCK_T lock); #define __lock_init(lock) __retarget_lock_init(&lock) #define __lock_init_recursive(lock) __retarget_lock_init_recursive(&lock) #define __lock_close(lock) __retarget_lock_close(lock) #define __lock_close_recursive(lock) __retarget_lock_close_recursive(lock) #define __lock_acquire(lock) __retarget_lock_acquire(lock) #define __lock_acquire_recursive(lock) __retarget_lock_acquire_recursive(lock) #define __lock_release(lock) __retarget_lock_release(lock) #define __lock_release_recursive(lock) __retarget_lock_release_recursive(lock) _END_STD_C #endif /* !defined(__SINGLE_THREAD) */ #define __LIBC_LOCK() __lock_acquire_recursive(&__lock___libc_recursive_mutex) #define __LIBC_UNLOCK() __lock_release_recursive(&__lock___libc_recursive_mutex) __LOCK_INIT_RECURSIVE(__libc_recursive_mutex) #endif /* __SYS_LOCK_H__ */ picolibc-1.8.11/libc/include/sys/meson.build000066400000000000000000000056601513574234600207230ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_sys_headers_all = [ 'auxv.h', 'cdefs.h', 'config.h', 'custom_file.h', '_default_fcntl.h', 'dirent.h', 'dir.h', 'errno.h', 'fcntl.h', 'features.h', 'file.h', 'iconvnls.h', '_initfini.h', '_intsup.h', '_locale.h', 'lock.h', 'param.h', 'queue.h', 'resource.h', 'sched.h', 'select.h', '_select.h', '_sigset.h', 'stat.h', '_stdint.h', 'string.h', 'syslimits.h', 'timeb.h', 'time.h', 'times.h', '_timespec.h', 'timespec.h', '_timeval.h', 'tree.h', '_types.h', 'types.h', '_tz_structs.h', 'unistd.h', 'utime.h', 'wait.h', '_wait.h' ] inc_sys_headers = [] foreach file : inc_sys_headers_all if not (file in inc_sys_headers_machine) inc_sys_headers += file else message('libc/include/sys/' + file + ': machine overrides generic') endif endforeach if really_install install_headers(inc_sys_headers, install_dir: include_dir / 'sys') endif if enable_cdefs_tests ignore_headers = ['config.h', 'features.h', 'string.h', 'custom_file.h', 'dirent.h'] foreach header : inc_sys_headers if not (header in ignore_headers) and not (header.startswith('_')) test_name = 'check-cdef-sys-' + header test(test_name, validate_cdefs, args: [meson.current_source_dir() / header] + cc.cmd_array() + c_args + inc_args, suite: 'headers') endif endforeach endif picolibc-1.8.11/libc/include/sys/param.h000066400000000000000000000042421513574234600200250ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This is a dummy file, not customized for any particular system. If there is a param.h in libc/sys/SYSDIR/sys, it will override this one. */ #ifndef _SYS_PARAM_H #define _SYS_PARAM_H #include #include #include #include #ifndef NBBY #define NBBY 8 /* number of bits in a byte */ #endif #ifndef HZ #define HZ (60) #endif #ifndef NOFILE #define NOFILE (60) #endif #ifndef PATHSIZE #define PATHSIZE (1024) #endif #define MAXPATHLEN PATH_MAX #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #ifndef howmany #define howmany(x, y) (((x) + ((y) - 1)) / (y)) #endif #endif picolibc-1.8.11/libc/include/sys/queue.h000066400000000000000000001215371513574234600200600ustar00rootroot00000000000000/*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)queue.h 8.5 (Berkeley) 8/20/94 * $FreeBSD$ */ #ifndef _SYS_QUEUE_H_ #define _SYS_QUEUE_H_ #include /* * This file defines four types of data structures: singly-linked lists, * singly-linked tail queues, lists and tail queues. * * A singly-linked list is headed by a single forward pointer. The elements * are singly linked for minimum space and pointer manipulation overhead at * the expense of O(n) removal for arbitrary elements. New elements can be * added to the list after an existing element or at the head of the list. * Elements being removed from the head of the list should use the explicit * macro for this purpose for optimum efficiency. A singly-linked list may * only be traversed in the forward direction. Singly-linked lists are ideal * for applications with large datasets and few or no removals or for * implementing a LIFO queue. * * A singly-linked tail queue is headed by a pair of pointers, one to the * head of the list and the other to the tail of the list. The elements are * singly linked for minimum space and pointer manipulation overhead at the * expense of O(n) removal for arbitrary elements. New elements can be added * to the list after an existing element, at the head of the list, or at the * end of the list. Elements being removed from the head of the tail queue * should use the explicit macro for this purpose for optimum efficiency. * A singly-linked tail queue may only be traversed in the forward direction. * Singly-linked tail queues are ideal for applications with large datasets * and few or no removals or for implementing a FIFO queue. * * A list is headed by a single forward pointer (or an array of forward * pointers for a hash table header). The elements are doubly linked * so that an arbitrary element can be removed without a need to * traverse the list. New elements can be added to the list before * or after an existing element or at the head of the list. A list * may be traversed in either direction. * * A tail queue is headed by a pair of pointers, one to the head of the * list and the other to the tail of the list. The elements are doubly * linked so that an arbitrary element can be removed without a need to * traverse the list. New elements can be added to the list before or * after an existing element, at the head of the list, or at the end of * the list. A tail queue may be traversed in either direction. * * For details on the use of these macros, see the queue(3) manual page. * * Below is a summary of implemented functions where: * + means the macro is available * - means the macro is not available * s means the macro is available but is slow (runs in O(n) time) * * SLIST LIST STAILQ TAILQ * _HEAD + + + + * _CLASS_HEAD + + + + * _HEAD_INITIALIZER + + + + * _ENTRY + + + + * _CLASS_ENTRY + + + + * _INIT + + + + * _EMPTY + + + + * _FIRST + + + + * _NEXT + + + + * _PREV - + - + * _LAST - - + + * _LAST_FAST - - - + * _FOREACH + + + + * _FOREACH_FROM + + + + * _FOREACH_SAFE + + + + * _FOREACH_FROM_SAFE + + + + * _FOREACH_REVERSE - - - + * _FOREACH_REVERSE_FROM - - - + * _FOREACH_REVERSE_SAFE - - - + * _FOREACH_REVERSE_FROM_SAFE - - - + * _INSERT_HEAD + + + + * _INSERT_BEFORE - + - + * _INSERT_AFTER + + + + * _INSERT_TAIL - - + + * _CONCAT s s + + * _REMOVE_AFTER + - + - * _REMOVE_HEAD + - + - * _REMOVE s + s + * _SWAP + + + + * */ #ifdef QUEUE_MACRO_DEBUG #warn Use QUEUE_MACRO_DEBUG_TRACE and / or QUEUE_MACRO_DEBUG_TRASH #define QUEUE_MACRO_DEBUG_TRACE #define QUEUE_MACRO_DEBUG_TRASH #endif #ifdef QUEUE_MACRO_DEBUG_TRACE /* Store the last 2 places the queue element or head was altered */ struct qm_trace { unsigned long lastline; unsigned long prevline; const char *lastfile; const char *prevfile; }; #define TRACEBUF struct qm_trace trace; #define TRACEBUF_INITIALIZER { __LINE__, 0, __FILE__, NULL }, #define QMD_TRACE_HEAD(head) \ do { \ (head)->trace.prevline = (head)->trace.lastline; \ (head)->trace.prevfile = (head)->trace.lastfile; \ (head)->trace.lastline = __LINE__; \ (head)->trace.lastfile = __FILE__; \ } while (0) #define QMD_TRACE_ELEM(elem) \ do { \ (elem)->trace.prevline = (elem)->trace.lastline; \ (elem)->trace.prevfile = (elem)->trace.lastfile; \ (elem)->trace.lastline = __LINE__; \ (elem)->trace.lastfile = __FILE__; \ } while (0) #else /* !QUEUE_MACRO_DEBUG_TRACE */ #define QMD_TRACE_ELEM(elem) #define QMD_TRACE_HEAD(head) #define TRACEBUF #define TRACEBUF_INITIALIZER #endif /* QUEUE_MACRO_DEBUG_TRACE */ #ifdef QUEUE_MACRO_DEBUG_TRASH #define TRASHIT(x) \ do { \ (x) = (void *)-1; \ } while (0) #define QMD_IS_TRASHED(x) ((x) == (void *)(intptr_t)-1) #else /* !QUEUE_MACRO_DEBUG_TRASH */ #define TRASHIT(x) #define QMD_IS_TRASHED(x) 0 #endif /* QUEUE_MACRO_DEBUG_TRASH */ #if defined(QUEUE_MACRO_DEBUG_TRACE) || defined(QUEUE_MACRO_DEBUG_TRASH) #define QMD_SAVELINK(name, link) void **name = (void *)&(link) #else /* !QUEUE_MACRO_DEBUG_TRACE && !QUEUE_MACRO_DEBUG_TRASH */ #define QMD_SAVELINK(name, link) #endif /* QUEUE_MACRO_DEBUG_TRACE || QUEUE_MACRO_DEBUG_TRASH */ #ifdef __cplusplus /* * In C++ there can be structure lists and class lists: */ #define QUEUE_TYPEOF(type) type #else #define QUEUE_TYPEOF(type) struct type #endif /* * Singly-linked List declarations. */ #define SLIST_HEAD(name, type) \ struct name { \ struct type *slh_first; /* first element */ \ } #define SLIST_CLASS_HEAD(name, type) \ struct name { \ class type *slh_first; /* first element */ \ } #define SLIST_HEAD_INITIALIZER(head) { NULL } #define SLIST_ENTRY(type) \ struct { \ struct type *sle_next; /* next element */ \ } #define SLIST_CLASS_ENTRY(type) \ struct { \ class type *sle_next; /* next element */ \ } /* * Singly-linked List functions. */ #if (defined(_KERNEL) && defined(INVARIANTS)) #define QMD_SLIST_CHECK_PREVPTR(prevp, elm) \ do { \ if (*(prevp) != (elm)) \ panic("Bad prevptr *(%p) == %p != %p", (prevp), *(prevp), (elm)); \ } while (0) #else #define QMD_SLIST_CHECK_PREVPTR(prevp, elm) #endif #define SLIST_CONCAT(head1, head2, type, field) \ do { \ QUEUE_TYPEOF(type) *curelm = SLIST_FIRST(head1); \ if (curelm == NULL) { \ if ((SLIST_FIRST(head1) = SLIST_FIRST(head2)) != NULL) \ SLIST_INIT(head2); \ } else if (SLIST_FIRST(head2) != NULL) { \ while (SLIST_NEXT(curelm, field) != NULL) \ curelm = SLIST_NEXT(curelm, field); \ SLIST_NEXT(curelm, field) = SLIST_FIRST(head2); \ SLIST_INIT(head2); \ } \ } while (0) #define SLIST_EMPTY(head) ((head)->slh_first == NULL) #define SLIST_FIRST(head) ((head)->slh_first) #define SLIST_FOREACH(var, head, field) \ for ((var) = SLIST_FIRST((head)); (var); (var) = SLIST_NEXT((var), field)) #define SLIST_FOREACH_FROM(var, head, field) \ for ((var) = ((var) ? (var) : SLIST_FIRST((head))); (var); (var) = SLIST_NEXT((var), field)) #define SLIST_FOREACH_SAFE(var, head, field, tvar) \ for ((var) = SLIST_FIRST((head)); (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ (var) = (tvar)) #define SLIST_FOREACH_FROM_SAFE(var, head, field, tvar) \ for ((var) = ((var) ? (var) : SLIST_FIRST((head))); \ (var) && ((tvar) = SLIST_NEXT((var), field), 1); (var) = (tvar)) #define SLIST_FOREACH_PREVPTR(var, varp, head, field) \ for ((varp) = &SLIST_FIRST((head)); ((var) = *(varp)) != NULL; \ (varp) = &SLIST_NEXT((var), field)) #define SLIST_INIT(head) \ do { \ SLIST_FIRST((head)) = NULL; \ } while (0) #define SLIST_INSERT_AFTER(slistelm, elm, field) \ do { \ SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \ SLIST_NEXT((slistelm), field) = (elm); \ } while (0) #define SLIST_INSERT_HEAD(head, elm, field) \ do { \ SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \ SLIST_FIRST((head)) = (elm); \ } while (0) #define SLIST_NEXT(elm, field) ((elm)->field.sle_next) #define SLIST_REMOVE(head, elm, type, field) \ do { \ QMD_SAVELINK(oldnext, (elm)->field.sle_next); \ if (SLIST_FIRST((head)) == (elm)) { \ SLIST_REMOVE_HEAD((head), field); \ } else { \ QUEUE_TYPEOF(type) *curelm = SLIST_FIRST(head); \ while (SLIST_NEXT(curelm, field) != (elm)) \ curelm = SLIST_NEXT(curelm, field); \ SLIST_REMOVE_AFTER(curelm, field); \ } \ TRASHIT(*oldnext); \ } while (0) #define SLIST_REMOVE_AFTER(elm, field) \ do { \ SLIST_NEXT(elm, field) = SLIST_NEXT(SLIST_NEXT(elm, field), field); \ } while (0) #define SLIST_REMOVE_HEAD(head, field) \ do { \ SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \ } while (0) #define SLIST_REMOVE_PREVPTR(prevp, elm, field) \ do { \ QMD_SLIST_CHECK_PREVPTR(prevp, elm); \ *(prevp) = SLIST_NEXT(elm, field); \ TRASHIT((elm)->field.sle_next); \ } while (0) #define SLIST_SWAP(head1, head2, type) \ do { \ QUEUE_TYPEOF(type) *swap_first = SLIST_FIRST(head1); \ SLIST_FIRST(head1) = SLIST_FIRST(head2); \ SLIST_FIRST(head2) = swap_first; \ } while (0) /* * Singly-linked Tail queue declarations. */ #define STAILQ_HEAD(name, type) \ struct name { \ struct type *stqh_first; /* first element */ \ struct type **stqh_last; /* addr of last next element */ \ } #define STAILQ_CLASS_HEAD(name, type) \ struct name { \ class type *stqh_first; /* first element */ \ class type **stqh_last; /* addr of last next element */ \ } #define STAILQ_HEAD_INITIALIZER(head) { NULL, &(head).stqh_first } #define STAILQ_ENTRY(type) \ struct { \ struct type *stqe_next; /* next element */ \ } #define STAILQ_CLASS_ENTRY(type) \ struct { \ class type *stqe_next; /* next element */ \ } /* * Singly-linked Tail queue functions. */ #define STAILQ_CONCAT(head1, head2) \ do { \ if (!STAILQ_EMPTY((head2))) { \ *(head1)->stqh_last = (head2)->stqh_first; \ (head1)->stqh_last = (head2)->stqh_last; \ STAILQ_INIT((head2)); \ } \ } while (0) #define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) #define STAILQ_FIRST(head) ((head)->stqh_first) #define STAILQ_FOREACH(var, head, field) \ for ((var) = STAILQ_FIRST((head)); (var); (var) = STAILQ_NEXT((var), field)) #define STAILQ_FOREACH_FROM(var, head, field) \ for ((var) = ((var) ? (var) : STAILQ_FIRST((head))); (var); (var) = STAILQ_NEXT((var), field)) #define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ for ((var) = STAILQ_FIRST((head)); (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ (var) = (tvar)) #define STAILQ_FOREACH_FROM_SAFE(var, head, field, tvar) \ for ((var) = ((var) ? (var) : STAILQ_FIRST((head))); \ (var) && ((tvar) = STAILQ_NEXT((var), field), 1); (var) = (tvar)) #define STAILQ_INIT(head) \ do { \ STAILQ_FIRST((head)) = NULL; \ (head)->stqh_last = &STAILQ_FIRST((head)); \ } while (0) #define STAILQ_INSERT_AFTER(head, tqelm, elm, field) \ do { \ if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL) \ (head)->stqh_last = &STAILQ_NEXT((elm), field); \ STAILQ_NEXT((tqelm), field) = (elm); \ } while (0) #define STAILQ_INSERT_HEAD(head, elm, field) \ do { \ if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ (head)->stqh_last = &STAILQ_NEXT((elm), field); \ STAILQ_FIRST((head)) = (elm); \ } while (0) #define STAILQ_INSERT_TAIL(head, elm, field) \ do { \ STAILQ_NEXT((elm), field) = NULL; \ *(head)->stqh_last = (elm); \ (head)->stqh_last = &STAILQ_NEXT((elm), field); \ } while (0) #define STAILQ_LAST(head, type, field) \ (STAILQ_EMPTY((head)) ? NULL \ : __containerof((head)->stqh_last, QUEUE_TYPEOF(type), field.stqe_next)) #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) #define STAILQ_REMOVE(head, elm, type, field) \ do { \ QMD_SAVELINK(oldnext, (elm)->field.stqe_next); \ if (STAILQ_FIRST((head)) == (elm)) { \ STAILQ_REMOVE_HEAD((head), field); \ } else { \ QUEUE_TYPEOF(type) *curelm = STAILQ_FIRST(head); \ while (STAILQ_NEXT(curelm, field) != (elm)) \ curelm = STAILQ_NEXT(curelm, field); \ STAILQ_REMOVE_AFTER(head, curelm, field); \ } \ TRASHIT(*oldnext); \ } while (0) #define STAILQ_REMOVE_AFTER(head, elm, field) \ do { \ if ((STAILQ_NEXT(elm, field) = STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \ (head)->stqh_last = &STAILQ_NEXT((elm), field); \ } while (0) #define STAILQ_REMOVE_HEAD(head, field) \ do { \ if ((STAILQ_FIRST((head)) = STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ (head)->stqh_last = &STAILQ_FIRST((head)); \ } while (0) #define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) \ do { \ if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL) \ (head)->stqh_last = &STAILQ_FIRST((head)); \ } while (0) #define STAILQ_SWAP(head1, head2, type) \ do { \ QUEUE_TYPEOF(type) *swap_first = STAILQ_FIRST(head1); \ QUEUE_TYPEOF(type) **swap_last = (head1)->stqh_last; \ STAILQ_FIRST(head1) = STAILQ_FIRST(head2); \ (head1)->stqh_last = (head2)->stqh_last; \ STAILQ_FIRST(head2) = swap_first; \ (head2)->stqh_last = swap_last; \ if (STAILQ_EMPTY(head1)) \ (head1)->stqh_last = &STAILQ_FIRST(head1); \ if (STAILQ_EMPTY(head2)) \ (head2)->stqh_last = &STAILQ_FIRST(head2); \ } while (0) /* * List declarations. */ #define LIST_HEAD(name, type) \ struct name { \ struct type *lh_first; /* first element */ \ } #define LIST_CLASS_HEAD(name, type) \ struct name { \ class type *lh_first; /* first element */ \ } #define LIST_HEAD_INITIALIZER(head) { NULL } #define LIST_ENTRY(type) \ struct { \ struct type *le_next; /* next element */ \ struct type **le_prev; /* address of previous next element */ \ } #define LIST_CLASS_ENTRY(type) \ struct { \ class type *le_next; /* next element */ \ class type **le_prev; /* address of previous next element */ \ } /* * List functions. */ #if (defined(_KERNEL) && defined(INVARIANTS)) /* * QMD_LIST_CHECK_HEAD(LIST_HEAD *head, LIST_ENTRY NAME) * * If the list is non-empty, validates that the first element of the list * points back at 'head.' */ #define QMD_LIST_CHECK_HEAD(head, field) \ do { \ if (LIST_FIRST((head)) != NULL \ && LIST_FIRST((head))->field.le_prev != &LIST_FIRST((head))) \ panic("Bad list head %p first->prev != head", (head)); \ } while (0) /* * QMD_LIST_CHECK_NEXT(TYPE *elm, LIST_ENTRY NAME) * * If an element follows 'elm' in the list, validates that the next element * points back at 'elm.' */ #define QMD_LIST_CHECK_NEXT(elm, field) \ do { \ if (LIST_NEXT((elm), field) != NULL \ && LIST_NEXT((elm), field)->field.le_prev != &((elm)->field.le_next)) \ panic("Bad link elm %p next->prev != elm", (elm)); \ } while (0) /* * QMD_LIST_CHECK_PREV(TYPE *elm, LIST_ENTRY NAME) * * Validates that the previous element (or head of the list) points to 'elm.' */ #define QMD_LIST_CHECK_PREV(elm, field) \ do { \ if (*(elm)->field.le_prev != (elm)) \ panic("Bad link elm %p prev->next != elm", (elm)); \ } while (0) #else #define QMD_LIST_CHECK_HEAD(head, field) #define QMD_LIST_CHECK_NEXT(elm, field) #define QMD_LIST_CHECK_PREV(elm, field) #endif /* (_KERNEL && INVARIANTS) */ #define LIST_CONCAT(head1, head2, type, field) \ do { \ QUEUE_TYPEOF(type) *curelm = LIST_FIRST(head1); \ if (curelm == NULL) { \ if ((LIST_FIRST(head1) = LIST_FIRST(head2)) != NULL) { \ LIST_FIRST(head2)->field.le_prev = &LIST_FIRST((head1)); \ LIST_INIT(head2); \ } \ } else if (LIST_FIRST(head2) != NULL) { \ while (LIST_NEXT(curelm, field) != NULL) \ curelm = LIST_NEXT(curelm, field); \ LIST_NEXT(curelm, field) = LIST_FIRST(head2); \ LIST_FIRST(head2)->field.le_prev = &LIST_NEXT(curelm, field); \ LIST_INIT(head2); \ } \ } while (0) #define LIST_EMPTY(head) ((head)->lh_first == NULL) #define LIST_FIRST(head) ((head)->lh_first) #define LIST_FOREACH(var, head, field) \ for ((var) = LIST_FIRST((head)); (var); (var) = LIST_NEXT((var), field)) #define LIST_FOREACH_FROM(var, head, field) \ for ((var) = ((var) ? (var) : LIST_FIRST((head))); (var); (var) = LIST_NEXT((var), field)) #define LIST_FOREACH_SAFE(var, head, field, tvar) \ for ((var) = LIST_FIRST((head)); (var) && ((tvar) = LIST_NEXT((var), field), 1); (var) = (tvar)) #define LIST_FOREACH_FROM_SAFE(var, head, field, tvar) \ for ((var) = ((var) ? (var) : LIST_FIRST((head))); \ (var) && ((tvar) = LIST_NEXT((var), field), 1); (var) = (tvar)) #define LIST_INIT(head) \ do { \ LIST_FIRST((head)) = NULL; \ } while (0) #define LIST_INSERT_AFTER(listelm, elm, field) \ do { \ QMD_LIST_CHECK_NEXT(listelm, field); \ if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL) \ LIST_NEXT((listelm), field)->field.le_prev = &LIST_NEXT((elm), field); \ LIST_NEXT((listelm), field) = (elm); \ (elm)->field.le_prev = &LIST_NEXT((listelm), field); \ } while (0) #define LIST_INSERT_BEFORE(listelm, elm, field) \ do { \ QMD_LIST_CHECK_PREV(listelm, field); \ (elm)->field.le_prev = (listelm)->field.le_prev; \ LIST_NEXT((elm), field) = (listelm); \ *(listelm)->field.le_prev = (elm); \ (listelm)->field.le_prev = &LIST_NEXT((elm), field); \ } while (0) #define LIST_INSERT_HEAD(head, elm, field) \ do { \ QMD_LIST_CHECK_HEAD((head), field); \ if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \ LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field); \ LIST_FIRST((head)) = (elm); \ (elm)->field.le_prev = &LIST_FIRST((head)); \ } while (0) #define LIST_NEXT(elm, field) ((elm)->field.le_next) #define LIST_PREV(elm, head, type, field) \ ((elm)->field.le_prev == &LIST_FIRST((head)) \ ? NULL \ : __containerof((elm)->field.le_prev, QUEUE_TYPEOF(type), field.le_next)) #define LIST_REMOVE(elm, field) \ do { \ QMD_SAVELINK(oldnext, (elm)->field.le_next); \ QMD_SAVELINK(oldprev, (elm)->field.le_prev); \ QMD_LIST_CHECK_NEXT(elm, field); \ QMD_LIST_CHECK_PREV(elm, field); \ if (LIST_NEXT((elm), field) != NULL) \ LIST_NEXT((elm), field)->field.le_prev = (elm)->field.le_prev; \ *(elm)->field.le_prev = LIST_NEXT((elm), field); \ TRASHIT(*oldnext); \ TRASHIT(*oldprev); \ } while (0) #define LIST_SWAP(head1, head2, type, field) \ do { \ QUEUE_TYPEOF(type) *swap_tmp = LIST_FIRST(head1); \ LIST_FIRST((head1)) = LIST_FIRST((head2)); \ LIST_FIRST((head2)) = swap_tmp; \ if ((swap_tmp = LIST_FIRST((head1))) != NULL) \ swap_tmp->field.le_prev = &LIST_FIRST((head1)); \ if ((swap_tmp = LIST_FIRST((head2))) != NULL) \ swap_tmp->field.le_prev = &LIST_FIRST((head2)); \ } while (0) /* * Tail queue declarations. */ #define TAILQ_HEAD(name, type) \ struct name { \ struct type *tqh_first; /* first element */ \ struct type **tqh_last; /* addr of last next element */ \ TRACEBUF \ } #define TAILQ_CLASS_HEAD(name, type) \ struct name { \ class type *tqh_first; /* first element */ \ class type **tqh_last; /* addr of last next element */ \ TRACEBUF \ } #define TAILQ_HEAD_INITIALIZER(head) { NULL, &(head).tqh_first, TRACEBUF_INITIALIZER } #define TAILQ_ENTRY(type) \ struct { \ struct type *tqe_next; /* next element */ \ struct type **tqe_prev; /* address of previous next element */ \ TRACEBUF \ } #define TAILQ_CLASS_ENTRY(type) \ struct { \ class type *tqe_next; /* next element */ \ class type **tqe_prev; /* address of previous next element */ \ TRACEBUF \ } /* * Tail queue functions. */ #if (defined(_KERNEL) && defined(INVARIANTS)) /* * QMD_TAILQ_CHECK_HEAD(TAILQ_HEAD *head, TAILQ_ENTRY NAME) * * If the tailq is non-empty, validates that the first element of the tailq * points back at 'head.' */ #define QMD_TAILQ_CHECK_HEAD(head, field) \ do { \ if (!TAILQ_EMPTY(head) && TAILQ_FIRST((head))->field.tqe_prev != &TAILQ_FIRST((head))) \ panic("Bad tailq head %p first->prev != head", (head)); \ } while (0) /* * QMD_TAILQ_CHECK_TAIL(TAILQ_HEAD *head, TAILQ_ENTRY NAME) * * Validates that the tail of the tailq is a pointer to pointer to NULL. */ #define QMD_TAILQ_CHECK_TAIL(head, field) \ do { \ if (*(head)->tqh_last != NULL) \ panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head)); \ } while (0) /* * QMD_TAILQ_CHECK_NEXT(TYPE *elm, TAILQ_ENTRY NAME) * * If an element follows 'elm' in the tailq, validates that the next element * points back at 'elm.' */ #define QMD_TAILQ_CHECK_NEXT(elm, field) \ do { \ if (TAILQ_NEXT((elm), field) != NULL \ && TAILQ_NEXT((elm), field)->field.tqe_prev != &((elm)->field.tqe_next)) \ panic("Bad link elm %p next->prev != elm", (elm)); \ } while (0) /* * QMD_TAILQ_CHECK_PREV(TYPE *elm, TAILQ_ENTRY NAME) * * Validates that the previous element (or head of the tailq) points to 'elm.' */ #define QMD_TAILQ_CHECK_PREV(elm, field) \ do { \ if (*(elm)->field.tqe_prev != (elm)) \ panic("Bad link elm %p prev->next != elm", (elm)); \ } while (0) #else #define QMD_TAILQ_CHECK_HEAD(head, field) #define QMD_TAILQ_CHECK_TAIL(head, headname) #define QMD_TAILQ_CHECK_NEXT(elm, field) #define QMD_TAILQ_CHECK_PREV(elm, field) #endif /* (_KERNEL && INVARIANTS) */ #define TAILQ_CONCAT(head1, head2, field) \ do { \ if (!TAILQ_EMPTY(head2)) { \ *(head1)->tqh_last = (head2)->tqh_first; \ (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ (head1)->tqh_last = (head2)->tqh_last; \ TAILQ_INIT((head2)); \ QMD_TRACE_HEAD(head1); \ QMD_TRACE_HEAD(head2); \ } \ } while (0) #define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) #define TAILQ_FIRST(head) ((head)->tqh_first) #define TAILQ_FOREACH(var, head, field) \ for ((var) = TAILQ_FIRST((head)); (var); (var) = TAILQ_NEXT((var), field)) #define TAILQ_FOREACH_FROM(var, head, field) \ for ((var) = ((var) ? (var) : TAILQ_FIRST((head))); (var); (var) = TAILQ_NEXT((var), field)) #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ for ((var) = TAILQ_FIRST((head)); (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ (var) = (tvar)) #define TAILQ_FOREACH_FROM_SAFE(var, head, field, tvar) \ for ((var) = ((var) ? (var) : TAILQ_FIRST((head))); \ (var) && ((tvar) = TAILQ_NEXT((var), field), 1); (var) = (tvar)) #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ for ((var) = TAILQ_LAST((head), headname); (var); (var) = TAILQ_PREV((var), headname, field)) #define TAILQ_FOREACH_REVERSE_FROM(var, head, headname, field) \ for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname)); (var); \ (var) = TAILQ_PREV((var), headname, field)) #define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ for ((var) = TAILQ_LAST((head), headname); \ (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); (var) = (tvar)) #define TAILQ_FOREACH_REVERSE_FROM_SAFE(var, head, headname, field, tvar) \ for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname)); \ (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); (var) = (tvar)) #define TAILQ_INIT(head) \ do { \ TAILQ_FIRST((head)) = NULL; \ (head)->tqh_last = &TAILQ_FIRST((head)); \ QMD_TRACE_HEAD(head); \ } while (0) #define TAILQ_INSERT_AFTER(head, listelm, elm, field) \ do { \ QMD_TAILQ_CHECK_NEXT(listelm, field); \ if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL) \ TAILQ_NEXT((elm), field)->field.tqe_prev = &TAILQ_NEXT((elm), field); \ else { \ (head)->tqh_last = &TAILQ_NEXT((elm), field); \ QMD_TRACE_HEAD(head); \ } \ TAILQ_NEXT((listelm), field) = (elm); \ (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \ QMD_TRACE_ELEM(&(elm)->field); \ QMD_TRACE_ELEM(&(listelm)->field); \ } while (0) #define TAILQ_INSERT_BEFORE(listelm, elm, field) \ do { \ QMD_TAILQ_CHECK_PREV(listelm, field); \ (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ TAILQ_NEXT((elm), field) = (listelm); \ *(listelm)->field.tqe_prev = (elm); \ (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \ QMD_TRACE_ELEM(&(elm)->field); \ QMD_TRACE_ELEM(&(listelm)->field); \ } while (0) #define TAILQ_INSERT_HEAD(head, elm, field) \ do { \ QMD_TAILQ_CHECK_HEAD(head, field); \ if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \ TAILQ_FIRST((head))->field.tqe_prev = &TAILQ_NEXT((elm), field); \ else \ (head)->tqh_last = &TAILQ_NEXT((elm), field); \ TAILQ_FIRST((head)) = (elm); \ (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \ QMD_TRACE_HEAD(head); \ QMD_TRACE_ELEM(&(elm)->field); \ } while (0) #define TAILQ_INSERT_TAIL(head, elm, field) \ do { \ QMD_TAILQ_CHECK_TAIL(head, field); \ TAILQ_NEXT((elm), field) = NULL; \ (elm)->field.tqe_prev = (head)->tqh_last; \ *(head)->tqh_last = (elm); \ (head)->tqh_last = &TAILQ_NEXT((elm), field); \ QMD_TRACE_HEAD(head); \ QMD_TRACE_ELEM(&(elm)->field); \ } while (0) #define TAILQ_LAST(head, headname) (*(((struct headname *)((head)->tqh_last))->tqh_last)) /* * The FAST function is fast in that it causes no data access other * then the access to the head. The standard LAST function above * will cause a data access of both the element you want and * the previous element. FAST is very useful for instances when * you may want to prefetch the last data element. */ #define TAILQ_LAST_FAST(head, type, field) \ (TAILQ_EMPTY(head) ? NULL : __containerof((head)->tqh_last, QUEUE_TYPEOF(type), field.tqe_next)) #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) #define TAILQ_PREV(elm, headname, field) (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) #define TAILQ_REMOVE(head, elm, field) \ do { \ QMD_SAVELINK(oldnext, (elm)->field.tqe_next); \ QMD_SAVELINK(oldprev, (elm)->field.tqe_prev); \ QMD_TAILQ_CHECK_NEXT(elm, field); \ QMD_TAILQ_CHECK_PREV(elm, field); \ if ((TAILQ_NEXT((elm), field)) != NULL) \ TAILQ_NEXT((elm), field)->field.tqe_prev = (elm)->field.tqe_prev; \ else { \ (head)->tqh_last = (elm)->field.tqe_prev; \ QMD_TRACE_HEAD(head); \ } \ *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \ TRASHIT(*oldnext); \ TRASHIT(*oldprev); \ QMD_TRACE_ELEM(&(elm)->field); \ } while (0) #define TAILQ_SWAP(head1, head2, type, field) \ do { \ QUEUE_TYPEOF(type) *swap_first = (head1)->tqh_first; \ QUEUE_TYPEOF(type) **swap_last = (head1)->tqh_last; \ (head1)->tqh_first = (head2)->tqh_first; \ (head1)->tqh_last = (head2)->tqh_last; \ (head2)->tqh_first = swap_first; \ (head2)->tqh_last = swap_last; \ if ((swap_first = (head1)->tqh_first) != NULL) \ swap_first->field.tqe_prev = &(head1)->tqh_first; \ else \ (head1)->tqh_last = &(head1)->tqh_first; \ if ((swap_first = (head2)->tqh_first) != NULL) \ swap_first->field.tqe_prev = &(head2)->tqh_first; \ else \ (head2)->tqh_last = &(head2)->tqh_first; \ } while (0) #ifdef _KERNEL /* * XXX insque() and remque() are an old way of handling certain queues. * They bogusly assumes that all queue heads look alike. */ struct quehead { struct quehead *qh_link; struct quehead *qh_rlink; }; #ifdef __GNUC__ static __inline void insque(void *a, void *b) { struct quehead *element = (struct quehead *)a, *head = (struct quehead *)b; element->qh_link = head->qh_link; element->qh_rlink = head; head->qh_link = element; element->qh_link->qh_rlink = element; } static __inline void remque(void *a) { struct quehead *element = (struct quehead *)a; element->qh_link->qh_rlink = element->qh_rlink; element->qh_rlink->qh_link = element->qh_link; element->qh_rlink = 0; } #else /* !__GNUC__ */ void insque(void *a, void *b); void remque(void *a); #endif /* __GNUC__ */ #endif /* _KERNEL */ #endif /* !_SYS_QUEUE_H_ */ picolibc-1.8.11/libc/include/sys/resource.h000066400000000000000000000036471513574234600205640ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SYS_RESOURCE_H_ #define _SYS_RESOURCE_H_ #include _BEGIN_STD_C #define RUSAGE_SELF 0 /* calling process */ #define RUSAGE_CHILDREN -1 /* terminated child processes */ #if __GNU_VISIBLE #define RUSAGE_THREAD 1 #endif struct rusage { struct timeval ru_utime; /* user time used */ struct timeval ru_stime; /* system time used */ }; int getrusage(int, struct rusage *); _END_STD_C #endif /* !_SYS_RESOURCE_H_ */ picolibc-1.8.11/libc/include/sys/sched.h000066400000000000000000000036551513574234600200220ustar00rootroot00000000000000/* * Written by Joel Sherrill . * * COPYRIGHT (c) 1989-2010. * On-Line Applications Research Corporation (OAR). * * Permission to use, copy, modify, and distribute this software for any * purpose without fee is hereby granted, provided that this entire notice * is included in all copies of any software which is or includes a copy * or modification of this software. * * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED * WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION * OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS * SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. * * $Id$ */ #ifndef _SYS_SCHED_H_ #define _SYS_SCHED_H_ #include #include #include _BEGIN_STD_C /* Scheduling Policies */ /* Open Group Specifications Issue 6 */ #define SCHED_OTHER 0 #define SCHED_FIFO 1 #define SCHED_RR 2 #if defined(_POSIX_SPORADIC_SERVER) #define SCHED_SPORADIC 4 #endif #if __GNU_VISIBLE #define SCHED_IDLE 5 #define SCHED_BATCH 6 /* Flag to drop realtime policies and negative nice values on fork(). */ #define SCHED_RESET_ON_FORK 0x40000000 #endif /* Scheduling Parameters */ /* Open Group Specifications Issue 6 */ struct sched_param { int sched_priority; /* Process execution scheduling priority */ #if defined(_POSIX_SPORADIC_SERVER) || defined(_POSIX_THREAD_SPORADIC_SERVER) int sched_ss_low_priority; /* Low scheduling priority for sporadic */ /* server */ struct timespec sched_ss_repl_period; /* Replenishment period for sporadic server */ struct timespec sched_ss_init_budget; /* Initial budget for sporadic server */ int sched_ss_max_repl; /* Maximum pending replenishments for */ /* sporadic server */ #endif }; _END_STD_C #endif /* end of include file */ picolibc-1.8.11/libc/include/sys/select.h000066400000000000000000000037741513574234600202150ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SYS_SELECT_H #define _SYS_SELECT_H #include #include #include #include #include #include #if !defined(_SIGSET_T_DECLARED) #define _SIGSET_T_DECLARED typedef __sigset_t sigset_t; #endif _BEGIN_STD_C #if __POSIX_VISIBLE >= 200112 int pselect(int __n, fd_set *__readfds, fd_set *__writefds, fd_set *__exceptfds, const struct timespec *__timeout, const sigset_t *__set); #endif _END_STD_C #endif /* sys/select.h */ picolibc-1.8.11/libc/include/sys/stat.h000066400000000000000000000253161513574234600177050ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SYS_STAT_H #define _SYS_STAT_H #include #include #include _BEGIN_STD_C #ifndef _BLKCNT_T_DECLARED typedef __blkcnt_t blkcnt_t; #define _BLKCNT_T_DECLARED #endif #ifndef _BLKSIZE_T_DECLARED typedef __blksize_t blksize_t; #define _BLKSIZE_T_DECLARED #endif #ifndef _DEV_T_DECLARED typedef __dev_t dev_t; /* device number or struct cdev */ #define _DEV_T_DECLARED #endif #ifndef _INO_T_DECLARED typedef __ino_t ino_t; /* inode number */ #define _INO_T_DECLARED #endif #ifndef _MODE_T_DECLARED typedef __mode_t mode_t; /* permissions */ #define _MODE_T_DECLARED #endif #ifndef _NLINK_T_DECLARED typedef __nlink_t nlink_t; /* link count */ #define _NLINK_T_DECLARED #endif #ifndef _UID_T_DECLARED typedef __uid_t uid_t; /* user id */ #define _UID_T_DECLARED #endif #ifndef _GID_T_DECLARED typedef __gid_t gid_t; /* group id */ #define _GID_T_DECLARED #endif #ifndef _OFF_T_DECLARED typedef __off_t off_t; /* file offset */ #define _OFF_T_DECLARED #endif #ifndef _OFF64_T_DECLARED typedef __off64_t off64_t; /* 64-bit file offset */ #define _OFF64_T_DECLARED #endif #ifndef _TIME_T_DECLARED typedef _TIME_T_ time_t; #define _TIME_T_DECLARED #endif /* dj's stat defines _STAT_H_ */ #ifndef _STAT_H_ /* It is intended that the layout of this structure not change when the sizes of any of the basic types change (short, int, long) [via a compile time option]. */ struct stat { dev_t st_dev; ino_t st_ino; mode_t st_mode; nlink_t st_nlink; uid_t st_uid; gid_t st_gid; #if defined(__linux) && defined(__x86_64__) int __pad0; #endif dev_t st_rdev; #if defined(__linux) && !defined(__x86_64__) unsigned short int __pad2; #endif off_t st_size; #if defined(__linux) #define _STAT_HAS_ST_BLKSIZE blksize_t st_blksize; blkcnt_t st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; #define st_atime st_atim.tv_sec /* Backward compatibility */ #define st_mtime st_mtim.tv_sec #define st_ctime st_ctim.tv_sec #if defined(__linux) && defined(__x86_64__) __uint64_t __glibc_reserved[3]; #endif #else #if defined(__rtems__) struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; #define _STAT_HAS_ST_BLKSIZE blksize_t st_blksize; blkcnt_t st_blocks; #else /* SysV/sco doesn't have the rest... But Solaris, eabi does. */ #if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__) time_t st_atime; time_t st_mtime; time_t st_ctime; #else struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; #define _STAT_HAS_ST_BLKSIZE blksize_t st_blksize; blkcnt_t st_blocks; #if !defined(__rtems__) long st_spare4[2]; #endif #endif #endif #endif }; #if __LARGEFILE64_VISIBLE struct stat64 { __dev_t st_dev; /* Device. */ #ifdef __x86_64__ __ino64_t st_ino; /* File serial number. */ __nlink_t st_nlink; /* Link count. */ __mode_t st_mode; /* File mode. */ #else unsigned int __pad1; __ino_t __st_ino; /* 32bit file serial number. */ __mode_t st_mode; /* File mode. */ __nlink_t st_nlink; /* Link count. */ #endif __uid_t st_uid; /* User ID of the file's owner. */ __gid_t st_gid; /* Group ID of the file's group.*/ #ifdef __x86_64__ int __pad0; __dev_t st_rdev; /* Device number, if device. */ __off_t st_size; /* Size of file, in bytes. */ #else __dev_t st_rdev; /* Device number, if device. */ unsigned int __pad2; __off64_t st_size; /* Size of file, in bytes. */ #endif #define _STAT64_HAS_ST_BLKSIZE __blksize_t st_blksize; /* Optimal block size for I/O. */ __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated. */ #if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__) __time_t st_atime; /* Time of last access. */ __syscall_ulong_t st_atimensec; /* Nscecs of last access. */ __time_t st_mtime; /* Time of last modification. */ __syscall_ulong_t st_mtimensec; /* Nsecs of last modification. */ __time_t st_ctime; /* Time of last status change. */ __syscall_ulong_t st_ctimensec; /* Nsecs of last status change. */ #else /* Nanosecond resolution timestamps are stored in a format equivalent to 'struct timespec'. This is the type used whenever possible but the Unix namespace rules do not allow the identifier 'timespec' to appear in the header. Therefore we have to handle the use of this header in strictly standard-compliant sources special. */ struct timespec st_atim; /* Time of last access. */ struct timespec st_mtim; /* Time of last modification. */ struct timespec st_ctim; /* Time of last status change. */ #endif #ifdef __x86_64__ __int64_t __glibc_reserved[3]; #else __ino64_t st_ino; /* File serial number. */ #endif }; #endif #if !(defined(__svr4__) && !defined(__PPC__) && !defined(__sun__)) #define st_atime st_atim.tv_sec #define st_ctime st_ctim.tv_sec #define st_mtime st_mtim.tv_sec #endif #define _IFMT 0170000 /* type of file */ #define _IFDIR 0040000 /* directory */ #define _IFCHR 0020000 /* character special */ #define _IFBLK 0060000 /* block special */ #define _IFREG 0100000 /* regular */ #define _IFLNK 0120000 /* symbolic link */ #define _IFSOCK 0140000 /* socket */ #define _IFIFO 0010000 /* fifo */ #define S_BLKSIZE 1024 /* size of a block */ #define S_ISUID 0004000 /* set user id on execution */ #define S_ISGID 0002000 /* set group id on execution */ #define S_ISVTX 0001000 /* save swapped text even after use */ #if __BSD_VISIBLE #define S_IREAD 0000400 /* read permission, owner */ #define S_IWRITE 0000200 /* write permission, owner */ #define S_IEXEC 0000100 /* execute/search permission, owner */ #define S_ENFMT 0002000 /* enforcement-mode locking */ #endif /* !_BSD_VISIBLE */ #define S_IFMT _IFMT #define S_IFDIR _IFDIR #define S_IFCHR _IFCHR #define S_IFBLK _IFBLK #define S_IFREG _IFREG #define S_IFLNK _IFLNK #define S_IFSOCK _IFSOCK #define S_IFIFO _IFIFO #ifdef _WIN32 /* The Windows header files define _S_ forms of these, so we do too for easier portability. */ #define _S_IFMT _IFMT #define _S_IFDIR _IFDIR #define _S_IFCHR _IFCHR #define _S_IFIFO _IFIFO #define _S_IFREG _IFREG #define _S_IREAD 0000400 #define _S_IWRITE 0000200 #define _S_IEXEC 0000100 #endif #define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) #define S_IRUSR 0000400 /* read permission, owner */ #define S_IWUSR 0000200 /* write permission, owner */ #define S_IXUSR 0000100 /* execute/search permission, owner */ #define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) #define S_IRGRP 0000040 /* read permission, group */ #define S_IWGRP 0000020 /* write permission, grougroup */ #define S_IXGRP 0000010 /* execute/search permission, group */ #define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) #define S_IROTH 0000004 /* read permission, other */ #define S_IWOTH 0000002 /* write permission, other */ #define S_IXOTH 0000001 /* execute/search permission, other */ #if __BSD_VISIBLE #define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */ #define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */ #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */ #endif #define S_ISBLK(m) (((m) & _IFMT) == _IFBLK) #define S_ISCHR(m) (((m) & _IFMT) == _IFCHR) #define S_ISDIR(m) (((m) & _IFMT) == _IFDIR) #define S_ISFIFO(m) (((m) & _IFMT) == _IFIFO) #define S_ISREG(m) (((m) & _IFMT) == _IFREG) #define S_ISLNK(m) (((m) & _IFMT) == _IFLNK) #define S_ISSOCK(m) (((m) & _IFMT) == _IFSOCK) #if defined(__CYGWIN__) || defined(__rtems__) /* Special tv_nsec values for futimens(2) and utimensat(2). */ #define UTIME_NOW -2L #define UTIME_OMIT -1L #endif int chmod(const char *__path, mode_t __mode); int fchmod(int __fd, mode_t __mode); int fstat(int __fd, struct stat *__sbuf); int mkdir(const char *_path, mode_t __mode); int mkfifo(const char *__path, mode_t __mode); int stat(const char *__restrict __path, struct stat *__restrict __sbuf); mode_t umask(mode_t __mask); #if __LARGEFILE64_VISIBLE int stat64(const char * __restrict __path, struct stat64 * __restrict __sbuf); int fstat64(int __fd, struct stat64 *__sbuf); #endif #if defined(__SPU__) || defined(__rtems__) || defined(__CYGWIN__) || __POSIX_VISIBLE >= 200112L \ || defined(__BSD_VISIBLE) || (_XOPEN_SOURCE - 0) >= 500 int lstat(const char * __restrict __path, struct stat * __restrict __buf); #endif #if defined(__SPU__) || defined(__rtems__) || defined(__CYGWIN__) || defined(__BSD_VISIBLE) \ || (_XOPEN_SOURCE - 0) >= 500 || __SVID_VISIBLE int mknod(const char *__path, mode_t __mode, dev_t __dev); #endif #if __ATFILE_VISIBLE int fchmodat(int, const char *, mode_t, int); int fstatat(int, const char * __restrict, struct stat * __restrict, int); int mkdirat(int, const char *, mode_t); int mkfifoat(int, const char *, mode_t); int mknodat(int, const char *, mode_t, dev_t); int utimensat(int, const char *, const struct timespec[2], int); #endif #if __POSIX_VISIBLE >= 200809 int futimens(int, const struct timespec[2]); #endif #endif /* !_STAT_H_ */ _END_STD_C #endif /* _SYS_STAT_H */ picolibc-1.8.11/libc/include/sys/string.h000066400000000000000000000002621513574234600202310ustar00rootroot00000000000000/* Copyright (c) 2005 Jeff Johnston */ /* This is a dummy used as a placeholder for systems that need to have a special header file. */ picolibc-1.8.11/libc/include/sys/syslimits.h000066400000000000000000000123301513574234600207620ustar00rootroot00000000000000/* * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)syslimits.h 8.1 (Berkeley) 6/2/93 * $FreeBSD: src/sys/sys/syslimits.h,v 1.10 2001/06/18 20:24:54 wollman Exp $ */ #ifndef _SYS_SYSLIMITS_H_ #define _SYS_SYSLIMITS_H_ #include #if __POSIX_VISIBLE /* Runtime invariant values */ #define ARG_MAX 65536 /* max bytes for an exec function */ #define ATEXIT_MAX 32 /* max atexit functions */ #define CHILD_MAX 40 /* max simultaneous processes */ #define IOV_MAX 1024 /* max elements in i/o vector */ #define OPEN_MAX 64 /* max open files per process */ #define TZNAME_MAX 10 /* max time zone name length */ /* Pathname values */ #define LINK_MAX 32767 /* max file link count */ #define MAX_CANON 255 /* max bytes in term canon input line */ #define MAX_INPUT 255 /* max bytes in terminal input */ #define NAME_MAX 255 /* max bytes in a file name */ #define PATH_MAX 1024 /* max bytes in pathname */ #define PIPE_BUF 512 /* max bytes for atomic pipe writes */ /* Runtime increasable values */ #define COLL_WEIGHTS_MAX 0 /* max weights for order keyword */ #define EXPR_NEST_MAX 32 /* max expressions nested in expr(1) */ #define LINE_MAX 2048 /* max bytes in an input line */ #define RE_DUP_MAX 255 /* max RE's in interval notation */ #define _POSIX_AIO_LISTIO_MAX 2 #define _POSIX_AIO_MAX 1 #define _POSIX_ARG_MAX 4096 #define _POSIX_CHILD_MAX 6 #define _POSIX_DELAYTIMER_MAX 32 #define _POSIX_HOST_NAME_MAX 255 #define _POSIX_LINK_MAX 8 #define _POSIX_LOGIN_NAME_MAX 9 #define _POSIX_MAX_CANON 255 #define _POSIX_MAX_INPUT 255 #define _POSIX_MQ_OPEN_MAX 8 #define _POSIX_MQ_PRIO_MAX 32 #define _POSIX_NAME_MAX 14 #define _POSIX_NGROUPS_MAX 0 #define _POSIX_OPEN_MAX 16 #define _POSIX_PATH_MAX 255 #define _POSIX_PIPE_BUF 512 #define _POSIX_RE_DUP_MAX 255 #define _POSIX_RTSIG_MAX 8 #define _POSIX_SEM_NSEMS_MAX 256 #define _POSIX_SEM_VALUE_MAX 32767 #define _POSIX_SIGQUEUE_MAX 32 #define _POSIX_SSIZE_MAX 32767 #define _POSIX_SS_REPL_MAX 4 #define _POSIX_STREAM_MAX 8 #define _POSIX_SYMLINK_MAX 255 #define _POSIX_SYMLOOP_MAX 8 #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 #define _POSIX_THREAD_KEYS_MAX 128 #define _POSIX_THREAD_THREADS_MAX 64 #define _POSIX_TIMER_MAX 32 #define _POSIX_TRACE_EVENT_NAME_MAX 30 #define _POSIX_TRACE_NAME_MAX 8 #define _POSIX_TRACE_SYS_MAX 8 #define _POSIX_TRACE_USER_EVENT_MAX 32 #define _POSIX_TTY_NAME_MAX 9 #define _POSIX_TZNAME_MAX 3 #define _POSIX2_BC_BASE_MAX 99 #define _POSIX2_BC_DIM_MAX 2048 #define _POSIX2_BC_SCALE_MAX 99 #define _POSIX2_BC_STRING_MAX 1000 #define _POSIX2_CHARCLASS_NAME_MAX 14 #define _POSIX2_COLL_WEIGHTS_MAX 2 #define _POSIX2_EXPR_NEST_MAX 32 #define _POSIX2_LINE_MAX 2048 #define _POSIX2_RE_DUP_MAX 255 #endif /* __POSIX_VISIBLE */ #ifdef _XOPEN_SOURCE #define _XOPEN_IOV_MAX 16 #define _XOPEN_NAME_MAX 255 #define _XOPEN_PATH_MAX 1024 #endif #if __MISC_VISIBLE #define NSIG_MAX __LONG_WIDTH__ /* max signal number */ #endif #endif picolibc-1.8.11/libc/include/sys/time.h000066400000000000000000000311531513574234600176640ustar00rootroot00000000000000/* time.h -- An implementation of the standard Unix file. Written by Geoffrey Noer Public domain; no rights reserved. */ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1982, 1986, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)time.h 8.5 (Berkeley) 5/4/95 * $FreeBSD: head/sys/sys/time.h 346176 2019-04-13 04:46:35Z imp $ */ #ifndef _SYS_TIME_H_ #define _SYS_TIME_H_ #include #include #include #include #include _BEGIN_STD_C #ifndef _SUSECONDS_T_DECLARED typedef __suseconds_t suseconds_t; #define _SUSECONDS_T_DECLARED #endif /* * Names of the interval timers, and structure * defining a timer setting. */ #define ITIMER_REAL 0 #define ITIMER_VIRTUAL 1 #define ITIMER_PROF 2 struct itimerval { struct timeval it_interval; /* timer interval */ struct timeval it_value; /* current value */ }; int getitimer(int __which, struct itimerval *__value); int gettimeofday(struct timeval * __restrict __p, void * __restrict __tz); int setitimer(int __which, const struct itimerval * __restrict __value, struct itimerval * __restrict __ovalue); int utimes(const char *, const struct timeval[2]); #if __BSD_VISIBLE struct timezone { int tz_minuteswest; /* minutes west of Greenwich */ int tz_dsttime; /* type of dst correction */ }; int adjtime(const struct timeval *, struct timeval *); int futimes(int, const struct timeval[2]); int lutimes(const char *, const struct timeval[2]); int settimeofday(const struct timeval *, const struct timezone *); #define DST_NONE 0 /* not on dst */ #define DST_USA 1 /* USA style dst */ #define DST_AUST 2 /* Australian style dst */ #define DST_WET 3 /* Western European dst */ #define DST_MET 4 /* Middle European dst */ #define DST_EET 5 /* Eastern European dst */ #define DST_CAN 6 /* Canada */ #ifndef _SBINTIME_T_DECLARED typedef __int64_t sbintime_t; #define _SBINTIME_T_DECLARED #endif struct bintime { time_t sec; __uint64_t frac; }; static __inline void bintime_addx(struct bintime *_bt, __uint64_t _x) { __uint64_t _u; _u = _bt->frac; _bt->frac += _x; if (_u > _bt->frac) _bt->sec++; } static __inline void bintime_add(struct bintime *_bt, const struct bintime *_bt2) { __uint64_t _u; _u = _bt->frac; _bt->frac += _bt2->frac; if (_u > _bt->frac) _bt->sec++; _bt->sec += _bt2->sec; } static __inline void bintime_sub(struct bintime *_bt, const struct bintime *_bt2) { __uint64_t _u; _u = _bt->frac; _bt->frac -= _bt2->frac; if (_u < _bt->frac) _bt->sec--; _bt->sec -= _bt2->sec; } static __inline void bintime_mul(struct bintime *_bt, unsigned int _x) { __uint64_t _p1, _p2; _p1 = (_bt->frac & 0xffffffffull) * _x; _p2 = (_bt->frac >> 32) * _x + (_p1 >> 32); _bt->sec *= _x; _bt->sec += (_p2 >> 32); _bt->frac = (_p2 << 32) | (_p1 & 0xffffffffull); } static __inline void bintime_shift(struct bintime *_bt, int _exp) { if (_exp > 0) { _bt->sec <<= _exp; _bt->sec |= _bt->frac >> (64 - _exp); _bt->frac <<= _exp; } else if (_exp < 0) { _bt->frac >>= -_exp; _bt->frac |= (__uint64_t)_bt->sec << (64 + _exp); _bt->sec >>= -_exp; } } #define bintime_clear(a) ((a)->sec = (a)->frac = 0) #define bintime_isset(a) ((a)->sec || (a)->frac) #define bintime_cmp(a, b, cmp) \ (((a)->sec == (b)->sec) ? ((a)->frac cmp(b)->frac) : ((a)->sec cmp(b)->sec)) #define SBT_1S ((sbintime_t)1 << 32) #define SBT_1M (SBT_1S * 60) #define SBT_1MS (SBT_1S / 1000) #define SBT_1US (SBT_1S / 1000000) #define SBT_1NS (SBT_1S / 1000000000) /* beware rounding, see nstosbt() */ #define SBT_MAX 0x7fffffffffffffffLL static __inline int sbintime_getsec(sbintime_t _sbt) { return (_sbt >> 32); } static __inline sbintime_t bttosbt(const struct bintime _bt) { return (((sbintime_t)_bt.sec << 32) + (_bt.frac >> 32)); } static __inline struct bintime sbttobt(sbintime_t _sbt) { struct bintime _bt; _bt.sec = _sbt >> 32; _bt.frac = _sbt << 32; return (_bt); } /* * Decimal<->sbt conversions. Multiplying or dividing by SBT_1NS results in * large roundoff errors which sbttons() and nstosbt() avoid. Millisecond and * microsecond functions are also provided for completeness. * * These functions return the smallest sbt larger or equal to the * number of seconds requested so that sbttoX(Xtosbt(y)) == y. Unlike * top of second computations below, which require that we tick at the * top of second, these need to be rounded up so we do whatever for at * least as long as requested. * * The naive computation we'd do is this * ((unit * 2^64 / SIFACTOR) + 2^32-1) >> 32 * However, that overflows. Instead, we compute * ((unit * 2^63 / SIFACTOR) + 2^31-1) >> 32 * and use pre-computed constants that are the ceil of the 2^63 / SIFACTOR * term to ensure we are using exactly the right constant. We use the lesser * evil of ull rather than a __uint64_t cast to ensure we have well defined * right shift semantics. With these changes, we get all the ns, us and ms * conversions back and forth right. */ static __inline __int64_t sbttons(sbintime_t _sbt) { __uint64_t ns; ns = _sbt; if (ns >= SBT_1S) ns = (ns >> 32) * 1000000000; else ns = 0; return (ns + (1000000000 * (_sbt & 0xffffffffu) >> 32)); } static __inline sbintime_t nstosbt(__int64_t _ns) { sbintime_t sb = 0; if (_ns >= SBT_1S) { sb = (_ns / 1000000000) * SBT_1S; _ns = _ns % 1000000000; } /* 9223372037 = ceil(2^63 / 1000000000) */ sb += ((_ns * 9223372037ull) + 0x7fffffff) >> 31; return (sb); } static __inline __int64_t sbttous(sbintime_t _sbt) { return ((1000000 * _sbt) >> 32); } static __inline sbintime_t ustosbt(__int64_t _us) { sbintime_t sb = 0; if (_us >= SBT_1S) { sb = (_us / 1000000) * SBT_1S; _us = _us % 1000000; } /* 9223372036855 = ceil(2^63 / 1000000) */ sb += ((_us * 9223372036855ull) + 0x7fffffff) >> 31; return (sb); } static __inline __int64_t sbttoms(sbintime_t _sbt) { return ((1000 * _sbt) >> 32); } static __inline sbintime_t mstosbt(__int64_t _ms) { sbintime_t sb = 0; if (_ms >= SBT_1S) { sb = (_ms / 1000) * SBT_1S; _ms = _ms % 1000; } /* 9223372036854776 = ceil(2^63 / 1000) */ sb += ((_ms * 9223372036854776ull) + 0x7fffffff) >> 31; return (sb); } /*- * Background information: * * When converting between timestamps on parallel timescales of differing * resolutions it is historical and scientific practice to round down rather * than doing 4/5 rounding. * * The date changes at midnight, not at noon. * * Even at 15:59:59.999999999 it's not four'o'clock. * * time_second ticks after N.999999999 not after N.4999999999 */ static __inline void bintime2timespec(const struct bintime *_bt, struct timespec *_ts) { _ts->tv_sec = _bt->sec; _ts->tv_nsec = ((__uint64_t)1000000000 * (__uint32_t)(_bt->frac >> 32)) >> 32; } static __inline void timespec2bintime(const struct timespec *_ts, struct bintime *_bt) { _bt->sec = _ts->tv_sec; /* 18446744073 = int(2^64 / 1000000000) */ _bt->frac = _ts->tv_nsec * (__uint64_t)18446744073LL; } static __inline void bintime2timeval(const struct bintime *_bt, struct timeval *_tv) { _tv->tv_sec = _bt->sec; _tv->tv_usec = ((__uint64_t)1000000 * (__uint32_t)(_bt->frac >> 32)) >> 32; } static __inline void timeval2bintime(const struct timeval *_tv, struct bintime *_bt) { _bt->sec = _tv->tv_sec; /* 18446744073709 = int(2^64 / 1000000) */ _bt->frac = _tv->tv_usec * (__uint64_t)18446744073709LL; } static __inline struct timespec sbttots(sbintime_t _sbt) { struct timespec _ts; _ts.tv_sec = _sbt >> 32; _ts.tv_nsec = sbttons((__uint32_t)_sbt); return (_ts); } static __inline sbintime_t tstosbt(struct timespec _ts) { return (((sbintime_t)_ts.tv_sec << 32) + nstosbt(_ts.tv_nsec)); } static __inline struct timeval sbttotv(sbintime_t _sbt) { struct timeval _tv; _tv.tv_sec = _sbt >> 32; _tv.tv_usec = sbttous((__uint32_t)_sbt); return (_tv); } static __inline sbintime_t tvtosbt(struct timeval _tv) { return (((sbintime_t)_tv.tv_sec << 32) + ustosbt(_tv.tv_usec)); } /* Operations on timespecs */ #define timespecclear(tvp) ((tvp)->tv_sec = (tvp)->tv_nsec = 0) #define timespecisset(tvp) ((tvp)->tv_sec || (tvp)->tv_nsec) #define timespeccmp(tvp, uvp, cmp) \ (((tvp)->tv_sec == (uvp)->tv_sec) ? ((tvp)->tv_nsec cmp(uvp)->tv_nsec) \ : ((tvp)->tv_sec cmp(uvp)->tv_sec)) #define timespecadd(tsp, usp, vsp) \ do { \ (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ if ((vsp)->tv_nsec >= 1000000000L) { \ (vsp)->tv_sec++; \ (vsp)->tv_nsec -= 1000000000L; \ } \ } while (0) #define timespecsub(tsp, usp, vsp) \ do { \ (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ if ((vsp)->tv_nsec < 0) { \ (vsp)->tv_sec--; \ (vsp)->tv_nsec += 1000000000L; \ } \ } while (0) #define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) #define timercmp(tvp, uvp, cmp) \ (((tvp)->tv_sec == (uvp)->tv_sec) ? ((tvp)->tv_usec cmp(uvp)->tv_usec) \ : ((tvp)->tv_sec cmp(uvp)->tv_sec)) #define timeradd(tvp, uvp, vvp) \ do { \ (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ if ((vvp)->tv_usec >= 1000000) { \ (vvp)->tv_sec++; \ (vvp)->tv_usec -= 1000000; \ } \ } while (0) #define timersub(tvp, uvp, vvp) \ do { \ (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ if ((vvp)->tv_usec < 0) { \ (vvp)->tv_sec--; \ (vvp)->tv_usec += 1000000; \ } \ } while (0) #endif /* __BSD_VISIBLE */ #if __GNU_VISIBLE int futimesat(int, const char *, const struct timeval[2]); #endif #include _END_STD_C #endif /* !_SYS_TIME_H_ */ picolibc-1.8.11/libc/include/sys/timeb.h000066400000000000000000000043011513574234600200210ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* timeb.h -- An implementation of the standard Unix file. Written by Ian Lance Taylor Public domain; no rights reserved. declares the structure used by the ftime function, as well as the ftime function itself. Newlib does not provide an implementation of ftime. */ #ifndef _SYS_TIMEB_H #define _SYS_TIMEB_H #include #include _BEGIN_STD_C #ifndef _TIME_T_DECLARED typedef _TIME_T_ time_t; #define _TIME_T_DECLARED #endif struct timeb { time_t time; unsigned short millitm; short timezone; short dstflag; }; extern int ftime(struct timeb *); _END_STD_C #endif /* ! defined (_SYS_TIMEB_H) */ picolibc-1.8.11/libc/include/sys/times.h000066400000000000000000000037421513574234600200520ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SYS_TIMES_H #define _SYS_TIMES_H #include #include _BEGIN_STD_C #ifndef _CLOCK_T_DECLARED typedef _CLOCK_T_ clock_t; #define _CLOCK_T_DECLARED #endif /* Get Process Times, P1003.1b-1993, p. 92 */ struct tms { clock_t tms_utime; /* user time */ clock_t tms_stime; /* system time */ clock_t tms_cutime; /* user time, children */ clock_t tms_cstime; /* system time, children */ }; clock_t times(struct tms *); _END_STD_C #endif /* !_SYS_TIMES_H */ picolibc-1.8.11/libc/include/sys/timespec.h000066400000000000000000000044211513574234600205350ustar00rootroot00000000000000/*- * Copyright (c) 1982, 1986, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)time.h 8.5 (Berkeley) 5/4/95 * from: FreeBSD: src/sys/sys/time.h,v 1.43 2000/03/20 14:09:05 phk Exp * $FreeBSD$ */ #ifndef _SYS_TIMESPEC_H_ #define _SYS_TIMESPEC_H_ #include #include #if __BSD_VISIBLE #define TIMEVAL_TO_TIMESPEC(tv, ts) \ do { \ (ts)->tv_sec = (tv)->tv_sec; \ (ts)->tv_nsec = (tv)->tv_usec * 1000; \ } while (0) #define TIMESPEC_TO_TIMEVAL(tv, ts) \ do { \ (tv)->tv_sec = (ts)->tv_sec; \ (tv)->tv_usec = (ts)->tv_nsec / 1000; \ } while (0) #endif /* __BSD_VISIBLE */ #endif /* _SYS_TIMESPEC_H_ */ picolibc-1.8.11/libc/include/sys/tree.h000066400000000000000000001506721513574234600176750ustar00rootroot00000000000000/* $NetBSD: tree.h,v 1.8 2004/03/28 19:38:30 provos Exp $ */ /* $OpenBSD: tree.h,v 1.7 2002/10/17 21:51:54 art Exp $ */ /* $FreeBSD: head/sys/sys/tree.h 347360 2019-05-08 18:47:00Z trasz $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright 2002 Niels Provos * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SYS_TREE_H_ #define _SYS_TREE_H_ #ifndef __PERMIT_DEPRECATED_SYS_TREE_H #warning "sys/tree.h is deprecated and will be removed in the future." #endif #include /* * This file defines data structures for different types of trees: * splay trees and red-black trees. * * A splay tree is a self-organizing data structure. Every operation * on the tree causes a splay to happen. The splay moves the requested * node to the root of the tree and partly rebalances it. * * This has the benefit that request locality causes faster lookups as * the requested nodes move to the top of the tree. On the other hand, * every lookup causes memory writes. * * The Balance Theorem bounds the total access time for m operations * and n inserts on an initially empty tree as O((m + n)lg n). The * amortized cost for a sequence of m accesses to a splay tree is O(lg n); * * A red-black tree is a binary search tree with the node color as an * extra attribute. It fulfills a set of conditions: * - every search path from the root to a leaf consists of the * same number of black nodes, * - each red node (except for the root) has a black parent, * - each leaf node is black. * * Every operation on a red-black tree is bounded as O(lg n). * The maximum height of a red-black tree is 2lg (n+1). */ #define SPLAY_HEAD(name, type) \ struct name { \ struct type *sph_root; /* root of the tree */ \ } #define SPLAY_INITIALIZER(root) { NULL } #define SPLAY_INIT(root) \ do { \ (root)->sph_root = NULL; \ } while (/*CONSTCOND*/ 0) #define SPLAY_ENTRY(type) \ struct { \ struct type *spe_left; /* left element */ \ struct type *spe_right; /* right element */ \ } #define SPLAY_LEFT(elm, field) (elm)->field.spe_left #define SPLAY_RIGHT(elm, field) (elm)->field.spe_right #define SPLAY_ROOT(head) (head)->sph_root #define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL) /* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */ #define SPLAY_ROTATE_RIGHT(head, tmp, field) \ do { \ SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \ SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ (head)->sph_root = tmp; \ } while (/*CONSTCOND*/ 0) #define SPLAY_ROTATE_LEFT(head, tmp, field) \ do { \ SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \ SPLAY_LEFT(tmp, field) = (head)->sph_root; \ (head)->sph_root = tmp; \ } while (/*CONSTCOND*/ 0) #define SPLAY_LINKLEFT(head, tmp, field) \ do { \ SPLAY_LEFT(tmp, field) = (head)->sph_root; \ tmp = (head)->sph_root; \ (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \ } while (/*CONSTCOND*/ 0) #define SPLAY_LINKRIGHT(head, tmp, field) \ do { \ SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ tmp = (head)->sph_root; \ (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \ } while (/*CONSTCOND*/ 0) #define SPLAY_ASSEMBLE(head, node, left, right, field) \ do { \ SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \ SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field); \ SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \ SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \ } while (/*CONSTCOND*/ 0) /* Generates prototypes and inline functions */ #define SPLAY_PROTOTYPE(name, type, field, cmp) \ void name##_SPLAY(struct name *, struct type *); \ void name##_SPLAY_MINMAX(struct name *, int); \ struct type *name##_SPLAY_INSERT(struct name *, struct type *); \ struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \ \ /* Finds the node with the same key as elm */ \ static __unused __inline struct type *name##_SPLAY_FIND(struct name *head, struct type *elm) \ { \ if (SPLAY_EMPTY(head)) \ return (NULL); \ name##_SPLAY(head, elm); \ if ((cmp)(elm, (head)->sph_root) == 0) \ return (head->sph_root); \ return (NULL); \ } \ \ static __unused __inline struct type *name##_SPLAY_NEXT(struct name *head, struct type *elm) \ { \ name##_SPLAY(head, elm); \ if (SPLAY_RIGHT(elm, field) != NULL) { \ elm = SPLAY_RIGHT(elm, field); \ while (SPLAY_LEFT(elm, field) != NULL) { \ elm = SPLAY_LEFT(elm, field); \ } \ } else \ elm = NULL; \ return (elm); \ } \ \ static __unused __inline struct type *name##_SPLAY_MIN_MAX(struct name *head, int val) \ { \ name##_SPLAY_MINMAX(head, val); \ return (SPLAY_ROOT(head)); \ } /* Main splay operation. * Moves node close to the key of elm to top */ #define SPLAY_GENERATE(name, type, field, cmp) \ struct type *name##_SPLAY_INSERT(struct name *head, struct type *elm) \ { \ if (SPLAY_EMPTY(head)) { \ SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \ } else { \ int __comp; \ name##_SPLAY(head, elm); \ __comp = (cmp)(elm, (head)->sph_root); \ if (__comp < 0) { \ SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field); \ SPLAY_RIGHT(elm, field) = (head)->sph_root; \ SPLAY_LEFT((head)->sph_root, field) = NULL; \ } else if (__comp > 0) { \ SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field); \ SPLAY_LEFT(elm, field) = (head)->sph_root; \ SPLAY_RIGHT((head)->sph_root, field) = NULL; \ } else \ return ((head)->sph_root); \ } \ (head)->sph_root = (elm); \ return (NULL); \ } \ \ struct type *name##_SPLAY_REMOVE(struct name *head, struct type *elm) \ { \ struct type *__tmp; \ if (SPLAY_EMPTY(head)) \ return (NULL); \ name##_SPLAY(head, elm); \ if ((cmp)(elm, (head)->sph_root) == 0) { \ if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \ (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \ } else { \ __tmp = SPLAY_RIGHT((head)->sph_root, field); \ (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \ name##_SPLAY(head, elm); \ SPLAY_RIGHT((head)->sph_root, field) = __tmp; \ } \ return (elm); \ } \ return (NULL); \ } \ \ void name##_SPLAY(struct name *head, struct type *elm) \ { \ struct type __node, *__left, *__right, *__tmp; \ int __comp; \ \ SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL; \ __left = __right = &__node; \ \ while ((__comp = (cmp)(elm, (head)->sph_root)) != 0) { \ if (__comp < 0) { \ __tmp = SPLAY_LEFT((head)->sph_root, field); \ if (__tmp == NULL) \ break; \ if ((cmp)(elm, __tmp) < 0) { \ SPLAY_ROTATE_RIGHT(head, __tmp, field); \ if (SPLAY_LEFT((head)->sph_root, field) == NULL) \ break; \ } \ SPLAY_LINKLEFT(head, __right, field); \ } else if (__comp > 0) { \ __tmp = SPLAY_RIGHT((head)->sph_root, field); \ if (__tmp == NULL) \ break; \ if ((cmp)(elm, __tmp) > 0) { \ SPLAY_ROTATE_LEFT(head, __tmp, field); \ if (SPLAY_RIGHT((head)->sph_root, field) == NULL) \ break; \ } \ SPLAY_LINKRIGHT(head, __left, field); \ } \ } \ SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ } \ \ /* Splay with either the minimum or the maximum element \ * Used to find minimum or maximum element in tree. \ */ \ void name##_SPLAY_MINMAX(struct name *head, int __comp) \ { \ struct type __node, *__left, *__right, *__tmp; \ \ SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL; \ __left = __right = &__node; \ \ while (1) { \ if (__comp < 0) { \ __tmp = SPLAY_LEFT((head)->sph_root, field); \ if (__tmp == NULL) \ break; \ if (__comp < 0) { \ SPLAY_ROTATE_RIGHT(head, __tmp, field); \ if (SPLAY_LEFT((head)->sph_root, field) == NULL) \ break; \ } \ SPLAY_LINKLEFT(head, __right, field); \ } else if (__comp > 0) { \ __tmp = SPLAY_RIGHT((head)->sph_root, field); \ if (__tmp == NULL) \ break; \ if (__comp > 0) { \ SPLAY_ROTATE_LEFT(head, __tmp, field); \ if (SPLAY_RIGHT((head)->sph_root, field) == NULL) \ break; \ } \ SPLAY_LINKRIGHT(head, __left, field); \ } \ } \ SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ } #define SPLAY_NEGINF -1 #define SPLAY_INF 1 #define SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y) #define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y) #define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y) #define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y) #define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF)) #define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL : name##_SPLAY_MIN_MAX(x, SPLAY_INF)) #define SPLAY_FOREACH(x, name, head) \ for ((x) = SPLAY_MIN(name, head); (x) != NULL; (x) = SPLAY_NEXT(name, head, x)) /* Macros that define a red-black tree */ #define RB_HEAD(name, type) \ struct name { \ struct type *rbh_root; /* root of the tree */ \ } #define RB_INITIALIZER(root) { NULL } #define RB_INIT(root) \ do { \ (root)->rbh_root = NULL; \ } while (/*CONSTCOND*/ 0) #define RB_BLACK 0 #define RB_RED 1 #define RB_ENTRY(type) \ struct { \ struct type *rbe_left; /* left element */ \ struct type *rbe_right; /* right element */ \ struct type *rbe_parent; /* parent element */ \ int rbe_color; /* node color */ \ } #define RB_LEFT(elm, field) (elm)->field.rbe_left #define RB_RIGHT(elm, field) (elm)->field.rbe_right #define RB_PARENT(elm, field) (elm)->field.rbe_parent #define RB_COLOR(elm, field) (elm)->field.rbe_color #define RB_ISRED(elm, field) ((elm) != NULL && RB_COLOR(elm, field) == RB_RED) #define RB_ROOT(head) (head)->rbh_root #define RB_EMPTY(head) (RB_ROOT(head) == NULL) #define RB_SET_PARENT(dst, src, field) \ do { \ RB_PARENT(dst, field) = src; \ } while (/*CONSTCOND*/ 0) #define RB_SET(elm, parent, field) \ do { \ RB_SET_PARENT(elm, parent, field); \ RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \ RB_COLOR(elm, field) = RB_RED; \ } while (/*CONSTCOND*/ 0) #define RB_SET_BLACKRED(black, red, field) \ do { \ RB_COLOR(black, field) = RB_BLACK; \ RB_COLOR(red, field) = RB_RED; \ } while (/*CONSTCOND*/ 0) /* * Something to be invoked in a loop at the root of every modified subtree, * from the bottom up to the root, to update augmented node data. */ #ifndef RB_AUGMENT #define RB_AUGMENT(x) break #endif #define RB_SWAP_CHILD(head, out, in, field) \ do { \ if (RB_PARENT(out, field) == NULL) \ RB_ROOT(head) = (in); \ else if ((out) == RB_LEFT(RB_PARENT(out, field), field)) \ RB_LEFT(RB_PARENT(out, field), field) = (in); \ else \ RB_RIGHT(RB_PARENT(out, field), field) = (in); \ } while (/*CONSTCOND*/ 0) #define RB_ROTATE_LEFT(head, elm, tmp, field) \ do { \ (tmp) = RB_RIGHT(elm, field); \ if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field)) != NULL) { \ RB_SET_PARENT(RB_RIGHT(elm, field), elm, field); \ } \ RB_SET_PARENT(tmp, RB_PARENT(elm, field), field); \ RB_SWAP_CHILD(head, elm, tmp, field); \ RB_LEFT(tmp, field) = (elm); \ RB_SET_PARENT(elm, tmp, field); \ RB_AUGMENT(elm); \ } while (/*CONSTCOND*/ 0) #define RB_ROTATE_RIGHT(head, elm, tmp, field) \ do { \ (tmp) = RB_LEFT(elm, field); \ if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field)) != NULL) { \ RB_SET_PARENT(RB_LEFT(elm, field), elm, field); \ } \ RB_SET_PARENT(tmp, RB_PARENT(elm, field), field); \ RB_SWAP_CHILD(head, elm, tmp, field); \ RB_RIGHT(tmp, field) = (elm); \ RB_SET_PARENT(elm, tmp, field); \ RB_AUGMENT(elm); \ } while (/*CONSTCOND*/ 0) /* * The RB_PARENT_ROTATE_LEFT() and RB_PARENT_ROTATE_RIGHT() rotations are * specialized versions of RB_ROTATE_LEFT() and RB_ROTATE_RIGHT() which may be * used if the parent node exists and the direction of the child element is * known. */ #define RB_PARENT_ROTATE_LEFT(parent, left, tmp, field) \ do { \ (tmp) = RB_RIGHT(left, field); \ if ((RB_RIGHT(left, field) = RB_LEFT(tmp, field)) != NULL) { \ RB_SET_PARENT(RB_RIGHT(left, field), left, field); \ } \ RB_SET_PARENT(tmp, parent, field); \ RB_LEFT(parent, field) = (tmp); \ RB_LEFT(tmp, field) = (left); \ RB_SET_PARENT(left, tmp, field); \ RB_AUGMENT(left); \ } while (/*CONSTCOND*/ 0) #define RB_PARENT_ROTATE_RIGHT(parent, right, tmp, field) \ do { \ (tmp) = RB_LEFT(right, field); \ if ((RB_LEFT(right, field) = RB_RIGHT(tmp, field)) != NULL) { \ RB_SET_PARENT(RB_LEFT(right, field), right, field); \ } \ RB_SET_PARENT(tmp, parent, field); \ RB_RIGHT(parent, field) = (tmp); \ RB_RIGHT(tmp, field) = (right); \ RB_SET_PARENT(right, tmp, field); \ RB_AUGMENT(right); \ } while (/*CONSTCOND*/ 0) /* * The RB_RED_ROTATE_LEFT() and RB_RED_ROTATE_RIGHT() rotations are specialized * versions of RB_ROTATE_LEFT() and RB_ROTATE_RIGHT() which may be used if we * rotate an element with a red child which has a black sibling. Such a red * node must have at least two child nodes so that the following red-black tree * invariant is fulfilled: * * Every path from a given node to any of its descendant NULL nodes goes * through the same number of black nodes. * * elm (could be the root) * / \ * BLACK RED (left or right child) * / \ * BLACK BLACK */ #define RB_RED_ROTATE_LEFT(head, elm, tmp, field) \ do { \ (tmp) = RB_RIGHT(elm, field); \ RB_RIGHT(elm, field) = RB_LEFT(tmp, field); \ RB_SET_PARENT(RB_RIGHT(elm, field), elm, field); \ RB_SET_PARENT(tmp, RB_PARENT(elm, field), field); \ RB_SWAP_CHILD(head, elm, tmp, field); \ RB_LEFT(tmp, field) = (elm); \ RB_SET_PARENT(elm, tmp, field); \ RB_AUGMENT(elm); \ } while (/*CONSTCOND*/ 0) #define RB_RED_ROTATE_RIGHT(head, elm, tmp, field) \ do { \ (tmp) = RB_LEFT(elm, field); \ RB_LEFT(elm, field) = RB_RIGHT(tmp, field); \ RB_SET_PARENT(RB_LEFT(elm, field), elm, field); \ RB_SET_PARENT(tmp, RB_PARENT(elm, field), field); \ RB_SWAP_CHILD(head, elm, tmp, field); \ RB_RIGHT(tmp, field) = (elm); \ RB_SET_PARENT(elm, tmp, field); \ RB_AUGMENT(elm); \ } while (/*CONSTCOND*/ 0) /* Generates prototypes and inline functions */ #define RB_PROTOTYPE(name, type, field, cmp) RB_PROTOTYPE_INTERNAL(name, type, field, cmp, ) #define RB_PROTOTYPE_STATIC(name, type, field, cmp) \ RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __unused static) #define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \ RB_PROTOTYPE_INSERT_COLOR(name, type, attr); \ RB_PROTOTYPE_REMOVE_COLOR(name, type, attr); \ RB_PROTOTYPE_INSERT(name, type, attr); \ RB_PROTOTYPE_REMOVE(name, type, attr); \ RB_PROTOTYPE_FIND(name, type, attr); \ RB_PROTOTYPE_NFIND(name, type, attr); \ RB_PROTOTYPE_NEXT(name, type, attr); \ RB_PROTOTYPE_PREV(name, type, attr); \ RB_PROTOTYPE_MINMAX(name, type, attr); \ RB_PROTOTYPE_REINSERT(name, type, attr); #define RB_PROTOTYPE_INSERT_COLOR(name, type, attr) \ attr void name##_RB_INSERT_COLOR(struct name *, struct type *) #define RB_PROTOTYPE_REMOVE_COLOR(name, type, attr) \ attr void name##_RB_REMOVE_COLOR(struct name *, struct type *) #define RB_PROTOTYPE_REMOVE(name, type, attr) \ attr struct type *name##_RB_REMOVE(struct name *, struct type *) #define RB_PROTOTYPE_INSERT(name, type, attr) \ attr struct type *name##_RB_INSERT(struct name *, struct type *) #define RB_PROTOTYPE_FIND(name, type, attr) \ attr struct type *name##_RB_FIND(struct name *, struct type *) #define RB_PROTOTYPE_NFIND(name, type, attr) \ attr struct type *name##_RB_NFIND(struct name *, struct type *) #define RB_PROTOTYPE_NEXT(name, type, attr) attr struct type *name##_RB_NEXT(struct type *) #define RB_PROTOTYPE_PREV(name, type, attr) attr struct type *name##_RB_PREV(struct type *) #define RB_PROTOTYPE_MINMAX(name, type, attr) attr struct type *name##_RB_MINMAX(struct name *, int) #define RB_PROTOTYPE_REINSERT(name, type, attr) \ attr struct type *name##_RB_REINSERT(struct name *, struct type *) /* Main rb operation. * Moves node close to the key of elm to top */ #define RB_GENERATE(name, type, field, cmp) RB_GENERATE_INTERNAL(name, type, field, cmp, ) #define RB_GENERATE_STATIC(name, type, field, cmp) \ RB_GENERATE_INTERNAL(name, type, field, cmp, __unused static) #define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \ RB_GENERATE_INSERT_COLOR(name, type, field, attr) \ RB_GENERATE_REMOVE_COLOR(name, type, field, attr) \ RB_GENERATE_INSERT(name, type, field, cmp, attr) \ RB_GENERATE_REMOVE(name, type, field, attr) \ RB_GENERATE_FIND(name, type, field, cmp, attr) \ RB_GENERATE_NFIND(name, type, field, cmp, attr) \ RB_GENERATE_NEXT(name, type, field, attr) \ RB_GENERATE_PREV(name, type, field, attr) \ RB_GENERATE_MINMAX(name, type, field, attr) \ RB_GENERATE_REINSERT(name, type, field, cmp, attr) #define RB_GENERATE_INSERT_COLOR(name, type, field, attr) \ attr void name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ { \ struct type *parent, *gparent, *tmp; \ while (RB_ISRED((parent = RB_PARENT(elm, field)), field)) { \ gparent = RB_PARENT(parent, field); \ if (parent == RB_LEFT(gparent, field)) { \ tmp = RB_RIGHT(gparent, field); \ if (RB_ISRED(tmp, field)) { \ RB_COLOR(tmp, field) = RB_BLACK; \ RB_SET_BLACKRED(parent, gparent, field); \ elm = gparent; \ continue; \ } \ if (RB_RIGHT(parent, field) == elm) { \ RB_PARENT_ROTATE_LEFT(gparent, parent, tmp, field); \ tmp = parent; \ parent = elm; \ elm = tmp; \ } \ RB_SET_BLACKRED(parent, gparent, field); \ RB_ROTATE_RIGHT(head, gparent, tmp, field); \ } else { \ tmp = RB_LEFT(gparent, field); \ if (RB_ISRED(tmp, field)) { \ RB_COLOR(tmp, field) = RB_BLACK; \ RB_SET_BLACKRED(parent, gparent, field); \ elm = gparent; \ continue; \ } \ if (RB_LEFT(parent, field) == elm) { \ RB_PARENT_ROTATE_RIGHT(gparent, parent, tmp, field); \ tmp = parent; \ parent = elm; \ elm = tmp; \ } \ RB_SET_BLACKRED(parent, gparent, field); \ RB_ROTATE_LEFT(head, gparent, tmp, field); \ } \ } \ RB_COLOR(head->rbh_root, field) = RB_BLACK; \ } #define RB_GENERATE_REMOVE_COLOR(name, type, field, attr) \ attr void name##_RB_REMOVE_COLOR(struct name *head, struct type *parent) \ { \ struct type *elm, *tmp; \ elm = NULL; \ do { \ if (RB_LEFT(parent, field) == elm) { \ tmp = RB_RIGHT(parent, field); \ if (RB_COLOR(tmp, field) == RB_RED) { \ RB_SET_BLACKRED(tmp, parent, field); \ RB_RED_ROTATE_LEFT(head, parent, tmp, field); \ tmp = RB_RIGHT(parent, field); \ } \ if (RB_ISRED(RB_RIGHT(tmp, field), field)) \ RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK; \ else if (RB_ISRED(RB_LEFT(tmp, field), field)) { \ struct type *oleft; \ RB_PARENT_ROTATE_RIGHT(parent, tmp, oleft, field); \ RB_COLOR(oleft, field) = RB_BLACK; \ tmp = oleft; \ } else { \ RB_COLOR(tmp, field) = RB_RED; \ elm = parent; \ parent = RB_PARENT(elm, field); \ continue; \ } \ RB_COLOR(tmp, field) = RB_COLOR(parent, field); \ RB_COLOR(parent, field) = RB_BLACK; \ RB_ROTATE_LEFT(head, parent, tmp, field); \ elm = RB_ROOT(head); \ break; \ } else { \ tmp = RB_LEFT(parent, field); \ if (RB_COLOR(tmp, field) == RB_RED) { \ RB_SET_BLACKRED(tmp, parent, field); \ RB_RED_ROTATE_RIGHT(head, parent, tmp, field); \ tmp = RB_LEFT(parent, field); \ } \ if (RB_ISRED(RB_LEFT(tmp, field), field)) \ RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK; \ else if (RB_ISRED(RB_RIGHT(tmp, field), field)) { \ struct type *oright; \ RB_PARENT_ROTATE_LEFT(parent, tmp, oright, field); \ RB_COLOR(oright, field) = RB_BLACK; \ tmp = oright; \ } else { \ RB_COLOR(tmp, field) = RB_RED; \ elm = parent; \ parent = RB_PARENT(elm, field); \ continue; \ } \ RB_COLOR(tmp, field) = RB_COLOR(parent, field); \ RB_COLOR(parent, field) = RB_BLACK; \ RB_ROTATE_RIGHT(head, parent, tmp, field); \ elm = RB_ROOT(head); \ break; \ } \ } while (RB_COLOR(elm, field) == RB_BLACK && parent != NULL); \ RB_COLOR(elm, field) = RB_BLACK; \ } #define RB_GENERATE_REMOVE(name, type, field, attr) \ attr struct type *name##_RB_REMOVE(struct name *head, struct type *elm) \ { \ struct type *child, *old, *parent, *right; \ int color; \ \ old = elm; \ parent = RB_PARENT(elm, field); \ right = RB_RIGHT(elm, field); \ color = RB_COLOR(elm, field); \ if (RB_LEFT(elm, field) == NULL) \ elm = child = right; \ else if (right == NULL) \ elm = child = RB_LEFT(elm, field); \ else { \ if ((child = RB_LEFT(right, field)) == NULL) { \ child = RB_RIGHT(right, field); \ RB_RIGHT(old, field) = child; \ parent = elm = right; \ } else { \ do \ elm = child; \ while ((child = RB_LEFT(elm, field)) != NULL); \ child = RB_RIGHT(elm, field); \ parent = RB_PARENT(elm, field); \ RB_LEFT(parent, field) = child; \ RB_SET_PARENT(RB_RIGHT(old, field), elm, field); \ } \ RB_SET_PARENT(RB_LEFT(old, field), elm, field); \ color = RB_COLOR(elm, field); \ elm->field = old->field; \ } \ RB_SWAP_CHILD(head, old, elm, field); \ if (child != NULL) { \ RB_SET_PARENT(child, parent, field); \ RB_COLOR(child, field) = RB_BLACK; \ } else if (color != RB_RED && parent != NULL) \ name##_RB_REMOVE_COLOR(head, parent); \ while (parent != NULL) { \ RB_AUGMENT(parent); \ parent = RB_PARENT(parent, field); \ } \ return (old); \ } #define RB_GENERATE_INSERT(name, type, field, cmp, attr) \ /* Inserts a node into the RB tree */ \ attr struct type *name##_RB_INSERT(struct name *head, struct type *elm) \ { \ struct type *tmp; \ struct type *parent = NULL; \ int comp = 0; \ tmp = RB_ROOT(head); \ while (tmp) { \ parent = tmp; \ comp = (cmp)(elm, parent); \ if (comp < 0) \ tmp = RB_LEFT(tmp, field); \ else if (comp > 0) \ tmp = RB_RIGHT(tmp, field); \ else \ return (tmp); \ } \ RB_SET(elm, parent, field); \ if (parent != NULL) { \ if (comp < 0) \ RB_LEFT(parent, field) = elm; \ else \ RB_RIGHT(parent, field) = elm; \ } else \ RB_ROOT(head) = elm; \ name##_RB_INSERT_COLOR(head, elm); \ while (elm != NULL) { \ RB_AUGMENT(elm); \ elm = RB_PARENT(elm, field); \ } \ return (NULL); \ } #define RB_GENERATE_FIND(name, type, field, cmp, attr) \ /* Finds the node with the same key as elm */ \ attr struct type *name##_RB_FIND(struct name *head, struct type *elm) \ { \ struct type *tmp = RB_ROOT(head); \ int comp; \ while (tmp) { \ comp = cmp(elm, tmp); \ if (comp < 0) \ tmp = RB_LEFT(tmp, field); \ else if (comp > 0) \ tmp = RB_RIGHT(tmp, field); \ else \ return (tmp); \ } \ return (NULL); \ } #define RB_GENERATE_NFIND(name, type, field, cmp, attr) \ /* Finds the first node greater than or equal to the search key */ \ attr struct type *name##_RB_NFIND(struct name *head, struct type *elm) \ { \ struct type *tmp = RB_ROOT(head); \ struct type *res = NULL; \ int comp; \ while (tmp) { \ comp = cmp(elm, tmp); \ if (comp < 0) { \ res = tmp; \ tmp = RB_LEFT(tmp, field); \ } else if (comp > 0) \ tmp = RB_RIGHT(tmp, field); \ else \ return (tmp); \ } \ return (res); \ } #define RB_GENERATE_NEXT(name, type, field, attr) \ /* ARGSUSED */ \ attr struct type *name##_RB_NEXT(struct type *elm) \ { \ if (RB_RIGHT(elm, field)) { \ elm = RB_RIGHT(elm, field); \ while (RB_LEFT(elm, field)) \ elm = RB_LEFT(elm, field); \ } else { \ if (RB_PARENT(elm, field) && (elm == RB_LEFT(RB_PARENT(elm, field), field))) \ elm = RB_PARENT(elm, field); \ else { \ while (RB_PARENT(elm, field) && (elm == RB_RIGHT(RB_PARENT(elm, field), field))) \ elm = RB_PARENT(elm, field); \ elm = RB_PARENT(elm, field); \ } \ } \ return (elm); \ } #define RB_GENERATE_PREV(name, type, field, attr) \ /* ARGSUSED */ \ attr struct type *name##_RB_PREV(struct type *elm) \ { \ if (RB_LEFT(elm, field)) { \ elm = RB_LEFT(elm, field); \ while (RB_RIGHT(elm, field)) \ elm = RB_RIGHT(elm, field); \ } else { \ if (RB_PARENT(elm, field) && (elm == RB_RIGHT(RB_PARENT(elm, field), field))) \ elm = RB_PARENT(elm, field); \ else { \ while (RB_PARENT(elm, field) && (elm == RB_LEFT(RB_PARENT(elm, field), field))) \ elm = RB_PARENT(elm, field); \ elm = RB_PARENT(elm, field); \ } \ } \ return (elm); \ } #define RB_GENERATE_MINMAX(name, type, field, attr) \ attr struct type *name##_RB_MINMAX(struct name *head, int val) \ { \ struct type *tmp = RB_ROOT(head); \ struct type *parent = NULL; \ while (tmp) { \ parent = tmp; \ if (val < 0) \ tmp = RB_LEFT(tmp, field); \ else \ tmp = RB_RIGHT(tmp, field); \ } \ return (parent); \ } #define RB_GENERATE_REINSERT(name, type, field, cmp, attr) \ attr struct type *name##_RB_REINSERT(struct name *head, struct type *elm) \ { \ struct type *cmpelm; \ if (((cmpelm = RB_PREV(name, head, elm)) != NULL && cmp(cmpelm, elm) >= 0) \ || ((cmpelm = RB_NEXT(name, head, elm)) != NULL && cmp(elm, cmpelm) >= 0)) { \ /* XXXLAS: Remove/insert is heavy handed. */ \ RB_REMOVE(name, head, elm); \ return (RB_INSERT(name, head, elm)); \ } \ return (NULL); \ } #define RB_NEGINF -1 #define RB_INF 1 #define RB_INSERT(name, x, y) name##_RB_INSERT(x, y) #define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) #define RB_FIND(name, x, y) name##_RB_FIND(x, y) #define RB_NFIND(name, x, y) name##_RB_NFIND(x, y) #define RB_NEXT(name, x, y) name##_RB_NEXT(y) #define RB_PREV(name, x, y) name##_RB_PREV(y) #define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) #define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) #define RB_REINSERT(name, x, y) name##_RB_REINSERT(x, y) #define RB_FOREACH(x, name, head) \ for ((x) = RB_MIN(name, head); (x) != NULL; (x) = name##_RB_NEXT(x)) #define RB_FOREACH_FROM(x, name, y) \ for ((x) = (y); ((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL); (x) = (y)) #define RB_FOREACH_SAFE(x, name, head, y) \ for ((x) = RB_MIN(name, head); ((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL); \ (x) = (y)) #define RB_FOREACH_REVERSE(x, name, head) \ for ((x) = RB_MAX(name, head); (x) != NULL; (x) = name##_RB_PREV(x)) #define RB_FOREACH_REVERSE_FROM(x, name, y) \ for ((x) = (y); ((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL); (x) = (y)) #define RB_FOREACH_REVERSE_SAFE(x, name, head, y) \ for ((x) = RB_MAX(name, head); ((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL); \ (x) = (y)) #endif /* _SYS_TREE_H_ */ picolibc-1.8.11/libc/include/sys/types.h000066400000000000000000000151041513574234600200700ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* unified sys/types.h: start with sef's sysvi386 version. merge go32 version -- a few ifdefs. h8300hms, h8300xray, and sysvnecv70 disagree on the following types: typedef int gid_t; typedef int uid_t; typedef int dev_t; typedef int ino_t; typedef int mode_t; typedef int caddr_t; however, these aren't "reasonable" values, the sysvi386 ones make far more sense, and should work sufficiently well (in particular, h8300 doesn't have a stat, and the necv70 doesn't matter.) -- eichin */ #ifndef _SYS_TYPES_H #include #include /* BSD types permitted by POSIX and always exposed as in Glibc. Only provided for backward compatibility with BSD code. The uintN_t standard types should be preferred in new code. */ #if ___int8_t_defined typedef __uint8_t u_int8_t; #endif #if ___int16_t_defined typedef __uint16_t u_int16_t; #endif #if ___int32_t_defined typedef __uint32_t u_int32_t; #endif #if ___int64_t_defined typedef __uint64_t u_int64_t; #endif typedef __intptr_t register_t; #define __BIT_TYPES_DEFINED__ 1 #ifndef __need_inttypes #define _SYS_TYPES_H #include #include #if __BSD_VISIBLE #include #define physadr physadr_t #define quad quad_t #ifndef _IN_ADDR_T_DECLARED typedef __uint32_t in_addr_t; /* base type for internet address */ #define _IN_ADDR_T_DECLARED #endif #ifndef _IN_PORT_T_DECLARED typedef __uint16_t in_port_t; #define _IN_PORT_T_DECLARED #endif typedef __uintptr_t u_register_t; #endif /* __BSD_VISIBLE */ #if __MISC_VISIBLE #ifndef _BSDTYPES_DEFINED /* also defined in mingw/gmon.h and in w32api/winsock[2].h */ #ifndef __u_char_defined typedef unsigned char u_char; #define __u_char_defined #endif #ifndef __u_short_defined typedef unsigned short u_short; #define __u_short_defined #endif #ifndef __u_int_defined typedef unsigned int u_int; #define __u_int_defined #endif #ifndef __u_long_defined typedef unsigned long u_long; #define __u_long_defined #endif #define _BSDTYPES_DEFINED #endif #endif /* __MISC_VISIBLE */ #if __MISC_VISIBLE typedef unsigned short ushort; /* System V compatibility */ typedef unsigned int uint; /* System V compatibility */ typedef unsigned long ulong; /* System V compatibility */ #endif #ifndef _BLKCNT_T_DECLARED typedef __blkcnt_t blkcnt_t; #define _BLKCNT_T_DECLARED #endif #ifndef _BLKSIZE_T_DECLARED typedef __blksize_t blksize_t; #define _BLKSIZE_T_DECLARED #endif #ifndef _CLOCK_T_DECLARED typedef _CLOCK_T_ clock_t; #define _CLOCK_T_DECLARED #endif #ifndef _TIME_T_DECLARED typedef _TIME_T_ time_t; #define _TIME_T_DECLARED #endif typedef __daddr_t daddr_t; #ifndef __caddr_t_defined typedef char *caddr_t; #define __caddr_t_defined #endif #ifndef _FSBLKCNT_T_DECLARED /* for statvfs() */ typedef __fsblkcnt_t fsblkcnt_t; typedef __fsfilcnt_t fsfilcnt_t; #define _FSBLKCNT_T_DECLARED #endif #ifndef _ID_T_DECLARED typedef __id_t id_t; /* can hold a uid_t or pid_t */ #define _ID_T_DECLARED #endif #ifndef _INO_T_DECLARED typedef __ino_t ino_t; /* inode number */ #define _INO_T_DECLARED #endif #if defined(__i386__) && (defined(GO32) || defined(__MSDOS__)) typedef char *addr_t; typedef unsigned long vm_offset_t; typedef unsigned long vm_size_t; #endif /* __i386__ && (GO32 || __MSDOS__) */ #ifndef _SSIZE_T_DECLARED typedef _ssize_t ssize_t; #define _SSIZE_T_DECLARED #endif #ifndef _OFF_T_DECLARED typedef __off_t off_t; /* file offset */ #define _OFF_T_DECLARED #endif #ifndef _OFF64_T_DECLARED typedef __off64_t off64_t; /* 64-bit file offset */ #define _OFF64_T_DECLARED #endif #ifndef _DEV_T_DECLARED typedef __dev_t dev_t; /* device number or struct cdev */ #define _DEV_T_DECLARED #endif #ifndef _UID_T_DECLARED typedef __uid_t uid_t; /* user id */ #define _UID_T_DECLARED #endif #ifndef _GID_T_DECLARED typedef __gid_t gid_t; /* group id */ #define _GID_T_DECLARED #endif #ifndef _PID_T_DECLARED typedef __pid_t pid_t; /* process id */ #define _PID_T_DECLARED #endif #ifndef _KEY_T_DECLARED typedef __key_t key_t; /* IPC key */ #define _KEY_T_DECLARED #endif #ifndef _MODE_T_DECLARED typedef __mode_t mode_t; /* permissions */ #define _MODE_T_DECLARED #endif #ifndef _NLINK_T_DECLARED typedef __nlink_t nlink_t; /* link count */ #define _NLINK_T_DECLARED #endif #ifndef _CLOCKID_T_DECLARED typedef __clockid_t clockid_t; #define _CLOCKID_T_DECLARED #ifdef __ZEPHYR__ #define __clockid_t_defined /* Zephyr <= 3.7 compat */ #endif #endif #ifndef _TIMER_T_DECLARED typedef __timer_t timer_t; #define _TIMER_T_DECLARED #ifdef __ZEPHYR__ #define __timer_t_defined /* Zephyr <= 3.7 compat */ #endif #endif #ifndef _USECONDS_T_DECLARED typedef __useconds_t useconds_t; /* microseconds (unsigned) */ #define _USECONDS_T_DECLARED #endif #ifndef _SUSECONDS_T_DECLARED typedef __suseconds_t suseconds_t; #define _SUSECONDS_T_DECLARED #endif #if __BSD_VISIBLE #ifndef _SBINTIME_T_DECLARED typedef __int64_t sbintime_t; #define _SBINTIME_T_DECLARED #endif #endif #include #include #endif /* !__need_inttypes */ #undef __need_inttypes #include #define __Long int32_t #define __ULong uint32_t #endif /* _SYS_TYPES_H */ picolibc-1.8.11/libc/include/sys/unistd.h000066400000000000000000000553241513574234600202420ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SYS_UNISTD_H #define _SYS_UNISTD_H #include #define __need_size_t #define __need_ptrdiff_t #define __need_NULL #include #include _BEGIN_STD_C #ifndef _USECONDS_T_DECLARED typedef __useconds_t useconds_t; /* microseconds (unsigned) */ #define _USECONDS_T_DECLARED #endif #ifndef _INTPTR_T_DECLARED typedef __intptr_t intptr_t; #define _INTPTR_T_DECLARED #endif #ifndef _SSIZE_T_DECLARED typedef _ssize_t ssize_t; #define _SSIZE_T_DECLARED #endif #ifndef _OFF_T_DECLARED typedef __off_t off_t; #define _OFF_T_DECLARED #endif #ifndef _OFF64_T_DECLARED typedef __off64_t off64_t; /* 64-bit file offset */ #define _OFF64_T_DECLARED #endif #ifndef _UID_T_DECLARED typedef __uid_t uid_t; /* user id */ #define _UID_T_DECLARED #endif #ifndef _GID_T_DECLARED typedef __gid_t gid_t; /* group id */ #define _GID_T_DECLARED #endif #ifndef _PID_T_DECLARED typedef __pid_t pid_t; /* process id */ #define _PID_T_DECLARED #endif extern char **environ; __noreturn void _exit(int __status); int access(const char *__path, int __amode); unsigned alarm(unsigned __secs); int brk(void *); int chdir(const char *__path); int chown(const char *__path, uid_t __owner, gid_t __group); #if __BSD_VISIBLE || (__XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112) int chroot(const char *__path); #endif int close(int __fildes); #if __POSIX_VISIBLE >= 202405 int posix_close(int __fildes, int __flag); #endif #if __POSIX_VISIBLE >= 199209 size_t confstr(int __name, char *__buf, size_t __len); #endif #if __XSI_VISIBLE char *crypt(const char *__key, const char *__salt); #endif #if __XSI_VISIBLE && __XSI_VISIBLE < 700 char *ctermid(char *__s); #endif #if __XSI_VISIBLE && __XSI_VISIBLE < 600 char *cuserid(char *__s); #endif #if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 500) int daemon(int nochdir, int noclose); #endif int dup(int __fildes); int dup2(int __fildes, int __fildes2); #if __GNU_VISIBLE int dup3(int __fildes, int __fildes2, int flags); int eaccess(const char *__path, int __mode); #endif #if __XSI_VISIBLE void encrypt(char *, int); #endif #if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 500) void endusershell(void); #endif #if __GNU_VISIBLE int euidaccess(const char *__path, int __mode); #endif int execl(const char *__path, const char *, ...); int execle(const char *__path, const char *, ...); int execlp(const char *__file, const char *, ...); #if __MISC_VISIBLE int execlpe(const char *__file, const char *, ...); #endif int execv(const char *__path, char * const __argv[]); int execve(const char *__path, char * const __argv[], char * const __envp[]); int execvp(const char *__file, char * const __argv[]); #if __GNU_VISIBLE int execvpe(const char *__file, char * const __argv[], char * const __envp[]); #endif #if __ATFILE_VISIBLE int faccessat(int __dirfd, const char *__path, int __mode, int __flags); #endif #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809 int fchdir(int __fildes); #endif #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809 int fchown(int __fildes, uid_t __owner, gid_t __group); #endif #if __ATFILE_VISIBLE int fchownat(int __dirfd, const char *__path, uid_t __owner, gid_t __group, int __flags); #endif #if __POSIX_VISIBLE >= 200809 int fexecve(int __fd, char * const __argv[], char * const __envp[]); #endif pid_t fork(void); long fpathconf(int __fd, int __name); int fsync(int __fd); #if __POSIX_VISIBLE >= 199309 int fdatasync(int __fd); #endif #if __GNU_VISIBLE char *get_current_dir_name(void); #endif char *getcwd(char *__buf, size_t __size); #if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 500) int getdomainname(char *__name, size_t __len); #endif #if __BSD_VISIBLE int getentropy(void *, size_t); #endif gid_t getegid(void); uid_t geteuid(void); gid_t getgid(void); int getgroups(int __gidsetsize, gid_t __grouplist[]); #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 long gethostid(void); #endif char *getlogin(void); #if defined(_POSIX_THREAD_SAFE_FUNCTIONS) int getlogin_r(char *name, size_t namesize); #endif #if __BSD_VISIBLE || (__XSI_VISIBLE && __POSIX_VISIBLE < 200112) char *getpass(const char *__prompt); int getpagesize(void); #endif #if __BSD_VISIBLE int getpeereid(int, uid_t *, gid_t *); #endif #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 4 pid_t getpgid(pid_t); #endif pid_t getpgrp(void); pid_t getpid(void); pid_t getppid(void); #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 4 pid_t getsid(pid_t); #endif uid_t getuid(void); #if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 500) char *getusershell(void); #endif #if __BSD_VISIBLE || (__XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200809) char *getwd(char *__buf); #endif #if __BSD_VISIBLE int iruserok(unsigned long raddr, int superuser, const char *ruser, const char *luser); #endif int isatty(int __fildes); #if __BSD_VISIBLE int issetugid(void); #endif #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809 int lchown(const char *__path, uid_t __owner, gid_t __group); #endif int link(const char *__path1, const char *__path2); #if __ATFILE_VISIBLE int linkat(int __dirfd1, const char *__path1, int __dirfd2, const char *__path2, int __flags); #endif #if __MISC_VISIBLE || __XSI_VISIBLE int nice(int __nice_value); #endif #if !defined(__INSIDE_CYGWIN__) off_t lseek(int __fildes, off_t __offset, int __whence); #endif #if __MISC_VISIBLE || __XSI_VISIBLE >= 4 #define F_ULOCK 0 #define F_LOCK 1 #define F_TLOCK 2 #define F_TEST 3 int lockf(int __fd, int __cmd, off_t __len); #endif long pathconf(const char *__path, int __name); int pause(void); #if __POSIX_VISIBLE >= 199506 int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)); #endif int pipe(int __fildes[2]); #if __GNU_VISIBLE int pipe2(int __fildes[2], int flags); #endif #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 500 ssize_t pread(int __fd, void *__buf, size_t __nbytes, off_t __offset); ssize_t pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset); #endif ssize_t read(int __fd, void *__buf, size_t __nbyte); #if __BSD_VISIBLE int rresvport(int *__alport); int revoke(char *__path); #endif int rmdir(const char *__path); #if __BSD_VISIBLE int ruserok(const char *rhost, int superuser, const char *ruser, const char *luser); #endif #if __BSD_VISIBLE || (__XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112) void *sbrk(ptrdiff_t __incr); #endif #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 int setegid(gid_t __gid); int seteuid(uid_t __uid); #endif int setgid(gid_t __gid); #if __BSD_VISIBLE int setgroups(int ngroups, const gid_t *grouplist); #endif #if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 500) int sethostname(const char *, size_t); #endif int setpgid(pid_t __pid, pid_t __pgid); #if __SVID_VISIBLE || __XSI_VISIBLE >= 500 int setpgrp(void); #endif #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 int setregid(gid_t __rgid, gid_t __egid); int setreuid(uid_t __ruid, uid_t __euid); #endif pid_t setsid(void); int setuid(uid_t __uid); #if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 500) void setusershell(void); #endif unsigned sleep(unsigned int __seconds); #if __XSI_VISIBLE void swab(const void * __restrict, void * __restrict, ssize_t); #endif long sysconf(int __name); pid_t tcgetpgrp(int __fildes); int tcsetpgrp(int __fildes, pid_t __pgrp_id); char *ttyname(int __fildes); int ttyname_r(int, char *, size_t); int unlink(const char *__path); #if __XSI_VISIBLE >= 500 && __POSIX_VISIBLE < 200809 || __BSD_VISIBLE int usleep(useconds_t __useconds); #endif #if __BSD_VISIBLE int vhangup(void); #endif ssize_t write(int __fd, const void *__buf, size_t __nbyte); extern char *optarg; /* getopt(3) external variables */ extern int optind, opterr, optopt; int getopt(int, char *const[], const char *); extern int optreset; /* getopt(3) external variable */ #if __BSD_VISIBLE || (__XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200809) pid_t vfork(void); #endif #ifdef _LIBC /* Provide prototypes for most of the _ names that are provided in newlib for some compilers. */ int close(int __fildes); pid_t fork(void); pid_t getpid(void); int isatty(int __fildes); int link(const char *__path1, const char *__path2); _off_t lseek(int __fildes, _off_t __offset, int __whence); void *sbrk(ptrdiff_t __incr); int unlink(const char *__path); #endif #if __LARGEFILE64_VISIBLE _off64_t lseek64(int __filedes, _off64_t __offset, int __whence); #endif #if !defined(__INSIDE_CYGWIN__) #if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500 int ftruncate(int __fd, off_t __length); #endif #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 500 int truncate(const char *, off_t __length); #endif #endif #if __BSD_VISIBLE || __POSIX_VISIBLE < 200112 int getdtablesize(void); #endif #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 500 useconds_t ualarm(useconds_t __useconds, useconds_t __interval); #endif #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500 #if !(defined(_WINSOCK_H) || defined(_WINSOCKAPI_) || defined(__USE_W32_SOCKETS)) /* winsock[2].h defines as __stdcall, and with int as 2nd arg */ int gethostname(char *__name, size_t __len); #endif #endif #if __MISC_VISIBLE int setdtablesize(int); #endif #if __BSD_VISIBLE || __XSI_VISIBLE >= 500 void sync(void); #endif #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 4 ssize_t readlink(const char * __restrict __path, char * __restrict __buf, size_t __buflen); int symlink(const char *__name1, const char *__name2); #endif #if __ATFILE_VISIBLE ssize_t readlinkat(int __dirfd1, const char *__restrict __path, char *__restrict __buf, size_t __buflen); int symlinkat(const char *, int, const char *); int unlinkat(int, const char *, int); #endif #define F_OK 0 #define R_OK 4 #define W_OK 2 #define X_OK 1 #define SEEK_SET 0 #define SEEK_CUR 1 #define SEEK_END 2 #if __GNU_VISIBLE || __POSIX_VISIBLE >= 202405 #define SEEK_DATA 3 #define SEEK_HOLE 4 #endif #include #define STDIN_FILENO 0 /* standard input file descriptor */ #define STDOUT_FILENO 1 /* standard output file descriptor */ #define STDERR_FILENO 2 /* standard error file descriptor */ #ifndef _POSIX2_RE_DUP_MAX /* The maximum number of repeated occurrences of a regular expression * permitted when using the interval notation `\{M,N\}'. */ #define _POSIX2_RE_DUP_MAX 255 #endif /* _POSIX2_RE_DUP_MAX */ /* * Flag values for posix_close per IEEE Std 1003.1, 2024 Edition */ #if __POSIX_VISIBLE >= 202405 #define POSIX_CLOSE_RESTART 1 #endif /* * sysconf values per IEEE Std 1003.1, 2008 Edition */ #define _SC_ARG_MAX 0 #define _SC_CHILD_MAX 1 #define _SC_CLK_TCK 2 #define _SC_NGROUPS_MAX 3 #define _SC_OPEN_MAX 4 #define _SC_JOB_CONTROL 5 #define _SC_SAVED_IDS 6 #define _SC_VERSION 7 #define _SC_PAGESIZE 8 #define _SC_PAGE_SIZE _SC_PAGESIZE /* These are non-POSIX values we accidentally introduced in 2000 without guarding them. Keeping them unguarded for backward compatibility. */ #define _SC_NPROCESSORS_CONF 9 #define _SC_NPROCESSORS_ONLN 10 #define _SC_PHYS_PAGES 11 #define _SC_AVPHYS_PAGES 12 /* End of non-POSIX values. */ #define _SC_MQ_OPEN_MAX 13 #define _SC_MQ_PRIO_MAX 14 #define _SC_RTSIG_MAX 15 #define _SC_SEM_NSEMS_MAX 16 #define _SC_SEM_VALUE_MAX 17 #define _SC_SIGQUEUE_MAX 18 #define _SC_TIMER_MAX 19 #define _SC_TZNAME_MAX 20 #define _SC_ASYNCHRONOUS_IO 21 #define _SC_FSYNC 22 #define _SC_MAPPED_FILES 23 #define _SC_MEMLOCK 24 #define _SC_MEMLOCK_RANGE 25 #define _SC_MEMORY_PROTECTION 26 #define _SC_MESSAGE_PASSING 27 #define _SC_PRIORITIZED_IO 28 #define _SC_REALTIME_SIGNALS 29 #define _SC_SEMAPHORES 30 #define _SC_SHARED_MEMORY_OBJECTS 31 #define _SC_SYNCHRONIZED_IO 32 #define _SC_TIMERS 33 #define _SC_AIO_LISTIO_MAX 34 #define _SC_AIO_MAX 35 #define _SC_AIO_PRIO_DELTA_MAX 36 #define _SC_DELAYTIMER_MAX 37 #define _SC_THREAD_KEYS_MAX 38 #define _SC_THREAD_STACK_MIN 39 #define _SC_THREAD_THREADS_MAX 40 #define _SC_TTY_NAME_MAX 41 #define _SC_THREADS 42 #define _SC_THREAD_ATTR_STACKADDR 43 #define _SC_THREAD_ATTR_STACKSIZE 44 #define _SC_THREAD_PRIORITY_SCHEDULING 45 #define _SC_THREAD_PRIO_INHERIT 46 /* _SC_THREAD_PRIO_PROTECT was _SC_THREAD_PRIO_CEILING in early drafts */ #define _SC_THREAD_PRIO_PROTECT 47 #define _SC_THREAD_PRIO_CEILING _SC_THREAD_PRIO_PROTECT #define _SC_THREAD_PROCESS_SHARED 48 #define _SC_THREAD_SAFE_FUNCTIONS 49 #define _SC_GETGR_R_SIZE_MAX 50 #define _SC_GETPW_R_SIZE_MAX 51 #define _SC_LOGIN_NAME_MAX 52 #define _SC_THREAD_DESTRUCTOR_ITERATIONS 53 #define _SC_ADVISORY_INFO 54 #define _SC_ATEXIT_MAX 55 #define _SC_BARRIERS 56 #define _SC_BC_BASE_MAX 57 #define _SC_BC_DIM_MAX 58 #define _SC_BC_SCALE_MAX 59 #define _SC_BC_STRING_MAX 60 #define _SC_CLOCK_SELECTION 61 #define _SC_COLL_WEIGHTS_MAX 62 #define _SC_CPUTIME 63 #define _SC_EXPR_NEST_MAX 64 #define _SC_HOST_NAME_MAX 65 #define _SC_IOV_MAX 66 #define _SC_IPV6 67 #define _SC_LINE_MAX 68 #define _SC_MONOTONIC_CLOCK 69 #define _SC_RAW_SOCKETS 70 #define _SC_READER_WRITER_LOCKS 71 #define _SC_REGEXP 72 #define _SC_RE_DUP_MAX 73 #define _SC_SHELL 74 #define _SC_SPAWN 75 #define _SC_SPIN_LOCKS 76 #define _SC_SPORADIC_SERVER 77 #define _SC_SS_REPL_MAX 78 #define _SC_SYMLOOP_MAX 79 #define _SC_THREAD_CPUTIME 80 #define _SC_THREAD_SPORADIC_SERVER 81 #define _SC_TIMEOUTS 82 #define _SC_TRACE 83 #define _SC_TRACE_EVENT_FILTER 84 #define _SC_TRACE_EVENT_NAME_MAX 85 #define _SC_TRACE_INHERIT 86 #define _SC_TRACE_LOG 87 #define _SC_TRACE_NAME_MAX 88 #define _SC_TRACE_SYS_MAX 89 #define _SC_TRACE_USER_EVENT_MAX 90 #define _SC_TYPED_MEMORY_OBJECTS 91 #define _SC_V7_ILP32_OFF32 92 #define _SC_V6_ILP32_OFF32 _SC_V7_ILP32_OFF32 #define _SC_XBS5_ILP32_OFF32 _SC_V7_ILP32_OFF32 #define _SC_V7_ILP32_OFFBIG 93 #define _SC_V6_ILP32_OFFBIG _SC_V7_ILP32_OFFBIG #define _SC_XBS5_ILP32_OFFBIG _SC_V7_ILP32_OFFBIG #define _SC_V7_LP64_OFF64 94 #define _SC_V6_LP64_OFF64 _SC_V7_LP64_OFF64 #define _SC_XBS5_LP64_OFF64 _SC_V7_LP64_OFF64 #define _SC_V7_LPBIG_OFFBIG 95 #define _SC_V6_LPBIG_OFFBIG _SC_V7_LPBIG_OFFBIG #define _SC_XBS5_LPBIG_OFFBIG _SC_V7_LPBIG_OFFBIG #define _SC_XOPEN_CRYPT 96 #define _SC_XOPEN_ENH_I18N 97 #define _SC_XOPEN_LEGACY 98 #define _SC_XOPEN_REALTIME 99 #define _SC_STREAM_MAX 100 #define _SC_PRIORITY_SCHEDULING 101 #define _SC_XOPEN_REALTIME_THREADS 102 #define _SC_XOPEN_SHM 103 #define _SC_XOPEN_STREAMS 104 #define _SC_XOPEN_UNIX 105 #define _SC_XOPEN_VERSION 106 #define _SC_2_CHAR_TERM 107 #define _SC_2_C_BIND 108 #define _SC_2_C_DEV 109 #define _SC_2_FORT_DEV 110 #define _SC_2_FORT_RUN 111 #define _SC_2_LOCALEDEF 112 #define _SC_2_PBS 113 #define _SC_2_PBS_ACCOUNTING 114 #define _SC_2_PBS_CHECKPOINT 115 #define _SC_2_PBS_LOCATE 116 #define _SC_2_PBS_MESSAGE 117 #define _SC_2_PBS_TRACK 118 #define _SC_2_SW_DEV 119 #define _SC_2_UPE 120 #define _SC_2_VERSION 121 #define _SC_THREAD_ROBUST_PRIO_INHERIT 122 #define _SC_THREAD_ROBUST_PRIO_PROTECT 123 #define _SC_XOPEN_UUCP 124 #define _SC_LEVEL1_ICACHE_SIZE 125 #define _SC_LEVEL1_ICACHE_ASSOC 126 #define _SC_LEVEL1_ICACHE_LINESIZE 127 #define _SC_LEVEL1_DCACHE_SIZE 128 #define _SC_LEVEL1_DCACHE_ASSOC 129 #define _SC_LEVEL1_DCACHE_LINESIZE 130 #define _SC_LEVEL2_CACHE_SIZE 131 #define _SC_LEVEL2_CACHE_ASSOC 132 #define _SC_LEVEL2_CACHE_LINESIZE 133 #define _SC_LEVEL3_CACHE_SIZE 134 #define _SC_LEVEL3_CACHE_ASSOC 135 #define _SC_LEVEL3_CACHE_LINESIZE 136 #define _SC_LEVEL4_CACHE_SIZE 137 #define _SC_LEVEL4_CACHE_ASSOC 138 #define _SC_LEVEL4_CACHE_LINESIZE 139 #define _SC_POSIX_26_VERSION 140 /* * pathconf values per IEEE Std 1003.1, 2008 Edition */ #define _PC_LINK_MAX 0 #define _PC_MAX_CANON 1 #define _PC_MAX_INPUT 2 #define _PC_NAME_MAX 3 #define _PC_PATH_MAX 4 #define _PC_PIPE_BUF 5 #define _PC_CHOWN_RESTRICTED 6 #define _PC_NO_TRUNC 7 #define _PC_VDISABLE 8 #define _PC_ASYNC_IO 9 #define _PC_PRIO_IO 10 #define _PC_SYNC_IO 11 #define _PC_FILESIZEBITS 12 #define _PC_2_SYMLINKS 13 #define _PC_SYMLINK_MAX 14 #define _PC_ALLOC_SIZE_MIN 15 #define _PC_REC_INCR_XFER_SIZE 16 #define _PC_REC_MAX_XFER_SIZE 17 #define _PC_REC_MIN_XFER_SIZE 18 #define _PC_REC_XFER_ALIGN 19 #define _PC_TIMESTAMP_RESOLUTION 20 /* * confstr values per IEEE Std 1003.1, 2004 Edition */ /* Only defined on Cygwin and RTEMS for now. */ #if defined(__CYGWIN__) || defined(__rtems__) #define _CS_PATH 0 #define _CS_POSIX_V7_ILP32_OFF32_CFLAGS 1 #define _CS_POSIX_V6_ILP32_OFF32_CFLAGS _CS_POSIX_V7_ILP32_OFF32_CFLAGS #define _CS_XBS5_ILP32_OFF32_CFLAGS _CS_POSIX_V7_ILP32_OFF32_CFLAGS #define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS 2 #define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS _CS_POSIX_V7_ILP32_OFF32_LDFLAGS #define _CS_XBS5_ILP32_OFF32_LDFLAGS _CS_POSIX_V7_ILP32_OFF32_LDFLAGS #define _CS_POSIX_V7_ILP32_OFF32_LIBS 3 #define _CS_POSIX_V6_ILP32_OFF32_LIBS _CS_POSIX_V7_ILP32_OFF32_LIBS #define _CS_XBS5_ILP32_OFF32_LIBS _CS_POSIX_V7_ILP32_OFF32_LIBS #define _CS_XBS5_ILP32_OFF32_LINTFLAGS 4 #define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS 5 #define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS #define _CS_XBS5_ILP32_OFFBIG_CFLAGS _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS #define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS 6 #define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS #define _CS_XBS5_ILP32_OFFBIG_LDFLAGS _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS #define _CS_POSIX_V7_ILP32_OFFBIG_LIBS 7 #define _CS_POSIX_V6_ILP32_OFFBIG_LIBS _CS_POSIX_V7_ILP32_OFFBIG_LIBS #define _CS_XBS5_ILP32_OFFBIG_LIBS _CS_POSIX_V7_ILP32_OFFBIG_LIBS #define _CS_XBS5_ILP32_OFFBIG_LINTFLAGS 8 #define _CS_POSIX_V7_LP64_OFF64_CFLAGS 9 #define _CS_POSIX_V6_LP64_OFF64_CFLAGS _CS_POSIX_V7_LP64_OFF64_CFLAGS #define _CS_XBS5_LP64_OFF64_CFLAGS _CS_POSIX_V7_LP64_OFF64_CFLAGS #define _CS_POSIX_V7_LP64_OFF64_LDFLAGS 10 #define _CS_POSIX_V6_LP64_OFF64_LDFLAGS _CS_POSIX_V7_LP64_OFF64_LDFLAGS #define _CS_XBS5_LP64_OFF64_LDFLAGS _CS_POSIX_V7_LP64_OFF64_LDFLAGS #define _CS_POSIX_V7_LP64_OFF64_LIBS 11 #define _CS_POSIX_V6_LP64_OFF64_LIBS _CS_POSIX_V7_LP64_OFF64_LIBS #define _CS_XBS5_LP64_OFF64_LIBS _CS_POSIX_V7_LP64_OFF64_LIBS #define _CS_XBS5_LP64_OFF64_LINTFLAGS 12 #define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS 13 #define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS #define _CS_XBS5_LPBIG_OFFBIG_CFLAGS _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS #define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS 14 #define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS #define _CS_XBS5_LPBIG_OFFBIG_LDFLAGS _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS #define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS 15 #define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS _CS_POSIX_V7_LPBIG_OFFBIG_LIBS #define _CS_XBS5_LPBIG_OFFBIG_LIBS _CS_POSIX_V7_LPBIG_OFFBIG_LIBS #define _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS 16 #define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS 17 #define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS #define _CS_XBS5_WIDTH_RESTRICTED_ENVS _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS #define _CS_POSIX_V7_THREADS_CFLAGS 18 #define _CS_POSIX_V7_THREADS_LDFLAGS 19 #define _CS_V7_ENV 20 #define _CS_V6_ENV _CS_V7_ENV #define _CS_LFS_CFLAGS 21 #define _CS_LFS_LDFLAGS 22 #define _CS_LFS_LIBS 23 #define _CS_LFS_LINTFLAGS 24 #endif _END_STD_C #if __SSP_FORTIFY_LEVEL > 0 #include #endif #endif /* _SYS_UNISTD_H */ picolibc-1.8.11/libc/include/sys/utime.h000066400000000000000000000034761513574234600200600ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SYS_UTIME_H #define _SYS_UTIME_H /* This is a dummy file, not customized for any particular system. If there is a utime.h in libc/sys/SYSDIR/sys, it will override this one. */ #include _BEGIN_STD_C struct utimbuf { time_t actime; time_t modtime; }; _END_STD_C #endif /* _SYS_UTIME_H */ picolibc-1.8.11/libc/include/sys/wait.h000066400000000000000000000032541513574234600176730ustar00rootroot00000000000000/* Copyright (c) 1982, 1986, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SYS_WAIT_H #define _SYS_WAIT_H #include _BEGIN_STD_C #include #include pid_t wait(int *); pid_t waitpid(pid_t, int *, int); _END_STD_C #endif picolibc-1.8.11/libc/include/tar.h000066400000000000000000000026771513574234600167070ustar00rootroot00000000000000/* Copyright (c) 2007 Ralf Corsepius */ /* * tar.h */ #ifndef _TAR_H #define _TAR_H #include /* General definitions */ #define TMAGIC "ustar" /* ustar plus null byte. */ #define TMAGLEN 6 /* Length of the above. */ #define TVERSION "00" /* 00 without a null byte. */ #define TVERSLEN 2 /* Length of the above. */ /* Typeflag field definitions */ #define REGTYPE '0' /* Regular file. */ #define AREGTYPE '\0' /* Regular file. */ #define LNKTYPE '1' /* Link. */ #define SYMTYPE '2' /* Symbolic link. */ #define CHRTYPE '3' /* Character special. */ #define BLKTYPE '4' /* Block special. */ #define DIRTYPE '5' /* Directory. */ #define FIFOTYPE '6' /* FIFO special. */ #define CONTTYPE '7' /* Reserved. */ /* Mode field bit definitions (octal) */ #define TSUID 04000 /* Set UID on execution. */ #define TSGID 02000 /* Set GID on execution. */ #if __XSI_VISIBLE || __POSIX_VISIBLE < 200112 #define TSVTX 01000 /* On directories, restricted deletion flag. */ #endif #define TUREAD 00400 /* Read by owner. */ #define TUWRITE 00200 /* Write by owner. */ #define TUEXEC 00100 /* Execute/search by owner. */ #define TGREAD 00040 /* Read by group. */ #define TGWRITE 00020 /* Write by group. */ #define TGEXEC 00010 /* Execute/search by group. */ #define TOREAD 00004 /* Read by other. */ #define TOWRITE 00002 /* Write by other. */ #define TOEXEC 00001 /* Execute/search by other. */ #endif picolibc-1.8.11/libc/include/termios.h000066400000000000000000000034501513574234600175710ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include _BEGIN_STD_C #include _END_STD_C picolibc-1.8.11/libc/include/time.h000066400000000000000000000170461513574234600170530ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * time.h * * Struct and function declarations for dealing with time. */ #ifndef _TIME_H_ #define _TIME_H_ #include #define __need_size_t #define __need_NULL #include #include #include _BEGIN_STD_C #ifndef _CLOCKS_PER_SEC_ #define _CLOCKS_PER_SEC_ 1000000 #endif #ifndef CLOCKS_PER_SEC #define CLOCKS_PER_SEC _CLOCKS_PER_SEC_ #endif #ifndef TIME_UTC #define TIME_UTC 1 #endif #ifndef _CLOCK_T_DECLARED typedef _CLOCK_T_ clock_t; #define _CLOCK_T_DECLARED #endif struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; #ifdef __TM_GMTOFF long __TM_GMTOFF; #endif #ifdef __TM_ZONE const char *__TM_ZONE; #endif }; #if __POSIX_VISIBLE #ifndef CLK_TCK #define CLK_TCK CLOCKS_PER_SEC #endif /* Flag indicating time is "absolute" with respect to the clock associated with a time. Value 4 is historic. */ #define TIMER_ABSTIME 4 #include #ifndef _CLOCKID_T_DECLARED typedef __clockid_t clockid_t; #define _CLOCKID_T_DECLARED #endif #ifndef _TIMER_T_DECLARED typedef __timer_t timer_t; #define _TIMER_T_DECLARED #endif /* * Structure defined by POSIX.1b to be like a itimerval, but with * timespecs. Used in the timer_*() system calls. */ struct itimerspec { struct timespec it_interval; struct timespec it_value; }; #ifndef _PID_T_DECLARED typedef __pid_t pid_t; /* process id */ #define _PID_T_DECLARED #endif #endif #if __GNU_VISIBLE #define CLOCK_REALTIME_COARSE (0) #endif #define CLOCK_REALTIME (1) /* Manifest Constants, P1003.4b/D8, p. 55 */ #if defined(_POSIX_CPUTIME) /* When used in a clock or timer function call, this is interpreted as the identifier of the CPU_time clock associated with the PROCESS making the function call. */ #define CLOCK_PROCESS_CPUTIME_ID (2) #endif #if defined(_POSIX_THREAD_CPUTIME) /* When used in a clock or timer function call, this is interpreted as the identifier of the CPU_time clock associated with the THREAD making the function call. */ #define CLOCK_THREAD_CPUTIME_ID (3) #endif #if defined(_POSIX_MONOTONIC_CLOCK) /* The identifier for the system-wide monotonic clock, which is defined * as a clock whose value cannot be set via clock_settime() and which * cannot have backward clock jumps. */ #define CLOCK_MONOTONIC (4) #endif #if __GNU_VISIBLE #define CLOCK_MONOTONIC_RAW (5) #define CLOCK_MONOTONIC_COARSE (6) #define CLOCK_BOOTTIME (7) #define CLOCK_REALTIME_ALARM (8) #define CLOCK_BOOTTIME_ALARM (9) #endif /* defines for the opengroup specifications Derived from Issue 1 of the SVID. */ #if __SVID_VISIBLE || __XSI_VISIBLE extern long _timezone; extern int _daylight; #endif #if __POSIX_VISIBLE extern char *tzname[2]; #endif /* __POSIX_VISIBLE */ char *asctime(const struct tm *_tblock); #if __POSIX_VISIBLE #define __ASCTIME_SIZE 26 char *asctime_r(const struct tm * __restrict, char[__restrict_arr __min_size(__ASCTIME_SIZE)]); #endif clock_t clock(void); #if defined(_POSIX_CPUTIME) int clock_getcpuclockid(pid_t pid, clockid_t *clock_id); #endif /* _POSIX_CPUTIME */ #if __POSIX_VISIBLE int clock_getres(clockid_t clock_id, struct timespec *res); int clock_gettime(clockid_t clock_id, struct timespec *tp); int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp); int clock_settime(clockid_t clock_id, const struct timespec *tp); #endif char *ctime(const time_t *_time); #if __POSIX_VISIBLE char *ctime_r(const time_t *, char[__restrict_arr __min_size(__ASCTIME_SIZE)]); #endif double difftime(time_t _time2, time_t _time1); #if __XSI_VISIBLE >= 4 extern int getdate_err; struct tm *getdate(const char *); #endif /* __XSI_VISIBLE >= 4 */ #if __GNU_VISIBLE int getdate_r(const char *, struct tm *); #endif /* __GNU_VISIBLE */ struct tm *gmtime(const time_t *_timer); #if __POSIX_VISIBLE || __ZEPHYR_VISIBLE struct tm *gmtime_r(const time_t * __restrict, struct tm * __restrict); #endif struct tm *localtime(const time_t *_timer); #if __POSIX_VISIBLE struct tm *localtime_r(const time_t * __restrict, struct tm * __restrict); #endif time_t mktime(struct tm *_timeptr); int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); size_t strftime(char * __restrict _s, size_t _maxsize, const char * __restrict _fmt, const struct tm * __restrict _t); int timespec_get(struct timespec *_ts, int _base); #if __POSIX_VISIBLE size_t strftime_l(char * __restrict _s, size_t _maxsize, const char *__restrict _fmt, const struct tm * __restrict _t, locale_t _l); #endif #if __XSI_VISIBLE char *strptime(const char * __restrict, const char * __restrict, struct tm * __restrict); #endif #if __GNU_VISIBLE char *strptime_l(const char * __restrict, const char * __restrict, struct tm * __restrict, locale_t); #endif time_t time(time_t *_timer); #if __BSD_VISIBLE || __SVID_VISIBLE || __GNU_VISIBLE time_t timegm(struct tm *_timeptr); #endif #if __POSIX_VISIBLE struct sigevent; int timer_create(clockid_t clock_id, struct sigevent * __restrict evp, timer_t * __restrict timerid); int timer_delete(timer_t timerid); int timer_getoverrun(timer_t timerid); int timer_gettime(timer_t timerid, struct itimerspec *value); int timer_settime(timer_t timerid, int flags, const struct itimerspec * __restrict value, struct itimerspec * __restrict ovalue); #endif void tzset(void); #if __STDC_WANT_LIB_EXT1__ == 1 #ifndef __STDC_LIB_EXT1__ #define __STDC_LIB_EXT1__ 1 #endif #include #ifndef _ERRNO_T_DEFINED typedef __errno_t errno_t; #define _ERRNO_T_DEFINED #endif #ifndef _RSIZE_T_DEFINED typedef __rsize_t rsize_t; #define _RSIZE_T_DEFINED #endif #endif _END_STD_C #endif /* _TIME_H_ */ picolibc-1.8.11/libc/include/uchar.h000066400000000000000000000053141513574234600172120ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _UCHAR_H_ #define _UCHAR_H_ #include #include #include #define __need_size_t #include #define __STDC_VERSION_UCHAR_H_ 202311L _BEGIN_STD_C #ifndef _MBSTATE_DECLARED typedef _mbstate_t mbstate_t; #define _MBSTATE_DECLARED #endif #ifndef __cpp_char8_t typedef unsigned char char8_t; #endif #if !defined __cplusplus || __cplusplus < 201103L typedef __uint_least16_t char16_t; typedef __uint_least32_t char32_t; #endif size_t mbrtoc8(char8_t * __restrict pc8, const char * __restrict s, size_t n, _mbstate_t * __restrict ps); size_t c8rtomb(char * __restrict s, char8_t c8, _mbstate_t * __restrict ps); size_t mbrtoc16(char16_t * __restrict pc16, const char * __restrict s, size_t n, _mbstate_t * __restrict ps); size_t c16rtomb(char * __restrict s, char16_t c16, _mbstate_t * __restrict ps); size_t mbrtoc32(char32_t * __restrict pc32, const char * __restrict s, size_t n, _mbstate_t * __restrict ps); size_t c32rtomb(char * __restrict s, char32_t c32, _mbstate_t * __restrict ps); _END_STD_C #endif /* _UCHAR_H_ */ picolibc-1.8.11/libc/include/unctrl.h000066400000000000000000000036211513574234600174160ustar00rootroot00000000000000/* From curses.h. */ /* * Copyright (c) 1981, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef _UNCTRL_H_ #define _UNCTRL_H_ #include #define unctrl(c) __unctrl[(c) & 0xff] #define unctrllen(ch) __unctrllen[(ch) & 0xff] extern const char * const __unctrl[256]; /* Control strings. */ extern const char __unctrllen[256]; /* Control strings length. */ #endif /* _UNCTRL_H_ */ picolibc-1.8.11/libc/include/unistd.h000066400000000000000000000034661513574234600174240ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _UNISTD_H_ #define _UNISTD_H_ #include #endif /* _UNISTD_H_ */ picolibc-1.8.11/libc/include/utime.h000066400000000000000000000035611513574234600172350ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include _BEGIN_STD_C /* The utime function is defined in libc/sys//sys if it exists. */ #include _END_STD_C picolibc-1.8.11/libc/include/utmp.h000066400000000000000000000034461513574234600171010ustar00rootroot00000000000000/* Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. All or some portions of this file are derived from material licensed to the University of California by American Telephone and Telegraph Co. or Unix System Laboratories, Inc. and are reproduced herein with the permission of UNIX System Laboratories, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include _BEGIN_STD_C #include _END_STD_C picolibc-1.8.11/libc/include/wchar.h000066400000000000000000000240271513574234600172160ustar00rootroot00000000000000/* Copyright (c) 2001 Alexey Zelkin 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. */ #ifndef _WCHAR_H_ #define _WCHAR_H_ #include #define __need_size_t #define __need_wchar_t #define __need_wint_t #define __need_NULL #include /* For _mbstate_t definition. */ #include #define __need___va_list #include #ifndef WEOF #define WEOF ((wint_t) - 1) #endif /* This must match definition in */ #ifndef WCHAR_MIN #ifdef __WCHAR_MIN__ #define WCHAR_MIN __WCHAR_MIN__ #elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0) #define WCHAR_MIN (0 + L'\0') #else #define WCHAR_MIN (-0x7fffffff - 1 + L'\0') #endif #endif /* This must match definition in */ #ifndef WCHAR_MAX #ifdef __WCHAR_MAX__ #define WCHAR_MAX __WCHAR_MAX__ #elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0) #define WCHAR_MAX (0xffffffffu + L'\0') #else #define WCHAR_MAX (0x7fffffff + L'\0') #endif #endif #if __POSIX_VISIBLE >= 200809 #include #endif _BEGIN_STD_C #ifndef ___FILE_DECLARED typedef struct __file __FILE; #define ___FILE_DECLARED #endif #if __POSIX_VISIBLE >= 200809 || _XSI_VISIBLE #ifndef _FILE_DECLARED typedef __FILE FILE; #define _FILE_DECLARED #endif #ifndef _WCTYPE_DECLARED typedef __wctype_t wctype_t; #define _WCTYPE_DECLARED #endif #endif /* As required by C, declare tm as incomplete type. The actual definition is in time.h. */ struct tm; #ifndef _MBSTATE_DECLARED typedef _mbstate_t mbstate_t; #define _MBSTATE_DECLARED #endif wint_t btowc(int); wint_t fgetwc(__FILE *); #if __GNU_VISIBLE wint_t fgetwc_unlocked(__FILE *); #endif wchar_t *fgetws(wchar_t * __restrict, int, __FILE * __restrict); #if __GNU_VISIBLE wchar_t *fgetws_unlocked(wchar_t * __restrict, int, __FILE * __restrict); #endif wint_t fputwc(wchar_t, __FILE *); #if __GNU_VISIBLE wint_t fputwc_unlocked(wchar_t, __FILE *); #endif int fputws(const wchar_t * __restrict, __FILE * __restrict); #if __GNU_VISIBLE int fputws_unlocked(const wchar_t * __restrict, __FILE * __restrict); #endif #if __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE >= 500 int fwide(__FILE *, int); #endif #if __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE >= 500 int fwprintf(__FILE * __restrict, const wchar_t * __restrict, ...); int fwscanf(__FILE * __restrict, const wchar_t * __restrict, ...); #endif wint_t getwc(__FILE *); #if __GNU_VISIBLE wint_t getwc_unlocked(__FILE *); #endif wint_t getwchar(void); #if __GNU_VISIBLE wint_t getwchar_unlocked(void); #endif size_t mbrlen(const char * __restrict, size_t, mbstate_t * __restrict); size_t mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, mbstate_t * __restrict); int mbsinit(const mbstate_t *); #if __POSIX_VISIBLE >= 200809 size_t mbsnrtowcs(wchar_t * __restrict, const char ** __restrict, size_t, size_t, mbstate_t * __restrict); #endif size_t mbsrtowcs(wchar_t * __restrict, const char ** __restrict, size_t, mbstate_t * __restrict); #if __POSIX_VISIBLE >= 200809 __FILE *open_wmemstream(wchar_t **, size_t *); #endif wint_t putwc(wchar_t, __FILE *); #if __GNU_VISIBLE wint_t putwc_unlocked(wchar_t, __FILE *); #endif wint_t putwchar(wchar_t); #if __GNU_VISIBLE wint_t putwchar_unlocked(wchar_t); #endif #if __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE >= 500 int swprintf(wchar_t * __restrict, size_t, const wchar_t * __restrict, ...); int swscanf(const wchar_t * __restrict, const wchar_t * __restrict, ...); #endif wint_t ungetwc(wint_t wc, __FILE *); #if __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE >= 500 int vfwprintf(__FILE * __restrict, const wchar_t * __restrict, __gnuc_va_list); int vfwscanf(__FILE * __restrict, const wchar_t * __restrict, __gnuc_va_list); int vswprintf(wchar_t * __restrict, size_t, const wchar_t * __restrict, __gnuc_va_list); int vswscanf(const wchar_t * __restrict, const wchar_t * __restrict, __gnuc_va_list); int vwprintf(const wchar_t * __restrict, __gnuc_va_list); int vwscanf(const wchar_t * __restrict, __gnuc_va_list); #endif #if __POSIX_VISIBLE >= 200809 wchar_t *wcpcpy(wchar_t * __restrict, const wchar_t * __restrict); wchar_t *wcpncpy(wchar_t * __restrict, const wchar_t * __restrict, size_t); #endif size_t wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict); #if __POSIX_VISIBLE >= 200809 int wcscasecmp(const wchar_t *, const wchar_t *); int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); #endif wchar_t *wcscat(wchar_t * __restrict, const wchar_t * __restrict); wchar_t *wcschr(const wchar_t *, wchar_t); int wcscmp(const wchar_t *, const wchar_t *); int wcscoll(const wchar_t *, const wchar_t *); #if __POSIX_VISIBLE >= 200809 int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); #endif wchar_t *wcscpy(wchar_t * __restrict, const wchar_t * __restrict); size_t wcscspn(const wchar_t *, const wchar_t *); #if __POSIX_VISIBLE >= 200809 void free(void *) __nothrow; wchar_t *wcsdup(const wchar_t *) __malloc_like __warn_unused_result; #endif size_t wcsftime(wchar_t * __restrict, size_t, const wchar_t * __restrict, const struct tm * __restrict); #if __GNU_VISIBLE size_t wcsftime_l(wchar_t * __restrict, size_t, const wchar_t * __restrict, const struct tm * __restrict, locale_t); #endif #if __BSD_VISIBLE size_t wcslcat(wchar_t *, const wchar_t *, size_t); size_t wcslcpy(wchar_t *, const wchar_t *, size_t); #endif size_t wcslen(const wchar_t *); #if __POSIX_VISIBLE >= 200809 int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); #endif wchar_t *wcsncat(wchar_t * __restrict, const wchar_t * __restrict, size_t); int wcsncmp(const wchar_t *, const wchar_t *, size_t); wchar_t *wcsncpy(wchar_t * __restrict, const wchar_t * __restrict, size_t); #if __POSIX_VISIBLE >= 200809 size_t wcsnlen(const wchar_t *, size_t); size_t wcsnrtombs(char * __restrict, const wchar_t ** __restrict, size_t, size_t, mbstate_t * __restrict); #endif wchar_t *wcspbrk(const wchar_t *, const wchar_t *); wchar_t *wcsrchr(const wchar_t *, wchar_t); size_t wcsrtombs(char *__restrict, const wchar_t **__restrict, size_t, mbstate_t *__restrict); size_t wcsspn(const wchar_t *, const wchar_t *); wchar_t *wcsstr(const wchar_t * __restrict, const wchar_t * __restrict); double wcstod(const wchar_t *__restrict, wchar_t **__restrict); #if __GNU_VISIBLE double wcstod_l(const wchar_t *, wchar_t **, locale_t); #endif #if __ISO_C_VISIBLE >= 1999 float wcstof(const wchar_t * __restrict, wchar_t ** __restrict); #endif #if __GNU_VISIBLE float wcstof_l(const wchar_t *, wchar_t **, locale_t); #endif wchar_t *wcstok(wchar_t * __restrict, const wchar_t * __restrict, wchar_t ** __restrict); long wcstol(const wchar_t *__restrict, wchar_t **__restrict, int); #if __GNU_VISIBLE long wcstol_l(const wchar_t * __restrict, wchar_t ** __restrict, int, locale_t); #endif #if __ISO_C_VISIBLE >= 1999 && defined(__HAVE_LONG_DOUBLE) long double wcstold(const wchar_t *, wchar_t **); #endif #if __GNU_VISIBLE && defined(__HAVE_LONG_DOUBLE) long double wcstold_l(const wchar_t *, wchar_t **, locale_t); #endif #if __ISO_C_VISIBLE >= 1999 long long wcstoll(const wchar_t * __restrict, wchar_t ** __restrict, int); #endif #if __GNU_VISIBLE long long wcstoll_l(const wchar_t * __restrict, wchar_t ** __restrict, int, locale_t); #endif unsigned long wcstoul(const wchar_t * __restrict, wchar_t ** __restrict, int); #if __GNU_VISIBLE unsigned long wcstoul_l(const wchar_t * __restrict, wchar_t ** __restrict, int, locale_t); #endif #if __ISO_C_VISIBLE >= 1999 unsigned long long wcstoull(const wchar_t * __restrict, wchar_t ** __restrict, int); #endif #if __GNU_VISIBLE unsigned long long wcstoull_l(const wchar_t * __restrict, wchar_t ** __restrict, int, locale_t); #endif #if __XSI_VISIBLE int wcswidth(const wchar_t *, size_t); #endif size_t wcsxfrm(wchar_t * __restrict, const wchar_t * __restrict, size_t); #if __POSIX_VISIBLE >= 200809 size_t wcsxfrm_l(wchar_t * __restrict, const wchar_t * __restrict, size_t, locale_t); #endif int wctob(wint_t); #if __XSI_VISIBLE int wcwidth(const wchar_t); #endif wchar_t *wmemchr(const wchar_t *, wchar_t, size_t); int wmemcmp(const wchar_t *, const wchar_t *, size_t); wchar_t *wmemcpy(wchar_t * __restrict, const wchar_t * __restrict, size_t); wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t); #if __GNU_VISIBLE wchar_t *wmempcpy(wchar_t * __restrict, const wchar_t * __restrict, size_t); #endif wchar_t *wmemset(wchar_t *, wchar_t, size_t); #if __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE >= 500 int wprintf(const wchar_t * __restrict, ...); int wscanf(const wchar_t * __restrict, ...); #endif #if __STDC_WANT_LIB_EXT1__ == 1 #ifndef __STDC_LIB_EXT1__ #define __STDC_LIB_EXT1__ 1 #endif #include #ifndef _ERRNO_T_DEFINED typedef __errno_t errno_t; #define _ERRNO_T_DEFINED #endif #ifndef _RSIZE_T_DEFINED typedef __rsize_t rsize_t; #define _RSIZE_T_DEFINED #endif #endif _END_STD_C #if __SSP_FORTIFY_LEVEL > 0 #include #endif #endif /* _WCHAR_H_ */ picolibc-1.8.11/libc/include/wctype.h000066400000000000000000000035141513574234600174230ustar00rootroot00000000000000/* Copyright (c) 2002 Jeff Johnston */ #ifndef _WCTYPE_H_ #define _WCTYPE_H_ #include #include #define __need_wint_t #include #if __POSIX_VISIBLE >= 200809 #include #endif #ifndef WEOF #define WEOF ((wint_t) - 1) #endif _BEGIN_STD_C #ifndef _WCTYPE_DECLARED typedef __wctype_t wctype_t; #define _WCTYPE_DECLARED #endif #ifndef _WCTRANS_DECLARED typedef int wctrans_t; #define _WCTRANS_DECLARED #endif int iswalnum(wint_t); int iswalpha(wint_t); #if __ISO_C_VISIBLE >= 1999 int iswblank(wint_t); #endif int iswcntrl(wint_t); int iswctype(wint_t, wctype_t); int iswdigit(wint_t); int iswgraph(wint_t); int iswlower(wint_t); int iswprint(wint_t); int iswpunct(wint_t); int iswspace(wint_t); int iswupper(wint_t); int iswxdigit(wint_t); wint_t towctrans(wint_t, wctrans_t); wint_t towupper(wint_t); wint_t towlower(wint_t); wctrans_t wctrans(const char *); wctype_t wctype(const char *); #if __POSIX_VISIBLE >= 200809 int iswalnum_l(wint_t, locale_t); int iswalpha_l(wint_t, locale_t); int iswblank_l(wint_t, locale_t); int iswcntrl_l(wint_t, locale_t); int iswctype_l(wint_t, wctype_t, locale_t); int iswdigit_l(wint_t, locale_t); int iswgraph_l(wint_t, locale_t); int iswlower_l(wint_t, locale_t); int iswprint_l(wint_t, locale_t); int iswpunct_l(wint_t, locale_t); int iswspace_l(wint_t, locale_t); int iswupper_l(wint_t, locale_t); int iswxdigit_l(wint_t, locale_t); wint_t towctrans_l(wint_t, wctrans_t, locale_t); wint_t towupper_l(wint_t, locale_t); wint_t towlower_l(wint_t, locale_t); wctrans_t wctrans_l(const char *, locale_t); wctype_t wctype_l(const char *, locale_t); #endif _END_STD_C #endif /* _WCTYPE_H_ */ picolibc-1.8.11/libc/include/wordexp.h000066400000000000000000000030731513574234600176000ustar00rootroot00000000000000/* Copyright (C) 2002, 2010 by Red Hat, Incorporated. All rights reserved. * * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #ifndef _WORDEXP_H_ #define _WORDEXP_H_ #include _BEGIN_STD_C struct _wordexp_t { size_t we_wordc; /* Count of words matched by words. */ char **we_wordv; /* Pointer to list of expanded words. */ size_t we_offs; /* Slots to reserve at the beginning of we_wordv. */ }; typedef struct _wordexp_t wordexp_t; #define WRDE_DOOFFS 0x0001 /* Use we_offs. */ #define WRDE_APPEND 0x0002 /* Append to output from previous call. */ #define WRDE_NOCMD 0x0004 /* Don't perform command substitution. */ #define WRDE_REUSE \ 0x0008 /* pwordexp points to a wordexp_t struct returned from \ a previous successful call to wordexp. */ #define WRDE_SHOWERR 0x0010 /* Print error messages to stderr. */ #define WRDE_UNDEF 0x0020 /* Report attempt to expand undefined shell variable. */ enum { WRDE_SUCCESS, WRDE_NOSPACE, WRDE_BADCHAR, WRDE_BADVAL, WRDE_CMDSUB, WRDE_SYNTAX, WRDE_NOSYS }; /* Note: This implementation of wordexp requires a version of bash that supports the --wordexp and --protected arguments to be present on the system. It does not support the WRDE_UNDEF flag. */ int wordexp(const char *__restrict, wordexp_t *__restrict, int); void wordfree(wordexp_t *); _END_STD_C #endif /* _WORDEXP_H_ */ picolibc-1.8.11/libc/libc.in.xml000066400000000000000000000023571513574234600163600ustar00rootroot00000000000000 newlib picolibc-1.8.11/libc/locale/000077500000000000000000000000001513574234600155505ustar00rootroot00000000000000picolibc-1.8.11/libc/locale/CMakeLists.txt000066400000000000000000000035771513574234600203240ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2025 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources( duplocale.c freelocale.c getlocalename_l.c localeconv.c localedata.c locale_ctype_ptr.c locale_ctype_ptr_l.c localedata.c locale_mb_cur_max.c locale_names.c newlocale.c nl_langinfo.c setlocale.c timedata.c uselocale.c ) target_include_directories(c PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") picolibc-1.8.11/libc/locale/duplocale.c000066400000000000000000000034061513574234600176670ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include "locale_private.h" locale_t duplocale(locale_t locale) { if (locale == LC_GLOBAL_LOCALE) locale = __global_locale; return locale; } picolibc-1.8.11/libc/locale/freelocale.c000066400000000000000000000033441513574234600200210ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include "locale_private.h" #ifdef __HAVE_POSIX_LOCALE_API void freelocale(locale_t locale) { (void)locale; } #endif picolibc-1.8.11/libc/locale/getlocalename_l.c000066400000000000000000000036271513574234600210370ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include "locale_private.h" const char * getlocalename_l(int category, locale_t locale) { if (category < LC_ALL || category >= _LC_LAST) { errno = EINVAL; return NULL; } if (locale == LC_GLOBAL_LOCALE) locale = __global_locale; return __locale_name(locale); } picolibc-1.8.11/libc/locale/locale_ctype_ptr.c000066400000000000000000000034571513574234600212550ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include "locale_private.h" #include "../ctype/ctype_.h" #ifdef __MB_EXTENDED_CHARSETS_NON_UNICODE const char * __locale_ctype_ptr(void) { return __get_ctype(__get_current_locale()); } #endif picolibc-1.8.11/libc/locale/locale_ctype_ptr_l.c000066400000000000000000000034541513574234600215650ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include "locale_private.h" #include "../ctype/ctype_.h" #ifdef __MB_EXTENDED_CHARSETS_NON_UNICODE const char * __locale_ctype_ptr_l(locale_t locale) { return __get_ctype(locale); } #endif picolibc-1.8.11/libc/locale/locale_mb_cur_max.c000066400000000000000000000033141513574234600213500ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "locale_private.h" size_t __locale_mb_cur_max(void) { return __locale_mb_cur_max_l(__get_current_locale()); } picolibc-1.8.11/libc/locale/locale_names.c000066400000000000000000000154661513574234600203520ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "locale_private.h" const char * const __locale_names[locale_END - locale_BASE] = { [locale_C - locale_BASE] = "C", #ifdef __MB_CAPABLE [locale_UTF_8 - locale_BASE] = "C.UTF-8", #ifdef __MB_EXTENDED_CHARSETS_UCS [locale_UCS_2 - locale_BASE] = "C.UCS-2", [locale_UCS_2LE - locale_BASE] = "C.UCS-2LE", [locale_UCS_2BE - locale_BASE] = "C.UCS-2BE", [locale_UCS_4 - locale_BASE] = "C.UCS-4", [locale_UCS_4LE - locale_BASE] = "C.UCS-4LE", [locale_UCS_4BE - locale_BASE] = "C.UCS-4BE", #endif #ifdef __MB_EXTENDED_CHARSETS_ISO [locale_ISO_8859_1 - locale_BASE] = "C.ISO-8859-1", [locale_ISO_8859_2 - locale_BASE] = "C.ISO-8859-2", [locale_ISO_8859_3 - locale_BASE] = "C.ISO-8859-3", [locale_ISO_8859_4 - locale_BASE] = "C.ISO-8859-4", [locale_ISO_8859_5 - locale_BASE] = "C.ISO-8859-5", [locale_ISO_8859_6 - locale_BASE] = "C.ISO-8859-6", [locale_ISO_8859_7 - locale_BASE] = "C.ISO-8859-7", [locale_ISO_8859_8 - locale_BASE] = "C.ISO-8859-8", [locale_ISO_8859_9 - locale_BASE] = "C.ISO-8859-9", [locale_ISO_8859_10 - locale_BASE] = "C.ISO-8859-10", [locale_ISO_8859_11 - locale_BASE] = "C.ISO-8859-11", [locale_ISO_8859_13 - locale_BASE] = "C.ISO-8859-13", [locale_ISO_8859_14 - locale_BASE] = "C.ISO-8859-14", [locale_ISO_8859_15 - locale_BASE] = "C.ISO-8859-15", [locale_ISO_8859_16 - locale_BASE] = "C.ISO-8859-16", #endif #ifdef __MB_EXTENDED_CHARSETS_WINDOWS [locale_CP437 - locale_BASE] = "C.CP437", [locale_CP720 - locale_BASE] = "C.CP720", [locale_CP737 - locale_BASE] = "C.CP737", [locale_CP775 - locale_BASE] = "C.CP775", [locale_CP850 - locale_BASE] = "C.CP850", [locale_CP852 - locale_BASE] = "C.CP852", [locale_CP855 - locale_BASE] = "C.CP855", [locale_CP857 - locale_BASE] = "C.CP857", [locale_CP858 - locale_BASE] = "C.CP858", [locale_CP862 - locale_BASE] = "C.CP862", [locale_CP866 - locale_BASE] = "C.CP866", [locale_CP874 - locale_BASE] = "C.CP874", [locale_CP1125 - locale_BASE] = "C.CP1125", [locale_CP1250 - locale_BASE] = "C.CP1250", [locale_CP1251 - locale_BASE] = "C.CP1251", [locale_CP1252 - locale_BASE] = "C.CP1252", [locale_CP1253 - locale_BASE] = "C.CP1253", [locale_CP1254 - locale_BASE] = "C.CP1254", [locale_CP1255 - locale_BASE] = "C.CP1255", [locale_CP1256 - locale_BASE] = "C.CP1256", [locale_CP1257 - locale_BASE] = "C.CP1257", [locale_CP1258 - locale_BASE] = "C.CP1258", [locale_KOI8_R - locale_BASE] = "C.KOI8-R", [locale_KOI8_U - locale_BASE] = "C.KOI8-U", [locale_GEORGIAN_PS - locale_BASE] = "C.GEORGIAN-PS", [locale_PT154 - locale_BASE] = "C.PT154", [locale_KOI8_T - locale_BASE] = "C.KOI8-T", #endif #ifdef __MB_EXTENDED_CHARSETS_JIS [locale_JIS - locale_BASE] = "C.JIS", [locale_EUCJP - locale_BASE] = "C.EUC-JP", [locale_SJIS - locale_BASE] = "C.SHIFT-JIS", #endif #endif }; static const char * __find_locale_sep(const char *str) { char c; for (;;) { c = *str; switch (c) { case '\0': case '.': case '-': return str; } ++str; } } static bool __skip_char(char c) { return c == '.' || c == '_' || c == '-'; } /* * Match two charset strings, ignoring ., _ and - unless * those occur at the end of the input string. * This is a case-insensitive match */ static bool __match_charset(const char *str, const char *name) { for (;;) { char sc, nc; while (__skip_char(nc = *name++)) ; while (__skip_char(sc = *str++) && nc) ; /* discard trailing / bits -- those are for iconv modes */ if (sc == '/') sc = '\0'; if (LOCALE_ISUPPER(sc)) sc = LOCALE_TOLOWER(sc); if (LOCALE_ISUPPER(nc)) nc = LOCALE_TOLOWER(nc); if (sc != nc) return false; if (!sc) return true; } } /* * Map a charset name to one of our internal locale ids. * Returns locale_INVALID for an invalid charset */ enum locale_id __find_charset(const char *charset) { enum locale_id id; if (__match_charset(charset, "ascii") || __match_charset(charset, "us_ascii")) return locale_C; #ifdef __MB_CAPABLE for (id = locale_UTF_8; id < locale_END; id++) { if (__match_charset(charset, __locale_name(id) + 2)) break; } if (id == locale_END) id = locale_INVALID; #else id = locale_INVALID; #endif return id; } #ifdef __MB_CAPABLE #define LOCALE_DEFAULT locale_UTF_8 #else #define LOCALE_DEFAULT locale_C #endif /* * Map a locale name to one of our internal locale ids. * Returns locale_INVALID for an invalid charset */ enum locale_id __find_locale(const char *name) { enum locale_id id = LOCALE_DEFAULT; const char *lang_end; if (!name) return locale_INVALID; if (!*name) return _DEFAULT_LOCALE; /* POSIX is an alias for C */ if (!strcmp(name, "POSIX")) name = __locale_name(locale_C); lang_end = __find_locale_sep(name); /* Switch the default locale to C when the territory is 'C' */ if (lang_end == name + 1 && LOCALE_TOLOWER(*name) == 'c') id = locale_C; if (*lang_end) id = __find_charset(lang_end + 1); return id; } picolibc-1.8.11/libc/locale/locale_private.h000066400000000000000000000214671513574234600207240ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _LOCALE_PRIVATE_H_ #define _LOCALE_PRIVATE_H_ #include #include #include #include #include #include #include #include #include #define __HAVE_POSIX_LOCALE_API #define NUMCAT ((_LC_MESSAGES - LC_ALL) + 1) /* * This operates like _tolower on upper case letters, but also works * correctly on lower case letters. */ #define LOCALE_ISUPPER(c) ('A' <= (c) && (c) <= 'Z') #define LOCALE_TOLOWER(c) ((c) | ('a' - 'A')) enum locale_id { locale_INVALID, locale_BASE, locale_C = locale_BASE, #ifdef __MB_CAPABLE locale_UTF_8, #ifdef __MB_EXTENDED_CHARSETS_UCS locale_UCS_2, locale_UCS_2LE, locale_UCS_2BE, locale_UCS_4, locale_UCS_4LE, locale_UCS_4BE, #endif #ifdef __MB_EXTENDED_CHARSETS_ISO locale_ISO_BASE, locale_EXTENDED_BASE = locale_ISO_BASE, locale_ISO_8859_1 = locale_ISO_BASE, locale_ISO_8859_2, locale_ISO_8859_3, locale_ISO_8859_4, locale_ISO_8859_5, locale_ISO_8859_6, locale_ISO_8859_7, locale_ISO_8859_8, locale_ISO_8859_9, locale_ISO_8859_10, locale_ISO_8859_11, locale_ISO_8859_13, locale_ISO_8859_14, locale_ISO_8859_15, locale_ISO_8859_16, #endif #ifdef __MB_EXTENDED_CHARSETS_WINDOWS locale_WINDOWS_BASE, #ifndef __MB_EXTENDED_CHARSETS_ISO locale_EXTENDED_BASE = locale_WINDOWS_BASE, #endif locale_CP437 = locale_WINDOWS_BASE, locale_CP720, locale_CP737, locale_CP775, locale_CP850, locale_CP852, locale_CP855, locale_CP857, locale_CP858, locale_CP862, locale_CP866, locale_CP874, locale_CP1125, locale_CP1250, locale_CP1251, locale_CP1252, locale_CP1253, locale_CP1254, locale_CP1255, locale_CP1256, locale_CP1257, locale_CP1258, locale_KOI8_R, locale_KOI8_U, locale_GEORGIAN_PS, locale_PT154, locale_KOI8_T, #endif #ifdef __MB_EXTENDED_CHARSETS_JIS locale_JIS_BASE, #if !defined(__MB_EXTENDED_CHARSETS_ISO) && !defined(__MB_EXTENDED_CHARSETS_WINDOWS) locale_EXTENDED_BASE = locale_JIS_BASE, #endif locale_JIS = locale_JIS_BASE, locale_EUCJP, locale_SJIS, #endif #endif locale_END, }; typedef int wctomb_f(char *, wchar_t, mbstate_t *); typedef wctomb_f *wctomb_p; typedef int mbtowc_f(wchar_t *, const char *, size_t, mbstate_t *); typedef mbtowc_f *mbtowc_p; #ifndef _DEFAULT_LOCALE #define _DEFAULT_LOCALE locale_C #endif extern const char * const __locale_names[]; extern locale_t __global_locale; #ifdef __HAVE_POSIX_LOCALE_API extern __THREAD_LOCAL locale_t _locale; #endif #ifdef __MB_CAPABLE extern const wctomb_p __wctomb[locale_END - locale_BASE]; extern const mbtowc_p __mbtowc[locale_END - locale_BASE]; #define __get_wctomb(id) __wctomb[(id) - locale_BASE] #define __get_mbtowc(id) __mbtowc[(id) - locale_BASE] #ifdef __HAVE_POSIX_LOCALE_API #define __WCTOMB_L(l) (__get_wctomb(l)) #define __MBTOWC_L(l) (__get_mbtowc(l)) #define __WCTOMB (__WCTOMB_L(__get_current_locale())) #define __MBTOWC (__MBTOWC_L(__get_current_locale())) #else #define __WCTOMB (__get_wctomb(__global_locale)) #define __MBTOWC (__get_mbtowc(__global_locale)) #endif #else #define __WCTOMB __ascii_wctomb #define __MBTOWC __ascii_mbtowc #define __WCTOMB_L(l) ((void)(l), __ascii_wctomb) #define __MBTOWC_L(l) ((void)(l), __ascii_mbtowc) #endif static inline locale_t __get_current_locale(void) { #ifdef __HAVE_POSIX_LOCALE_API if (_locale) return _locale; #endif return __global_locale; } static inline const char * __locale_name(locale_t id) { return __locale_names[id - locale_BASE]; } enum locale_id __find_charset(const char *name); enum locale_id __find_locale(const char *name); /* LC_NUMERIC data */ #define DECIMAL_POINT "." #define DECIMAL_POINT_L(l) ((void)(l), DECIMAL_POINT) #define THOUSANDS_SEP "" #define THOUSANDS_SEP_L(l) ((void)(l), THOUSANDS_SEP) #define NUMERIC_GROUPING "" #define NUMERIC_GROUPING_L(l) ((void)(l), "") #define WDECIMAL_POINT L"." #define WDECIMAL_POINT_L(l) ((void)(l), DECIMAL_POINT) #define WTHOUSANDS_SEP L"" #define WTHOUSANDS_SEP_L(l) ((void)(l), THOUSANDS_SEP) /* LC_TIME data */ #define TIME_ERA "" #define TIME_ERA_D_T_FMT_L(l) ((void)(l), "") #define TIME_ERA_D_T_FMT "" #define TIME_ERA_D_FMT_L(l) ((void)(l), "") #define TIME_ERA_D_FMT "" #define TIME_ERA_T_FMT_L(l) ((void)(l), "") #define TIME_ERA_T_FMT "" #define TIME_ALT_DIGITS "" #define TIME_WDAY __time_wday #define TIME_WDAY_NUM 7 #define TIME_WEEKDAY __time_weekday #define TIME_WEEKDAY_NUM 7 #define TIME_MON __time_mon #define TIME_MON_NUM 12 #define TIME_MONTH __time_month #define TIME_MONTH_NUM 12 #define TIME_AM_PM __time_am_pm #define TIME_AM_PM_NUM 2 #define TIME_C_FMT "%a %b %e %H:%M:%S %Y" #define TIME_X_FMT "%m/%d/%y" #define TIME_UX_FMT "%H:%M:%S" #define TIME_AMPM_FMT "%I:%M:%S %p" extern const char * const __time_wday[TIME_WDAY_NUM]; extern const char * const __time_weekday[TIME_WEEKDAY_NUM]; extern const char * const __time_mon[TIME_MON_NUM]; extern const char * const __time_month[TIME_MONTH_NUM]; extern const char * const __time_am_pm[TIME_AM_PM_NUM]; extern const wchar_t * const __wtime_wday[TIME_WDAY_NUM]; extern const wchar_t * const __wtime_weekday[TIME_WEEKDAY_NUM]; extern const wchar_t * const __wtime_mon[TIME_MON_NUM]; extern const wchar_t * const __wtime_month[TIME_MONTH_NUM]; extern const wchar_t * const __wtime_am_pm[TIME_AM_PM_NUM]; #define WTIME_ERA L"" #define WTIME_ERA_D_T_FMT_L(l) ((void)(l), L"") #define WTIME_ERA_D_T_FMT L"" #define WTIME_ERA_D_FMT_L(l) ((void)(l), L"") #define WTIME_ERA_D_FMT L"" #define WTIME_ERA_T_FMT_L(l) ((void)(l), L"") #define WTIME_ERA_T_FMT L"" #define WTIME_ALT_DIGITS_L(l) ((void)(l), L"") #define WTIME_ALT_DIGITS L"" #define WTIME_WDAY __wtime_wday #define WTIME_WEEKDAY __wtime_weekday #define WTIME_MON __wtime_mon #define WTIME_MONTH __wtime_month #define WTIME_AM_PM __wtime_am_pm #define WTIME_C_FMT L"%a %b %e %H:%M:%S %Y" #define WTIME_X_FMT L"%m/%d/%y" #define WTIME_UX_FMT L"%H:%M:%S" #define WTIME_AMPM_FMT L"%I:%M:%S %p" static inline bool __locale_is_C(locale_t locale) { #ifdef __MB_CAPABLE if (!locale) locale = __get_current_locale(); return locale == locale_C; #else (void)locale; return true; #endif } static inline size_t __locale_mb_cur_max_l(locale_t locale) { switch (locale) { #ifdef __MB_CAPABLE case locale_UTF_8: return 6; #ifdef __MB_EXTENDED_CHARSETS_JIS case locale_JIS: return 8; case locale_EUCJP: return 3; case locale_SJIS: return 2; #endif #endif default: return 1; } } static inline int __locale_cjk_lang(void) { #ifdef __MB_EXTENDED_CHARSETS_JIS switch (__get_current_locale()) { case locale_JIS: case locale_EUCJP: case locale_SJIS: return 1; default: break; } #endif return 0; } #endif /* _LOCALE_PRIVATE_H_ */ picolibc-1.8.11/libc/locale/localeconv.c000066400000000000000000000051461513574234600200470ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "locale_private.h" static const char decimal[] = "."; static const char empty[] = ""; static const struct lconv lconv = { .decimal_point = (char *)decimal, .thousands_sep = (char *)empty, .grouping = (char *)empty, .mon_decimal_point = (char *)empty, .mon_thousands_sep = (char *)empty, .mon_grouping = (char *)empty, .positive_sign = (char *)empty, .negative_sign = (char *)empty, .currency_symbol = (char *)empty, .frac_digits = CHAR_MAX, .p_cs_precedes = CHAR_MAX, .n_cs_precedes = CHAR_MAX, .p_sep_by_space = CHAR_MAX, .n_sep_by_space = CHAR_MAX, .p_sign_posn = CHAR_MAX, .n_sign_posn = CHAR_MAX, .int_curr_symbol = (char *)empty, .int_frac_digits = CHAR_MAX, .int_p_cs_precedes = CHAR_MAX, .int_n_cs_precedes = CHAR_MAX, .int_p_sep_by_space = CHAR_MAX, .int_n_sep_by_space = CHAR_MAX, .int_p_sign_posn = CHAR_MAX, .int_n_sign_posn = CHAR_MAX, }; struct lconv * localeconv(void) { return (struct lconv *)&lconv; } picolibc-1.8.11/libc/locale/localedata.c000066400000000000000000000034241513574234600200100ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "locale_private.h" #include "../ctype/ctype_.h" #include "../stdlib/local.h" locale_t __global_locale = locale_C; #ifdef __HAVE_POSIX_LOCALE_API __THREAD_LOCAL locale_t _locale; #endif picolibc-1.8.11/libc/locale/meson.build000066400000000000000000000043071513574234600177160ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2025 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_locale = [ 'duplocale.c', 'freelocale.c', 'getlocalename_l.c', 'localeconv.c', 'localedata.c', 'locale_ctype_ptr.c', 'locale_ctype_ptr_l.c', 'locale_mb_cur_max.c', 'locale_names.c', 'newlocale.c', 'nl_langinfo.c', 'setlocale.c', 'timedata.c', 'uselocale.c', ] srcs_locale_use = [] foreach file : srcs_locale s_file = fs.replace_suffix(file, '.S') if file in srcs_machine message('libc/locale/' + file + ': machine overrides generic') elif s_file in srcs_machine message('libc/locale/' + s_file + ': machine overrides generic') else srcs_locale_use += file endif endforeach src_locale = files(srcs_locale_use) picolibc-1.8.11/libc/locale/newlocale.c000066400000000000000000000044171513574234600176730ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include "locale_private.h" #include "../ctype/ctype_.h" #include "../stdlib/local.h" #ifdef __HAVE_POSIX_LOCALE_API locale_t newlocale(int category_mask, const char *name, locale_t base) { enum locale_id locale; locale = __find_locale(name); /* * Make sure the mask doesn't contain invalid bits, that locale * specifies a known locale value and that base is not * LC_GLOBAL_LOCALE */ if ((category_mask & ~LC_ALL_MASK) != 0 || locale == locale_INVALID || base == LC_GLOBAL_LOCALE) { errno = EINVAL; return 0; } if ((category_mask & LC_CTYPE) == 0) locale = locale_C; return locale; } #endif picolibc-1.8.11/libc/locale/nl_langinfo.c000066400000000000000000000067711513574234600202150ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include "locale_private.h" #include char * nl_langinfo_l(nl_item item, locale_t locale) { switch (item) { case CODESET: return (char *)__locale_name(locale); case D_T_FMT: return TIME_C_FMT; case D_FMT: return TIME_X_FMT; case T_FMT: return TIME_UX_FMT; case T_FMT_AMPM: return TIME_AMPM_FMT; case AM_STR: return (char *)TIME_AM_PM[0]; case PM_STR: return (char *)TIME_AM_PM[1]; case DAY_1: case DAY_2: case DAY_3: case DAY_4: case DAY_5: case DAY_6: case DAY_7: return (char *)TIME_WEEKDAY[item - DAY_1]; case ABDAY_1: case ABDAY_2: case ABDAY_3: case ABDAY_4: case ABDAY_5: case ABDAY_6: case ABDAY_7: return (char *)TIME_WDAY[item - ABDAY_1]; case MON_1: case MON_2: case MON_3: case MON_4: case MON_5: case MON_6: case MON_7: case MON_8: case MON_9: case MON_10: case MON_11: case MON_12: return (char *)TIME_MONTH[item - MON_1]; case ABMON_1: case ABMON_2: case ABMON_3: case ABMON_4: case ABMON_5: case ABMON_6: case ABMON_7: case ABMON_8: case ABMON_9: case ABMON_10: case ABMON_11: case ABMON_12: return (char *)TIME_MON[item - ABMON_1]; case ERA: return TIME_ERA; case ERA_D_FMT: return TIME_ERA_D_FMT; case ERA_D_T_FMT: return TIME_ERA_D_T_FMT; case ERA_T_FMT: return TIME_ERA_T_FMT; case ALT_DIGITS: return TIME_ALT_DIGITS; case RADIXCHAR: return DECIMAL_POINT; case THOUSEP: return THOUSANDS_SEP; case YESEXPR: return "^[yY]"; case NOEXPR: return "^[nN]"; case CRNCYSTR: return ""; default: return NULL; } } char * nl_langinfo(nl_item item) { return nl_langinfo_l(item, __get_current_locale()); } picolibc-1.8.11/libc/locale/posix_locale.c000066400000000000000000000032661513574234600204040ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "locale_private.h" #ifdef __HAVE_POSIX_LOCALE_API __THREAD_LOCAL locale_t _locale; #endif picolibc-1.8.11/libc/locale/setlocale.c000066400000000000000000000044521513574234600176740ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include "locale_private.h" #include "../ctype/ctype_.h" #include "../stdlib/local.h" char * setlocale(int category, const char *name) { enum locale_id locale; if (category < LC_ALL || category >= _LC_LAST) { errno = EINVAL; return NULL; } /* Return current locale value */ if (name == NULL) return (char *)__locale_name(__global_locale); /* Set the global locale */ locale = __find_locale(name); if (locale == locale_INVALID) return NULL; switch (category) { case LC_ALL: case LC_CTYPE: __global_locale = locale; break; default: break; } return (char *)__locale_name(__global_locale); } picolibc-1.8.11/libc/locale/timedata.c000066400000000000000000000056111513574234600175070ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include "locale_private.h" const char * const __time_wday[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; const char * const __time_weekday[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; const char * const __time_mon[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; const char * const __time_month[12] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; const char * const __time_am_pm[2] = { "AM", "PM" }; const wchar_t * const __wtime_wday[7] = { L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat" }; const wchar_t * const __wtime_weekday[7] = { L"Sunday", L"Monday", L"Tuesday", L"Wednesday", L"Thursday", L"Friday", L"Saturday" }; const wchar_t * const __wtime_mon[12] = { L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec" }; const wchar_t * const __wtime_month[12] = { L"January", L"February", L"March", L"April", L"May", L"June", L"July", L"August", L"September", L"October", L"November", L"December" }; const wchar_t * const __wtime_am_pm[2] = { L"AM", L"PM" }; picolibc-1.8.11/libc/locale/uselocale.c000066400000000000000000000036621513574234600176770ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include "locale_private.h" #include "../ctype/ctype_.h" #ifdef __HAVE_POSIX_LOCALE_API locale_t uselocale(locale_t locale) { locale_t current = _locale; if (current == 0) current = LC_GLOBAL_LOCALE; if (locale == LC_GLOBAL_LOCALE) locale = 0; _locale = locale; return current; } #endif picolibc-1.8.11/libc/machine/000077500000000000000000000000001513574234600157155ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/CMakeLists.txt000066400000000000000000000034731513574234600204640ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/CMakeLists.txt) add_subdirectory(${CMAKE_SYSTEM_PROCESSOR}) endif() if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686") add_subdirectory(shared_x86) endif() picolibc-1.8.11/libc/machine/aarch64/000077500000000000000000000000001513574234600171455ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/aarch64/CMakeLists.txt000066400000000000000000000041551513574234600217120ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources_flags("-fno-builtin" interrupt.c interrupt_vector.S memchr-stub.c memchr.S memcmp-stub.c memcmp.S memcpy-stub.c memcpy.S memmove-stub.c memmove.S memrchr-stub.c memrchr.S memset-stub.c memset.S rawmemchr-stub.c rawmemchr.S setjmp.S stpcpy-stub.c stpcpy.S strchr-stub.c strchr.S strchrnul-stub.c strchrnul.S strcmp-stub.c strcmp.S strcpy-stub.c strcpy.S strlen-stub.c strlen.S strncmp-stub.c strncmp.S strnlen-stub.c strnlen.S strrchr-stub.c strrchr.S tls.c ) add_subdirectory(machine) picolibc-1.8.11/libc/machine/aarch64/asmdefs.h000066400000000000000000000045471513574234600207520ustar00rootroot00000000000000/* * Macros for asm code. AArch64 version. * * Copyright (c) 2019-2023, Arm Limited. * SPDX-License-Identifier: MIT */ #ifndef _ASMDEFS_H #define _ASMDEFS_H /* Branch Target Identitication support. */ #ifdef __ARM_FEATURE_BTI_DEFAULT #define BTI_C hint 34 #define BTI_J hint 36 #define FEATURE_1_BTI 1 #else #define BTI_C #define BTI_J #define FEATURE_1_BTI 0 #endif /* Return address signing support (pac-ret). */ #ifdef __ARM_FEATURE_PAC_DEFAULT #define PACIASP hint 25; #define AUTIASP hint 29; #define FEATURE_1_PAC 2 #else #define PACIASP #define AUTIASP #define FEATURE_1_PAC 0 #endif /* GNU_PROPERTY_AARCH64_* macros from elf.h. */ #define FEATURE_1_AND 0xc0000000 /* Add a NT_GNU_PROPERTY_TYPE_0 note. */ #ifdef __ILP32__ #define GNU_PROPERTY(type, value) \ .section .note.gnu.property, "a"; \ .p2align 2; \ .word 4; \ .word 12; \ .word 5; \ .asciz "GNU"; \ .word type; \ .word 4; \ .word value; \ .text #else #define GNU_PROPERTY(type, value) \ .section .note.gnu.property, "a"; \ .p2align 3; \ .word 4; \ .word 16; \ .word 5; \ .asciz "GNU"; \ .word type; \ .word 4; \ .word value; \ .word 0; \ .text #endif /* If set then the GNU Property Note section will be added to mark objects to support BTI and PAC-RET. */ #ifndef WANT_GNU_PROPERTY #define WANT_GNU_PROPERTY (FEATURE_1_BTI|FEATURE_1_PAC) #endif #if WANT_GNU_PROPERTY /* Add property note with supported features to all asm files. */ GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_PAC) #endif #define ENTRY_ALIGN(name, alignment) \ .global name; \ .type name,%function; \ .align alignment; \ name: \ BTI_C; #define ENTRY(name) ENTRY_ALIGN(name, 6) #define ENTRY_ALIAS(name) \ .global name; \ .type name,%function; \ name: #define END(name) \ .size name, .-name; #define L(l) .L ## l #ifdef __ILP32__ /* Sanitize padding bits of pointer arguments as per aapcs64 */ #define PTR_ARG(n) mov w##n, w##n #else #define PTR_ARG(n) #endif #ifdef __ILP32__ /* Sanitize padding bits of size arguments as per aapcs64 */ #define SIZE_ARG(n) mov w##n, w##n #else #define SIZE_ARG(n) #endif /* Compiler supports SVE instructions */ #ifndef HAVE_SVE # if __aarch64__ && (__GNUC__ >= 8 || __clang_major__ >= 5) # define HAVE_SVE 1 # else # define HAVE_SVE 0 # endif #endif #endif picolibc-1.8.11/libc/machine/aarch64/interrupt.c000066400000000000000000000044541513574234600213540ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include void aarch64_halt_vector(void); void __section(".init") aarch64_halt_vector(void) { /* Loop forever. */ for (;;) ; } void aarch64_ignore_vector(void); void __section(".init") aarch64_ignore_vector(void) { /* Ignore the interrupt by returning */ } #define vector(name) \ void aarch64_##name##_vector(void) __attribute__((weak, alias("aarch64_ignore_vector"))) #define vector_halt(name) \ void aarch64_##name##_vector(void) __attribute__((weak, alias("aarch64_halt_vector"))) vector_halt(sync); vector_halt(serror); vector(irq); vector(fiq); picolibc-1.8.11/libc/machine/aarch64/interrupt_vector.S000066400000000000000000000042751513574234600227170ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ .section .text.init.enter,"ax",@progbits .align 11 .global __weak_vector_table .type __weak_vector_table, %function __weak_vector_table: SP_EL0: b aarch64_sync_vector . = SP_EL0 + 0x80 b aarch64_irq_vector . = SP_EL0 + 0x100 b aarch64_fiq_vector . = SP_EL0 + 0x180 b aarch64_serror_vector . = SP_EL0 + 0x200 SP_ELx: b aarch64_sync_vector . = SP_ELx + 0x80 b aarch64_irq_vector . = SP_ELx + 0x100 b aarch64_fiq_vector . = SP_ELx + 0x180 b aarch64_serror_vector . = SP_ELx + 0x200 .LFE2: .size __weak_vector_table, .-__weak_vector_table .weak __vector_table .set __vector_table,__weak_vector_table picolibc-1.8.11/libc/machine/aarch64/machine/000077500000000000000000000000001513574234600205515ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/aarch64/machine/CMakeLists.txt000066400000000000000000000031621513574234600233130ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_headers(machine _types.h fenv.h fenv-fp.h math.h ) picolibc-1.8.11/libc/machine/aarch64/machine/_fpmath.h000066400000000000000000000045611513574234600223460ustar00rootroot00000000000000/*- * Copyright (c) 2002, 2003 David Schultz * Copyright (c) 2014 The FreeBSD Foundation * 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$ */ /* * Change unsigned int/long used by FreeBSD to fixed width types because * ilp32 has a different size for unsigned long. --joel (20 Aug 2022) */ #include union IEEEl2bits { long double e; struct { uint64_t manl : 64; uint64_t manh : 48; uint32_t exp : 15; uint32_t sign : 1; } bits; /* TODO andrew: Check the packing here */ struct { uint64_t manl : 64; uint64_t manh : 48; uint32_t expsign : 16; } xbits; }; #define LDBL_NBIT 0 #define LDBL_IMPLICIT_NBIT #define mask_nbit_l(u) ((void)0) #define LDBL_MANH_SIZE 48 #define LDBL_MANL_SIZE 64 #define LDBL_TO_ARRAY32(u, a) \ do { \ (a)[0] = (uint32_t)(u).bits.manl; \ (a)[1] = (uint32_t)((u).bits.manl >> 32); \ (a)[2] = (uint32_t)(u).bits.manh; \ (a)[3] = (uint32_t)((u).bits.manh >> 32); \ } while (0) picolibc-1.8.11/libc/machine/aarch64/machine/_types.h000066400000000000000000000031631513574234600222300ustar00rootroot00000000000000/* Copyright (c) 2012 ARM Ltd All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the company may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MACHINE__TYPES_H #define _MACHINE__TYPES_H #include #define __machine_ssize_t_defined typedef long signed int _ssize_t; #endif /* _MACHINE__TYPES_H */ picolibc-1.8.11/libc/machine/aarch64/machine/fenv-fp.h000066400000000000000000000105611513574234600222660ustar00rootroot00000000000000/*- * Copyright (c) 2004-2005 David Schultz * 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$ */ __declare_fenv_inline(int) feclearexcept(int __excepts) { fexcept_t __r; __mrs_fpsr(__r); __r &= ~__excepts; __msr_fpsr(__r); return (0); } __declare_fenv_inline(int) fegetexceptflag(fexcept_t *__flagp, int __excepts) { fexcept_t __r; __mrs_fpsr(__r); *__flagp = __r & __excepts; return (0); } __declare_fenv_inline(int) fesetexceptflag(const fexcept_t *__flagp, int __excepts) { fexcept_t __r; __mrs_fpsr(__r); __r &= ~__excepts; __r |= *__flagp & __excepts; __msr_fpsr(__r); return (0); } __declare_fenv_inline(int) feraiseexcept(int __excepts) { fexcept_t __r; __mrs_fpsr(__r); __r |= __excepts; __msr_fpsr(__r); return (0); } __declare_fenv_inline(int) fesetexcept(int excepts) { return feraiseexcept(excepts); } __declare_fenv_inline(int) fetestexcept(int __excepts) { fexcept_t __r; __mrs_fpsr(__r); return (__r & __excepts); } __declare_fenv_inline(int) fegetround(void) { fenv_t __r; __mrs_fpcr(__r); return ((__r >> _ROUND_SHIFT) & _ROUND_MASK); } __declare_fenv_inline(int) fesetround(int __round) { fenv_t __r; if (__round & ~_ROUND_MASK) return (-1); __mrs_fpcr(__r); __r &= ~(_ROUND_MASK << _ROUND_SHIFT); __r |= __round << _ROUND_SHIFT; __msr_fpcr(__r); return (0); } __declare_fenv_inline(int) fegetenv(fenv_t *__envp) { fenv_t __r; __mrs_fpcr(__r); *__envp = __r & _ENABLE_MASK; __mrs_fpsr(__r); *__envp |= __r & (FE_ALL_EXCEPT | (_ROUND_MASK << _ROUND_SHIFT)); return (0); } __declare_fenv_inline(int) feholdexcept(fenv_t *__envp) { fenv_t __r; __mrs_fpcr(__r); *__envp = __r & _ENABLE_MASK; __r &= ~(_ENABLE_MASK); __msr_fpcr(__r); __mrs_fpsr(__r); *__envp |= __r & (FE_ALL_EXCEPT | (_ROUND_MASK << _ROUND_SHIFT)); __r &= ~(_ENABLE_MASK); __msr_fpsr(__r); return (0); } __declare_fenv_inline(int) fesetenv(const fenv_t *__envp) { __msr_fpcr((*__envp) & _ENABLE_MASK); __msr_fpsr((*__envp) & (FE_ALL_EXCEPT | (_ROUND_MASK << _ROUND_SHIFT))); return (0); } __declare_fenv_inline(int) feupdateenv(const fenv_t *__envp) { fexcept_t __r; __mrs_fpsr(__r); fesetenv(__envp); feraiseexcept(__r & FE_ALL_EXCEPT); return (0); } __declare_fenv_inline(int) feenableexcept(int __mask) { fenv_t __old_r, __new_r, __test_r; __mrs_fpcr(__old_r); __new_r = __old_r | ((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT); __msr_fpcr(__new_r); __asm("mrs %0, fpcr" : "=r"(__test_r)); if (__new_r != __test_r) return -1; return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); } __declare_fenv_inline(int) fedisableexcept(int __mask) { fenv_t __old_r, __new_r; __mrs_fpcr(__old_r); __new_r = __old_r & ~((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT); __msr_fpcr(__new_r); return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); } __declare_fenv_inline(int) fegetexcept(void) { fenv_t __r; __mrs_fpcr(__r); return ((__r & _ENABLE_MASK) >> _FPUSW_SHIFT); } picolibc-1.8.11/libc/machine/aarch64/machine/fenv.h000066400000000000000000000072031513574234600216620ustar00rootroot00000000000000/*- * Copyright (c) 2004-2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _FENV_H_ #define _FENV_H_ #include _BEGIN_STD_C typedef __uint64_t fenv_t; typedef __uint64_t fexcept_t; /* * We can't tell if we're using compiler-rt or libgcc; instead * we assume a connection between the compiler in use and * the runtime library. */ #if defined(__clang__) /* compiler-rt has no exceptions in soft-float */ #define __LONG_DOUBLE_NOROUND #define __LONG_DOUBLE_NOEXCEPT #if (__ARM_FP & 0x8) == 0 #define __DOUBLE_NOROUND #define __DOUBLE_NOEXCEPT #endif #if (__ARM_FP & 0x4) == 0 #define __FLOAT_NOROUND #define __FLOAT_NOEXCEPT #endif #else /* libgcc has exceptions when there is an FPU */ #if __ARM_FP == 0 #define __LONG_DOUBLE_NOROUND #define __LONG_DOUBLE_NOEXCEPT #define __DOUBLE_NOROUND #define __DOUBLE_NOEXCEPT #define __FLOAT_NOROUND #define __FLOAT_NOEXCEPT #endif #endif #if __ARM_FP /* Exception flags */ #define FE_INVALID 0x00000001 #define FE_DIVBYZERO 0x00000002 #define FE_OVERFLOW 0x00000004 #define FE_UNDERFLOW 0x00000008 #define FE_INEXACT 0x00000010 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) /* * Rounding modes * * We can't just use the hardware bit values here, because that would * make FE_UPWARD and FE_DOWNWARD negative, which is not allowed. */ #define FE_TONEAREST 0x0 #define FE_UPWARD 0x1 #define FE_DOWNWARD 0x2 #define FE_TOWARDZERO 0x3 #define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO) #define _ROUND_SHIFT 22 /* We need to be able to map status flag positions to mask flag positions */ #define _FPUSW_SHIFT 8 #define _ENABLE_MASK (FE_ALL_EXCEPT << _FPUSW_SHIFT) #define __mrs_fpcr(__r) __asm__ __volatile__("mrs %0, fpcr" : "=r"(__r)) #define __msr_fpcr(__r) __asm__ __volatile__("msr fpcr, %0" : : "r"(__r)) #define __mrs_fpsr(__r) __asm__ __volatile__("mrs %0, fpsr" : "=r"(__r)) #define __msr_fpsr(__r) __asm__ __volatile__("msr fpsr, %0" : : "r"(__r)) #else #define FE_TONEAREST 0x00000000 #endif #if !defined(__declare_fenv_inline) && defined(__declare_extern_inline) #define __declare_fenv_inline(type) __declare_extern_inline(type) #endif #ifdef __declare_fenv_inline #if __ARM_FP #include #else #include #endif #endif _END_STD_C #endif /* !_FENV_H_ */ picolibc-1.8.11/libc/machine/aarch64/machine/math.h000066400000000000000000000054461513574234600216640ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MACHINE_MATH_H_ #define _MACHINE_MATH_H_ #if __ARM_FP & 0x8 #define __HAVE_FAST_FMA 1 #endif #if __ARM_FP & 0x4 #define __HAVE_FAST_FMAF 1 #endif #ifdef __declare_extern_inline #ifdef __MATH_ERRNO #include #endif #if __ARM_FP & 0x8 __declare_extern_inline(double) sqrt(double x) { double result; #ifdef __MATH_ERRNO if (isless(x, 0.0)) errno = EDOM; #endif __asm__ __volatile__("fsqrt\t%d0, %d1" : "=w"(result) : "w"(x)); return result; } __declare_extern_inline(double) fma(double x, double y, double z) { double result; __asm__ __volatile__("fmadd\t%d0, %d1, %d2, %d3" : "=w"(result) : "w"(x), "w"(y), "w"(z)); return result; } #endif /* __ARM_FP & 0x8 */ #if __ARM_FP & 0x4 __declare_extern_inline(float) sqrtf(float x) { float result; #ifdef __MATH_ERRNO if (isless(x, 0.0f)) errno = EDOM; #endif __asm__ __volatile__("fsqrt\t%s0, %s1" : "=w"(result) : "w"(x)); return result; } __declare_extern_inline(float) fmaf(float x, float y, float z) { float result; __asm__ __volatile__("fmadd\t%s0, %s1, %s2, %s3" : "=w"(result) : "w"(x), "w"(y), "w"(z)); return result; } #endif /* __ARM_FP & 0x4 */ #endif #endif /* _MACHINE_MATH_H_ */ picolibc-1.8.11/libc/machine/aarch64/machine/meson.build000066400000000000000000000034031513574234600227130ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_machine_headers_machine = [ '_types.h', 'fenv.h', 'fenv-fp.h', 'math.h', ] if really_install install_headers(inc_machine_headers_machine, install_dir: include_dir / 'machine') endif picolibc-1.8.11/libc/machine/aarch64/memchr-stub.c000066400000000000000000000034031513574234600215370ustar00rootroot00000000000000/* Copyright (c) 2013, Linaro Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) \ || !defined(__ARM_NEON) #include "../../string/memchr.c" #else /* See memchr.S */ #endif picolibc-1.8.11/libc/machine/aarch64/memchr.S000066400000000000000000000075431513574234600205550ustar00rootroot00000000000000/* * memchr - find a character in a memory zone * * Copyright (c) 2014-2022, Arm Limited. * SPDX-License-Identifier: MIT */ #include #if (defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) || !defined(__ARM_NEON) /* See memchr-stub.c */ #else /* Assumptions: * * ARMv8-a, AArch64 * Neon Available. */ #include "asmdefs.h" /* Arguments and results. */ #define srcin x0 #define chrin w1 #define cntin x2 #define result x0 #define src x3 #define tmp x4 #define wtmp2 w5 #define synd x6 #define soff x9 #define cntrem x10 #define vrepchr v0 #define vdata1 v1 #define vdata2 v2 #define vhas_chr1 v3 #define vhas_chr2 v4 #define vrepmask v5 #define vend v6 /* * Core algorithm: * * For each 32-byte chunk we calculate a 64-bit syndrome value, with two bits * per byte. For each tuple, bit 0 is set if the relevant byte matched the * requested character and bit 1 is not used (faster than using a 32bit * syndrome). Since the bits in the syndrome reflect exactly the order in which * things occur in the original string, counting trailing zeros allows to * identify exactly which byte has matched. */ ENTRY (memchr) PTR_ARG (0) SIZE_ARG (2) /* Do not dereference srcin if no bytes to compare. */ cbz cntin, L(zero_length) /* * Magic constant 0x40100401 allows us to identify which lane matches * the requested byte. */ mov wtmp2, #0x0401 movk wtmp2, #0x4010, lsl #16 dup vrepchr.16b, chrin /* Work with aligned 32-byte chunks */ bic src, srcin, #31 dup vrepmask.4s, wtmp2 ands soff, srcin, #31 and cntrem, cntin, #31 b.eq L(loop) /* * Input string is not 32-byte aligned. We calculate the syndrome * value for the aligned 32 bytes block containing the first bytes * and mask the irrelevant part. */ ld1 {vdata1.16b, vdata2.16b}, [src], #32 sub tmp, soff, #32 adds cntin, cntin, tmp cmeq vhas_chr1.16b, vdata1.16b, vrepchr.16b cmeq vhas_chr2.16b, vdata2.16b, vrepchr.16b and vhas_chr1.16b, vhas_chr1.16b, vrepmask.16b and vhas_chr2.16b, vhas_chr2.16b, vrepmask.16b addp vend.16b, vhas_chr1.16b, vhas_chr2.16b /* 256->128 */ addp vend.16b, vend.16b, vend.16b /* 128->64 */ mov synd, vend.d[0] /* Clear the soff*2 lower bits */ lsl tmp, soff, #1 lsr synd, synd, tmp lsl synd, synd, tmp /* The first block can also be the last */ b.ls L(masklast) /* Have we found something already? */ cbnz synd, L(tail) L(loop): ld1 {vdata1.16b, vdata2.16b}, [src], #32 subs cntin, cntin, #32 cmeq vhas_chr1.16b, vdata1.16b, vrepchr.16b cmeq vhas_chr2.16b, vdata2.16b, vrepchr.16b /* If we're out of data we finish regardless of the result */ b.ls L(end) /* Use a fast check for the termination condition */ orr vend.16b, vhas_chr1.16b, vhas_chr2.16b addp vend.2d, vend.2d, vend.2d mov synd, vend.d[0] /* We're not out of data, loop if we haven't found the character */ cbz synd, L(loop) L(end): /* Termination condition found, let's calculate the syndrome value */ and vhas_chr1.16b, vhas_chr1.16b, vrepmask.16b and vhas_chr2.16b, vhas_chr2.16b, vrepmask.16b addp vend.16b, vhas_chr1.16b, vhas_chr2.16b /* 256->128 */ addp vend.16b, vend.16b, vend.16b /* 128->64 */ mov synd, vend.d[0] /* Only do the clear for the last possible block */ b.hs L(tail) L(masklast): /* Clear the (32 - ((cntrem + soff) % 32)) * 2 upper bits */ add tmp, cntrem, soff and tmp, tmp, #31 sub tmp, tmp, #32 neg tmp, tmp, lsl #1 lsl synd, synd, tmp lsr synd, synd, tmp L(tail): /* Count the trailing zeros using bit reversing */ rbit synd, synd /* Compensate the last post-increment */ sub src, src, #32 /* Check that we have found a character */ cmp synd, #0 /* And count the leading zeros */ clz synd, synd /* Compute the potential result */ add result, src, synd, lsr #1 /* Select result or NULL */ csel result, xzr, result, eq ret L(zero_length): mov result, #0 ret END (memchr) #endif picolibc-1.8.11/libc/machine/aarch64/memcmp-stub.c000066400000000000000000000034031513574234600215420ustar00rootroot00000000000000/* Copyright (c) 2013, Linaro Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) \ || !defined(__ARM_NEON) #include "../../string/memcmp.c" #else /* See memcmp.S */ #endif picolibc-1.8.11/libc/machine/aarch64/memcmp.S000066400000000000000000000072511513574234600205540ustar00rootroot00000000000000/* memcmp - compare memory * * Copyright (c) 2013-2022, Arm Limited. * SPDX-License-Identifier: MIT */ #include #if (defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) || !defined(__ARM_NEON) /* See memcmp-stub.c */ #else /* Assumptions: * * ARMv8-a, AArch64, Advanced SIMD, unaligned accesses. */ #include "asmdefs.h" #define src1 x0 #define src2 x1 #define limit x2 #define result w0 #define data1 x3 #define data1w w3 #define data2 x4 #define data2w w4 #define data3 x5 #define data3w w5 #define data4 x6 #define data4w w6 #define tmp x6 #define src1end x7 #define src2end x8 ENTRY (memcmp) PTR_ARG (0) PTR_ARG (1) SIZE_ARG (2) cmp limit, 16 b.lo L(less16) ldp data1, data3, [src1] ldp data2, data4, [src2] ccmp data1, data2, 0, ne ccmp data3, data4, 0, eq b.ne L(return2) add src1end, src1, limit add src2end, src2, limit cmp limit, 32 b.ls L(last_bytes) cmp limit, 160 b.hs L(loop_align) sub limit, limit, 32 .p2align 4 L(loop32): ldp data1, data3, [src1, 16] ldp data2, data4, [src2, 16] cmp data1, data2 ccmp data3, data4, 0, eq b.ne L(return2) cmp limit, 16 b.ls L(last_bytes) ldp data1, data3, [src1, 32] ldp data2, data4, [src2, 32] cmp data1, data2 ccmp data3, data4, 0, eq b.ne L(return2) add src1, src1, 32 add src2, src2, 32 L(last64): subs limit, limit, 32 b.hi L(loop32) /* Compare last 1-16 bytes using unaligned access. */ L(last_bytes): ldp data1, data3, [src1end, -16] ldp data2, data4, [src2end, -16] L(return2): cmp data1, data2 csel data1, data1, data3, ne csel data2, data2, data4, ne /* Compare data bytes and set return value to 0, -1 or 1. */ L(return): #ifndef __AARCH64EB__ rev data1, data1 rev data2, data2 #endif cmp data1, data2 cset result, ne cneg result, result, lo ret .p2align 4 L(less16): add src1end, src1, limit add src2end, src2, limit tbz limit, 3, L(less8) ldr data1, [src1] ldr data2, [src2] ldr data3, [src1end, -8] ldr data4, [src2end, -8] b L(return2) .p2align 4 L(less8): tbz limit, 2, L(less4) ldr data1w, [src1] ldr data2w, [src2] ldr data3w, [src1end, -4] ldr data4w, [src2end, -4] b L(return2) L(less4): tbz limit, 1, L(less2) ldrh data1w, [src1] ldrh data2w, [src2] cmp data1w, data2w b.ne L(return) L(less2): mov result, 0 tbz limit, 0, L(return_zero) ldrb data1w, [src1end, -1] ldrb data2w, [src2end, -1] sub result, data1w, data2w L(return_zero): ret L(loop_align): ldp data1, data3, [src1, 16] ldp data2, data4, [src2, 16] cmp data1, data2 ccmp data3, data4, 0, eq b.ne L(return2) /* Align src2 and adjust src1, src2 and limit. */ and tmp, src2, 15 sub tmp, tmp, 16 sub src2, src2, tmp add limit, limit, tmp sub src1, src1, tmp sub limit, limit, 64 + 16 .p2align 4 L(loop64): ldr q0, [src1, 16] ldr q1, [src2, 16] subs limit, limit, 64 ldr q2, [src1, 32] ldr q3, [src2, 32] eor v0.16b, v0.16b, v1.16b eor v1.16b, v2.16b, v3.16b ldr q2, [src1, 48] ldr q3, [src2, 48] umaxp v0.16b, v0.16b, v1.16b ldr q4, [src1, 64]! ldr q5, [src2, 64]! eor v1.16b, v2.16b, v3.16b eor v2.16b, v4.16b, v5.16b umaxp v1.16b, v1.16b, v2.16b umaxp v0.16b, v0.16b, v1.16b umaxp v0.16b, v0.16b, v0.16b fmov tmp, d0 ccmp tmp, 0, 0, hi b.eq L(loop64) /* If equal, process last 1-64 bytes using scalar loop. */ add limit, limit, 64 + 16 cbz tmp, L(last64) /* Determine the 8-byte aligned offset of the first difference. */ #ifdef __AARCH64EB__ rev16 tmp, tmp #endif rev tmp, tmp clz tmp, tmp bic tmp, tmp, 7 sub tmp, tmp, 48 ldr data1, [src1, tmp] ldr data2, [src2, tmp] #ifndef __AARCH64EB__ rev data1, data1 rev data2, data2 #endif mov result, 1 cmp data1, data2 cneg result, result, lo ret END (memcmp) #endif picolibc-1.8.11/libc/machine/aarch64/memcpy-stub.c000066400000000000000000000033521513574234600215610ustar00rootroot00000000000000/* Copyright (c) 2012-2013, Linaro Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) #include "../../string/memcpy.c" #else /* See memcpy.S */ #endif picolibc-1.8.11/libc/machine/aarch64/memcpy.S000066400000000000000000000127771513574234600206010ustar00rootroot00000000000000/* * memcpy - copy memory area * * Copyright (c) 2012-2022, Arm Limited. * SPDX-License-Identifier: MIT */ /* Assumptions: * * ARMv8-a, AArch64, unaligned accesses. * */ #include #if (defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) /* See memcpy-stub.c */ #else #include "asmdefs.h" #define dstin x0 #define src x1 #define count x2 #define dst x3 #define srcend x4 #define dstend x5 #define A_l x6 #define A_lw w6 #define A_h x7 #define B_l x8 #define B_lw w8 #define B_h x9 #define C_l x10 #define C_lw w10 #define C_h x11 #define D_l x12 #define D_h x13 #define E_l x14 #define E_h x15 #define F_l x16 #define F_h x17 #define G_l count #define G_h dst #define H_l src #define H_h srcend #define tmp1 x14 /* This implementation handles overlaps and supports both memcpy and memmove from a single entry point. It uses unaligned accesses and branchless sequences to keep the code small, simple and improve performance. Copies are split into 3 main cases: small copies of up to 32 bytes, medium copies of up to 128 bytes, and large copies. The overhead of the overlap check is negligible since it is only required for large copies. Large copies use a software pipelined loop processing 64 bytes per iteration. The destination pointer is 16-byte aligned to minimize unaligned accesses. The loop tail is handled by always copying 64 bytes from the end. */ ENTRY_ALIAS (memmove) ENTRY (memcpy) PTR_ARG (0) PTR_ARG (1) SIZE_ARG (2) add srcend, src, count add dstend, dstin, count cmp count, 128 b.hi L(copy_long) cmp count, 32 b.hi L(copy32_128) /* Small copies: 0..32 bytes. */ cmp count, 16 b.lo L(copy16) ldp A_l, A_h, [src] ldp D_l, D_h, [srcend, -16] stp A_l, A_h, [dstin] stp D_l, D_h, [dstend, -16] ret /* Copy 8-15 bytes. */ L(copy16): tbz count, 3, L(copy8) ldr A_l, [src] ldr A_h, [srcend, -8] str A_l, [dstin] str A_h, [dstend, -8] ret .p2align 3 /* Copy 4-7 bytes. */ L(copy8): tbz count, 2, L(copy4) ldr A_lw, [src] ldr B_lw, [srcend, -4] str A_lw, [dstin] str B_lw, [dstend, -4] ret /* Copy 0..3 bytes using a branchless sequence. */ L(copy4): cbz count, L(copy0) lsr tmp1, count, 1 ldrb A_lw, [src] ldrb C_lw, [srcend, -1] ldrb B_lw, [src, tmp1] strb A_lw, [dstin] strb B_lw, [dstin, tmp1] strb C_lw, [dstend, -1] L(copy0): ret .p2align 4 /* Medium copies: 33..128 bytes. */ L(copy32_128): ldp A_l, A_h, [src] ldp B_l, B_h, [src, 16] ldp C_l, C_h, [srcend, -32] ldp D_l, D_h, [srcend, -16] cmp count, 64 b.hi L(copy128) stp A_l, A_h, [dstin] stp B_l, B_h, [dstin, 16] stp C_l, C_h, [dstend, -32] stp D_l, D_h, [dstend, -16] ret .p2align 4 /* Copy 65..128 bytes. */ L(copy128): ldp E_l, E_h, [src, 32] ldp F_l, F_h, [src, 48] cmp count, 96 b.ls L(copy96) ldp G_l, G_h, [srcend, -64] ldp H_l, H_h, [srcend, -48] stp G_l, G_h, [dstend, -64] stp H_l, H_h, [dstend, -48] L(copy96): stp A_l, A_h, [dstin] stp B_l, B_h, [dstin, 16] stp E_l, E_h, [dstin, 32] stp F_l, F_h, [dstin, 48] stp C_l, C_h, [dstend, -32] stp D_l, D_h, [dstend, -16] ret .p2align 4 /* Copy more than 128 bytes. */ L(copy_long): /* Use backwards copy if there is an overlap. */ sub tmp1, dstin, src cbz tmp1, L(copy0) cmp tmp1, count b.lo L(copy_long_backwards) /* Copy 16 bytes and then align dst to 16-byte alignment. */ ldp D_l, D_h, [src] and tmp1, dstin, 15 bic dst, dstin, 15 sub src, src, tmp1 add count, count, tmp1 /* Count is now 16 too large. */ ldp A_l, A_h, [src, 16] stp D_l, D_h, [dstin] ldp B_l, B_h, [src, 32] ldp C_l, C_h, [src, 48] ldp D_l, D_h, [src, 64]! subs count, count, 128 + 16 /* Test and readjust count. */ b.ls L(copy64_from_end) L(loop64): stp A_l, A_h, [dst, 16] ldp A_l, A_h, [src, 16] stp B_l, B_h, [dst, 32] ldp B_l, B_h, [src, 32] stp C_l, C_h, [dst, 48] ldp C_l, C_h, [src, 48] stp D_l, D_h, [dst, 64]! ldp D_l, D_h, [src, 64]! subs count, count, 64 b.hi L(loop64) /* Write the last iteration and copy 64 bytes from the end. */ L(copy64_from_end): ldp E_l, E_h, [srcend, -64] stp A_l, A_h, [dst, 16] ldp A_l, A_h, [srcend, -48] stp B_l, B_h, [dst, 32] ldp B_l, B_h, [srcend, -32] stp C_l, C_h, [dst, 48] ldp C_l, C_h, [srcend, -16] stp D_l, D_h, [dst, 64] stp E_l, E_h, [dstend, -64] stp A_l, A_h, [dstend, -48] stp B_l, B_h, [dstend, -32] stp C_l, C_h, [dstend, -16] ret .p2align 4 /* Large backwards copy for overlapping copies. Copy 16 bytes and then align dst to 16-byte alignment. */ L(copy_long_backwards): ldp D_l, D_h, [srcend, -16] and tmp1, dstend, 15 sub srcend, srcend, tmp1 sub count, count, tmp1 ldp A_l, A_h, [srcend, -16] stp D_l, D_h, [dstend, -16] ldp B_l, B_h, [srcend, -32] ldp C_l, C_h, [srcend, -48] ldp D_l, D_h, [srcend, -64]! sub dstend, dstend, tmp1 subs count, count, 128 b.ls L(copy64_from_start) L(loop64_backwards): stp A_l, A_h, [dstend, -16] ldp A_l, A_h, [srcend, -16] stp B_l, B_h, [dstend, -32] ldp B_l, B_h, [srcend, -32] stp C_l, C_h, [dstend, -48] ldp C_l, C_h, [srcend, -48] stp D_l, D_h, [dstend, -64]! ldp D_l, D_h, [srcend, -64]! subs count, count, 64 b.hi L(loop64_backwards) /* Write the last iteration and copy 64 bytes from the start. */ L(copy64_from_start): ldp G_l, G_h, [src, 48] stp A_l, A_h, [dstend, -16] ldp A_l, A_h, [src, 32] stp B_l, B_h, [dstend, -32] ldp B_l, B_h, [src, 16] stp C_l, C_h, [dstend, -48] ldp C_l, C_h, [src] stp D_l, D_h, [dstend, -64] stp G_l, G_h, [dstin, 48] stp A_l, A_h, [dstin, 32] stp B_l, B_h, [dstin, 16] stp C_l, C_h, [dstin] ret END (memcpy) #endif picolibc-1.8.11/libc/machine/aarch64/memmove-stub.c000066400000000000000000000033461513574234600217370ustar00rootroot00000000000000/* Copyright (c) 2013, Linaro Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) #include "../../string/memmove.c" #else /* See memcpy.S */ #endif picolibc-1.8.11/libc/machine/aarch64/memmove.S000066400000000000000000000000761513574234600207410ustar00rootroot00000000000000/* This is either handled by the memmove stub or by memcpy */ picolibc-1.8.11/libc/machine/aarch64/memrchr-stub.c000066400000000000000000000004741513574234600217260ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-2-Clause * * Copyright (C) 2023 embedded brains GmbH & Co. KG */ #include #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) \ || !defined(__ARM_NEON) #include "../../string/memrchr.c" #else /* See memrchr.S */ #endif picolibc-1.8.11/libc/machine/aarch64/memrchr.S000066400000000000000000000046101513574234600207270ustar00rootroot00000000000000/* * memrchr - find last character in a memory zone. * * Copyright (c) 2020-2022, Arm Limited. * SPDX-License-Identifier: MIT */ /* Assumptions: * * ARMv8-a, AArch64, Advanced SIMD. * MTE compatible. */ #include #if (defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) || !defined(__ARM_NEON) /* See memrchr-stub.c */ #else #include "asmdefs.h" #define srcin x0 #define chrin w1 #define cntin x2 #define result x0 #define src x3 #define cntrem x4 #define synd x5 #define shift x6 #define tmp x7 #define end x8 #define endm1 x9 #define vrepchr v0 #define qdata q1 #define vdata v1 #define vhas_chr v2 #define vend v3 #define dend d3 /* Core algorithm: For each 16-byte chunk we calculate a 64-bit nibble mask value with four bits per byte. We take 4 bits of every comparison byte with shift right and narrow by 4 instruction. Since the bits in the nibble mask reflect the order in which things occur in the original string, counting leading zeros identifies exactly which byte matched. */ ENTRY (memrchr) PTR_ARG (0) add end, srcin, cntin sub endm1, end, 1 bic src, endm1, 15 cbz cntin, L(nomatch) ld1 {vdata.16b}, [src] dup vrepchr.16b, chrin cmeq vhas_chr.16b, vdata.16b, vrepchr.16b neg shift, end, lsl 2 shrn vend.8b, vhas_chr.8h, 4 /* 128->64 */ fmov synd, dend lsl synd, synd, shift cbz synd, L(start_loop) clz synd, synd sub result, endm1, synd, lsr 2 cmp cntin, synd, lsr 2 csel result, result, xzr, hi ret nop L(start_loop): subs cntrem, src, srcin b.ls L(nomatch) /* Make sure that it won't overread by a 16-byte chunk */ sub cntrem, cntrem, 1 tbz cntrem, 4, L(loop32_2) add src, src, 16 .p2align 5 L(loop32): ldr qdata, [src, -32]! cmeq vhas_chr.16b, vdata.16b, vrepchr.16b umaxp vend.16b, vhas_chr.16b, vhas_chr.16b /* 128->64 */ fmov synd, dend cbnz synd, L(end) L(loop32_2): ldr qdata, [src, -16] subs cntrem, cntrem, 32 cmeq vhas_chr.16b, vdata.16b, vrepchr.16b b.lo L(end_2) umaxp vend.16b, vhas_chr.16b, vhas_chr.16b /* 128->64 */ fmov synd, dend cbz synd, L(loop32) L(end_2): sub src, src, 16 L(end): shrn vend.8b, vhas_chr.8h, 4 /* 128->64 */ fmov synd, dend add tmp, src, 15 #ifdef __AARCH64EB__ rbit synd, synd #endif clz synd, synd sub tmp, tmp, synd, lsr 2 cmp tmp, srcin csel result, tmp, xzr, hs ret L(nomatch): mov result, 0 ret END (memrchr) #endif picolibc-1.8.11/libc/machine/aarch64/memset-stub.c000066400000000000000000000034101513574234600215540ustar00rootroot00000000000000/* Copyright (c) 2012-2013, Linaro Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) \ || !defined(__ARM_NEON) #include "../../string/memset.c" #else /* See memset.S */ #endif picolibc-1.8.11/libc/machine/aarch64/memset.S000066400000000000000000000044011513574234600205620ustar00rootroot00000000000000/* * memset - fill memory with a constant byte * * Copyright (c) 2012-2022, Arm Limited. * SPDX-License-Identifier: MIT */ /* Assumptions: * * ARMv8-a, AArch64, Advanced SIMD, unaligned accesses. * */ #include #if (defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) || !defined(__ARM_NEON) /* See memset-stub.c */ #else #include "asmdefs.h" #define dstin x0 #define val x1 #define valw w1 #define count x2 #define dst x3 #define dstend x4 #define zva_val x5 ENTRY (memset) PTR_ARG (0) SIZE_ARG (2) dup v0.16B, valw add dstend, dstin, count cmp count, 96 b.hi L(set_long) cmp count, 16 b.hs L(set_medium) mov val, v0.D[0] /* Set 0..15 bytes. */ tbz count, 3, 1f str val, [dstin] str val, [dstend, -8] ret .p2align 4 1: tbz count, 2, 2f str valw, [dstin] str valw, [dstend, -4] ret 2: cbz count, 3f strb valw, [dstin] tbz count, 1, 3f strh valw, [dstend, -2] 3: ret /* Set 17..96 bytes. */ L(set_medium): str q0, [dstin] tbnz count, 6, L(set96) str q0, [dstend, -16] tbz count, 5, 1f str q0, [dstin, 16] str q0, [dstend, -32] 1: ret .p2align 4 /* Set 64..96 bytes. Write 64 bytes from the start and 32 bytes from the end. */ L(set96): str q0, [dstin, 16] stp q0, q0, [dstin, 32] stp q0, q0, [dstend, -32] ret .p2align 4 L(set_long): and valw, valw, 255 bic dst, dstin, 15 str q0, [dstin] cmp count, 160 ccmp valw, 0, 0, hs b.ne L(no_zva) #ifndef SKIP_ZVA_CHECK mrs zva_val, dczid_el0 and zva_val, zva_val, 31 cmp zva_val, 4 /* ZVA size is 64 bytes. */ b.ne L(no_zva) #endif str q0, [dst, 16] stp q0, q0, [dst, 32] bic dst, dst, 63 sub count, dstend, dst /* Count is now 64 too large. */ sub count, count, 128 /* Adjust count and bias for loop. */ .p2align 4 L(zva_loop): add dst, dst, 64 dc zva, dst subs count, count, 64 b.hi L(zva_loop) stp q0, q0, [dstend, -64] stp q0, q0, [dstend, -32] ret L(no_zva): sub count, dstend, dst /* Count is 16 too large. */ sub dst, dst, 16 /* Dst is biased by -32. */ sub count, count, 64 + 16 /* Adjust count and bias for loop. */ L(no_zva_loop): stp q0, q0, [dst, 32] stp q0, q0, [dst, 64]! subs count, count, 64 b.hi L(no_zva_loop) stp q0, q0, [dstend, -64] stp q0, q0, [dstend, -32] ret END (memset) #endif picolibc-1.8.11/libc/machine/aarch64/meson.build000066400000000000000000000051451513574234600213140ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard, # Copyright © 2020 Anthony Anderson # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'interrupt.c', 'interrupt_vector.S', 'memchr-stub.c', 'memchr.S', 'memcmp-stub.c', 'memcmp.S', 'memcpy-stub.c', 'memcpy.S', 'memmove-stub.c', 'memmove.S', 'memrchr-stub.c', 'memrchr.S', 'memset-stub.c', 'memset.S', 'rawmemchr-stub.c', 'rawmemchr.S', 'setjmp.S', 'stpcpy-stub.c', 'stpcpy.S', 'strchr-stub.c', 'strchr.S', 'strchrnul-stub.c', 'strchrnul.S', 'strcmp-stub.c', 'strcmp.S', 'strcpy-stub.c', 'strcpy.S', 'strlen-stub.c', 'strlen.S', 'strncmp-stub.c', 'strncmp.S', 'strnlen-stub.c', 'strnlen.S', 'strrchr-stub.c', 'strrchr.S', 'tls.c' ] subdir('machine') subdir('sys') foreach params : targets target = params['name'] target_dir = params['dir'] target_c_args = params['c_args'] set_variable('lib_machine' + target, static_library('machine' + target, srcs_machine, pic: false, include_directories: inc, c_args: target_c_args + c_args + arg_fnobuiltin + arg_fnolto)) endforeach picolibc-1.8.11/libc/machine/aarch64/rawmemchr-stub.c000066400000000000000000000033601513574234600222530ustar00rootroot00000000000000/* Copyright (c) 2015-2016, ARM Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the company nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) #include "../../string/rawmemchr.c" #else /* See rawmemchr.S. */ #endif picolibc-1.8.11/libc/machine/aarch64/rawmemchr.S000066400000000000000000000043331513574234600212610ustar00rootroot00000000000000/* Copyright (c) 2015-2016, ARM Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the company nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Assumptions: * * ARMv8-a, AArch64, unaligned accesses * */ #include #if (defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) /* See rawmemchr-stub.c. */ #else #define L(l) .L ## l .macro def_fn f p2align=0 .text .p2align \p2align .global \f .type \f, %function \f: .endm /* Special case rawmemchr (s, 0) as strlen, otherwise tailcall memchr. Call strlen without setting up a full frame - it preserves x14/x15. */ def_fn rawmemchr p2align=5 cbz w1, L(do_strlen) mov x2, -1 b memchr L(do_strlen): mov x15, x30 mov x14, x0 bl strlen add x0, x14, x0 ret x15 .size rawmemchr, . - rawmemchr #endif picolibc-1.8.11/libc/machine/aarch64/setjmp.S000066400000000000000000000051251513574234600205760ustar00rootroot00000000000000/* Copyright (c) 2011, 2012 ARM Ltd All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the company may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #define GPR_LAYOUT \ REG_PAIR (x19, x20, 0); \ REG_PAIR (x21, x22, 16); \ REG_PAIR (x23, x24, 32); \ REG_PAIR (x25, x26, 48); \ REG_PAIR (x27, x28, 64); \ REG_PAIR (x29, x30, 80); \ REG_ONE (x16, 96) #define FPR_LAYOUT \ REG_PAIR ( d8, d9, 112); \ REG_PAIR (d10, d11, 128); \ REG_PAIR (d12, d13, 144); \ REG_PAIR (d14, d15, 160); // int setjmp (jmp_buf) .global setjmp .type setjmp, %function setjmp: #ifndef __LP64__ mov w0, w0 #endif mov x16, sp #define REG_PAIR(REG1, REG2, OFFS) stp REG1, REG2, [x0, OFFS] #define REG_ONE(REG1, OFFS) str REG1, [x0, OFFS] GPR_LAYOUT #if __ARM_FP FPR_LAYOUT #endif #undef REG_PAIR #undef REG_ONE mov w0, #0 ret .size setjmp, .-setjmp // void longjmp (jmp_buf, int) __noreturn .global longjmp .type longjmp, %function longjmp: #ifndef __LP64__ mov w0, w0 #endif #define REG_PAIR(REG1, REG2, OFFS) ldp REG1, REG2, [x0, OFFS] #define REG_ONE(REG1, OFFS) ldr REG1, [x0, OFFS] GPR_LAYOUT #if __ARM_FP FPR_LAYOUT #endif #undef REG_PAIR #undef REG_ONE mov sp, x16 cmp w1, #0 cinc w0, w1, eq // use br not ret, as ret is guaranteed to mispredict br x30 .size longjmp, .-longjmp picolibc-1.8.11/libc/machine/aarch64/stpcpy-stub.c000066400000000000000000000033441513574234600216120ustar00rootroot00000000000000/* Copyright (c) 2015, ARM Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the company nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) #include "../../string/stpcpy.c" #else /* See stpcpy.S */ #endif picolibc-1.8.11/libc/machine/aarch64/stpcpy.S000066400000000000000000000003071513574234600206130ustar00rootroot00000000000000/* * stpcpy - copy a string returning pointer to end. * * Copyright (c) 2020, Arm Limited. * SPDX-License-Identifier: MIT */ #include #define BUILD_STPCPY 1 #include "strcpy.S" picolibc-1.8.11/libc/machine/aarch64/strchr-stub.c000066400000000000000000000034021513574234600215700ustar00rootroot00000000000000/* Copyright (c) 2014, ARM Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the company nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) \ || !defined(__ARM_NEON) #include "../../string/strchr.c" #else /* See strchr.S */ #endif picolibc-1.8.11/libc/machine/aarch64/strchr.S000066400000000000000000000126121513574234600206000ustar00rootroot00000000000000/* strchr - find a character in a string Copyright (c) 2014-2022, ARM Limited All rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the company nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) || !defined(__ARM_NEON) /* See strchr-stub.c */ #else /* Assumptions: * * ARMv8-a, AArch64 * Neon Available. */ #include "asmdefs.h" /* Arguments and results. */ #define srcin x0 #define chrin w1 #define result x0 #define src x2 #define tmp1 x3 #define wtmp2 w4 #define tmp3 x5 #define vrepchr v0 #define vdata1 v1 #define vdata2 v2 #define vhas_nul1 v3 #define vhas_nul2 v4 #define vhas_chr1 v5 #define vhas_chr2 v6 #define vrepmask_0 v7 #define vrepmask_c v16 #define vend1 v17 #define vend2 v18 /* Core algorithm. For each 32-byte hunk we calculate a 64-bit syndrome value, with two bits per byte (LSB is always in bits 0 and 1, for both big and little-endian systems). For each tuple, bit 0 is set iff the relevant byte matched the requested character; bit 1 is set iff the relevant byte matched the NUL end of string (we trigger off bit0 for the special case of looking for NUL). Since the bits in the syndrome reflect exactly the order in which things occur in the original string a count_trailing_zeros() operation will identify exactly which byte is causing the termination, and why. */ /* Locals and temporaries. */ ENTRY (strchr) PTR_ARG (0) /* Magic constant 0xc0300c03 to allow us to identify which lane matches the requested byte. Even bits are set if the character matches, odd bits if either the char is NUL or matches. */ mov wtmp2, 0x0c03 movk wtmp2, 0xc030, lsl 16 dup vrepchr.16b, chrin bic src, srcin, #31 /* Work with aligned 32-byte hunks. */ dup vrepmask_c.4s, wtmp2 ands tmp1, srcin, #31 add vrepmask_0.4s, vrepmask_c.4s, vrepmask_c.4s /* equiv: lsl #1 */ b.eq L(loop) /* Input string is not 32-byte aligned. Rather than forcing the padding bytes to a safe value, we calculate the syndrome for all the bytes, but then mask off those bits of the syndrome that are related to the padding. */ ld1 {vdata1.16b, vdata2.16b}, [src], #32 neg tmp1, tmp1 cmeq vhas_nul1.16b, vdata1.16b, #0 cmeq vhas_chr1.16b, vdata1.16b, vrepchr.16b cmeq vhas_nul2.16b, vdata2.16b, #0 cmeq vhas_chr2.16b, vdata2.16b, vrepchr.16b bif vhas_nul1.16b, vhas_chr1.16b, vrepmask_0.16b bif vhas_nul2.16b, vhas_chr2.16b, vrepmask_0.16b and vend1.16b, vhas_nul1.16b, vrepmask_c.16b and vend2.16b, vhas_nul2.16b, vrepmask_c.16b lsl tmp1, tmp1, #1 addp vend1.16b, vend1.16b, vend2.16b // 256->128 mov tmp3, #~0 addp vend1.16b, vend1.16b, vend2.16b // 128->64 lsr tmp1, tmp3, tmp1 mov tmp3, vend1.d[0] bic tmp1, tmp3, tmp1 // Mask padding bits. cbnz tmp1, L(tail) .p2align 4 L(loop): ld1 {vdata1.16b, vdata2.16b}, [src], #32 cmeq vhas_chr1.16b, vdata1.16b, vrepchr.16b cmeq vhas_chr2.16b, vdata2.16b, vrepchr.16b cmhs vhas_nul1.16b, vhas_chr1.16b, vdata1.16b cmhs vhas_nul2.16b, vhas_chr2.16b, vdata2.16b orr vend1.16b, vhas_nul1.16b, vhas_nul2.16b umaxp vend1.16b, vend1.16b, vend1.16b mov tmp1, vend1.d[0] cbz tmp1, L(loop) /* Termination condition found. Now need to establish exactly why we terminated. */ bif vhas_nul1.16b, vhas_chr1.16b, vrepmask_0.16b bif vhas_nul2.16b, vhas_chr2.16b, vrepmask_0.16b and vend1.16b, vhas_nul1.16b, vrepmask_c.16b and vend2.16b, vhas_nul2.16b, vrepmask_c.16b addp vend1.16b, vend1.16b, vend2.16b // 256->128 addp vend1.16b, vend1.16b, vend2.16b // 128->64 mov tmp1, vend1.d[0] L(tail): /* Count the trailing zeros, by bit reversing... */ rbit tmp1, tmp1 /* Re-bias source. */ sub src, src, #32 clz tmp1, tmp1 /* And counting the leading zeros. */ /* Tmp1 is even if the target charager was found first. Otherwise we've found the end of string and we weren't looking for NUL. */ tst tmp1, #1 add result, src, tmp1, lsr #1 csel result, result, xzr, eq ret END (strchr) #endif picolibc-1.8.11/libc/machine/aarch64/strchrnul-stub.c000066400000000000000000000034101513574234600223060ustar00rootroot00000000000000/* Copyright (c) 2014, ARM Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the company nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) \ || !defined(__ARM_NEON) #include "../../string/strchrnul.c" #else /* See strchrnul.S */ #endif picolibc-1.8.11/libc/machine/aarch64/strchrnul.S000066400000000000000000000114641513574234600213230ustar00rootroot00000000000000/* strchrnul - find a character or nul in a string Copyright (c) 2014-2022, ARM Limited All rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the company nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) || !defined(__ARM_NEON) /* See strchrnul-stub.c */ #else /* Assumptions: * * ARMv8-a, AArch64 * Neon Available. */ #include "asmdefs.h" /* Arguments and results. */ #define srcin x0 #define chrin w1 #define result x0 #define src x2 #define tmp1 x3 #define wtmp2 w4 #define tmp3 x5 #define vrepchr v0 #define vdata1 v1 #define vdata2 v2 #define vhas_nul1 v3 #define vhas_nul2 v4 #define vhas_chr1 v5 #define vhas_chr2 v6 #define vrepmask v7 #define vend1 v16 /* Core algorithm. For each 32-byte hunk we calculate a 64-bit syndrome value, with two bits per byte (LSB is always in bits 0 and 1, for both big and little-endian systems). For each tuple, bit 0 is set iff the relevant byte matched the requested character or nul. Since the bits in the syndrome reflect exactly the order in which things occur in the original string a count_trailing_zeros() operation will identify exactly which byte is causing the termination. */ /* Locals and temporaries. */ ENTRY (strchrnul) PTR_ARG (0) /* Magic constant 0x40100401 to allow us to identify which lane matches the termination condition. */ mov wtmp2, #0x0401 movk wtmp2, #0x4010, lsl #16 dup vrepchr.16b, chrin bic src, srcin, #31 /* Work with aligned 32-byte hunks. */ dup vrepmask.4s, wtmp2 ands tmp1, srcin, #31 b.eq L(loop) /* Input string is not 32-byte aligned. Rather than forcing the padding bytes to a safe value, we calculate the syndrome for all the bytes, but then mask off those bits of the syndrome that are related to the padding. */ ld1 {vdata1.16b, vdata2.16b}, [src], #32 neg tmp1, tmp1 cmeq vhas_chr1.16b, vdata1.16b, vrepchr.16b cmeq vhas_chr2.16b, vdata2.16b, vrepchr.16b cmhs vhas_nul1.16b, vhas_chr1.16b, vdata1.16b cmhs vhas_nul2.16b, vhas_chr2.16b, vdata2.16b and vhas_chr1.16b, vhas_nul1.16b, vrepmask.16b and vhas_chr2.16b, vhas_nul2.16b, vrepmask.16b lsl tmp1, tmp1, #1 addp vend1.16b, vhas_chr1.16b, vhas_chr2.16b // 256->128 mov tmp3, #~0 addp vend1.16b, vend1.16b, vend1.16b // 128->64 lsr tmp1, tmp3, tmp1 mov tmp3, vend1.d[0] bic tmp1, tmp3, tmp1 // Mask padding bits. cbnz tmp1, L(tail) .p2align 4 L(loop): ld1 {vdata1.16b, vdata2.16b}, [src], #32 cmeq vhas_chr1.16b, vdata1.16b, vrepchr.16b cmeq vhas_chr2.16b, vdata2.16b, vrepchr.16b cmhs vhas_nul1.16b, vhas_chr1.16b, vdata1.16b cmhs vhas_nul2.16b, vhas_chr2.16b, vdata2.16b orr vend1.16b, vhas_nul1.16b, vhas_nul2.16b umaxp vend1.16b, vend1.16b, vend1.16b mov tmp1, vend1.d[0] cbz tmp1, L(loop) /* Termination condition found. Now need to establish exactly why we terminated. */ and vhas_chr1.16b, vhas_nul1.16b, vrepmask.16b and vhas_chr2.16b, vhas_nul2.16b, vrepmask.16b addp vend1.16b, vhas_chr1.16b, vhas_chr2.16b // 256->128 addp vend1.16b, vend1.16b, vend1.16b // 128->64 mov tmp1, vend1.d[0] L(tail): /* Count the trailing zeros, by bit reversing... */ rbit tmp1, tmp1 /* Re-bias source. */ sub src, src, #32 clz tmp1, tmp1 /* ... and counting the leading zeros. */ /* tmp1 is twice the offset into the fragment. */ add result, src, tmp1, lsr #1 ret END (strchrnul) #endif picolibc-1.8.11/libc/machine/aarch64/strcmp-stub.c000066400000000000000000000033521513574234600215770ustar00rootroot00000000000000/* Copyright (c) 2012-2013, Linaro Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) #include "../../string/strcmp.c" #else /* See strcmp.S */ #endif picolibc-1.8.11/libc/machine/aarch64/strcmp.S000066400000000000000000000102401513574234600205760ustar00rootroot00000000000000/* * strcmp - compare two strings * * Copyright (c) 2012-2022, Arm Limited. * SPDX-License-Identifier: MIT */ #include #if (defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) /* See strcmp-stub.c */ #else /* Assumptions: * * ARMv8-a, AArch64. * MTE compatible. */ #include "asmdefs.h" #define REP8_01 0x0101010101010101 #define REP8_7f 0x7f7f7f7f7f7f7f7f #define src1 x0 #define src2 x1 #define result x0 #define data1 x2 #define data1w w2 #define data2 x3 #define data2w w3 #define has_nul x4 #define diff x5 #define off1 x5 #define syndrome x6 #define tmp x6 #define data3 x7 #define zeroones x8 #define shift x9 #define off2 x10 /* On big-endian early bytes are at MSB and on little-endian LSB. LS_FW means shifting towards early bytes. */ #ifdef __AARCH64EB__ # define LS_FW lsl #else # define LS_FW lsr #endif /* NUL detection works on the principle that (X - 1) & (~X) & 0x80 (=> (X - 1) & ~(X | 0x7f)) is non-zero iff a byte is zero, and can be done in parallel across the entire word. Since carry propagation makes 0x1 bytes before a NUL byte appear NUL too in big-endian, byte-reverse the data before the NUL check. */ ENTRY (strcmp) PTR_ARG (0) PTR_ARG (1) sub off2, src2, src1 mov zeroones, REP8_01 and tmp, src1, 7 tst off2, 7 b.ne L(misaligned8) cbnz tmp, L(mutual_align) .p2align 4 L(loop_aligned): ldr data2, [src1, off2] ldr data1, [src1], 8 L(start_realigned): #ifdef __AARCH64EB__ rev tmp, data1 sub has_nul, tmp, zeroones orr tmp, tmp, REP8_7f #else sub has_nul, data1, zeroones orr tmp, data1, REP8_7f #endif bics has_nul, has_nul, tmp /* Non-zero if NUL terminator. */ ccmp data1, data2, 0, eq b.eq L(loop_aligned) #ifdef __AARCH64EB__ rev has_nul, has_nul #endif eor diff, data1, data2 orr syndrome, diff, has_nul L(end): #ifndef __AARCH64EB__ rev syndrome, syndrome rev data1, data1 rev data2, data2 #endif clz shift, syndrome /* The most-significant-non-zero bit of the syndrome marks either the first bit that is different, or the top bit of the first zero byte. Shifting left now will bring the critical information into the top bits. */ lsl data1, data1, shift lsl data2, data2, shift /* But we need to zero-extend (char is unsigned) the value and then perform a signed 32-bit subtraction. */ lsr data1, data1, 56 sub result, data1, data2, lsr 56 ret .p2align 4 L(mutual_align): /* Sources are mutually aligned, but are not currently at an alignment boundary. Round down the addresses and then mask off the bytes that precede the start point. */ bic src1, src1, 7 ldr data2, [src1, off2] ldr data1, [src1], 8 neg shift, src2, lsl 3 /* Bits to alignment -64. */ mov tmp, -1 LS_FW tmp, tmp, shift orr data1, data1, tmp orr data2, data2, tmp b L(start_realigned) L(misaligned8): /* Align SRC1 to 8 bytes and then compare 8 bytes at a time, always checking to make sure that we don't access beyond the end of SRC2. */ cbz tmp, L(src1_aligned) L(do_misaligned): ldrb data1w, [src1], 1 ldrb data2w, [src2], 1 cmp data1w, 0 ccmp data1w, data2w, 0, ne /* NZCV = 0b0000. */ b.ne L(done) tst src1, 7 b.ne L(do_misaligned) L(src1_aligned): neg shift, src2, lsl 3 bic src2, src2, 7 ldr data3, [src2], 8 #ifdef __AARCH64EB__ rev data3, data3 #endif lsr tmp, zeroones, shift orr data3, data3, tmp sub has_nul, data3, zeroones orr tmp, data3, REP8_7f bics has_nul, has_nul, tmp b.ne L(tail) sub off1, src2, src1 .p2align 4 L(loop_unaligned): ldr data3, [src1, off1] ldr data2, [src1, off2] #ifdef __AARCH64EB__ rev data3, data3 #endif sub has_nul, data3, zeroones orr tmp, data3, REP8_7f ldr data1, [src1], 8 bics has_nul, has_nul, tmp ccmp data1, data2, 0, eq b.eq L(loop_unaligned) lsl tmp, has_nul, shift #ifdef __AARCH64EB__ rev tmp, tmp #endif eor diff, data1, data2 orr syndrome, diff, tmp cbnz syndrome, L(end) L(tail): ldr data1, [src1] neg shift, shift lsr data2, data3, shift lsr has_nul, has_nul, shift #ifdef __AARCH64EB__ rev data2, data2 rev has_nul, has_nul #endif eor diff, data1, data2 orr syndrome, diff, has_nul b L(end) L(done): sub result, data1, data2 ret END (strcmp) #endif picolibc-1.8.11/libc/machine/aarch64/strcpy-stub.c000066400000000000000000000034021513574234600216070ustar00rootroot00000000000000/* Copyright (c) 2014, ARM Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the company nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) \ || !defined(__ARM_NEON) #include "../../string/strcpy.c" #else /* See strcpy.S */ #endif picolibc-1.8.11/libc/machine/aarch64/strcpy.S000066400000000000000000000112461513574234600206210ustar00rootroot00000000000000/* strcpy/stpcpy - copy a string returning pointer to start/end. Copyright (c) 2013, 2014, 2015, 2020-2023 ARM Ltd. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the company nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) || !defined(__ARM_NEON) /* See strcpy-stub.c */ #else /* Assumptions: * * ARMv8-a, AArch64, Advanced SIMD. * MTE compatible. */ #include "asmdefs.h" #define dstin x0 #define srcin x1 #define result x0 #define src x2 #define dst x3 #define len x4 #define synd x4 #define tmp x5 #define shift x5 #define data1 x6 #define dataw1 w6 #define data2 x7 #define dataw2 w7 #define dataq q0 #define vdata v0 #define vhas_nul v1 #define vend v2 #define dend d2 #define dataq2 q1 #ifdef BUILD_STPCPY # define STRCPY stpcpy # define IFSTPCPY(X,...) X,__VA_ARGS__ #else # define STRCPY strcpy # define IFSTPCPY(X,...) #endif /* Core algorithm: For each 16-byte chunk we calculate a 64-bit nibble mask value with four bits per byte. We take 4 bits of every comparison byte with shift right and narrow by 4 instruction. Since the bits in the nibble mask reflect the order in which things occur in the original string, counting leading zeros identifies exactly which byte matched. */ ENTRY (STRCPY) PTR_ARG (0) PTR_ARG (1) bic src, srcin, 15 ld1 {vdata.16b}, [src] cmeq vhas_nul.16b, vdata.16b, 0 lsl shift, srcin, 2 shrn vend.8b, vhas_nul.8h, 4 fmov synd, dend lsr synd, synd, shift cbnz synd, L(tail) ldr dataq, [src, 16]! cmeq vhas_nul.16b, vdata.16b, 0 shrn vend.8b, vhas_nul.8h, 4 fmov synd, dend cbz synd, L(start_loop) #ifndef __AARCH64EB__ rbit synd, synd #endif sub tmp, src, srcin clz len, synd add len, tmp, len, lsr 2 tbz len, 4, L(less16) sub tmp, len, 15 ldr dataq, [srcin] ldr dataq2, [srcin, tmp] str dataq, [dstin] str dataq2, [dstin, tmp] IFSTPCPY (add result, dstin, len) ret L(tail): rbit synd, synd clz len, synd lsr len, len, 2 L(less16): tbz len, 3, L(less8) sub tmp, len, 7 ldr data1, [srcin] ldr data2, [srcin, tmp] str data1, [dstin] str data2, [dstin, tmp] IFSTPCPY (add result, dstin, len) ret .p2align 4 L(less8): subs tmp, len, 3 b.lo L(less4) ldr dataw1, [srcin] ldr dataw2, [srcin, tmp] str dataw1, [dstin] str dataw2, [dstin, tmp] IFSTPCPY (add result, dstin, len) ret L(less4): cbz len, L(zerobyte) ldrh dataw1, [srcin] strh dataw1, [dstin] L(zerobyte): strb wzr, [dstin, len] IFSTPCPY (add result, dstin, len) ret .p2align 4 L(start_loop): sub tmp, srcin, dstin ldr dataq2, [srcin] sub dst, src, tmp str dataq2, [dstin] L(loop): str dataq, [dst], 32 ldr dataq, [src, 16] cmeq vhas_nul.16b, vdata.16b, 0 umaxp vend.16b, vhas_nul.16b, vhas_nul.16b fmov synd, dend cbnz synd, L(loopend) str dataq, [dst, -16] ldr dataq, [src, 32]! cmeq vhas_nul.16b, vdata.16b, 0 umaxp vend.16b, vhas_nul.16b, vhas_nul.16b fmov synd, dend cbz synd, L(loop) add dst, dst, 16 L(loopend): shrn vend.8b, vhas_nul.8h, 4 /* 128->64 */ fmov synd, dend sub dst, dst, 31 #ifndef __AARCH64EB__ rbit synd, synd #endif clz len, synd lsr len, len, 2 add dst, dst, len ldr dataq, [dst, tmp] str dataq, [dst] IFSTPCPY (add result, dst, 15) ret END (STRCPY) #endif picolibc-1.8.11/libc/machine/aarch64/strlen-stub.c000066400000000000000000000034031513574234600215730ustar00rootroot00000000000000/* Copyright (c) 2013, Linaro Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) \ || !defined(__ARM_NEON) #include "../../string/strlen.c" #else /* See strlen.S */ #endif picolibc-1.8.11/libc/machine/aarch64/strlen.S000066400000000000000000000145321513574234600206050ustar00rootroot00000000000000/* Copyright (c) 2013-2015, Linaro Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) || !defined(__ARM_NEON) /* See strlen-stub.c */ #else /* Assumptions: * * ARMv8-a, AArch64, Advanced SIMD, unaligned accesses. * Not MTE compatible. */ #include "asmdefs.h" #define srcin x0 #define len x0 #define src x1 #define data1 x2 #define data2 x3 #define has_nul1 x4 #define has_nul2 x5 #define tmp1 x4 #define tmp2 x5 #define tmp3 x6 #define tmp4 x7 #define zeroones x8 #define maskv v0 #define maskd d0 #define dataq1 q1 #define dataq2 q2 #define datav1 v1 #define datav2 v2 #define tmp x2 #define tmpw w2 #define synd x3 #define syndw w3 #define shift x4 /* For the first 32 bytes, NUL detection works on the principle that (X - 1) & (~X) & 0x80 (=> (X - 1) & ~(X | 0x7f)) is non-zero if a byte is zero, and can be done in parallel across the entire word. */ #define REP8_01 0x0101010101010101 #define REP8_7f 0x7f7f7f7f7f7f7f7f /* To test the page crossing code path more thoroughly, compile with -DTEST_PAGE_CROSS - this will force all calls through the slower entry path. This option is not intended for production use. */ #ifdef TEST_PAGE_CROSS # define MIN_PAGE_SIZE 32 #else # define MIN_PAGE_SIZE 4096 #endif /* Core algorithm: Since strings are short on average, we check the first 32 bytes of the string for a NUL character without aligning the string. In order to use unaligned loads safely we must do a page cross check first. If there is a NUL byte we calculate the length from the 2 8-byte words using conditional select to reduce branch mispredictions (it is unlikely strlen will be repeatedly called on strings with the same length). If the string is longer than 32 bytes, align src so we don't need further page cross checks, and process 32 bytes per iteration using a fast SIMD loop. If the page cross check fails, we read 32 bytes from an aligned address, and ignore any characters before the string. If it contains a NUL character, return the length, if not, continue in the main loop. */ ENTRY (strlen) PTR_ARG (0) and tmp1, srcin, MIN_PAGE_SIZE - 1 cmp tmp1, MIN_PAGE_SIZE - 32 b.hi L(page_cross) /* Look for a NUL byte in the first 16 bytes. */ ldp data1, data2, [srcin] mov zeroones, REP8_01 #ifdef __AARCH64EB__ /* For big-endian, carry propagation (if the final byte in the string is 0x01) means we cannot use has_nul1/2 directly. Since we expect strings to be small and early-exit, byte-swap the data now so has_null1/2 will be correct. */ rev data1, data1 rev data2, data2 #endif sub tmp1, data1, zeroones orr tmp2, data1, REP8_7f sub tmp3, data2, zeroones orr tmp4, data2, REP8_7f bics has_nul1, tmp1, tmp2 bic has_nul2, tmp3, tmp4 ccmp has_nul2, 0, 0, eq b.eq L(bytes16_31) /* Find the exact offset of the first NUL byte in the first 16 bytes from the string start. Enter with C = has_nul1 == 0. */ csel has_nul1, has_nul1, has_nul2, cc mov len, 8 rev has_nul1, has_nul1 csel len, xzr, len, cc clz tmp1, has_nul1 add len, len, tmp1, lsr 3 ret /* Look for a NUL byte at offset 16..31 in the string. */ L(bytes16_31): ldp data1, data2, [srcin, 16] #ifdef __AARCH64EB__ rev data1, data1 rev data2, data2 #endif sub tmp1, data1, zeroones orr tmp2, data1, REP8_7f sub tmp3, data2, zeroones orr tmp4, data2, REP8_7f bics has_nul1, tmp1, tmp2 bic has_nul2, tmp3, tmp4 ccmp has_nul2, 0, 0, eq b.eq L(loop_entry) /* Find the exact offset of the first NUL byte at offset 16..31 from the string start. Enter with C = has_nul1 == 0. */ csel has_nul1, has_nul1, has_nul2, cc mov len, 24 rev has_nul1, has_nul1 mov tmp3, 16 clz tmp1, has_nul1 csel len, tmp3, len, cc add len, len, tmp1, lsr 3 ret nop L(loop_entry): bic src, srcin, 31 .p2align 5 L(loop): ldp dataq1, dataq2, [src, 32]! uminp maskv.16b, datav1.16b, datav2.16b uminp maskv.16b, maskv.16b, maskv.16b cmeq maskv.8b, maskv.8b, 0 fmov synd, maskd cbz synd, L(loop) /* Low 32 bits of synd are non-zero if a NUL was found in datav1. */ cmeq maskv.16b, datav1.16b, 0 sub len, src, srcin cbnz syndw, 1f cmeq maskv.16b, datav2.16b, 0 add len, len, 16 1: /* Generate a bitmask and compute correct byte offset. */ shrn maskv.8b, maskv.8h, 4 fmov synd, maskd #ifndef __AARCH64EB__ rbit synd, synd #endif clz tmp, synd add len, len, tmp, lsr 2 ret L(page_cross): bic src, srcin, 31 mov tmpw, 0x0c03 movk tmpw, 0xc030, lsl 16 ld1 {datav1.16b, datav2.16b}, [src] dup maskv.4s, tmpw cmeq datav1.16b, datav1.16b, 0 cmeq datav2.16b, datav2.16b, 0 and datav1.16b, datav1.16b, maskv.16b and datav2.16b, datav2.16b, maskv.16b addp maskv.16b, datav1.16b, datav2.16b addp maskv.16b, maskv.16b, maskv.16b fmov synd, maskd lsl shift, srcin, 1 lsr synd, synd, shift cbz synd, L(loop) rbit synd, synd clz len, synd lsr len, len, 1 ret END (strlen) #endif picolibc-1.8.11/libc/machine/aarch64/strncmp-stub.c000066400000000000000000000033471513574234600217610ustar00rootroot00000000000000/* Copyright (c) 2013, Linaro Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) #include "../../string/strncmp.c" #else /* See strncmp.S */ #endif picolibc-1.8.11/libc/machine/aarch64/strncmp.S000066400000000000000000000245461513574234600207720ustar00rootroot00000000000000/* Copyright (c) 2013, 2018, Linaro Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) /* See strncmp-stub.c */ #else /* Assumptions: * * ARMv8-a, AArch64. * MTE compatible. */ #include "asmdefs.h" #define REP8_01 0x0101010101010101 #define REP8_7f 0x7f7f7f7f7f7f7f7f /* Parameters and result. */ #define src1 x0 #define src2 x1 #define limit x2 #define result x0 /* Internal variables. */ #define data1 x3 #define data1w w3 #define data2 x4 #define data2w w4 #define has_nul x5 #define diff x6 #define syndrome x7 #define tmp1 x8 #define tmp2 x9 #define tmp3 x10 #define zeroones x11 #define pos x12 #define mask x13 #define endloop x14 #define count mask #define offset pos #define neg_offset x15 /* Define endian dependent shift operations. On big-endian early bytes are at MSB and on little-endian LSB. LS_FW means shifting towards early bytes. LS_BK means shifting towards later bytes. */ #ifdef __AARCH64EB__ #define LS_FW lsl #define LS_BK lsr #else #define LS_FW lsr #define LS_BK lsl #endif ENTRY (strncmp) PTR_ARG (0) PTR_ARG (1) SIZE_ARG (2) cbz limit, L(ret0) eor tmp1, src1, src2 mov zeroones, #REP8_01 tst tmp1, #7 and count, src1, #7 b.ne L(misaligned8) cbnz count, L(mutual_align) /* NUL detection works on the principle that (X - 1) & (~X) & 0x80 (=> (X - 1) & ~(X | 0x7f)) is non-zero iff a byte is zero, and can be done in parallel across the entire word. */ .p2align 4 L(loop_aligned): ldr data1, [src1], #8 ldr data2, [src2], #8 L(start_realigned): subs limit, limit, #8 sub tmp1, data1, zeroones orr tmp2, data1, #REP8_7f eor diff, data1, data2 /* Non-zero if differences found. */ csinv endloop, diff, xzr, hi /* Last Dword or differences. */ bics has_nul, tmp1, tmp2 /* Non-zero if NUL terminator. */ ccmp endloop, #0, #0, eq b.eq L(loop_aligned) /* End of main loop */ L(full_check): #ifndef __AARCH64EB__ orr syndrome, diff, has_nul add limit, limit, 8 /* Rewind limit to before last subs. */ L(syndrome_check): /* Limit was reached. Check if the NUL byte or the difference is before the limit. */ rev syndrome, syndrome rev data1, data1 clz pos, syndrome rev data2, data2 lsl data1, data1, pos cmp limit, pos, lsr #3 lsl data2, data2, pos /* But we need to zero-extend (char is unsigned) the value and then perform a signed 32-bit subtraction. */ lsr data1, data1, #56 sub result, data1, data2, lsr #56 csel result, result, xzr, hi ret #else /* Not reached the limit, must have found the end or a diff. */ tbz limit, #63, L(not_limit) add tmp1, limit, 8 cbz limit, L(not_limit) lsl limit, tmp1, #3 /* Bits -> bytes. */ mov mask, #~0 lsr mask, mask, limit bic data1, data1, mask bic data2, data2, mask /* Make sure that the NUL byte is marked in the syndrome. */ orr has_nul, has_nul, mask L(not_limit): /* For big-endian we cannot use the trick with the syndrome value as carry-propagation can corrupt the upper bits if the trailing bytes in the string contain 0x01. */ /* However, if there is no NUL byte in the dword, we can generate the result directly. We can't just subtract the bytes as the MSB might be significant. */ cbnz has_nul, 1f cmp data1, data2 cset result, ne cneg result, result, lo ret 1: /* Re-compute the NUL-byte detection, using a byte-reversed value. */ rev tmp3, data1 sub tmp1, tmp3, zeroones orr tmp2, tmp3, #REP8_7f bic has_nul, tmp1, tmp2 rev has_nul, has_nul orr syndrome, diff, has_nul clz pos, syndrome /* The most-significant-non-zero bit of the syndrome marks either the first bit that is different, or the top bit of the first zero byte. Shifting left now will bring the critical information into the top bits. */ L(end_quick): lsl data1, data1, pos lsl data2, data2, pos /* But we need to zero-extend (char is unsigned) the value and then perform a signed 32-bit subtraction. */ lsr data1, data1, #56 sub result, data1, data2, lsr #56 ret #endif L(mutual_align): /* Sources are mutually aligned, but are not currently at an alignment boundary. Round down the addresses and then mask off the bytes that precede the start point. We also need to adjust the limit calculations, but without overflowing if the limit is near ULONG_MAX. */ bic src1, src1, #7 bic src2, src2, #7 ldr data1, [src1], #8 neg tmp3, count, lsl #3 /* 64 - bits(bytes beyond align). */ ldr data2, [src2], #8 mov tmp2, #~0 LS_FW tmp2, tmp2, tmp3 /* Shift (count & 63). */ /* Adjust the limit and ensure it doesn't overflow. */ adds limit, limit, count csinv limit, limit, xzr, lo orr data1, data1, tmp2 orr data2, data2, tmp2 b L(start_realigned) .p2align 4 /* Don't bother with dwords for up to 16 bytes. */ L(misaligned8): cmp limit, #16 b.hs L(try_misaligned_words) L(byte_loop): /* Perhaps we can do better than this. */ ldrb data1w, [src1], #1 ldrb data2w, [src2], #1 subs limit, limit, #1 ccmp data1w, #1, #0, hi /* NZCV = 0b0000. */ ccmp data1w, data2w, #0, cs /* NZCV = 0b0000. */ b.eq L(byte_loop) L(done): sub result, data1, data2 ret /* Align the SRC1 to a dword by doing a bytewise compare and then do the dword loop. */ L(try_misaligned_words): cbz count, L(src1_aligned) neg count, count and count, count, #7 sub limit, limit, count L(page_end_loop): ldrb data1w, [src1], #1 ldrb data2w, [src2], #1 cmp data1w, #1 ccmp data1w, data2w, #0, cs /* NZCV = 0b0000. */ b.ne L(done) subs count, count, #1 b.hi L(page_end_loop) /* The following diagram explains the comparison of misaligned strings. The bytes are shown in natural order. For little-endian, it is reversed in the registers. The "x" bytes are before the string. The "|" separates data that is loaded at one time. src1 | a a a a a a a a | b b b c c c c c | . . . src2 | x x x x x a a a a a a a a b b b | c c c c c . . . After shifting in each step, the data looks like this: STEP_A STEP_B STEP_C data1 a a a a a a a a b b b c c c c c b b b c c c c c data2 a a a a a a a a b b b 0 0 0 0 0 0 0 0 c c c c c The bytes with "0" are eliminated from the syndrome via mask. Align SRC2 down to 16 bytes. This way we can read 16 bytes at a time from SRC2. The comparison happens in 3 steps. After each step the loop can exit, or read from SRC1 or SRC2. */ L(src1_aligned): /* Calculate offset from 8 byte alignment to string start in bits. No need to mask offset since shifts are ignoring upper bits. */ lsl offset, src2, #3 bic src2, src2, #0xf mov mask, -1 neg neg_offset, offset ldr data1, [src1], #8 ldp tmp1, tmp2, [src2], #16 LS_BK mask, mask, neg_offset and neg_offset, neg_offset, #63 /* Need actual value for cmp later. */ /* Skip the first compare if data in tmp1 is irrelevant. */ tbnz offset, 6, L(misaligned_mid_loop) L(loop_misaligned): /* STEP_A: Compare full 8 bytes when there is enough data from SRC2.*/ LS_FW data2, tmp1, offset LS_BK tmp1, tmp2, neg_offset subs limit, limit, #8 orr data2, data2, tmp1 /* 8 bytes from SRC2 combined from two regs.*/ sub has_nul, data1, zeroones eor diff, data1, data2 /* Non-zero if differences found. */ orr tmp3, data1, #REP8_7f csinv endloop, diff, xzr, hi /* If limit, set to all ones. */ bic has_nul, has_nul, tmp3 /* Non-zero if NUL byte found in SRC1. */ orr tmp3, endloop, has_nul cbnz tmp3, L(full_check) ldr data1, [src1], #8 L(misaligned_mid_loop): /* STEP_B: Compare first part of data1 to second part of tmp2. */ LS_FW data2, tmp2, offset #ifdef __AARCH64EB__ /* For big-endian we do a byte reverse to avoid carry-propagation problem described above. This way we can reuse the has_nul in the next step and also use syndrome value trick at the end. */ rev tmp3, data1 #define data1_fixed tmp3 #else #define data1_fixed data1 #endif sub has_nul, data1_fixed, zeroones orr tmp3, data1_fixed, #REP8_7f eor diff, data2, data1 /* Non-zero if differences found. */ bic has_nul, has_nul, tmp3 /* Non-zero if NUL terminator. */ #ifdef __AARCH64EB__ rev has_nul, has_nul #endif cmp limit, neg_offset, lsr #3 orr syndrome, diff, has_nul bic syndrome, syndrome, mask /* Ignore later bytes. */ csinv tmp3, syndrome, xzr, hi /* If limit, set to all ones. */ cbnz tmp3, L(syndrome_check) /* STEP_C: Compare second part of data1 to first part of tmp1. */ ldp tmp1, tmp2, [src2], #16 cmp limit, #8 LS_BK data2, tmp1, neg_offset eor diff, data2, data1 /* Non-zero if differences found. */ orr syndrome, diff, has_nul and syndrome, syndrome, mask /* Ignore earlier bytes. */ csinv tmp3, syndrome, xzr, hi /* If limit, set to all ones. */ cbnz tmp3, L(syndrome_check) ldr data1, [src1], #8 sub limit, limit, #8 b L(loop_misaligned) #ifdef __AARCH64EB__ L(syndrome_check): clz pos, syndrome cmp pos, limit, lsl #3 b.lo L(end_quick) #endif L(ret0): mov result, #0 ret END(strncmp) #endif picolibc-1.8.11/libc/machine/aarch64/strnlen-stub.c000066400000000000000000000034051513574234600217530ustar00rootroot00000000000000/* Copyright (c) 2013, Linaro Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) \ || !defined(__ARM_NEON) #include "../../string/strnlen.c" #else /* See strnlen.S */ #endif picolibc-1.8.11/libc/machine/aarch64/strnlen.S000066400000000000000000000071351513574234600207640ustar00rootroot00000000000000/* strnlen - calculate the length of a string with limit. Copyright (c) 2013, Linaro Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) || !defined(__ARM_NEON) /* See strnlen-stub.c */ #else /* Assumptions: * * ARMv8-a, AArch64, Advanced SIMD. * MTE compatible. */ #include "asmdefs.h" #define srcin x0 #define cntin x1 #define result x0 #define src x2 #define synd x3 #define shift x4 #define tmp x4 #define cntrem x5 #define qdata q0 #define vdata v0 #define vhas_chr v1 #define vend v2 #define dend d2 /* Core algorithm: Process the string in 16-byte aligned chunks. Compute a 64-bit mask with four bits per byte using the shrn instruction. A count trailing zeros then identifies the first zero byte. */ ENTRY (strnlen) PTR_ARG (0) SIZE_ARG (1) bic src, srcin, 15 cbz cntin, L(nomatch) ld1 {vdata.16b}, [src] cmeq vhas_chr.16b, vdata.16b, 0 lsl shift, srcin, 2 shrn vend.8b, vhas_chr.8h, 4 /* 128->64 */ fmov synd, dend lsr synd, synd, shift cbz synd, L(start_loop) L(finish): rbit synd, synd clz synd, synd lsr result, synd, 2 cmp cntin, result csel result, cntin, result, ls ret L(nomatch): mov result, cntin ret L(start_loop): sub tmp, src, srcin add tmp, tmp, 17 subs cntrem, cntin, tmp b.lo L(nomatch) /* Make sure that it won't overread by a 16-byte chunk */ tbz cntrem, 4, L(loop32_2) sub src, src, 16 .p2align 5 L(loop32): ldr qdata, [src, 32]! cmeq vhas_chr.16b, vdata.16b, 0 umaxp vend.16b, vhas_chr.16b, vhas_chr.16b /* 128->64 */ fmov synd, dend cbnz synd, L(end) L(loop32_2): ldr qdata, [src, 16] subs cntrem, cntrem, 32 cmeq vhas_chr.16b, vdata.16b, 0 b.lo L(end_2) umaxp vend.16b, vhas_chr.16b, vhas_chr.16b /* 128->64 */ fmov synd, dend cbz synd, L(loop32) L(end_2): add src, src, 16 L(end): shrn vend.8b, vhas_chr.8h, 4 /* 128->64 */ sub result, src, srcin fmov synd, dend #ifndef __AARCH64EB__ rbit synd, synd #endif clz synd, synd add result, result, synd, lsr 2 cmp cntin, result csel result, cntin, result, ls ret END (strnlen) #endif picolibc-1.8.11/libc/machine/aarch64/strrchr-stub.c000066400000000000000000000034041513574234600217540ustar00rootroot00000000000000/* Copyright (c) 2014, ARM Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the company nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) \ || !defined(__ARM_NEON) #include "../../string/strrchr.c" #else /* See strrchr.S */ #endif picolibc-1.8.11/libc/machine/aarch64/strrchr.S000066400000000000000000000143121513574234600207610ustar00rootroot00000000000000/* strrchr - find last instance of a character in a string Copyright (c) 2014, ARM Limited All rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the company nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if (defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED)) || !defined(__LP64__) || !defined(__ARM_NEON) /* See strrchr-stub.c */ #else /* Assumptions: * * ARMv8-a, AArch64 * Neon Available. */ #include "asmdefs.h" /* Arguments and results. */ #define srcin x0 #define chrin w1 #define result x0 #define src x2 #define tmp1 x3 #define wtmp2 w4 #define tmp3 x5 #define src_match x6 #define src_offset x7 #define const_m1 x8 #define tmp4 x9 #define nul_match x10 #define chr_match x11 #define vrepchr v0 #define vdata1 v1 #define vdata2 v2 #define vhas_nul1 v3 #define vhas_nul2 v4 #define vhas_chr1 v5 #define vhas_chr2 v6 #define vrepmask_0 v7 #define vrepmask_c v16 #define vend1 v17 #define vend2 v18 /* Core algorithm. For each 32-byte hunk we calculate a 64-bit syndrome value, with two bits per byte (LSB is always in bits 0 and 1, for both big and little-endian systems). For each tuple, bit 0 is set iff the relevant byte matched the requested character; bit 1 is set iff the relevant byte matched the NUL end of string (we trigger off bit0 for the special case of looking for NUL). Since the bits in the syndrome reflect exactly the order in which things occur in the original string a count_trailing_zeros() operation will identify exactly which byte is causing the termination, and why. */ ENTRY (strrchr) PTR_ARG (0) /* Magic constant 0x40100401 to allow us to identify which lane matches the requested byte. Magic constant 0x80200802 used similarly for NUL termination. */ mov wtmp2, #0x0401 movk wtmp2, #0x4010, lsl #16 dup vrepchr.16b, chrin bic src, srcin, #31 /* Work with aligned 32-byte hunks. */ dup vrepmask_c.4s, wtmp2 mov src_offset, #0 ands tmp1, srcin, #31 add vrepmask_0.4s, vrepmask_c.4s, vrepmask_c.4s /* equiv: lsl #1 */ b.eq L(aligned) /* Input string is not 32-byte aligned. Rather than forcing the padding bytes to a safe value, we calculate the syndrome for all the bytes, but then mask off those bits of the syndrome that are related to the padding. */ ld1 {vdata1.16b, vdata2.16b}, [src], #32 neg tmp1, tmp1 cmeq vhas_nul1.16b, vdata1.16b, #0 cmeq vhas_chr1.16b, vdata1.16b, vrepchr.16b cmeq vhas_nul2.16b, vdata2.16b, #0 cmeq vhas_chr2.16b, vdata2.16b, vrepchr.16b and vhas_nul1.16b, vhas_nul1.16b, vrepmask_0.16b and vhas_chr1.16b, vhas_chr1.16b, vrepmask_c.16b and vhas_nul2.16b, vhas_nul2.16b, vrepmask_0.16b and vhas_chr2.16b, vhas_chr2.16b, vrepmask_c.16b addp vhas_nul1.16b, vhas_nul1.16b, vhas_nul2.16b // 256->128 addp vhas_chr1.16b, vhas_chr1.16b, vhas_chr2.16b // 256->128 addp vend1.16b, vhas_nul1.16b, vhas_chr1.16b // 128->64 mov nul_match, vend1.d[0] lsl tmp1, tmp1, #1 mov const_m1, #~0 lsr tmp3, const_m1, tmp1 mov chr_match, vend1.d[1] bic nul_match, nul_match, tmp3 // Mask padding bits. bic chr_match, chr_match, tmp3 // Mask padding bits. cbnz nul_match, L(tail) .p2align 4 L(loop): cmp chr_match, #0 csel src_match, src, src_match, ne csel src_offset, chr_match, src_offset, ne L(aligned): ld1 {vdata1.16b, vdata2.16b}, [src], #32 cmeq vhas_chr1.16b, vdata1.16b, vrepchr.16b cmeq vhas_chr2.16b, vdata2.16b, vrepchr.16b uminp vend1.16b, vdata1.16b, vdata2.16b and vhas_chr1.16b, vhas_chr1.16b, vrepmask_c.16b and vhas_chr2.16b, vhas_chr2.16b, vrepmask_c.16b cmeq vend1.16b, vend1.16b, 0 addp vhas_chr1.16b, vhas_chr1.16b, vhas_chr2.16b // 256->128 addp vend1.16b, vend1.16b, vhas_chr1.16b // 128->64 mov nul_match, vend1.d[0] mov chr_match, vend1.d[1] cbz nul_match, L(loop) cmeq vhas_nul1.16b, vdata1.16b, #0 cmeq vhas_nul2.16b, vdata2.16b, #0 and vhas_nul1.16b, vhas_nul1.16b, vrepmask_0.16b and vhas_nul2.16b, vhas_nul2.16b, vrepmask_0.16b addp vhas_nul1.16b, vhas_nul1.16b, vhas_nul2.16b addp vhas_nul1.16b, vhas_nul1.16b, vhas_nul1.16b mov nul_match, vhas_nul1.d[0] L(tail): /* Work out exactly where the string ends. */ sub tmp4, nul_match, #1 eor tmp4, tmp4, nul_match ands chr_match, chr_match, tmp4 /* And pick the values corresponding to the last match. */ csel src_match, src, src_match, ne csel src_offset, chr_match, src_offset, ne /* Count down from the top of the syndrome to find the last match. */ clz tmp3, src_offset /* Src_match points beyond the word containing the match, so we can simply subtract half the bit-offset into the syndrome. Because we are counting down, we need to go back one more character. */ add tmp3, tmp3, #2 sub result, src_match, tmp3, lsr #1 /* But if the syndrome shows no match was found, then return NULL. */ cmp src_offset, #0 csel result, result, xzr, ne ret END (strrchr) #endif picolibc-1.8.11/libc/machine/aarch64/sys/000077500000000000000000000000001513574234600177635ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/aarch64/sys/fcntl.h000066400000000000000000000004531513574234600212440ustar00rootroot00000000000000#ifndef _SYS_FCNTL_H_ #define _SYS_FCNTL_H_ #include /* We want to support O_BINARY for the open syscall. For example, the Demon debug monitor has a separate flag value for "rb" vs "r". */ #define _FBINARY 0x10000 #define O_BINARY _FBINARY #endif /* _SYS_FCNTL_H_ */ picolibc-1.8.11/libc/machine/aarch64/sys/meson.build000066400000000000000000000033171513574234600221310ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_sys_headers_machine = [ 'fcntl.h', ] if really_install install_headers(inc_sys_headers_machine, install_dir: include_dir / 'sys') endif picolibc-1.8.11/libc/machine/aarch64/tls.c000066400000000000000000000044621513574234600201210ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #ifdef __THREAD_LOCAL_STORAGE_API /* This code is duplicated in picocrt/machine/aarch/crt0.c */ /* The size of the thread control block. * TLS relocations are generated relative to * a location this far *before* the first thread * variable (!) * NB: The actual size before tp also includes padding * to align up to the alignment of .tdata/.tbss. */ #if __SIZE_WIDTH__ == 32 extern char __arm32_tls_tcb_offset; #define TP_OFFSET ((size_t)&__arm32_tls_tcb_offset) #else extern char __arm64_tls_tcb_offset; #define TP_OFFSET ((size_t)&__arm64_tls_tcb_offset) #endif void _set_tls(void *tls) { __asm__ volatile("msr tpidr_el0, %0" : : "r"(tls - TP_OFFSET)); } #endif picolibc-1.8.11/libc/machine/amdgcn/000077500000000000000000000000001513574234600171465ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/amdgcn/abort.c000066400000000000000000000016121513574234600204210ustar00rootroot00000000000000/* * Support file for amdgcn in newlib. * Copyright (c) 2014-2017 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include #include #include "exit-value.h" void __noreturn abort(void) { write(2, "GCN Kernel Aborted\n", 19); exit_with_status_and_signal(0, SIGABRT); } picolibc-1.8.11/libc/machine/amdgcn/atexit.c000066400000000000000000000014771513574234600206210ustar00rootroot00000000000000/* * Support file for amdgcn in newlib. * Copyright (c) 2014-2017 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include int atexit(void (*function)(void)) { /* Fail here. */ abort(); return 1; } picolibc-1.8.11/libc/machine/amdgcn/exit-value.h000066400000000000000000000031651513574234600214070ustar00rootroot00000000000000/* * Support file for amdgcn in newlib. * Copyright (c) 2017 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #ifndef _AMDGCN_EXIT_VALUE_H_ #define _AMDGCN_EXIT_VALUE_H_ static inline void __noreturn exit_with_int(int val) { /* Write the exit value to the conventional place. */ int *return_value; #if defined(__has_builtin) && __has_builtin(__builtin_gcn_kernarg_ptr) __asm__("s_load_dwordx2 %0, %1, 16 glc\n\t" "s_waitcnt 0" : "=Sg"(return_value) : "r"(__builtin_gcn_kernarg_ptr())); #else __asm__("s_load_dwordx2 %0, s[8:9], 16 glc\n\t" "s_waitcnt 0" : "=Sg"(return_value)); #endif *return_value = val; /* Terminate the current kernel. */ __asm__("s_endpgm"); __builtin_unreachable(); } static inline void __noreturn exit_with_status_and_signal(int val, int signal) { if (signal == 0) val = val & 0xff; else { val = (128 + signal) & 0xff; signal = signal & 0xff; } exit_with_int((0xffff << 16) | (signal << 8) | val); } #endif picolibc-1.8.11/libc/machine/amdgcn/getreent.c000066400000000000000000000073241513574234600211350ustar00rootroot00000000000000/* Copyright (c) 2014-2017 Mentor Graphics. The authors hereby grant permission to use, copy, modify, distribute, and license this software and its documentation for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions. No written agreement, license, or royalty fee is required for any of the authorized uses. Modifications to this software may be copyrighted by their authors and need not follow the licensing terms described here, provided that the new terms are clearly indicated on the first page of each file where they apply. */ /* get thread-specific reentrant pointer */ #include #include #include #include #include /* Copied from the HSA documentation. */ typedef struct hsa_signal_s { uint64_t handle; } hsa_signal_t; typedef struct hsa_kernel_dispatch_packet_s { uint16_t header; uint16_t setup; uint16_t workgroup_size_x; uint16_t workgroup_size_y; uint16_t workgroup_size_z; uint16_t reserved0; uint32_t grid_size_x; uint32_t grid_size_y; uint32_t grid_size_z; uint32_t private_segment_size; uint32_t group_segment_size; uint64_t kernel_object; uint64_t reserved2; hsa_signal_t completion_signal; } hsa_kernel_dispatch_packet_t; struct _reent * __getreent(void) { /* Place the reent data at the top of the stack allocation. */ struct data { int marker; struct _reent reent; } *data; #if defined(__has_builtin) && __has_builtin(__builtin_gcn_get_stack_limit) \ && __has_builtin(__builtin_gcn_first_call_this_thread_p) unsigned long addr = (((unsigned long)__builtin_gcn_get_stack_limit() - sizeof(struct data)) & ~7); data = (struct data *)addr; register long sp asm("s16"); if (sp >= addr) goto stackoverflow; if (__builtin_gcn_first_call_this_thread_p()) { data->marker = 12345; __builtin_memset(&data->reent, 0, sizeof(struct _reent)); _REENT_INIT_PTR_ZEROED(&data->reent); } else if (data->marker != 12345) goto stackoverflow; #else /* s[0:1] contains a 48-bit private segment base address. s11 contains the offset to the base of the stack. s[4:5] contains the dispatch pointer. WARNING: this code will break if s[0:1] is ever used for anything! */ const register unsigned long buffer_descriptor __asm__("s0"); unsigned long private_segment = buffer_descriptor & 0x0000ffffffffffff; const register unsigned int stack_offset __asm__("s11"); const register hsa_kernel_dispatch_packet_t *dispatch_ptr __asm__("s4"); unsigned long stack_base = private_segment + stack_offset; unsigned long stack_end = stack_base + dispatch_ptr->private_segment_size * 64; unsigned long addr = (stack_end - sizeof(struct data)) & ~7; data = (struct data *)addr; register long sp __asm__("s16"); if (sp >= addr) goto stackoverflow; /* Stash a marker in the unused upper 16 bits of s[0:1] to indicate that the reent data is initialized. */ const register unsigned int s1 __asm__("s1"); unsigned int marker = s1 >> 16; if (marker != 12345) { __asm__("s_and_b32\ts1, s1, 0xffff"); __asm__("s_or_b32\ts1, s1, (12345 << 16)"); data->marker = 12345; __builtin_memset(&data->reent, 0, sizeof(struct _reent)); _REENT_INIT_PTR_ZEROED(&data->reent); } else if (data->marker != 12345) goto stackoverflow; #endif return &data->reent; stackoverflow: write(2, "GCN Stack Overflow!\n", 20); abort(); } picolibc-1.8.11/libc/machine/amdgcn/mlock.c000066400000000000000000000055471513574234600204320ustar00rootroot00000000000000/* * Support file for AMDGCN in newlib. * Copyright (c) 2017 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include #include #include /* _sbrk_r expects us to use the real errno, not the reentrant one. */ #include #undef errno extern int errno; /* The runtime passes in heap space like this. */ struct heap { int64_t size; char data[0]; }; static char *__heap_ptr = (char *)-1; static char *__heap_end = (char *)-1; static int __heap_lock = 0; static void *__heap_lock_id = NULL; static int __heap_lock_cnt = 0; void * sbrk(ptrdiff_t nbytes) { if (__heap_ptr == (char *)-1) { /* Find the heap from kernargs. */ char *kernargs; #if defined(__has_builtin) && __has_builtin(__builtin_gcn_kernarg_ptr) kernargs = __builtin_gcn_kernarg_ptr(); #else /* The kernargs pointer is in s[8:9]. This will break if the enable_sgpr_* flags are ever changed. */ __asm__("s_mov_b64 %0, s[8:9]" : "=Sg"(kernargs)); #endif /* The heap data is at kernargs[3]. */ struct heap *heap = *(struct heap **)(kernargs + 24); __heap_ptr = heap->data; __heap_end = __heap_ptr + heap->size; } if ((__heap_ptr + nbytes) >= __heap_end) { errno = ENOMEM; return (void *)-1; } char *base = __heap_ptr; __heap_ptr += nbytes; return base; } void __malloc_lock(struct _reent *reent) { void *id = reent; if (id == __heap_lock_id) { if (__heap_lock_cnt < 1) abort(); ++__heap_lock_cnt; return; } while (__sync_lock_test_and_set(&__heap_lock, 1)) /* A sleep seems like it should allow the wavefront to yeild (maybe?) Use the shortest possible sleep time of 1*64 cycles. */ __asm__ volatile("s_sleep\t1" ::: "memory"); if (__heap_lock_id != NULL) abort(); if (__heap_lock_cnt != 0) abort(); __heap_lock_cnt = 1; __heap_lock_id = id; } void __malloc_unlock(struct _reent *reent) { void *id = reent; if (id != __heap_lock_id) abort(); if (__heap_lock_cnt < 1) abort(); --__heap_lock_cnt; if (__heap_lock_cnt > 0) return; __heap_lock_id = NULL; __sync_lock_release(&__heap_lock); } picolibc-1.8.11/libc/machine/amdgcn/signal.c000066400000000000000000000014161513574234600205710ustar00rootroot00000000000000/* Copyright (c) 2014-2017 Mentor Graphics. The authors hereby grant permission to use, copy, modify, distribute, and license this software and its documentation for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions. No written agreement, license, or royalty fee is required for any of the authorized uses. Modifications to this software may be copyrighted by their authors and need not follow the licensing terms described here, provided that the new terms are clearly indicated on the first page of each file where they apply. */ #include #include #include _sig_func_ptr signal(int sig, _sig_func_ptr func) { errno = EINVAL; return NULL; } picolibc-1.8.11/libc/machine/arc/000077500000000000000000000000001513574234600164625ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/arc/CMakeLists.txt000066400000000000000000000041711513574234600212250ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources_flags("-fno-builtin" setjmp.S vector_table.c tls.c ) if(NOT DEFINED CONFIG_ISA_ARCV3) picolibc_sources_flags("-fno-builtin" memcmp-bs-norm.S memcmp.S memcmp-stub.c memcpy-archs.S memcpy-bs.S memcpy.S memcpy-stub.c memset-archs.S memset-bs.S memset.S memset-stub.c strchr-bs-norm.S strchr-bs.S strchr.S strchr-stub.c strcmp-archs.S strcmp.S strcmp-stub.c strcpy-bs-arc600.S strcpy-bs.S strcpy.S strcpy-stub.c strncpy-bs.S strncpy.S strncpy-stub.c ) endif() picolibc-1.8.11/libc/machine/arc/asm.h000066400000000000000000000052371513574234600174220ustar00rootroot00000000000000#ifndef ARC_NEWLIB_ASM_H #define ARC_NEWLIB_ASM_H /* Copyright (c) 2015, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _ENTRY(name) \ .text ` .balign 4 ` .globl name ` name: #define FUNC(name) .type name,@function #define ENDFUNC0(name) .Lfe_##name: .size name,.Lfe_##name-name #define ENDFUNC(name) ENDFUNC0 (name) #define ENTRY(name) _ENTRY (name) ` FUNC (name) #define add_l add #define bcc_l bcc #define bclr_l bclr #define beq_l beq #define bic_l bic #define b_l b #define bne_l bne #define breq_l breq #define brne_l brne #define j_l j #define ldb_l ldb #define ld_l ld #define mov_l mov #define or_l or #define st_l st #define stb_l stb #define sub_l sub #define tst_l tst #define extb_l extb #define bcc_s bhs_s /* Compatibility with older ARC GCC, that doesn't provide some of the preprocessor defines used by newlib for ARC. */ #if defined (__Xbarrel_shifter) && !defined (__ARC_BARREL_SHIFTER__) #define __ARC_BARREL_SHIFTER__ 1 #endif #if defined (__EM__) && !defined (__ARCEM__) #define __ARCEM__ 1 #endif #if defined (__HS__) && !defined (__ARCHS__) #define __ARCHS__ 1 #endif #if defined (__LL64__) && !defined (__ARC_LL64__) #define __ARC_LL64__ 1 #endif #endif /* ARC_NEWLIB_ASM_H */ picolibc-1.8.11/libc/machine/arc/memcmp-bs-norm.S000066400000000000000000000121141513574234600214360ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/memcmp.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) #include "asm.h" #if !defined (__ARC601__) && defined (__ARC_NORM__) \ && defined (__ARC_BARREL_SHIFTER__) #ifdef __LITTLE_ENDIAN__ #define WORD2 r2 #define SHIFT r3 #else /* BIG ENDIAN */ #define WORD2 r3 #define SHIFT r2 #endif ENTRY (memcmp) or r12,r0,r1 asl_s r12,r12,30 #if defined (__ARC700__) || defined (__ARCEM__) || defined (__ARCHS__) sub_l r3,r2,1 brls r2,r12,.Lbytewise #else brls.d r2,r12,.Lbytewise sub_s r3,r2,1 #endif ld r4,[r0,0] ld r5,[r1,0] lsr.f lp_count,r3,3 #ifdef __ARCEM__ /* A branch can't be the last instruction in a zero overhead loop. So we move the branch to the start of the loop, duplicate it after the end, and set up r12 so that the branch isn't taken initially. */ mov_s r12,WORD2 lpne .Loop_end brne WORD2,r12,.Lodd ld WORD2,[r0,4] #else lpne .Loop_end ld_s WORD2,[r0,4] #endif ld_s r12,[r1,4] brne r4,r5,.Leven ld.a r4,[r0,8] ld.a r5,[r1,8] #ifdef __ARCEM__ .Loop_end: brne WORD2,r12,.Lodd #else brne WORD2,r12,.Lodd #ifdef __ARCHS__ nop #endif .Loop_end: #endif asl_s SHIFT,SHIFT,3 bcc_s .Last_cmp brne r4,r5,.Leven ld r4,[r0,4] ld r5,[r1,4] #ifdef __LITTLE_ENDIAN__ #if defined (__ARC700__) || defined (__ARCEM__) || defined (__ARCHS__) nop_s ; one more load latency cycle .Last_cmp: xor r0,r4,r5 bset r0,r0,SHIFT sub_s r1,r0,1 bic_s r1,r1,r0 norm r1,r1 b.d .Leven_cmp and r1,r1,24 .Leven: xor r0,r4,r5 sub_s r1,r0,1 bic_s r1,r1,r0 norm r1,r1 ; slow track insn and r1,r1,24 .Leven_cmp: asl r2,r4,r1 asl r12,r5,r1 lsr_s r2,r2,1 lsr_s r12,r12,1 j_s.d [blink] sub r0,r2,r12 .balign 4 .Lodd: xor r0,WORD2,r12 sub_s r1,r0,1 bic_s r1,r1,r0 norm r1,r1 ; slow track insn and r1,r1,24 asl_s r2,r2,r1 asl_s r12,r12,r1 lsr_s r2,r2,1 lsr_s r12,r12,1 j_s.d [blink] sub r0,r2,r12 #else /* !__ARC700__ */ .balign 4 .Last_cmp: xor r0,r4,r5 b.d .Leven_cmp bset r0,r0,SHIFT .Lodd: mov_s r4,WORD2 mov_s r5,r12 .Leven: xor r0,r4,r5 .Leven_cmp: mov_s r1,0x80808080 ; uses long immediate sub_s r12,r0,1 bic_s r0,r0,r12 sub r0,r1,r0 xor_s r0,r0,r1 and r1,r5,r0 and r0,r4,r0 xor.f 0,r0,r1 sub_s r0,r0,r1 j_s.d [blink] mov.mi r0,r1 #endif /* !__ARC700__ */ #else /* BIG ENDIAN */ .Last_cmp: neg_s SHIFT,SHIFT lsr r4,r4,SHIFT lsr r5,r5,SHIFT ; slow track insn .Leven: sub.f r0,r4,r5 mov.ne r0,1 j_s.d [blink] bset.cs r0,r0,31 .Lodd: cmp_s WORD2,r12 #if defined (__ARC700__) || defined (__ARCEM__) || defined (__ARCHS__) mov_s r0,1 j_s.d [blink] bset.cs r0,r0,31 #else j_s.d [blink] rrc r0,2 #endif /* __ARC700__ || __ARCEM__ || __ARCHS__ */ #endif /* ENDIAN */ .balign 4 .Lbytewise: breq r2,0,.Lnil ldb r4,[r0,0] ldb r5,[r1,0] lsr.f lp_count,r3 #ifdef __ARCEM__ mov r12,r3 lpne .Lbyte_end brne r3,r12,.Lbyte_odd #else lpne .Lbyte_end #endif ldb_s r3,[r0,1] ldb_l r12,[r1,1] brne r4,r5,.Lbyte_even ldb.a r4,[r0,2] ldb.a r5,[r1,2] #ifdef __ARCEM__ .Lbyte_end: brne r3,r12,.Lbyte_odd #else brne r3,r12,.Lbyte_odd #ifdef __ARCHS__ nop #endif .Lbyte_end: #endif bcc_l .Lbyte_even brne r4,r5,.Lbyte_even ldb_s r3,[r0,1] ldb_s r12,[r1,1] .Lbyte_odd: j_s.d [blink] sub r0,r3,r12 .Lbyte_even: j_s.d [blink] sub r0,r4,r5 .Lnil: j_s.d [blink] mov_l r0,0 ENDFUNC (memcmp) #endif /* !__ARC601__ && __ARC_NORM__ && __ARC_BARREL_SHIFTER__ */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/memcmp-stub.c000066400000000000000000000033231513574234600210600ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED) || defined(__ARC_RF16__) #include "../../string/memcmp.c" #else /* See memcmp-*.S. */ #endif picolibc-1.8.11/libc/machine/arc/memcmp.S000066400000000000000000000076731513574234600201010ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/memcmp.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) #include "asm.h" #if defined (__ARC601__) || !defined (__ARC_NORM__) \ || !defined (__ARC_BARREL_SHIFTER__) /* Addresses are unsigned, and at 0 is the vector table, so it's OK to assume that we can subtract 8 from a source end address without underflow. */ ENTRY (memcmp) or r12,r0,r1 tst r12,3 breq r2,0,.Lnil add_s r3,r0,r2 /* This algorithm for big endian targets sometimes works incorrectly when sources are aligned. To be precise the last step is omitted. Just use a simple bytewise variant until the algorithm is reviewed and fixed. */ #ifdef __LITTLE_ENDIAN__ bne_s .Lbytewise #else /* BIG ENDIAN */ b_s .Lbytewise #endif /* ENDIAN */ sub r6,r3,8 ld r4,[r0,0] ld r5,[r1,0] 2: brhs r0,r6,.Loop_end ld_s r3,[r0,4] ld_s r12,[r1,4] brne r4,r5,.Leven ld.a r4,[r0,8] breq.d r3,r12,2b ld.a r5,[r1,8] #ifdef __LITTLE_ENDIAN__ mov_s r4,r3 b.d .Lodd mov_s r5,r12 #else /* BIG ENDIAN */ cmp_s r3,r12 j_s.d [blink] rrc r0,2 #endif /* ENDIAN */ .balign 4 .Loop_end: sub r3,r0,r6 brhs r3,4,.Last_cmp brne r4,r5,.Leven ld r4,[r0,4] ld r5,[r1,4] #ifdef __LITTLE_ENDIAN__ .balign 4 .Last_cmp: mov_l r0,24 add3 r2,r0,r2 xor r0,r4,r5 b.d .Leven_cmp bset r0,r0,r2 .Lodd: .Leven: xor r0,r4,r5 .Leven_cmp: mov_s r1,0x80808080 ; uses long immediate sub_s r12,r0,1 bic_s r0,r0,r12 sub r0,r1,r0 xor_s r0,r0,r1 and r1,r5,r0 and r0,r4,r0 #else /* BIG ENDIAN */ .Last_cmp: mov_s r3,0 sub3 r2,r3,r2 sub_s r3,r3,1 bclr r3,r3,r2 add_l r3,r3,1 and r0,r4,r3 and r1,r5,r3 .Leven: #endif /* ENDIAN */ xor.f 0,r0,r1 sub_s r0,r0,r1 j_s.d [blink] mov.mi r0,r1 .balign 4 .Lbytewise: ldb r4,[r0,0] ldb r5,[r1,0] sub r6,r3,2 3: brhs r0,r6,.Lbyte_end ldb_s r3,[r0,1] ldb_s r12,[r1,1] brne r4,r5,.Lbyte_even ldb.a r4,[r0,2] breq.d r3,r12,3b ldb.a r5,[r1,2] .Lbyte_odd: j_s.d [blink] sub r0,r3,r12 .balign 4 .Lbyte_end: bbit1 r2,0,.Lbyte_even brne r4,r5,.Lbyte_even ldb r4,[r0,1] ldb r5,[r1,1] .Lbyte_even: j_s.d [blink] sub r0,r4,r5 .Lnil: j_s.d [blink] mov_s r0,0 ENDFUNC (memcmp) #endif /* __ARC601__ || !__ARC_NORM__ || !__ARC_BARREL_SHIFTER__ */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/memcpy-archs.S000066400000000000000000000202201513574234600211720ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/memcpy.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) #include "asm.h" #if defined (__ARCHS__) #ifdef __LITTLE_ENDIAN__ # define SHIFT_1(RX,RY,IMM) asl RX, RY, IMM ; << # define SHIFT_2(RX,RY,IMM) lsr RX, RY, IMM ; >> # define MERGE_1(RX,RY,IMM) asl RX, RY, IMM # define MERGE_2(RX,RY,IMM) # define EXTRACT_1(RX,RY,IMM) and RX, RY, 0xFFFF # define EXTRACT_2(RX,RY,IMM) lsr RX, RY, IMM #else # define SHIFT_1(RX,RY,IMM) lsr RX, RY, IMM ; >> # define SHIFT_2(RX,RY,IMM) asl RX, RY, IMM ; << # define MERGE_1(RX,RY,IMM) asl RX, RY, IMM ; << # define MERGE_2(RX,RY,IMM) asl RX, RY, IMM ; << # define EXTRACT_1(RX,RY,IMM) lsr RX, RY, IMM # define EXTRACT_2(RX,RY,IMM) lsr RX, RY, 0x08 #endif #ifdef __ARC_LL64__ # define PREFETCH_READ(RX) prefetch [RX, 56] # define PREFETCH_WRITE(RX) prefetchw [RX, 64] # define LOADX(DST,RX) ldd.ab DST, [RX, 8] # define STOREX(SRC,RX) std.ab SRC, [RX, 8] # define ZOLSHFT 5 # define ZOLAND 0x1F #else # define PREFETCH_READ(RX) prefetch [RX, 28] # define PREFETCH_WRITE(RX) prefetchw [RX, 32] # define LOADX(DST,RX) ld.ab DST, [RX, 4] # define STOREX(SRC,RX) st.ab SRC, [RX, 4] # define ZOLSHFT 4 # define ZOLAND 0xF #endif ;;; MEMCPY copy memory regions ;;; Input arguments: ;;; r0 - output memory region ;;; r1 - input memory region ;;; r2 - size in bytes ;;; Returns: ;;; r0 - pointer to the first byte of the output region ;;; Clobber: ;;; r1, r2, r3, r4, r5, r6, r8r9, r10r11, lp_count #if !defined (__ARC_UNALIGNED__) ;;; MEMCPY routine for the case when the CPU only accepts ALIGNED ;;; accesses to memory. ENTRY (memcpy) prefetch [r1] ; Prefetch the read location prefetchw [r0] ; Prefetch the write location mov.f 0, r2 ; if size is zero jz.d [blink] mov r3, r0 ; don't clobber ret val ; if size <= 8 cmp r2, 8 bls.d .Lsmallchunk mov.f lp_count, r2 and.f r4, r0, 0x03 rsub lp_count, r4, 4 lpnz .Laligndestination ; LOOP BEGIN ldb.ab r5, [r1,1] sub r2, r2, 1 stb.ab r5, [r3,1] .Laligndestination: ; Check the alignment of the source and.f r4, r1, 0x03 bnz.d .Lsourceunaligned ; CASE 0: Both source and destination are 32bit aligned ; Convert len to Dwords, unfold x4 lsr.f lp_count, r2, ZOLSHFT lpnz .Lcopy32_64bytes ; LOOP START LOADX (r6, r1) PREFETCH_READ (r1) PREFETCH_WRITE (r3) LOADX (r8, r1) LOADX (r10, r1) LOADX (r4, r1) STOREX (r6, r3) STOREX (r8, r3) STOREX (r10, r3) STOREX (r4, r3) .Lcopy32_64bytes: and.f lp_count, r2, ZOLAND ;Last remaining 31 bytes .Lsmallchunk: lpnz .Lcopyremainingbytes ; LOOP START ldb.ab r5, [r1,1] stb.ab r5, [r3,1] .Lcopyremainingbytes: j [blink] ; END CASE 0 .Lsourceunaligned: cmp r4, 2 beq.d .LunalignedOffby2 sub r2, r2, 1 bhi.d .LunalignedOffby3 ldb.ab r5, [r1, 1] ; CASE 1: The source is unaligned, off by 1 ; Hence I need to read 1 byte for a 16bit alignment ; and 2bytes to reach 32bit alignment ldh.ab r6, [r1, 2] sub r2, r2, 2 ; Convert to words, unfold x2 lsr.f lp_count, r2, 3 MERGE_1 (r6, r6, 8) MERGE_2 (r5, r5, 24) or r5, r5, r6 ; Both src and dst are aligned lpnz .Lcopy8bytes_1 ; LOOP START ld.ab r6, [r1, 4] prefetch [r1, 28] ;Prefetch the next read location ld.ab r8, [r1,4] prefetchw [r3, 32] ;Prefetch the next write location SHIFT_1 (r7, r6, 24) or r7, r7, r5 SHIFT_2 (r5, r6, 8) SHIFT_1 (r9, r8, 24) or r9, r9, r5 SHIFT_2 (r5, r8, 8) st.ab r7, [r3, 4] st.ab r9, [r3, 4] .Lcopy8bytes_1: ; Write back the remaining 16bits EXTRACT_1 (r6, r5, 16) sth.ab r6, [r3, 2] ; Write back the remaining 8bits EXTRACT_2 (r5, r5, 16) stb.ab r5, [r3, 1] and.f lp_count, r2, 0x07 ;Last 8bytes lpnz .Lcopybytewise_1 ; LOOP START ldb.ab r6, [r1,1] stb.ab r6, [r3,1] .Lcopybytewise_1: j [blink] .LunalignedOffby2: ; CASE 2: The source is unaligned, off by 2 ldh.ab r5, [r1, 2] sub r2, r2, 1 ; Both src and dst are aligned ; Convert to words, unfold x2 lsr.f lp_count, r2, 3 #ifdef __BIG_ENDIAN__ asl.nz r5, r5, 16 #endif lpnz .Lcopy8bytes_2 ; LOOP START ld.ab r6, [r1, 4] prefetch [r1, 28] ;Prefetch the next read location ld.ab r8, [r1,4] prefetchw [r3, 32] ;Prefetch the next write location SHIFT_1 (r7, r6, 16) or r7, r7, r5 SHIFT_2 (r5, r6, 16) SHIFT_1 (r9, r8, 16) or r9, r9, r5 SHIFT_2 (r5, r8, 16) st.ab r7, [r3, 4] st.ab r9, [r3, 4] .Lcopy8bytes_2: #ifdef __BIG_ENDIAN__ lsr.nz r5, r5, 16 #endif sth.ab r5, [r3, 2] and.f lp_count, r2, 0x07 ;Last 8bytes lpnz .Lcopybytewise_2 ; LOOP START ldb.ab r6, [r1,1] stb.ab r6, [r3,1] .Lcopybytewise_2: j [blink] .LunalignedOffby3: ; CASE 3: The source is unaligned, off by 3 ; Hence, I need to read 1byte for achieve the 32bit alignment ; Both src and dst are aligned ; Convert to words, unfold x2 lsr.f lp_count, r2, 3 #ifdef __BIG_ENDIAN__ asl.ne r5, r5, 24 #endif lpnz .Lcopy8bytes_3 ; LOOP START ld.ab r6, [r1, 4] prefetch [r1, 28] ;Prefetch the next read location ld.ab r8, [r1,4] prefetchw [r3, 32] ;Prefetch the next write location SHIFT_1 (r7, r6, 8) or r7, r7, r5 SHIFT_2 (r5, r6, 24) SHIFT_1 (r9, r8, 8) or r9, r9, r5 SHIFT_2 (r5, r8, 24) st.ab r7, [r3, 4] st.ab r9, [r3, 4] .Lcopy8bytes_3: #ifdef __BIG_ENDIAN__ lsr.nz r5, r5, 24 #endif stb.ab r5, [r3, 1] and.f lp_count, r2, 0x07 ;Last 8bytes lpnz .Lcopybytewise_3 ; LOOP START ldb.ab r6, [r1,1] stb.ab r6, [r3,1] .Lcopybytewise_3: j [blink] ENDFUNC (memcpy) #else ;;; MEMCPY routine which is used by systems with unaligned memory ;;; accesses. This is the case for most of ARCHS CPU family. ENTRY(memcpy) prefetch [r1] ; Prefetch the read location prefetchw [r0] ; Prefetch the write location mov.f 0, r2 ;;; if size is zero jz.d [blink] mov r3, r0 ; don't clobber ret val ;;; if size <= 8 cmp r2, 8 bls.d .Lsmallchunk mov.f lp_count, r2 ;;; Convert len to Dwords, unfold x4 lsr.f lp_count, r2, ZOLSHFT lpnz .Lcopyfast ;; LOOP START LOADX (r6, r1) PREFETCH_READ (r1) PREFETCH_WRITE (r3) LOADX (r8, r1) LOADX (r10, r1) LOADX (r4, r1) STOREX (r6, r3) STOREX (r8, r3) STOREX (r10, r3) STOREX (r4, r3) .Lcopyfast: #ifdef __ARC_LL64__ and r2, r2, ZOLAND ;Remaining 31 bytes lsr.f lp_count, r2, 3 ;Convert to 64-bit words. lpnz .Lcopy64b ;; LOOP START ldd.ab r6,[r1,8] std.ab r6,[r3,8] .Lcopy64b: and.f lp_count, r2, 0x07 ; Last 7 bytes #else and.f lp_count, r2, ZOLAND #endif .Lsmallchunk: lpnz .Lcopyremainingbytes ;; LOOP START ldb.ab r5, [r1,1] stb.ab r5, [r3,1] .Lcopyremainingbytes: j [blink] ENDFUNC(memcpy) #endif #endif /* __ARCHS__ */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/memcpy-bs.S000066400000000000000000000065031513574234600205060ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/memcpy.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) #include "asm.h" #if !defined (__ARC601__) && !defined (__ARCHS__) \ && defined (__ARC_BARREL_SHIFTER__) /* Mostly optimized for ARC700, but not bad for ARC600 either. */ /* This memcpy implementation does not support objects of 1GB or larger - the check for alignment does not work then. */ /* We assume that most sources and destinations are aligned, and that also lengths are mostly a multiple of four, although to a lesser extent. */ ENTRY (memcpy) or r3,r0,r1 asl_s r3,r3,30 mov_s r5,r0 brls.d r2,r3,.Lcopy_bytewise sub.f r3,r2,1 ld_s r12,[r1,0] asr.f lp_count,r3,3 bbit0.d r3,2,.Lnox4 bmsk_s r2,r2,1 st.ab r12,[r5,4] ld.a r12,[r1,4] .Lnox4: lppnz .Lendloop ld_s r3,[r1,4] st.ab r12,[r5,4] ld.a r12,[r1,8] st.ab r3,[r5,4] .Lendloop: breq_l r2,0,.Last_store ld r3,[r5,0] #ifdef __LITTLE_ENDIAN__ add3 r2,-1,r2 ; uses long immediate xor_s r12,r12,r3 bmsk r12,r12,r2 xor_s r12,r12,r3 #else /* BIG ENDIAN */ sub3 r2,31,r2 ; uses long immediate xor_s r3,r3,r12 bmsk r3,r3,r2 xor_s r12,r12,r3 #endif /* ENDIAN */ .Last_store: j_s.d [blink] st r12,[r5,0] .balign 4 .Lcopy_bytewise: jcs [blink] ldb_s r12,[r1,0] lsr.f lp_count,r3 bcc_s .Lnox1 stb.ab r12,[r5,1] ldb.a r12,[r1,1] .Lnox1: lppnz .Lendbloop ldb_s r3,[r1,1] stb.ab r12,[r5,1] ldb.a r12,[r1,2] stb.ab r3,[r5,1] .Lendbloop: j_s.d [blink] stb r12,[r5,0] ENDFUNC (memcpy) #endif /* !__ARC601__ && !__ARCHS__ && __ARC_BARREL_SHIFTER__ */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/memcpy-stub.c000066400000000000000000000033231513574234600210740ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED) || defined(__ARC_RF16__) #include "../../string/memcpy.c" #else /* See memcpy-*.S. */ #endif picolibc-1.8.11/libc/machine/arc/memcpy.S000066400000000000000000000063671513574234600201140ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/memcpy.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) #include "asm.h" #if defined (__ARC601__) || \ (!defined (__ARC_BARREL_SHIFTER__) && !defined (__ARCHS__)) /* Adapted from memcpy-bs.S. */ /* We assume that most sources and destinations are aligned, and that also lengths are mostly a multiple of four, although to a lesser extent. */ ENTRY (memcpy) or r3,r0,r1 bmsk.f 0,r3,1 breq_s r2,0,.Lnil mov_s r5,r0 bne.d .Lcopy_bytewise add r6,r0,r2 sub_s r3,r2,1 ld_s r12,[r1,0] bbit0.d r3,2,.Lnox4 sub r6,r6,8 st.ab r12,[r5,4] ld.a r12,[r1,4] .Lnox4: brlo r2,9,.Lendloop .Lnox4a: ld_s r3,[r1,4] st.ab r12,[r5,8] ld.a r12,[r1,8] brlo.d r5,r6,.Lnox4a st r3,[r5,-4] .Lendloop: #ifdef __LITTLE_ENDIAN__ ld r3,[r5,0] add3 r2,-1,r2 ; uses long immediate xor_s r12,r12,r3 bmsk r12,r12,r2 xor_s r12,r12,r3 #else /* BIG ENDIAN */ bmsk_s r2,r2,1 breq_s r2,0,.Last_store ld r3,[r5,0] sub3 r2,31,r2 ; uses long immediate xor_s r3,r3,r12 bmsk r3,r3,r2 xor_s r12,r12,r3 #endif /* ENDIAN */ .Last_store: j_s.d [blink] st r12,[r5,0] .Lnil: j_s [blink] .balign 4 .Lcopy_bytewise: ldb_s r12,[r1,0] bbit1.d r2,0,.Lnox1 sub r6,r6,2 stb.ab r12,[r5,1] ldb.a r12,[r1,1] .Lnox1: brlo r2,3,.Lendbloop .Lnox1a: ldb_s r3,[r1,1] stb.ab r12,[r5,2] ldb.a r12,[r1,2] brlo.d r5,r6,.Lnox1a stb r3,[r5,-1] .Lendbloop: j_s.d [blink] stb r12,[r5,0] ENDFUNC (memcpy) #endif /* __ARC601__ || (!__ARC_BARREL_SHIFTER__ && !__ARCHS__) */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/memset-archs.S000066400000000000000000000075201513574234600212020ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/memset.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) #include "asm.h" #ifdef __ARCHS__ #define USE_PREFETCH #ifdef USE_PREFETCH #define PREWRITE(A,B) prefetchw [(A),(B)] #else #define PREWRITE(A,B) prealloc [(A),(B)] #endif ENTRY (memset) prefetchw [r0] ; Prefetch the write location mov.f 0, r2 ; if size is zero jz.d [blink] mov r3, r0 ; don't clobber ret val ; if length < 8 brls.d.nt r2, 8, .Lsmallchunk mov.f lp_count,r2 and.f r4, r0, 0x03 rsub lp_count, r4, 4 lpnz @.Laligndestination ; LOOP BEGIN stb.ab r1, [r3,1] sub r2, r2, 1 .Laligndestination: ; Destination is aligned and r1, r1, 0xFF asl r4, r1, 8 or r4, r4, r1 asl r5, r4, 16 or r5, r5, r4 mov r4, r5 sub3 lp_count, r2, 8 cmp r2, 64 bmsk.hi r2, r2, 5 mov.ls lp_count, 0 add3.hi r2, r2, 8 ; Convert len to Dwords, unfold x8 lsr.f lp_count, lp_count, 6 lpnz @.Lset64bytes ; LOOP START PREWRITE (r3, 64) ;Prefetch the next write location #ifdef __ARC_LL64__ std.ab r4, [r3, 8] std.ab r4, [r3, 8] std.ab r4, [r3, 8] std.ab r4, [r3, 8] std.ab r4, [r3, 8] std.ab r4, [r3, 8] std.ab r4, [r3, 8] std.ab r4, [r3, 8] #else st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] #endif .Lset64bytes: lsr.f lp_count, r2, 5 ;Last remaining max 124 bytes lpnz .Lset32bytes ; LOOP START prefetchw [r3, 32] ;Prefetch the next write location #ifdef __ARC_LL64__ std.ab r4, [r3, 8] std.ab r4, [r3, 8] std.ab r4, [r3, 8] std.ab r4, [r3, 8] #else st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] st.ab r4, [r3, 4] #endif .Lset32bytes: and.f lp_count, r2, 0x1F ;Last remaining 31 bytes .Lsmallchunk: lpnz .Lcopy3bytes ; LOOP START stb.ab r1, [r3, 1] .Lcopy3bytes: j [blink] ENDFUNC (memset) #endif /* __ARCHS__ */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/memset-bs.S000066400000000000000000000110121513574234600204750ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/memset.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) #include "asm.h" /* ARC HS has it's own implementation of memset, yet we want this function still to be compiled under "__dummy_memset" disguise, because strncpy function uses __strncpy_bzero as a second entry point into memset. Would be better to add __strncpy_bzero label to memset for ARC HS though, and even better would be to avoid a second entry point into function. ARC HS always has barrel-shifter, so this implementation will be always used for this purpose. */ #if !defined (__ARC601__) && defined (__ARC_BARREL_SHIFTER__) /* To deal with alignment/loop issues, SMALL must be at least 2. */ #define SMALL 7 .global __strncpy_bzero .hidden __strncpy_bzero /* __strncpy_bzero provides the following interface to strncpy: r0: return value r2: zeroing length r3: zeroing start address No attempt is made here for __strncpy_memset to speed up aligned cases, because the copying of a string presumably leaves start address and length alignment for the zeroing randomly distributed. */ #ifdef __ARCHS__ ENTRY (__dummy_memset) #else ENTRY (memset) #endif #if !defined (__ARC700__) && !defined (__ARCEM__) #undef SMALL #define SMALL 8 /* Even faster if aligned. */ brls.d r2,SMALL,.Ltiny #endif mov_s r3,r0 or r12,r0,r2 bmsk.f r12,r12,1 extb_s r1,r1 asl r12,r1,8 beq.d .Laligned or_s r1,r1,r12 #if defined (__ARC700__) || defined (__ARCEM__) brls r2,SMALL,.Ltiny #endif .Lnot_tiny: add_s r12,r2,r3 stb r1,[r12,-1] bclr_l r12,r12,0 stw r1,[r12,-2] bmsk.f r12,r3,1 add_s r2,r2,r12 sub.ne r2,r2,4 stb.ab r1,[r3,1] bclr_s r3,r3,0 stw.ab r1,[r3,2] bclr_s r3,r3,1 .Laligned: ; This code address should be aligned for speed. #if defined (__ARC700__) || defined (__ARCEM__) asl r12,r1,16 lsr.f lp_count,r2,2 or_s r1,r1,r12 lpne .Loop_end st.ab r1,[r3,4] .Loop_end: j_s [blink] #else /* !__ARC700 */ lsr.f lp_count,r2,3 asl r12,r1,16 or_s r1,r1,r12 lpne .Loop_end st.ab r1,[r3,4] st.ab r1,[r3,4] .Loop_end: jcc [blink] j_s.d [blink] st_s r1,[r3] #endif /* !__ARC700 */ #if defined (__ARC700__) || defined (__ARCEM__) .balign 4 __strncpy_bzero: brhi.d r2,17,.Lnot_tiny mov_l r1,0 .Ltiny: mov.f lp_count,r2 lpne .Ltiny_end stb.ab r1,[r3,1] .Ltiny_end: j_s [blink] #else /* !__ARC700__ */ #if SMALL > 8 FIXME #endif .balign 4 __strncpy_bzero: brhi.d r2,8,.Lnot_tiny mov_s r1,0 .Ltiny: sub_s r2,r2,11 sub1 r12,pcl,r2 j_s [r12] stb_s r1,[r3,7] stb_s r1,[r3,6] stb_s r1,[r3,5] stb_s r1,[r3,4] stb_s r1,[r3,3] stb_s r1,[r3,2] stb_s r1,[r3,1] stb_s r1,[r3] j_s [blink] #endif /* !__ARC700 */ #ifdef __ARCHS__ ENDFUNC (__dummy_memset) #else ENDFUNC (memset) #endif #endif /* !__ARC601__ && __ARC_BARREL_SHIFTER__ */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/memset-stub.c000066400000000000000000000033231513574234600210740ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED) || defined(__ARC_RF16__) #include "../../string/memset.c" #else /* See memset-*.S. */ #endif picolibc-1.8.11/libc/machine/arc/memset.S000066400000000000000000000066251513574234600201110ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/memset.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) #include "asm.h" #if defined (__ARC601__) \ || (!defined (__ARC_BARREL_SHIFTER__) && !defined (__ARCHS__)) /* To deal with alignment/loop issues, SMALL must be at least 2. */ #define SMALL 8 /* Even faster if aligned. */ .global __strncpy_bzero .hidden __strncpy_bzero /* __strncpy_bzero provides the following interface to strncpy: r0: return value r2: zeroing length r3: zeroing start address No attempt is made here for __strncpy_memset to speed up aligned cases, because the copying of a string presumably leaves start address and length alignment for the zeroing randomly distributed. */ ENTRY (memset) brls.d r2,SMALL,.Ltiny mov_s r3,r0 or r12,r0,r2 bmsk.f r12,r12,1 breq_s r1,0,.Lbzero mov r4,0 stb.a r1,[sp,-4] stb r1,[sp,1] stb r1,[sp,2] stb r1,[sp,3] ld.ab r1,[sp,4] .Lbzero: beq.d .Laligned .Lbzero2: add r6,r2,r3 .Lnot_tiny: stb r1,[r6,-1] bclr r12,r6,0 stw r1,[r12,-2] stb.ab r1,[r3,1] bclr_s r3,r3,0 stw.ab r1,[r3,2] bclr_s r3,r3,1 .Laligned: ; This code address should be aligned for speed. sub r6,r6,8 brlo.d r6,r3,.Loop_end sub r6,r6,8 3: st_l r1,[r3,4] brhs.d r6,r3,3b st.ab r1,[r3,8] .Loop_end: bic r12,r6,3 j_s.d [blink] st_s r1,[r12,12] .balign 4 __strncpy_bzero: brhi.d r2,8,.Lbzero2 mov_s r1,0 .Ltiny: sub_s r2,r2,11 sub1 r12,pcl,r2 j_s [r12] stb_s r1,[r3,7] stb_s r1,[r3,6] stb_s r1,[r3,5] stb_s r1,[r3,4] stb_s r1,[r3,3] stb_s r1,[r3,2] stb_s r1,[r3,1] stb_s r1,[r3] j_s [blink] ENDFUNC (memset) #endif /* __ARC601__ || (!__ARC_BARREL_SHIFTER__ && !__ARCHS__) */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/meson.build000066400000000000000000000046241513574234600206320ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'memcmp-bs-norm.S', 'memcmp.S', 'memcmp-stub.c', 'memcpy-archs.S', 'memcpy-bs.S', 'memcpy.S', 'memcpy-stub.c', 'memset-archs.S', 'memset-bs.S', 'memset.S', 'memset-stub.c', 'setjmp.S', 'strchr-bs-norm.S', 'strchr-bs.S', 'strchr.S', 'strchr-stub.c', 'strcmp-archs.S', 'strcmp.S', 'strcmp-stub.c', 'strcpy-bs-arc600.S', 'strcpy-bs.S', 'strcpy.S', 'strcpy-stub.c', 'strncpy-bs.S', 'strncpy.S', 'strncpy-stub.c', 'tls.c', 'vector_table.c', ] foreach params : targets target = params['name'] target_dir = params['dir'] target_c_args = params['c_args'] set_variable('lib_machine' + target, static_library('machine' + target, srcs_machine, pic: false, include_directories: inc, c_args: target_c_args + c_args + arg_fnobuiltin + arg_fnolto)) endforeach picolibc-1.8.11/libc/machine/arc/setjmp.S000066400000000000000000000117711513574234600201170ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* ABI interface file these are the stack mappings for the registers as stored in the ABI for ARC */ #include #define ARC_REGSIZE __SIZEOF_LONG__ .file "setjmp.S" ABIr13 = 0 ABIr14 = ABIr13 + ARC_REGSIZE ABIr15 = ABIr14 + ARC_REGSIZE ABIr16 = ABIr15 + ARC_REGSIZE ABIr17 = ABIr16 + ARC_REGSIZE ABIr18 = ABIr17 + ARC_REGSIZE ABIr19 = ABIr18 + ARC_REGSIZE ABIr20 = ABIr19 + ARC_REGSIZE ABIr21 = ABIr20 + ARC_REGSIZE ABIr22 = ABIr21 + ARC_REGSIZE ABIr23 = ABIr22 + ARC_REGSIZE ABIr24 = ABIr23 + ARC_REGSIZE ABIr25 = ABIr24 + ARC_REGSIZE ABIr26 = ABIr25 + ARC_REGSIZE ABIr27 = ABIr26 + ARC_REGSIZE ABIr28 = ABIr27 + ARC_REGSIZE ABIr29 = ABIr28 + ARC_REGSIZE ABIr30 = ABIr29 + ARC_REGSIZE ABIr31 = ABIr30 + ARC_REGSIZE ABIlpc = ABIr31 + ARC_REGSIZE ABIlps = ABIlpc + ARC_REGSIZE ABIlpe = ABIlps + ARC_REGSIZE ABIflg = ABIlpe + ARC_REGSIZE ABIr58 = ABIflg + ARC_REGSIZE ABIr59 = ABIr58 + ARC_REGSIZE .text .align 4 .global setjmp .type setjmp,@function setjmp: st r13, [r0, ABIr13] st r14, [r0, ABIr14] st r15, [r0, ABIr15] st r16, [r0, ABIr16] st r17, [r0, ABIr17] st r18, [r0, ABIr18] st r19, [r0, ABIr19] st r20, [r0, ABIr20] st r21, [r0, ABIr21] st r22, [r0, ABIr22] st r23, [r0, ABIr23] st r24, [r0, ABIr24] st r25, [r0, ABIr25] st r26, [r0, ABIr26] st r27, [r0, ABIr27] st r28, [r0, ABIr28] st r29, [r0, ABIr29] st r30, [r0, ABIr30] st blink, [r0, ABIr31] #ifndef __ARCV3__ st lp_count, [r0, ABIlpc] #endif lr r2, [lp_start] lr r3, [lp_end] st r2, [r0, ABIlps] st r3, [r0, ABIlpe] #if (!defined (__ARC700__) && !defined (__ARCEM__) && !defined (__ARCHS__)) ; Till the configure changes are decided, and implemented, the code working on ; mlo/mhi and using mul64 should be disabled. ; st mlo, [r0, ABIr58] ; st mhi, [r0, ABIr59] lr r2, [status32] st r2, [r0, ABIflg] #endif ; If "MPY_OPTION > 6 or FPU_FMA_OPTION" in an ARCHS target, then there ; is accumulator support in the processor. #if (defined (__ARCHS__) && (defined (__ARC_FPU_DP_FMA__) || defined (__ARC_FPU_SP_FMA__) || defined (__ARC_MPY_DMPY__) || defined (__ARC_DSP__))) st r58, [r0, ABIr58] st r59, [r0, ABIr59] #endif j.d [blink] mov r0,0 .Lfe1: .size setjmp,.Lfe1-setjmp .align 4 .global longjmp .type longjmp,@function longjmp: ; load registers ld r13, [r0, ABIr13] ld r14, [r0, ABIr14] ld r15, [r0, ABIr15] ld r16, [r0, ABIr16] ld r17, [r0, ABIr17] ld r18, [r0, ABIr18] ld r19, [r0, ABIr19] ld r20, [r0, ABIr20] ld r21, [r0, ABIr21] ld r22, [r0, ABIr22] ld r23, [r0, ABIr23] ld r24, [r0, ABIr24] ld r25, [r0, ABIr25] ld r26, [r0, ABIr26] ld r27, [r0, ABIr27] ld r28, [r0, ABIr28] ld r3, [r0, ABIr29] mov r29, r3 ld r3, [r0, ABIr30] mov r30, r3 ld blink, [r0, ABIr31] #ifndef __ARCV3__ ld r3, [r0, ABIlpc] mov lp_count, r3 #endif ld r2, [r0, ABIlps] ld r3, [r0, ABIlpe] sr r2, [lp_start] sr r3, [lp_end] #if (!defined (__ARC700__) && !defined (__ARCEM__) && !defined (__ARCHS__)) ld r2, [r0, ABIr58] ld r3, [r0, ABIr59] ; We do not support restoring of mulhi and mlo registers, yet. ; mulu64 0,r2,1 ; restores mlo ; mov 0,mlo ; force multiply to finish ; sr r3, [mulhi] ld r2, [r0, ABIflg] flag r2 ; restore "status32" register #endif #if (defined (__ARCHS__) && (defined (__ARC_FPU_DP_FMA__) || defined (__ARC_FPU_SP_FMA__) || defined (__ARC_MPY_DMPY__) || defined (__ARC_DSP__))) ld r58, [r0, ABIr58] ld r59, [r0, ABIr59] #endif mov.f r1, r1 ; to avoid return 0 from longjmp mov.eq r1, 1 j.d [blink] mov r0,r1 .Lfe2: .size longjmp,.Lfe2-longjmp picolibc-1.8.11/libc/machine/arc/strchr-bs-norm.S000066400000000000000000000107631513574234600214750ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/strchr.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) /* ARC700 has a relatively long pipeline and branch prediction, so we want to avoid branches that are hard to predict. On the other hand, the presence of the norm instruction makes it easier to operate on whole words branch-free. */ #include "asm.h" #if (defined (__ARC700__) || defined (__ARCEM__) || defined (__ARCHS__)) \ && defined (__ARC_NORM__) && defined (__ARC_BARREL_SHIFTER__) ENTRY (strchr) extb_s r1,r1 asl r5,r1,8 bmsk r2,r0,1 or r5,r5,r1 mov_s r3,0x01010101 breq.d r2,r0,.Laligned asl r4,r5,16 sub_s r0,r0,r2 asl r7,r2,3 ld_s r2,[r0] #ifdef __LITTLE_ENDIAN__ asl r7,r3,r7 #else lsr r7,r3,r7 #endif or r5,r5,r4 ror r4,r3 sub r12,r2,r7 bic_s r12,r12,r2 and r12,r12,r4 brne.d r12,0,.Lfound0_ua xor r6,r2,r5 ld.a r2,[r0,4] sub r12,r6,r7 bic r12,r12,r6 #ifdef __LITTLE_ENDIAN__ and r7,r12,r4 breq r7,0,.Loop ; For speed, we want this branch to be unaligned. b_l .Lfound_char ; Likewise this one. #else and r12,r12,r4 breq_l r12,0,.Loop ; For speed, we want this branch to be unaligned. lsr_s r12,r12,7 bic r2,r7,r6 b.d .Lfound_char_b and_s r2,r2,r12 #endif ; /* We require this code address to be unaligned for speed... */ .Laligned: ld_s r2,[r0] or r5,r5,r4 ror r4,r3 ; /* ... so that this code address is aligned, for itself and ... */ .Loop: sub r12,r2,r3 bic_s r12,r12,r2 and r12,r12,r4 brne.d r12,0,.Lfound0 xor r6,r2,r5 ld.a r2,[r0,4] sub r12,r6,r3 bic r12,r12,r6 and r7,r12,r4 breq r7,0,.Loop /* ... so that this branch is unaligned. */ ; Found searched-for character. r0 has already advanced to next word. #ifdef __LITTLE_ENDIAN__ /* We only need the information about the first matching byte (i.e. the least significant matching byte) to be exact, hence there is no problem with carry effects. */ .Lfound_char: sub r3,r7,1 bic r3,r3,r7 norm r2,r3 sub_s r0,r0,1 asr_s r2,r2,3 j_l.d [blink] sub_s r0,r0,r2 .balign 4 .Lfound0_ua: mov_l r3,r7 .Lfound0: sub r3,r6,r3 bic r3,r3,r6 and r2,r3,r4 or_s r12,r12,r2 sub_s r3,r12,1 bic_s r3,r3,r12 norm r3,r3 add_s r0,r0,3 asr_s r12,r3,3 asl.f 0,r2,r3 sub_s r0,r0,r12 j_s.d [blink] mov.pl r0,0 #else /* BIG ENDIAN */ .Lfound_char: lsr r7,r7,7 bic r2,r7,r6 .Lfound_char_b: norm r2,r2 sub_s r0,r0,4 asr_s r2,r2,3 j_l.d [blink] add_s r0,r0,r2 .Lfound0_ua: mov_s r3,r7 .Lfound0: asl_s r2,r2,7 or r7,r6,r4 bic_s r12,r12,r2 sub r2,r7,r3 or r2,r2,r6 bic r12,r2,r12 bic.f r3,r4,r12 norm r3,r3 add.pl r3,r3,1 asr_s r12,r3,3 asl.f 0,r2,r3 add_s r0,r0,r12 j_s.d [blink] mov.mi r0,0 #endif /* ENDIAN */ ENDFUNC (strchr) #endif /* (__ARC700__ || __ARCEM__ || __ARCHS__) && __ARC_NORM__ && __ARC_BARREL_SHIFTER__ */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/strchr-bs.S000066400000000000000000000122561513574234600205230ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/strchr.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) #include "asm.h" /* In order to search for a zero in a W, we calculate X := (W - 0x01010101) & ~W & 0x80808080; In the little endian case: If no byte in W is zero, X will be zero; otherwise, the least significant byte of X which is nonzero indicates the least significant byte of W that is zero. In the big endian case: X will be zero iff no byte in W is zero. If X is nonzero, to find out which is the most significant zero byte in W, we calculate: Y := ~(((W | 0x80808080) - 0x01010101) | W) & 0x80808080; Each byte in Y is 0x80 if the the corresponding byte in W is zero, otherwise that byte of Y is 0. */ #if defined (__ARC_BARREL_SHIFTER__) && \ (defined (__ARC600__) || (!defined (__ARC_NORM__) && !defined (__ARC601__))) ENTRY (strchr) bmsk.f r2,r0,1 mov_s r3,0x01010101 extb_s r1,r1 asl r5,r1,8 or r5,r5,r1 beq.d .Laligned asl r4,r5,16 sub_s r0,r0,r2 asl_s r2,r2,3 #ifdef __LITTLE_ENDIAN__ asl r7,r3,r2 #else lsr r7,r3,r2 #endif ld_s r2,[r0] or r5,r5,r4 ror r4,r3 sub r12,r2,r7 bic_s r12,r12,r2 and r12,r12,r4 brne.d r12,0,.Lfound0_ua xor r6,r2,r5 ld.a r2,[r0,4] sub r12,r6,r7 bic r12,r12,r6 #ifdef __LITTLE_ENDIAN__ and.f r7,r12,r4 sub r12,r2,r3 bic_s r12,r12,r2 beq.d .Loop and r12,r12,r4 b.d .Lfound_char_ua btst r7,7 #else and.f r8,r12,r4 sub r12,r2,r3 bic_s r12,r12,r2 beq.d .Loop and r12,r12,r4 bic r12,r7,r6 asl_s r12,r12,7 and.f r2,r8,r12 b.d .Lfound_char_ua sub_s r0,r0,4 #endif .balign 4 .Laligned: ld_s r2,[r0] or r5,r5,r4 ror r4,r3 sub r12,r2,r3 bic_s r12,r12,r2 and r12,r12,r4 .Loop: brne.d r12,0,.Lfound0 xor r6,r2,r5 ld.a r2,[r0,4] sub r12,r6,r3 bic r12,r12,r6 and.f r7,r12,r4 sub r12,r2,r3 bic_s r12,r12,r2 beq.d .Loop and r12,r12,r4 ; Found searched-for character. r0 has already advanced to next word. #ifdef __LITTLE_ENDIAN__ /* We only need the information about the first matching byte (i.e. the least significant matching byte) to be exact, hence there is no problem with carry effects. */ .Lfound_char: btst r7,7 .Lfound_char_ua: sub_s r0,r0,4 add.eq r0,r0,1 btst.eq r7,15 add.eq r0,r0,1 btst.eq r7,23 j_s.d [blink] add.eq r0,r0,1 .balign 4 .Lfound0_ua: mov_l r3,r7 .Lfound0: sub r2,r6,r3 bic r2,r2,r6 and r2,r2,r4 or r3,r12,r2 sub_s r12,r3,1 xor_s r3,r3,r12 tst_s r2,r3 lsr r2,r3,31 lsr r12,r3,16 jeq.d [blink] mov.eq r0,0 lsr r3,r3,8 sub_s r2,r2,r12 sub_s r2,r2,r3 bmsk_s r2,r2,1 j_s.d [blink] add_s r0,r0,r2 #else /* BIG ENDIAN */ .Lfound_char: asl r6,r6,7 sub_s r0,r0,4 bic.f r2,r7,r6 .Lfound_char_ua: add.pl r0,r0,1 jmi.d [blink] btst_s r2,23 add.eq r0,r0,1 btst.eq r2,15 j_s.d [blink] add.eq r0,r0,1 ; N.B. if we searched for a char zero and found it in the MSB, ; and ignored matches are identical, we will take the early exit ; like for an ordinary found zero - except for the extra stalls at jhi - ; but still compute the right result. .Lfound0_ua: mov_s r3,r7 .Lfound0: asl_s r2,r2,7 or r7,r6,r4 bic_s r12,r12,r2 sub r2,r7,r3 or r2,r2,r6 bic r2,r4,r2 cmp r12,r2 mov.hi r0,0 btst.ls r2,31 jhi.d [blink] add.eq r0,r0,1 btst.eq r2,23 add.eq r0,r0,1 btst.eq r2,15 j_s.d [blink] add.eq r0,r0,1 #endif /* ENDIAN */ ENDFUNC (strchr) #endif /* __ARC_BARREL_SHIFTER__ && (__ARC600__ || (!__ARC_NORM__ && !__ARC601__)) */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/strchr-stub.c000066400000000000000000000045701513574234600211140ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include /* strchr.S */ #if !defined(__OPTIMIZE_SIZE__) && !defined(__PREFER_SIZE_OVER_SPEED) #if defined(__ARC601__) || !defined(__ARC_BARREL_SHIFTER__) #define STRCHR_ASM #endif #endif /* strchr-bs.S */ #if !defined(__OPTIMIZE_SIZE__) && !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__ARC_RF16__) #if defined(__ARC_BARREL_SHIFTER__) \ && (defined(__ARC600__) || (!defined(__ARC_NORM__) && !defined(__ARC601__))) #define STRCHR_ASM #endif #endif /* strchr-bs-norm.S */ #if !defined(__OPTIMIZE_SIZE__) && !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__ARC_RF16__) #if (defined(__ARC700__) || defined(__ARCEM__) || defined(__ARCHS__)) && defined(__ARC_NORM__) \ && defined(__ARC_BARREL_SHIFTER__) #define STRCHR_ASM #endif #endif #ifndef STRCHR_ASM #include "../../string/strchr.c" #endif picolibc-1.8.11/libc/machine/arc/strchr.S000066400000000000000000000122721513574234600201170ustar00rootroot00000000000000/* Copyright (c) 2015, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/strchr.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) #include "asm.h" /* In order to search for a zero in a W, we calculate X := (W - 0x01010101) & ~W & 0x80808080; In the little endian case: If no byte in W is zero, X will be zero; otherwise, the least significant byte of X which is nonzero indicates the least significant byte of W that is zero. In the big endian case: X will be zero iff no byte in W is zero. If X is nonzero, to find out which is the most significant zero byte in W, we calculate: Y := ~(((W | 0x80808080) - 0x01010101) | W) & 0x80808080; Each byte in Y is 0x80 if the the corresponding byte in W is zero, otherwise that byte of Y is 0. */ #if defined (__ARC601__) || !defined (__ARC_BARREL_SHIFTER__) ENTRY (strchr) bmsk.f r2,r0,1 mov_s r3,0x01010101 extb_s r1,r1 mov r8,0 add3 r5,r8,r1 add3 r5,r8,r5 add2 r5,r1,r5 add3 r4,r8,r5 add3 r4,r8,r4 add3 r4,r8,r4 add3 r4,r8,r4 beq.d .Laligned add3 r4,r8,r4 sub_s r0,r0,r2 #ifdef __LITTLE_ENDIAN__ add3.f r2,-1,r2 bmsk r7,r3,r2 rsub.pl r7,r7,r3 #else mov_s r12,31 sub3 r2,r12,r2 bmsk r7,r3,r2 #endif ld_s r2,[r0] add1 r5,r5,r4 ror r4,r3 sub r12,r2,r7 bic_s r12,r12,r2 and r12,r12,r4 brne.d r12,0,.Lfound0_ua xor r6,r2,r5 ld.a r2,[r0,4] sub r12,r6,r7 bic r12,r12,r6 #ifdef __LITTLE_ENDIAN__ and.f r7,r12,r4 sub r12,r2,r3 bic_s r12,r12,r2 beq.d .Loop and r12,r12,r4 b.d .Lfound_char_ua btst r7,7 #else and.f r8,r12,r4 sub r12,r2,r3 bic_s r12,r12,r2 beq.d .Loop and r12,r12,r4 bic r12,r7,r6 bic r2,r3,r12 sub1 r2,r3,r2 sub_s r0,r0,4 b.d .Lfound_char_ua bic.f r2,r8,r2 #endif .balign 4 .Laligned: ld_s r2,[r0] add1 r5,r5,r4 ror r4,r3 sub r12,r2,r3 bic_s r12,r12,r2 and r12,r12,r4 .Loop: brne.d r12,0,.Lfound0 xor r6,r2,r5 ld.a r2,[r0,4] sub r12,r6,r3 bic r12,r12,r6 and.f r7,r12,r4 sub r12,r2,r3 bic_s r12,r12,r2 beq.d .Loop and r12,r12,r4 ; Found searched-for character. r0 has already advanced to next word. #ifdef __LITTLE_ENDIAN__ /* We only need the information about the first matching byte (i.e. the least significant matching byte) to be exact, hence there is no problem with carry effects. */ .Lfound_char: btst r7,7 .Lfound_char_ua: sub_s r0,r0,4 add.eq r0,r0,1 btst.eq r7,15 add.eq r0,r0,1 btst.eq r7,23 j_s.d [blink] add.eq r0,r0,1 .balign 4 .Lfound0_ua: mov_l r3,r7 .Lfound0: sub r2,r6,r3 bic r2,r2,r6 and r2,r2,r4 or r3,r12,r2 sub_s r12,r3,1 xor_s r3,r3,r12 cmp 0xffff,r3 ; cmp uses limm ; ARC600 would do: asl.f 0,r3,9 tst_s r2,r3 mov.eq r0,0 add.mi r0,r0,1 btst.ne r3,15 j_s.d [blink] adc.ne r0,r0,1 #else /* BIG ENDIAN */ .Lfound_char: and r2,r6,r3 sub1 r2,r3,r2 sub_s r0,r0,4 bic.f r2,r7,r2 .Lfound_char_ua: add.pl r0,r0,1 jmi.d [blink] btst_s r2,23 add.eq r0,r0,1 btst.eq r2,15 j_s.d [blink] add.eq r0,r0,1 ; N.B. if we searched for a char zero and found it in the MSB, ; and ignored matches are identical, we will take the early exit ; like for an ordinary found zero - except for the extra stalls at jhi - ; but still compute the right result. .Lfound0_ua: mov_s r3,r7 .Lfound0: and_s r2,r2,r3 sub1 r2,r3,r2 or r7,r6,r4 bic_s r12,r12,r2 sub r2,r7,r3 or r2,r2,r6 bic r2,r4,r2 cmp_s r12,r2 mov.hi r0,0 btst.ls r2,31 jhi.d [blink] add.eq r0,r0,1 btst.eq r2,23 add.eq r0,r0,1 btst.eq r2,15 j_s.d [blink] add.eq r0,r0,1 #endif /* ENDIAN */ ENDFUNC (strchr) #endif /* __ARC601__ || !__ARC_BARREL_SHIFTER__ */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/strcmp-archs.S000066400000000000000000000057221513574234600212220ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/strcmp.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) #include "asm.h" #ifdef __ARCHS__ ENTRY (strcmp) or r2, r0, r1 bmsk_s r2, r2, 1 brne r2, 0, .Lcharloop ; s1 and s2 are word aligned ld.ab r2, [r0, 4] mov_s r12, 0x01010101 ror r11, r12 .align 4 .LwordLoop: ld.ab r3, [r1, 4] ; Detect NULL char in str1 sub r4, r2, r12 ld.ab r5, [r0, 4] bic r4, r4, r2 and r4, r4, r11 brne.d.nt r4, 0, .LfoundNULL ; Check if the read locations are the same cmp r2, r3 beq.d .LwordLoop mov.eq r2, r5 ; A match is found, spot it out #ifdef __LITTLE_ENDIAN__ swape r3, r3 mov_s r0, 1 swape r2, r2 #else mov_s r0, 1 #endif cmp_s r2, r3 j_s.d [blink] bset.lo r0, r0, 31 .align 4 .LfoundNULL: #ifdef __BIG_ENDIAN__ swape r4, r4 swape r2, r2 swape r3, r3 #endif ; Find null byte ffs r0, r4 bmsk r2, r2, r0 bmsk r3, r3, r0 swape r2, r2 swape r3, r3 ; make the return value sub.f r0, r2, r3 mov.hi r0, 1 j_s.d [blink] bset.lo r0, r0, 31 .align 4 .Lcharloop: ldb.ab r2, [r0, 1] ldb.ab r3, [r1, 1] nop breq r2, 0, .Lcmpend breq r2, r3, .Lcharloop .align 4 .Lcmpend: j_s.d [blink] sub r0, r2, r3 ENDFUNC (strcmp) #endif /* __ARCHS__ */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/strcmp-stub.c000066400000000000000000000033231513574234600211120ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED) || defined(__ARC_RF16__) #include "../../string/strcmp.c" #else /* See strcmp-*.S. */ #endif picolibc-1.8.11/libc/machine/arc/strcmp.S000066400000000000000000000106211513574234600201160ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/strcmp.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) #include "asm.h" /* This is optimized primarily for the ARC700. It would be possible to speed up the loops by one cycle / word respective one cycle / byte by forcing double source 1 alignment, unrolling by a factor of two, and speculatively loading the second word / byte of source 1; however, that would increase the overhead for loop setup / finish, and strcmp might often terminate early. */ #ifndef __ARCHS__ ENTRY (strcmp) or r2,r0,r1 bmsk_s r2,r2,1 brne_l r2,0,.Lcharloop mov_s r12,0x01010101 ror r5,r12 .Lwordloop: ld.ab r2,[r0,4] ld.ab r3,[r1,4] nop_s sub r4,r2,r12 bic r4,r4,r2 and r4,r4,r5 brne_l r4,0,.Lfound0 breq r2,r3,.Lwordloop #ifdef __LITTLE_ENDIAN__ xor r0,r2,r3 ; mask for difference sub_s r1,r0,1 bic_s r0,r0,r1 ; mask for least significant difference bit sub r1,r5,r0 xor r0,r5,r1 ; mask for least significant difference byte and_s r2,r2,r0 and_s r3,r3,r0 #endif /* LITTLE ENDIAN */ cmp_s r2,r3 mov_s r0,1 j_s.d [blink] bset.lo r0,r0,31 .balign 4 #ifdef __LITTLE_ENDIAN__ .Lfound0: xor r0,r2,r3 ; mask for difference or r0,r0,r4 ; or in zero indicator sub_s r1,r0,1 bic_s r0,r0,r1 ; mask for least significant difference bit sub r1,r5,r0 xor r0,r5,r1 ; mask for least significant difference byte and_s r2,r2,r0 and_s r3,r3,r0 sub.f r0,r2,r3 mov.hi r0,1 j_s.d [blink] bset.lo r0,r0,31 #else /* BIG ENDIAN */ /* The zero-detection above can mis-detect 0x01 bytes as zeroes because of carry-propagateion from a lower significant zero byte. We can compensate for this by checking that bit0 is zero. This compensation is not necessary in the step where we get a low estimate for r2, because in any affected bytes we already have 0x00 or 0x01, which will remain unchanged when bit 7 is cleared. */ .balign 4 .Lfound0: #ifdef __ARC_BARREL_SHIFTER__ lsr r0,r4,8 lsr_s r1,r2 bic_s r2,r2,r0 ; get low estimate for r2 and get ... bic_s r0,r0,r1 ; or_s r3,r3,r0 ; ... high estimate r3 so that r2 > r3 will ... cmp_s r3,r2 ; ... be independent of trailing garbage or_s r2,r2,r0 ; likewise for r3 > r2 bic_s r3,r3,r0 rlc r0,0 ; r0 := r2 > r3 ? 1 : 0 cmp_s r2,r3 j_s.d [blink] bset.lo r0,r0,31 #else /* __ARC_BARREL_SHIFTER__ */ /* Fall through to .Lcharloop. */ sub_s r0,r0,4 sub_s r1,r1,4 #endif /* __ARC_BARREL_SHIFTER__ */ #endif /* ENDIAN */ .balign 4 .Lcharloop: ldb.ab r2,[r0,1] ldb.ab r3,[r1,1] nop_s breq_l r2,0,.Lcmpend breq r2,r3,.Lcharloop .Lcmpend: j_s.d [blink] sub r0,r2,r3 ENDFUNC (strcmp) #endif /* !__ARCHS__ */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/strcpy-bs-arc600.S000066400000000000000000000066571513574234600215430ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/strcpy.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) #include "asm.h" #if defined (__ARC600__) && defined (__ARC_BARREL_SHIFTER__) /* If dst and src are 4 byte aligned, copy 8 bytes at a time. If the src is 4, but not 8 byte aligned, we first read 4 bytes to get it 8 byte aligned. Thus, we can do a little read-ahead, without dereferencing a cache line that we should not touch. Note that short and long instructions have been scheduled to avoid branch stalls. This version is optimized for the ARC600 pipeline. */ ENTRY (strcpy) or r2,r0,r1 bmsk.f 0,r2,1 mov r8,0x01010101 bne.d .Lcharloop mov_s r10,r0 ld_l r3,[r1,0] bbit0.d r1,2,.Loop_setup ror r12,r8 sub r2,r3,r8 bic_s r2,r2,r3 and_s r2,r2,r12 brne_s r2,0,.Lr3z st.ab r3,[r10,4] ld.a r3,[r1,4] .Loop_setup: ld.a r4,[r1,4] sub r2,r3,r8 and.f r2,r2,r12 sub r5,r4,r8 and.eq.f r5,r5,r12 b.d .Loop_start mov_s r6,r3 .balign 4 .Loop: ld.a r3,[r1,4] st r4,[r10,4] ld.a r4,[r1,4] sub r2,r3,r8 and.f r2,r2,r12 sub r5,r4,r8 and.eq.f r5,r5,r12 st.ab r6,[r10,8] mov r6,r3 .Loop_start: beq.d .Loop bic_s r2,r2,r3 brne.d r2,0,.Lr3z and r5,r5,r12 bic r5,r5,r4 breq.d r5,0,.Loop mov_s r3,r4 st.ab r6,[r10,4] #ifdef __LITTLE_ENDIAN__ .Lr3z: bmsk.f r1,r3,7 .Lr3z_loop: lsr_s r3,r3,8 stb.ab r1,[r10,1] bne.d .Lr3z_loop bmsk.f r1,r3,7 j_s [blink] #else .Lr3z: lsr.f r1,r3,24 .Lr3z_loop: asl_s r3,r3,8 stb.ab r1,[r10,1] bne.d .Lr3z_loop lsr.f r1,r3,24 j_s [blink] #endif .balign 4 .Lcharloop: ldb.ab r3,[r1,1] brne.d r3,0,.Lcharloop stb.ab r3,[r10,1] j [blink] ENDFUNC (strcpy) #endif /* __ARC600__ && __ARC_BARREL_SHIFTER__ */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/strcpy-bs.S000066400000000000000000000064641513574234600205460ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/strcpy.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) #include "asm.h" #if (defined (__ARC700__) || defined (__ARCEM__) || defined (__ARCHS__)) \ && defined (__ARC_BARREL_SHIFTER__) /* If dst and src are 4 byte aligned, copy 8 bytes at a time. If the src is 4, but not 8 byte aligned, we first read 4 bytes to get it 8 byte aligned. Thus, we can do a little read-ahead, without dereferencing a cache line that we should not touch. Note that short and long instructions have been scheduled to avoid branch stalls. The beq_s to r3z could be made unaligned & long to avoid a stall there, but the it is not likely to be taken often, and it would also be likey to cost an unaligned mispredict at the next call. */ ENTRY (strcpy) or r2,r0,r1 bmsk_s r2,r2,1 brne.d r2,0,charloop mov_s r10,r0 ld_s r3,[r1,0] mov r8,0x01010101 bbit0.d r1,2,loop_start ror r12,r8 sub r2,r3,r8 bic_s r2,r2,r3 tst_s r2,r12 bne_l r3z mov_s r4,r3 .balign 4 loop: ld.a r3,[r1,4] st.ab r4,[r10,4] loop_start: ld.a r4,[r1,4] sub r2,r3,r8 bic_s r2,r2,r3 tst_l r2,r12 bne_l r3z st.ab r3,[r10,4] sub r2,r4,r8 bic r2,r2,r4 tst_l r2,r12 beq_l loop mov_s r3,r4 #ifdef __LITTLE_ENDIAN__ r3z: bmsk.f r1,r3,7 lsr_s r3,r3,8 #else r3z: lsr.f r1,r3,24 asl_s r3,r3,8 #endif bne.d r3z stb.ab r1,[r10,1] j_s [blink] .balign 4 charloop: ldb.ab r3,[r1,1] brne.d r3,0,charloop stb.ab r3,[r10,1] j [blink] ENDFUNC (strcpy) #endif /* (__ARC700__ || __ARCEM__ || __ARCHS__) && __ARC_BARREL_SHIFTER__ */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/strcpy-stub.c000066400000000000000000000033231513574234600211260ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED) || defined(__ARC_RF16__) #include "../../string/strcpy.c" #else /* See strcpy-*.S. */ #endif picolibc-1.8.11/libc/machine/arc/strcpy.S000066400000000000000000000056661513574234600201470ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/strcpy.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) #include "asm.h" #if defined (__ARC601__) || !defined (__ARC_BARREL_SHIFTER__) /* If dst and src are 4 byte aligned, copy 8 bytes at a time. If the src is 4, but not 8 byte aligned, we first read 4 bytes to get it 8 byte aligned. Thus, we can do a little read-ahead, without dereferencing a cache line that we should not touch. This version is a compromise between speed for the 601 pipeline and code size. */ ENTRY (strcpy) or r2,r0,r1 bmsk.f 0,r2,1 mov r8,0x01010101 bne.d .Lcharloop mov_s r10,r0 ld_s r3,[r1] bbit0.d r1,2,.Loop_start ror r12,r8 sub r2,r3,r8 bic_s r2,r2,r3 and_s r2,r2,r12 brne_s r2,0,.Lr3z mov r4,r3 sub_s r1,r1,4 .balign 4 .Loop: ld.a r3,[r1,8] st.ab r4,[r10,4] .Loop_start: ld r4,[r1,4] sub r2,r3,r8 bic_s r2,r2,r3 tst_s r2,r12 sub r5,r4,r8 bic r5,r5,r4 bne_s .Lr3z and r5,r5,r12 breq.d r5,0,.Loop st.ab r3,[r10,4] ;mov_s r3,r4 add_s r1,r1,4 .balign 4 .Lr3z: .Lcharloop: ldb.ab r3,[r1,1] brne.d r3,0,.Lcharloop stb.ab r3,[r10,1] j_s [blink] ENDFUNC (strcpy) #endif /* __ARC601__ || !__ARC_BARREL_SHIFTER__ */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/strncpy-bs.S000066400000000000000000000111141513574234600207100ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/strncpy.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) #include "asm.h" /* If dst and src are 4 byte aligned, copy 8 bytes at a time. If the src is 4, but not 8 byte aligned, we first read 4 bytes to get it 8 byte aligned. Thus, we can do a little read-ahead, without dereferencing a cache line that we should not touch. Note that short and long instructions have been scheduled to avoid branch stalls. The beq_s to r3z could be made unaligned & long to avoid a stall there, but the it is not likely to be taken often, and it would also be likey to cost an unaligned mispredict at the next call. */ #if !defined (__ARC601__) && defined (__ARC_BARREL_SHIFTER__) #if defined (__ARC700___) || defined (__ARCEM__) || defined (__ARCHS__) #define BRand(a,b,l) tst a,b ` bne_l l #else #define BRand(a,b,l) and a,a,b ` brne_s a,0,l #endif ENTRY (strncpy) cmp_s r2,8 or r12,r0,r1 bmsk.cc.f r12,r12,1 brne.d r12,0,.Lbytewise mov_s r10,r0 ld_s r3,[r1,0] mov r8,0x01010101 sub lp_count,r2,1 bbit0.d r1,2,.Loop_start ror r11,r8 sub r12,r3,r8 bic_l r12,r12,r3 BRand (r12,r11,.Lr3z) mov_s r4,r3 ld.a r3,[r1,4] sub lp_count,lp_count,4 st.ab r4,[r10,4] .balign 4 .Loop_start: lsr.f lp_count,lp_count,3 lpne .Loop_end ld.a r4,[r1,4] sub r12,r3,r8 bic_s r12,r12,r3 BRand (r12,r11,.Lr3z) st.ab r3,[r10,4] sub r12,r4,r8 bic r12,r12,r4 BRand (r12,r11,.Lr4z) ld.a r3,[r1,4] st.ab r4,[r10,4] .Loop_end: bcc_s .Lastword ld.a r4,[r1,4] sub r12,r3,r8 bic_s r12,r12,r3 BRand (r12,r11,.Lr3z) st.ab r3,[r10,4] mov_s r3,r4 .Lastword: and.f lp_count,r2,3 mov.eq lp_count,4 lp .Last_byte_end #ifdef __LITTLE_ENDIAN__ bmsk.f r1,r3,7 lsr.ne r3,r3,8 #else lsr.f r1,r3,24 asl.ne r3,r3,8 #endif stb.ab r1,[r10,1] .Last_byte_end: j_s [blink] .balign 4 .Lr4z: mov_l r3,r4 .Lr3z: #if defined (__ARC700__) || defined (__ARCEM__) || defined (__ARCHS__) #ifdef __LITTLE_ENDIAN__ bmsk.f r1,r3,7 lsr_s r3,r3,8 #else lsr.f r1,r3,24 asl_s r3,r3,8 #endif bne.d .Lr3z stb.ab r1,[r10,1] #else /* ! __ARC700__ */ #ifdef __LITTLE_ENDIAN__ bmsk.f r1,r3,7 .Lr3z_loop: lsr_s r3,r3,8 stb.ab r1,[r10,1] bne.d .Lr3z_loop bmsk.f r1,r3,7 #else lsr.f r1,r3,24 .Lr3z_loop: asl_s r3,r3,8 stb.ab r1,[r10,1] bne.d .Lr3z_loop lsr.f r1,r3,24 #endif /* ENDIAN */ #endif /* ! __ARC700__ */ .Lzero_rest: ; __strncpy_bzero requires: ; return value in r0 ; zeroing length in r2 ; zeroing start address in r3 mov_s r3,r10 add_s r2,r2,r0 b.d __strncpy_bzero sub_s r2,r2,r3 .balign 4 .Lbytewise: sub.f r2,r2,1 mov_l r3,r0 jcs [blink] .Lcharloop: ldb.ab r12,[r1,1] beq.d .Last_byte sub.f r2,r2,1 brne.d r12,0,.Lcharloop stb.ab r12,[r3,1] b.d __strncpy_bzero stb.ab r12,[r3,1] .Last_byte: j_s.d [blink] stb_l r12,[r3] ENDFUNC (strncpy) #endif /* !__ARC601__ && __ARC_BARREL_SHIFTER__ */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/strncpy-stub.c000066400000000000000000000033241513574234600213050ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED) || defined(__ARC_RF16__) #include "../../string/strncpy.c" #else /* See strncpy-*.S. */ #endif picolibc-1.8.11/libc/machine/arc/strncpy.S000066400000000000000000000073011513574234600203110ustar00rootroot00000000000000/* Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is optimized for performance. For code size a generic implementation of this function from libc/string/strncpy.c will be used. */ #include #if !defined (__OPTIMIZE_SIZE__) && !defined (__PREFER_SIZE_OVER_SPEED) \ && !defined (__ARC_RF16__) #include "asm.h" /* If dst and src are 4 byte aligned, copy 8 bytes at a time. If the src is 4, but not 8 byte aligned, we first read 4 bytes to get it 8 byte aligned. Thus, we can do a little read-ahead, without dereferencing a cache line that we should not touch. */ #if defined (__ARC601__) || !defined (__ARC_BARREL_SHIFTER__) #define BRand(a,b,l) and a,a,b ` brne_s a,0,l ENTRY (strncpy) cmp_s r2,8 or r12,r0,r1 bmsk.cc.f r12,r12,1 brne.d r12,0,.Lbytewise mov_s r10,r0 ld_s r3,[r1,0] mov r8,0x01010101 add r6,r0,r2 sub r6,r6,8 bbit0.d r1,2,.Loop_start ror r11,r8 sub r12,r3,r8 bic_l r12,r12,r3 BRand (r12,r11,.Lr3z) mov_s r4,r3 ld.a r3,[r1,4] st.ab r4,[r10,4] .balign 4 .Loop_start: brhs r10,r6,.Loop_end 1: ld.a r4,[r1,4] sub r12,r3,r8 bic_s r12,r12,r3 BRand (r12,r11,.Lr3z2) st.ab r3,[r10,4] sub r12,r4,r8 bic r12,r12,r4 BRand (r12,r11,.Lr4z) ld.a r3,[r1,4] brlo.d r10,r6,1b st.ab r4,[r10,4] .Loop_end: add r6,r6,4 brhs r10,r6,.Lastword sub r12,r3,r8 bic_s r12,r12,r3 BRand (r12,r11,.Lr3z) add_s r1,r1,4 st.ab r3,[r10,4] .Lastword: sub_s r2,r2,1 b.d .Lstart_charloop bmsk.f r2,r2,1 .balign 4 nop_s .Lr3z2: sub_s r1,r1,4 .Lr4z: .Lr3z: .balign 4 .Lr3z_loop: ldb.ab r3,[r1,1] brne.d r3,0,.Lr3z_loop stb.ab r3,[r10,1] .Lzero_rest: ; __strncpy_bzero requires: ; return value in r0 ; zeroing length in r2 ; zeroing start address in r3 mov_s r3,r10 add_s r2,r2,r0 b.d __strncpy_bzero sub_s r2,r2,r3 .balign 4 .Lbytewise: sub.f r2,r2,1 jcs [blink] .Lstart_charloop: mov_s r3,r10 .Lcharloop: ldb.ab r12,[r1,1] beq.d .Last_byte sub.f r2,r2,1 brne.d r12,0,.Lcharloop stb.ab r12,[r3,1] b.d __strncpy_bzero stb.ab r12,[r3,1] .Last_byte: j_s.d [blink] stb_s r12,[r3] ENDFUNC (strncpy) #endif /* __ARC601__ || !__ARC_BARREL_SHIFTER__ */ #endif /* !__OPTIMIZE_SIZE__ && !__PREFER_SIZE_OVER_SPEED */ picolibc-1.8.11/libc/machine/arc/tls.c000066400000000000000000000042771513574234600174420ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #ifdef __THREAD_LOCAL_STORAGE_API #ifdef __ARC_TLS_REGNO__ #define TLS_REGNO __ARC_TLS_REGNO__ #elif defined(__ARC64__) #define TLS_REGNO 30 #else #define TLS_REGNO 26 #endif #ifdef __ARC64__ extern char __arc64_tls_tcb_offset[]; #define TP_OFFSET ((size_t)__arc64_tls_tcb_offset) #else extern char __arc_tls_tcb_offset[]; #define TP_OFFSET ((size_t)__arc_tls_tcb_offset) #endif #define _REG(n) "r" #n #define REG(n) _REG(n) void _set_tls(void *tls) { tls = (uint8_t *)tls - TP_OFFSET; __asm__("mov " REG(TLS_REGNO) ", %0" : : "r"(tls)); } #endif picolibc-1.8.11/libc/machine/arc/vector_table.c000066400000000000000000000057141513574234600213060ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include /* Interrupt functions */ void arc_halt_vector(void); void arc_halt_vector(void) { for (;;) ; } void arc_ignore_vector(void); void arc_ignore_vector(void) { } #define isr(name) void arc_##name##_vector(void) __attribute__((weak, alias("arc_ignore_vector"))); #define isr_halt(name) \ void arc_##name##_vector(void) __attribute__((weak, alias("arc_halt_vector"))); isr_halt(memory_error); isr_halt(instruction_error); isr_halt(machine_check); isr(tlb_miss_i); isr(tlb_miss_d); isr(prot_v); isr(privilege_v); isr(swi); isr(trap); isr(extension); isr(div_zero); /* dc_error is unused in ARCv3 and de-facto unused in ARCv2 as well */ isr(dc_error); isr(maligned); void _start(void); extern uint8_t __stack[]; #define i(addr, name) [(addr) / 4] = (void (*)(void))arc_##name##_vector __section(".data.init.enter") void (* const __weak_vector_table[])(void) __attribute((aligned(128))) = { [0] = (void *)_start, i(0x04, memory_error), i(0x08, instruction_error), i(0x0c, machine_check), i(0x10, tlb_miss_i), i(0x14, tlb_miss_d), i(0x18, prot_v), i(0x1c, privilege_v), i(0x20, swi), i(0x24, trap), i(0x28, extension), i(0x2c, div_zero), i(0x30, dc_error), i(0x34, maligned), }; __weak_reference(__weak_vector_table, __vector_table); picolibc-1.8.11/libc/machine/arc64/000077500000000000000000000000001513574234600166345ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/arc64/CMakeLists.txt000066400000000000000000000033631513574234600214010ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources_flags("-fno-builtin" memchr.S memcmp.S memcmp-stub.c memcpy.S memcpy-stub.c memmove.S memset.S memset-stub.c setjmp.S strcat.S strcmp.S strlen.S tls.c ) picolibc-1.8.11/libc/machine/arc64/memchr.S000066400000000000000000000227641513574234600202460ustar00rootroot00000000000000/* Copyright (c) 2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include ; r0 void* ptr ; r1 int ch ; r2 size_t count #if defined (__ARC64_ARCH32__) ENTRY (memchr) LSRP.f 0, r2, 4 ; counter for 16-byte chunks beq.d @.L_start_1_byte_search ; Filter for 1 byte bmsk r1, r1, 7 lsl8 r9, r1 or r9, r9, r1 vpack2hl r1, r9, r9 ; r1 is now setup with the special 4 byte repetition of the target byte ; We use r1 because we dont have any more registers free inside the main loop ; r9 can be repurposed mov r8, NULL_32DT_1 ror r9, r8 xor r3, r3, r3 .L_search_16_bytes: #if defined (__ARC64_LL64__) ldd.ab r4r5, [r0, +8] ldd.ab r6r7, [r0, +8] #else ld.ab r4, [r0, +4] ld.ab r5, [r0, +4] ld.ab r6, [r0, +4] ld.ab r7, [r0, +4] #endif xor r4, r4, r1 xor r5, r5, r1 xor r6, r6, r1 xor r7, r7, r1 sub r10, r4, r8 sub r11, r5, r8 sub r12, r6, r8 sub r13, r7, r8 bic r10, r10, r4 bic r11, r11, r5 bic r12, r12, r6 bic r13, r13, r7 tst r10, r9 bset.ne r3, r3, 4 tst r11, r9 bset.ne r3, r3, 3 tst r12, r9 bset.ne r3, r3, 2 tst r13, r9 bset.ne r3, r3, 1 ; Break if found brne.d r3, 0, @.L_found_in_16B ; Keep going we have more 16 byte chunks sub r2, r2, 16 brge r2, 16, @.L_search_16_bytes ; Reset byte repetition of r1 to 1 single byte bmsk r1, r1, 7 .L_start_1_byte_search: ; Check if r2 is 0 breq.d r2, 0, @.L_byte_not_found ldb.ab r10, [r0, +1] .L_search_1_byte: breq r10, r1, @.L_found_byte dbnz.d r2, @.L_search_1_byte ldb.ab r10, [r0, +1] ; Byte not found .L_byte_not_found: j.d [blink] MOVP r0, 0 .L_found_byte: j_s.d [blink] SUBP r0, r0, 1 .L_found_in_16B: fls r5, r3 ; [2] ; Select appropriate register to analyze [4] mov r2, r13 ; Point r13 to first NULL byte containing double word [3] sub2 r0, r0, r5 asr.f r3, r3, 3 mov.c r2, r12 asr.f r3, r3, 1 mov.c r2, r11 asr.f r3, r3, 1 mov.c r2, r10 and r2, r2, r9 ; [5] ffs r2, r2 ; [6] xbfu r2, r2, 0b0111000011 ; [7] j.d [blink] add r0, r0, r2 ; [8] ENDFUNC (memchr) #else ENTRY (memchr) lsrl.f 0, r2, 5 ; counter for 32-byte chunks beq.d @.L_start_1_byte_search ; Filter for 1 byte bmsk r1, r1, 7 lsl8 r9, r1 or r9, r9, r1 vpack2hl r1, r9, r9 vpack2wl r1, r1, r1 ; r1 is now setup with the special 4 byte repetition of the target byte ; We use r1 because we dont have any more registers free inside the main loop ; r9 can be repurposed vpack2wl r8, NULL_32DT_1, NULL_32DT_1 asll r9, r8, 7 xorl r3, r3, r3 .L_search_32_bytes: ; Using 128-bit memory operations #if defined (__ARC64_M128__) lddl.ab r4r5, [r0, +16] lddl.ab r6r7, [r0, +16] ; The 64-bit crunching implementation. #elif defined (__ARC64_ARCH64__) ldl.ab r4, [r0, +8] ldl.ab r5, [r0, +8] ldl.ab r6, [r0, +8] ldl.ab r7, [r0, +8] #else # error Unknown configuration #endif xorl r4, r4, r1 xorl r5, r5, r1 xorl r6, r6, r1 xorl r7, r7, r1 subl r10, r4, r8 subl r11, r5, r8 subl r12, r6, r8 subl r13, r7, r8 bicl r10, r10, r4 bicl r11, r11, r5 bicl r12, r12, r6 bicl r13, r13, r7 tstl r10, r9 bset.ne r3, r3, 4 tstl r11, r9 bset.ne r3, r3, 3 tstl r12, r9 bset.ne r3, r3, 2 tstl r13, r9 bset.ne r3, r3, 1 ; Break if found brne.d r3, 0, @.L_found_in_32B ; Keep going we have more 16 byte chunks subl r2, r2, 32 brge r2, 32, @.L_search_32_bytes ; Reset byte repetition of r1 to 1 single byte bmskl r1, r1, 7 .L_start_1_byte_search: ; Check if r2 is 0 breq.d r2, 0, @.L_byte_not_found ldb.ab r10, [r0, +1] .L_search_1_byte: breq r10, r1, @.L_found_byte dbnz.d r2, @.L_search_1_byte ldb.ab r10, [r0, +1] ; Byte not found .L_byte_not_found: j.d [blink] movl r0, 0 .L_found_byte: j_s.d [blink] subl r0, r0, 1 .L_found_in_32B: fls r5, r3 ; [2] ; Select appropriate register to analyze [4] movl r2, r13 ; Point r13 to first NULL byte containing double word [3] sub3l r0, r0, r5 asr.f r3, r3, 3 movl.c r2, r12 asr.f r3, r3, 1 movl.c r2, r11 asr.f r3, r3, 1 movl.c r2, r10 andl r2, r2, r9 ; [5] ffsl r2, r2 ; [6] xbful r2, r2, 0b0111000011 ; [7] j.d [blink] addl r0, r0, r2 ; [8] ENDFUNC (memchr) #endif ;; This code uses a common technique for NULL byte detection inside a word. ;; Details on this technique can be found in: ;; (https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord) ; ; In sum, this technique allows for detecting a NULL byte inside any given ; amount of bits by performing the following operation ; DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) [0] ; ; The code above implements this by setting r8 to a 0x01010101... sequence and ; r9 to a 0x80808080... sequence of appropriate length ; As LIMM are 32 bit only, we need to perform MOVHL and ORL [1] operations to ; have the appropriate 64 bit values in place ; ; As we want a specific byte and not a NULL byte, we create in r1 a constant ; that is made up of the target byte, on each byte position, that we xor with ; the loaded data to force a NULL byte only if the target byte is present. ; After that we can use the technique directly ; ;; Search is done 32 bytes at a time, either with 64 bit loads or 128 bit loads ;; If the target byte is detected, the position of the double word is encoded ;; in r3, which is eventually used to adjust r0 ; ; r3 is set via bset, which means we can simply use a fls to obtain the first ; match (or ffs depending on the values in bset) [2]. ; The reason for starting at 1 and not 0 is so r3 encodes how many double ; words to go back, and it wouldnt make sense to go back 0 (the byte would be ; in the next loop iteration). ; ; The first step to take is point r0 to the appropriate double word. ; As the chosen encoded information is how many double words to go back, ; we can simply multiply r3 by 8 and reduce r0 by that amount [3] ; ; Then, we need to place the loaded double word containing the first target byte ; found, into a "common" register we can operate on later [4]. ; ; To do this without any jumps, we can shift r3 and perform a conditional mov ; based on the carry flag value. ; The order is very important because the byte can appear in several double ; words, so we want to analyze from last to first. ; ; We can ignore the first asr (which would be asr.f 2, as we started r3 on 1) ; because if r13 isnt the target byte, r2 will always be overwritten so we can ; just decide to start at r7, and overwrite it if needed. ; ; Now comes the tricky part. In order to obtain the first target byte, we need ; to understand the NULL byte detection operation. It is explained in depth in ; the link above but in short, it works by first setting the highest bit of each ; byte to 1, if the corresponding byte is either 0 or more than 0x80 ; Then, separately, it makes the highest bit of each byte 1, if the byte is ; less than 0x80. The last step is to AND these two values (this operation is ; simplified with the SUB, BIC and TST instructions). ; ; This means that the evaluated equation result value [5] has zeros for all non ; zero bytes, except for the NULL bytes (which are the target bytes after the ; xor). Therefore, we can simply find the first non zero bit (counting from bit ; 0) which will be inside the position of the first NULL byte. ; ; One thing to note, is that ffs oddly returns 31 if no bit is found, setting ; the zero flag. As r9 is never all 0s at this stage (would mean there is no ; NULL byte and we wouldnt be here) we dont need to worry about that. [6] ; ; We can then convert the bit position into the last byte position by looking ; into bits 3 to 5, and shifting 3 bits to the right. This can be combined into ; a single xbful operation. The bottom 000011 represent shift by 3 and the top ; 0111 represents the mask (3 to 5 shifted by 3 is 0 to 2). We dont need to ; worry about the case where ffs does not find a bit, because we know for sure ; there is at least one NULL byte, and therefore one of the highest bits is set ; to 1 [7] ; ; Finally, we can add the NULL/target byte position inside the loaded double ; word to r0 to obtain the bytes absolute position [8] ; ; ; Some operations are re-ordered such that register dependency is reduced, ; allowing the CPU to run more instructions in parallel ; picolibc-1.8.11/libc/machine/arc64/memcmp-stub.c000066400000000000000000000032151513574234600212320ustar00rootroot00000000000000/* Copyright (c) 2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if defined(__ARC64_ARCH32__) #include "../../string/memcmp.c" #else /* See memcpy.S. */ #endif picolibc-1.8.11/libc/machine/arc64/memcmp.S000066400000000000000000000224541513574234600202450ustar00rootroot00000000000000/* Copyright (c) 2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #if defined (__ARC64_ARCH64__) ; R0: lhs ; R1: rhs ; R2: count ; ret (R0): ; - lhs < rhs: <0 ; - lhs = rhs: 0 ; - lhs > rhs: >0 ENTRY (memcmp) cmpl r2, 64 bls.d @.L_compare_1_bytes movl r3, r0 ; "r0" will be used as return value ; If one is curious why the code below looks like the way it does, ; there is a documentation at the end of this file. lsrl r12, r2, 5 ; counter for 32-byte chunks xor r13, r13, r13 ; the mask showing inequal registers ldl.ab r4, [r3, +8] ldl.ab r5, [r1, +8] .L_compare_32_bytes: ldl.ab r6, [r3, +8] ldl.ab r7, [r1, +8] ldl.ab r8, [r3, +8] ldl.ab r9, [r1, +8] ldl.ab r10, [r3, +8] ldl.ab r11, [r1, +8] xorl.f 0, r4, r5 xor.ne r13, r13, 0b0001 xorl.f 0, r6, r7 xor.ne r13, r13, 0b0010 xorl.f 0, r8, r9 xor.ne r13, r13, 0b0100 xorl.f 0, r10, r11 xor.ne r13, r13, 0b1000 brne r13, 0, @.L_unequal_find ldl.ab r4, [r3, +8] dbnz.d r12, @.L_compare_32_bytes ldl.ab r5, [r1, +8] ; Adjusting the pointers because of the extra loads in the end subl r1, r1, 8 subl r3, r3, 8 bmsk_s r2, r2, 4 ; any remaining bytes to compare .L_compare_1_bytes: cmp r2, 0 jeq.d [blink] xor_s r0, r0, r0 ldb.ab r4, [r3, +1] ldb.ab r5, [r1, +1] 2: sub.f r0, r4, r5 jne.d [blink] ldb.ab r4, [r3, +1] dbnz.d r2, @2b ldb.ab r5, [r1, +1] ; this load may read beyond the "count". j_s [blink] ; At this point, we want to find the _first_ comparison that marked the ; inequality of "lhs" and "rhs". The rest acts like a multiplexer: ; ; if r4 was not equal to r5 --> r1=r4, r2=r5 ; if r6 was not equal to r7 --> r1=r6, r2=r7 ; if r8 was not equal to r9 --> r1=r8, r2=r9 ; if r10 was not equal to r11 --> r1=r10, r2=r11 ; find_different_byte(r1, r2) ; ; About the "bi [n]" (branch index) instruction: This instruction alters ; next PC (program counter): ; ; next_pc = current_pc + n*4 n*4 is the same as n<<2 ; ; In other words, it tells the processor to execute the n'th instruction ; from where we are (assuming all the next instructions are 4 bytes long). ; ; We used this to our benefit. We made each "case" (unequal_r4r5, ; unequal_r5r6, ...) 16 bytes long (power of 2) and fed "bi" an index ; that is already multiplied by 4 (asl r13, r13, 2). This translates ; into "bi [n]" jumping to 16-bytes slots. The last slot we did not ; make 16 bytes long with "nop" because we don't need to address after ; it. .L_unequal_find: ffs r13, r13 asl r13, r13, 2 bi [r13] .L_unequal_r4r5: movl r1, r4 b.d @.L_diff_byte_in_regs movl r2, r5 nop .L_unequal_r6r7: movl r1, r6 b.d @.L_diff_byte_in_regs movl r2, r7 nop .L_unequal_r8r9: movl r1, r8 b.d @.L_diff_byte_in_regs movl r2, r9 nop .L_unequal_r10r11: movl r1, r10 movl r2, r11 ; fall-through ; If we're here, that means the two operands are not equal. ; 1) First we have to get a mask of their inequality through "xor" ; 2) Then, find the first bit position that they're different: "ffs" ; 3) Depending on the bit position, we want the whole byte containing ; that bit, in both operands, to become the very first byte (least ; significant byte), so that we can subtract one from another. ; Below is an illustration of bit positions and how much we should ; shift the numbers right: ; bit position range : (in binary) | shift right by : (in binary) ; -------------------+-------------------+----------------+------------ ; [ 0, 7] : (000000 - 000111) | lsr 0 : 000000 ; [ 8,15] : (001000 - 001111) | lsr 8 : 001000 ; [16,23] : (010000 - 010111) | lsr 16 : 010000 ; [24,31] : (011000 - 011111) | lsr 24 : 011000 ; ... : ... | ... : ... ; [56,63] : (111000 - 111111) | lsr 56 : 111000 ; We need to ignore the least 3 bits of "position" to get "shift right" ; amount: "and 0x38, ..." ; 4) When the bytes are positioned at byte #0, mask out the rest of the ; bytes and subtract the two operands: lhs - rhs .L_diff_byte_in_regs: xorl r0, r1, r2 ; (1) ffsl r0, r0 ; (2) and r0, r0, 0x38 ; (3) lsrl r1, r1, r0 ; (3) lsrl r2, r2, r0 ; (3) bmsk_s r1, r1, 7 ; (4) bmsk_s r2, r2, 7 ; (4) j_s.d [blink] subl r0, r1, r2 ; (4) ENDFUNC (memcmp) ; __ARC64_ARCH64__ #endif ; The loop at the heart of the "memcmp" function follows some specific ; logic and has gone through a few optimisation filters. Knowing them ; will help understand the code better. ; ; The comparison logic ; -------------------- ; In each loop, we compare 32 bytes of data from "lhs" and "rhs". Those ; comparisons takes place by using 8 sets of registers: ; ; r4 == r5 xor.f 0, r4, r5 lhs[i+0] == rhs[i+0] ; r6 == r7 xor.f 0, r6, r7 lhs[i+8] == rhs[i+8] ; r8 == r9 xor.f 0, r8, r9 lhs[i+16] == rhs[i+16] ; r10 == r11 xor.f 0, r10, r11 lhs[i+24] == rhs[i+32] ; ; The idea is to set a corresponding bit in r13 register for each ; comparison that fails. The relation between the bits and the ; comparisons are: ; ; r13[0..63] = 0 ; r13[0] = 1 if r4 != r5 ; r13[1] = 1 if r6 != r7 ; r13[2] = 1 if r8 != r9 ; r13[3] = 1 if r10 != r11 ; ; If r13 remains 0, the next possible iteration of the loop begins. ; If it is not 0 anymore, the algorithm will be interested in the ; lowest bit that is set to 1. That is achieved by the "ffs" ; (find first set) instruction. ; ; The loop transformation ; ----------------------- ; 1) At first, the loop looks like below: ; ; .loop ; ldl.ab r4, [r3, +8] ; ldl.ab r5, [r1, +8] ; ... ; ldl.ab r10, [r3, +8] ; ldl.ab r11, [r1, +8] ; xorl.f 0, r4, r5 ; xor.ne r13, r13, 0b0001 ; ... ; xorl.f 0, r10, r11 ; xor.ne r13, r13, 0b1000 ; brne r13, 0, @.unequal_find ; dbnz r12, @.loop ; ; 2) "dbnz" instruction has a delay slot. To make the code more ; efficient, we can bring the first 2 instructions of the loop ; to the end (they will be executed just before the next iteration ; begins). To make the logic of the program sound, those 2 ; instructions need to be duplicated before the loop start as well: ; ; ldl.ab r4, [r3, +8] ; ldl.ab r5, [r1, +8] ; .loop ; ldl.ab r6, [r3, +8] ; ldl.ab r7, [r1, +8] ; ... ; ldl.ab r10, [r3, +8] ; ldl.ab r11, [r1, +8] ; xorl.f 0, r4, r5 ; xor.ne r13, r13, 0b0001 ; ... ; xorl.f 0, r10, r11 ; xor.ne r13, r13, 0b1000 ; brne r13, 0, @.unequal_find ; ldl.ab r4, [r3, +8] ; dbnz.d r12, @.loop ; ldl.ab r5, [r1, +8] ; ; There is one more loose end to take care of: At the last iteration ; of the loop, there is an extra load into r4 and r5 registers while ; incrementing the pointers (r3 and r1). We have to correct for that ; after the loop: ; ; .loop: ; .. ; brne r13, 0, @.unequal_find ; ldl.ab r4, [r3, +8] ; dbnz.d r12, @.loop ; ldl.ab r5, [r1, +8] ; subl r1, r1, 8 ; subl r3, r3, 8 ; ; One last remark about NOT filling the delay slot of "brne" with ; "ldl.ab r4, ...". If the branch is taken, the rest of code that ; is responsible for finding the differentiating bytes relies that ; all 8 registers hold the comparison data of the loop. Putting ; "ldl.ab r4, ..." into the delay slot of "brne ..." would clobber ; the "r4" register: ; ; .loop: ; .. ; brne.d r13, 0, @.unequal_find --> this branch might be taken ; ldl.ab r4, [r3, +8] --> clobbers r4 ; dbnz.d r12, @.loop ; ldl.ab r5, [r1, +8] ; ; Having "ldl.ab r4, ..." between "brne" and "dbnz" as two control flow ; altering instructions is good enough. picolibc-1.8.11/libc/machine/arc64/memcpy-stub.c000066400000000000000000000032541513574234600212510ustar00rootroot00000000000000/* Copyright (c) 2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if !defined(__ARC64_ARCH32__) && !defined(__ARC64_ARCH64__) #include "../../string/memcpy.c" #else /* See memcpy.S. */ #endif picolibc-1.8.11/libc/machine/arc64/memcpy.S000066400000000000000000000156271513574234600202650ustar00rootroot00000000000000/* Copyright (c) 2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include ; This file contains variants of the same function with different ; instructions. The generic one, the implementation that comes the ; last after the #else macro, is the most commented. ; Using 128-bit memory operations #if defined (__ARC64_M128__) ENTRY (memcpy) lsrl.f r12, r2, 6 ; Check size < 64bytes beq.d @.L_write_1_bytes movl r3, r0 .L_write_64_bytes: lddl.ab r4r5, [r1, +16] lddl.ab r6r7, [r1, +16] lddl.ab r8r9, [r1, +16] lddl.ab r10r11, [r1, +16] stdl.ab r4r5, [r3, +16] stdl.ab r6r7, [r3, +16] stdl.ab r8r9, [r3, +16] dbnz.d r12, @.L_write_64_bytes stdl.ab r10r11, [r3, +16] .L_write_1_bytes: ;; Handle anything between 15bytes < size < 64bytes ;; The algorithm has two phases: ;; - copy 16, 32, or 48 bytes of data using 128bit ops ;; - copy the remaining 15 bytes of data using a single stdl/lddl pair bmsk.f r2, r2, 5 ; Check size == 0 jeq.d [blink] lsr.f r12, r2, 4 ; Check size < 16bytes beq.d @1f xor r12, r12, 3 ;; R12 can be 3,2, or 1, which are indicating how much data we should ;; copy: 3 -> 48bytes, 2 -> 32bytes, 1 -> 16bytes. ;; Zero case shouldn't happen as we check for it above. ;; Then I use the BI instructions to implement the following code ;; switch ($R12) ;; case 3: ;; lddl RA, ... ;; stdl RA, ... ;; case 2: ;; lddl RA, ... ;; stdl RA, ... ;; case 1: ;; lddl RA, ... ;; stdl RA, ... ;; case 0: ;; break ;; N.B the BI instruction works the other way than I expected, namely ;; BI's entry 0 is the closest to instruction, hence I need to bit ;; invert R12 to get the desired behaviour (done by above XOR). asl r12,r12,1 bi [r12] lddl.ab r4r5, [r1, +16] stdl.ab r4r5, [r3, +16] lddl.ab r6r7, [r1, +16] stdl.ab r6r7, [r3, +16] lddl.ab r8r9, [r1, +16] stdl.ab r8r9, [r3, +16] bmsk.f r2, r2, 3 ; Check size == 0 jeq.d [blink] subl r2, r2, 16 ;; We are still having 15 bytes top to transfer, exactly like in the ;; case of below byte-by-byte transfer. However, we already transfered ;; at least 16bytes before, thus, we can create a new 16byte load which ;; re-reads parts of the already transfer data AND the remaining up to ;; 15 bytes of data still to be transfered. ;; The position of the window is controlled by the $r12 which is the ;; complement of the number of remaining bytes. addl r3, r3, r2 lddl r4r5, [r1, r2] j_s.d [blink] stdl r4r5, [r3] 1: ;; Anything size < 16 we go byte by byte. ldb.ab r4, [r1, +1] dbnz.d r2, @1b stb.ab r4, [r3, +1] j_s [blink] ENDFUNC (memcpy) ; The 64-bit crunching implementation. #elif defined (__ARC64_ARCH64__) \ || (defined (__ARC64_ARCH32__) && defined (__ARC64_LL64__)) ; R0: dest ; R1: source ; R2: count ; ret (R0): dest ; clobber: r1, r3, r4r5, r6r7, r8r9, r10r11, r12 ENTRY (memcpy) LSRP.f r12, r2, 5 ; counter for 32-byte chunks beq.d @.L_write_31_bytes MOVP r3, r0 ; do not clobber the "dest" .L_write_32_bytes: ; Take care of 32 byte chunks LD64.ab r4, [r1, +8] LD64.ab r6, [r1, +8] LD64.ab r8, [r1, +8] LD64.ab r10,[r1, +8] ST64.ab r4, [r3, +8] ST64.ab r6, [r3, +8] ST64.ab r8, [r3, +8] dbnz.d r12, @.L_write_32_bytes ST64.ab r10, [r3, +8] ; Shove store in delay slot bmsk_s r2, r2, 4 ; From now on, we only care for the remainder % 32 ; The remainder bits indicating how many more bytes to copy ; .------------------------. ; | b4 | b3 | b2 | b1 | b0 | ; `------------------------' ; 16 8 4 2 1 .L_write_31_bytes: bbit0.d r2, 2, @1f ; is b2 set? then copy 4 bytes lsr r12, r2, 3 ; see the notes below ld.ab r4, [r1, 4] st.ab r4, [r3, 4] 1: bbit0.d r2, 1, @1f ; is b1 set? then copy 2 bytes xor r12, r12, 3 ldh.ab r4, [r1, 2] sth.ab r4, [r3, 2] 1: bbit0.d r2, 0, @1f ; is b0 set? then copy 1 byte asl r12, r12, 1 ldb.ab r4, [r1, 1] stb.ab r4, [r3, 1] ; Interpreting bits (b4,b3) [1] and how they correlate to branch index: ; ; (b4,b3) | bytes to copy | branch index ; --------+---------------+------------- ; 00b | 0 | 3 (11b) ; 01b | 8 | 2 (10b) ; 10b | 16 | 1 (01b) ; 11b | 24 | 0 (00b) ; ; To go from (b4,b3) to branch index, the bits must be flipped. ; In other words, they must be XORed with 11b [2]. ; ; Last but not least, "bi" jumps at boundaries of 4. We need to double ; the index to jump 8 bytes [3]. ; ; Hence, the 3 operations for calculating the branch index that are spread ; in "bbit0" delay slots: ; ; lsr r12, r2, 3 [1] ; xor r12, r12, 3 [2] ; asl r12, r12, 1 [3] 1: bi [r12] LD64.ab r4, [r1, 8] ST64.ab r4, [r3, 8] LD64.ab r4, [r1, 8] ST64.ab r4, [r3, 8] LD64.ab r4, [r1, 8] ST64.ab r4, [r3, 8] j_s [blink] ENDFUNC (memcpy) #elif defined (__ARC64_ARCH32__) ENTRY (memcpy) lsr.f r11, r2, 4 ; counter for 16-byte chunks beq.d @.L_write_15_bytes mov r3, r0 ; work on a copy of "r0" .L_write_16_bytes: ld.ab r4, [r1, 4] ld.ab r5, [r1, 4] ld.ab r6, [r1, 4] ld.ab r7, [r1, 4] st.ab r4, [r3, 4] st.ab r5, [r3, 4] st.ab r6, [r3, 4] dbnz.d r11, @.L_write_16_bytes st.ab r7, [r3, 4] bmsk_s r2, r2, 3 .L_write_15_bytes: bbit0.d r2, 1, @1f lsr r11, r2, 2 ldh.ab r4, [r1, 2] sth.ab r4, [r3, 2] 1: bbit0.d r2, 0, @1f xor r11, r11, 3 ldb.ab r4, [r1, 1] stb.ab r4, [r3, 1] 1: asl r11, r11, 1 bi [r11] ld.ab r4,[r1, 4] st.ab r4,[r3, 4] ld.ab r4,[r1, 4] st.ab r4,[r3, 4] ld r4,[r1] st r4,[r3] j_s [blink] ENDFUNC (memcpy) #else # error Unknown configuration #endif picolibc-1.8.11/libc/machine/arc64/memmove.S000066400000000000000000000170461513574234600204350ustar00rootroot00000000000000/* Copyright (c) 2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include ; r0 void* dest ; r1 const void* src ; r2 size_t count ; The 64-bit crunching implementation. #if defined (__ARC64_ARCH32__) && !defined(__ARC64_LL64__) ENTRY (memmove) ; If the destination is greater than the source cmp r0, r1 ADDP r4, r1, r2 ; or if the source plus count is smaller than the destination cmp.eq r4, r0 ; We can safely perform a normal memcpy. Otherwise, we need to perform it ; backwards blo.d @.L_normal_memcpy lsr.f r11, r2, 4 ; counter for 16-byte chunks ADDP r3, r0, r2 ; Backwards search ; The only thing that changes between memcpy and memmove is copy direction ; in case the dest and src address memory locations overlap ; More detailed information is in the forwards copy and at the end of ; this document ADDP r1, r1, r2 bmsk_s r2, r2, 3 bbit0.d r2, 1, @1f lsr r5, r2, 2 ldh.aw r4, [r1, -2] sth.aw r4, [r3, -2] 1: bbit0.d r2, 0, @1f xor r5, r5, 3 ldb.aw r4, [r1, -1] stb.aw r4, [r3, -1] 1: asl r5, r5, 1 bi [r5] ld.aw r4,[r1, -4] st.aw r4,[r3, -4] ld.aw r4,[r1, -4] st.aw r4,[r3, -4] ld.aw r4,[r1, -4] st.aw r4,[r3, -4] ; Return if there are no 16 byte chunks jeq [blink] .L_write_backwards_16_bytes: ld.aw r4, [r1, -4] ld.aw r5, [r1, -4] ld.aw r6, [r1, -4] ld.aw r7, [r1, -4] st.aw r4, [r3, -4] st.aw r5, [r3, -4] st.aw r6, [r3, -4] dbnz.d r11, @.L_write_backwards_16_bytes st.aw r7, [r3, -4] j_s [blink] .L_normal_memcpy: beq.d @.L_write_forwards_15_bytes mov r3, r0 ; work on a copy of "r0" .L_write_forwards_16_bytes: ld.ab r4, [r1, 4] ld.ab r5, [r1, 4] ld.ab r6, [r1, 4] ld.ab r7, [r1, 4] st.ab r4, [r3, 4] st.ab r5, [r3, 4] st.ab r6, [r3, 4] dbnz.d r11, @.L_write_forwards_16_bytes st.ab r7, [r3, 4] bmsk_s r2, r2, 3 .L_write_forwards_15_bytes: bbit0.d r2, 1, @1f lsr r11, r2, 2 ldh.ab r4, [r1, 2] sth.ab r4, [r3, 2] 1: bbit0.d r2, 0, @1f xor r11, r11, 3 ldb.ab r4, [r1, 1] stb.ab r4, [r3, 1] 1: asl r11, r11, 1 bi [r11] ld.ab r4,[r1, 4] st.ab r4,[r3, 4] ld.ab r4,[r1, 4] st.ab r4,[r3, 4] ld r4,[r1] st r4,[r3] j_s [blink] ENDFUNC (memmove) #else ENTRY (memmove) ; If the destination is greater than the source cmp r0, r1 ADDP r4, r1, r2 ; or if the source plus count is smaller than the destination cmp.eq r4, r0 ; We can safely perform a normal memcpy. Otherwise, we need to perform it ; backwards blo.d @.L_normal_memcpy LSRP.f r12, r2, 5 ; counter for 32-byte chunks ADDP r3, r0, r2 ; Backwards search ; The only thing that changes between memcpy and memmove is copy direction ; in case the dest and src address memory locations overlap ; More detailed information is in the forwards copy and at the end of ; this document ; Set both r0 and r1 to point to the end of each memory location ADDP r1, r1, r2 bmsk_s r2, r2, 4 bbit0.d r2, 0, @1f lsr r11, r2, 3 ldb.aw r4, [r1, -1] stb.aw r4, [r3, -1] 1: bbit0.d r2, 1, @1f xor r11, r11, 3 ldh.aw r4, [r1, -2] sth.aw r4, [r3, -2] 1: bbit0.d r2, 2, @1f asl r11, r11, 1 ld.aw r4, [r1, -4] st.aw r4, [r3, -4] 1: bi [r11] LD64.aw r4, [r1, -8] ST64.aw r4, [r3, -8] LD64.aw r4, [r1, -8] ST64.aw r4, [r3, -8] LD64.aw r4, [r1, -8] ST64.aw r4, [r3, -8] ; Jump if there are no 32 byte chunks jeq [blink] .L_write_backwards_32_bytes: ; Take care of 32 byte chunks #if defined (__ARC64_M128__) lddl.aw r4r5, [r1, -16] lddl.aw r6r7, [r1, -16] stdl.aw r4r5, [r3, -16] stdl.aw r6r7, [r3, -16] dbnz r12, @.L_write_backwards_32_bytes #elif defined (__ARC64_ARCH64__) || ( defined (__ARC64_ARCH32__) && defined (__ARC64_LL64__) ) LD64.aw r4, [r1, -8] LD64.aw r6, [r1, -8] LD64.aw r8, [r1, -8] LD64.aw r10,[r1, -8] ST64.aw r4, [r3, -8] ST64.aw r6, [r3, -8] ST64.aw r8, [r3, -8] dbnz.d r12, @.L_write_backwards_32_bytes ST64.aw r10, [r3, -8] #else # error Unknown configuration #endif j_s [blink] ; Normal memcpy .L_normal_memcpy: ;LSRP.f r12, r2, 5 ; Moved up beq.d @.L_write_forwards_31_bytes MOVP r3, r0 ; do not clobber the "dest" .L_write_forwards_32_bytes: ; Take care of 32 byte chunks #if defined (__ARC64_M128__) lddl.ab r4r5, [r1, +16] lddl.ab r6r7, [r1, +16] stdl.ab r4r5, [r3, +16] stdl.ab r6r7, [r3, +16] dbnz r12, @.L_write_forwards_32_bytes #elif defined (__ARC64_ARCH64__) || ( defined (__ARC64_ARCH32__) && defined (__ARC64_LL64__) ) LD64.ab r4, [r1, +8] LD64.ab r6, [r1, +8] LD64.ab r8, [r1, +8] LD64.ab r10,[r1, +8] ST64.ab r4, [r3, +8] ST64.ab r6, [r3, +8] ST64.ab r8, [r3, +8] dbnz.d r12, @.L_write_forwards_32_bytes ST64.ab r10, [r3, +8] ; Shove store in delay slot #else # error Unknown configuration #endif bmsk_s r2, r2, 4 ; From now on, we only care for the remainder % 32 ; The remainder bits indicating how many more bytes to copy ; .------------------------. ; | b4 | b3 | b2 | b1 | b0 | ; `------------------------' ; 16 8 4 2 1 .L_write_forwards_31_bytes: bbit0.d r2, 2, @1f ; is b2 set? then copy 4 bytes lsr r12, r2, 3 ; see the notes below ld.ab r4, [r1, 4] st.ab r4, [r3, 4] 1: bbit0.d r2, 1, @1f ; is b1 set? then copy 2 bytes xor r12, r12, 3 ldh.ab r4, [r1, 2] sth.ab r4, [r3, 2] 1: bbit0.d r2, 0, @1f ; is b0 set? then copy 1 byte asl r12, r12, 1 ldb.ab r4, [r1, 1] stb.ab r4, [r3, 1] ; Interpreting bits (b4,b3) [1] and how they correlate to branch index: ; ; (b4,b3) | bytes to copy | branch index ; --------+---------------+------------- ; 00b | 0 | 3 (11b) ; 01b | 8 | 2 (10b) ; 10b | 16 | 1 (01b) ; 11b | 24 | 0 (00b) ; ; To go from (b4,b3) to branch index, the bits must be flipped. ; In other words, they must be XORed with 11b [2]. ; ; Last but not least, "bi" jumps at boundaries of 4. We need to double ; the index to jump 8 bytes [3]. ; ; Hence, the 3 operations for calculating the branch index that are spread ; in "bbit0" delay slots: ; ; lsr r12, r2, 3 [1] ; xor r12, r12, 3 [2] ; asl r12, r12, 1 [3] 1: bi [r12] LD64.ab r4, [r1, 8] ST64.ab r4, [r3, 8] LD64.ab r4, [r1, 8] ST64.ab r4, [r3, 8] LD64.ab r4, [r1, 8] ST64.ab r4, [r3, 8] j_s [blink] ENDFUNC (memmove) #endif picolibc-1.8.11/libc/machine/arc64/memset-stub.c000066400000000000000000000032541513574234600212510ustar00rootroot00000000000000/* Copyright (c) 2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if !defined(__ARC64_ARCH32__) && !defined(__ARC64_ARCH64__) #include "../../string/memset.c" #else /* See memcpy.S. */ #endif picolibc-1.8.11/libc/machine/arc64/memset.S000066400000000000000000000105611513574234600202550ustar00rootroot00000000000000/* Copyright (c) 2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include ; This file contains variants of the same function with different ; instructions. The generic one, the implementation that comes the ; last after the #else macro, is the most commented. ; Using 128-bit memory operations #if defined (__ARC64_M128__) ENTRY (memset) ;; Assemble 128b token bmsk_s r1, r1, 7 lsl8 r3, r1 or_s r1, r1, r3 lsl16 r3, r1 or r6, r1, r3 addhl r6, r6, r6 movl r7, r6 lsrl.f r5, r2, 6 beq.d @.L_write_63_bytes movl r4, r0 .L_write_64_bytes: stdl.ab r6r7, [r4, +16] stdl.ab r6r7, [r4, +16] stdl.ab r6r7, [r4, +16] dbnz.d r5, @.L_write_64_bytes stdl.ab r6r7, [r4, +16] bmsk_s r2, r2, 5 .L_write_63_bytes: bbit0.d r2, 3, @1f lsr r3, r2, 4 stl.ab r6, [r4, 8] 1: bbit0.d r2, 2, @1f xor r3, r3, 3 st.ab r6, [r4, 4] 1: bbit0 r2, 1, @1f sth.ab r6, [r4, 2] 1: bbit0 r2, 0, @1f stb.ab r6, [r4, 1] 1: bi [r3] stdl.ab r6r7,[r4, 16] stdl.ab r6r7,[r4, 16] stdl.ab r6r7,[r4, 16] j_s [blink] .L_write_1_bytes: breq r2, 0, @.L_return dbnz.d r2, @. stb.ab r1, [r4, +1] .L_return: j_s [blink] ENDFUNC (memset) ; The generic 64-bit implementation without any frills. #elif defined (__ARC64_ARCH64__) || defined (__ARC64_LL64__) #if defined (__ARC64_ARCH32__) # define MOVH mov r7,r6 #elif defined (__ARC64_ARCH64__) # define MOVH addhl r6,r6,r6 #else # error Please use either 32-bit or 64-bit version of arc64 compiler #endif ; R0: dest ; R1: ch ; R2: count ; ret (R0): dest ENTRY (memset) ;; Assemble the bytes to 64bit words bmsk_s r1, r1, 7 ; treat it like unsigned char lsl8 r3, r1 or_s r1, r1, r3 lsl16 r3, r1 or r6, r1, r3 MOVH LSRP.f r5, r2, 5 ; counter for 32-byte chunks beq.d @.L_write_31_bytes MOVP r4, r0 ; work on a copy of "r0" .L_write_32_bytes: ST64.ab r6, [r4, +8] ST64.ab r6, [r4, +8] ST64.ab r6, [r4, +8] dbnz.d r5, @.L_write_32_bytes ST64.ab r6, [r4, +8] bmsk_s r2, r2, 4 .L_write_31_bytes: bbit0.d r2, 2, @1f lsr r3, r2, 3 st.ab r6, [r4, 4] 1: bbit0.d r2, 1, @1f xor r3, r3, 3 sth.ab r6, [r4, 2] 1: bbit0 r2, 0, @1f stb.ab r6, [r4, 1] 1: bi [r3] ST64.ab r6,[r4, 8] ST64.ab r6,[r4, 8] ST64.ab r6,[r4, 8] j_s [blink] ENDFUNC (memset) #elif defined (__ARC64_ARCH32__) ENTRY (memset) ;; Assemble the bytes to 32bit words bmsk_s r1, r1, 7 ; treat it like unsigned char lsl8 r3, r1 or_s r1, r1, r3 lsl16 r3, r1 or r6, r1, r3 lsr.f r5, r2, 4 ; counter for 16-byte chunks beq.d @.L_write_15_bytes mov r4, r0 ; work on a copy of "r0" .L_write_16_bytes: st.ab r6, [r4, 4] st.ab r6, [r4, 4] st.ab r6, [r4, 4] dbnz.d r5, @.L_write_16_bytes st.ab r6, [r4, 4] bmsk_s r2, r2, 3 .L_write_15_bytes: bbit0.d r2, 1, @1f lsr r3, r2, 2 sth.ab r6, [r4, 2] 1: bbit0.d r2, 0, @1f xor r3, r3, 3 stb.ab r6, [r4, 1] 1: bi [r3] st.ab r6,[r4, 4] st.ab r6,[r4, 4] st.ab r6,[r4, 4] j_s [blink] ENDFUNC (memset) #else # error Unknown configuration #endif picolibc-1.8.11/libc/machine/arc64/meson.build000066400000000000000000000042011513574234600207730ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'memchr.S', 'memcmp.S', 'memcmp-stub.c', 'memcpy.S', 'memcpy-stub.c', 'memmove.S', 'memset.S', 'memset-stub.c', 'setjmp.S', 'strcat.S', 'strcmp.S', 'strlen.S', 'tls.c', 'vector_table.c', ] subdir('sys') foreach params : targets target = params['name'] target_dir = params['dir'] target_c_args = params['c_args'] set_variable('lib_machine' + target, static_library('machine' + target, srcs_machine, pic: false, include_directories: inc, c_args: target_c_args + c_args + arg_fnobuiltin)) endforeach picolibc-1.8.11/libc/machine/arc64/setjmp.S000066400000000000000000000063411513574234600202660ustar00rootroot00000000000000/* Copyright (c) 2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include /* ABI interface file these are the stack mappings for the registers as stored in the ABI for ARC */ ABIr14 = 0 ABIr15 = ABIr14 + REG_SZ ABIr16 = ABIr15 + REG_SZ ABIr17 = ABIr16 + REG_SZ ABIr18 = ABIr17 + REG_SZ ABIr19 = ABIr18 + REG_SZ ABIr20 = ABIr19 + REG_SZ ABIr21 = ABIr20 + REG_SZ ABIr22 = ABIr21 + REG_SZ ABIr23 = ABIr22 + REG_SZ ABIr24 = ABIr23 + REG_SZ ABIr25 = ABIr24 + REG_SZ ABIr26 = ABIr25 + REG_SZ ABIr27 = ABIr26 + REG_SZ ABIr28 = ABIr27 + REG_SZ ABIr29 = ABIr28 + REG_SZ ABIr30 = ABIr29 + REG_SZ ABIr31 = ABIr30 + REG_SZ ENTRY (setjmp) REG_ST r14, [r0, ABIr14] REG_ST r15, [r0, ABIr15] REG_ST r16, [r0, ABIr16] REG_ST r17, [r0, ABIr17] REG_ST r18, [r0, ABIr18] REG_ST r19, [r0, ABIr19] REG_ST r20, [r0, ABIr20] REG_ST r21, [r0, ABIr21] REG_ST r22, [r0, ABIr22] REG_ST r23, [r0, ABIr23] REG_ST r24, [r0, ABIr24] REG_ST r25, [r0, ABIr25] REG_ST r26, [r0, ABIr26] REG_ST r27, [r0, ABIr27] REG_ST r28, [r0, ABIr28] REG_ST r29, [r0, ABIr29] REG_ST r30, [r0, ABIr30] REG_ST blink, [r0, ABIr31] j.d [blink] mov r0,0 .size setjmp,.-setjmp ENTRY (longjmp) ; load registers REG_LD r14, [r0, ABIr14] REG_LD r15, [r0, ABIr15] REG_LD r16, [r0, ABIr16] REG_LD r17, [r0, ABIr17] REG_LD r18, [r0, ABIr18] REG_LD r19, [r0, ABIr19] REG_LD r20, [r0, ABIr20] REG_LD r21, [r0, ABIr21] REG_LD r22, [r0, ABIr22] REG_LD r23, [r0, ABIr23] REG_LD r24, [r0, ABIr24] REG_LD r25, [r0, ABIr25] REG_LD r26, [r0, ABIr26] REG_LD r27, [r0, ABIr27] REG_LD r28, [r0, ABIr28] REG_LD r29, [r0, ABIr29] REG_LD r30, [r0, ABIr30] REG_LD blink, [r0, ABIr31] mov.f r1, r1 ; to avoid return 0 from longjmp mov.z r1, 1 j.d [blink] mov r0,r1 .size longjmp,.-longjmp picolibc-1.8.11/libc/machine/arc64/strcat.S000066400000000000000000000320601513574234600202610ustar00rootroot00000000000000/* Copyright (c) 2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include ; r0 char* dest ; r1 const char* src ; dest and src MUST NOT intercept ; Brief: ; Perform the same operation as strlen for finding the end of r0 string ; If r0 and r1 have ; If 4 byte aligned ; Do 4 byte search until there are no more 4 byte chunks ; Then, do 1 byte search ; Otherwise, 1 byte search until alignment ; Then, do 4 byte search as previously specified ; ;; More in depth description at the end ; ; R0 char* dest (destination string) ; R1 const char* src (source string) ; ret (R0): ; - char* (destiantion string) ; #if defined (__ARC64_ARCH32__) ENTRY (strcat) ; Find end of r0 string ; ========================== STRLEN CODE START ========================== ; Preserve r0 for size calculation when returning mov r13, r0 xor r6, r6, r6 ; Setup byte detector (more information below) [1] mov r8, NULL_32DT_1 asl r9, r8, 7 .L_4_4B_search: #if defined (__ARC64_LL64__) ldd.ab r2r3, [r13, +8] ldd.ab r4r5, [r13, +8] #else ld.ab r2, [r13, +4] ld.ab r3, [r13, +4] ld.ab r4, [r13, +4] ld.ab r5, [r13, +4] #endif ; NULL byte position is detected and encoded in r6 [0] [9] sub r10, r2, r8 sub r11, r3, r8 sub r12, r4, r8 sub r7, r5, r8 bic r10, r10, r2 bic r11, r11, r3 bic r12, r12, r4 bic r7, r7, r5 tst r10, r9 bset.ne r6, r6, 4 tst r11, r9 bset.ne r6, r6, 3 tst r12, r9 bset.ne r6, r6, 2 tst r7, r9 bset.ne r6, r6, 1 breq.d r6, 0, @.L_4_4B_search fls r5, r6 ; [2] ; Point r13 to first NULL byte containing double word [3] sub2 r13, r13, r5 ; Select appropriate register to analyze [4] mov r2, r7 asr.f r6, r6, 3 mov.c r2, r12 asr.f r6, r6, 1 mov.c r2, r11 asr.f r6, r6, 1 mov.c r2, r10 ; Point r13 to first NULL byte in selected double word and r2, r2, r9 ; [5] ffs r2, r2 ; [6] xbfu r2, r2, 0b0111000011 ; [7] add r13, r13, r2 ; [8] ; ========================== STRLEN CODE END >|< ========================== xor r6, r6, r6 .L_4_4B_search_src: #if defined (__ARC64_LL64__) ldd.ab r2r3, [r1, +8] ldd.ab r4r5, [r1, +8] #else ld.ab r2, [r1, +4] ld.ab r3, [r1, +4] ld.ab r4, [r1, +4] ld.ab r5, [r1, +4] #endif ; NULL byte position is detected and encoded in r6 [0] [9] sub r10, r2, r8 sub r11, r3, r8 sub r12, r4, r8 sub r7, r5, r8 bic r10, r10, r2 bic r11, r11, r3 bic r12, r12, r4 bic r7, r7, r5 tst r10, r9 bset.ne r6, r6, 4 tst r11, r9 bset.ne r6, r6, 3 tst r12, r9 bset.ne r6, r6, 2 tst r7, r9 bset.ne r6, r6, 1 brne r6, 0, @.L_found_in_32B #if defined (__ARC64_LL64__) std.ab r2r3, [r13, +8] std.ab r4r5, [r13, +8] #else st.ab r2, [r13, +4] st.ab r3, [r13, +4] st.ab r4, [r13, +4] st.ab r5, [r13, +4] #endif b @.L_4_4B_search_src .L_found_in_32B: fls r6, r6 ; [2] ; Point r1 to first NULL byte containing double word [3] sub2 r1, r1, r6 ;; Store the already loaded data ; 4 -> 1 to 3 -> 0 ;subl r6, r6, 1 ; Invert so the biggest branch is at the end, and we dont need to increase ; block size ; 3 -> 0 to 0 -> 3 ;subl r6, 3, r6 ; Condense the two subs here rsub r6, r6, 4 asl r6, r6, 2 ; Store double words bi [r6] b.d @.L_store_lastL32bits mov r11, r2 nop nop st.ab r2, [r13, +4] b.d @.L_store_lastL32bits mov r11, r3 nop st.ab r2, [r13, +4] st.ab r3, [r13, +4] b.d @.L_store_lastL32bits mov r11, r4 st.ab r2, [r13, +4] st.ab r3, [r13, +4] st.ab r4, [r13, +4] mov r11, r5 ; r11 now contains the data to write .L_store_lastL32bits: sub r10, r11, r8 bic r10, r10, r11 and r10, r10, r9 ; [5] ffs r2, r10 ; [6] add r2, r2, 1 xbfu r2, r2, 0b0111000011 ; [7] mov r3, -1; Bitmask setup ; If the NULL byte is in byte 3 (starting from the right) ; we want to store 8-3 bytes rsub r2, r2, 8 asl r2, r2, 3 ; According to the target byte, setup masks lsr r3, r3, r2 not r4, r3 ; Obtain relevant data from destination ld r10, [r13] ; Get which data from dest is not to be overwritten and OR it ; with the relevant data to write and r3, r3, r11 and r4, r4, r10 or r3, r3, r4 j_s.d [blink] st.ab r3, [r13, +4] ENDFUNC (strcat) #else ENTRY (strcat) ; Find end of r0 string ; ========================== STRLEN CODE START ========================== ; Preserve r0 for size calculation when returning movl r13, r0 xorl r6, r6, r6 ; Setup byte detector (more information below) [1] vpack2wl r8, NULL_32DT_1, NULL_32DT_1 asll r9, r8, 7 .L_4_8B_search: ; Using 128-bit memory operations #if defined (__ARC64_M128__) lddl.ab r2r3, [r13, +16] lddl.ab r4r5, [r13, +16] ; The 64-bit crunching implementation. #elif defined (__ARC64_ARCH64__) ldl.ab r2, [r13, +8] ldl.ab r3, [r13, +8] ldl.ab r4, [r13, +8] ldl.ab r5, [r13, +8] #else # error Unknown configuration #endif ; NULL byte position is detected and encoded in r6 [0] [9] subl r10, r2, r8 subl r11, r3, r8 subl r12, r4, r8 subl r7, r5, r8 bicl r10, r10, r2 bicl r11, r11, r3 bicl r12, r12, r4 bicl r7, r7, r5 tstl r10, r9 bset.ne r6, r6, 4 tstl r11, r9 bset.ne r6, r6, 3 tstl r12, r9 bset.ne r6, r6, 2 tstl r7, r9 bset.ne r6, r6, 1 breq.d r6, 0, @.L_4_8B_search fls r5, r6 ; [2] ; Point r13 to first NULL byte containing double word [3] sub3l r13, r13, r5 ; Select appropriate register to analyze [4] MOVP r2, r7 asr.f r6, r6, 3 MOVP.c r2, r12 asr.f r6, r6, 1 MOVP.c r2, r11 asr.f r6, r6, 1 MOVP.c r2, r10 ; Point r13 to first NULL byte in selected double word andl r2, r2, r9 ; [5] ffsl r2, r2 ; [6] xbful r2, r2, 0b0111000011 ; [7] addl r13, r13, r2 ; [8] ; ========================== STRLEN CODE END >|< ========================== xorl r6, r6, r6 .L_4_8B_search_src: #if defined (__ARC64_M128__) lddl.ab r2r3, [r1, +16] lddl.ab r4r5, [r1, +16] #elif defined (__ARC64_ARCH64__) ldl.ab r2, [r1, +8] ldl.ab r3, [r1, +8] ldl.ab r4, [r1, +8] ldl.ab r5, [r1, +8] #else # error Unknown configuration #endif ; NULL byte position is detected and encoded in r6 [0] [9] subl r10, r2, r8 subl r11, r3, r8 subl r12, r4, r8 subl r7, r5, r8 bicl r10, r10, r2 bicl r11, r11, r3 bicl r12, r12, r4 bicl r7, r7, r5 tstl r10, r9 bset.ne r6, r6, 4 tstl r11, r9 bset.ne r6, r6, 3 tstl r12, r9 bset.ne r6, r6, 2 tstl r7, r9 bset.ne r6, r6, 1 brne r6, 0, @.L_found_in_32B #if defined (__ARC64_M128__) stdl.ab r2r3, [r13, +16] stdl.ab r4r5, [r13, +16] #elif defined (__ARC64_ARCH64__) stl.ab r2, [r13, +8] stl.ab r3, [r13, +8] stl.ab r4, [r13, +8] stl.ab r5, [r13, +8] #else # error Unknown configuration #endif b @.L_4_8B_search_src .L_found_in_32B: fls r6, r6 ; [2] ; Point r1 to first NULL byte containing double word [3] sub3l r1, r1, r6 ;; Store the already loaded data ; 4 -> 1 to 3 -> 0 ;subl r6, r6, 1 ; Invert so the biggest branch is at the end, and we dont need to increase ; block size ; 3 -> 0 to 0 -> 3 ;subl r6, 3, r6 ; Condense the two subs here rsubl r6, r6, 4 asll r6, r6, 2 ; Store double words bi [r6] b.d @.L_store_lastL64bits MOVP r11, r2 nop nop stl.ab r2, [r13, +8] b.d @.L_store_lastL64bits MOVP r11, r3 nop stl.ab r2, [r13, +8] stl.ab r3, [r13, +8] b.d @.L_store_lastL64bits MOVP r11, r4 stl.ab r2, [r13, +8] stl.ab r3, [r13, +8] stl.ab r4, [r13, +8] MOVP r11, r5 ; r11 now contains the data to write .L_store_lastL64bits: subl r10, r11, r8 bicl r10, r10, r11 andl r10, r10, r9 ; [5] ffsl r2, r10 ; [6] addl r2, r2, 1 xbful r2, r2, 0b0111000011 ; [7] movl r3, -1; Bitmask setup ; If the NULL byte is in byte 3 (starting from the right) ; we want to store 8-3 bytes rsubl r2, r2, 8 asl r2, r2, 3 ; According to the target byte, setup masks lsrl r3, r3, r2 notl r4, r3 ; Obtain relevant data from destination ldl r10, [r13] ; Get which data from dest is not to be overwritten and OR it ; with the relevant data to write andl r3, r3, r11 andl r4, r4, r10 orl r3, r3, r4 j_s.d [blink] stl.ab r3, [r13, +8] ENDFUNC (strcat) #endif ;; This code uses a common technique for NULL byte detection inside a word. ;; Details on this technique can be found in: ;; (https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord) ; ; In sum, this technique allows for detecting a NULL byte inside any given ; amount of bits by performing the following operation ; DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) [0] ; ; The code above implements this by setting r8 to a 0x01010101... sequence and ; r9 to a 0x80808080... sequence of appropriate length ; As LIMM are 32 bit only, we need to perform MOVHL and ORL [1] operations to ; have the appropriate 64 bit values in place ; ;; Search is done 32 bytes at a time, either with 64 bit loads or 128 bit loads ;; If a NULL byte is detected, the position of the double word is encoded ;; in r6, which is then used to adjust r13 to the exact byte ; ; r6 is set via bset, which means we can simply use a fls to obtain the first ; match (or ffs depending on the values in bset) [2]. ; The reason for starting at 1 and not 0 is so r6 encodes how many double ; words to go back, and it wouldnt make sense to go back 0 (the NULL would be ; in the next loop iteration). ; ; The first step to take is point r13 to the appropriate double word. ; As the chosen encoded information is how many double words to go back, ; we can simply multiply r6 by 8 and reduce r13 by that amount [3] ; ; Then, we need to place the loaded double word containing the first NULL byte ; into a "common" register we can operate on later [4]. ; ; To do this without any jumps, we can shift r6 and perform a conditional mov ; based on the carry flag value. ; The order is very important because the NULL byte can appear in several ; double words, so we want to analyze from last to first. ; ; We can ignore the first asr (which would be asr.f 2, as we started r6 on 1) ; because if r7 isnt the NULL byte, r2 will always be overwritten so we can ; just decide to start at r7, and overwrite it if needed. ; ; Now comes the tricky part. In order to obtain the first NULL byte, we need to ; understand the NULL byte detection operation. It is explained in depth in the ; link above but in short, it works by first setting the highest bit of each ; byte to 1, if the corresponding byte is either 0 or less than 0x80 ; Then, separately, it makes the highest bit of each byte 1, if the byte is ; less than 0x80. The last step is to and these two values (this operation is ; simplified with the subl, bicl and tst instructions). ; ; This means that the evaluated equation result value [5] has zeros for all non ; zero bytes, except for the NULL bytes. Therefore, we can simply find the ; first non zero bit (counting from bit 0) which will be inside the position of ; the first NULL byte. ; ; One thing to note, is that ffs oddly returns 31 if no bit is found, setting ; the zero flag. As r9 is never all 0s at this stage (would mean there is no ; NULL byte and we wouldnt be here) we dont need to worry about that. [6] ; ; We can then convert the bit position into the last byte position by looking ; into bits 3 to 5, and shifting 3 bits to the right. This can be combined into ; a single xbful operation. The bottom 000011 represent shift by 3 and the top ; 0111 represents the mask (3 to 5 shifted by 3 is 0 to 2). We dont need to worry ; about the case where ffs does not find a bit, because we know for sure there is ; at least one NULL byte, and therefore one of the highest bits is set to 1 [7] ; ; Finally, we can add the NULL byte position inside the loaded double word to ; r13 and subtract r0 from r13 to obtain the string size [8] ; ; Some operations are re-ordered such that register dependency is reduced, ; allowing the CPU to run more instructions in parallel [9] ; ; ; Some data was already read, and needs to be stored following the same read ; order. To do this, we need to make the ; ; picolibc-1.8.11/libc/machine/arc64/strcmp.S000066400000000000000000000221601513574234600202710ustar00rootroot00000000000000/* Copyright (c) 2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #if defined (__ARC64_ARCH32__) ; 64 bit version has the same working principles, with slightly different ; instructions, so it is more commented ENTRY (strcmp) xor r12, r12, r12 mov r8, NULL_32DT_1 asl r9, r8, 7 .L_3_4B_comparison: ld.ab r6, [r0, +4] ld.ab r7, [r1, +4] #if defined (__ARC64_LL64__) ldd.ab r2r3, [r0, +8] ldd.ab r4r5, [r1, +8] #else ld.ab r2, [r0, +4] ld.ab r3, [r0, +4] ld.ab r4, [r1, +4] ld.ab r5, [r1, +4] #endif sub r13, r6, r8 sub r10, r2, r8 sub r11, r3, r8 bic r13, r13, r6 bic r10, r10, r2 bic r11, r11, r3 ; Look for difference sub.f 0, r6, r7 bset.ne r12, r12, 3 sub.f 0, r2, r4 bset.ne r12, r12, 2 sub.f 0, r3, r5 bset.ne r12, r12, 1 ; Look for NULL byte and.f r13, r13, r9 bset.ne r12, r12, 3 and.f r10, r10, r9 bset.ne r12, r12, 2 and.f r11, r11, r9 bset.ne r12, r12, 1 breq r12, 0, @.L_3_4B_comparison ; Setup r0, r3 and r5 with the relevant loaded and intermediate values mov r0, r11 mov r3, r3 mov r5, r5 asr.f r12, r12, 3 mov.c r0, r10 mov.c r3, r2 mov.c r5, r4 asr.f r12, r12, 1 mov.c r0, r13 mov.c r3, r6 mov.c r5, r7 ffs.f r10, r0 xor r12, r3, r5 mov.z r10, 32 ffs r12, r12 xbfu r10, r10, 0b0111000011 xbfu r12, r12, 0b0111000011 sub.f 0, r10, r12 asl.ge r12, r12, 3 ; Difference is first lsr.ge r3, r3, r12 lsr.ge r5, r5, r12 bmsk r3, r3, 7 bmsk r5, r5, 7 j_s.d [blink] sub r0, r3, r5 ENDFUNC(strcmp) #else ENTRY (strcmp) xorl r12, r12, r12 ; Setup byte detector (more information bellow) [1] vpack2wl r8, NULL_32DT_1, NULL_32DT_1 ; Set r9 as a copy of r8 for vectorized sub asll r9, r8, 7 .L_3_8B_comparison: ldl.ab r6, [r0, +8] ldl.ab r7, [r1, +8] ; Using 128-bit memory operations #if defined (__ARC64_M128__) lddl.ab r2r3, [r0, +16] lddl.ab r4r5, [r1, +16] ; The 64-bit crunching implementation. #elif defined (__ARC64_ARCH64__) ldl.ab r2, [r0, +8] ldl.ab r3, [r0, +8] ldl.ab r4, [r1, +8] ldl.ab r5, [r1, +8] #else # error Unknown configuration #endif subl r13, r6, r8 subl r10, r2, r8 subl r11, r3, r8 bicl r13, r13, r6 bicl r10, r10, r2 bicl r11, r11, r3 ; Look for difference subl.f 0, r6, r7 bset.ne r12, r12, 3 subl.f 0, r2, r4 bset.ne r12, r12, 2 subl.f 0, r3, r5 bset.ne r12, r12, 1 ; Look for NULL byte andl.f r13, r13, r9 bset.ne r12, r12, 3 andl.f r10, r10, r9 bset.ne r12, r12, 2 andl.f r11, r11, r9 bset.ne r12, r12, 1 breq r12, 0, @.L_3_8B_comparison ; Setup r0, r3 and r5 with the relevant loaded and intermediate values [2] ; [3] movl r0, r11 movl r3, r3 movl r5, r5 asr.f r12, r12, 3 movl.c r0, r10 movl.c r3, r2 movl.c r5, r4 asr.f r12, r12, 1 movl.c r0, r13 movl.c r3, r6 movl.c r5, r7 ffsl.f r10, r0 ; [5] xorl r12, r3, r5 movl.z r10, 64 ; [6] ffsl r12, r12 ; [8] xbful r10, r10, 0b0111000011 ; [7] xbful r12, r12, 0b0111000011 ; r12 contains position of difference and r10 the position of a NULL byte ; r3 and r5 contain the differing 8 bytes ; Is there a difference? subl.f 0, r10, r12 ; Multiply the byte position by 8 to get bit shift asll.ge r12, r12, 3 lsrl.ge r3, r3, r12 lsrl.ge r5, r5, r12 ; There is no difference. Up until the NULL byte which must be bmskl r3, r3, 7 bmskl r5, r5, 7 j_s.d [blink] subl r0, r3, r5 ENDFUNC (strcmp) #endif ;; One important thing to note, is that we look for the first byte difference on ;; both strings but we only look for the NULL byte in one string. ;; This is because if a NULL byte appears first, it will be the first different ;; byte. If it doesnt, the difference is what matters either way. If there is no ;; difference, the NULL bytes will coincide! ; ; ;; This code uses a common technique for NULL byte detection inside a word. ;; Details on this technique can be found in: ;; (https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord) ; ; In sum, this technique allows for detecting a NULL byte inside any given ; amount of bits by performing the following operation ; DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) [0] ; ; The code above implements this by setting r8 to a 0x01010101... sequence and ; r1 to a 0x80808080... sequence of appropriate length ; As LIMM are 32 bit only, we need to perform MOVHL and ORL [1] operations to ; have the appropriate 64 bit values in place ; ;; Comparison is done 24 bytes at a time, either with 3 64 bit loads or 1 128 bit ;; load and 1 64 bit. ;; If either a NULL byte or a difference between the strings is found, r12 is ;; used to know in which word the NULL/difference is found ; ; With the carry bit from r12, we can use mov.c to only move the appropriate ; registers into the ones we will operate on [2]. We can safely directly move ; the last set of registers without looking at r12, because if they aren't the ; appropriate ones, they will be rewritten afterwards. [3] ; ;; Knowing the registers that contain the relevant information, we only need to ;; look into where the difference and one of the zeros is. ;; This is because, if the zeros are in different places, the difference will ;; either be an earlier difference, or the first zero, so the actual zeros are ;; irrelevant. ;; Zero position is only relevant if there is no difference. And if there is no ;; difference, the zeros have the same position. ; ; So now comes the tricky part. In order to obtain the position of a "first ; NULL byte", we need to understand the NULL byte detection operation. ; It is explained in depth in the link above but in short, it works by first ; setting the highest bit of each byte to 1, if the corresponding byte is either ; 0 or more than 0x80 ; Then, it makes the highest bit of each byte 1, if the byte is less than 0x80. ; The last step is to AND these two values (this operation is simplified with ; the SUB, BIC and TST instructions). ; ; This means that the evaluated equation result value has zeros for all non ; zero bytes, except for the NULL bytes. Therefore, we can simply find the ; first non zero bit (counting from bit 0) which will be inside the position of ; the first NULL byte. [5] ; ; One thing to note, is that ffs oddly returns 31/63 if no bit is found, setting ; the zero flag. As there can be that no NULL byte is present on one or both ; strings at this point, we must set r10 and r11 to 32/64 when appropriate. [6] ; ; We can then convert the bit position into the last byte position by looking ; into bits 3 to 5, and shifting 3 bits to the right. This can be combined into ; a single xbful operation. The bottom 000011 represent shift by 3 and the top ; 0111 represents the mask (3 to 5 shifted by 3 is 0 to 2). [7] ; ; To obtain the position of the difference, all we need to do is xor the two ; registers. This way, every equal byte cancels out and all we are left with ; is gibberish in the differing bytes. We can use the same ffs and xbuf ; operations to get the differing byte position. ; ; Note that the order of the operations isnt the same as in this explanation, ; to reduce register dependency between instructions ; ; ; Unlike with r10, we dont need to check the zero flag for r12s' ffs because if ; it is 0, it means there is no difference in the loaded data so any subtraction ; operation will return 0 [8] ; ; There is one optimization that is being overlooked, which is returning 0 if ; there is no difference, but there are NULL bytes anywhere, right after the ; main loop. The reason for this is because the only way this can happen is if ; the strings have the same length AND either are a multiple of 16/8 bytes, or ; the bytes that follow the NULL bytes also match. As this is extremely ; unlikely, it isnt worth it to perform this optimization since it would require ; an extra branch in all runs ; picolibc-1.8.11/libc/machine/arc64/strlen.S000066400000000000000000000203541513574234600202730ustar00rootroot00000000000000/* Copyright (c) 2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include ; Code Brief (more info at the bottom): ; Searches the provided string, 32 bytes at a time, using 128 bit loads ; Finds the NULL bytes inside the loaded data ; Analyzes the first NULL byte containing double word and calculates ; size appropriately ; ; R0 const char* ptr (string to measure) ; ret (R0): ; - unsigned (string size) ; #if defined (__ARC64_ARCH32__) ENTRY (strlen) ; Preserve r0 for size calculation when returning mov r13, r0 xor r12, r12, r12 ; Setup byte detector (more information bellow) [1] mov r8, NULL_32DT_1 ; Set r9 as a copy of r8 for vectorized sub mov r9, r8 asl r1, r8, 7 .L_4_4B_search: #if defined (__ARC64_LL64__) ldd.ab r2r3, [r13, +8] ldd.ab r4r5, [r13, +8] #else ld.ab r2, [r13, +4] ld.ab r3, [r13, +4] ld.ab r4, [r13, +4] ld.ab r5, [r13, +4] #endif ; NULL byte position is detected and encoded in r12 [0] [9] vsub2 r10, r2, r8 vsub2 r6, r4, r8 bic r10, r10, r2 bic r11, r11, r3 bic r6, r6, r4 bic r7, r7, r5 tst r10, r1 bset.ne r12, r12, 4 tst r11, r1 bset.ne r12, r12, 3 tst r6, r1 bset.ne r12, r12, 2 tst r7, r1 bset.ne r12, r12, 1 breq.d r12, 0, @.L_4_4B_search fls r5, r12 ; [2] ; Point r13 to first NULL byte containing double word [3] sub2 r13, r13, r5 ; Select appropriate register to analyze [4] mov r2, r7 asr.f r12, r12, 3 mov.c r2, r6 asr.f r12, r12, 1 mov.c r2, r11 asr.f r12, r12, 1 mov.c r2, r10 ; Point r13 to first NULL byte in selected double word .L_fix_r13: and r1, r2, r1 ; [5] ffs r1, r1 ; [6] xbfu r1, r1, 0b0111000011 ; [7] add r13, r13, r1 ; [8] j_s.d [blink] sub r0, r13, r0 ENDFUNC (strlen) #else ENTRY (strlen) ; Preserve r0 for size calculation when returning movl r13, r0 xor r12, r12, r12 ; Setup byte detector (more information bellow) [1] vpack2wl r8, NULL_32DT_1, NULL_32DT_1 asll r1, r8, 7 .L_4_8B_search: ; Using 128-bit memory operations #if defined (__ARC64_M128__) lddl.ab r2r3, [r13, +16] lddl.ab r4r5, [r13, +16] ; The 64-bit crunching implementation. #elif defined (__ARC64_ARCH64__) ldl.ab r2, [r13, +8] ldl.ab r3, [r13, +8] ldl.ab r4, [r13, +8] ldl.ab r5, [r13, +8] #else # error Unknown configuration #endif ; NULL byte position is detected and encoded in r6 [0] [9] subl r10, r2, r8 subl r11, r3, r8 subl r6, r4, r8 subl r7, r5, r8 bicl r10, r10, r2 bicl r11, r11, r3 bicl r6, r6, r4 bicl r7, r7, r5 tstl r10, r1 bset.ne r12, r12, 4 tstl r11, r1 bset.ne r12, r12, 3 tstl r6, r1 bset.ne r12, r12, 2 tstl r7, r1 bset.ne r12, r12, 1 breq.d r12, 0, @.L_4_8B_search flsl r5, r12 ; [2] ; Point r13 to first NULL byte containing double word [3] sub3l r13, r13, r5 ; Select appropriate register to analyze [4] movl r2, r7 asr.f r12, r12, 3 movl.c r2, r6 asr.f r12, r12, 1 movl.c r2, r11 asr.f r12, r12, 1 movl.c r2, r10 ; Point r13 to first NULL byte in selected double word .L_fix_r13: andl r1, r2, r1 ; [5] ffsl r1, r1 ; [6] xbful r1, r1, 0b0111000011 ; [7] addl r13, r13, r1 ; [8] j_s.d [blink] subl r0, r13, r0 ENDFUNC (strlen) #endif ;; This code uses a common technique for NULL byte detection inside a word. ;; Details on this technique can be found in: ;; (https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord) ; ; In sum, this technique allows for detecting a NULL byte inside any given ; amount of bits by performing the following operation ; DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) [0] ; ; The code above implements this by setting r8 to a ; 0x01010101... sequence and r1 to a 0x80808080... sequence of ; appropriate length As LIMM are 32 bit only, we need to perform MOVHL ; and ORL [1] operations to have the appropriate 64 bit values in ; place ; ;; Search is done 32 bytes at a time, either with 64 bit loads or 128 ;; bit loads If a NULL byte is detected, the position of the double ;; word is encoded in r12, which is then used to adjust r13 ; ; r12 is set via bset, which means we can simply use a fls to obtain ; the first match (or ffs depending on the values in bset) [2]. The ; reason for starting at 1 and not 0 is so r12 encodes how many double ; words to go back, and it wouldnt make sense to go back 0 (the NULL ; would be in the next loop iteration). ; ; The first step to take is point r13 to the appropriate double word. ; As the chosen encoded information is how many double words to go ; back, we can simply multiply r12 by 8 and reduce r13 by that amount ; [3] ; ; Then, we need to place the loaded double word containing the first ; NULL byte into a "common" register we can operate on later [4]. ; ; To do this without any jumps, we can shift r12 and perform a ; conditional mov based on the carry flag value. The order is very ; important because the NULL byte can appear in several double words, ; so we want to analyze from last to first. ; ; We can ignore the first asr (which would be asr.f 2, as we started ; r12 on 1) because if r7 isnt the NULL byte, r2 will always be ; overwritten so we can just decide to start at r7, and overwrite it ; if needed. ; ; Now comes the tricky part. In order to obtain the first NULL byte, ; we need to understand the NULL byte detection operation. It is ; explained in depth in the link above but in short, it works by first ; setting the highest bit of each byte to 1, if the corresponding byte ; is either 0 or more than 0x80 Then, separately, it makes the highest ; bit of each byte 1, if the byte is less than 0x80. The last step is ; to AND these two values (this operation is simplified with the SUB, ; BIC and TST instructions). ; ; This means that the evaluated equation result value [5] has zeros ; for all non zero bytes, except for the NULL bytes. Therefore, we can ; simply find the first non zero bit (counting from bit 0) which will ; be inside the position of the first NULL byte. ; ; One thing to note, is that ffs oddly returns 31 if no bit is found, ; setting the zero flag. As r9 is never all 0s at this stage (would ; mean there is no NULL byte and we wouldnt be here) we dont need to ; worry about that. [6] ; ; We can then convert the bit position into the last byte position by ; looking into bits 3 to 5, and shifting 3 bits to the right. This can ; be combined into a single xbful operation. The bottom 000011 ; represent shift by 3 and the top 0111 represents the mask (3 to 5 ; shifted by 3 is 0 to 2). We dont need to worry about the case where ; ffs does not find a bit, because we know for sure there is at least ; one NULL byte, and therefore one of the highest bits is set to 1 [7] ; ; Finally, we can add the NULL byte position inside the loaded double ; word to r13 and subtract r0 from r13 to obtain the string size [8] ; ; ; Some operations are re-ordered such that register dependency is ; reduced, allowing the CPU to run more instructions in parallel [9] ; ; picolibc-1.8.11/libc/machine/arc64/sys/000077500000000000000000000000001513574234600174525ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/arc64/sys/asm.h000066400000000000000000000047231513574234600204110ustar00rootroot00000000000000/* Copyright (c) 2024, Synopsys, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SYS_ASM_H #define _SYS_ASM_H /* * Macros to handle different pointer/register sizes for 32/64-bit code */ #if defined (__ARC64_ARCH32__) # define ST64 std # define LD64 ldd # define MOVP mov # define LSRP lsr # define ADDP add # define SUBP sub # define REG_SZ 4 # define REG_ST st # define REG_LD ld #elif defined (__ARC64_ARCH64__) # define ST64 stl # define LD64 ldl # define MOVP movl # define LSRP lsrl # define ADDP addl # define SUBP subl # define REG_SZ 8 # define REG_ST stl # define REG_LD ldl #else # error Please use either 32-bit or 64-bit version of arc64 compiler #endif # define NULL_32DT_1 0x01010101 # define NULL_32DT_2 0x80808080 #define _ENTRY(name) .text ` .balign 4 ` .globl name ` name: #define FUNC(name) .type name,@function #define ENDFUNC0(name) .Lfe_##name: .size name,.Lfe_##name-name #define ENDFUNC(name) ENDFUNC0 (name) #define ENTRY(name) _ENTRY (name) ` FUNC (name) #endif /* _SYS_ASM_H */ picolibc-1.8.11/libc/machine/arc64/sys/meson.build000066400000000000000000000033031513574234600216130ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2026 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_sys_headers_machine = [ ] if really_install install_headers(inc_sys_headers_machine, install_dir: include_dir / 'sys') endif picolibc-1.8.11/libc/machine/arc64/tls.c000066400000000000000000000031471513574234600176070ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2026 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "../arc/tls.c" picolibc-1.8.11/libc/machine/arc64/vector_table.c000066400000000000000000000031601513574234600214510ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2026 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "../arc/vector_table.c" picolibc-1.8.11/libc/machine/arm/000077500000000000000000000000001513574234600164745ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/arm/CMakeLists.txt000066400000000000000000000035001513574234600212320ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # add_subdirectory(machine) picolibc_sources_flags("-fno-builtin" aeabi_memset.c bzero.c interrupt.c memchr.c memchr.S memcpy.c memcpy.S memmove.c memset.c memset.S read_tp.S set_tls.c setjmp.S strcmp.S strcpy.S strlen.c strlen.S tls.c ) picolibc-1.8.11/libc/machine/arm/aeabi_memset.c000066400000000000000000000042351513574234600212570ustar00rootroot00000000000000/* * Copyright (c) 2015 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include /* Support the routine __aeabi_memset. Can't alias to memset because the arguments are in a different order */ /* *__used added so that building with clang -flto * doesn't discard this function */ #undef memset void __used __weak __aeabi_memset(void *dest, size_t n, int c); void __aeabi_memset(void *dest, size_t n, int c) { /*Note that relative to ANSI memset, __aeabi_memset hase the order of its second and third arguments reversed. */ memset(dest, c, n); } /* Support the alias for the __aeabi_memset which may assume memory alignment. */ __weak_reference(__aeabi_memset, __aeabi_memset4); __weak_reference(__aeabi_memset, __aeabi_memset8); picolibc-1.8.11/libc/machine/arm/arm_asm.h000066400000000000000000000365071513574234600202770ustar00rootroot00000000000000/* * Copyright (c) 2009 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef ARM_ASM__H #define ARM_ASM__H #include "machine/acle-compat.h" #if __ARM_ARCH >= 7 && defined (__ARM_ARCH_ISA_ARM) # define _ISA_ARM_7 #endif #if __ARM_ARCH >= 6 && defined (__ARM_ARCH_ISA_ARM) # define _ISA_ARM_6 #endif #if __ARM_ARCH >= 5 # define _ISA_ARM_5 #endif #if __ARM_ARCH >= 4 && __ARM_ARCH_ISA_THUMB >= 1 # define _ISA_ARM_4T #endif #if __ARM_ARCH >= 4 && __ARM_ARCH_ISA_THUMB == 0 # define _ISA_ARM_4 #endif #if __ARM_ARCH_ISA_THUMB >= 2 # define _ISA_THUMB_2 #endif #if __ARM_ARCH_ISA_THUMB >= 1 # define _ISA_THUMB_1 #endif /* Check whether leaf function PAC signing has been requested in the -mbranch-protect compile-time option. */ #define LEAF_PROTECT_BIT 2 #ifdef __ARM_FEATURE_PAC_DEFAULT # define HAVE_PAC_LEAF \ ((__ARM_FEATURE_PAC_DEFAULT & (1 << LEAF_PROTECT_BIT)) && 1) #else # define HAVE_PAC_LEAF 0 #endif /* Provide default parameters for PAC-code handling in leaf-functions. */ #if HAVE_PAC_LEAF # ifndef PAC_LEAF_PUSH_IP # define PAC_LEAF_PUSH_IP 1 # endif #else /* !HAVE_PAC_LEAF */ # undef PAC_LEAF_PUSH_IP # define PAC_LEAF_PUSH_IP 0 #endif /* HAVE_PAC_LEAF */ #define STACK_ALIGN_ENFORCE 0 #ifdef __ASSEMBLER__ /****************************************************************************** * Implementation of the prologue and epilogue assembler macros and their * associated helper functions. * * These functions add support for the following: * * - M-profile branch target identification (BTI) landing-pads when compiled * with `-mbranch-protection=bti'. * - PAC-signing and verification instructions, depending on hardware support * and whether the PAC-signing of leaf functions has been requested via the * `-mbranch-protection=pac-ret+leaf' compiler argument. * - 8-byte stack alignment preservation at function entry, defaulting to the * value of STACK_ALIGN_ENFORCE. * * Notes: * - Prologue stack alignment is implemented by detecting a push with an odd * number of registers and prepending a dummy register to the list. * - If alignment is attempted on a list containing r0, compilation will result * in an error. * - If alignment is attempted in a list containing r1, r0 will be prepended to * the register list and r0 will be restored prior to function return. for * functions with non-void return types, this will result in the corruption of * the result register. * - Stack alignment is enforced via the following helper macro call-chain: * * {prologue|epilogue} ->_align8 -> _preprocess_reglist -> * _preprocess_reglist1 -> {_prologue|_epilogue} * * - Debug CFI directives are automatically added to prologues and epilogues, * assisted by `cfisavelist' and `cfirestorelist', respectively. * * Arguments: * prologue * -------- * - first - If `last' specified, this serves as start of general-purpose * register (GPR) range to push onto stack, otherwise represents * single GPR to push onto stack. If omitted, no GPRs pushed * onto stack at prologue. * - last - If given, specifies inclusive upper-bound of GPR range. * - push_ip - Determines whether IP register is to be pushed to stack at * prologue. When pac-signing is requested, this holds the * the pac-key. Either 1 or 0 to push or not push, respectively. * Default behavior: Set to value of PAC_LEAF_PUSH_IP macro. * - push_lr - Determines whether to push lr to the stack on function entry. * Either 1 or 0 to push or not push, respectively. * - align8 - Whether to enforce alignment. Either 1 or 0, with 1 requesting * alignment. * * epilogue * -------- * The epilogue should be called passing the same arguments as those passed to * the prologue to ensure the stack is not corrupted on function return. * * Usage examples: * * prologue push_ip=1 -> push {ip} * epilogue push_ip=1, align8=1 -> pop {r2, ip} * prologue push_ip=1, push_lr=1 -> push {ip, lr} * epilogue 1 -> pop {r1} * prologue 1, align8=1 -> push {r0, r1} * epilogue 1, push_ip=1 -> pop {r1, ip} * prologue 1, 4 -> push {r1-r4} * epilogue 1, 4 push_ip=1 -> pop {r1-r4, ip} * ******************************************************************************/ /* Don't emit unwind or exception table entries */ .macro fnstart #ifdef __INCLUDE_EXIDX .fnstart #endif .endm .macro cantunwind #ifdef __INCLUDE_EXIDX .cantunwind #endif .endm .macro fnend #ifdef __INCLUDE_EXIDX .fnend #endif .endm /* Emit .cfi_restore directives for a consecutive sequence of registers. */ .macro cfirestorelist first, last .cfi_restore \last .if \last-\first cfirestorelist \first, \last-1 .endif .endm /* Emit .cfi_offset directives for a consecutive sequence of registers. */ .macro cfisavelist first, last, index=1 .cfi_offset \last, -4*(\index) .if \last-\first cfisavelist \first, \last-1, \index+1 .endif .endm .macro _prologue first=-1, last=-1, push_ip=PAC_LEAF_PUSH_IP, push_lr=0 .if \push_ip & 1 != \push_ip .error "push_ip may be either 0 or 1" .endif .if \push_lr & 1 != \push_lr .error "push_lr may be either 0 or 1" .endif .if \first != -1 .if \last == -1 /* Upper-bound not provided: Set upper = lower. */ _prologue \first, \first, \push_ip, \push_lr .exitm .endif .endif #if HAVE_PAC_LEAF #if __ARM_FEATURE_BTI_DEFAULT pacbti ip, lr, sp #else pac ip, lr, sp #endif /* __ARM_FEATURE_BTI_DEFAULT */ .cfi_register 143, 12 #else #if __ARM_FEATURE_BTI_DEFAULT bti #endif /* __ARM_FEATURE_BTI_DEFAULT */ #endif /* HAVE_PAC_LEAF */ .if \first != -1 .if \last != \first .if \last >= 13 .error "SP cannot be in the save list" .endif .if \push_ip .if \push_lr /* Case 1: push register range, ip and lr registers. */ push {r\first-r\last, ip, lr} .cfi_adjust_cfa_offset ((\last-\first)+3)*4 .cfi_offset 14, -4 .cfi_offset 143, -8 cfisavelist \first, \last, 3 .else // !\push_lr /* Case 2: push register range and ip register. */ push {r\first-r\last, ip} .cfi_adjust_cfa_offset ((\last-\first)+2)*4 .cfi_offset 143, -4 cfisavelist \first, \last, 2 .endif .else // !\push_ip .if \push_lr /* Case 3: push register range and lr register. */ push {r\first-r\last, lr} .cfi_adjust_cfa_offset ((\last-\first)+2)*4 .cfi_offset 14, -4 cfisavelist \first, \last, 2 .else // !\push_lr /* Case 4: push register range. */ push {r\first-r\last} .cfi_adjust_cfa_offset ((\last-\first)+1)*4 cfisavelist \first, \last, 1 .endif .endif .else // \last == \first .if \push_ip .if \push_lr /* Case 5: push single GP register plus ip and lr registers. */ push {r\first, ip, lr} .cfi_adjust_cfa_offset 12 .cfi_offset 14, -4 .cfi_offset 143, -8 cfisavelist \first, \first, 3 .else // !\push_lr /* Case 6: push single GP register plus ip register. */ push {r\first, ip} .cfi_adjust_cfa_offset 8 .cfi_offset 143, -4 cfisavelist \first, \first, 2 .endif .else // !\push_ip .if \push_lr /* Case 7: push single GP register plus lr register. */ push {r\first, lr} .cfi_adjust_cfa_offset 8 .cfi_offset 14, -4 cfisavelist \first, \first, 2 .else // !\push_lr /* Case 8: push single GP register. */ push {r\first} .cfi_adjust_cfa_offset 4 cfisavelist \first, \first, 1 .endif .endif .endif .else // \first == -1 .if \push_ip .if \push_lr /* Case 9: push ip and lr registers. */ push {ip, lr} .cfi_adjust_cfa_offset 8 .cfi_offset 14, -4 .cfi_offset 143, -8 .else // !\push_lr /* Case 10: push ip register. */ push {ip} .cfi_adjust_cfa_offset 4 .cfi_offset 143, -4 .endif .else // !\push_ip .if \push_lr /* Case 11: push lr register. */ push {lr} .cfi_adjust_cfa_offset 4 .cfi_offset 14, -4 .endif .endif .endif .endm .macro _epilogue first=-1, last=-1, push_ip=PAC_LEAF_PUSH_IP, push_lr=0 .if \push_ip & 1 != \push_ip .error "push_ip may be either 0 or 1" .endif .if \push_lr & 1 != \push_lr .error "push_lr may be either 0 or 1" .endif .if \first != -1 .if \last == -1 /* Upper-bound not provided: Set upper = lower. */ _epilogue \first, \first, \push_ip, \push_lr .exitm .endif .if \last != \first .if \last >= 13 .error "SP cannot be in the save list" .endif .if \push_ip .if \push_lr /* Case 1: pop register range, ip and lr registers. */ pop {r\first-r\last, ip, lr} .cfi_restore 14 .cfi_register 143, 12 cfirestorelist \first, \last .else // !\push_lr /* Case 2: pop register range and ip register. */ pop {r\first-r\last, ip} .cfi_register 143, 12 cfirestorelist \first, \last .endif .else // !\push_ip .if \push_lr /* Case 3: pop register range and lr register. */ pop {r\first-r\last, lr} .cfi_restore 14 cfirestorelist \first, \last .else // !\push_lr /* Case 4: pop register range. */ pop {r\first-r\last} cfirestorelist \first, \last .endif .endif .else // \last == \first .if \push_ip .if \push_lr /* Case 5: pop single GP register plus ip and lr registers. */ pop {r\first, ip, lr} .cfi_restore 14 .cfi_register 143, 12 cfirestorelist \first, \first .else // !\push_lr /* Case 6: pop single GP register plus ip register. */ pop {r\first, ip} .cfi_register 143, 12 cfirestorelist \first, \first .endif .else // !\push_ip .if \push_lr /* Case 7: pop single GP register plus lr register. */ pop {r\first, lr} .cfi_restore 14 cfirestorelist \first, \first .else // !\push_lr /* Case 8: pop single GP register. */ pop {r\first} cfirestorelist \first, \first .endif .endif .endif .else // \first == -1 .if \push_ip .if \push_lr /* Case 9: pop ip and lr registers. */ pop {ip, lr} .cfi_restore 14 .cfi_register 143, 12 .else // !\push_lr /* Case 10: pop ip register. */ pop {ip} .cfi_register 143, 12 .endif .else // !\push_ip .if \push_lr /* Case 11: pop lr register. */ pop {lr} .cfi_restore 14 .endif .endif .endif #if HAVE_PAC_LEAF aut ip, lr, sp #endif /* HAVE_PAC_LEAF */ bx lr .endm # clean up expressions in 'last' .macro _preprocess_reglist1 first:req, last:req, push_ip:req, push_lr:req, reglist_op:req .if \last == 0 \reglist_op \first, 0, \push_ip, \push_lr .elseif \last == 1 \reglist_op \first, 1, \push_ip, \push_lr .elseif \last == 2 \reglist_op \first, 2, \push_ip, \push_lr .elseif \last == 3 \reglist_op \first, 3, \push_ip, \push_lr .elseif \last == 4 \reglist_op \first, 4, \push_ip, \push_lr .elseif \last == 5 \reglist_op \first, 5, \push_ip, \push_lr .elseif \last == 6 \reglist_op \first, 6, \push_ip, \push_lr .elseif \last == 7 \reglist_op \first, 7, \push_ip, \push_lr .elseif \last == 8 \reglist_op \first, 8, \push_ip, \push_lr .elseif \last == 9 \reglist_op \first, 9, \push_ip, \push_lr .elseif \last == 10 \reglist_op \first, 10, \push_ip, \push_lr .elseif \last == 11 \reglist_op \first, 11, \push_ip, \push_lr .else .error "last (\last) out of range" .endif .endm # clean up expressions in 'first' .macro _preprocess_reglist first:req, last, push_ip=0, push_lr=0, reglist_op:req .ifb \last _preprocess_reglist \first \first \push_ip \push_lr .else .if \first > \last .error "last (\last) must be at least as great as first (\first)" .endif .if \first == 0 _preprocess_reglist1 0, \last, \push_ip, \push_lr, \reglist_op .elseif \first == 1 _preprocess_reglist1 1, \last, \push_ip, \push_lr, \reglist_op .elseif \first == 2 _preprocess_reglist1 2, \last, \push_ip, \push_lr, \reglist_op .elseif \first == 3 _preprocess_reglist1 3, \last, \push_ip, \push_lr, \reglist_op .elseif \first == 4 _preprocess_reglist1 4, \last, \push_ip, \push_lr, \reglist_op .elseif \first == 5 _preprocess_reglist1 5, \last, \push_ip, \push_lr, \reglist_op .elseif \first == 6 _preprocess_reglist1 6, \last, \push_ip, \push_lr, \reglist_op .elseif \first == 7 _preprocess_reglist1 7, \last, \push_ip, \push_lr, \reglist_op .elseif \first == 8 _preprocess_reglist1 8, \last, \push_ip, \push_lr, \reglist_op .elseif \first == 9 _preprocess_reglist1 9, \last, \push_ip, \push_lr, \reglist_op .elseif \first == 10 _preprocess_reglist1 10, \last, \push_ip, \push_lr, \reglist_op .elseif \first == 11 _preprocess_reglist1 11, \last, \push_ip, \push_lr, \reglist_op .else .error "first (\first) out of range" .endif .endif .endm .macro _align8 first, last, push_ip=0, push_lr=0, reglist_op=_prologue .ifb \first .ifnb \last .error "can't have last (\last) without specifying first" .else // \last not blank .if ((\push_ip + \push_lr) % 2) == 0 \reglist_op first=-1, last=-1, push_ip=\push_ip, push_lr=\push_lr .exitm .else // ((\push_ip + \push_lr) % 2) odd _align8 2, 2, \push_ip, \push_lr, \reglist_op .exitm .endif // ((\push_ip + \push_lr) % 2) == 0 .endif // .ifnb \last .endif // .ifb \first .ifb \last _align8 \first, \first, \push_ip, \push_lr, \reglist_op .else .if \push_ip & 1 <> \push_ip .error "push_ip may be 0 or 1" .endif .if \push_lr & 1 <> \push_lr .error "push_lr may be 0 or 1" .endif .ifeq (\last - \first + \push_ip + \push_lr) % 2 .if \first == 0 .error "Alignment required and first register is r0" .exitm .endif _preprocess_reglist \first-1, \last, \push_ip, \push_lr, \reglist_op .else _preprocess_reglist \first \last, \push_ip, \push_lr, \reglist_op .endif .endif .endm .macro prologue first, last, push_ip=PAC_LEAF_PUSH_IP, push_lr=0, align8=STACK_ALIGN_ENFORCE .if \align8 _align8 \first, \last, \push_ip, \push_lr, _prologue .else _prologue first=\first, last=\last, push_ip=\push_ip, push_lr=\push_lr .endif .endm .macro epilogue first, last, push_ip=PAC_LEAF_PUSH_IP, push_lr=0, align8=STACK_ALIGN_ENFORCE .if \align8 _align8 \first, \last, \push_ip, \push_lr, reglist_op=_epilogue .else _epilogue first=\first, last=\last, push_ip=\push_ip, push_lr=\push_lr .endif .endm .macro ASM_ALIAS_THUMB_STATE new old .global \new .type \new, %function .thumb_set \new, \old .endm .macro ASM_ALIAS_ARM_STATE new old .global \new .type \new, %function .set \new, \old .endm #endif /* __ASSEMBLER__ */ #endif /* ARM_ASM__H */ picolibc-1.8.11/libc/machine/arm/arm_tls.h000066400000000000000000000042511513574234600203100ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #if ((__ARM_FEATURE_COPROC & 1) || __ARM_ARCH >= 8) && __ARM_ARCH_PROFILE != 'M' && __ARM_ARCH >= 6 #define ARM_TLS_CP15 #endif /* Switch cortex-m0 to use RP2040 CPUID register if requested */ #ifdef __THREAD_LOCAL_STORAGE_RP2040 #define ARM_RP2040 #endif #ifdef ARM_RP2040 #define RP2040_SIO_BASE 0xd0000000 #define RP2040_CPUID (RP2040_SIO_BASE + 0) #define ARM_TLS_COUNT 2 #else #define ARM_TLS_COUNT 1 #endif #ifndef _IN_ASM /* This needs to be global so that __aeabi_read_tp can * refer to it in an asm statement */ #ifndef ARM_TLS_CP15 extern void *__tls[ARM_TLS_COUNT]; #endif #endif picolibc-1.8.11/libc/machine/arm/bzero.c000066400000000000000000000033051513574234600177620ustar00rootroot00000000000000/* * Copyright (c) 2015 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "../../string/bzero.c" /* Support the alias for the __aeabi_memclr which may assume memory alignment. */ __weak_reference(bzero, __aeabi_memclr4); __weak_reference(bzero, __aeabi_memclr8); __weak_reference(bzero, __aeabi_memclr); picolibc-1.8.11/libc/machine/arm/interrupt.c000066400000000000000000000107231513574234600206770ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if __ARM_ARCH_PROFILE == 'M' #define STRINGIFY(x) #x /* Interrupt functions */ void arm_halt_isr(void); void __disable_sanitizer arm_halt_isr(void) { for (;;) ; } void arm_ignore_isr(void); void __disable_sanitizer arm_ignore_isr(void) { } #define isr(name) void arm_##name##_isr(void) __attribute__((weak, alias("arm_ignore_isr"))); #define isr_halt(name) void arm_##name##_isr(void) __attribute__((weak, alias("arm_halt_isr"))); isr(nmi); isr_halt(hardfault); isr_halt(memmanage); isr_halt(busfault); isr_halt(usagefault); isr(svc); isr(debugmon); isr(pendsv); isr(systick); void _start(void); extern uint8_t __stack[]; #define i(addr, name) [(addr) / 4] = (void (*)(void))arm_##name##_isr __section(".data.init.enter") void (* const __weak_interrupt_vector[])(void) __attribute((aligned(128))) = { [0] = (void (*)(void))__stack, [1] = _start, i(0x08, nmi), i(0x0c, hardfault), i(0x10, memmanage), i(0x14, busfault), i(0x18, usagefault), i(0x2c, svc), i(0x30, debugmon), i(0x38, pendsv), i(0x3c, systick), }; __weak_reference(__weak_interrupt_vector, __interrupt_vector); #else void arm_halt_vector(void); void __naked __disable_sanitizer arm_halt_vector(void) { /* Loop forever. */ __asm__("1: b 1b"); } void arm_ignore_vector(void); void __naked __disable_sanitizer arm_ignore_vector(void) { /* Ignore the interrupt by returning */ __asm__("bx lr"); } #define vector(name) __weak_reference(arm_ignore_vector, arm_##name##_vector) #define vector_halt(name) __weak_reference(arm_halt_vector, arm_##name##_vector) vector_halt(undef); vector_halt(svc); vector_halt(prefetch_abort); vector_halt(data_abort); vector(not_used); vector(irq); vector(fiq); void __weak_vector_table(void); void __naked __section(".text.init.enter") __disable_sanitizer __weak_vector_table(void) { /* * Exception vector that lives at the * start of program text (usually 0x0) */ #ifdef __thumb2__ /* Thumb 2 processors start in thumb mode */ __asm__(".thumb\n" ".syntax unified\n" "b.w _start\n" "b.w arm_undef_vector\n" "b.w arm_svc_vector\n" "b.w arm_prefetch_abort_vector\n" "b.w arm_data_abort_vector\n" "b.w arm_not_used_vector\n" "b.w arm_irq_vector\n" "b.w arm_fiq_vector"); #else /* Thumb 1 and arm processors start in arm mode */ __asm__(".arm\n" "b _start\n" "b arm_undef_vector\n" "b arm_svc_vector\n" "b arm_prefetch_abort_vector\n" "b arm_data_abort_vector\n" "b arm_not_used_vector\n" "b arm_irq_vector\n" "b arm_fiq_vector"); #endif } __weak_reference(__weak_vector_table, __vector_table); #endif picolibc-1.8.11/libc/machine/arm/machine/000077500000000000000000000000001513574234600201005ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/arm/machine/CMakeLists.txt000066400000000000000000000032151513574234600226410ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_headers(machine acle-compat.h _endian.h fenv.h fenv-fp.h math.h param.h ) picolibc-1.8.11/libc/machine/arm/machine/_endian.h000066400000000000000000000033631513574234600216530ustar00rootroot00000000000000/* ARM configuration file. Copyright (c) 2015 ARM Ltd. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the company may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __MACHINE_ENDIAN_H__ #error "must be included via " #endif /* !__MACHINE_ENDIAN_H__ */ #define _LITTLE_ENDIAN 1234 #define _BIG_ENDIAN 4321 #define _PDP_ENDIAN 3412 #ifdef __ARMEB__ #define _BYTE_ORDER _BIG_ENDIAN #else #define _BYTE_ORDER _LITTLE_ENDIAN #endif picolibc-1.8.11/libc/machine/arm/machine/acle-compat.h000066400000000000000000000123201513574234600224340ustar00rootroot00000000000000/* * Copyright (c) 2014 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __ARM_ARCH /* ACLE standardises a set of pre-defines that describe the ARM architecture. These were mostly implemented in GCC around GCC-4.8; older versions have no, or only partial support. To provide a level of backwards compatibility we try to work out what the definitions should be, given the older pre-defines that GCC did produce. This isn't complete, but it should be enough for use by routines that depend on this header. */ /* No need to handle ARMv8, GCC had ACLE support before that. */ #ifdef __ARM_ARCH_7__ /* The common subset of ARMv7 in all profiles. */ #define __ARM_ARCH 7 #define __ARM_ARCH_ISA_THUMB 2 #define __ARM_FEATURE_CLZ #define __ARM_FEATURE_LDREX 7 #define __ARM_FEATURE_UNALIGNED #endif #if defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) #define __ARM_ARCH 7 #define __ARM_ARCH_ISA_THUMB 2 #define __ARM_ARCH_ISA_ARM #define __ARM_FEATURE_CLZ #define __ARM_FEATURE_SIMD32 #define __ARM_FEATURE_DSP #define __ARM_FEATURE_QBIT #define __ARM_FEATURE_SAT #define __ARM_FEATURE_LDREX 15 #define __ARM_FEATURE_UNALIGNED #ifdef __ARM_ARCH_7A__ #define __ARM_ARCH_PROFILE 'A' #else #define __ARM_ARCH_PROFILE 'R' #endif #endif #ifdef __ARM_ARCH_7EM__ #define __ARM_ARCH 7 #define __ARM_ARCH_ISA_THUMB 2 #define __ARM_FEATURE_CLZ #define __ARM_FEATURE_SIMD32 #define __ARM_FEATURE_DSP #define __ARM_FEATURE_QBIT #define __ARM_FEATURE_SAT #define __ARM_FEATURE_LDREX 7 #define __ARM_FEATURE_UNALIGNED #define __ARM_ARCH_PROFILE 'M' #endif #ifdef __ARM_ARCH_7M__ #define __ARM_ARCH 7 #define __ARM_ARCH_ISA_THUMB 2 #define __ARM_FEATURE_CLZ #define __ARM_FEATURE_QBIT #define __ARM_FEATURE_SAT #define __ARM_FEATURE_LDREX 7 #define __ARM_FEATURE_UNALIGNED #define __ARM_ARCH_PROFILE 'M' #endif #ifdef __ARM_ARCH_6T2__ #define __ARM_ARCH 6 #define __ARM_ARCH_ISA_THUMB 2 #define __ARM_ARCH_ISA_ARM #define __ARM_FEATURE_CLZ #define __ARM_FEATURE_SIMD32 #define __ARM_FEATURE_DSP #define __ARM_FEATURE_QBIT #define __ARM_FEATURE_SAT #define __ARM_FEATURE_LDREX 4 #define __ARM_FEATURE_UNALIGNED #endif #ifdef __ARM_ARCH_6M__ #define __ARM_ARCH 6 #define __ARM_ARCH_ISA_THUMB 1 #define __ARM_ARCH_PROFILE 'M' #endif #if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) \ || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) #define __ARM_ARCH 6 #define __ARM_ARCH_ISA_THUMB 1 #define __ARM_ARCH_ISA_ARM #define __ARM_FEATURE_CLZ #define __ARM_FEATURE_SIMD32 #define __ARM_FEATURE_DSP #define __ARM_FEATURE_QBIT #define __ARM_FEATURE_SAT #define __ARM_FEATURE_UNALIGNED #ifndef __thumb__ #if defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) #define __ARM_FEATURE_LDREX 15 #else #define __ARM_FEATURE_LDREX 4 #endif #endif #endif #if defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5E__) #define __ARM_ARCH 5 #define __ARM_ARCH_ISA_ARM #ifdef __ARM_ARCH_5TE__ #define __ARM_ARCH_ISA_THUMB 1 #endif #define __ARM_FEATURE_CLZ #define __ARM_FEATURE_DSP #endif #if defined(__ARM_ARCH_5T__) || defined(__ARM_ARCH_5__) #define __ARM_ARCH 5 #define __ARM_ARCH_ISA_ARM #ifdef __ARM_ARCH_5TE__ #define __ARM_ARCH_ISA_THUMB 1 #endif #define __ARM_FEATURE_CLZ #endif #ifdef __ARM_ARCH_4T__ #define __ARM_ARCH 4 #define __ARM_ARCH_ISA_ARM #define __ARM_ARCH_ISA_THUMB 1 #endif #ifdef __ARM_ARCH_4__ #define __ARM_ARCH 4 #define __ARM_ARCH_ISA_ARM #endif #if defined(__ARM_ARCH_3__) || defined(__ARM_ARCH_3M__) #define __ARM_ARCH 3 #define __ARM_ARCH_ISA_ARM #endif #ifdef __ARM_ARCH_2__ #define __ARM_ARCH 2 #define __ARM_ARCH_ISA_ARM #endif #ifdef __ARMEB__ #define __ARM_BIG_ENDIAN #endif /* If we still don't know what the target architecture is, then we're probably not using GCC. */ #ifndef __ARM_ARCH #error Unable to determine architecture version. #endif #endif /* __ARM_ARCH */ picolibc-1.8.11/libc/machine/arm/machine/fenv-fp.h000066400000000000000000000110261513574234600216120ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2023 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _vmrs_fpscr(__r) __asm__ __volatile__("vmrs %0, fpscr" : "=&r"(__r)) #define _vmsr_fpscr(__r) __asm__ __volatile__("vmsr fpscr, %0" : : "r"(__r)) #define _FPU_MASK_SHIFT 8 #define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO) __declare_fenv_inline(int) feclearexcept(int excepts) { fexcept_t __fpsr; _vmrs_fpscr(__fpsr); __fpsr &= ~excepts; _vmsr_fpscr(__fpsr); return (0); } __declare_fenv_inline(int) fedisableexcept(int __mask) { fenv_t __old_fpsr, __new_fpsr; _vmrs_fpscr(__old_fpsr); __new_fpsr = __old_fpsr & ~((__mask & FE_ALL_EXCEPT) << _FPU_MASK_SHIFT); _vmsr_fpscr(__new_fpsr); return ((__old_fpsr >> _FPU_MASK_SHIFT) & FE_ALL_EXCEPT); } __declare_fenv_inline(int) feenableexcept(int __mask) { fenv_t __old_fpsr, __new_fpsr, __check_fpsr; _vmrs_fpscr(__old_fpsr); __new_fpsr = __old_fpsr | ((__mask & FE_ALL_EXCEPT) << _FPU_MASK_SHIFT); _vmsr_fpscr(__new_fpsr); _vmrs_fpscr(__check_fpsr); if (__check_fpsr != __new_fpsr) return -1; return ((__old_fpsr >> _FPU_MASK_SHIFT) & FE_ALL_EXCEPT); } __declare_fenv_inline(int) fegetenv(fenv_t *envp) { _vmrs_fpscr(*envp); return (0); } __declare_fenv_inline(int) fegetexcept(void) { fenv_t __fpsr; _vmrs_fpscr(__fpsr); return (__fpsr & FE_ALL_EXCEPT); } __declare_fenv_inline(int) fegetexceptflag(fexcept_t *flagp, int excepts) { fexcept_t __fpsr; _vmrs_fpscr(__fpsr); *flagp = __fpsr & excepts; return (0); } __declare_fenv_inline(int) fegetround(void) { fenv_t __fpsr; _vmrs_fpscr(__fpsr); return (__fpsr & _ROUND_MASK); } __declare_fenv_inline(int) feholdexcept(fenv_t *envp) { fenv_t __env; _vmrs_fpscr(__env); *envp = __env; __env &= ~(FE_ALL_EXCEPT); _vmsr_fpscr(__env); return (0); } __declare_fenv_inline(int) fesetenv(const fenv_t *envp) { _vmsr_fpscr(*envp); return (0); } __declare_fenv_inline(int) fesetexceptflag(const fexcept_t *flagp, int excepts) { fexcept_t __fpsr; _vmrs_fpscr(__fpsr); __fpsr &= ~excepts; __fpsr |= *flagp & excepts; _vmsr_fpscr(__fpsr); return (0); } __declare_fenv_inline(int) feraiseexcept(int excepts) { fexcept_t __ex = excepts; return fesetexceptflag(&__ex, excepts); } __declare_fenv_inline(int) fesetexcept(int excepts) { return feraiseexcept(excepts); } __declare_fenv_inline(int) fesetround(int round) { fenv_t __fpsr; /* Check for invalid rounding modes */ if (round & ~(_ROUND_MASK)) return 1; _vmrs_fpscr(__fpsr); __fpsr &= ~(_ROUND_MASK); __fpsr |= round; _vmsr_fpscr(__fpsr); return (0); } __declare_fenv_inline(int) fetestexcept(int excepts) { fexcept_t __fpsr; _vmrs_fpscr(__fpsr); return (__fpsr & excepts); } __declare_fenv_inline(int) feupdateenv(const fenv_t *envp) { fexcept_t __fpsr; _vmrs_fpscr(__fpsr); _vmsr_fpscr(*envp); feraiseexcept(__fpsr & FE_ALL_EXCEPT); return (0); } picolibc-1.8.11/libc/machine/arm/machine/fenv.h000066400000000000000000000051521513574234600212120ustar00rootroot00000000000000/*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2004-2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _MACHINE_FENV_H_ #define _MACHINE_FENV_H_ 1 _BEGIN_STD_C typedef int fenv_t; typedef int fexcept_t; #if (__ARM_FP & 0x8) == 0 #define __DOUBLE_NOROUND #define __DOUBLE_NOEXCEPT #define __LONG_DOUBLE_NOEXCEPT #endif #if (__ARM_FP & 0x4) == 0 #define __FLOAT_NOROUND #define __FLOAT_NOEXCEPT #endif #if __ARM_FP != 0 /* Exception flags */ #define FE_INVALID 0x0001 #define FE_DIVBYZERO 0x0002 #define FE_OVERFLOW 0x0004 #define FE_UNDERFLOW 0x0008 #define FE_INEXACT 0x0010 #define FE_DENORMAL 0x0080 #define FE_ALL_EXCEPT \ (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW | FE_DENORMAL) /* Rounding modes */ #define FE_TONEAREST 0x00000000 #define FE_UPWARD 0x00400000 #define FE_DOWNWARD 0x00800000 #define FE_TOWARDZERO 0x00c00000 #else #define FE_TONEAREST 0x00000000 #endif #if !defined(__declare_fenv_inline) && defined(__declare_extern_inline) #define __declare_fenv_inline(type) __declare_extern_inline(type) #endif _END_STD_C #ifdef __declare_fenv_inline #if __ARM_FP == 0 #include #else #include #endif #endif #endif /* _MACHINE_FENV_H_ */ picolibc-1.8.11/libc/machine/arm/machine/math.h000066400000000000000000000136031513574234600212050ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * Copyright (c) 2017 embedded brains GmbH. All rights reserved Copyright (c) 2011, 2012 ARM Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MACHINE_MATH_H_ #define _MACHINE_MATH_H_ #if (__ARM_FEATURE_FMA && (__ARM_FP & 8)) #define __HAVE_FAST_FMA 1 #endif #if (__ARM_FEATURE_FMA && (__ARM_FP & 4)) #define __HAVE_FAST_FMAF 1 #endif #ifdef __declare_extern_inline #ifdef __MATH_ERRNO #include #endif #if (__ARM_FP & 0x8) /* * Double precision routines */ __declare_extern_inline(double) sqrt(double x) { double result; #ifdef __MATH_ERRNO if (isless(x, 0.0)) errno = EDOM; #endif #if __ARM_ARCH >= 6 __asm__ volatile("vsqrt.f64 %P0, %P1" : "=w"(result) : "w"(x)); #else /* VFP9 Erratum 760019, see GCC sources "gcc/config/arm/vfp.md" */ __asm__ volatile("vsqrt.f64 %P0, %P1" : "=&w"(result) : "w"(x)); #endif return result; } __declare_extern_inline(double) fabs(double x) { double result; __asm__("vabs.f64\t%P0, %P1" : "=w"(result) : "w"(x)); return result; } #if __ARM_ARCH >= 8 __declare_extern_inline(double) ceil(double x) { double result; __asm__ volatile("vrintp.f64\t%P0, %P1" : "=w"(result) : "w"(x)); return result; } __declare_extern_inline(double) floor(double x) { double result; __asm__ volatile("vrintm.f64\t%P0, %P1" : "=w"(result) : "w"(x)); return result; } __declare_extern_inline(double) nearbyint(double x) { if (isnan(x)) return x + x; #if defined(FE_INEXACT) fenv_t env; fegetenv(&env); #endif __asm__ volatile("vrintr.f64\t%P0, %P1" : "=w"(x) : "w"(x)); #if defined(FE_INEXACT) fesetenv(&env); #endif return x; } __declare_extern_inline(double) rint(double x) { double result; __asm__ volatile("vrintx.f64\t%P0, %P1" : "=w"(result) : "w"(x)); return result; } __declare_extern_inline(double) round(double x) { double result; __asm__ volatile("vrinta.f64\t%P0, %P1" : "=w"(result) : "w"(x)); return result; } __declare_extern_inline(double) trunc(double x) { double result; __asm__ volatile("vrintz.f64\t%P0, %P1" : "=w"(result) : "w"(x)); return result; } #endif /* __ARM_ARCH >= 8 */ #if __HAVE_FAST_FMA __declare_extern_inline(double) fma(double x, double y, double z) { __asm__ volatile("vfma.f64 %P0, %P1, %P2" : "+w"(z) : "w"(x), "w"(y)); return z; } #endif #endif /* (__ARM_FP & 0x8) */ #if (__ARM_FP & 0x4) /* * Single precision functions */ __declare_extern_inline(float) sqrtf(float x) { float result; #ifdef __MATH_ERRNO if (isless(x, 0.0f)) errno = EDOM; #endif #if __ARM_ARCH >= 6 __asm__ volatile("vsqrt.f32 %0, %1" : "=w"(result) : "w"(x)); #else /* VFP9 Erratum 760019, see GCC sources "gcc/config/arm/vfp.md" */ __asm__ volatile("vsqrt.f32 %0, %1" : "=&w"(result) : "w"(x) : "cc", "memory"); #endif return result; } __declare_extern_inline(float) fabsf(float x) { float result; __asm__("vabs.f32\t%0, %1" : "=t"(result) : "t"(x)); return result; } #if __ARM_ARCH >= 8 __declare_extern_inline(float) ceilf(float x) { float result; __asm__ volatile("vrintp.f32\t%0, %1" : "=t"(result) : "t"(x)); return result; } __declare_extern_inline(float) floorf(float x) { float result; __asm__ volatile("vrintm.f32\t%0, %1" : "=t"(result) : "t"(x)); return result; } __declare_extern_inline(float) nearbyintf(float x) { if (isnan(x)) return x + x; #if defined(FE_INEXACT) fenv_t env; fegetenv(&env); #endif __asm__ volatile("vrintr.f32\t%0, %1" : "=t"(x) : "t"(x)); #if defined(FE_INEXACT) fesetenv(&env); #endif return x; } __declare_extern_inline(float) rintf(float x) { float result; __asm__ volatile("vrintx.f32\t%0, %1" : "=t"(result) : "t"(x)); return result; } __declare_extern_inline(float) roundf(float x) { float result; __asm__ volatile("vrinta.f32\t%0, %1" : "=t"(result) : "t"(x)); return result; } __declare_extern_inline(float) truncf(float x) { float result; __asm__ volatile("vrintz.f32\t%0, %1" : "=t"(result) : "t"(x)); return result; } #endif /* __ARM_ARCH >= 8 */ #if __HAVE_FAST_FMAF __declare_extern_inline(float) fmaf(float x, float y, float z) { __asm__ volatile("vfma.f32 %0, %1, %2" : "+t"(z) : "t"(x), "t"(y)); return z; } #endif #endif /* (__ARM_FP & 0x4) */ #endif /* have attributes */ #endif /* _MACHINE_MATH_H_ */ picolibc-1.8.11/libc/machine/arm/machine/meson.build000066400000000000000000000034441513574234600222470ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2020 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_machine_headers_machine = [ 'acle-compat.h', '_endian.h', 'fenv.h', 'fenv-fp.h', 'math.h', 'param.h', ] if really_install install_headers(inc_machine_headers_machine, install_dir: include_dir / 'machine') endif picolibc-1.8.11/libc/machine/arm/machine/param.h000066400000000000000000000003161513574234600213510ustar00rootroot00000000000000/* Copyright (c) 2004 Jeff Johnston */ /* ARM configuration file; HZ is 100 rather than the default 60 */ #ifndef _MACHINE_PARAM_H #define _MACHINE_PARAM_H #define HZ (100) #endif picolibc-1.8.11/libc/machine/arm/memchr.S000066400000000000000000000307141513574234600201000ustar00rootroot00000000000000/* Copyright (c) 2010-2011, Linaro Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Linaro Limited nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Written by Dave Gilbert This memchr routine is optimised on a Cortex-A9 and should work on all ARMv7 processors. It has a fast path for short sizes, and has an optimised path for large data sets; the worst case is finding the match early in a large data set. */ /* Copyright (c) 2015 ARM Ltd. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ // 2011-02-07 david.gilbert@linaro.org // Extracted from local git a5b438d861 // 2011-07-14 david.gilbert@linaro.org // Import endianness fix from local git ea786f1b // 2011-10-11 david.gilbert@linaro.org // Import from cortex-strings bzr rev 63 // Flip to ldrd (as suggested by Greta Yorsh) // Make conditional on CPU type // tidy // This code requires armv6t2 or later. Uses Thumb2. #include .syntax unified #include "arm_asm.h" // NOTE: This ifdef MUST match the one in memchr-stub.c #if defined (__ARM_NEON__) || defined (__ARM_NEON) #if __ARM_ARCH >= 8 && __ARM_ARCH_PROFILE == 'R' .arch armv8-r #else .arch armv7-a #endif .fpu neon /* Arguments */ #define srcin r0 #define chrin r1 #define cntin r2 /* Retval */ #define result r0 /* Live range does not overlap with srcin */ /* Working registers */ #define src r1 /* Live range does not overlap with chrin */ #define tmp r3 #define synd r0 /* No overlap with srcin or result */ #define soff r12 /* Working NEON registers */ #define vrepchr q0 #define vdata0 q1 #define vdata0_0 d2 /* Lower half of vdata0 */ #define vdata0_1 d3 /* Upper half of vdata0 */ #define vdata1 q2 #define vdata1_0 d4 /* Lower half of vhas_chr0 */ #define vdata1_1 d5 /* Upper half of vhas_chr0 */ #define vrepmask q3 #define vrepmask0 d6 #define vrepmask1 d7 #define vend q4 #define vend0 d8 #define vend1 d9 /* * Core algorithm: * * For each 32-byte chunk we calculate a 32-bit syndrome value, with one bit per * byte. Each bit is set if the relevant byte matched the requested character * and cleared otherwise. Since the bits in the syndrome reflect exactly the * order in which things occur in the original string, counting trailing zeros * allows to identify exactly which byte has matched. */ .text .thumb_func .align 4 .p2align 4,,15 .global memchr .type memchr,%function memchr: .cfi_sections .debug_frame .cfi_startproc /* Use a simple loop if there are less than 8 bytes to search. */ cmp cntin, #7 bhi .Llargestr and chrin, chrin, #0xff .Lsmallstr: subs cntin, cntin, #1 blo .Lnotfound /* Return not found if reached end. */ ldrb tmp, [srcin], #1 cmp tmp, chrin bne .Lsmallstr /* Loop again if not found. */ /* Otherwise fixup address and return. */ sub result, result, #1 bx lr .Llargestr: vdup.8 vrepchr, chrin /* Duplicate char across all lanes. */ /* * Magic constant 0x8040201008040201 allows us to identify which lane * matches the requested byte. */ movw tmp, #0x0201 movt tmp, #0x0804 lsl soff, tmp, #4 vmov vrepmask0, tmp, soff vmov vrepmask1, tmp, soff /* Work with aligned 32-byte chunks */ bic src, srcin, #31 ands soff, srcin, #31 beq .Lloopintro /* Go straight to main loop if it's aligned. */ /* * Input string is not 32-byte aligned. We calculate the syndrome * value for the aligned 32 bytes block containing the first bytes * and mask the irrelevant part. */ vld1.8 {vdata0, vdata1}, [src:256]! sub tmp, soff, #32 adds cntin, cntin, tmp vceq.i8 vdata0, vdata0, vrepchr vceq.i8 vdata1, vdata1, vrepchr vand vdata0, vdata0, vrepmask vand vdata1, vdata1, vrepmask vpadd.i8 vdata0_0, vdata0_0, vdata0_1 vpadd.i8 vdata1_0, vdata1_0, vdata1_1 vpadd.i8 vdata0_0, vdata0_0, vdata1_0 vpadd.i8 vdata0_0, vdata0_0, vdata0_0 vmov synd, vdata0_0[0] /* Clear the soff lower bits */ lsr synd, synd, soff lsl synd, synd, soff /* The first block can also be the last */ bls .Lmasklast /* Have we found something already? */ cbnz synd, .Ltail .Lloopintro: vpush {vend} /* 264/265 correspond to d8/d9 for q4 */ .cfi_adjust_cfa_offset 16 .cfi_rel_offset 264, 0 .cfi_rel_offset 265, 8 .p2align 3,,7 .Lloop: vld1.8 {vdata0, vdata1}, [src:256]! subs cntin, cntin, #32 vceq.i8 vdata0, vdata0, vrepchr vceq.i8 vdata1, vdata1, vrepchr /* If we're out of data we finish regardless of the result. */ bls .Lend /* Use a fast check for the termination condition. */ vorr vend, vdata0, vdata1 vorr vend0, vend0, vend1 vmov synd, tmp, vend0 orrs synd, synd, tmp /* We're not out of data, loop if we haven't found the character. */ beq .Lloop .Lend: vpop {vend} .cfi_adjust_cfa_offset -16 .cfi_restore 264 .cfi_restore 265 /* Termination condition found, let's calculate the syndrome value. */ vand vdata0, vdata0, vrepmask vand vdata1, vdata1, vrepmask vpadd.i8 vdata0_0, vdata0_0, vdata0_1 vpadd.i8 vdata1_0, vdata1_0, vdata1_1 vpadd.i8 vdata0_0, vdata0_0, vdata1_0 vpadd.i8 vdata0_0, vdata0_0, vdata0_0 vmov synd, vdata0_0[0] cbz synd, .Lnotfound bhi .Ltail .Lmasklast: /* Clear the (-cntin) upper bits to avoid out-of-bounds matches. */ neg cntin, cntin lsl synd, synd, cntin lsrs synd, synd, cntin it eq moveq src, #0 /* If no match, set src to 0 so the retval is 0. */ .Ltail: /* Count the trailing zeros using bit reversing */ rbit synd, synd /* Compensate the last post-increment */ sub src, src, #32 /* Count the leading zeros */ clz synd, synd /* Compute the potential result and return */ add result, src, synd bx lr .Lnotfound: /* Set result to NULL if not found and return */ mov result, #0 bx lr .cfi_endproc .size memchr, . - memchr #elif __ARM_ARCH_ISA_THUMB >= 2 && defined (__ARM_FEATURE_DSP) #if __ARM_ARCH_PROFILE == 'M' #if __ARM_ARCH >= 8 /* keep config inherited from -march=. */ #else .arch armv7e-m #endif /* __ARM_ARCH >= 8 */ #else .arch armv6t2 #endif /* __ARM_ARCH_PROFILE == 'M' */ // this lets us check a flag in a 00/ff byte easily in either endianness #ifdef __ARMEB__ #define CHARTSTMASK(c) 1<<(31-(c*8)) #else #define CHARTSTMASK(c) 1<<(c*8) #endif .text .thumb // --------------------------------------------------------------------------- .thumb_func .align 2 .p2align 4,,15 .global memchr .type memchr,%function fnstart .cfi_sections .debug_frame .cfi_startproc memchr: // r0 = start of memory to scan // r1 = character to look for // r2 = length // returns r0 = pointer to character or NULL if not found prologue and r1,r1,#0xff // Don't trust the caller to pass a char cmp r2,#16 // If short don't bother with anything clever blt 20f tst r0, #7 // If it's already aligned skip the next bit beq 10f // Work up to an aligned point 5: ldrb r3, [r0],#1 subs r2, r2, #1 cmp r3, r1 beq 50f // If it matches exit found tst r0, #7 cbz r2, 40f // If we run off the end, exit not found bne 5b // If not aligned yet then do next byte 10: // We are aligned, we know we have at least 8 bytes to work with push {r4,r5,r6,r7} .cfi_adjust_cfa_offset 16 .cfi_rel_offset 4, 0 .cfi_rel_offset 5, 4 .cfi_rel_offset 6, 8 .cfi_rel_offset 7, 12 orr r1, r1, r1, lsl #8 // expand the match word across all bytes orr r1, r1, r1, lsl #16 bic r4, r2, #7 // Number of double words to work with * 8 mvns r7, #0 // all F's movs r3, #0 15: ldrd r5,r6,[r0],#8 subs r4, r4, #8 eor r5,r5, r1 // r5,r6 have 00's where bytes match the target eor r6,r6, r1 uadd8 r5, r5, r7 // Par add 0xff - sets GE bits for bytes!=0 sel r5, r3, r7 // bytes are 00 for none-00 bytes, // or ff for 00 bytes - NOTE INVERSION uadd8 r6, r6, r7 // Par add 0xff - sets GE bits for bytes!=0 sel r6, r5, r7 // chained....bytes are 00 for none-00 bytes // or ff for 00 bytes - NOTE INVERSION cbnz r6, 60f bne 15b // (Flags from the subs above) pop {r4,r5,r6,r7} .cfi_restore 7 .cfi_restore 6 .cfi_restore 5 .cfi_restore 4 .cfi_adjust_cfa_offset -16 and r1,r1,#0xff // r1 back to a single character and r2,r2,#7 // Leave the count remaining as the number // after the double words have been done 20: cbz r2, 40f // 0 length or hit the end already then not found 21: // Post aligned section, or just a short call ldrb r3,[r0],#1 subs r2,r2,#1 eor r3,r3,r1 // r3 = 0 if match - doesn't break flags from sub cbz r3, 50f bne 21b // on r2 flags 40: .cfi_remember_state movs r0,#0 // not found epilogue 50: .cfi_restore_state .cfi_remember_state subs r0,r0,#1 // found epilogue 60: // We're here because the fast path found a hit // now we have to track down exactly which word it was // r0 points to the start of the double word after the one tested // r5 has the 00/ff pattern for the first word, r6 has the chained value // This point is reached from cbnz midway through label 15 prior to // popping r4-r7 off the stack. .cfi_restore_state alone disregards // this, so we manually correct this. .cfi_restore_state // Standard post-prologue state .cfi_adjust_cfa_offset 16 .cfi_rel_offset 4, 0 .cfi_rel_offset 5, 4 .cfi_rel_offset 6, 8 .cfi_rel_offset 7, 12 cmp r5, #0 itte eq moveq r5, r6 // the end is in the 2nd word subeq r0,r0,#3 // Points to 2nd byte of 2nd word subne r0,r0,#7 // or 2nd byte of 1st word // r0 currently points to the 2nd byte of the word containing the hit tst r5, # CHARTSTMASK(0) // 1st character bne 61f adds r0,r0,#1 tst r5, # CHARTSTMASK(1) // 2nd character ittt eq addeq r0,r0,#1 tsteq r5, # (3<<15) // 2nd & 3rd character // If not the 3rd must be the last one addeq r0,r0,#1 61: pop {r4,r5,r6,r7} .cfi_restore 7 .cfi_restore 6 .cfi_restore 5 .cfi_restore 4 .cfi_adjust_cfa_offset -16 subs r0,r0,#1 epilogue .cfi_endproc cantunwind fnend #else /* Defined in memchr.c. */ #endif picolibc-1.8.11/libc/machine/arm/memchr.c000066400000000000000000000036501513574234600201170ustar00rootroot00000000000000/* Copyright (c) 2015 ARM Ltd. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* The structure of the following #if #else #endif conditional chain must match the chain in memchr.S. */ #include #include "machine/acle-compat.h" #if defined(__ARM_NEON__) || defined(__ARM_NEON) /* Defined in memchr.S. */ #elif __ARM_ARCH_ISA_THUMB >= 2 && defined(__ARM_FEATURE_DSP) /* Defined in memchr.S. */ #else #include "../../string/memchr.c" #endif picolibc-1.8.11/libc/machine/arm/memcpy-armv7a.S000066400000000000000000000365621513574234600213210ustar00rootroot00000000000000/* Copyright (c) 2013, Linaro Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Linaro Limited nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This memcpy routine is optimised for Cortex-A15 cores and takes advantage of VFP or NEON when built with the appropriate flags. Assumptions: ARMv6 (ARMv7-a if using Neon) ARM state Unaligned accesses LDRD/STRD support unaligned word accesses If compiled with GCC, this file should be enclosed within following pre-processing check: if defined (__ARM_ARCH_7A__) && defined (__ARM_FEATURE_UNALIGNED) */ #include #include "arm_asm.h" .syntax unified /* This implementation requires ARM state. */ .arm #ifdef __ARM_NEON__ .fpu neon .arch armv7-a # define FRAME_SIZE 4 # define USE_VFP # define USE_NEON #elif __ARM_FP != 0 .arch armv6 .fpu vfpv2 # define FRAME_SIZE 32 # define USE_VFP #else .arch armv6 # define FRAME_SIZE 32 #endif /* Old versions of GAS incorrectly implement the NEON align semantics. */ #ifdef BROKEN_ASM_NEON_ALIGN #define ALIGN(addr, align) addr,:align #else #define ALIGN(addr, align) addr:align #endif #define PC_OFFSET 8 /* PC pipeline compensation. */ #define INSN_SIZE 4 /* Call parameters. */ #define dstin r0 #define src r1 #define count r2 /* Locals. */ #define tmp1 r3 #define dst ip #define tmp2 r10 #ifndef USE_NEON /* For bulk copies using GP registers. */ #define A_l r2 /* Call-clobbered. */ #define A_h r3 /* Call-clobbered. */ #define B_l r4 #define B_h r5 #define C_l r6 #define C_h r7 #define D_l r8 #define D_h r9 #endif /* Number of lines ahead to pre-fetch data. If you change this the code below will need adjustment to compensate. */ #define prefetch_lines 5 #ifdef USE_VFP .macro cpy_line_vfp vreg, base vstr \vreg, [dst, #\base] vldr \vreg, [src, #\base] vstr d0, [dst, #\base + 8] vldr d0, [src, #\base + 8] vstr d1, [dst, #\base + 16] vldr d1, [src, #\base + 16] vstr d2, [dst, #\base + 24] vldr d2, [src, #\base + 24] vstr \vreg, [dst, #\base + 32] vldr \vreg, [src, #\base + prefetch_lines * 64 - 32] vstr d0, [dst, #\base + 40] vldr d0, [src, #\base + 40] vstr d1, [dst, #\base + 48] vldr d1, [src, #\base + 48] vstr d2, [dst, #\base + 56] vldr d2, [src, #\base + 56] .endm .macro cpy_tail_vfp vreg, base vstr \vreg, [dst, #\base] vldr \vreg, [src, #\base] vstr d0, [dst, #\base + 8] vldr d0, [src, #\base + 8] vstr d1, [dst, #\base + 16] vldr d1, [src, #\base + 16] vstr d2, [dst, #\base + 24] vldr d2, [src, #\base + 24] vstr \vreg, [dst, #\base + 32] vstr d0, [dst, #\base + 40] vldr d0, [src, #\base + 40] vstr d1, [dst, #\base + 48] vldr d1, [src, #\base + 48] vstr d2, [dst, #\base + 56] vldr d2, [src, #\base + 56] .endm #endif .macro def_fn f p2align=0 .text .p2align \p2align .global \f .type \f, %function \f: .endm def_fn memcpy p2align=6 ASM_ALIAS_ARM_STATE __aeabi_memcpy, memcpy ASM_ALIAS_ARM_STATE __aeabi_memcpy4, memcpy ASM_ALIAS_ARM_STATE __aeabi_memcpy8, memcpy mov dst, dstin /* Preserve dstin, we need to return it. */ cmp count, #64 bge .Lcpy_not_short /* Deal with small copies quickly by dropping straight into the exit block. */ .Ltail63unaligned: #ifdef USE_NEON and tmp1, count, #0x38 rsb tmp1, tmp1, #(56 - PC_OFFSET + INSN_SIZE) add pc, pc, tmp1 vld1.8 {d0}, [src]! /* 14 words to go. */ vst1.8 {d0}, [dst]! vld1.8 {d0}, [src]! /* 12 words to go. */ vst1.8 {d0}, [dst]! vld1.8 {d0}, [src]! /* 10 words to go. */ vst1.8 {d0}, [dst]! vld1.8 {d0}, [src]! /* 8 words to go. */ vst1.8 {d0}, [dst]! vld1.8 {d0}, [src]! /* 6 words to go. */ vst1.8 {d0}, [dst]! vld1.8 {d0}, [src]! /* 4 words to go. */ vst1.8 {d0}, [dst]! vld1.8 {d0}, [src]! /* 2 words to go. */ vst1.8 {d0}, [dst]! tst count, #4 ldrne tmp1, [src], #4 strne tmp1, [dst], #4 #else /* Copy up to 15 full words of data. May not be aligned. */ /* Cannot use VFP for unaligned data. */ and tmp1, count, #0x3c add dst, dst, tmp1 add src, src, tmp1 rsb tmp1, tmp1, #(60 - PC_OFFSET/2 + INSN_SIZE/2) /* Jump directly into the sequence below at the correct offset. */ add pc, pc, tmp1, lsl #1 ldr tmp1, [src, #-60] /* 15 words to go. */ str tmp1, [dst, #-60] ldr tmp1, [src, #-56] /* 14 words to go. */ str tmp1, [dst, #-56] ldr tmp1, [src, #-52] str tmp1, [dst, #-52] ldr tmp1, [src, #-48] /* 12 words to go. */ str tmp1, [dst, #-48] ldr tmp1, [src, #-44] str tmp1, [dst, #-44] ldr tmp1, [src, #-40] /* 10 words to go. */ str tmp1, [dst, #-40] ldr tmp1, [src, #-36] str tmp1, [dst, #-36] ldr tmp1, [src, #-32] /* 8 words to go. */ str tmp1, [dst, #-32] ldr tmp1, [src, #-28] str tmp1, [dst, #-28] ldr tmp1, [src, #-24] /* 6 words to go. */ str tmp1, [dst, #-24] ldr tmp1, [src, #-20] str tmp1, [dst, #-20] ldr tmp1, [src, #-16] /* 4 words to go. */ str tmp1, [dst, #-16] ldr tmp1, [src, #-12] str tmp1, [dst, #-12] ldr tmp1, [src, #-8] /* 2 words to go. */ str tmp1, [dst, #-8] ldr tmp1, [src, #-4] str tmp1, [dst, #-4] #endif lsls count, count, #31 ldrhcs tmp1, [src], #2 ldrbne src, [src] /* Src is dead, use as a scratch. */ strhcs tmp1, [dst], #2 strbne src, [dst] bx lr .Lcpy_not_short: /* At least 64 bytes to copy, but don't know the alignment yet. */ str tmp2, [sp, #-FRAME_SIZE]! and tmp2, src, #7 and tmp1, dst, #7 cmp tmp1, tmp2 bne .Lcpy_notaligned #ifdef USE_VFP /* Magic dust alert! Force VFP on Cortex-A9. Experiments show that the FP pipeline is much better at streaming loads and stores. This is outside the critical loop. */ vmov.f32 s0, s0 #endif /* SRC and DST have the same mutual 32-bit alignment, but we may still need to pre-copy some bytes to get to natural alignment. We bring DST into full 64-bit alignment. */ lsls tmp2, dst, #29 beq 1f rsbs tmp2, tmp2, #0 sub count, count, tmp2, lsr #29 ldrmi tmp1, [src], #4 strmi tmp1, [dst], #4 lsls tmp2, tmp2, #2 ldrhcs tmp1, [src], #2 ldrbne tmp2, [src], #1 strhcs tmp1, [dst], #2 strbne tmp2, [dst], #1 1: subs tmp2, count, #64 /* Use tmp2 for count. */ blt .Ltail63aligned cmp tmp2, #512 bge .Lcpy_body_long .Lcpy_body_medium: /* Count in tmp2. */ #ifdef USE_VFP 1: vldr d0, [src, #0] subs tmp2, tmp2, #64 vldr d1, [src, #8] vstr d0, [dst, #0] vldr d0, [src, #16] vstr d1, [dst, #8] vldr d1, [src, #24] vstr d0, [dst, #16] vldr d0, [src, #32] vstr d1, [dst, #24] vldr d1, [src, #40] vstr d0, [dst, #32] vldr d0, [src, #48] vstr d1, [dst, #40] vldr d1, [src, #56] vstr d0, [dst, #48] add src, src, #64 vstr d1, [dst, #56] add dst, dst, #64 bge 1b tst tmp2, #0x3f beq .Ldone .Ltail63aligned: /* Count in tmp2. */ and tmp1, tmp2, #0x38 add dst, dst, tmp1 add src, src, tmp1 rsb tmp1, tmp1, #(56 - PC_OFFSET + INSN_SIZE) add pc, pc, tmp1 vldr d0, [src, #-56] /* 14 words to go. */ vstr d0, [dst, #-56] vldr d0, [src, #-48] /* 12 words to go. */ vstr d0, [dst, #-48] vldr d0, [src, #-40] /* 10 words to go. */ vstr d0, [dst, #-40] vldr d0, [src, #-32] /* 8 words to go. */ vstr d0, [dst, #-32] vldr d0, [src, #-24] /* 6 words to go. */ vstr d0, [dst, #-24] vldr d0, [src, #-16] /* 4 words to go. */ vstr d0, [dst, #-16] vldr d0, [src, #-8] /* 2 words to go. */ vstr d0, [dst, #-8] #else sub src, src, #8 sub dst, dst, #8 1: ldrd A_l, A_h, [src, #8] strd A_l, A_h, [dst, #8] ldrd A_l, A_h, [src, #16] strd A_l, A_h, [dst, #16] ldrd A_l, A_h, [src, #24] strd A_l, A_h, [dst, #24] ldrd A_l, A_h, [src, #32] strd A_l, A_h, [dst, #32] ldrd A_l, A_h, [src, #40] strd A_l, A_h, [dst, #40] ldrd A_l, A_h, [src, #48] strd A_l, A_h, [dst, #48] ldrd A_l, A_h, [src, #56] strd A_l, A_h, [dst, #56] ldrd A_l, A_h, [src, #64]! strd A_l, A_h, [dst, #64]! subs tmp2, tmp2, #64 bge 1b tst tmp2, #0x3f bne 1f ldr tmp2,[sp], #FRAME_SIZE bx lr 1: add src, src, #8 add dst, dst, #8 .Ltail63aligned: /* Count in tmp2. */ /* Copy up to 7 d-words of data. Similar to Ltail63unaligned, but we know that the src and dest are 32-bit aligned so we can use LDRD/STRD to improve efficiency. */ /* TMP2 is now negative, but we don't care about that. The bottom six bits still tell us how many bytes are left to copy. */ and tmp1, tmp2, #0x38 add dst, dst, tmp1 add src, src, tmp1 rsb tmp1, tmp1, #(56 - PC_OFFSET + INSN_SIZE) add pc, pc, tmp1 ldrd A_l, A_h, [src, #-56] /* 14 words to go. */ strd A_l, A_h, [dst, #-56] ldrd A_l, A_h, [src, #-48] /* 12 words to go. */ strd A_l, A_h, [dst, #-48] ldrd A_l, A_h, [src, #-40] /* 10 words to go. */ strd A_l, A_h, [dst, #-40] ldrd A_l, A_h, [src, #-32] /* 8 words to go. */ strd A_l, A_h, [dst, #-32] ldrd A_l, A_h, [src, #-24] /* 6 words to go. */ strd A_l, A_h, [dst, #-24] ldrd A_l, A_h, [src, #-16] /* 4 words to go. */ strd A_l, A_h, [dst, #-16] ldrd A_l, A_h, [src, #-8] /* 2 words to go. */ strd A_l, A_h, [dst, #-8] #endif tst tmp2, #4 ldrne tmp1, [src], #4 strne tmp1, [dst], #4 lsls tmp2, tmp2, #31 /* Count (tmp2) now dead. */ ldrhcs tmp1, [src], #2 ldrbne tmp2, [src] strhcs tmp1, [dst], #2 strbne tmp2, [dst] .Ldone: ldr tmp2, [sp], #FRAME_SIZE bx lr .Lcpy_body_long: /* Count in tmp2. */ /* Long copy. We know that there's at least (prefetch_lines * 64) bytes to go. */ #ifdef USE_VFP /* Don't use PLD. Instead, read some data in advance of the current copy position into a register. This should act like a PLD operation but we won't have to repeat the transfer. */ vldr d3, [src, #0] vldr d4, [src, #64] vldr d5, [src, #128] vldr d6, [src, #192] vldr d7, [src, #256] vldr d0, [src, #8] vldr d1, [src, #16] vldr d2, [src, #24] add src, src, #32 subs tmp2, tmp2, #prefetch_lines * 64 * 2 blt 2f 1: cpy_line_vfp d3, 0 cpy_line_vfp d4, 64 cpy_line_vfp d5, 128 add dst, dst, #3 * 64 add src, src, #3 * 64 cpy_line_vfp d6, 0 cpy_line_vfp d7, 64 add dst, dst, #2 * 64 add src, src, #2 * 64 subs tmp2, tmp2, #prefetch_lines * 64 bge 1b 2: cpy_tail_vfp d3, 0 cpy_tail_vfp d4, 64 cpy_tail_vfp d5, 128 add src, src, #3 * 64 add dst, dst, #3 * 64 cpy_tail_vfp d6, 0 vstr d7, [dst, #64] vldr d7, [src, #64] vstr d0, [dst, #64 + 8] vldr d0, [src, #64 + 8] vstr d1, [dst, #64 + 16] vldr d1, [src, #64 + 16] vstr d2, [dst, #64 + 24] vldr d2, [src, #64 + 24] vstr d7, [dst, #64 + 32] add src, src, #96 vstr d0, [dst, #64 + 40] vstr d1, [dst, #64 + 48] vstr d2, [dst, #64 + 56] add dst, dst, #128 add tmp2, tmp2, #prefetch_lines * 64 b .Lcpy_body_medium #else /* Long copy. Use an SMS style loop to maximize the I/O bandwidth of the core. We don't have enough spare registers to synthesise prefetching, so use PLD operations. */ /* Pre-bias src and dst. */ sub src, src, #8 sub dst, dst, #8 pld [src, #8] pld [src, #72] subs tmp2, tmp2, #64 pld [src, #136] ldrd A_l, A_h, [src, #8] strd B_l, B_h, [sp, #8] ldrd B_l, B_h, [src, #16] strd C_l, C_h, [sp, #16] ldrd C_l, C_h, [src, #24] strd D_l, D_h, [sp, #24] pld [src, #200] ldrd D_l, D_h, [src, #32]! b 1f .p2align 6 2: pld [src, #232] strd A_l, A_h, [dst, #40] ldrd A_l, A_h, [src, #40] strd B_l, B_h, [dst, #48] ldrd B_l, B_h, [src, #48] strd C_l, C_h, [dst, #56] ldrd C_l, C_h, [src, #56] strd D_l, D_h, [dst, #64]! ldrd D_l, D_h, [src, #64]! subs tmp2, tmp2, #64 1: strd A_l, A_h, [dst, #8] ldrd A_l, A_h, [src, #8] strd B_l, B_h, [dst, #16] ldrd B_l, B_h, [src, #16] strd C_l, C_h, [dst, #24] ldrd C_l, C_h, [src, #24] strd D_l, D_h, [dst, #32] ldrd D_l, D_h, [src, #32] bcs 2b /* Save the remaining bytes and restore the callee-saved regs. */ strd A_l, A_h, [dst, #40] add src, src, #40 strd B_l, B_h, [dst, #48] ldrd B_l, B_h, [sp, #8] strd C_l, C_h, [dst, #56] ldrd C_l, C_h, [sp, #16] strd D_l, D_h, [dst, #64] ldrd D_l, D_h, [sp, #24] add dst, dst, #72 tst tmp2, #0x3f bne .Ltail63aligned ldr tmp2, [sp], #FRAME_SIZE bx lr #endif .Lcpy_notaligned: pld [src] pld [src, #64] /* There's at least 64 bytes to copy, but there is no mutual alignment. */ /* Bring DST to 64-bit alignment. */ lsls tmp2, dst, #29 pld [src, #(2 * 64)] beq 1f rsbs tmp2, tmp2, #0 sub count, count, tmp2, lsr #29 ldrmi tmp1, [src], #4 strmi tmp1, [dst], #4 lsls tmp2, tmp2, #2 ldrbne tmp1, [src], #1 ldrhcs tmp2, [src], #2 strbne tmp1, [dst], #1 strhcs tmp2, [dst], #2 1: pld [src, #(3 * 64)] subs count, count, #64 ldrmi tmp2, [sp], #FRAME_SIZE bmi .Ltail63unaligned pld [src, #(4 * 64)] #ifdef USE_NEON vld1.8 {d0-d3}, [src]! vld1.8 {d4-d7}, [src]! subs count, count, #64 bmi 2f 1: pld [src, #(4 * 64)] vst1.8 {d0-d3}, [ALIGN (dst, 64)]! vld1.8 {d0-d3}, [src]! vst1.8 {d4-d7}, [ALIGN (dst, 64)]! vld1.8 {d4-d7}, [src]! subs count, count, #64 bpl 1b 2: vst1.8 {d0-d3}, [ALIGN (dst, 64)]! vst1.8 {d4-d7}, [ALIGN (dst, 64)]! ands count, count, #0x3f #else /* Use an SMS style loop to maximize the I/O bandwidth. */ sub src, src, #4 sub dst, dst, #8 subs tmp2, count, #64 /* Use tmp2 for count. */ ldr A_l, [src, #4] ldr A_h, [src, #8] strd B_l, B_h, [sp, #8] ldr B_l, [src, #12] ldr B_h, [src, #16] strd C_l, C_h, [sp, #16] ldr C_l, [src, #20] ldr C_h, [src, #24] strd D_l, D_h, [sp, #24] ldr D_l, [src, #28] ldr D_h, [src, #32]! b 1f .p2align 6 2: pld [src, #(5 * 64) - (32 - 4)] strd A_l, A_h, [dst, #40] ldr A_l, [src, #36] ldr A_h, [src, #40] strd B_l, B_h, [dst, #48] ldr B_l, [src, #44] ldr B_h, [src, #48] strd C_l, C_h, [dst, #56] ldr C_l, [src, #52] ldr C_h, [src, #56] strd D_l, D_h, [dst, #64]! ldr D_l, [src, #60] ldr D_h, [src, #64]! subs tmp2, tmp2, #64 1: strd A_l, A_h, [dst, #8] ldr A_l, [src, #4] ldr A_h, [src, #8] strd B_l, B_h, [dst, #16] ldr B_l, [src, #12] ldr B_h, [src, #16] strd C_l, C_h, [dst, #24] ldr C_l, [src, #20] ldr C_h, [src, #24] strd D_l, D_h, [dst, #32] ldr D_l, [src, #28] ldr D_h, [src, #32] bcs 2b /* Save the remaining bytes and restore the callee-saved regs. */ strd A_l, A_h, [dst, #40] add src, src, #36 strd B_l, B_h, [dst, #48] ldrd B_l, B_h, [sp, #8] strd C_l, C_h, [dst, #56] ldrd C_l, C_h, [sp, #16] strd D_l, D_h, [dst, #64] ldrd D_l, D_h, [sp, #24] add dst, dst, #72 ands count, tmp2, #0x3f #endif ldr tmp2, [sp], #FRAME_SIZE bne .Ltail63unaligned bx lr .size memcpy, . - memcpy picolibc-1.8.11/libc/machine/arm/memcpy-armv7m.S000066400000000000000000000205661513574234600213320ustar00rootroot00000000000000/* * Copyright (c) 2013 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This memcpy routine is optimised for Cortex-M3/M4 cores with/without unaligned access. If compiled with GCC, this file should be enclosed within following pre-processing check: if defined (__ARM_ARCH_7M__) || defined (__ARM_ARCH_7EM__) Prototype: void *memcpy (void *dst, const void *src, size_t count); The job will be done in 5 steps. Step 1: Align src/dest pointers, copy mis-aligned if fail to align both Step 2: Repeatedly copy big block size of __OPT_BIG_BLOCK_SIZE Step 3: Repeatedly copy big block size of __OPT_MID_BLOCK_SIZE Step 4: Copy word by word Step 5: Copy byte-to-byte Tunable options: __OPT_BIG_BLOCK_SIZE: Size of big block in words. Default to 64. __OPT_MID_BLOCK_SIZE: Size of big block in words. Default to 16. */ #include #include "arm_asm.h" #ifndef __OPT_BIG_BLOCK_SIZE #define __OPT_BIG_BLOCK_SIZE (4 * 16) #endif #ifndef __OPT_MID_BLOCK_SIZE #define __OPT_MID_BLOCK_SIZE (4 * 4) #endif #if __OPT_BIG_BLOCK_SIZE == 16 #define BEGIN_UNROLL_BIG_BLOCK \ .irp offset, 0,4,8,12 #elif __OPT_BIG_BLOCK_SIZE == 32 #define BEGIN_UNROLL_BIG_BLOCK \ .irp offset, 0,4,8,12,16,20,24,28 #elif __OPT_BIG_BLOCK_SIZE == 64 #define BEGIN_UNROLL_BIG_BLOCK \ .irp offset, 0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60 #else #error "Illegal __OPT_BIG_BLOCK_SIZE" #endif #if __OPT_MID_BLOCK_SIZE == 8 #define BEGIN_UNROLL_MID_BLOCK \ .irp offset, 0,4 #elif __OPT_MID_BLOCK_SIZE == 16 #define BEGIN_UNROLL_MID_BLOCK \ .irp offset, 0,4,8,12 #else #error "Illegal __OPT_MID_BLOCK_SIZE" #endif #define END_UNROLL .endr .syntax unified .text .align 2 .global memcpy .thumb .thumb_func fnstart .cfi_sections .debug_frame .cfi_startproc .type memcpy, %function ASM_ALIAS_THUMB_STATE __aeabi_memcpy, memcpy ASM_ALIAS_THUMB_STATE __aeabi_memcpy4, memcpy ASM_ALIAS_THUMB_STATE __aeabi_memcpy8, memcpy memcpy: // r0: dst // r1: src // r2: len #ifdef __ARM_FEATURE_UNALIGNED /* In case of UNALIGNED access supported, ip is not used in function body. */ prologue push_ip=HAVE_PAC_LEAF mov ip, r0 #else prologue 0 push_ip=HAVE_PAC_LEAF #endif /* __ARM_FEATURE_UNALIGNED */ orr r3, r1, r0 ands r3, r3, #3 bne .Lmisaligned_copy .Lbig_block: subs r2, __OPT_BIG_BLOCK_SIZE blo .Lmid_block /* Kernel loop for big block copy */ .align 2 .Lbig_block_loop: BEGIN_UNROLL_BIG_BLOCK #ifdef __ARM_ARCH_7EM__ ldr r3, [r1], #4 str r3, [r0], #4 END_UNROLL #else /* __ARM_ARCH_7M__ */ ldr r3, [r1, \offset] str r3, [r0, \offset] END_UNROLL adds r0, __OPT_BIG_BLOCK_SIZE adds r1, __OPT_BIG_BLOCK_SIZE #endif subs r2, __OPT_BIG_BLOCK_SIZE bhs .Lbig_block_loop .Lmid_block: adds r2, __OPT_BIG_BLOCK_SIZE - __OPT_MID_BLOCK_SIZE blo .Lcopy_word_by_word /* Kernel loop for mid-block copy */ .align 2 .Lmid_block_loop: BEGIN_UNROLL_MID_BLOCK #ifdef __ARM_ARCH_7EM__ ldr r3, [r1], #4 str r3, [r0], #4 END_UNROLL #else /* __ARM_ARCH_7M__ */ ldr r3, [r1, \offset] str r3, [r0, \offset] END_UNROLL adds r0, __OPT_MID_BLOCK_SIZE adds r1, __OPT_MID_BLOCK_SIZE #endif subs r2, __OPT_MID_BLOCK_SIZE bhs .Lmid_block_loop .Lcopy_word_by_word: adds r2, __OPT_MID_BLOCK_SIZE - 4 blo .Lcopy_less_than_4 /* Kernel loop for small block copy */ .align 2 .Lcopy_word_by_word_loop: ldr r3, [r1], #4 str r3, [r0], #4 subs r2, #4 bhs .Lcopy_word_by_word_loop .Lcopy_less_than_4: adds r2, #4 beq .Ldone lsls r2, r2, #31 itt ne ldrbne r3, [r1], #1 strbne r3, [r0], #1 bcc .Ldone #ifdef __ARM_FEATURE_UNALIGNED ldrh r3, [r1] strh r3, [r0] #else ldrb r3, [r1] strb r3, [r0] ldrb r3, [r1, #1] strb r3, [r0, #1] #endif /* __ARM_FEATURE_UNALIGNED */ .Ldone: .cfi_remember_state #ifdef __ARM_FEATURE_UNALIGNED mov r0, ip epilogue push_ip=HAVE_PAC_LEAF #else epilogue 0 push_ip=HAVE_PAC_LEAF #endif /* __ARM_FEATURE_UNALIGNED */ .align 2 .Lmisaligned_copy: .cfi_restore_state #ifdef __ARM_FEATURE_UNALIGNED /* Define label DST_ALIGNED to BIG_BLOCK. It will go to aligned copy once destination is adjusted to aligned. */ #define Ldst_aligned Lbig_block /* Copy word by word using LDR when alignment can be done in hardware, i.e., SCTLR.A is set, supporting unaligned access in LDR and STR. */ cmp r2, #8 blo .Lbyte_copy /* if src is aligned, just go to the big block loop. */ lsls r3, r1, #30 beq .Ldst_aligned #else /* if len < 12, misalignment adjustment has more overhead than just byte-to-byte copy. Also, len must >=8 to guarantee code afterward work correctly. */ cmp r2, #12 blo .Lbyte_copy #endif /* __ARM_FEATURE_UNALIGNED */ /* Align dst only, not trying to align src. That is the because handling of aligned src and misaligned dst need more overhead than otherwise. By doing this the worst case is when initial src is aligned, additional up to 4 byte additional copy will executed, which is acceptable. */ ands r3, r0, #3 beq .Ldst_aligned rsb r3, #4 subs r2, r3 lsls r3, r3, #31 itt ne ldrbne r3, [r1], #1 strbne r3, [r0], #1 bcc .Ldst_aligned #ifdef __ARM_FEATURE_UNALIGNED ldrh r3, [r1], #2 strh r3, [r0], #2 b .Ldst_aligned #else ldrb r3, [r1], #1 strb r3, [r0], #1 ldrb r3, [r1], #1 strb r3, [r0], #1 /* Now that dst is aligned */ .Ldst_aligned: /* if r1 is aligned now, it means r0/r1 has the same misalignment, and they are both aligned now. Go aligned copy. */ ands r3, r1, #3 beq .Lbig_block /* dst is aligned, but src isn't. Misaligned copy. */ push {r4, r5} .cfi_adjust_cfa_offset 8 .cfi_rel_offset 4, 0 .cfi_rel_offset 5, 4 subs r2, #4 /* Backward r1 by misaligned bytes, to make r1 aligned. Since we need to restore r1 to unaligned address after the loop, we need keep the offset bytes to ip and sub it from r1 afterward. */ subs r1, r3 rsb ip, r3, #4 /* Pre-load on word */ ldr r4, [r1], #4 cmp r3, #2 beq .Lmisaligned_copy_2_2 cmp r3, #3 beq .Lmisaligned_copy_3_1 .macro mis_src_copy shift 1: #ifdef __ARM_BIG_ENDIAN lsls r4, r4, \shift #else lsrs r4, r4, \shift #endif ldr r3, [r1], #4 #ifdef __ARM_BIG_ENDIAN lsrs r5, r3, 32-\shift #else lsls r5, r3, 32-\shift #endif orr r4, r4, r5 str r4, [r0], #4 mov r4, r3 subs r2, #4 bhs 1b .endm .Lmisaligned_copy_1_3: mis_src_copy shift=8 b .Lsrc_misaligned_tail .Lmisaligned_copy_3_1: mis_src_copy shift=24 b .Lsrc_misaligned_tail .Lmisaligned_copy_2_2: /* For 2_2 misalignment, ldr is still faster than 2 x ldrh. */ mis_src_copy shift=16 .Lsrc_misaligned_tail: adds r2, #4 subs r1, ip pop {r4, r5} .cfi_restore 4 .cfi_restore 5 .cfi_adjust_cfa_offset -8 #endif /* __ARM_FEATURE_UNALIGNED */ .Lbyte_copy: subs r2, #4 blo .Lcopy_less_than_4 .Lbyte_copy_loop: subs r2, #1 ldrb r3, [r1], #1 strb r3, [r0], #1 bhs .Lbyte_copy_loop ldrb r3, [r1] strb r3, [r0] ldrb r3, [r1, #1] strb r3, [r0, #1] ldrb r3, [r1, #2] strb r3, [r0, #2] #ifdef __ARM_FEATURE_UNALIGNED mov r0, ip epilogue push_ip=HAVE_PAC_LEAF #else epilogue 0 push_ip=HAVE_PAC_LEAF #endif /* __ARM_FEATURE_UNALIGNED */ .cfi_endproc cantunwind fnend .size memcpy, .-memcpy picolibc-1.8.11/libc/machine/arm/memcpy.S000066400000000000000000000037261513574234600201220ustar00rootroot00000000000000/* * Copyright (c) 2013-2015 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* The structure of the following #if #else #endif conditional chain must match the chain in memcpy-stub.c. */ #include #include "machine/acle-compat.h" #if defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED) /* Defined in memcpy-stub.c. */ #elif (__ARM_ARCH >= 7 && __ARM_ARCH_PROFILE == 'A' \ && defined (__ARM_FEATURE_UNALIGNED)) #include "memcpy-armv7a.S" #elif __ARM_ARCH_ISA_THUMB == 2 && !__ARM_ARCH_ISA_ARM #include "memcpy-armv7m.S" #else /* Defined in memcpy-stub.c. */ #endif picolibc-1.8.11/libc/machine/arm/memcpy.c000066400000000000000000000043561513574234600201420ustar00rootroot00000000000000/* Copyright (c) 2015 ARM Ltd. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* The structure of the following #if #else #endif conditional chain must match the chain in memcpy.S. */ #include #include "machine/acle-compat.h" #if (defined(__OPTIMIZE_SIZE__) || defined(__PREFER_SIZE_OVER_SPEED)) #define MEMCPY_FALLBACK #elif (__ARM_ARCH >= 7 && __ARM_ARCH_PROFILE == 'A' && defined(__ARM_FEATURE_UNALIGNED)) /* Defined in memcpy-armv7a.S. */ #elif __ARM_ARCH_ISA_THUMB == 2 && !__ARM_ARCH_ISA_ARM /* Defined in memcpy-armv7m.S. */ #else #define MEMCPY_FALLBACK #endif #ifdef MEMCPY_FALLBACK #include "../../string/memcpy.c" __weak_reference(memcpy, __aeabi_memcpy4); __weak_reference(memcpy, __aeabi_memcpy8); __weak_reference(memcpy, __aeabi_memcpy); #endif picolibc-1.8.11/libc/machine/arm/memmove.c000066400000000000000000000035471513574234600203160ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2021 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "../../string/memmove.c" /* Support the alias for the __aeabi_memmove which may assume memory alignment. */ __weak_reference(memmove, __aeabi_memmove4); __weak_reference(memmove, __aeabi_memmove8); __weak_reference(memmove, __aeabi_memmove); picolibc-1.8.11/libc/machine/arm/memset-arm.S000066400000000000000000000046611513574234600206760ustar00rootroot00000000000000/* * Copyright (c) 2015 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include .arm .syntax unified .global memset .type memset, %function memset: tst r0, #3 stmfd sp!, {r4, lr} beq 10f cmp r2, #0 sub r2, r2, #1 beq 9f and ip, r1, #255 mov r3, r0 b 2f 1: cmp r2, #0 sub r2, r2, #1 beq 9f 2: strb ip, [r3], #1 tst r3, #3 bne 1b 3: cmp r2, #3 bls 7f and lr, r1, #255 orr lr, lr, lr, asl #8 cmp r2, #15 orr lr, lr, lr, asl #16 bls 5f mov r4, r2 add ip, r3, #16 4: sub r4, r4, #16 cmp r4, #15 str lr, [ip, #-16] str lr, [ip, #-12] str lr, [ip, #-8] str lr, [ip, #-4] add ip, ip, #16 bhi 4b sub ip, r2, #16 bic ip, ip, #15 and r2, r2, #15 add ip, ip, #16 cmp r2, #3 add r3, r3, ip bls 7f 5: mov r4, r3 mov ip, r2 6: sub ip, ip, #4 cmp ip, #3 str lr, [r4], #4 bhi 6b sub ip, r2, #4 bic ip, ip, #3 add ip, ip, #4 add r3, r3, ip and r2, r2, #3 7: cmp r2, #0 andne r1, r1, #255 addne r2, r3, r2 beq 9f 8: strb r1, [r3], #1 cmp r3, r2 bne 8b 9: ldmfd sp!, {r4, lr} bx lr 10: mov r3, r0 b 3b .size memset, . - memset picolibc-1.8.11/libc/machine/arm/memset-thumb.S000066400000000000000000000054021513574234600212300ustar00rootroot00000000000000/* * Copyright (c) 2015 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "arm_asm.h" .thumb .syntax unified .global memset .type memset, %function .p2align 1 memset: fnstart .cfi_sections .debug_frame .cfi_startproc prologue 4 6 push_ip=HAVE_PAC_LEAF lsls r3, r0, #30 beq 10f subs r4, r2, #1 cmp r2, #0 beq 9f lsls r5, r1, #24 lsrs r5, r5, #24 movs r3, r0 movs r6, #3 b 2f 1: subs r2, r4, #1 cmp r4, #0 beq 9f movs r4, r2 2: adds r3, r3, #1 subs r2, r3, #1 strb r5, [r2] tst r3, r6 bne 1b 3: cmp r4, #3 bls 7f movs r5, #255 ands r5, r1 lsls r2, r5, #8 orrs r5, r2 lsls r2, r5, #16 orrs r5, r2 cmp r4, #15 bls 5f movs r6, r4 subs r6, r6, #16 lsrs r6, r6, #4 adds r6, r6, #1 lsls r6, r6, #4 movs r2, r3 adds r3, r3, r6 4: str r5, [r2] str r5, [r2, #4] str r5, [r2, #8] str r5, [r2, #12] adds r2, r2, #16 cmp r3, r2 bne 4b movs r2, #15 ands r4, r2 cmp r4, #3 bls 7f 5: subs r6, r4, #4 lsrs r6, r6, #2 adds r6, r6, #1 lsls r6, r6, #2 movs r2, r3 adds r3, r3, r6 6: stmia r2!, {r5} cmp r3, r2 bne 6b movs r2, #3 ands r4, r2 7: cmp r4, #0 beq 9f lsls r1, r1, #24 lsrs r1, r1, #24 adds r4, r3, r4 8: strb r1, [r3] adds r3, r3, #1 cmp r4, r3 bne 8b 9: .cfi_remember_state epilogue 4 6 push_ip=HAVE_PAC_LEAF .cfi_restore_state 10: movs r3, r0 movs r4, r2 b 3b .cfi_endproc cantunwind fnend .size memset, . - memset picolibc-1.8.11/libc/machine/arm/memset-thumb2.S000066400000000000000000000053141513574234600213140ustar00rootroot00000000000000/* * Copyright (c) 2015 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "arm_asm.h" .thumb .syntax unified .global memset .type memset, %function .p2align 1 memset: fnstart .cfi_sections .debug_frame .cfi_startproc prologue 4 6 push_ip=HAVE_PAC_LEAF lsls r4, r0, #30 beq 10f subs r4, r2, #1 cmp r2, #0 beq 9f uxtb r5, r1 mov r3, r0 b 2f 1: subs r2, r4, #1 cbz r4, 9f mov r4, r2 2: strb r5, [r3], #1 lsls r2, r3, #30 bne 1b 3: cmp r4, #3 bls 7f uxtb r5, r1 orr r5, r5, r5, lsl #8 cmp r4, #15 orr r5, r5, r5, lsl #16 bls 5f mov r6, r4 add r2, r3, #16 4: subs r6, r6, #16 cmp r6, #15 str r5, [r2, #-16] str r5, [r2, #-12] str r5, [r2, #-8] str r5, [r2, #-4] add r2, r2, #16 bhi 4b sub r2, r4, #16 bic r2, r2, #15 and r4, r4, #15 adds r2, r2, #16 cmp r4, #3 add r3, r3, r2 bls 7f 5: mov r6, r3 mov r2, r4 6: subs r2, r2, #4 cmp r2, #3 str r5, [r6], #4 bhi 6b subs r2, r4, #4 bic r2, r2, #3 adds r2, r2, #4 add r3, r3, r2 and r4, r4, #3 7: cbz r4, 9f uxtb r1, r1 add r4, r4, r3 8: strb r1, [r3], #1 cmp r3, r4 bne 8b 9: .cfi_remember_state epilogue 4 6 push_ip=HAVE_PAC_LEAF .cfi_restore_state 10: mov r4, r2 mov r3, r0 b 3b .cfi_endproc cantunwind fnend .size memset, . - memset #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/arm/memset.S000066400000000000000000000033771513574234600201240ustar00rootroot00000000000000/* * Copyright (c) 2015 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* NOTE: This ifdef MUST match the one in memset.c. */ #include #if __ARM_FP != 0 && !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) # if defined (__thumb2__) # include "memset-thumb2.S" # elif defined (__thumb__) # include "memset-thumb.S" # else # include "memset-arm.S" # endif #endif picolibc-1.8.11/libc/machine/arm/memset.c000066400000000000000000000042151513574234600201340ustar00rootroot00000000000000/* * Copyright (c) 2015 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include /* According to the run-time ABI for the ARM Architecture, this function is allowed to corrupt only the integer core register permitted to be corrupted by the [AAPCS] (r0-r3, ip, lr, and CPSR). Therefore, we can't just simply use alias to support the function aeabi_memset for the targets with FP register. Instead, versions for these specific targets are written in assembler (in aeabi_memset-soft.S). */ /* NOTE: This ifdef MUST match the one in memset-soft.S. */ #if __ARM_FP != 0 && !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) /* Defined in memset-soft.S. */ #else #include "../../string/memset.c" #endif picolibc-1.8.11/libc/machine/arm/meson.build000066400000000000000000000042551513574234600206440ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'setjmp.S', 'strcmp.S', 'strcpy.S', 'aeabi_memset.c', 'bzero.c', 'interrupt.c', 'memchr.c', 'memchr.S', 'memcpy.c', 'memcpy.S', 'memmove.c', 'memset.c', 'memset.S', 'read_tp.S', 'set_tls.c', 'strlen.c', 'strlen.S', 'tls.c', ] subdir('machine') subdir('sys') foreach params : targets target = params['name'] target_dir = params['dir'] target_c_args = params['c_args'] set_variable('lib_machine' + target, static_library('machine' + target, srcs_machine, pic: false, include_directories: inc, c_args: target_c_args + c_args + arg_fnobuiltin + arg_fnolto)) endforeach picolibc-1.8.11/libc/machine/arm/read_tp.S000066400000000000000000000055271513574234600202470ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * Copyright © 2024 Stephen Street * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #ifdef __THREAD_LOCAL_STORAGE #define _IN_ASM #include "arm_tls.h" /* * This cannot be a C ABI function as the compiler assumes that it * does not modify anything other than r0 and lr. */ .syntax unified .section .text.__aeabi_read_tp .align 4 .p2align 4,,15 .global __aeabi_read_tp .type __aeabi_read_tp,%function #ifdef __thumb__ .thumb #endif __aeabi_read_tp: .cfi_sections .debug_frame .cfi_startproc #ifdef ARM_TLS_CP15 mrc p15, 0, r0, c13, c0, 3 bx lr #else #ifdef ARM_RP2040 /* * Code for RP2040 processor. This is a dual-core cortex-m0 * design. We use the CPUID register, stored at offset zero of * the Single-cycle IO block at 0xd0000000 */ #define TLS_SIZE (4 * RP2040_NCORE) push {r1,lr} /* Save R1 (and LR) */ ldr r1,=0xd0000000 /* Address of SIO->CPUID */ ldr r1,[r1] /* Fetch active core */ lsls r1,r1,#2 /* Multiply by 4 */ ldr r0,=__tls /* Address of __tls array */ ldr r0,[r0,r1] /* Fetch __tls[CPUID] */ pop {r1,pc} /* Restore R1 and return */ #else #define TLS_SIZE 4 ldr r0,=__tls /* Load the address of __tls */ ldr r0,[r0] /* Dereference to get the value of __tls */ bx lr /* All done, return to caller */ #endif #endif .cfi_endproc #endif picolibc-1.8.11/libc/machine/arm/set_tls.c000066400000000000000000000050121513574234600203130ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * Copyright © 2024 Stephen Street * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #ifdef __THREAD_LOCAL_STORAGE_API #include "arm_tls.h" /* This needs to be global so that __aeabi_read_tp can * refer to it in an asm statement */ #ifndef ARM_TLS_CP15 extern void *__tls[]; #endif /* The size of the thread control block. * TLS relocations are generated relative to * a location this far *before* the first thread * variable (!) * NB: The actual size before tp also includes padding * to align up to the alignment of .tdata/.tbss. */ #define TCB_SIZE 8 extern char __arm32_tls_tcb_offset; #define TP_OFFSET ((size_t)&__arm32_tls_tcb_offset) void _set_tls(void *tls) { tls = (uint8_t *)tls - TP_OFFSET; #ifdef ARM_TLS_CP15 __asm__("mcr p15, 0, %0, cr13, cr0, 3" : : "r"(tls)); #else #ifdef ARM_RP2040 uint32_t cpuid = *(uint32_t *)0xd0000000; __tls[cpuid] = tls; #else __tls[0] = tls; #endif #endif } #endif picolibc-1.8.11/libc/machine/arm/setjmp.S000066400000000000000000000161061513574234600201260ustar00rootroot00000000000000/* This is a simple version of setjmp and longjmp. Copyright (c) 1997 Nick Clifton, Cygnus Solutions */ #include #include "machine/acle-compat.h" /* ANSI concatenation macros. */ #define CONCAT(a, b) CONCAT2(a, b) #define CONCAT2(a, b) a##b #ifndef __USER_LABEL_PREFIX__ #error __USER_LABEL_PREFIX__ not defined #endif #define SYM(x) CONCAT (__USER_LABEL_PREFIX__, x) #ifdef __ELF__ #define TYPE(x) .type SYM(x),function #define SIZE(x) .size SYM(x), . - SYM(x) #else #define TYPE(x) #define SIZE(x) #endif /* Jump buffer allocation sizes. */ #define JUMPBUF_CORE_REGS_SIZE (10 * 4) #define JUMPBUF_FP_REGS_SIZE (8 * 8) #define JUMPBUF_PAC (JUMPBUF_CORE_REGS_SIZE + JUMPBUF_FP_REGS_SIZE + 0) /* Arm/Thumb interworking support: The interworking scheme expects functions to use a BX instruction to return control to their parent. Since we need this code to work in both interworked and non-interworked environments as well as with older processors which do not have the BX instruction we do the following: Test the return address. If the bottom bit is clear perform an "old style" function exit. (We know that we are in ARM mode and returning to an ARM mode caller). Otherwise use the BX instruction to perform the function exit. We know that we will never attempt to perform the BX instruction on an older processor, because that kind of processor will never be interworked, and a return address with the bottom bit set will never be generated. In addition, we do not actually assemble the BX instruction as this would require us to tell the assembler that the processor is an ARM7TDMI and it would store this information in the binary. We want this binary to be able to be linked with binaries compiled for older processors however, so we do not want such information stored there. If we are running using the APCS-26 convention however, then we never test the bottom bit, because this is part of the processor status. Instead we just do a normal return, since we know that we cannot be returning to a Thumb caller - the Thumb does not support APCS-26. Function entry is much simpler. If we are compiling for the Thumb we just switch into ARM mode and then drop through into the rest of the function. The function exit code will take care of the restore to Thumb mode. For Thumb-2 do everything in Thumb mode. */ .syntax unified /* GCC 12.1 and later and clang will tell the assembler exactly which floating point (or MVE) unit is required and we don't want to override that. Conversely, older versions of the compiler don't pass this information so we need to enable the VFP version that is most appropriate. The choice here should support all suitable VFP versions that the older toolchains can handle. */ #if __GNUC__ && __GNUC__ < 12 && !defined(__clang__) /* Ensure that FPU instructions are correctly compiled and, likewise, the appropriate build attributes are added to the resulting object file. Check whether the MVE extension is present and whether we have support for hardware floating point-operations. VFPxd covers all the cases we need in this file for hardware floating-point and should be compatible with all required FPUs that we need to support. */ # if __ARM_FP && !__clang__ .fpu vfpxd # endif # if __ARM_FEATURE_MVE && !__clang__ .arch_extension mve # endif #endif #if __ARM_ARCH_ISA_THUMB == 1 && !__ARM_ARCH_ISA_ARM /* ARMv6-M-like has to be implemented in Thumb mode. */ .thumb .thumb_func .globl SYM (setjmp) TYPE (setjmp) SYM (setjmp): /* Save registers in jump buffer. */ stmia r0!, {r4, r5, r6, r7} mov r1, r8 mov r2, r9 mov r3, r10 mov r4, fp mov r5, sp mov r6, lr stmia r0!, {r1, r2, r3, r4, r5, r6} subs r0, r0, #40 /* Restore callee-saved low regs. */ ldmia r0!, {r4, r5, r6, r7} /* Return zero. */ movs r0, #0 bx lr .thumb_func .globl SYM (longjmp) TYPE (longjmp) SYM (longjmp): /* Restore High regs. */ adds r0, r0, #16 ldmia r0!, {r2, r3, r4, r5, r6} mov r8, r2 mov r9, r3 mov r10, r4 mov fp, r5 mov sp, r6 ldmia r0!, {r3} /* lr */ /* Restore low regs. */ subs r0, r0, #40 ldmia r0!, {r4, r5, r6, r7} /* Return the result argument, or 1 if it is zero. */ movs r0, r1 bne 1f movs r0, #1 1: bx r3 #else #ifdef __APCS_26__ #define RET movs pc, lr #elif defined(__thumb2__) #define RET bx lr #else #define RET tst lr, #1; \ moveq pc, lr ; \ .inst 0xe12fff1e /* bx lr */ #endif #ifdef __thumb2__ .macro COND where when i\where \when .endm #else .macro COND where when .endm #endif #if defined(__thumb2__) .macro MODE .thumb .thumb_func .endm .macro PROLOGUE name .endm #elif defined(__thumb__) #define MODE .thumb_func .macro PROLOGUE name .code 16 bx pc nop .code 32 SYM (.arm_start_of.\name): .endm #else /* Arm */ #define MODE .code 32 .macro PROLOGUE name .endm #endif .macro FUNC_START name .text .align 2 MODE .globl SYM (\name) .cfi_sections .debug_frame .cfi_startproc TYPE (\name) SYM (\name): PROLOGUE \name .endm .macro FUNC_END name RET .cfi_endproc SIZE (\name) .endm /* -------------------------------------------------------------------- int setjmp (jmp_buf); -------------------------------------------------------------------- */ FUNC_START setjmp #if __ARM_FEATURE_PAC_DEFAULT # if __ARM_FEATURE_BTI_DEFAULT pacbti ip, lr, sp # else pac ip, lr, sp # endif /* __ARM_FEATURE_BTI_DEFAULT */ mov r3, ip str r3, [r0, #JUMPBUF_PAC] .cfi_register 143, 12 #else # if __ARM_FEATURE_BTI_DEFAULT bti # endif /* __ARM_FEATURE_BTI_DEFAULT */ #endif /* __ARM_FEATURE_PAC_DEFAULT */ /* Save all the callee-preserved registers into the jump buffer. */ #ifdef __thumb2__ mov ip, sp stmia r0!, { r4-r10, fp, ip, lr } #else stmia r0!, { r4-r10, fp, sp, lr } #endif #if defined __ARM_FP || defined __ARM_FEATURE_MVE vstm r0, { d8-d15 } #endif /* When setting up the jump buffer return 0. */ mov r0, #0 #if __ARM_FEATURE_PAC_DEFAULT mov ip, r3 aut ip, lr, sp #endif /* __ARM_FEATURE_PAC_DEFAULT */ FUNC_END setjmp /* -------------------------------------------------------------------- volatile void longjmp (jmp_buf, int); -------------------------------------------------------------------- */ FUNC_START longjmp #if __ARM_FEATURE_BTI_DEFAULT bti #endif /* __ARM_FEATURE_BTI_DEFAULT */ #if __ARM_FEATURE_PAC_DEFAULT /* Keep original jmpbuf address for retrieving pac-code for authentication. */ mov r2, r0 #endif /* __ARM_FEATURE_PAC_DEFAULT */ /* If we have stack extension code it ought to be handled here. */ /* Restore the registers, retrieving the state when setjmp() was called. */ #ifdef __thumb2__ ldmia r0!, { r4-r10, fp, ip, lr } mov sp, ip #else ldmia r0!, { r4-r10, fp, sp, lr } #endif #if defined __ARM_FP || defined __ARM_FEATURE_MVE vldm r0, { d8-d15 } #endif /* Put the return value into the integer result register. But if it is zero then return 1 instead. */ movs r0, r1 it eq moveq r0, #1 #if __ARM_FEATURE_PAC_DEFAULT ldr ip, [r2, #JUMPBUF_PAC] aut ip, lr, sp #endif /* __ARM_FEATURE_PAC_DEFAULT */ FUNC_END longjmp #endif picolibc-1.8.11/libc/machine/arm/strcmp-arm-tiny.S000066400000000000000000000035411513574234600216710ustar00rootroot00000000000000/* * Copyright (c) 2012-2014 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Tiny version of strcmp in ARM state. Used only when optimizing for size. Also supports Thumb-2. */ #include #include "arm_asm.h" .syntax unified def_fn strcmp fnstart .cfi_sections .debug_frame .cfi_startproc prologue 1: ldrb r2, [r0], #1 ldrb r3, [r1], #1 cmp r2, #1 it cs cmpcs r2, r3 beq 1b 2: subs r0, r2, r3 epilogue .cfi_endproc cantunwind fnend .size strcmp, . - strcmp picolibc-1.8.11/libc/machine/arm/strcmp-armv4.S000066400000000000000000000233421513574234600211630ustar00rootroot00000000000000/* * Copyright (c) 2012-2014 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Basic ARM implementation. This should run on anything except for ARMv6-M, but there are better implementations for later revisions of the architecture. This version can support ARMv4T ARM/Thumb interworking. */ /* Parameters and result. */ #include #define src1 r0 #define src2 r1 #define result r0 /* Overlaps src1. */ /* Internal variables. */ #define data1 r2 #define data2 r3 #define magic1 r4 #define tmp2 r5 #define tmp1 r12 #define syndrome r12 /* Overlaps tmp1 */ /* For armv4t and newer, toolchains will transparently convert 'bx lr' to 'mov pc, lr' if needed. GCC has deprecated support for anything older than armv4t, but this should handle that corner case in case anyone needs it anyway */ .macro RETURN #if __ARM_ARCH <= 4 && __ARM_ARCH_ISA_THUMB == 0 mov pc, lr #else bx lr #endif .endm .arm def_fn strcmp .cfi_sections .debug_frame .cfi_startproc eor tmp1, src1, src2 tst tmp1, #3 /* Strings not at same byte offset from a word boundary. */ bne .Lstrcmp_unaligned ands tmp1, src1, #3 bic src1, src1, #3 bic src2, src2, #3 ldr data1, [src1], #4 ldreq data2, [src2], #4 beq 1f /* Although s1 and s2 have identical initial alignment, they are not currently word aligned. Rather than comparing bytes, make sure that any bytes fetched from before the addressed bytes are forced to 0xff. Then they will always compare equal. */ eor tmp1, tmp1, #3 mvn data2, #MSB lsl tmp1, tmp1, #3 S2LO tmp1, data2, tmp1 ldr data2, [src2], #4 orr data1, data1, tmp1 orr data2, data2, tmp1 1: /* Load the 'magic' constant 0x01010101. */ str r4, [sp, #-4]! .cfi_def_cfa_offset 4 .cfi_offset 4, -4 mov magic1, #1 orr magic1, magic1, magic1, lsl #8 orr magic1, magic1, magic1, lsl #16 .p2align 2 4: sub syndrome, data1, magic1 cmp data1, data2 /* check for any zero bytes in first word */ biceq syndrome, syndrome, data1 tsteq syndrome, magic1, lsl #7 ldreq data1, [src1], #4 ldreq data2, [src2], #4 beq 4b 2: /* There's a zero or a different byte in the word */ S2HI result, data1, #24 S2LO data1, data1, #8 cmp result, #1 cmpcs result, data2, S2HI #24 S2LOEQ data2, data2, #8 beq 2b /* On a big-endian machine, RESULT contains the desired byte in bits 0-7; on a little-endian machine they are in bits 24-31. In both cases the other bits in RESULT are all zero. For DATA2 the interesting byte is at the other end of the word, but the other bits are not necessarily zero. We need a signed result representing the differnece in the unsigned bytes, so for the little-endian case we can't just shift the interesting bits up. */ #ifdef __ARM_BIG_ENDIAN sub result, result, data2, lsr #24 #else and data2, data2, #255 rsb result, data2, result, lsr #24 #endif ldr r4, [sp], #4 .cfi_restore 4 .cfi_def_cfa_offset 0 RETURN #if 0 /* The assembly code below is based on the following alogrithm. */ #ifdef __ARM_BIG_ENDIAN #define RSHIFT << #define LSHIFT >> #else #define RSHIFT >> #define LSHIFT << #endif #define body(shift) \ mask = 0xffffffffU RSHIFT shift; \ data1 = *src1++; \ data2 = *src2++; \ do \ { \ tmp2 = data1 & mask; \ if (__builtin_expect(tmp2 != data2 RSHIFT shift, 0)) \ { \ data2 RSHIFT= shift; \ break; \ } \ if (__builtin_expect(((data1 - b1) & ~data1) & (b1 << 7), 0)) \ { \ /* See comment in assembler below re syndrome on big-endian */\ if ((((data1 - b1) & ~data1) & (b1 << 7)) & mask) \ data2 RSHIFT= shift; \ else \ { \ data2 = *src2; \ tmp2 = data1 RSHIFT (32 - shift); \ data2 = (data2 LSHIFT (32 - shift)) RSHIFT (32 - shift); \ } \ break; \ } \ data2 = *src2++; \ tmp2 ^= data1; \ if (__builtin_expect(tmp2 != data2 LSHIFT (32 - shift), 0)) \ { \ tmp2 = data1 >> (32 - shift); \ data2 = (data2 << (32 - shift)) RSHIFT (32 - shift); \ break; \ } \ data1 = *src1++; \ } while (1) const unsigned* src1; const unsigned* src2; unsigned data1, data2; unsigned mask; unsigned shift; unsigned b1 = 0x01010101; char c1, c2; unsigned tmp2; while (((unsigned) s1) & 3) { c1 = *s1++; c2 = *s2++; if (c1 == 0 || c1 != c2) return c1 - (int)c2; } src1 = (unsigned*) (((unsigned)s1) & ~3); src2 = (unsigned*) (((unsigned)s2) & ~3); tmp2 = ((unsigned) s2) & 3; if (tmp2 == 1) { body(8); } else if (tmp2 == 2) { body(16); } else { body (24); } do { #ifdef __ARM_BIG_ENDIAN c1 = (char) tmp2 >> 24; c2 = (char) data2 >> 24; #else /* not __ARM_BIG_ENDIAN */ c1 = (char) tmp2; c2 = (char) data2; #endif /* not __ARM_BIG_ENDIAN */ tmp2 RSHIFT= 8; data2 RSHIFT= 8; } while (c1 != 0 && c1 == c2); return c1 - c2; #endif /* 0 */ /* First of all, compare bytes until src1(sp1) is word-aligned. */ .Lstrcmp_unaligned: tst src1, #3 beq 2f ldrb data1, [src1], #1 ldrb data2, [src2], #1 cmp data1, #1 cmpcs data1, data2 beq .Lstrcmp_unaligned sub result, data1, data2 RETURN 2: stmfd sp!, {r4, r5} .cfi_def_cfa_offset 8 .cfi_offset 4, -8 .cfi_offset 5, -4 mov magic1, #1 orr magic1, magic1, magic1, lsl #8 orr magic1, magic1, magic1, lsl #16 ldr data1, [src1], #4 and tmp2, src2, #3 bic src2, src2, #3 ldr data2, [src2], #4 cmp tmp2, #2 beq .Loverlap2 bhi .Loverlap1 /* Critical inner Loop: Block with 3 bytes initial overlap */ .p2align 2 .Loverlap3: bic tmp2, data1, #MSB cmp tmp2, data2, S2LO #8 sub syndrome, data1, magic1 bic syndrome, syndrome, data1 bne 4f ands syndrome, syndrome, magic1, lsl #7 ldreq data2, [src2], #4 bne 5f eor tmp2, tmp2, data1 cmp tmp2, data2, S2HI #24 bne 6f ldr data1, [src1], #4 b .Loverlap3 4: S2LO data2, data2, #8 b .Lstrcmp_tail 5: #ifdef __ARM_BIG_ENDIAN /* The syndrome value may contain false ones if the string ends with the bytes 0x01 0x00. */ tst data1, #0xff000000 tstne data1, #0x00ff0000 tstne data1, #0x0000ff00 beq .Lstrcmp_done_equal #else bics syndrome, syndrome, #0xff000000 bne .Lstrcmp_done_equal #endif ldrb data2, [src2] S2LO tmp2, data1, #24 #ifdef __ARM_BIG_ENDIAN lsl data2, data2, #24 #endif b .Lstrcmp_tail 6: S2LO tmp2, data1, #24 and data2, data2, #LSB b .Lstrcmp_tail /* Critical inner Loop: Block with 2 bytes initial overlap. */ .p2align 2 .Loverlap2: S2HI tmp2, data1, #16 sub syndrome, data1, magic1 S2LO tmp2, tmp2, #16 bic syndrome, syndrome, data1 cmp tmp2, data2, S2LO #16 bne 4f ands syndrome, syndrome, magic1, lsl #7 ldreq data2, [src2], #4 bne 5f eor tmp2, tmp2, data1 cmp tmp2, data2, S2HI #16 bne 6f ldr data1, [src1], #4 b .Loverlap2 5: #ifdef __ARM_BIG_ENDIAN /* The syndrome value may contain false ones if the string ends with the bytes 0x01 0x00 */ tst data1, #0xff000000 tstne data1, #0x00ff0000 beq .Lstrcmp_done_equal #else lsls syndrome, syndrome, #16 bne .Lstrcmp_done_equal #endif ldrh data2, [src2] S2LO tmp2, data1, #16 #ifdef __ARM_BIG_ENDIAN lsl data2, data2, #16 #endif b .Lstrcmp_tail 6: S2HI data2, data2, #16 S2LO tmp2, data1, #16 4: S2LO data2, data2, #16 b .Lstrcmp_tail /* Critical inner Loop: Block with 1 byte initial overlap. */ .p2align 2 .Loverlap1: and tmp2, data1, #LSB cmp tmp2, data2, S2LO #24 sub syndrome, data1, magic1 bic syndrome, syndrome, data1 bne 4f ands syndrome, syndrome, magic1, lsl #7 ldreq data2, [src2], #4 bne 5f eor tmp2, tmp2, data1 cmp tmp2, data2, S2HI #8 bne 6f ldr data1, [src1], #4 b .Loverlap1 4: S2LO data2, data2, #24 b .Lstrcmp_tail 5: /* The syndrome value may contain false ones if the string ends with the bytes 0x01 0x00. */ tst data1, #LSB beq .Lstrcmp_done_equal ldr data2, [src2], #4 6: S2LO tmp2, data1, #8 bic data2, data2, #MSB b .Lstrcmp_tail .Lstrcmp_done_equal: mov result, #0 .cfi_remember_state ldmfd sp!, {r4, r5} .cfi_restore 4 .cfi_restore 5 .cfi_def_cfa_offset 0 RETURN .Lstrcmp_tail: .cfi_restore_state and r2, tmp2, #LSB and result, data2, #LSB cmp result, #1 cmpcs result, r2 S2LOEQ tmp2, tmp2, #8 S2LOEQ data2, data2, #8 beq .Lstrcmp_tail sub result, r2, result ldmfd sp!, {r4, r5} .cfi_restore 4 .cfi_restore 5 .cfi_def_cfa_offset 0 RETURN .cfi_endproc .size strcmp, . - strcmp picolibc-1.8.11/libc/machine/arm/strcmp-armv4t.S000066400000000000000000000040031513574234600213400ustar00rootroot00000000000000/* * Copyright (c) 2012-2014 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This version is only used when we want a very basic Thumb1 implementation or for size, otherwise we use the base ARMv4 version. This is also suitable for ARMv6-M. */ #include .thumb .syntax unified .arch armv4t .eabi_attribute Tag_also_compatible_with, "\006\013" /* ARMv6-M. */ .eabi_attribute Tag_ARM_ISA_use, 0 def_fn strcmp .cfi_sections .debug_frame .cfi_startproc 1: ldrb r2, [r0] ldrb r3, [r1] cmp r2, #0 beq 2f adds r0, r0, #1 adds r1, r1, #1 cmp r2, r3 beq 1b 2: subs r0, r2, r3 bx lr .cfi_endproc .size strcmp, . - strcmp picolibc-1.8.11/libc/machine/arm/strcmp-armv6.S000066400000000000000000000270421513574234600211660ustar00rootroot00000000000000/* * Copyright (c) 2012-2014 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Implementation of strcmp for ARMv6. Use ldrd to support wider loads, provided the data is sufficiently aligned. Use saturating arithmetic to optimize the compares. */ /* Build Options: STRCMP_NO_PRECHECK: Don't run a quick pre-check of the first byte in the string. If comparing completely random strings the pre-check will save time, since there is a very high probability of a mismatch in the first character: we save significant overhead if this is the common case. However, if strings are likely to be identical (eg because we're verifying a hit in a hash table), then this check is largely redundant. */ #include .arm /* Parameters and result. */ #define src1 r0 #define src2 r1 #define result r0 /* Overlaps src1. */ /* Internal variables. */ #define tmp1 r4 #define tmp2 r5 #define const_m1 r12 /* Additional internal variables for 64-bit aligned data. */ #define data1a r2 #define data1b r3 #define data2a r6 #define data2b r7 #define syndrome_a tmp1 #define syndrome_b tmp2 /* Additional internal variables for 32-bit aligned data. */ #define data1 r2 #define data2 r3 #define syndrome tmp2 /* Macro to compute and return the result value for word-aligned cases. */ .macro strcmp_epilogue_aligned synd d1 d2 restore_r6 #ifdef __ARM_BIG_ENDIAN /* If data1 contains a zero byte, then syndrome will contain a 1 in bit 7 of that byte. Otherwise, the highest set bit in the syndrome will highlight the first different bit. It is therefore sufficient to extract the eight bits starting with the syndrome bit. */ clz tmp1, \synd lsl r1, \d2, tmp1 .if \restore_r6 ldrd r6, r7, [sp, #8] .endif .cfi_restore 6 .cfi_restore 7 lsl \d1, \d1, tmp1 .cfi_remember_state lsr result, \d1, #24 ldrd r4, r5, [sp], #16 .cfi_restore 4 .cfi_restore 5 sub result, result, r1, lsr #24 bx lr #else /* To use the big-endian trick we'd have to reverse all three words. that's slower than this approach. */ rev \synd, \synd clz tmp1, \synd bic tmp1, tmp1, #7 lsr r1, \d2, tmp1 .cfi_remember_state .if \restore_r6 ldrd r6, r7, [sp, #8] .endif .cfi_restore 6 .cfi_restore 7 lsr \d1, \d1, tmp1 and result, \d1, #255 and r1, r1, #255 ldrd r4, r5, [sp], #16 .cfi_restore 4 .cfi_restore 5 sub result, result, r1 bx lr #endif .endm .text .p2align 5 .Lstrcmp_start_addr: #ifndef STRCMP_NO_PRECHECK .Lfastpath_exit: sub r0, r2, r3 bx lr #endif def_fn strcmp #ifndef STRCMP_NO_PRECHECK ldrb r2, [src1] ldrb r3, [src2] cmp r2, #1 cmpcs r2, r3 bne .Lfastpath_exit #endif .cfi_sections .debug_frame .cfi_startproc strd r4, r5, [sp, #-16]! .cfi_def_cfa_offset 16 .cfi_offset 4, -16 .cfi_offset 5, -12 orr tmp1, src1, src2 strd r6, r7, [sp, #8] .cfi_offset 6, -8 .cfi_offset 7, -4 mvn const_m1, #0 tst tmp1, #7 beq .Lloop_aligned8 .Lnot_aligned: eor tmp1, src1, src2 tst tmp1, #7 bne .Lmisaligned8 /* Deal with mutual misalignment by aligning downwards and then masking off the unwanted loaded data to prevent a difference. */ and tmp1, src1, #7 bic src1, src1, #7 and tmp2, tmp1, #3 bic src2, src2, #7 lsl tmp2, tmp2, #3 /* Bytes -> bits. */ ldrd data1a, data1b, [src1], #16 tst tmp1, #4 ldrd data2a, data2b, [src2], #16 /* In ARM code we can't use ORN, but with do have MVN with a register shift. */ mvn tmp1, const_m1, S2HI tmp2 orr data1a, data1a, tmp1 orr data2a, data2a, tmp1 beq .Lstart_realigned8 orr data1b, data1b, tmp1 mov data1a, const_m1 orr data2b, data2b, tmp1 mov data2a, const_m1 b .Lstart_realigned8 /* Unwind the inner loop by a factor of 2, giving 16 bytes per pass. */ .p2align 5,,12 /* Don't start in the tail bytes of a cache line. */ .p2align 2 /* Always word aligned. */ .Lloop_aligned8: ldrd data1a, data1b, [src1], #16 ldrd data2a, data2b, [src2], #16 .Lstart_realigned8: uadd8 syndrome_b, data1a, const_m1 /* Only want GE bits, */ eor syndrome_a, data1a, data2a sel syndrome_a, syndrome_a, const_m1 uadd8 syndrome_b, data1b, const_m1 /* Only want GE bits. */ eor syndrome_b, data1b, data2b sel syndrome_b, syndrome_b, const_m1 orrs syndrome_b, syndrome_b, syndrome_a /* Only need if s_a == 0 */ bne .Ldiff_found ldrd data1a, data1b, [src1, #-8] ldrd data2a, data2b, [src2, #-8] uadd8 syndrome_b, data1a, const_m1 /* Only want GE bits, */ eor syndrome_a, data1a, data2a sel syndrome_a, syndrome_a, const_m1 uadd8 syndrome_b, data1b, const_m1 /* Only want GE bits. */ eor syndrome_b, data1b, data2b sel syndrome_b, syndrome_b, const_m1 orrs syndrome_b, syndrome_b, syndrome_a /* Only need if s_a == 0 */ beq .Lloop_aligned8 .Ldiff_found: cmp syndrome_a, #0 bne .Ldiff_in_a .Ldiff_in_b: strcmp_epilogue_aligned syndrome_b, data1b, data2b 1 .Ldiff_in_a: .cfi_restore_state strcmp_epilogue_aligned syndrome_a, data1a, data2a 1 .cfi_restore_state .Lmisaligned8: tst tmp1, #3 bne .Lmisaligned4 ands tmp1, src1, #3 bne .Lmutual_align4 /* Unrolled by a factor of 2, to reduce the number of post-increment operations. */ .Lloop_aligned4: ldr data1, [src1], #8 ldr data2, [src2], #8 .Lstart_realigned4: uadd8 syndrome, data1, const_m1 /* Only need GE bits. */ eor syndrome, data1, data2 sel syndrome, syndrome, const_m1 cmp syndrome, #0 bne .Laligned4_done ldr data1, [src1, #-4] ldr data2, [src2, #-4] uadd8 syndrome, data1, const_m1 eor syndrome, data1, data2 sel syndrome, syndrome, const_m1 cmp syndrome, #0 beq .Lloop_aligned4 .Laligned4_done: strcmp_epilogue_aligned syndrome, data1, data2, 0 .Lmutual_align4: .cfi_restore_state /* Deal with mutual misalignment by aligning downwards and then masking off the unwanted loaded data to prevent a difference. */ lsl tmp1, tmp1, #3 /* Bytes -> bits. */ bic src1, src1, #3 ldr data1, [src1], #8 bic src2, src2, #3 ldr data2, [src2], #8 /* In ARM code we can't use ORN, but with do have MVN with a register shift. */ mvn tmp1, const_m1, S2HI tmp1 orr data1, data1, tmp1 orr data2, data2, tmp1 b .Lstart_realigned4 .Lmisaligned4: ands tmp1, src1, #3 beq .Lsrc1_aligned sub src2, src2, tmp1 bic src1, src1, #3 lsls tmp1, tmp1, #31 ldr data1, [src1], #4 beq .Laligned_m2 bcs .Laligned_m1 #ifdef STRCMP_NO_PRECHECK ldrb data2, [src2, #1] uxtb tmp1, data1, ror #BYTE1_OFFSET cmp tmp1, #1 cmpcs tmp1, data2 bne .Lmisaligned_exit .Laligned_m2: ldrb data2, [src2, #2] uxtb tmp1, data1, ror #BYTE2_OFFSET cmp tmp1, #1 cmpcs tmp1, data2 bne .Lmisaligned_exit .Laligned_m1: ldrb data2, [src2, #3] uxtb tmp1, data1, ror #BYTE3_OFFSET cmp tmp1, #1 cmpcs tmp1, data2 beq .Lsrc1_aligned #else /* STRCMP_NO_PRECHECK */ /* If we've done the pre-check, then we don't need to check the first byte again here. */ ldrb data2, [src2, #2] uxtb tmp1, data1, ror #BYTE2_OFFSET cmp tmp1, #1 cmpcs tmp1, data2 bne .Lmisaligned_exit .Laligned_m2: ldrb data2, [src2, #3] uxtb tmp1, data1, ror #BYTE3_OFFSET cmp tmp1, #1 cmpcs tmp1, data2 beq .Laligned_m1 #endif .Lmisaligned_exit: .cfi_remember_state sub result, tmp1, data2 ldr r4, [sp], #16 .cfi_restore 4 bx lr #ifndef STRCMP_NO_PRECHECK .Laligned_m1: add src2, src2, #4 #endif .Lsrc1_aligned: .cfi_restore_state /* src1 is word aligned, but src2 has no common alignment with it. */ ldr data1, [src1], #4 lsls tmp1, src2, #31 /* C=src2[1], Z=src2[0]. */ bic src2, src2, #3 ldr data2, [src2], #4 bhi .Loverlap1 /* C=1, Z=0 => src2[1:0] = 0b11. */ bcs .Loverlap2 /* C=1, Z=1 => src2[1:0] = 0b10. */ /* (overlap3) C=0, Z=0 => src2[1:0] = 0b01. */ .Loverlap3: bic tmp1, data1, #MSB uadd8 syndrome, data1, const_m1 eors syndrome, tmp1, data2, S2LO #8 sel syndrome, syndrome, const_m1 bne 4f cmp syndrome, #0 ldreq data2, [src2], #4 bne 5f eor tmp1, tmp1, data1 cmp tmp1, data2, S2HI #24 bne 6f ldr data1, [src1], #4 b .Loverlap3 4: S2LO data2, data2, #8 b .Lstrcmp_tail 5: bics syndrome, syndrome, #MSB bne .Lstrcmp_done_equal /* We can only get here if the MSB of data1 contains 0, so fast-path the exit. */ ldrb result, [src2] .cfi_remember_state ldrd r4, r5, [sp], #16 .cfi_restore 4 .cfi_restore 5 /* R6/7 Not used in this sequence. */ .cfi_restore 6 .cfi_restore 7 neg result, result bx lr 6: .cfi_restore_state S2LO data1, data1, #24 and data2, data2, #LSB b .Lstrcmp_tail .p2align 5,,12 /* Ensure at least 3 instructions in cache line. */ .Loverlap2: and tmp1, data1, const_m1, S2LO #16 uadd8 syndrome, data1, const_m1 eors syndrome, tmp1, data2, S2LO #16 sel syndrome, syndrome, const_m1 bne 4f cmp syndrome, #0 ldreq data2, [src2], #4 bne 5f eor tmp1, tmp1, data1 cmp tmp1, data2, S2HI #16 bne 6f ldr data1, [src1], #4 b .Loverlap2 4: S2LO data2, data2, #16 b .Lstrcmp_tail 5: ands syndrome, syndrome, const_m1, S2LO #16 bne .Lstrcmp_done_equal ldrh data2, [src2] S2LO data1, data1, #16 #ifdef __ARM_BIG_ENDIAN lsl data2, data2, #16 #endif b .Lstrcmp_tail 6: S2LO data1, data1, #16 and data2, data2, const_m1, S2LO #16 b .Lstrcmp_tail .p2align 5,,12 /* Ensure at least 3 instructions in cache line. */ .Loverlap1: and tmp1, data1, #LSB uadd8 syndrome, data1, const_m1 eors syndrome, tmp1, data2, S2LO #24 sel syndrome, syndrome, const_m1 bne 4f cmp syndrome, #0 ldreq data2, [src2], #4 bne 5f eor tmp1, tmp1, data1 cmp tmp1, data2, S2HI #8 bne 6f ldr data1, [src1], #4 b .Loverlap1 4: S2LO data2, data2, #24 b .Lstrcmp_tail 5: tst syndrome, #LSB bne .Lstrcmp_done_equal ldr data2, [src2] 6: S2LO data1, data1, #8 bic data2, data2, #MSB b .Lstrcmp_tail .Lstrcmp_done_equal: mov result, #0 .cfi_remember_state ldrd r4, r5, [sp], #16 .cfi_restore 4 .cfi_restore 5 /* R6/7 not used in this sequence. */ .cfi_restore 6 .cfi_restore 7 bx lr .Lstrcmp_tail: .cfi_restore_state #ifndef __ARM_BIG_ENDIAN rev data1, data1 rev data2, data2 /* Now everything looks big-endian... */ #endif uadd8 tmp1, data1, const_m1 eor tmp1, data1, data2 sel syndrome, tmp1, const_m1 clz tmp1, syndrome lsl data1, data1, tmp1 lsl data2, data2, tmp1 lsr result, data1, #24 ldrd r4, r5, [sp], #16 .cfi_restore 4 .cfi_restore 5 /* R6/7 not used in this sequence. */ .cfi_restore 6 .cfi_restore 7 sub result, result, data2, lsr #24 bx lr .cfi_endproc .size strcmp, . - .Lstrcmp_start_addr picolibc-1.8.11/libc/machine/arm/strcmp-armv6m.S000066400000000000000000000061121513574234600213360ustar00rootroot00000000000000/* * Copyright (c) 2014 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Implementation of strcmp for ARMv6m. This version is only used in ARMv6-M when we want an efficient implementation. Otherwize if the code size is preferred, strcmp-armv4t.S will be used. */ #include .thumb_func .syntax unified .arch armv6-m .macro DoSub n, label subs r0, r0, r1 #ifdef __ARM_BIG_ENDIAN lsrs r1, r4, \n #else lsls r1, r4, \n #endif orrs r1, r0 bne \label .endm .macro Byte_Test n, label lsrs r0, r2, \n lsrs r1, r3, \n DoSub \n, \label .endm .text def_fn strcmp .cfi_sections .debug_frame .cfi_startproc mov r2, r0 push {r4, r5, r6, lr} orrs r2, r1 lsls r2, r2, #30 bne 6f ldr r5, =0x01010101 lsls r6, r5, #7 1: ldmia r0!, {r2} ldmia r1!, {r3} subs r4, r2, r5 bics r4, r2 ands r4, r6 beq 3f #ifdef __ARM_BIG_ENDIAN Byte_Test #24, 4f Byte_Test #16, 4f Byte_Test #8, 4f b 7f 3: cmp r2, r3 beq 1b cmp r2, r3 #else uxtb r0, r2 uxtb r1, r3 DoSub #24, 2f uxth r0, r2 uxth r1, r3 DoSub #16, 2f lsls r0, r2, #8 lsls r1, r3, #8 lsrs r0, r0, #8 lsrs r1, r1, #8 DoSub #8, 2f lsrs r0, r2, #24 lsrs r1, r3, #24 subs r0, r0, r1 2: pop {r4, r5, r6, pc} 3: cmp r2, r3 beq 1b rev r0, r2 rev r1, r3 cmp r0, r1 #endif bls 5f movs r0, #1 4: pop {r4, r5, r6, pc} 5: movs r0, #0 mvns r0, r0 pop {r4, r5, r6, pc} 6: ldrb r2, [r0, #0] ldrb r3, [r1, #0] adds r0, #1 adds r1, #1 cmp r2, #0 beq 7f cmp r2, r3 bne 7f ldrb r2, [r0, #0] ldrb r3, [r1, #0] adds r0, #1 adds r1, #1 cmp r2, #0 beq 7f cmp r2, r3 beq 6b 7: subs r0, r2, r3 pop {r4, r5, r6, pc} .cfi_endproc .size strcmp, . - strcmp picolibc-1.8.11/libc/machine/arm/strcmp-armv7.S000066400000000000000000000302601513574234600211630ustar00rootroot00000000000000/* * Copyright (c) 2012-2014 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Implementation of strcmp for ARMv7 when DSP instructions are available. Use ldrd to support wider loads, provided the data is sufficiently aligned. Use saturating arithmetic to optimize the compares. */ /* Build Options: STRCMP_NO_PRECHECK: Don't run a quick pre-check of the first byte in the string. If comparing completely random strings the pre-check will save time, since there is a very high probability of a mismatch in the first character: we save significant overhead if this is the common case. However, if strings are likely to be identical (eg because we're verifying a hit in a hash table), then this check is largely redundant. */ /* This version uses Thumb-2 code. */ #include .thumb .syntax unified #include "arm_asm.h" /* Parameters and result. */ #define src1 r0 #define src2 r1 #define result r0 /* Overlaps src1. */ /* Internal variables. */ #define tmp1 r4 #define tmp2 r5 #define const_m1 r12 /* Additional internal variables for 64-bit aligned data. */ #define data1a r2 #define data1b r3 #define data2a r6 #define data2b r7 #define syndrome_a tmp1 #define syndrome_b tmp2 /* Additional internal variables for 32-bit aligned data. */ #define data1 r2 #define data2 r3 #define syndrome tmp2 /* Macro to compute and return the result value for word-aligned cases. */ .macro strcmp_epilogue_aligned synd d1 d2 restore_r6 #ifdef __ARM_BIG_ENDIAN /* If data1 contains a zero byte, then syndrome will contain a 1 in bit 7 of that byte. Otherwise, the highest set bit in the syndrome will highlight the first different bit. It is therefore sufficient to extract the eight bits starting with the syndrome bit. */ clz tmp1, \synd lsl r1, \d2, tmp1 .if \restore_r6 ldrd r6, r7, [sp, #8] .endif .cfi_restore 6 .cfi_restore 7 lsl \d1, \d1, tmp1 .cfi_remember_state lsr result, \d1, #24 ldrd r4, r5, [sp], #16 .cfi_restore 4 .cfi_restore 5 .cfi_adjust_cfa_offset -16 sub result, result, r1, lsr #24 epilogue push_ip=HAVE_PAC_LEAF #else /* To use the big-endian trick we'd have to reverse all three words. that's slower than this approach. */ rev \synd, \synd clz tmp1, \synd bic tmp1, tmp1, #7 lsr r1, \d2, tmp1 .cfi_remember_state .if \restore_r6 ldrd r6, r7, [sp, #8] .endif .cfi_restore 6 .cfi_restore 7 lsr \d1, \d1, tmp1 and result, \d1, #255 and r1, r1, #255 ldrd r4, r5, [sp], #16 .cfi_restore 4 .cfi_restore 5 .cfi_adjust_cfa_offset -16 sub result, result, r1 epilogue push_ip=HAVE_PAC_LEAF #endif .endm .text .p2align 5 def_fn strcmp fnstart .cfi_sections .debug_frame .cfi_startproc prologue push_ip=HAVE_PAC_LEAF #ifndef STRCMP_NO_PRECHECK ldrb r2, [src1] ldrb r3, [src2] cmp r2, #1 it cs cmpcs r2, r3 bne .Lfastpath_exit #endif strd r4, r5, [sp, #-16]! .cfi_adjust_cfa_offset 16 .cfi_rel_offset 4, 0 .cfi_rel_offset 5, 4 orr tmp1, src1, src2 strd r6, r7, [sp, #8] .cfi_rel_offset 6, 8 .cfi_rel_offset 7, 12 mvn const_m1, #0 lsl r2, tmp1, #29 cbz r2, .Lloop_aligned8 .Lnot_aligned: eor tmp1, src1, src2 tst tmp1, #7 bne .Lmisaligned8 /* Deal with mutual misalignment by aligning downwards and then masking off the unwanted loaded data to prevent a difference. */ and tmp1, src1, #7 bic src1, src1, #7 and tmp2, tmp1, #3 bic src2, src2, #7 lsl tmp2, tmp2, #3 /* Bytes -> bits. */ ldrd data1a, data1b, [src1], #16 tst tmp1, #4 ldrd data2a, data2b, [src2], #16 /* In thumb code we can't use MVN with a register shift, but we do have ORN. */ S2HI tmp1, const_m1, tmp2 orn data1a, data1a, tmp1 orn data2a, data2a, tmp1 beq .Lstart_realigned8 orn data1b, data1b, tmp1 mov data1a, const_m1 orn data2b, data2b, tmp1 mov data2a, const_m1 b .Lstart_realigned8 /* Unwind the inner loop by a factor of 2, giving 16 bytes per pass. */ .p2align 5,,12 /* Don't start in the tail bytes of a cache line. */ .p2align 2 /* Always word aligned. */ .Lloop_aligned8: ldrd data1a, data1b, [src1], #16 ldrd data2a, data2b, [src2], #16 .Lstart_realigned8: uadd8 syndrome_b, data1a, const_m1 /* Only want GE bits, */ eor syndrome_a, data1a, data2a sel syndrome_a, syndrome_a, const_m1 cbnz syndrome_a, .Ldiff_in_a uadd8 syndrome_b, data1b, const_m1 /* Only want GE bits. */ eor syndrome_b, data1b, data2b sel syndrome_b, syndrome_b, const_m1 cbnz syndrome_b, .Ldiff_in_b ldrd data1a, data1b, [src1, #-8] ldrd data2a, data2b, [src2, #-8] uadd8 syndrome_b, data1a, const_m1 /* Only want GE bits, */ eor syndrome_a, data1a, data2a sel syndrome_a, syndrome_a, const_m1 uadd8 syndrome_b, data1b, const_m1 /* Only want GE bits. */ eor syndrome_b, data1b, data2b sel syndrome_b, syndrome_b, const_m1 /* Can't use CBZ for backwards branch. */ orrs syndrome_b, syndrome_b, syndrome_a /* Only need if s_a == 0 */ beq .Lloop_aligned8 .Ldiff_found: cbnz syndrome_a, .Ldiff_in_a .Ldiff_in_b: strcmp_epilogue_aligned syndrome_b, data1b, data2b 1 .Ldiff_in_a: .cfi_restore_state strcmp_epilogue_aligned syndrome_a, data1a, data2a 1 .cfi_restore_state .Lmisaligned8: tst tmp1, #3 bne .Lmisaligned4 ands tmp1, src1, #3 bne .Lmutual_align4 /* Unrolled by a factor of 2, to reduce the number of post-increment operations. */ .Lloop_aligned4: ldr data1, [src1], #8 ldr data2, [src2], #8 .Lstart_realigned4: uadd8 syndrome, data1, const_m1 /* Only need GE bits. */ eor syndrome, data1, data2 sel syndrome, syndrome, const_m1 cbnz syndrome, .Laligned4_done ldr data1, [src1, #-4] ldr data2, [src2, #-4] uadd8 syndrome, data1, const_m1 eor syndrome, data1, data2 sel syndrome, syndrome, const_m1 cmp syndrome, #0 beq .Lloop_aligned4 .Laligned4_done: strcmp_epilogue_aligned syndrome, data1, data2, 0 .Lmutual_align4: .cfi_restore_state /* Deal with mutual misalignment by aligning downwards and then masking off the unwanted loaded data to prevent a difference. */ lsl tmp1, tmp1, #3 /* Bytes -> bits. */ bic src1, src1, #3 ldr data1, [src1], #8 bic src2, src2, #3 ldr data2, [src2], #8 /* In thumb code we can't use MVN with a register shift, but we do have ORN. */ S2HI tmp1, const_m1, tmp1 orn data1, data1, tmp1 orn data2, data2, tmp1 b .Lstart_realigned4 .Lmisaligned4: ands tmp1, src1, #3 beq .Lsrc1_aligned sub src2, src2, tmp1 bic src1, src1, #3 lsls tmp1, tmp1, #31 ldr data1, [src1], #4 beq .Laligned_m2 bcs .Laligned_m1 #ifdef STRCMP_NO_PRECHECK ldrb data2, [src2, #1] uxtb tmp1, data1, ror #BYTE1_OFFSET subs tmp1, tmp1, data2 bne .Lmisaligned_exit cbz data2, .Lmisaligned_exit .Laligned_m2: ldrb data2, [src2, #2] uxtb tmp1, data1, ror #BYTE2_OFFSET subs tmp1, tmp1, data2 bne .Lmisaligned_exit cbz data2, .Lmisaligned_exit .Laligned_m1: ldrb data2, [src2, #3] uxtb tmp1, data1, ror #BYTE3_OFFSET subs tmp1, tmp1, data2 bne .Lmisaligned_exit add src2, src2, #4 cbnz data2, .Lsrc1_aligned #else /* STRCMP_NO_PRECHECK */ /* If we've done the pre-check, then we don't need to check the first byte again here. */ ldrb data2, [src2, #2] uxtb tmp1, data1, ror #BYTE2_OFFSET subs tmp1, tmp1, data2 bne .Lmisaligned_exit cbz data2, .Lmisaligned_exit .Laligned_m2: ldrb data2, [src2, #3] uxtb tmp1, data1, ror #BYTE3_OFFSET subs tmp1, tmp1, data2 bne .Lmisaligned_exit cbnz data2, .Laligned_m1 #endif .Lmisaligned_exit: .cfi_remember_state mov result, tmp1 ldr r4, [sp], #16 .cfi_restore 4 .cfi_adjust_cfa_offset -16 epilogue push_ip=HAVE_PAC_LEAF #ifndef STRCMP_NO_PRECHECK .Lfastpath_exit: .cfi_restore_state .cfi_remember_state sub r0, r2, r3 epilogue push_ip=HAVE_PAC_LEAF .Laligned_m1: .cfi_restore_state .cfi_remember_state add src2, src2, #4 #endif .Lsrc1_aligned: .cfi_restore_state /* src1 is word aligned, but src2 has no common alignment with it. */ ldr data1, [src1], #4 lsls tmp1, src2, #31 /* C=src2[1], Z=src2[0]. */ bic src2, src2, #3 ldr data2, [src2], #4 bhi .Loverlap1 /* C=1, Z=0 => src2[1:0] = 0b11. */ bcs .Loverlap2 /* C=1, Z=1 => src2[1:0] = 0b10. */ /* (overlap3) C=0, Z=0 => src2[1:0] = 0b01. */ .Loverlap3: bic tmp1, data1, #MSB uadd8 syndrome, data1, const_m1 eors syndrome, tmp1, data2, S2LO #8 sel syndrome, syndrome, const_m1 bne 4f cbnz syndrome, 5f ldr data2, [src2], #4 eor tmp1, tmp1, data1 cmp tmp1, data2, S2HI #24 bne 6f ldr data1, [src1], #4 b .Loverlap3 4: S2LO data2, data2, #8 b .Lstrcmp_tail 5: bics syndrome, syndrome, #MSB bne .Lstrcmp_done_equal /* We can only get here if the MSB of data1 contains 0, so fast-path the exit. */ ldrb result, [src2] .cfi_remember_state ldrd r4, r5, [sp], #16 .cfi_restore 4 .cfi_restore 5 /* R6/7 Not used in this sequence. */ .cfi_restore 6 .cfi_restore 7 .cfi_adjust_cfa_offset -16 neg result, result epilogue push_ip=HAVE_PAC_LEAF 6: .cfi_restore_state S2LO data1, data1, #24 and data2, data2, #LSB b .Lstrcmp_tail .p2align 5,,12 /* Ensure at least 3 instructions in cache line. */ .Loverlap2: and tmp1, data1, const_m1, S2LO #16 uadd8 syndrome, data1, const_m1 eors syndrome, tmp1, data2, S2LO #16 sel syndrome, syndrome, const_m1 bne 4f cbnz syndrome, 5f ldr data2, [src2], #4 eor tmp1, tmp1, data1 cmp tmp1, data2, S2HI #16 bne 6f ldr data1, [src1], #4 b .Loverlap2 4: S2LO data2, data2, #16 b .Lstrcmp_tail 5: ands syndrome, syndrome, const_m1, S2LO #16 bne .Lstrcmp_done_equal ldrh data2, [src2] S2LO data1, data1, #16 #ifdef __ARM_BIG_ENDIAN lsl data2, data2, #16 #endif b .Lstrcmp_tail 6: S2LO data1, data1, #16 and data2, data2, const_m1, S2LO #16 b .Lstrcmp_tail .p2align 5,,12 /* Ensure at least 3 instructions in cache line. */ .Loverlap1: and tmp1, data1, #LSB uadd8 syndrome, data1, const_m1 eors syndrome, tmp1, data2, S2LO #24 sel syndrome, syndrome, const_m1 bne 4f cbnz syndrome, 5f ldr data2, [src2], #4 eor tmp1, tmp1, data1 cmp tmp1, data2, S2HI #8 bne 6f ldr data1, [src1], #4 b .Loverlap1 4: S2LO data2, data2, #24 b .Lstrcmp_tail 5: tst syndrome, #LSB bne .Lstrcmp_done_equal ldr data2, [src2] 6: S2LO data1, data1, #8 bic data2, data2, #MSB b .Lstrcmp_tail .Lstrcmp_done_equal: mov result, #0 .cfi_remember_state ldrd r4, r5, [sp], #16 .cfi_restore 4 .cfi_restore 5 /* R6/7 not used in this sequence. */ .cfi_restore 6 .cfi_restore 7 .cfi_adjust_cfa_offset -16 epilogue push_ip=HAVE_PAC_LEAF .Lstrcmp_tail: .cfi_restore_state #ifndef __ARM_BIG_ENDIAN rev data1, data1 rev data2, data2 /* Now everything looks big-endian... */ #endif uadd8 tmp1, data1, const_m1 eor tmp1, data1, data2 sel syndrome, tmp1, const_m1 clz tmp1, syndrome lsl data1, data1, tmp1 lsl data2, data2, tmp1 lsr result, data1, #24 ldrd r4, r5, [sp], #16 .cfi_restore 4 .cfi_restore 5 /* R6/7 not used in this sequence. */ .cfi_restore 6 .cfi_restore 7 .cfi_adjust_cfa_offset -16 sub result, result, data2, lsr #24 epilogue push_ip=HAVE_PAC_LEAF .cfi_endproc cantunwind fnend .size strcmp, . - strcmp picolibc-1.8.11/libc/machine/arm/strcmp-armv7m.S000066400000000000000000000224011513574234600213360ustar00rootroot00000000000000/* * Copyright (c) 2012-2014 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Very similar to the generic code, but uses Thumb2 as implemented in ARMv7-M. */ #include #include "arm_asm.h" /* Parameters and result. */ #define src1 r0 #define src2 r1 #define result r0 /* Overlaps src1. */ /* Internal variables. */ #define data1 r2 #define data2 r3 #define tmp2 r5 #define tmp1 r12 #define syndrome r12 /* Overlaps tmp1 */ .thumb .syntax unified def_fn strcmp fnstart .cfi_sections .debug_frame .cfi_startproc prologue push_ip=HAVE_PAC_LEAF eor tmp1, src1, src2 tst tmp1, #3 /* Strings not at same byte offset from a word boundary. */ bne .Lstrcmp_unaligned ands tmp1, src1, #3 bic src1, src1, #3 bic src2, src2, #3 ldr data1, [src1], #4 it eq ldreq data2, [src2], #4 beq 4f /* Although s1 and s2 have identical initial alignment, they are not currently word aligned. Rather than comparing bytes, make sure that any bytes fetched from before the addressed bytes are forced to 0xff. Then they will always compare equal. */ eor tmp1, tmp1, #3 mvn data2, #MSB lsl tmp1, tmp1, #3 S2LO tmp1, data2, tmp1 ldr data2, [src2], #4 orr data1, data1, tmp1 orr data2, data2, tmp1 .p2align 2 /* Critical loop. */ 4: sub syndrome, data1, #0x01010101 cmp data1, data2 /* check for any zero bytes in first word */ itttt eq biceq syndrome, syndrome, data1 tsteq syndrome, #0x80808080 ldreq data1, [src1], #4 ldreq data2, [src2], #4 beq 4b 2: .cfi_remember_state /* There's a zero or a different byte in the word */ S2HI result, data1, #24 S2LO data1, data1, #8 cmp result, #1 it cs cmpcs result, data2, S2HI #24 it eq S2LOEQ data2, data2, #8 beq 2b /* On a big-endian machine, RESULT contains the desired byte in bits 0-7; on a little-endian machine they are in bits 24-31. In both cases the other bits in RESULT are all zero. For DATA2 the interesting byte is at the other end of the word, but the other bits are not necessarily zero. We need a signed result representing the differnece in the unsigned bytes, so for the little-endian case we can't just shift the interesting bits up. */ #ifdef __ARM_BIG_ENDIAN sub result, result, data2, lsr #24 #else and data2, data2, #255 lsrs result, result, #24 subs result, result, data2 #endif epilogue push_ip=HAVE_PAC_LEAF #if 0 /* The assembly code below is based on the following alogrithm. */ #ifdef __ARM_BIG_ENDIAN #define RSHIFT << #define LSHIFT >> #else #define RSHIFT >> #define LSHIFT << #endif #define body(shift) \ mask = 0xffffffffU RSHIFT shift; \ data1 = *src1++; \ data2 = *src2++; \ do \ { \ tmp2 = data1 & mask; \ if (__builtin_expect(tmp2 != data2 RSHIFT shift, 0)) \ { \ data2 RSHIFT= shift; \ break; \ } \ if (__builtin_expect(((data1 - b1) & ~data1) & (b1 << 7), 0)) \ { \ /* See comment in assembler below re syndrome on big-endian */\ if ((((data1 - b1) & ~data1) & (b1 << 7)) & mask) \ data2 RSHIFT= shift; \ else \ { \ data2 = *src2; \ tmp2 = data1 RSHIFT (32 - shift); \ data2 = (data2 LSHIFT (32 - shift)) RSHIFT (32 - shift); \ } \ break; \ } \ data2 = *src2++; \ tmp2 ^= data1; \ if (__builtin_expect(tmp2 != data2 LSHIFT (32 - shift), 0)) \ { \ tmp2 = data1 >> (32 - shift); \ data2 = (data2 << (32 - shift)) RSHIFT (32 - shift); \ break; \ } \ data1 = *src1++; \ } while (1) const unsigned* src1; const unsigned* src2; unsigned data1, data2; unsigned mask; unsigned shift; unsigned b1 = 0x01010101; char c1, c2; unsigned tmp2; while (((unsigned) s1) & 3) { c1 = *s1++; c2 = *s2++; if (c1 == 0 || c1 != c2) return c1 - (int)c2; } src1 = (unsigned*) (((unsigned)s1) & ~3); src2 = (unsigned*) (((unsigned)s2) & ~3); tmp2 = ((unsigned) s2) & 3; if (tmp2 == 1) { body(8); } else if (tmp2 == 2) { body(16); } else { body (24); } do { #ifdef __ARM_BIG_ENDIAN c1 = (char) tmp2 >> 24; c2 = (char) data2 >> 24; #else /* not __ARM_BIG_ENDIAN */ c1 = (char) tmp2; c2 = (char) data2; #endif /* not __ARM_BIG_ENDIAN */ tmp2 RSHIFT= 8; data2 RSHIFT= 8; } while (c1 != 0 && c1 == c2); return c1 - c2; #endif /* 0 */ /* First of all, compare bytes until src1(sp1) is word-aligned. */ .Lstrcmp_unaligned: .cfi_restore_state tst src1, #3 beq 2f .cfi_remember_state ldrb data1, [src1], #1 ldrb data2, [src2], #1 cmp data1, #1 it cs cmpcs data1, data2 beq .Lstrcmp_unaligned sub result, data1, data2 epilogue push_ip=HAVE_PAC_LEAF 2: .cfi_restore_state stmfd sp!, {r5} .cfi_adjust_cfa_offset 4 .cfi_rel_offset 5, 0 ldr data1, [src1], #4 and tmp2, src2, #3 bic src2, src2, #3 ldr data2, [src2], #4 cmp tmp2, #2 beq .Loverlap2 bhi .Loverlap1 /* Critical inner Loop: Block with 3 bytes initial overlap */ .p2align 2 .Loverlap3: bic tmp2, data1, #MSB cmp tmp2, data2, S2LO #8 sub syndrome, data1, #0x01010101 bic syndrome, syndrome, data1 bne 4f ands syndrome, syndrome, #0x80808080 it eq ldreq data2, [src2], #4 bne 5f eor tmp2, tmp2, data1 cmp tmp2, data2, S2HI #24 bne 6f ldr data1, [src1], #4 b .Loverlap3 4: S2LO data2, data2, #8 b .Lstrcmp_tail 5: #ifdef __ARM_BIG_ENDIAN /* The syndrome value may contain false ones if the string ends with the bytes 0x01 0x00. */ tst data1, #0xff000000 itt ne tstne data1, #0x00ff0000 tstne data1, #0x0000ff00 beq .Lstrcmp_done_equal #else bics syndrome, syndrome, #0xff000000 bne .Lstrcmp_done_equal #endif ldrb data2, [src2] S2LO tmp2, data1, #24 #ifdef __ARM_BIG_ENDIAN lsl data2, data2, #24 #endif b .Lstrcmp_tail 6: S2LO tmp2, data1, #24 and data2, data2, #LSB b .Lstrcmp_tail /* Critical inner Loop: Block with 2 bytes initial overlap. */ .p2align 2 .Loverlap2: S2HI tmp2, data1, #16 sub syndrome, data1, #0x01010101 S2LO tmp2, tmp2, #16 bic syndrome, syndrome, data1 cmp tmp2, data2, S2LO #16 bne 4f ands syndrome, syndrome, #0x80808080 it eq ldreq data2, [src2], #4 bne 5f eor tmp2, tmp2, data1 cmp tmp2, data2, S2HI #16 bne 6f ldr data1, [src1], #4 b .Loverlap2 5: #ifdef __ARM_BIG_ENDIAN /* The syndrome value may contain false ones if the string ends with the bytes 0x01 0x00 */ tst data1, #0xff000000 it ne tstne data1, #0x00ff0000 beq .Lstrcmp_done_equal #else lsls syndrome, syndrome, #16 bne .Lstrcmp_done_equal #endif ldrh data2, [src2] S2LO tmp2, data1, #16 #ifdef __ARM_BIG_ENDIAN lsl data2, data2, #16 #endif b .Lstrcmp_tail 6: S2HI data2, data2, #16 S2LO tmp2, data1, #16 4: S2LO data2, data2, #16 b .Lstrcmp_tail /* Critical inner Loop: Block with 1 byte initial overlap. */ .p2align 2 .Loverlap1: and tmp2, data1, #LSB cmp tmp2, data2, S2LO #24 sub syndrome, data1, #0x01010101 bic syndrome, syndrome, data1 bne 4f ands syndrome, syndrome, #0x80808080 it eq ldreq data2, [src2], #4 bne 5f eor tmp2, tmp2, data1 cmp tmp2, data2, S2HI #8 bne 6f ldr data1, [src1], #4 b .Loverlap1 4: S2LO data2, data2, #24 b .Lstrcmp_tail 5: /* The syndrome value may contain false ones if the string ends with the bytes 0x01 0x00. */ tst data1, #LSB beq .Lstrcmp_done_equal ldr data2, [src2], #4 6: S2LO tmp2, data1, #8 bic data2, data2, #MSB b .Lstrcmp_tail .Lstrcmp_done_equal: mov result, #0 .cfi_remember_state ldmfd sp!, {r5} .cfi_restore 5 .cfi_adjust_cfa_offset -4 epilogue push_ip=HAVE_PAC_LEAF .Lstrcmp_tail: .cfi_restore_state and r2, tmp2, #LSB and result, data2, #LSB cmp result, #1 it cs cmpcs result, r2 itt eq S2LOEQ tmp2, tmp2, #8 S2LOEQ data2, data2, #8 beq .Lstrcmp_tail sub result, r2, result ldmfd sp!, {r5} .cfi_restore 5 .cfi_adjust_cfa_offset -4 epilogue push_ip=HAVE_PAC_LEAF .cfi_endproc cantunwind fnend .size strcmp, . - strcmp picolibc-1.8.11/libc/machine/arm/strcmp.S000066400000000000000000000055561513574234600201430ustar00rootroot00000000000000/* * Copyright (c) 2012-2014 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Wrapper for the various implementations of strcmp. */ #include #include "machine/acle-compat.h" #ifdef __ARM_BIG_ENDIAN #define S2LO lsl #define S2LOEQ lsleq #define S2HI lsr #define MSB 0x000000ff #define LSB 0xff000000 #define BYTE0_OFFSET 24 #define BYTE1_OFFSET 16 #define BYTE2_OFFSET 8 #define BYTE3_OFFSET 0 #else /* not __ARM_BIG_ENDIAN */ #define S2LO lsr #define S2LOEQ lsreq #define S2HI lsl #define BYTE0_OFFSET 0 #define BYTE1_OFFSET 8 #define BYTE2_OFFSET 16 #define BYTE3_OFFSET 24 #define MSB 0xff000000 #define LSB 0x000000ff #endif /* not __ARM_BIG_ENDIAN */ .macro def_fn f p2align=0 .text .p2align \p2align .global \f .type \f, %function \f: .endm #if defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED) \ || (__ARM_ARCH_ISA_THUMB == 1 && !__ARM_ARCH_ISA_ARM) # if defined (__thumb__) && !defined (__thumb2__) /* Thumb1 only variant. If size is preferred, use strcmp-armv4t.S. If speed is preferred, the strcmp function in strcmp-armv6m.S will be used. */ # if defined (__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED) # include "strcmp-armv4t.S" # else # include "strcmp-armv6m.S" # endif # else # include "strcmp-arm-tiny.S" # endif #elif __ARM_ARCH_ISA_THUMB == 2 # ifdef __ARM_FEATURE_SIMD32 # include "strcmp-armv7.S" # else # include "strcmp-armv7m.S" # endif #elif __ARM_ARCH >= 6 # include "strcmp-armv6.S" #else # include "strcmp-armv4.S" #endif picolibc-1.8.11/libc/machine/arm/strcpy.S000066400000000000000000000111251513574234600201440ustar00rootroot00000000000000/* * Copyright (c) 2008 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "arm_asm.h" #ifdef __thumb2__ #define magic1(REG) #0x01010101 #define magic2(REG) #0x80808080 #else #define magic1(REG) REG #define magic2(REG) REG , lsl #7 #endif .syntax unified #ifdef __thumb__ .thumb #endif .text .global strcpy .type strcpy, %function strcpy: fnstart .cfi_sections .debug_frame .cfi_startproc prologue push_ip=HAVE_PAC_LEAF #if !(defined(__OPTIMIZE_SIZE__) || defined (__PREFER_SIZE_OVER_SPEED) || \ (defined (__thumb__) && !defined (__thumb2__))) #ifdef _ISA_ARM_7 pld [r1] #endif eor r2, r0, r1 mov ip, r0 tst r2, #3 bne 4f tst r1, #3 bne 3f 5: #ifndef __thumb2__ str r5, [sp, #-4]! mov r5, #0x01 orr r5, r5, r5, lsl #8 orr r5, r5, r5, lsl #16 #endif str r4, [sp, #-4]! tst r1, #4 ldr r3, [r1], #4 beq 2f sub r2, r3, magic1(r5) bics r2, r2, r3 tst r2, magic2(r5) itt eq streq r3, [ip], #4 ldreq r3, [r1], #4 bne 1f /* Inner loop. We now know that r1 is 64-bit aligned, so we can safely fetch up to two words. This allows us to avoid load stalls. */ .p2align 2 2: #ifdef _ISA_ARM_7 pld [r1, #8] #endif ldr r4, [r1], #4 sub r2, r3, magic1(r5) bics r2, r2, r3 tst r2, magic2(r5) sub r2, r4, magic1(r5) bne 1f str r3, [ip], #4 bics r2, r2, r4 tst r2, magic2(r5) itt eq ldreq r3, [r1], #4 streq r4, [ip], #4 beq 2b mov r3, r4 1: #ifdef __ARMEB__ rors r3, r3, #24 #endif strb r3, [ip], #1 tst r3, #0xff #ifdef __ARMEL__ ror r3, r3, #8 #endif bne 1b ldr r4, [sp], #4 #ifndef __thumb2__ ldr r5, [sp], #4 #endif bx lr /* Strings have the same offset from word alignment, but it's not zero. */ 3: tst r1, #1 beq 1f ldrb r2, [r1], #1 strb r2, [ip], #1 cmp r2, #0 it eq bxeq lr 1: tst r1, #2 beq 5b ldrh r2, [r1], #2 #ifdef __ARMEB__ tst r2, #0xff00 iteet ne strhne r2, [ip], #2 lsreq r2, r2, #8 strbeq r2, [ip] tstne r2, #0xff #else tst r2, #0xff itet ne strhne r2, [ip], #2 strbeq r2, [ip] tstne r2, #0xff00 #endif bne 5b .cfi_remember_state epilogue push_ip=HAVE_PAC_LEAF .cfi_restore_state /* src and dst do not have a common word-alignement. Fall back to byte copying. */ 4: ldrb r2, [r1], #1 strb r2, [ip], #1 cmp r2, #0 bne 4b #elif !defined (__thumb__) || defined (__thumb2__) mov r3, r0 1: ldrb r2, [r1], #1 strb r2, [r3], #1 cmp r2, #0 bne 1b #else movs r3, r0 1: ldrb r2, [r1] adds r1, #1 strb r2, [r3] adds r3, #1 cmp r2, #0 bne 1b #endif epilogue push_ip=HAVE_PAC_LEAF .cfi_endproc cantunwind fnend .size strcpy, . - strcpy #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/arm/strlen-armv7.S000066400000000000000000000143171513574234600211670ustar00rootroot00000000000000/* Copyright (c) 2010-2011,2013 Linaro Limited All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Linaro Limited nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Assumes: ARMv6T2 or ARMv7E-M, AArch32 */ /* Copyright (c) 2015 ARM Ltd. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "arm_asm.h" .macro def_fn f p2align=0 .text .p2align \p2align .global \f .type \f, %function \f: .endm #ifdef __ARMEB__ #define S2LO lsl #define S2HI lsr #else #define S2LO lsr #define S2HI lsl #endif /* This code requires Thumb. */ #if __ARM_ARCH_PROFILE == 'M' #if __ARM_ARCH >= 8 /* keep config inherited from -march=. */ #else .arch armv7e-m #endif /* if __ARM_ARCH >= 8 */ #else .arch armv6t2 #endif .eabi_attribute Tag_ARM_ISA_use, 0 .thumb .syntax unified /* Parameters and result. */ #define srcin r0 #define result r0 /* Internal variables. */ #define src r1 #define data1a r2 #define data1b r3 #define const_m1 r12 #define const_0 r4 #define tmp1 r4 /* Overlaps const_0 */ #define tmp2 r5 def_fn strlen p2align=6 fnstart .cfi_sections .debug_frame .cfi_startproc prologue 4 5 push_ip=HAVE_PAC_LEAF pld [srcin, #0] bic src, srcin, #7 mvn const_m1, #0 ands tmp1, srcin, #7 /* (8 - bytes) to alignment. */ pld [src, #32] bne.w .Lmisaligned8 mov const_0, #0 mov result, #-8 .Lloop_aligned: /* Bytes 0-7. */ ldrd data1a, data1b, [src] pld [src, #64] add result, result, #8 .Lstart_realigned: uadd8 data1a, data1a, const_m1 /* Saturating GE<0:3> set. */ sel data1a, const_0, const_m1 /* Select based on GE<0:3>. */ uadd8 data1b, data1b, const_m1 sel data1b, data1a, const_m1 /* Only used if d1a == 0. */ cbnz data1b, .Lnull_found /* Bytes 8-15. */ ldrd data1a, data1b, [src, #8] uadd8 data1a, data1a, const_m1 /* Saturating GE<0:3> set. */ add result, result, #8 sel data1a, const_0, const_m1 /* Select based on GE<0:3>. */ uadd8 data1b, data1b, const_m1 sel data1b, data1a, const_m1 /* Only used if d1a == 0. */ cbnz data1b, .Lnull_found /* Bytes 16-23. */ ldrd data1a, data1b, [src, #16] uadd8 data1a, data1a, const_m1 /* Saturating GE<0:3> set. */ add result, result, #8 sel data1a, const_0, const_m1 /* Select based on GE<0:3>. */ uadd8 data1b, data1b, const_m1 sel data1b, data1a, const_m1 /* Only used if d1a == 0. */ cbnz data1b, .Lnull_found /* Bytes 24-31. */ ldrd data1a, data1b, [src, #24] add src, src, #32 uadd8 data1a, data1a, const_m1 /* Saturating GE<0:3> set. */ add result, result, #8 sel data1a, const_0, const_m1 /* Select based on GE<0:3>. */ uadd8 data1b, data1b, const_m1 sel data1b, data1a, const_m1 /* Only used if d1a == 0. */ cmp data1b, #0 beq .Lloop_aligned .Lnull_found: .cfi_remember_state cmp data1a, #0 itt eq addeq result, result, #4 moveq data1a, data1b #ifndef __ARMEB__ rev data1a, data1a #endif clz data1a, data1a add result, result, data1a, lsr #3 /* Bits -> Bytes. */ epilogue 4 5 push_ip=HAVE_PAC_LEAF .Lmisaligned8: .cfi_restore_state ldrd data1a, data1b, [src] and tmp2, tmp1, #3 rsb result, tmp1, #0 lsl tmp2, tmp2, #3 /* Bytes -> bits. */ tst tmp1, #4 pld [src, #64] S2HI tmp2, const_m1, tmp2 orn data1a, data1a, tmp2 itt ne ornne data1b, data1b, tmp2 movne data1a, const_m1 mov const_0, #0 b .Lstart_realigned .cfi_endproc cantunwind fnend .size strlen, . - strlen #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/arm/strlen-thumb1-Os.S000066400000000000000000000037771513574234600217220ustar00rootroot00000000000000/* Copyright (c) 2015 ARM Ltd. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include .macro def_fn f p2align=0 .text .p2align \p2align .global \f .type \f, %function \f: .endm .arch armv4t .eabi_attribute Tag_also_compatible_with, "\006\013" /* ARMv6-M. */ .eabi_attribute Tag_ARM_ISA_use, 0 .thumb .syntax unified def_fn strlen p2align=1 movs r3, #0 1: ldrb r2, [r0, r3] adds r3, r3, #1 cmp r2, #0 bne 1b subs r0, r3, #1 bx lr .size strlen, . - strlen #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/arm/strlen-thumb2-Os.S000066400000000000000000000043501513574234600217070ustar00rootroot00000000000000/* Copyright (c) 2015 ARM Ltd. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "arm_asm.h" .macro def_fn f p2align=0 .text .p2align \p2align .global \f .type \f, %function \f: .endm #if __ARM_ARCH_PROFILE == 'M' && __ARM_ARCH >= 8 /* keep config inherited from -march=. */ #elif __ARM_ARCH_ISA_THUMB >= 2 && __ARM_ARCH >= 7 .arch armv7 #else .arch armv6t2 #endif .eabi_attribute Tag_ARM_ISA_use, 0 .thumb .syntax unified def_fn strlen p2align=1 fnstart .cfi_sections .debug_frame .cfi_startproc prologue mov r3, r0 1: ldrb r2, [r3], #1 cmp r2, #0 bne 1b subs r0, r3, r0 subs r0, #1 epilogue .cfi_endproc cantunwind fnend .size strlen, . - strlen #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/arm/strlen.S000066400000000000000000000042571513574234600201370ustar00rootroot00000000000000/* Copyright (c) 2015 ARM Ltd. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Linaro nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "arm_asm.h" #if defined __OPTIMIZE_SIZE__ || defined __PREFER_SIZE_OVER_SPEED #if __ARM_ARCH_ISA_THUMB == 2 #include "strlen-thumb2-Os.S" #elif defined (__thumb__) #include "strlen-thumb1-Os.S" #else /* Implemented in strlen-stub.c. */ #endif #else /* defined __OPTIMIZE_SIZE__ || defined __PREFER_SIZE_OVER_SPEED */ #if defined __thumb__ && ! defined __thumb2__ /* Implemented in strlen-stub.c. */ #elif __ARM_ARCH_ISA_THUMB >= 2 && defined __ARM_FEATURE_DSP #include "strlen-armv7.S" #else /* Implemented in strlen-stub.c. */ #endif #endif #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/arm/strlen.c000066400000000000000000000131571513574234600201560ustar00rootroot00000000000000/* * Copyright (c) 2008-2015 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "arm_asm.h" #include #include #if defined __OPTIMIZE_SIZE__ || defined __PREFER_SIZE_OVER_SPEED #if __ARM_ARCH_ISA_THUMB == 2 /* Implemented in strlen.S. */ #elif defined(__thumb__) /* Implemented in strlen.S. */ #else #include "../../string/strlen.c" #endif #else /* defined __OPTIMIZE_SIZE__ || defined __PREFER_SIZE_OVER_SPEED */ #if defined __thumb__ && !defined __thumb2__ #include "../../string/strlen.c" #elif __ARM_ARCH_ISA_THUMB >= 2 && defined __ARM_FEATURE_DSP /* Implemented in strlen.S. */ #else #ifdef __GNUCLIKE_PRAGMA_DIAGNOSTIC #pragma GCC diagnostic ignored "-Wunused-parameter" #endif size_t __naked strlen(const char *str) { __asm__("len .req r0\n\t" "data .req r3\n\t" "addr .req r1\n\t" #ifdef _ISA_ARM_7 "pld [r0]\n\t" #endif /* Word-align address */ "bic addr, r0, #3\n\t" /* Get adjustment for start ... */ "ands len, r0, #3\n\t" "neg len, len\n\t" /* First word of data */ "ldr data, [addr], #4\n\t" /* Ensure bytes preceeding start ... */ "add ip, len, #4\n\t" "mov ip, ip, asl #3\n\t" "mvn r2, #0\n\t" /* ... are masked out */ #ifdef __thumb__ "itt ne\n\t" #ifdef __ARMEB__ "lslne r2, ip\n\t" #else "lsrne r2, ip\n\t" #endif "orrne data, data, r2\n\t" #else "it ne\n\t" #ifdef __ARMEB__ "orrne data, data, r2, lsl ip\n\t" #else "orrne data, data, r2, lsr ip\n\t" #endif #endif /* Magic const 0x01010101 */ #ifdef _ISA_ARM_7 "movw ip, #0x101\n\t" #else "mov ip, #0x1\n\t" "orr ip, ip, ip, lsl #8\n\t" #endif "orr ip, ip, ip, lsl #16\n" /* This is the main loop. We subtract one from each byte in the word: the sign bit changes iff the byte was zero or 0x80 -- we eliminate the latter case by anding the result with the 1-s complement of the data. */ "1:\n\t" /* test (data - 0x01010101) */ "sub r2, data, ip\n\t" /* ... & ~data */ "bic r2, r2, data\n\t" /* ... & 0x80808080 == 0? */ "ands r2, r2, ip, lsl #7\n\t" #ifdef _ISA_ARM_7 /* yes, get more data... */ "itt eq\n\t" "ldreq data, [addr], #4\n\t" /* and 4 more bytes */ "addeq len, len, #4\n\t" /* Unroll the loop a bit. */ "pld [addr, #8]\n\t" /* test (data - 0x01010101) */ "ittt eq\n\t" "subeq r2, data, ip\n\t" /* ... & ~data */ "biceq r2, r2, data\n\t" /* ... & 0x80808080 == 0? */ "andeqs r2, r2, ip, lsl #7\n\t" #endif "itt eq\n\t" /* yes, get more data... */ "ldreq data, [addr], #4\n\t" /* and 4 more bytes */ "addeq len, len, #4\n\t" "beq 1b\n\t" #ifdef __ARMEB__ "tst data, #0xff000000\n\t" "itttt ne\n\t" "addne len, len, #1\n\t" "tstne data, #0xff0000\n\t" "addne len, len, #1\n\t" "tstne data, #0xff00\n\t" "it ne\n\t" "addne len, len, #1\n\t" #else #ifdef _ISA_ARM_5 /* R2 is the residual sign bits from the above test. All we need to do now is establish the position of the first zero byte... */ /* Little-endian is harder, we need the number of trailing zeros / 8 */ #ifdef _ISA_ARM_7 "rbit r2, r2\n\t" "clz r2, r2\n\t" #else "rsb r1, r2, #0\n\t" "and r2, r2, r1\n\t" "clz r2, r2\n\t" "rsb r2, r2, #31\n\t" #endif "add len, len, r2, lsr #3\n\t" #else /* No CLZ instruction */ "tst data, #0xff\n\t" "itttt ne\n\t" "addne len, len, #1\n\t" "tstne data, #0xff00\n\t" "addne len, len, #1\n\t" "tstne data, #0xff0000\n\t" "it ne\n\t" "addne len, len, #1\n\t" #endif #endif "bx lr\n\t"); } #endif #endif picolibc-1.8.11/libc/machine/arm/sys/000077500000000000000000000000001513574234600173125ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/arm/sys/meson.build000066400000000000000000000033021513574234600214520ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_sys_headers_machine = [ ] if really_install install_headers(inc_sys_headers_machine, install_dir: include_dir / 'sys') endif picolibc-1.8.11/libc/machine/arm/tls.c000066400000000000000000000036051513574234600174460ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * Copyright © 2024 Stephen Street * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #ifdef __THREAD_LOCAL_STORAGE #include "arm_tls.h" /* This needs to be global so that __aeabi_read_tp can * refer to it in an asm statement */ #ifndef ARM_TLS_CP15 void *__tls[ARM_TLS_COUNT]; #endif #endif picolibc-1.8.11/libc/machine/avr/000077500000000000000000000000001513574234600165055ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/avr/macros.inc000066400000000000000000000223571513574234600204750ustar00rootroot00000000000000/* Copyright (c) 2002, 2005, 2006, 2007 Marek Michalkiewicz Copyright (c) 2006 Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* macros.inc - macros for use in assembler sources Contributors: Created by Marek Michalkiewicz */ #include #include "sectionname.h" /* if not defined, assume old version with underscores */ #ifndef __USER_LABEL_PREFIX__ #define __USER_LABEL_PREFIX__ _ #endif #ifndef __REGISTER_PREFIX__ #define __REGISTER_PREFIX__ #endif /* the assembler line separator (just in case it ever changes) */ #define _L $ #define CONCAT1(a, b) CONCAT2(a, b) #define CONCAT2(a, b) a ## b #define _U(x) CONCAT1(__USER_LABEL_PREFIX__, x) #define _R(x) CONCAT1(__REGISTER_PREFIX__, x) /* these should help to fix the "can't have function named r1()" bug which may require adding '%' in front of register names. */ #define r0 _R(r0) #define r1 _R(r1) #define r2 _R(r2) #define r3 _R(r3) #define r4 _R(r4) #define r5 _R(r5) #define r6 _R(r6) #define r7 _R(r7) #define r8 _R(r8) #define r9 _R(r9) #define r10 _R(r10) #define r11 _R(r11) #define r12 _R(r12) #define r13 _R(r13) #define r14 _R(r14) #define r15 _R(r15) #define r16 _R(r16) #define r17 _R(r17) #define r18 _R(r18) #define r19 _R(r19) #define r20 _R(r20) #define r21 _R(r21) #define r22 _R(r22) #define r23 _R(r23) #define r24 _R(r24) #define r25 _R(r25) #define r26 _R(r26) #define r27 _R(r27) #define r28 _R(r28) #define r29 _R(r29) #define r30 _R(r30) #define r31 _R(r31) #if !defined(__tmp_reg__) #if defined(__AVR_TINY__) #define __tmp_reg__ r16 #else #define __tmp_reg__ r0 #endif #endif #if !defined(__zero_reg__) #if defined(__AVR_TINY__) #define __zero_reg__ r17 #else #define __zero_reg__ r1 #endif #endif #if (__AVR_HAVE_JMP_CALL__) #define XJMP jmp #define XCALL call #else #define XJMP rjmp #define XCALL rcall #endif /* used only by fplib/strtod.S - libgcc internal function calls */ #define PROLOGUE_SAVES(offset) XJMP (__prologue_saves__ + 2 * (offset)) #define EPILOGUE_RESTORES(offset) XJMP (__epilogue_restores__ + 2 * (offset)) #if FLASHEND > 0x10000 /* ATmega103 */ #define BIG_CODE 1 #else #define BIG_CODE 0 #endif #ifndef __AVR_HAVE_MOVW__ # if defined(__AVR_ENHANCED__) && __AVR_ENHANCED__ # define __AVR_HAVE_MOVW__ 1 # endif #endif #ifndef __AVR_HAVE_LPMX__ # if defined(__AVR_ENHANCED__) && __AVR_ENHANCED__ # define __AVR_HAVE_LPMX__ 1 # endif #endif #ifndef __AVR_HAVE_MUL__ # if defined(__AVR_ENHANCED__) && __AVR_ENHANCED__ # define __AVR_HAVE_MUL__ 1 # endif #endif /* Smart version of movw: - uses "movw" if possible (supported by MCU, and both registers even) - handles overlapping register pairs correctly - no instruction generated if source and destination are the same (may expand to 0, 1 or 2 instructions). */ .macro X_movw dst src .L_movw_dst = -1 .L_movw_src = -1 .L_movw_n = 0 .irp reg, r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, \ r10,r11,r12,r13,r14,r15,r16,r17,r18,r19, \ r20,r21,r22,r23,r24,r25,r26,r27,r28,r29, \ r30,r31 .ifc \reg,\dst .L_movw_dst = .L_movw_n .endif .ifc \reg,\src .L_movw_src = .L_movw_n .endif .L_movw_n = .L_movw_n + 1 .endr .L_movw_n = 0 .irp reg, R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, \ R10,R11,R12,R13,R14,R15,R16,R17,R18,R19, \ R20,R21,R22,R23,R24,R25,R26,R27,R28,R29, \ R30,R31 .ifc \reg,\dst .L_movw_dst = .L_movw_n .endif .ifc \reg,\src .L_movw_src = .L_movw_n .endif .L_movw_n = .L_movw_n + 1 .endr .if .L_movw_dst < 0 .L_movw_n = 0 .rept 32 .if \dst == .L_movw_n .L_movw_dst = .L_movw_n .endif .L_movw_n = .L_movw_n + 1 .endr .endif .if .L_movw_src < 0 .L_movw_n = 0 .rept 32 .if \src == .L_movw_n .L_movw_src = .L_movw_n .endif .L_movw_n = .L_movw_n + 1 .endr .endif .if (.L_movw_dst < 0) || (.L_movw_src < 0) .err ; Invalid 'X_movw' arg. .endif .if ((.L_movw_src) - (.L_movw_dst)) /* different registers */ .if (((.L_movw_src) | (.L_movw_dst)) & 0x01) .if (((.L_movw_src)-(.L_movw_dst)) & 0x80) /* src < dest */ mov (.L_movw_dst)+1, (.L_movw_src)+1 mov (.L_movw_dst), (.L_movw_src) .else /* src > dest */ mov (.L_movw_dst), (.L_movw_src) mov (.L_movw_dst)+1, (.L_movw_src)+1 .endif .else /* both even -> overlap not possible */ #if defined(__AVR_HAVE_MOVW__) && __AVR_HAVE_MOVW__ movw \dst, \src #else mov (.L_movw_dst), (.L_movw_src) mov (.L_movw_dst)+1, (.L_movw_src)+1 #endif .endif .endif .endm /* Macro 'X_lpm' extends enhanced lpm instruction for classic chips. Usage: X_lpm reg, dst where reg is 0..31, r0..r31 or R0..R31 dst is z, Z, z+ or Z+ It is possible to omit both arguments. Possible results for classic chips: lpm lpm / mov Rd,r0 lpm / adiw ZL,1 lpm / mov Rd,r0 / adiw ZL,1 For enhanced chips it is one instruction always. ATTENTION: unlike enhanced chips SREG (S,V,N,Z,C) flags are changed in case of 'Z+' dst. R0 is scratch. */ .macro X_lpm dst=r0, src=Z /* dst evaluation */ .L_lpm_dst = -1 .L_lpm_n = 0 .irp reg, r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, \ r10,r11,r12,r13,r14,r15,r16,r17,r18,r19, \ r20,r21,r22,r23,r24,r25,r26,r27,r28,r29, \ r30,r31 .ifc \reg,\dst .L_lpm_dst = .L_lpm_n .endif .L_lpm_n = .L_lpm_n + 1 .endr .L_lpm_n = 0 .irp reg, R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, \ R10,R11,R12,R13,R14,R15,R16,R17,R18,R19, \ R20,R21,R22,R23,R24,R25,R26,R27,R28,R29, \ R30,R31 .ifc \reg,\dst .L_lpm_dst = .L_lpm_n .endif .L_lpm_n = .L_lpm_n + 1 .endr .if .L_lpm_dst < 0 .L_lpm_n = 0 .rept 32 .if \dst == .L_lpm_n .L_lpm_dst = .L_lpm_n .endif .L_lpm_n = .L_lpm_n + 1 .endr .endif .if (.L_lpm_dst < 0) .err ; Invalid dst arg of 'X_lpm' macro. .endif /* src evaluation */ .L_lpm_src = -1 .L_lpm_n = 0 .irp reg, z,Z,z+,Z+ .ifc \reg,\src .L_lpm_src = .L_lpm_n .endif .L_lpm_n = .L_lpm_n + 1 .endr .if (.L_lpm_src < 0) .err ; Invalid src arg of 'X_lpm' macro. .endif /* instruction(s) */ .if .L_lpm_src < 2 .if .L_lpm_dst == 0 lpm .else #if defined(__AVR_HAVE_LPMX__) && __AVR_HAVE_LPMX__ lpm .L_lpm_dst, Z #else lpm mov .L_lpm_dst, r0 #endif .endif .else .if (.L_lpm_dst >= 30) .err ; Registers 30 and 31 are inhibited as 'X_lpm *,Z+' dst. .endif #if defined(__AVR_HAVE_LPMX__) && __AVR_HAVE_LPMX__ lpm .L_lpm_dst, Z+ #else lpm .if .L_lpm_dst mov .L_lpm_dst, r0 .endif adiw r30, 1 #endif .endif .endm /* LPM_R0_ZPLUS_INIT is used before the loop to initialize RAMPZ for future devices with RAMPZ:Z auto-increment - [e]lpm r0, Z+. LPM_R0_ZPLUS_NEXT is used inside the loop to load a byte from the program memory at [RAMPZ:]Z to R0, and increment [RAMPZ:]Z. The argument in both macros is a register that contains the high byte (bits 23-16) of the address, bits 15-0 should be in the Z (r31:r30) register. It can be any register except for: r0, r1 (__zero_reg__ - assumed to always contain 0), r30, r31. */ .macro LPM_R0_ZPLUS_INIT hhi #if __AVR_ENHANCED__ #if __AVR_HAVE_ELPM__ out AVR_RAMPZ_ADDR, \hhi #endif #endif .endm .macro LPM_R0_ZPLUS_NEXT hhi #if __AVR_ENHANCED__ #if __AVR_HAVE_ELPM__ /* ELPM with RAMPZ:Z post-increment, load RAMPZ only once */ elpm r0, Z+ #else /* LPM with Z post-increment, max 64K, no RAMPZ (ATmega83/161/163/32) */ lpm r0, Z+ #endif #else #if __AVR_HAVE_ELPM__ /* ELPM without post-increment, load RAMPZ each time (ATmega103) */ out AVR_RAMPZ_ADDR, \hhi elpm adiw r30,1 adc \hhi, __zero_reg__ #else /* LPM without post-increment, max 64K, no RAMPZ (AT90S*) */ lpm adiw r30,1 #endif #endif .endm picolibc-1.8.11/libc/machine/avr/meson.build000066400000000000000000000031611513574234600206500ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'setjmp.S', ] src_machine = files(srcs_machine) picolibc-1.8.11/libc/machine/avr/sectionname.h000066400000000000000000000041341513574234600211650ustar00rootroot00000000000000/* Copyright (c) 2009 Atmel Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __SECTIONNAME_H__ #define __SECTIONNAME_H__ /* Put all avr-libc functions in a common, unique sub-section name under .text. */ #define CLIB_SECTION .text.avr - libc #define MLIB_SECTION .text.avr - libc.fplib #define STR(x) _STR(x) #define _STR(x) #x #define ATTRIBUTE_CLIB_SECTION __section(STR(CLIB_SECTION)) #define ATTRIBUTE_MLIB_SECTION __section(STR(MLIB_SECTION)) #define ASSEMBLY_CLIB_SECTION .section CLIB_SECTION, "ax", @progbits #define ASSEMBLY_MLIB_SECTION .section MLIB_SECTION, "ax", @progbits #endif picolibc-1.8.11/libc/machine/avr/setjmp.S000066400000000000000000000117351513574234600201420ustar00rootroot00000000000000/* Copyright (c) 2002, Marek Michalkiewicz All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: setjmp.S 2484 2015-08-17 06:34:41Z pitchumani $ */ /* setjmp.S Contributors: Created by Marek Michalkiewicz */ /* jmp_buf: offset size description 0 16/2 call-saved registers (r2-r17) (AVR_TINY arch has only 2 call saved registers (r18,r19)) 16/2 2 frame pointer (r29:r28) 18/4 2 stack pointer (SPH:SPL) 20/6 1 status register (SREG) 21/7 2/3 return address (PC) (2 bytes used for <=128Kw flash) 23/24/9 = total size (AVR_TINY arch always has 2 bytes PC) All multibytes are stored as little-endian. int setjmp(jmp_buf __jmpb); void longjmp(jmp_buf __jmpb, int __val) __noreturn; */ #include #ifndef __DOXYGEN__ #include #include "macros.inc" /* ???: What was a reason to use aliases for common registers? Check the address: is it a port number (value for IN/OUT)? */ #if AVR_STACK_POINTER_LO_ADDR != 0x3D \ || AVR_STATUS_ADDR != 0x3F # error "Strange address of common registers SPL, SREG" #endif #define jmpb_hi r25 #define jmpb_lo r24 #define val_hi r23 #define val_lo r22 #define ret_lo r24 #define ret_hi r25 ASSEMBLY_CLIB_SECTION .global _U(setjmp) .type _U(setjmp), @function _U(setjmp): X_movw XL, jmpb_lo ; save call-saved registers and frame pointer #if !defined(__AVR_TINY__) .irp .L_regno, 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,28,29 #else .irp .L_regno, 18,19,28,29 #endif st X+, r\.L_regno .endr ; get return address #if defined(__AVR_3_BYTE_PC__) && __AVR_3_BYTE_PC__ pop __tmp_reg__ ; used below #endif pop ZH pop ZL ; save stack pointer (after poping) in ret_lo, AVR_STACK_POINTER_LO_ADDR st X+, ret_lo #ifdef __HAVE_AVR_STACK_POINTER_HI in ret_lo, AVR_STACK_POINTER_HI_ADDR st X+, ret_lo #else st X+, __zero_reg__ #endif ; save status register (I flag) in ret_lo, AVR_STATUS_ADDR st X+, ret_lo ; save return address st X+, ZL st X+, ZH ; return zero clr ret_lo clr ret_hi #if defined(__AVR_3_BYTE_PC__) && __AVR_3_BYTE_PC__ st X+, __tmp_reg__ rjmp .L_jmp3 #else ijmp #endif .size _U(setjmp), . - _U(setjmp) .global _U(longjmp) .type _U(longjmp), @function _U(longjmp): X_movw XL, jmpb_lo ; return value X_movw ret_lo, val_lo ; if zero, change to 1 cpi ret_lo, 1 cpc ret_hi, __zero_reg__ adc ret_lo, __zero_reg__ ; restore call-saved registers and frame pointer #if !defined(__AVR_TINY__) .irp .L_regno, 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,28,29 #else .irp .L_regno, 18,19,28,29 #endif ld r\.L_regno, X+ .endr ; restore stack pointer (SP value before the setjmp() call) and SREG ld ZL, X+ ld ZH, X+ ld __tmp_reg__, X+ #if defined (__AVR_XMEGA__) && __AVR_XMEGA__ /* A write to SPL will automatically disable interrupts for up to 4 instructions or until the next I/O memory write. */ out AVR_STATUS_ADDR, __tmp_reg__ out AVR_STACK_POINTER_LO_ADDR, ZL out AVR_STACK_POINTER_HI_ADDR, ZH #else # ifdef __HAVE_AVR_STACK_POINTER_HI /* interrupts disabled for shortest possible time (3 cycles) */ cli out AVR_STACK_POINTER_HI_ADDR, ZH # endif /* Restore status register (including the interrupt enable flag). Interrupts are re-enabled only after the next instruction. */ out AVR_STATUS_ADDR, __tmp_reg__ out AVR_STACK_POINTER_LO_ADDR, ZL #endif ; get return address and jump ld ZL, X+ ld ZH, X+ #if defined(__AVR_3_BYTE_PC__) && __AVR_3_BYTE_PC__ ld __tmp_reg__, X+ .L_jmp3: push ZL push ZH push __tmp_reg__ ret #else ijmp #endif .size _U(longjmp), . - _U(longjmp) #endif /* !__DOXYGEN__ */ picolibc-1.8.11/libc/machine/bfin/000077500000000000000000000000001513574234600166335ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/bfin/longjmp.S000066400000000000000000000044561513574234600204360ustar00rootroot00000000000000/* * longjmp for the Blackfin processor * * Copyright (C) 2006 Analog Devices, Inc. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #define _ASM #define _SETJMP_H .text; .align 4; .globl _longjmp; .type _longjmp, STT_FUNC; _longjmp: P0 = R0; R0 = [P0 + 0x00]; [--SP] = R0; /* Put P0 on the stack */ P1 = [P0 + 0x04]; P2 = [P0 + 0x08]; P3 = [P0 + 0x0C]; P4 = [P0 + 0x10]; P5 = [P0 + 0x14]; FP = [P0 + 0x18]; R0 = [SP++]; /* Grab P0 from old stack */ SP = [P0 + 0x1C]; /* Update Stack Pointer */ [--SP] = R0; /* Put P0 on new stack */ [--SP] = R1; /* Put VAL arg on new stack */ R0 = [P0 + 0x20]; /* Data Registers */ R1 = [P0 + 0x24]; R2 = [P0 + 0x28]; R3 = [P0 + 0x2C]; R4 = [P0 + 0x30]; R5 = [P0 + 0x34]; R6 = [P0 + 0x38]; R7 = [P0 + 0x3C]; R0 = [P0 + 0x40]; ASTAT = R0; R0 = [P0 + 0x44]; /* Loop Counters */ LC0 = R0; R0 = [P0 + 0x48]; LC1 = R0; R0 = [P0 + 0x4C]; /* Accumulators */ A0.W = R0; R0 = [P0 + 0x50]; A0.X = R0; R0 = [P0 + 0x54]; A1.W = R0; R0 = [P0 + 0x58]; A1.X = R0; R0 = [P0 + 0x5C]; /* Index Registers */ I0 = R0; R0 = [P0 + 0x60]; I1 = R0; R0 = [P0 + 0x64]; I2 = R0; R0 = [P0 + 0x68]; I3 = R0; R0 = [P0 + 0x6C]; /* Modifier Registers */ M0 = R0; R0 = [P0 + 0x70]; M1 = R0; R0 = [P0 + 0x74]; M2 = R0; R0 = [P0 + 0x78]; M3 = R0; R0 = [P0 + 0x7C]; /* Length Registers */ L0 = R0; R0 = [P0 + 0x80]; L1 = R0; R0 = [P0 + 0x84]; L2 = R0; R0 = [P0 + 0x88]; L3 = R0; R0 = [P0 + 0x8C]; /* Base Registers */ B0 = R0; R0 = [P0 + 0x90]; B1 = R0; R0 = [P0 + 0x94]; B2 = R0; R0 = [P0 + 0x98]; B3 = R0; R0 = [P0 + 0x9C]; /* Return Address (PC) */ RETS = R0; R0 = [SP++]; P0 = [SP++]; CC = R0 == 0; IF !CC JUMP 1f; R0 = 1; 1: RTS; .size _longjmp, .-_longjmp; picolibc-1.8.11/libc/machine/bfin/setjmp.S000066400000000000000000000041631513574234600202650ustar00rootroot00000000000000/* * setjmp for the Blackfin processor * * Copyright (C) 2006 Analog Devices, Inc. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #define _ASM #define _SETJMP_H .text; .align 4; .globl _setjmp; .type _setjmp, STT_FUNC; _setjmp: [--SP] = P0; /* Save P0 */ P0 = R0; R0 = [SP++]; [P0 + 0x00] = R0; /* Save saved P0 */ [P0 + 0x04] = P1; [P0 + 0x08] = P2; [P0 + 0x0C] = P3; [P0 + 0x10] = P4; [P0 + 0x14] = P5; [P0 + 0x18] = FP; /* Frame Pointer */ [P0 + 0x1C] = SP; /* Stack Pointer */ [P0 + 0x20] = P0; /* Data Registers */ [P0 + 0x24] = R1; [P0 + 0x28] = R2; [P0 + 0x2C] = R3; [P0 + 0x30] = R4; [P0 + 0x34] = R5; [P0 + 0x38] = R6; [P0 + 0x3C] = R7; R0 = ASTAT; [P0 + 0x40] = R0; R0 = LC0; /* Loop Counters */ [P0 + 0x44] = R0; R0 = LC1; [P0 + 0x48] = R0; R0 = A0.W; /* Accumulators */ [P0 + 0x4C] = R0; R0 = A0.X; [P0 + 0x50] = R0; R0 = A1.W; [P0 + 0x54] = R0; R0 = A1.X; [P0 + 0x58] = R0; R0 = I0; /* Index Registers */ [P0 + 0x5C] = R0; R0 = I1; [P0 + 0x60] = R0; R0 = I2; [P0 + 0x64] = R0; R0 = I3; [P0 + 0x68] = R0; R0 = M0; /* Modifier Registers */ [P0 + 0x6C] = R0; R0 = M1; [P0 + 0x70] = R0; R0 = M2; [P0 + 0x74] = R0; R0 = M3; [P0 + 0x78] = R0; R0 = L0; /* Length Registers */ [P0 + 0x7c] = R0; R0 = L1; [P0 + 0x80] = R0; R0 = L2; [P0 + 0x84] = R0; R0 = L3; [P0 + 0x88] = R0; R0 = B0; /* Base Registers */ [P0 + 0x8C] = R0; R0 = B1; [P0 + 0x90] = R0; R0 = B2; [P0 + 0x94] = R0; R0 = B3; [P0 + 0x98] = R0; R0 = RETS; [P0 + 0x9C] = R0; R0 = 0; RTS; .size _setjmp, .-_setjmp; picolibc-1.8.11/libc/machine/cr16/000077500000000000000000000000001513574234600164705ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/cr16/getenv.c000066400000000000000000000016661513574234600201350ustar00rootroot00000000000000/* getenv.c -- Implementation of the getenv() routine * * Copyright (c) 2004 National Semiconductor Corporation * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ /* getenv() is implemented as a low-level function, thus we only invoke here the system call. */ #include char * getenv(const char *name) { char *_getenv(const char *); return (_getenv(name)); } picolibc-1.8.11/libc/machine/cr16/setjmp.S000066400000000000000000000061071513574234600201220ustar00rootroot00000000000000#include ############################################################################## # setjmp.S -- CR16 setjmp routine # # # /* Copyright (c) 2004 National Semiconductor Corporation */ # # # The authors hereby grant permission to use, copy, modify, distribute, # # and license this software and its documentation for any purpose, provided # # that existing copyright notices are retained in all copies and that this # # notice is included verbatim in any distributions. No written agreement, # # license, or royalty fee is required for any of the authorized uses. # # Modifications to this software may be copyrighted by their authors # # and need not follow the licensing terms described here, provided that # # the new terms are clearly indicated on the first page of each file where # # they apply. # # # # C library -- setjmp, longjmp # # longjmp(a,v) # # will generate a "return(v)" # # from the last call to # # setjmp(a) # # by restoring r7-ra, sp, # # and pc from 'a' # # and doing a return. (Makes sure that longjmp never returns 0). # ############################################################################## .text .file "setjmp.s" .align 4 .globl _setjmp .align 4 _setjmp: #r3, r2: .blkw storw r7, 0(r3,r2) addd $2, (r3,r2) storw r8, 0(r3,r2) addd $2, (r3,r2) storw r9, 0(r3,r2) addd $2, (r3,r2) storw r10, 0(r3,r2) addd $2, (r3,r2) storw r11, 0(r3,r2) addd $2, (r3,r2) stord (r12), 0(r3,r2) addd $4, (r3,r2) stord (r13), 0(r3,r2) addd $4, (r3,r2) stord (ra), 0(r3,r2) addd $4, (r3,r2) stord (sp), 0(r3,r2) movd $0,(r1,r0) jump (ra) .globl _longjmp _longjmp: #r3, r2: .blkw # pointer save area #r5, r4: .blkw # ret vlaue loadw 0(r3,r2), r7 addd $2, (r3,r2) loadw 0(r3,r2), r8 addd $2, (r3,r2) loadw 0(r3,r2), r9 addd $2, (r3,r2) loadw 0(r3,r2), r10 addd $2, (r3,r2) loadw 0(r3,r2), r11 addd $2, (r3,r2) loadd 0(r3,r2), (r12) addd $4, (r3,r2) loadd 0(r3,r2), (r13) addd $4, (r3,r2) loadd 0(r3,r2), (ra) addd $4, (r3,r2) loadd 0(r3,r2), (sp) #ifdef __INT32__ movd (r5,r4), (r1,r0) cmpd $0, (r5,r4) bne end1 movd $1, (r1,r0) #else movw r4, r0 cmpw $0, r4 bne end1 movw $1, r0 #endif end1: jump (ra) .align 4 picolibc-1.8.11/libc/machine/cr16/sys/000077500000000000000000000000001513574234600173065ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/cr16/sys/asm.h000066400000000000000000000261641513574234600202500ustar00rootroot00000000000000/* asm.h -- CR16 architecture intrinsic functions * * Copyright (c) 2012 National Semiconductor Corporation * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #ifndef _ASM #define _ASM /* Note that immediate input values are not checked for validity. It is the user's responsibility to use the intrinsic functions with appropriate immediate values. */ /* Addition Instructions */ #define _addb_(src, dest) __asm__("addb %1, %0" : "=r" (dest) : \ "ri" ((unsigned char)src), "0" (dest) : "cc") #define _addub_(src, dest) __asm__("addub %1, %0" : "=r" (dest) : \ "ri" ((unsigned char)src), "0" (dest) : "cc") #define _addw_(src, dest) __asm__("addw %1, %0" : "=r" (dest) : \ "ri" ((unsigned short)src), "0" (dest) : "cc") #define _adduw_(src, dest) __asm__("adduw %1, %0" : "=r" (dest) : \ "ri" ((unsigned short)src), "0" (dest) : "cc") #define _addd_(src, dest) __asm__("addd %1, %0" : "=r" (dest) : \ "ri" ((unsigned long)src), "0" (dest) : "cc") /* Add with Carry */ #define _addcb_(src, dest) __asm__("addcb %1, %0" : "=r" (dest) : \ "ri" ((unsigned char)src), "0" (dest) : "cc") #define _addcw_(src, dest) __asm__("addcw %1, %0" : "=r" (dest) : \ "ri" ((unsigned short)src), "0" (dest) : "cc") /* Bitwise Logical AND */ #define _andb_(src, dest) __asm__("andb %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) #define _andw_(src, dest) __asm__("andw %1,%0" : "=r" (dest) : \ "ri" ((unsigned short)src) , "0" (dest)) #define _andd_(src, dest) __asm__("andd %1,%0" : "=r" (dest) : \ "ri" ((unsigned long)src) , "0" (dest)) /* Arithmetic shift Instructions */ #define _ashub_(count, dest) __asm__("ashub %1,%0" : "=r" (dest) : \ "ri" ((char)count) , "0" (dest) ) #define _ashuw_(count, dest) __asm__("ashuw %1,%0" : "=r" (dest) : \ "ri" ((char)count) , "0" (dest) ) #define _ashud_(count, dest) __asm__("ashud %1,%0" : "=r" (dest) : \ "ri" ((char)count) , "0" (dest) ) /* cbit (clear bit) Instructions */ #define _cbitb_(pos, dest) __asm__("cbitb %1,%0" : "=mr" (dest) : \ "i" ((unsigned char)pos) , "0" (dest) : "cc") #define _cbitw_(pos, dest) __asm__("cbitw %1,%0" : "=mr" (dest) : \ "i" ((unsigned char)pos) , "0" (dest) : "cc") /* Compare Instructions */ #define _cmpb_(src1, src2) __asm__("cmpb %0,%1" : /* no output */ : \ "ri" ((unsigned char)src1) , "r" (src2) : "cc") #define _cmpw_(src1, src2) __asm__("cmpw %0,%1" : /* no output */ : \ "ri" ((unsigned short)src1) , "r" (src2) : "cc") #define _cmpd_(src1, src2) __asm__("cmpd %0,%1" : /* no output */ : \ "ri" ((unsigned long)src1) , "r" (src2) : "cc") /* Disable Inerrupts instructions */ #define _di_() __asm__ volatile ("di\n" : : : "cc") #define _disable_() __asm__ volatile ("di\n" : : : "cc") #define _disable_interrupt_() _di_ /* Enable Inerrupts instructions */ #define _ei_() __asm__ volatile ("ei\n" : : : "cc") #define _enable_() __asm__ volatile ("ei\n" : : : "cc") #define _enable_interrupt_() _ei_ /* Enable Inerrupts instructions and Wait */ #define _eiwait_() __asm__ volatile ("eiwait" : : : "cc") /* excp Instructions */ #define _excp_(vector) __asm__ volatile ("excp " # vector) /* lpr and lprd Instructions */ #define _lpr_(procreg, src) __asm__("lpr\t%0," procreg : \ /* no output */ : "r" (src) : "cc") #define _lprd_(procregd, src) __asm__("lprd\t%0," procregd : \ /* no output */ : "r" (src) : "cc") /* Left Shift Instructions */ #define _lshb_(count, dest) __asm__("lshb %1,%0" : "=r" (dest) : \ "ri" ((char)count) , "0" (dest) ) #define _lshw_(count, dest) __asm__("lshw %1,%0" : "=r" (dest) : \ "ri" ((char)count) , "0" (dest) ) #define _lshd_(count, dest) __asm__("lshd %1,%0" : "=r" (dest) : \ "ri" ((char)count) , "0" (dest) ) /* Load Instructions */ #define _loadb_(base, dest) __asm__("loadb %1,%0" : "=r" (dest) : \ "m" (base) , "0" (dest)) #define _loadw_(base, dest) __asm__("loadw %1,%0" : "=r" (dest) : \ "m" (base) , "0" (dest)) #define _loadd_(base, dest) __asm__("loadd %1,%0" : "=r" (dest) : \ "m" (base) , "0" (dest)) /* Load Multiple Instructions */ #define _loadm_(src, mask) __asm__("loadm %0,%1" : /* No output */ : \ "r" ((unsigned int)src) , "i" (mask)) #define _loadmp_(src, mask) __asm__("loadmp %0,%1" : /* No output */ : \ "r" ((unsigned int)src) , "i" (mask)) /* Multiply Accumulate Instrutions */ #define _macsw_(hi, lo, src1, src2) __asm__("macsw %1,%0" \ : =l (lo), =h (hi) \ : "r" ((short)src1) , "r" (src2)) #define _macuw_(hi, lo, src1, src2) __asm__("macuw %1,%0" \ : =l (lo), =h (hi) \ : "r" ((unsigned short)src1) , "r" (src2)) #define _macqw_(src1, src2) __asm__("macqw %1,%0" \ : =l (lo), =h (hi) \ :"r" ((short)src1) , "r" (src2)) /* Move Instructions */ #define _movb_(src, dest) __asm__("movb %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) #define _movw_(src, dest) __asm__("movw %1,%0" : "=r" (dest) : \ "ri" ((unsigned short)src) , "0" (dest)) #define _movd_(src, dest) __asm__("movd %1,%0" : "=r" (dest) : \ "ri" ((unsigned int)src) , "0" (dest)) #define _movxb_(src, dest) __asm__("movxb %1,%0" : "=r" (dest) : \ "r" (src), "0" (dest) ) #define _movzb_(src, dest) __asm__("movzb %1,%0" : "=r" (dest) : \ "r" (src), "0" (dest) ) #define _movxw_(src, dest) __asm__("movxw %1,%0" : "=r" (dest) : \ "r" (src), "0" (dest) ) #define _movzw_(src, dest) __asm__("movzw %1,%0" : "=r" (dest) : \ "r" (src), "0" (dest) ) /* Multiplication Instructions */ #define _mulb_(src, dest) __asm__("mulb %1,%0" : "=r" (dest) : \ "ri" ((char)src) , "0" (dest)) #define _mulw_(src, dest) __asm__("mulw %1,%0" : "=r" (dest) : \ "ri" ((short)src) , "0" (dest)) #define _mulsb_(src, dest) __asm__("mulsb %1,%0" : "=r" (dest) : \ "r" ((char)src) , "0" (dest)) #define _mulsw_(src, dest) __asm__("mulsw %1,%0" : "=r" (dest) : \ "r" ((short)src) , "0" (dest)) #define _muluw_(src, dest) __asm__("muluw %1,%0" : "=r" (dest) : \ "r" ((unsigned short)src) , "0" (dest)) /* nop Instruction */ #define _nop_() __asm__("nop") /* or Instructions */ #define _orb_(src, dest) __asm__("orb %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) #define _orw_(src, dest) __asm__("orw %1,%0" : "=r" (dest) : \ "ri" ((unsigned short)src) , "0" (dest)) #define _ord_(src, dest) __asm__("ord %1,%0" : "=r" (dest) : \ "ri" ((unsigned int)src) , "0" (dest)) /* retx Instruction */ #define _retx_() __asm__("retx") /* Set Bit Instructions */ #define _sbitb_(pos, dest) __asm__("sbitb %1,%0" : "=mr" (dest) : \ "i" ((unsigned char)pos) , "0" (dest) : "cc") #define _sbitw_(pos, dest) __asm__("sbitw %1,%0" : "=mr" (dest) : \ "i" ((unsigned char)pos) , "0" (dest) : "cc") /* spr and sprd Instructions */ #define _spr_(procreg, dest) __asm__("spr\t" procreg ",%0" : \ "=r" (dest) : /* no input */ "0" (dest) : "cc") #define _sprd_(procregd, dest) __asm__("sprd\t" procregd ",%0" : \ "=r" (dest) : /* no input */ "0" (dest) : "cc") /* Store Instructions */ #define _storb_(src, address) __asm__("storb %1,%0" : "=m" (address) : \ "ri" ((unsigned int)src)) #define _storw_(src, address) __asm__("storw %1,%0" : "=m" (address) : \ "ri" ((unsigned int)src)) #define _stord_(src, address) __asm__("stord %1,%0" : "=m" (address) : \ "ri" ((unsigned int)src)) /* Store Multiple Instructions */ #define _storm_(mask, src) __asm__("storm %1,%0" : /* No output here */ : \ "i" (mask) , "r" ((unsigned int)src)) #define _stormp_(mask, src) __asm__("stormp %1,%0" : /* No output here */ : \ "i" (mask) , "r" ((unsigned int)src)) /* Substruct Instructions */ #define _subb_(src, dest) __asm__("subb %1, %0" : "=r" (dest) : \ "ri" ((unsigned char)src), "0" (dest) : "cc") #define _subw_(src, dest) __asm__("subw %1, %0" : "=r" (dest) : \ "ri" ((unsigned short)src), "0" (dest) : "cc") #define _subd_(src, dest) __asm__("subd %1, %0" : "=r" (dest) : \ "ri" ((unsigned long)src), "0" (dest) : "cc") /* Substruct with Carry Instructions */ #define _subcb_(src, dest) __asm__("subcb %1, %0" : "=r" (dest) : \ "ri" ((unsigned char)src), "0" (dest) : "cc") #define _subcw_(src, dest) __asm__("subcw %1, %0" : "=r" (dest) : \ "ri" ((unsigned short)src), "0" (dest) : "cc") /* Test Bit Instructions */ #define _tbit_(offset, base) __asm__("tbit %0,%1" : /* no output */ : \ "ri" ((unsigned char)offset) , "r" (base) : "cc") #define _tbitb_(pos, dest) __asm__("tbitb %0,%1" : /* No output */ : \ "i" ((unsigned char)pos) , "m" (dest) : "cc") #define _tbitw_(pos, dest) __asm__("tbitw %0,%1" : /* No output */ : \ "i" ((unsigned char)pos) , "m" (dest) : "cc") /* wait Instruction*/ #define _wait_() __asm__ volatile ("wait" : : : "cc") /* xor Instructions */ #define _xorb_(src, dest) __asm__("xorb %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) #define _xorw_(src, dest) __asm__("xorw %1,%0" : "=r" (dest) : \ "ri" ((unsigned short)src) , "0" (dest)) #define _xord_(src, dest) __asm__("xord %1,%0" : "=r" (dest) : \ "ri" ((unsigned long)src) , "0" (dest)) #if !defined (__CR16C__) #define _di_() __asm__ volatile ("di\n" : : : "cc") #else /* In CR16C architecture the "nop" instruction is required after the di instruction in order to be sure the interrupts are indeed disabled. For details, refer the the CR16C Programmers Reference Manual. */ #define _di_() __asm__ volatile ("di\n\tnop" : : : "cc") #endif /* mtgpr Instruction */ #define _mtgpr_(src, gpr) \ __asm__ volatile ("movd\t%[_src], " gpr : /* no output */ \ : [_src] "ri" (src) \ : gpr ) /* mfgpr Instruction */ #define _mfgpr_(gpr, dest) \ __asm__ volatile ("movd\t" gpr ", %[_dest]" : [_dest] "=r" (dest) \ : /* no inputs */ ) /* set_i_bit Operation Definition */ #define set_i_bit() \ do \ { \ unsigned short tpsr; \ _spr_("psr", tpsr); \ tpsr |= 0x0800; \ _lpr_("psr",tpsr); \ } while(0) /* set_i_bit Macro Definition */ #define _enable_global_interrupt_ set_i_bit /* clear_i_bit Operation Definition */ #define clear_i_bit() \ do \ { \ unsigned short tpsr; \ _spr_("psr", tpsr); \ tpsr &= 0xf7ff; \ _lpr_("psr",tpsr); \ } while(0) /* clear_i_bit Macro Definition */ #define _disbale_global_interrupt_ clear_i_bit #define _save_asm_(x) \ __asm__ volatile (x ::: "memory","cc", \ "r0","r1","r2","r3","r4","r5","r6","r7", \ "r8","r9","r10","r11","r12","r13") #endif /* _ASM */ picolibc-1.8.11/libc/machine/cr16/sys/libh.h000066400000000000000000000025371513574234600204040ustar00rootroot00000000000000/* libh.h -- CR16 default handlers * * Copyright (c) 2004 National Semiconductor Corporation * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #ifndef _LIBH #define _LIBH /* These are the first 16 entries of the default dispatch table as defined in the CompactRISC architecture: Entry Function ----- -------- 0 NULL 1 nmi 2 NULL 3 NULL 4 NULL 5 svc 6 dvz 7 flg 8 bpt 9 trc 10 und 11 NULL 12 iad 13 NULL 14 dbg 15 ise */ extern void (* const _dispatch_table[])(void); /* Function prototypes */ void svc_handler(void); void dvz_handler(void); void flg_handler(void); void und_handler(void); void iad_handler(void); #endif /* _LIBH */ picolibc-1.8.11/libc/machine/cr16/sys/syscall.h000066400000000000000000000034111513574234600211300ustar00rootroot00000000000000/* syscall.h -- CR16 virtual I/O and trap service codes * * Copyright (c) 2004 National Semiconductor Corporation * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #ifndef _SYSCALL_H #define _SYSCALL_H #include /* SVC codes to pass to the debugger */ /* Virtual I/O services */ #define SVC_OPEN 0x401 #define SVC_CLOSE 0x402 #define SVC_READ 0x403 #define SVC_WRITE 0x404 #define SVC_LSEEK 0x405 #define SVC_RENAME 0x406 #define SVC_UNLINK 0x407 #define SVC_GETENV 0x408 /* Time service */ #define SVC_TIME 0x300 /* Start/end of program services */ #define SVC_EOP 0x410 /* Trap services */ #define SVC_SVC 0x505 #define SVC_DVZ 0x506 #define SVC_FLG 0x507 #define SVC_UND 0x50a #define SVC_IAD 0x50c /* Places the code of the requested service in R0, then transfers control to the debugger using the BPT exception. It is called from the start routine, VIO functions and the trap handlers. */ #define STRINGIFY(x) #x #define HOST_SERVICE(service) \ do { \ __asm__("movd\t$" STRINGIFY(service) ",(r1,r0)"); \ _excp_(svc); \ } while (0) #endif /* _SYSCALL_H */ picolibc-1.8.11/libc/machine/cris/000077500000000000000000000000001513574234600166555ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/cris/include/000077500000000000000000000000001513574234600203005ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/cris/include/pthread.h000066400000000000000000000057331513574234600221100ustar00rootroot00000000000000/* pthread.h dummy. Copyright (C) 2001, 2004, 2005 Axis Communications AB. 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. Neither the name of Axis Communications nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AXIS COMMUNICATIONS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Simple fallback-include to enable thread-enabled exception support for libgcc, but with posix-interface to a default-dummy, so a posix library can optionally be linked in, which isn't possible if gthr-single.h is used. No other use is supported; *DO NOT* think this gives you a valid pthread interface to use in your applications. */ #ifndef _PTHREAD_FAKE #define _PTHREAD_FAKE #include _BEGIN_STD_C typedef int pthread_once_t; typedef unsigned int pthread_key_t; /* This must be layout-compatible with the linuxthreads type. */ typedef struct { int a, b; void *c; int d; struct { long int e; int f; } g; } pthread_mutex_t; /* This give bits equal to the linuxthreads initializer. */ #define PTHREAD_MUTEX_INITIALIZER \ { \ 0, 0, 0, 0, { 0, 0 } \ } #define PTHREAD_ONCE_INIT 0 /* This isn't the right prototype, but it let's us get away with not defining a lot of datatypes. */ extern int pthread_create(void) __THROW; extern int pthread_once(pthread_once_t *, void (*)(void)) __THROW; extern int pthread_key_create(pthread_key_t *, void (*)(void *)) __THROW; extern int pthread_setspecific(pthread_key_t, const void *) __THROW; extern void *pthread_getspecific(pthread_key_t) __THROW; extern int pthread_mutex_lock(pthread_mutex_t *) __THROW; extern int pthread_key_delete(pthread_key_t) __THROW; extern int pthread_mutex_trylock(pthread_mutex_t *) __THROW; extern int pthread_mutex_unlock(pthread_mutex_t *) __THROW; _END_STD_C #endif /* not _PTHREAD_FAKE */ picolibc-1.8.11/libc/machine/cris/libcdtor.c000066400000000000000000000061301513574234600206230ustar00rootroot00000000000000/* Call ctors and dtors from elinux a.out shared libraries. Copyright (C) 1999, 2000, 2003, 2004, 2005 Axis Communications. 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. Neither the name of Axis Communications nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AXIS COMMUNICATIONS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include typedef void (*vfnp)(void); /* The guts of the _Libctors and _Libdtors is "optimized" away into empty functions when the definition is visible as well. Simplest solution is to emit the definitions as asm. We have no .previous directive in a.out, so we rely on the fact that everything in this file goes into the .text section. */ __asm__(".text\n\t.global .$global.lib.ctors\n.$global.lib.ctors:\n\t.dword 0"); __asm__(".text\n\t.global .$global.lib.dtors\n.$global.lib.dtors:\n\t.dword 0"); extern vfnp * const _Ctors __asm__(".$global.lib.ctors"); extern vfnp * const _Dtors __asm__(".$global.lib.dtors"); /* We better provide weak empty ctor and dtor lists, since they are not created if the main program does not have ctor/dtors. Because it's otherwise not used, GCC trunk "Mon Jul 25 22:33:14 UTC 2005" thinks it can remove defaultors, so we need to artificially mark it as used. FIXME: Perhaps a GCC bug. */ static vfnp const defaultors[] __used = { 0, 0 }; extern vfnp *__CTOR_LIST__ __attribute__((weak, alias("defaultors"))); extern vfnp *__DTOR_LIST__ __attribute__((weak, alias("defaultors"))); void _Libctors(void) { const vfnp *firstor = _Ctors; const vfnp *ctors; /* Have to find the last ctor; they will run in opposite order as in the table. */ if (firstor != 0 && *firstor != 0) { for (ctors = firstor; *ctors != 0; ctors++) ; while (--ctors != firstor) { (**ctors)(); } (**ctors)(); } } void _Libdtors(void) { const vfnp *dtors = _Dtors; if (dtors) while (*dtors != 0) { (**dtors++)(); } } picolibc-1.8.11/libc/machine/cris/memcpy.c000066400000000000000000000176061513574234600203250ustar00rootroot00000000000000/* A memcpy for CRIS. Copyright (C) 1994-2005 Axis Communications. 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. Neither the name of Axis Communications nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AXIS COMMUNICATIONS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FIXME: This file should really only be used for reference, as the result is somewhat depending on gcc generating what we expect rather than what we describe. An assembly file should be used instead. */ #include #include #include "../../string/local.h" /* Break even between movem and move16 is really at 38.7 * 2, but modulo 44, so up to the next multiple of 44, we use ordinary code. */ #define MEMCPY_BY_BLOCK_THRESHOLD (44 * 2) /* No name ambiguities in this file. */ __asm__(".syntax no_register_prefix"); void * __no_builtin memcpy(void * __restrict pdst, const void * __restrict psrc, size_t pn) { /* Now we want the parameters put in special registers. Make sure the compiler is able to make something useful of this. As it is now: r10 -> r13; r11 -> r11 (nop); r12 -> r12 (nop). If gcc was allright, it really would need no temporaries, and no stack space to save stuff on. */ register void *return_dst __asm__("r10") = pdst; register unsigned char *dst __asm__("r13") = pdst; register unsigned const char *src __asm__("r11") = psrc; register int n __asm__("r12") = pn; /* When src is aligned but not dst, this makes a few extra needless cycles. I believe it would take as many to check that the re-alignment was unnecessary. */ if (((unsigned long)dst & 3) != 0 /* Don't align if we wouldn't copy more than a few bytes; so we don't have to check further for overflows. */ && n >= 3) { if ((unsigned long)dst & 1) { n--; *dst = *src; src++; dst++; } if ((unsigned long)dst & 2) { n -= 2; *(short *)dst = *(short *)src; src += 2; dst += 2; } } /* Decide which copying method to use. */ if (n >= MEMCPY_BY_BLOCK_THRESHOLD) { /* It is not optimal to tell the compiler about clobbering any registers; that will move the saving/restoring of those registers to the function prologue/epilogue, and make non-movem sizes suboptimal. */ __asm__ volatile("\ ;; GCC does promise correct register allocations, but let's \n\ ;; make sure it keeps its promises. \n\ .ifnc %0-%1-%2,$r13-$r11-$r12 \n\ .error \"GCC reg alloc bug: %0-%1-%4 != $r13-$r12-$r11\" \n\ .endif \n\ \n\ ;; Save the registers we'll use in the movem process \n\ ;; on the stack. \n\ subq 11*4,sp \n\ movem r10,[sp] \n\ \n\ ;; Now we've got this: \n\ ;; r11 - src \n\ ;; r13 - dst \n\ ;; r12 - n \n\ \n\ ;; Update n for the first loop. \n\ subq 44,r12 \n\ 0: \n\ " #ifdef __arch_common_v10_v32 /* Cater to branch offset difference between v32 and v10. We assume the branch below has an 8-bit offset. */ " setf\n" #endif " movem [r11+],r10 \n\ subq 44,r12 \n\ bge 0b \n\ movem r10,[r13+] \n\ \n\ ;; Compensate for last loop underflowing n. \n\ addq 44,r12 \n\ \n\ ;; Restore registers from stack. \n\ movem [sp+],r10" /* Outputs. */ : "=r"(dst), "=r"(src), "=r"(n) /* Inputs. */ : "0"(dst), "1"(src), "2"(n)); } while (n >= 16) { *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; n -= 16; } switch (n) { case 0: break; case 1: *dst = *src; break; case 2: *(short *)dst = *(short *)src; break; case 3: *(short *)dst = *(short *)src; dst += 2; src += 2; *dst = *src; break; case 4: *(long *)dst = *(long *)src; break; case 5: *(long *)dst = *(long *)src; dst += 4; src += 4; *dst = *src; break; case 6: *(long *)dst = *(long *)src; dst += 4; src += 4; *(short *)dst = *(short *)src; break; case 7: *(long *)dst = *(long *)src; dst += 4; src += 4; *(short *)dst = *(short *)src; dst += 2; src += 2; *dst = *src; break; case 8: *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; break; case 9: *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *dst = *src; break; case 10: *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(short *)dst = *(short *)src; break; case 11: *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(short *)dst = *(short *)src; dst += 2; src += 2; *dst = *src; break; case 12: *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; break; case 13: *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *dst = *src; break; case 14: *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(short *)dst = *(short *)src; break; case 15: *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(short *)dst = *(short *)src; dst += 2; src += 2; *dst = *src; break; } return return_dst; } picolibc-1.8.11/libc/machine/cris/memmove.c000066400000000000000000000207311513574234600204710ustar00rootroot00000000000000/* A memmove for CRIS. Copyright (C) 2000-2005 Axis Communications. 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. Neither the name of Axis Communications nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AXIS COMMUNICATIONS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FIXME: This file should really only be used for reference, as the result is somewhat depending on gcc generating what we expect rather than what we describe. An assembly file should be used instead. Even worse, we base it on memcpy, on the assumption that overlapping moves are rare, and we will do no worse than the generic memmove. */ #include #include /* Break even between movem and move16 is really at 38.7 * 2, but modulo 44, so up to the next multiple of 44, we use ordinary code. */ #define MEMMOVE_BY_BLOCK_THRESHOLD (44 * 2) /* No name ambiguities in this file. */ __asm__(".syntax no_register_prefix"); void * memmove(void *pdst, const void *psrc, size_t pn) { /* Now we want the parameters put in special registers. Make sure the compiler is able to make something useful of this. As it is now: r10 -> r13; r11 -> r11 (nop); r12 -> r12 (nop). If gcc was allright, it really would need no temporaries, and no stack space to save stuff on. */ register void *return_dst __asm__("r10") = pdst; register unsigned char *dst __asm__("r13") = pdst; register unsigned const char *src __asm__("r11") = psrc; register int n __asm__("r12") = pn; /* Check and handle overlap. */ if (src < dst && dst < src + n) { /* Destructive overlap. We could optimize this, but we don't (for the moment). */ src += n; dst += n; while (n--) { *--dst = *--src; } return return_dst; } /* Whew, no overlap. Proceed as with memcpy. We could call it instead of having a copy here. That would spoil some of the optimization, so we take the trouble with having two copies. */ /* When src is aligned but not dst, this makes a few extra needless cycles. I believe it would take as many to check that the re-alignment was unnecessary. */ if (((unsigned long)dst & 3) != 0 /* Don't align if we wouldn't copy more than a few bytes; so we don't have to check further for overflows. */ && n >= 3) { if ((unsigned long)dst & 1) { n--; *dst = *src; src++; dst++; } if ((unsigned long)dst & 2) { n -= 2; *(short *)dst = *(short *)src; src += 2; dst += 2; } } /* Decide which copying method to use. */ if (n >= MEMMOVE_BY_BLOCK_THRESHOLD) { /* It is not optimal to tell the compiler about clobbering any registers; that will move the saving/restoring of those registers to the function prologue/epilogue, and make non-movem sizes suboptimal. */ __asm__ volatile("\ ;; GCC does promise correct register allocations, but let's \n\ ;; make sure it keeps its promises. \n\ .ifnc %0-%1-%2,$r13-$r11-$r12 \n\ .error \"GCC reg alloc bug: %0-%1-%4 != $r13-$r12-$r11\" \n\ .endif \n\ \n\ ;; Save the registers we'll use in the movem process \n\ ;; on the stack. \n\ subq 11*4,sp \n\ movem r10,[sp] \n\ \n\ ;; Now we've got this: \n\ ;; r11 - src \n\ ;; r13 - dst \n\ ;; r12 - n \n\ \n\ ;; Update n for the first loop. \n\ subq 44,r12 \n\ 0: \n\ " #ifdef __arch_common_v10_v32 /* Cater to branch offset difference between v32 and v10. We assume the branch below has an 8-bit offset. */ " setf\n" #endif " movem [r11+],r10 \n\ subq 44,r12 \n\ bge 0b \n\ movem r10,[r13+] \n\ \n\ ;; Compensate for last loop underflowing n. \n\ addq 44,r12 \n\ \n\ ;; Restore registers from stack. \n\ movem [sp+],r10" /* Outputs. */ : "=r"(dst), "=r"(src), "=r"(n) /* Inputs. */ : "0"(dst), "1"(src), "2"(n)); } while (n >= 16) { *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; n -= 16; } switch (n) { case 0: break; case 1: *dst = *src; break; case 2: *(short *)dst = *(short *)src; break; case 3: *(short *)dst = *(short *)src; dst += 2; src += 2; *dst = *src; break; case 4: *(long *)dst = *(long *)src; break; case 5: *(long *)dst = *(long *)src; dst += 4; src += 4; *dst = *src; break; case 6: *(long *)dst = *(long *)src; dst += 4; src += 4; *(short *)dst = *(short *)src; break; case 7: *(long *)dst = *(long *)src; dst += 4; src += 4; *(short *)dst = *(short *)src; dst += 2; src += 2; *dst = *src; break; case 8: *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; break; case 9: *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *dst = *src; break; case 10: *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(short *)dst = *(short *)src; break; case 11: *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(short *)dst = *(short *)src; dst += 2; src += 2; *dst = *src; break; case 12: *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; break; case 13: *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *dst = *src; break; case 14: *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(short *)dst = *(short *)src; break; case 15: *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(long *)dst = *(long *)src; dst += 4; src += 4; *(short *)dst = *(short *)src; dst += 2; src += 2; *dst = *src; break; } return return_dst; } picolibc-1.8.11/libc/machine/cris/memset.c000066400000000000000000000204031513574234600203120ustar00rootroot00000000000000/* A memset for CRIS. Copyright (C) 1999-2005 Axis Communications. 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. Neither the name of Axis Communications nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AXIS COMMUNICATIONS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FIXME: This file should really only be used for reference, as the result is somewhat depending on gcc generating what we expect rather than what we describe. An assembly file should be used instead. */ /* Note the multiple occurrence of the expression "12*4", including the asm. It is hard to get it into the asm in a good way. Thus better to expose the problem everywhere: no macro. */ /* Assuming one cycle per dword written or read (ok, not really true; the world is not ideal), and one cycle per instruction, then 43+3*(n/48-1) <= 24+24*(n/48-1) so n >= 45.7; n >= 0.9; we win on the first full 48-byte block to set. */ #include #define MEMSET_BY_BLOCK_THRESHOLD (1 * 48) /* No name ambiguities in this file. */ __asm__(".syntax no_register_prefix"); void * memset(void *pdst, int c, unsigned int plen) { /* Now we want the parameters in special registers. Make sure the compiler does something usable with this. */ register char *return_dst __asm__("r10") = pdst; register int n __asm__("r12") = plen; register int lc __asm__("r11") = c; /* Most apps use memset sanely. Memsetting about 3..4 bytes or less get penalized here compared to the generic implementation. */ /* This is fragile performancewise at best. Check with newer GCC releases, if they compile cascaded "x |= x << 8" to sane code. */ __asm__("movu.b %0,r13 \n\ lslq 8,r13 \n\ move.b %0,r13 \n\ move.d r13,%0 \n\ lslq 16,r13 \n\ or.d r13,%0" : "=r"(lc) /* Inputs. */ : "0"(lc) /* Outputs. */ : "r13"); /* Trash. */ { register char *dst __asm__("r13") = pdst; if (((unsigned long)pdst & 3) != 0 /* Oops! n = 0 must be a valid call, regardless of alignment. */ && n >= 3) { if ((unsigned long)dst & 1) { *dst = (char)lc; n--; dst++; } if ((unsigned long)dst & 2) { *(short *)dst = lc; n -= 2; dst += 2; } } /* Decide which setting method to use. */ if (n >= MEMSET_BY_BLOCK_THRESHOLD) { /* It is not optimal to tell the compiler about clobbering any registers; that will move the saving/restoring of those registers to the function prologue/epilogue, and make non-block sizes suboptimal. */ __asm__ volatile( "\ ;; GCC does promise correct register allocations, but let's \n\ ;; make sure it keeps its promises. \n\ .ifnc %0-%1-%4,$r13-$r12-$r11 \n\ .error \"GCC reg alloc bug: %0-%1-%4 != $r13-$r12-$r11\" \n\ .endif \n\ \n\ ;; Save the registers we'll clobber in the movem process \n\ ;; on the stack. Don't mention them to gcc, it will only be \n\ ;; upset. \n\ subq 11*4,sp \n\ movem r10,[sp] \n\ \n\ move.d r11,r0 \n\ move.d r11,r1 \n\ move.d r11,r2 \n\ move.d r11,r3 \n\ move.d r11,r4 \n\ move.d r11,r5 \n\ move.d r11,r6 \n\ move.d r11,r7 \n\ move.d r11,r8 \n\ move.d r11,r9 \n\ move.d r11,r10 \n\ \n\ ;; Now we've got this: \n\ ;; r13 - dst \n\ ;; r12 - n \n\ \n\ ;; Update n for the first loop \n\ subq 12*4,r12 \n\ 0: \n\ " #include #ifdef __arch_common_v10_v32 /* Cater to branch offset difference between v32 and v10. We assume the branch below has an 8-bit offset. */ " setf\n" #endif " subq 12*4,r12 \n\ bge 0b \n\ movem r11,[r13+] \n\ \n\ ;; Compensate for last loop underflowing n. \n\ addq 12*4,r12 \n\ \n\ ;; Restore registers from stack. \n\ movem [sp+],r10" /* Outputs. */ : "=r"(dst), "=r"(n) /* Inputs. */ : "0"(dst), "1"(n), "r"(lc)); } /* An ad-hoc unroll, used for 4*12-1..16 bytes. */ while (n >= 16) { *(long *)dst = lc; dst += 4; *(long *)dst = lc; dst += 4; *(long *)dst = lc; dst += 4; *(long *)dst = lc; dst += 4; n -= 16; } switch (n) { case 0: break; case 1: *dst = (char)lc; break; case 2: *(short *)dst = (short)lc; break; case 3: *(short *)dst = (short)lc; dst += 2; *dst = (char)lc; break; case 4: *(long *)dst = lc; break; case 5: *(long *)dst = lc; dst += 4; *dst = (char)lc; break; case 6: *(long *)dst = lc; dst += 4; *(short *)dst = (short)lc; break; case 7: *(long *)dst = lc; dst += 4; *(short *)dst = (short)lc; dst += 2; *dst = (char)lc; break; case 8: *(long *)dst = lc; dst += 4; *(long *)dst = lc; break; case 9: *(long *)dst = lc; dst += 4; *(long *)dst = lc; dst += 4; *dst = (char)lc; break; case 10: *(long *)dst = lc; dst += 4; *(long *)dst = lc; dst += 4; *(short *)dst = (short)lc; break; case 11: *(long *)dst = lc; dst += 4; *(long *)dst = lc; dst += 4; *(short *)dst = (short)lc; dst += 2; *dst = (char)lc; break; case 12: *(long *)dst = lc; dst += 4; *(long *)dst = lc; dst += 4; *(long *)dst = lc; break; case 13: *(long *)dst = lc; dst += 4; *(long *)dst = lc; dst += 4; *(long *)dst = lc; dst += 4; *dst = (char)lc; break; case 14: *(long *)dst = lc; dst += 4; *(long *)dst = lc; dst += 4; *(long *)dst = lc; dst += 4; *(short *)dst = (short)lc; break; case 15: *(long *)dst = lc; dst += 4; *(long *)dst = lc; dst += 4; *(long *)dst = lc; dst += 4; *(short *)dst = (short)lc; dst += 2; *dst = (char)lc; break; } } return return_dst; } picolibc-1.8.11/libc/machine/cris/setjmp.c000066400000000000000000000200551513574234600203250ustar00rootroot00000000000000/* A setjmp.c for CRIS Copyright (C) 1993-2005 Axis Communications. 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. Neither the name of Axis Communications nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AXIS COMMUNICATIONS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* For benefit of CRIS v0..v3, we save and restore CCR to be able to correctly handle DI/EI; otherwise there would be no reason to save it. Note also that the "move x,ccr" does NOT affect the DMA enable bits (E and D) of v0..v3. We do not save mof; it is call-clobbered. It also does not exist in v0..v8; it should be safe to read or write to it there, but better not. jmp_buf[0] - PC jmp_buf[1] - SP (R14) jmp_buf[2] - R13 jmp_buf[3] - R12 jmp_buf[4] - R11 jmp_buf[5] - R10 jmp_buf[6] - R9 jmp_buf[7] - R8 jmp_buf[8] - R7 jmp_buf[9] - R6 jmp_buf[10] - R5 jmp_buf[11] - R4 jmp_buf[12] - R3 jmp_buf[13] - R2 jmp_buf[14] - R1 jmp_buf[15] - R0 jmp_buf[16] - SRP jmp_buf[17] - CCR */ #include #include int setjmp(jmp_buf buf) { int ret; #if defined(__arch_common_v10_v32) || defined(__arch_v32) /* No offsets in the compatibility mode. Also, movem saves in different order on v10 than on v32, so we use single move instructions instead, this not being a speed-prioritized operation. And we don't save CCR or CCS; since long unuseful. */ __asm__ __volatile__("move.d %1,$r13 \n" "move 0f,$mof \n" "move $mof,[$r13+] \n" "move.d $sp,[$r13+] \n" "clear.d [$r13+] \n" "move.d $r12,[$r13+] \n" "move.d $r11,[$r13+] \n" "move.d $r10,[$r13+] \n" "moveq 1,$r9 \n" "move.d $r9,[$r13+] \n" "move.d $r8,[$r13+] \n" "move.d $r7,[$r13+] \n" "move.d $r6,[$r13+] \n" "move.d $r5,[$r13+] \n" "move.d $r4,[$r13+] \n" "move.d $r3,[$r13+] \n" "move.d $r2,[$r13+] \n" "move.d $r1,[$r13+] \n" "move.d $r0,[$r13+] \n" "move $srp,[$r13+] \n" "clear.d [$r13+] \n" "clear.d $r9 \n" "0: \n" "move.d $r9,%0" /* Output. */ : "=&r"(ret) /* Input. */ : "r"(buf) /* Clobber. */ : "r9", "r13", "memory"); #else /* not __arch_common_v10_v32 or __arch_v32 */ #ifdef __PIC__ __asm__ __volatile__("moveq 1,$r9 \n" "movem $sp,[%1+1*4] \n" "move.d $pc,$r9 \n" "addq 0f-.,$r9 \n" "move.d $r9,[%1] \n" "move $srp,[%1+16*4] \n" "move $ccr,[%1+17*4] \n" "clear.d $r9 \n" "0: \n" "move.d $r9,%0" /* Output. */ : "=&r"(ret) /* Input. */ : "r"(buf) /* Clobber. */ : "r9", "memory"); #else /* not PIC */ __asm__ __volatile__("moveq 1,$r9 \n" "movem $sp,[%1+1*4] \n" "move.d 0f,$r9 \n" "move.d $r9,[%1] \n" "move $srp,[%1+16*4] \n" "move $ccr,[%1+17*4] \n" "clear.d $r9 \n" "0: \n" "move.d $r9,%0" /* Output. */ : "=&r"(ret) /* Input. */ : "r"(buf) /* Clobber. */ : "r9"); #endif /* not PIC */ #endif /* not __arch_common_v10_v32 or __arch_v32 */ return ret; } void longjmp(jmp_buf buf, int val) { #if defined(__arch_common_v10_v32) || defined(__arch_v32) __asm__ __volatile__("cmpq 0,%1 \n" "beq 0f \n" "move.d %0,$r13 ; In delay-slot. \n" "addq 6*4,$r13 \n" "move.d %1,[$r13] \n" "subq 6*4,$r13 \n" "0:\n" #ifdef __arch_common_v10_v32 /* Cater to branch offset difference between v32 and v10. We assume the branch above is 8-bit. */ "setf\n" #endif "move [$r13+],$mof \n" "move.d [$r13+],$sp \n" "addq 4,$r13 \n" "move.d [$r13+],$r12 \n" "move.d [$r13+],$r11 \n" "move.d [$r13+],$r10 \n" "move.d [$r13+],$r9 \n" "move.d [$r13+],$r8 \n" "move.d [$r13+],$r7 \n" "move.d [$r13+],$r6 \n" "move.d [$r13+],$r5 \n" "move.d [$r13+],$r4 \n" "move.d [$r13+],$r3 \n" "move.d [$r13+],$r2 \n" "move.d [$r13+],$r1 \n" "move.d [$r13+],$r0 \n" "move [$r13+],$srp \n" "move $mof,$r13 \n" "jump $r13 \n" "setf" /* No outputs. */ : /* Inputs. */ : "r"(buf), "r"(val) : "r13", "memory"); #else /* not __arch_common_v10_v32 or __arch_v32 */ __asm__ __volatile__("move [%0+17*4],$ccr \n" "move [%0+16*4],$srp \n" "test.d %1 \n" "beq 0f \n" "nop \n" "move.d %1,[%0+6*4] ; Offset for r9. \n" "0: \n" "movem [%0],$pc" /* No outputs. */ : /* Inputs. */ : "r"(buf), "r"(val) : "memory"); #endif /* not __arch_common_v10_v32 or __arch_v32 */ } picolibc-1.8.11/libc/machine/cris/sys/000077500000000000000000000000001513574234600174735ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/cris/sys/errno.h000066400000000000000000000235051513574234600207760ustar00rootroot00000000000000/* Copyright (C) 2001, 2004, 2005 Axis Communications AB. 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. Neither the name of Axis Communications nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS CONTRIBUTORS AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AXIS COMMUNICATIONS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This file is to be kept in sync with libc/include/sys/errno.h on which it is based, except values used or returned by syscalls must be those of the Linux/CRIS kernel. */ /* errno is not a global variable, because that would make using it non-reentrant. Instead, its address is returned by the function __errno. */ #ifndef _SYS_ERRNO_H_ #define _SYS_ERRNO_H_ #include _BEGIN_STD_C #define errno (*__errno()) int *__errno(void); /* Please don't use these variables directly. Use strerror instead. */ extern const char * const _sys_errlist[]; extern int _sys_nerr; #define __errno_r(ptr) errno /* Adjusted to the linux asm/errno.h */ #define EPERM 1 /* Operation not permitted */ #define ENOENT 2 /* No such file or directory */ #define ESRCH 3 /* No such process */ #define EINTR 4 /* Interrupted system call */ #define EIO 5 /* I/O error */ #define ENXIO 6 /* No such device or address */ #define E2BIG 7 /* Arg list too long */ #define ENOEXEC 8 /* Exec format error */ #define EBADF 9 /* Bad file number */ #define ECHILD 10 /* No child processes */ #define EAGAIN 11 /* Try again */ #define ENOMEM 12 /* Out of memory */ #define EACCES 13 /* Permission denied */ #define EFAULT 14 /* Bad address */ #define ENOTBLK 15 /* Block device required */ #define EBUSY 16 /* Device or resource busy */ #define EEXIST 17 /* File exists */ #define EXDEV 18 /* Cross-device link */ #define ENODEV 19 /* No such device */ #define ENOTDIR 20 /* Not a directory */ #define EISDIR 21 /* Is a directory */ #define EINVAL 22 /* Invalid argument */ #define ENFILE 23 /* File table overflow */ #define EMFILE 24 /* Too many open files */ #define ENOTTY 25 /* Not a typewriter */ #define ETXTBSY 26 /* Text file busy */ #define EFBIG 27 /* File too large */ #define ENOSPC 28 /* No space left on device */ #define ESPIPE 29 /* Illegal seek */ #define EROFS 30 /* Read-only file system */ #define EMLINK 31 /* Too many links */ #define EPIPE 32 /* Broken pipe */ #define EDOM 33 /* Math argument out of domain of func */ #define ERANGE 34 /* Math result not representable */ #define EDEADLK 35 /* Resource deadlock would occur */ #define ENAMETOOLONG 36 /* File name too long */ #define ENOLCK 37 /* No record locks available */ #define ENOSYS 38 /* Function not implemented */ #define ENOTEMPTY 39 /* Directory not empty */ #define ELOOP 40 /* Too many symbolic links encountered */ #define EWOULDBLOCK EAGAIN /* Operation would block */ #define ENOMSG 42 /* No message of desired type */ #define EIDRM 43 /* Identifier removed */ #define ECHRNG 44 /* Channel number out of range */ #define EL2NSYNC 45 /* Level 2 not synchronized */ #define EL3HLT 46 /* Level 3 halted */ #define EL3RST 47 /* Level 3 reset */ #define ELNRNG 48 /* Link number out of range */ #define EUNATCH 49 /* Protocol driver not attached */ #define ENOCSI 50 /* No CSI structure available */ #define EL2HLT 51 /* Level 2 halted */ #define EBADE 52 /* Invalid exchange */ #define EBADR 53 /* Invalid request descriptor */ #define EXFULL 54 /* Exchange full */ #define ENOANO 55 /* No anode */ #define EBADRQC 56 /* Invalid request code */ #define EBADSLT 57 /* Invalid slot */ #define EDEADLOCK EDEADLK #define EBFONT 59 /* Bad font file format */ /* This is only used internally in newlib; not returned by the kernel. EBFONT seems the closest match for a "bad file format" error. */ #define EFTYPE EBFONT /* Inappropriate file type or format */ #define ENOSTR 60 /* Device not a stream */ #define ENODATA 61 /* No data available */ #define ETIME 62 /* Timer expired */ #define ENOSR 63 /* Out of streams resources */ #define ENONET 64 /* Machine is not on the network */ #define ENOPKG 65 /* Package not installed */ #define EREMOTE 66 /* Object is remote */ #define ENOLINK 67 /* Link has been severed */ #define EADV 68 /* Advertise error */ #define ESRMNT 69 /* Srmount error */ #define ECOMM 70 /* Communication error on send */ #define EPROTO 71 /* Protocol error */ #define EMULTIHOP 72 /* Multihop attempted */ #define EDOTDOT 73 /* RFS specific error */ #define EBADMSG 74 /* Not a data message */ #define EOVERFLOW 75 /* Value too large for defined data type */ #define ENOTUNIQ 76 /* Name not unique on network */ #define EBADFD 77 /* File descriptor in bad state */ #define EREMCHG 78 /* Remote address changed */ #define ELIBACC 79 /* Can not access a needed shared library */ #define ELIBBAD 80 /* Accessing a corrupted shared library */ #define ELIBSCN 81 /* .lib section in a.out corrupted */ #define ELIBMAX 82 /* Attempting to link in too many shared libraries */ #define ELIBEXEC 83 /* Cannot exec a shared library directly */ #define EILSEQ 84 /* Illegal byte sequence */ #define ERESTART 85 /* Interrupted system call should be restarted */ #define ESTRPIPE 86 /* Streams pipe error */ #define EUSERS 87 /* Too many users */ #define ENOTSOCK 88 /* Socket operation on non-socket */ #define EDESTADDRREQ 89 /* Destination address required */ #define EMSGSIZE 90 /* Message too long */ #define EPROTOTYPE 91 /* Protocol wrong type for socket */ #define ENOPROTOOPT 92 /* Protocol not available */ #define EPROTONOSUPPORT 93 /* Protocol not supported */ #define ESOCKTNOSUPPORT 94 /* Socket type not supported */ #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ #define EPFNOSUPPORT 96 /* Protocol family not supported */ #define EAFNOSUPPORT 97 /* Address family not supported by protocol */ #define EADDRINUSE 98 /* Address already in use */ #define EADDRNOTAVAIL 99 /* Cannot assign requested address */ #define ENETDOWN 100 /* Network is down */ #define ENETUNREACH 101 /* Network is unreachable */ #define ENETRESET 102 /* Network dropped connection because of reset */ #define ECONNABORTED 103 /* Software caused connection abort */ #define ECONNRESET 104 /* Connection reset by peer */ #define ENOBUFS 105 /* No buffer space available */ #define EISCONN 106 /* Transport endpoint is already connected */ #define ENOTCONN 107 /* Transport endpoint is not connected */ #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ #define ETOOMANYREFS 109 /* Too many references: cannot splice */ #define ETIMEDOUT 110 /* Connection timed out */ #define ECONNREFUSED 111 /* Connection refused */ #define EHOSTDOWN 112 /* Host is down */ #define EHOSTUNREACH 113 /* No route to host */ #define EALREADY 114 /* Operation already in progress */ #define EINPROGRESS 115 /* Operation now in progress */ #define ESTALE 116 /* Stale NFS file handle */ #define EUCLEAN 117 /* Structure needs cleaning */ #define ENOTNAM 118 /* Not a XENIX named type file */ #define ENAVAIL 119 /* No XENIX semaphores available */ #define EISNAM 120 /* Is a named type file */ #define EREMOTEIO 121 /* Remote I/O error */ #define EDQUOT 122 /* Quota exceeded */ #define ENOMEDIUM 123 /* No medium found */ #define EMEDIUMTYPE 124 /* Wrong medium type */ #define ECANCELED 125 /* Operation Canceled */ #define ENOKEY 126 /* Required key not available */ #define EKEYEXPIRED 127 /* Key has expired */ #define EKEYREVOKED 128 /* Key has been revoked */ #define EKEYREJECTED 129 /* Key was rejected by service */ #define EOWNERDEAD 130 /* Owner died */ #define ENOTRECOVERABLE 131 /* State not recoverable */ /* Widely known to be a synonym in Linux. */ #define ENOTSUP EOPNOTSUPP #define __ELASTERROR 2000 /* Users can add values starting here */ _END_STD_C #endif /* _SYS_ERRNO_H */ picolibc-1.8.11/libc/machine/cris/sys/fcntl.h000066400000000000000000000144311513574234600207550ustar00rootroot00000000000000/* Copyright (C) 2001, 2004, 2005 Axis Communications AB. 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. Neither the name of Axis Communications nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS CONTRIBUTORS AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AXIS COMMUNICATIONS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This file is to be kept in sync with libc/include/sys/fcntl.h, on which it is based, except values used or returned by syscalls must be those of the Linux/CRIS kernel. */ #ifndef _FCNTL_ #define _FCNTL_ #include _BEGIN_STD_C #define _FOPEN (-1) /* from sys/file.h, kernel use only */ #define _FREAD 0x0001 /* read enabled */ #define _FWRITE 0x0002 /* write enabled */ #define _FNDELAY 0x0800 /* non blocking I/O (4.2 style) */ #define _FAPPEND 0x0400 /* append (writes guaranteed at the end) */ #define _FMARK 0x0010 /* internal; mark during gc() */ #define _FDEFER 0x0020 /* internal; defer for next gc pass */ #define _FASYNC 0x2000 /* signal pgrp when data ready */ #define _FCREAT 0x0040 /* open with file create */ #define _FTRUNC 0x0200 /* open with truncation */ #define _FEXCL 0x0080 /* error on open if file exists */ #define _FNBIO _FNONBLOCK /* non blocking I/O (sys5 style) */ #define _FSYNC 0x1000 /* do all writes synchronously */ #define _FNONBLOCK 0x0800 /* non blocking I/O (POSIX style) */ #define _FNOCTTY 0x0100 /* don't assign a ctty on this open */ #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR) /* * Flag values for open(2) and fcntl(2) * The kernel adds 1 to the open modes to turn it into some * combination of FREAD and FWRITE. */ #define O_RDONLY 0 /* +1 == FREAD */ #define O_WRONLY 1 /* +1 == FWRITE */ #define O_RDWR 2 /* +1 == FREAD|FWRITE */ #define O_APPEND _FAPPEND #define O_CREAT _FCREAT #define O_TRUNC _FTRUNC #define O_EXCL _FEXCL /* O_SYNC _FSYNC not posix, defined below */ /* O_NDELAY _FNDELAY set in include/fcntl.h */ /* O_NDELAY _FNBIO set in 5include/fcntl.h */ #define O_NONBLOCK _FNONBLOCK #define O_NOCTTY _FNOCTTY #ifndef _POSIX_SOURCE #define O_SYNC _FSYNC /* * Flags that work for fcntl(fd, F_SETFL, FXXXX) */ #define FAPPEND _FAPPEND #define FSYNC _FSYNC #define FASYNC _FASYNC #define FNBIO _FNBIO #define FNONBIO _FNONBLOCK /* XXX fix to be NONBLOCK everywhere */ #define FNDELAY _FNDELAY /* * Flags that are disallowed for fcntl's (FCNTLCANT); * used for opens, internal state, or locking. */ #define FREAD _FREAD #define FWRITE _FWRITE #define FMARK _FMARK #define FDEFER _FDEFER #define FSHLOCK _FSHLOCK #define FEXLOCK _FEXLOCK /* * The rest of the flags, used only for opens */ #define FOPEN _FOPEN #define FCREAT _FCREAT #define FTRUNC _FTRUNC #define FEXCL _FEXCL #define FNOCTTY _FNOCTTY #endif /* !_POSIX_SOURCE */ /* XXX close on exec request; must match UF_EXCLOSE in user.h */ #define FD_CLOEXEC 1 /* posix */ /* fcntl(2) requests */ #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get f_flags */ #define F_SETFD 2 /* set f_flags */ #define F_GETFL 3 /* more flags (cloexec) */ #define F_SETFL 4 #define F_GETLK 5 #define F_SETLK 6 #define F_SETLKW 7 #define F_SETOWN 8 /* for sockets. */ #define F_GETOWN 9 /* for sockets. */ /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ /* for posix fcntl() and lockf() */ #define F_RDLCK 0 #define F_WRLCK 1 #define F_UNLCK 2 /* for old implementation of bsd flock () */ #define F_EXLCK 4 /* or 3 */ #define F_SHLCK 8 /* or 4 */ /* operations for bsd flock(), also used by the kernel implementation */ #define LOCK_SH 1 /* shared lock */ #define LOCK_EX 2 /* exclusive lock */ #define LOCK_NB \ 4 /* or'd with one of the above to prevent \ blocking */ #define LOCK_UN 8 /* remove lock */ /* file segment locking set data type - information passed to system by user */ struct flock { short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */ short l_whence; /* flag to choose starting offset */ long l_start; /* relative offset, in bytes */ long l_len; /* length, in bytes; 0 means lock to EOF */ short l_pid; /* returned with F_GETLK */ short l_xxx; /* reserved for future use */ }; #ifndef _POSIX_SOURCE /* extended file segment locking set data type */ struct eflock { short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */ short l_whence; /* flag to choose starting offset */ long l_start; /* relative offset, in bytes */ long l_len; /* length, in bytes; 0 means lock to EOF */ short l_pid; /* returned with F_GETLK */ short l_xxx; /* reserved for future use */ long l_rpid; /* Remote process id wanting this lock */ long l_rsys; /* Remote system id wanting this lock */ }; #endif /* !_POSIX_SOURCE */ #include #include /* sigh. for the mode bits for open/creat */ extern int open(const char *, int, ...); extern int creat(const char *, mode_t); extern int fcntl(int, int, ...); /* Provide _ prototypes for functions provided by some versions of newlib. */ #ifdef _LIBC extern int _open(const char *, int, ...); extern int _fcntl(int, int, ...); #ifdef __LARGE64_FILES extern int _open64(const char *, int, ...); #endif #endif _END_STD_C #endif /* !_FCNTL_ */ picolibc-1.8.11/libc/machine/cris/sys/signal.h000066400000000000000000000105701513574234600211240ustar00rootroot00000000000000/* Copyright (C) 2001, 2004, 2005 Axis Communications AB. 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. Neither the name of Axis Communications nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS CONTRIBUTORS AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AXIS COMMUNICATIONS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This file is to be kept in sync (well, reasonably so, it's quite different) with libc/include/sys/signal.h on which it is based, except values used or returned by syscalls must be those of the Linux/CRIS kernel. */ /* sys/signal.h */ #ifndef _SYS_SIGNAL_H #define _SYS_SIGNAL_H #include #include _BEGIN_STD_C typedef unsigned long sigset_t; /* Adjusted to linux, has unused sa_restorer field and unsigned long sa_flags; relatively unimportant though. */ /* Type of a signal handler. */ typedef void (*__sighandler_t)(int); /* The type used in newlib sources. */ typedef __sighandler_t _sig_func_ptr; struct sigaction { __sighandler_t sa_handler; sigset_t sa_mask; unsigned long sa_flags; void (*sa_restorer)(void); }; /* Adjusted to glibc; other values. */ #define SA_NOCLDSTOP 1 /* only value supported now for sa_flags */ #if __POSIX_VISIBLE #define SIG_SETMASK 2 /* set mask with sigprocmask() */ #define SIG_BLOCK 0 /* set of signals to block */ #define SIG_UNBLOCK 1 /* set of signals to, well, unblock */ int sigprocmask(int __how, const sigset_t *__a, sigset_t *__b); #endif /* __POSIX_VISIBLE */ #ifdef _LIBC int _kill(pid_t, int); #endif #if __POSIX_VISIBLE int kill(pid_t, int); int sigaddset(sigset_t *, const int); int sigdelset(sigset_t *, const int); int sigismember(const sigset_t *, int); int sigfillset(sigset_t *); int sigemptyset(sigset_t *); /* These depend upon the type of sigset_t, which right now is always a long.. They're in the POSIX namespace, but are not ANSI. */ #define sigaddset(what, sig) (*(what) |= (1 << (sig)), 0) #define sigdelset(what, sig) (*(what) &= ~(1 << (sig)), 0) #define sigemptyset(what) (*(what) = 0, 0) #define sigfillset(what) (*(what) = ~(0), 0) #define sigismember(what, sig) (((*(what)) & (1 << (sig))) != 0) #endif /* __POSIX_VISIBLE */ /* Using __MISC_VISIBLE until POSIX Issue 8 is officially released */ #if __MISC_VISIBLE /* POSIX Issue 8 adds sig2str() and str2sig() */ #define SIG2STR_MAX 17 /* (sizeof("RTMAX+") + sizeof("4294967295") - 1) */ int sig2str(int, char *); int str2sig(const char * __restrict, int * __restrict); #endif /* __MISC_VISIBLE */ #define SIGHUP 1 #define SIGINT 2 #define SIGQUIT 3 #define SIGILL 4 #define SIGTRAP 5 #define SIGABRT 6 #define SIGIOT 6 #define SIGBUS 7 #define SIGFPE 8 #define SIGKILL 9 #define SIGUSR1 10 #define SIGSEGV 11 #define SIGUSR2 12 #define SIGPIPE 13 #define SIGALRM 14 #define SIGTERM 15 #define SIGSTKFLT 16 #define SIGCHLD 17 #define SIGCONT 18 #define SIGSTOP 19 #define SIGTSTP 20 #define SIGTTIN 21 #define SIGTTOU 22 #define SIGURG 23 #define SIGXCPU 24 #define SIGXFSZ 25 #define SIGVTALRM 26 #define SIGPROF 27 #define SIGWINCH 28 #define SIGIO 29 #define SIGPOLL SIGIO #define SIGPWR 30 #define NSIG 31 _END_STD_C #ifndef _SIGNAL_H_ /* Some applications take advantage of the fact that * and are equivalent in glibc. Allow for that here. */ #include #endif #endif /* _SYS_SIGNAL_H */ picolibc-1.8.11/libc/machine/crx/000077500000000000000000000000001513574234600165115ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/crx/getenv.c000066400000000000000000000016661513574234600201560ustar00rootroot00000000000000/* getenv.c -- Implementation of the getenv() routine * * Copyright (c) 2004 National Semiconductor Corporation * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ /* getenv() is implemented as a low-level function, thus we only invoke here the system call. */ #include char * getenv(const char *name) { char *_getenv(const char *); return (_getenv(name)); } picolibc-1.8.11/libc/machine/crx/setjmp.S000066400000000000000000000046221513574234600201430ustar00rootroot00000000000000#include ############################################################################## # setjmp.S -- CRX setjmp routine # # # /* Copyright (c) 2004 National Semiconductor Corporation */ # # # The authors hereby grant permission to use, copy, modify, distribute, # # and license this software and its documentation for any purpose, provided # # that existing copyright notices are retained in all copies and that this # # notice is included verbatim in any distributions. No written agreement, # # license, or royalty fee is required for any of the authorized uses. # # Modifications to this software may be copyrighted by their authors # # and need not follow the licensing terms described here, provided that # # the new terms are clearly indicated on the first page of each file where # # they apply. # # # # C library -- setjmp, longjmp # # longjmp(a,v) # # will generate a "return(v)" # # from the last call to # # setjmp(a) # # by restoring r7-ra, sp, # # and pc from 'a' # # and doing a return. (Makes sure that longjmp never returns 0). # ############################################################################## .text .file "setjmp.s" .align 4 .globl _setjmp .align 4 _setjmp: #r2: .blkw storm r2,{r7,r8,r9,r10,r11,r12,r13,r14} stord sp,0(r2) movd $0,r0 jump ra .globl _longjmp _longjmp: #r2: .blkw # pointer save area #r3: .blkw # ret vlaue loadm r2, {r7,r8,r9,r10,r11,r12,r13,ra} loadd 0(r2), sp movd r3, r0 cmpd $0, r3 bne end1 movd $1, r0 end1: jump ra .align 4 picolibc-1.8.11/libc/machine/crx/sys/000077500000000000000000000000001513574234600173275ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/crx/sys/asm.h000066400000000000000000000471521513574234600202710ustar00rootroot00000000000000/* asm.h -- CRX architecture intrinsic functions * * Copyright (c) 2004 National Semiconductor Corporation * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #ifndef _ASM #define _ASM /* Note that immediate input values are not checked for validity. It is the user's responsibility to use the intrinsic functions with appropriate immediate values. */ /* Absolute Instructions */ #define _absb_(src, dest) __asm__("absb %1, %0" : "=r" (dest) : \ "r" ((char)src) , "0" (dest)) #define _absw_(src, dest) __asm__("absw %1,%0" : "=r" (dest) : \ "r" ((short)src) , "0" (dest)) #define _absd_(src, dest) __asm__("absd %1, %0" : "=r" (dest) : \ "r" ((int)src) , "0" (dest)) /* Addition Instructions */ #define _addb_(src, dest) __asm__("addb %1, %0" : "=r" (dest) : \ "ri" ((unsigned char)src), "0" (dest) : "cc") #define _addub_(src, dest) __asm__("addub %1, %0" : "=r" (dest) : \ "ri" ((unsigned char)src), "0" (dest) : "cc") #define _addw_(src, dest) __asm__("addw %1, %0" : "=r" (dest) : \ "ri" ((unsigned short)src), "0" (dest) : "cc") #define _adduw_(src, dest) __asm__("adduw %1, %0" : "=r" (dest) : \ "ri" ((unsigned short)src), "0" (dest) : "cc") #define _addd_(src, dest) __asm__("addd %1, %0" : "=r" (dest) : \ "ri" ((unsigned int)src), "0" (dest) : "cc") #define _addud_(src, dest) __asm__("addud %1, %0" : "=r" (dest) : \ "ri" ((unsigned int)src), "0" (dest) : "cc") /* Add with Carry */ #define _addcb_(src, dest) __asm__("addcb %1, %0" : "=r" (dest) : \ "ri" ((unsigned char)src), "0" (dest) : "cc") #define _addcw_(src, dest) __asm__("addcw %1, %0" : "=r" (dest) : \ "ri" ((unsigned short)src), "0" (dest) : "cc") #define _addcd_(src, dest) __asm__("addcd %1, %0" : "=r" (dest) : \ "ri" ((unsigned int)src), "0" (dest) : "cc") /* Q-format Add */ #define _addqb_(src, dest) __asm__("addqb %1, %0" : "=r" (dest) : \ "r" ((unsigned char)src), "0" (dest) : "cc") #define _addqw_(src, dest) __asm__("addqw %1, %0" : "=r" (dest) : \ "r" ((unsigned short)src), "0" (dest) : "cc") #define _addqd_(src, dest) __asm__("addqd %1, %0" : "=r" (dest) : \ "r" ((unsigned int)src), "0" (dest) : "cc") /* Bitwise Logical AND */ #define _andb_(src, dest) __asm__("andb %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) #define _andw_(src, dest) __asm__("andw %1,%0" : "=r" (dest) : \ "ri" ((unsigned short)src) , "0" (dest)) #define _andd_(src, dest) __asm__("andd %1,%0" : "=r" (dest) : \ "ri" ((unsigned int)src) , "0" (dest)) /* bswap Instruction */ #define _bswap_(src, dest) __asm__("bswap %1,%0" : "=r" (dest) : \ "r" ((unsigned int)src) , "0" (dest)) /* cbit (clear bit) Instructions */ #define _cbitb_(pos, dest) __asm__("cbitb %1,%0" : "=mr" (dest) : \ "i" ((unsigned char)pos) , "0" (dest) : "cc") #define _cbitw_(pos, dest) __asm__("cbitw %1,%0" : "=mr" (dest) : \ "i" ((unsigned char)pos) , "0" (dest) : "cc") #define _cbitd_(pos, dest) __asm__("cbitd %1,%0" : "=r" (dest) : \ "i" ((unsigned char)pos) , "0" (dest) : "cc") /* Compare Instructions */ #define _cmpb_(src1, src2) __asm__("cmpb %0,%1" : /* no output */ : \ "ri" ((unsigned char)src1) , "r" (src2) : "cc") #define _cmpw_(src1,src2) __asm__("cmpw %0,%1" : /* no output */ \ : "ri" ((unsigned short)src1) , "r" (src2) : "cc") #define _cmpd_(src1,src2) __asm__("cmpd %0,%1" : /* no output */ \ : "ri" ((unsigned int)src1) , "r" (src2) : "cc") /* cntl Count Leading Ones Instructions */ #define _cntl1b_(src, dest) __asm__("cntl1b %1,%0" : "=r" (dest) : \ "r" ((char)src) , "0" (dest)) #define _cntl1w_(src, dest) __asm__("cntl1w %1,%0" : "=r" (dest) : \ "r" ((short)src) , "0" (dest)) #define _cntl1d_(src, dest) __asm__("cntl1d %1,%0" : "=r" (dest) : \ "r" ((int)src) , "0" (dest)) /* cntl Count Leading Zeros Instructions */ #define _cntl0b_(src, dest) __asm__("cntl0b %1,%0" : "=r" (dest) : \ "r" ((char)src) , "0" (dest)) #define _cntl0w_(src, dest) __asm__("cntl0w %1,%0" : "=r" (dest) : \ "r" ((short)src) , "0" (dest)) #define _cntl0d_(src, dest) __asm__("cntl0d %1,%0" : "=r" (dest) : \ "r" ((int)src) , "0" (dest)) /* cntl Count Leading Signs Instructions */ #define _cntlsb_(src, dest) __asm__("cntlsb %1,%0" : "=r" (dest) : \ "r" ((char)src) , "0" (dest)) #define _cntlsw_(src, dest) __asm__("cntlsw %1,%0" : "=r" (dest) : \ "r" ((short)src) , "0" (dest)) #define _cntlsd_(src, dest) __asm__("cntlsd %1,%0" : "=r" (dest) : \ "r" ((int)src) , "0" (dest)) /* Disable Inerrupts instructions */ #define _di_() __asm__ volatile ("di\n" : : : "cc") #define _disable_() __asm__ volatile ("di\n" : : : "cc") /* Enable Inerrupts instructions */ #define _ei_() __asm__ volatile ("ei\n" : : : "cc") #define _enable_() __asm__ volatile ("ei\n" : : : "cc") /* Enable Inerrupts instructions and Wait */ #define _eiwait_() __asm__ volatile ("eiwait" : : : "cc") /* excp Instructions */ #define _excp_(vector) __asm__ volatile ("excp " # vector) /* getpid Instruction */ #define _getrfid_(dest) __asm__("getrfid %0" : "=r" (dest) : \ /* No input */ : "cc") /* Load Instructions */ #define _loadb_(base,dest) __asm__("loadb %1,%0" : "=r" (dest) : \ "m" (base) , "0" (dest)) #define _loadw_(base,dest) __asm__("loadw %1,%0" : "=r" (dest) : \ "m" (base) , "0" (dest)) #define _loadd_(base,dest) __asm__("loadd %1,%0" : "=r" (dest) : \ "m" (base) , "0" (dest)) /* Load Multiple Instructions */ #define _loadm_(src, mask) __asm__("loadm %0,%1" : /* No output */ : \ "r" ((unsigned int)src) , "i" (mask)) #define _loadmp_(src, mask) __asm__("loadmp %0,%1" : /* No output */ : \ "r" ((unsigned int)src) , "i" (mask)) /* Multiply Accumulate Instrutions */ #define _macsb_(hi, lo, src1, src2) __asm__("macsb %1,%0" \ : =l (lo), =h (hi) \ : "r" ((char)src1) , "r" (src2)) #define _macsw_(hi, lo, src1, src2) __asm__("macsw %1,%0" \ : =l (lo), =h (hi) \ : "r" ((short)src1) , "r" (src2)) #define _macsd_(hi, lo, src1, src2) __asm__("macsd %1,%0" \ : =l (lo), =h (hi) \ : "r" ((int)src1) , "r" (src2)) #define _macub_(hi, lo, src1, src2) __asm__("macub %1,%0" \ : =l (lo), =h (hi) \ :"r" ((unsigned char)src1) , "r" (src2)) #define _macuw_(hi, lo, src1, src2) __asm__("macuw %1,%0" \ : =l (lo), =h (hi) \ : "r" ((unsigned short)src1) , "r" (src2)) #define _macud_(hi, lo, src1, src2) __asm__("macud %1,%0" \ : =l (lo), =h (hi) \ : "r" ((unsigned int)src1) , "r" (src2)) /* Q-Format Multiply Accumulate Instrutions */ #define _macqb_(src1, src2) __asm__("macqb %1,%0" \ : =l (lo), =h (hi) \ :"r" ((char)src1) , "r" (src2)) #define _macqw_(src1, src2) __asm__("macqw %1,%0" \ : =l (lo), =h (hi) \ :"r" ((short)src1) , "r" (src2)) #define _macqd_(src1, src2) __asm__("macqd %1,%0" \ : =l (lo), =h (hi) \ :"r" ((int)src1) , "r" (src2)) /* Maximum Instructions */ #define _maxsb_(src, dest) __asm__("maxsb %1,%0" : "=r" (dest) : \ "r" ((char)src) , "0" (dest)) #define _maxsw_(src, dest) __asm__("maxsw %1,%0" : "=r" (dest) : \ "r" ((short)src) , "0" (dest)) #define _maxsd_(src, dest) __asm__("maxsd %1,%0" : "=r" (dest) : \ "r" ((int)src) , "0" (dest)) #define _maxub_(src, dest) __asm__("maxub %1,%0" : "=r" (dest) : \ "r" ((unsigned char)src) , "0" (dest)) #define _maxuw_(src, dest) __asm__("maxuw %1,%0" : "=r" (dest) : \ "r" ((unsigned short)src) , "0" (dest)) #define _maxud_(src, dest) __asm__("maxud %1,%0" : "=r" (dest) : \ "r" ((unsigned int)src) , "0" (dest)) /* Minimum Instructions */ #define _minsb_(src, dest) __asm__("minsb %1,%0" : "=r" (dest) : \ "r" ((char)src) , "0" (dest)) #define _minsw_(src, dest) __asm__("minsw %1,%0" : "=r" (dest) : \ "r" ((short)src) , "0" (dest)) #define _minsd_(src, dest) __asm__("minsd %1,%0" : "=r" (dest) : \ "r" ((int)src) , "0" (dest)) #define _minub_(src, dest) __asm__("minub %1,%0" : "=r" (dest) : \ "r" ((unsigned char)src) , "0" (dest)) #define _minuw_(src, dest) __asm__("minuw %1,%0" : "=r" (dest) : \ "r" ((unsigned short)src) , "0" (dest)) #define _minud_(src, dest) __asm__("minud %1,%0" : "=r" (dest) : \ "r" ((unsigned int)src) , "0" (dest)) /* Move Instructions */ #define _movb_(src, dest) __asm__("movb %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) #define _movw_(src, dest) __asm__("movw %1,%0" : "=r" (dest) : \ "ri" ((unsigned short)src) , "0" (dest)) #define _movd_(src, dest) __asm__("movd %1,%0" : "=r" (dest) : \ "ri" ((unsigned int)src) , "0" (dest)) /* mtpr and mfpr Insturctions */ #define _mtpr_(procregd, src) __asm__("mtpr\t%0," procregd : /* no output */ : \ "r" (src) : "cc") #define _mfpr_(procregd, dest) __asm__("mfpr\t" procregd ",%0" : "=r" (dest) : \ /* no input */ "0" (dest) : "cc") /* Multiplication Instructions */ #define _mulsbw_(src, dest) __asm__("mulsbw %1,%0" : "=r" (dest) : \ "r" ((char)src) , "0" (dest)) #define _mulubw_(src, dest) __asm__("mulubw %1,%0" : "=r" (dest) : \ "r" ((unsigned char)src) , "0" (dest)) #define _mulswd_(src, dest) __asm__("mulswd %1,%0" : "=r" (dest) : \ "r" ((short)src) , "0" (dest)) #define _muluwd_(src, dest) __asm__("muluwd %1,%0" : "=r" (dest) : \ "r" ((unsigned short)src) , "0" (dest)) #define _mulb_(src, dest) __asm__("mulb %1,%0" : "=r" (dest) : \ "ri" ((char)src) , "0" (dest)) #define _mulw_(src, dest) __asm__("mulw %1,%0" : "=r" (dest) : \ "ri" ((short)src) , "0" (dest)) #define _muld_(src, dest) __asm__("muld %1,%0" : "=r" (dest) : \ "ri" ((int)src) , "0" (dest)) #define _mullsd_(hi, lo, src1, src2) __asm__("mullsd %2,%3" \ : =l (lo), =h (hi) \ : "r" ((unsigned int)src1) , "r" ((unsigned int)src2)) #define _mullud_(hi, lo, src1, src2) __asm__("mullud %2,%3" \ : =l (lo), =h (hi) \ : "r" ((int)src1) , "r" ((int)src2)) /* Q-Format Multiplication Instructions */ #define _mulqb_(src, dest) __asm__("mulqb %1,%0" : "=r" (dest) : \ "r" ((char)src) , "0" (dest)) #define _mulqw_(src, dest) __asm__("mulqw %1,%0" : "=r" (dest) : \ "r" ((short)src) , "0" (dest)) /* nop Instruction */ #define _nop_() __asm__("nop") /* Negate Instructions */ #define _negb_(src, dest) __asm__("negb %1,%0" : "=r" (dest) : \ "r" ((char)src) , "0" (dest)) #define _negw_(src, dest) __asm__("negw %1,%0" : "=r" (dest) : \ "r" ((short)src) , "0" (dest)) #define _negd_(src, dest) __asm__("negd %1,%0" : "=r" (dest) : \ "r" ((int)src) , "0" (dest)) /* or Instructions */ #define _orb_(src, dest) __asm__("orb %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) #define _orw_(src, dest) __asm__("orw %1,%0" : "=r" (dest) : \ "ri" ((unsigned short)src) , "0" (dest)) #define _ord_(src, dest) __asm__("ord %1,%0" : "=r" (dest) : \ "ri" ((unsigned int)src) , "0" (dest)) /* Pop 1's Count Instructions */ #define _popcntb_(src, dest) __asm__("popcntb %1,%0" : "=r" (dest) : \ "r" ((char)src) , "0" (dest)) #define _popcntw_(src, dest) __asm__("popcntw %1,%0" : "=r" (dest) : \ "r" ((short)src) , "0" (dest)) #define _popcntd_(src, dest) __asm__("popcntd %1,%0" : "=r" (dest) : \ "r" ((int)src) , "0" (dest)) /* Rotate and Mask Instructions */ #define _ram_(shift, end, begin, dest, src) __asm__("ram %1, %2, %3, %0, %4" : \ "=r" (dest) : \ "i" ((unsigned char) shift), \ "i" (end), "i" (begin), \ "r" (src), "0" (dest)) #define _rim_(shift, end, begin, dest, src) __asm__("rim %1, %2, %3, %0, %4" : \ "=r" (dest) : \ "i" ((unsigned char) shift), \ "i" (end), "i" (begin), \ "r" (src), "0" (dest)) /* retx Instruction */ #define _retx_() __asm__("retx") /* Rotate Instructions */ #define _rotb_(shift, dest) __asm__("rotb %1,%0" : "=r" (dest) : \ "i" ((unsigned char)shift) , "0" (dest)) #define _rotw_(shift, dest) __asm__("rotw %1,%0" : "=r" (dest) : \ "i" ((unsigned char)shift) , "0" (dest)) #define _rotd_(shift, dest) __asm__("rotd %1,%0" : "=r" (dest) : \ "i" ((unsigned char)shift) , "0" (dest)) #define _rotlb_(shift, dest) __asm__("rotlb %1,%0" : "=r" (dest) : \ "r" ((unsigned char)shift) , "0" (dest)) #define _rotlw_(shift, dest) __asm__("rotlw %1,%0" : "=r" (dest) : \ "r" ((unsigned char)shift) , "0" (dest)) #define _rotld_(shift, dest) __asm__("rotld %1,%0" : "=r" (dest) : \ "r" ((unsigned char)shift) , "0" (dest)) #define _rotrb_(shift, dest) __asm__("rotrb %1,%0" : "=r" (dest) : \ "r" ((unsigned char)shift) , "0" (dest)) #define _rotrw_(shift, dest) __asm__("rotrw %1,%0" : "=r" (dest) : \ "r" ((unsigned char)shift) , "0" (dest)) #define _rotrd_(shift, dest) __asm__("rotrd %1,%0" : "=r" (dest) : \ "r" ((unsigned char)shift) , "0" (dest)) /* Set Bit Instructions */ #define _sbitb_(pos,dest) __asm__("sbitb %1,%0" : "=mr" (dest) : \ "i" ((unsigned char)pos) , "0" (dest) : "cc") #define _sbitw_(pos,dest) __asm__("sbitw %1,%0" : "=mr" (dest) : \ "i" ((unsigned char)pos) , "0" (dest) : "cc") #define _sbitd_(pos,dest) __asm__("sbitd %1,%0" : "=mr" (dest) : \ "i" ((unsigned char)pos) , "0" (dest) : "cc") /* setrfid Instruction */ #define _setrfid_(src) __asm__("setrfid %0" : /* No output */ : \ "r" (src) : "cc") /* Sign Extend Instructions */ #define _sextbw_(src, dest) __asm__("sextbw %1,%0" : "=r" (dest) : \ "r" ((char)src) , "0" (dest) ) #define _sextbd_(src, dest) __asm__("sextbd %1,%0" : "=r" (dest) : \ "r" ((char)src) , "0" (dest) ) #define _sextwd_(src, dest) __asm__("sextwd %1,%0" : "=r" (dest) : \ "r" ((short)src) , "0" (dest) ) /* Shift Left Logical Instructions */ #define _sllb_(src, dest) __asm__("sllb %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) #define _sllw_(src, dest) __asm__("sllw %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) #define _slld_(src, dest) __asm__("slld %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) /* Shift Right Arithmetic Instructions */ #define _srab_(src, dest) __asm__("srab %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) #define _sraw_(src, dest) __asm__("sraw %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) #define _srad_(src, dest) __asm__("srad %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) /* Shift Right Logical Instructions */ #define _srlb_(src, dest) __asm__("srlb %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) #define _srlw_(src, dest) __asm__("srlw %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) #define _srld_(src, dest) __asm__("srld %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) /* Store Instructions */ #define _storb_(src,address) __asm__("storb %1,%0" : "=m" (address) : \ "ri" ((unsigned int)src)) #define _storw_(src,address) __asm__("storw %1,%0" : "=m" (address) : \ "ri" ((unsigned int)src)) #define _stord_(src,address) __asm__("stord %1,%0" : "=m" (address) : \ "ri" ((unsigned int)src)) /* Store Multiple Instructions */ #define _storm_(mask, src) __asm__("storm %1,%0" : /* No output here */ : \ "i" (mask) , "r" ((unsigned int)src)) #define _stormp_(mask, src) __asm__("stormp %1,%0" : /* No output here */ : \ "i" (mask) , "r" ((unsigned int)src)) /* Substruct Instructions */ #define _subb_(src, dest) __asm__("subb %1, %0" : "=r" (dest) : \ "ri" ((unsigned char)src), "0" (dest) : "cc") #define _subw_(src, dest) __asm__("subw %1, %0" : "=r" (dest) : \ "ri" ((unsigned short)src), "0" (dest) : "cc") #define _subd_(src, dest) __asm__("subd %1, %0" : "=r" (dest) : \ "ri" ((unsigned int)src), "0" (dest) : "cc") /* Substruct with Carry Instructions */ #define _subcb_(src, dest) __asm__("subcb %1, %0" : "=r" (dest) : \ "ri" ((unsigned char)src), "0" (dest) : "cc") #define _subcw_(src, dest) __asm__("subcw %1, %0" : "=r" (dest) : \ "ri" ((unsigned short)src), "0" (dest) : "cc") #define _subcd_(src, dest) __asm__("subcd %1, %0" : "=r" (dest) : \ "ri" ((unsigned int)src), "0" (dest) : "cc") /* Q-Format Substruct Instructions */ #define _subqb_(src, dest) __asm__("subqw %1,%0" : "=r" (dest) : \ "r" ((char)src) , "0" (dest)) #define _subqw_(src, dest) __asm__("subqw %1,%0" : "=r" (dest) : \ "r" ((short)src) , "0" (dest)) #define _subqd_(src, dest) __asm__("subqd %1,%0" : "=r" (dest) : \ "r" ((short)src) , "0" (dest)) /* Test Bit Instructions */ #define _tbitb_(pos,dest) __asm__("tbitb %0,%1" : /* No output */ : \ "i" ((unsigned char)pos) , "rm" (dest) : "cc") #define _tbitw_(pos,dest) __asm__("tbitw %0,%1" : /* No output */ : \ "i" ((unsigned char)pos) , "rm" (dest) : "cc") #define _tbitd_(pos,dest) __asm__("tbitd %0,%1" : /* No output */ : \ "i" ((unsigned char)pos) , "rm" (dest) : "cc") /* wait Instruction*/ #define _wait_() __asm__ volatile ("wait" : : : "cc") /* xor Instructions */ #define _xorb_(src, dest) __asm__("xorb %1,%0" : "=r" (dest) : \ "ri" ((unsigned char)src) , "0" (dest)) #define _xorw_(src, dest) __asm__("xorw %1,%0" : "=r" (dest) : \ "ri" ((unsigned short)src) , "0" (dest)) #define _xord_(src, dest) __asm__("xord %1,%0" : "=r" (dest) : \ "ri" ((unsigned int)src) , "0" (dest)) /* Zero Extend Instructions */ #define _zextbw_(src, dest) __asm__("zextbw %1,%0" : "=r" (dest) : \ "r" ((unsigned char)src) , "0" (dest)) #define _zextbd_(src, dest) __asm__("zextbd %1,%0" : "=r" (dest) : \ "r" ((unsigned char)src) , "0" (dest)) #define _zextwd_(src, dest) __asm__("zextwd %1,%0" : "=r" (dest) : \ "r" ((unsigned short)src) , "0" (dest)) #define _save_asm_(x) \ __asm__ volatile (x ::: "memory","cc", \ "r0","r1","r2","r3","r4","r5","r6","r7", \ "r8","r9","r10","r11","r12","r13") #endif /* _ASM */ picolibc-1.8.11/libc/machine/crx/sys/libh.h000066400000000000000000000025361513574234600204240ustar00rootroot00000000000000/* libh.h -- CRX default handlers * * Copyright (c) 2004 National Semiconductor Corporation * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #ifndef _LIBH #define _LIBH /* These are the first 16 entries of the default dispatch table as defined in the CompactRISC architecture: Entry Function ----- -------- 0 NULL 1 nmi 2 NULL 3 NULL 4 NULL 5 svc 6 dvz 7 flg 8 bpt 9 trc 10 und 11 NULL 12 iad 13 NULL 14 dbg 15 ise */ extern void (* const _dispatch_table[])(void); /* Function prototypes */ void svc_handler(void); void dvz_handler(void); void flg_handler(void); void und_handler(void); void iad_handler(void); #endif /* _LIBH */ picolibc-1.8.11/libc/machine/crx/sys/syscall.h000066400000000000000000000034531513574234600211570ustar00rootroot00000000000000/* syscall.h -- CRX virtual I/O and trap service codes * * Copyright (c) 2004 National Semiconductor Corporation * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #ifndef _SYSCALL_H #define _SYSCALL_H #include /* SVC codes to pass to the debugger */ /* Virtual I/O services */ #define SVC_OPEN 0x401 #define SVC_CLOSE 0x402 #define SVC_READ 0x403 #define SVC_WRITE 0x404 #define SVC_LSEEK 0x405 #define SVC_RENAME 0x406 #define SVC_UNLINK 0x407 #define SVC_GETENV 0x408 /* Time service */ #define SVC_TIME 0x300 /* Start/end of program services */ #define SVC_EOP 0x410 /* Trap services */ #define SVC_SVC 0x505 #define SVC_DVZ 0x506 #define SVC_FLG 0x507 #define SVC_UND 0x50a #define SVC_IAD 0x50c /* Places the code of the requested service in R0, then transfers control to the debugger using the BPT exception. It is called from the start routine, VIO functions and the trap handlers. */ #define STRINGIFY(x) #x #define HOST_SERVICE(service) \ do { \ __asm__("movd\t$" STRINGIFY(service) ",r0"); \ _excp_(bpt); \ __asm__(".short\t0xFFFF"); \ } while (0) #endif /* _SYSCALL_H */ picolibc-1.8.11/libc/machine/csky/000077500000000000000000000000001513574234600166665ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/csky/meson.build000066400000000000000000000031601513574234600210300ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2020 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'setjmp.S', ] src_machine = files(srcs_machine) picolibc-1.8.11/libc/machine/csky/setjmp.S000066400000000000000000000034211513574234600203140ustar00rootroot00000000000000/* Copyright (c) 2020 C-SKY Microsystems All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #include .section .text .align 3 .globl setjmp .type setjmp,@function .globl longjmp .type longjmp,@function setjmp: #if defined(__CK801__) stw r4, (r0, 0) stw r5, (r0, 4) stw r6, (r0, 8) stw r7, (r0, 12) stw r8, (r0, 16) stw r15, (r0, 20) stw sp, (r0, 24) #elif defined(__CK802__) stm r4-r11, (r0) stw r15, (r0, 32) stw sp, (r0, 36) #else stm r4-r11, (r0) stw r15, (r0, 32) stw r16, (r0, 36) stw r17, (r0, 40) stw r26, (r0, 44) stw r27, (r0, 48) stw r28, (r0, 52) stw r29, (r0, 56) stw r30, (r0, 60) stw r31, (r0, 64) stw sp, (r0, 68) #endif movi r0, 0 rts longjmp: #if defined(__CK801__) ldw r4, (r0, 0) ldw r5, (r0, 4) ldw r6, (r0, 8) ldw r7, (r0, 12) ldw r8, (r0, 16) ldw r15, (r0, 20) ldw sp, (r0, 24) #elif defined(__CK802__) ldm r4-r11, (r0) ldw r15, (r0, 32) ldw sp, (r0, 36) #else ldm r4-r11, (r0) ldw r15, (r0, 32) ldw r16, (r0, 36) ldw r17, (r0, 40) ldw r26, (r0, 44) ldw r27, (r0, 48) ldw r28, (r0, 52) ldw r29, (r0, 56) ldw r30, (r0, 60) ldw r31, (r0, 64) ldw sp, (r0, 68) #endif mov r0, r1 cmpnei r1, 0 bt 1f movi r0, 1 1: rts picolibc-1.8.11/libc/machine/d10v/000077500000000000000000000000001513574234600164675ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/d10v/setjmp.S000066400000000000000000000035241513574234600201210ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include ; setjmp/longjmp for D10V. The jmpbuf looks like this: ; ; Register jmpbuf offset ; R6 0x00 ; R7 0x02 ; R8 0x04 ; R9 0x06 ; R10 0x08 ; R11 0x0a ; R13 (return address) 0x0c ; R15 (SP) 0x0E .text .globl setjmp .type setjmp,@function .stabs "setjmp.S",100,0,0,setjmp .stabs "int:t(0,1)=r(0,1);-65536;65535;",128,0,0,0 .stabs "setjmp:F(0,1)",36,0,1,setjmp setjmp: ; Address of jmpbuf is passed in R0. Save the appropriate registers. st2w r6, @r0+ st2w r8, @r0+ st2w r10, @r0+ st r13, @r0+ st r15, @r0+ ; Return 0 to caller ldi r0, 0 jmp r13 .Lsetjmp: .size setjmp,.Lsetjmp-setjmp .stabs "",36,0,0,.Lsetjmp-setjmp .globl longjmp .type longjmp,@function .stabs "longjmp:F(0,1)",36,0,1,longjmp longjmp: ; Address of jmpbuf is in R0. Restore the registers. ld2w r6, @r0+ ld2w r8, @r0+ ld2w r10, @r0+ ld r13, @r0+ ld r15, @r0+ ; Value to return to caller is in R1. If caller attemped to return 0, ; return 1 instead. mv r0, r1 cmpeqi r0, 0 exef0t || ldi r0,1 jmp r13 .Llongjmp: .size longjmp,.Llongjmp-longjmp .stabs "",36,0,0,.Llongjmp-longjmp picolibc-1.8.11/libc/machine/d30v/000077500000000000000000000000001513574234600164715ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/d30v/setjmp.S000066400000000000000000000056451513574234600201310ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include ; setjmp/longjmp for D30V. .text .globl setjmp .type setjmp,@function .stabs "setjmp.S",100,0,0,setjmp .stabs "int:t(0,1)=r(0,1);-2147483648;2147483647;",128,0,0,0 .stabs "setjmp:F(0,1)",36,0,1,setjmp setjmp: ; Address of jmpbuf is passed in R2. Save the appropriate registers. st2w r26, @(r2+,r0) st2w r28, @(r2+,r0) st2w r30, @(r2+,r0) st2w r32, @(r2+,r0) st2w r34, @(r2+,r0) st2w r36, @(r2+,r0) st2w r38, @(r2+,r0) st2w r40, @(r2+,r0) st2w r42, @(r2+,r0) st2w r44, @(r2+,r0) st2w r46, @(r2+,r0) st2w r48, @(r2+,r0) st2w r50, @(r2+,r0) st2w r52, @(r2+,r0) st2w r54, @(r2+,r0) st2w r56, @(r2+,r0) st2w r58, @(r2+,r0) st2w r60, @(r2+,r0) st2w r62, @(r2+,r0) mvfacc r4, a1, 16 mvfacc r5, a1, 0 st2w r4, @(r2+,r0) mvfsys r4, psw mvfsys r5, rpt_c st2w r4, @(r2+,r0) mvfsys r4, rpt_s mvfsys r5, rpt_e st2w r4, @(r2+,r0) mvfsys r4, mod_s mvfsys r5, mod_e st2w r4, @(r2+,r0) ; Return 0 to caller add r2, r0, r0 jmp link .Lsetjmp: .size setjmp,.Lsetjmp-setjmp .stabs "",36,0,0,.Lsetjmp-setjmp .globl longjmp .type longjmp,@function .stabs "longjmp:F(0,1)",36,0,1,longjmp longjmp: ; Address of jmpbuf is in R2. Restore the registers. ld2w r26, @(r2+,r0) ld2w r28, @(r2+,r0) ld2w r30, @(r2+,r0) ld2w r32, @(r2+,r0) ld2w r34, @(r2+,r0) ld2w r36, @(r2+,r0) ld2w r38, @(r2+,r0) ld2w r40, @(r2+,r0) ld2w r42, @(r2+,r0) ld2w r44, @(r2+,r0) ld2w r46, @(r2+,r0) ld2w r48, @(r2+,r0) ld2w r50, @(r2+,r0) ld2w r52, @(r2+,r0) ld2w r54, @(r2+,r0) ld2w r56, @(r2+,r0) ld2w r58, @(r2+,r0) ld2w r60, @(r2+,r0) ld2w r62, @(r2+,r0) ld2w r4, @(r2+,r0) mvtacc a1, r4, r5 mvfsys r6, psw ld2w r4, @(r2+,r0) /* psw, rpt_c */ and r6, r6, 0xfcff /* set rp, md bits from setjmp, leave */ and r4, r4, 0x0300 /* all other psw bits the same */ or r4, r4, r6 mvtsys psw, r4 mvtsys rpt_c, r5 ld2w r4, @(r2+,r0) mvtsys rpt_s, r4 mvtsys rpt_e, r5 ld2w r4, @(r2+,r0) mvtsys mod_s, r4 mvtsys mod_e, r5 ; Value to return to caller is in R3. If caller attemped to return 0, ; return 1 instead. cmpeq f0, r3, 0 || add r2, r3, r0 jmp link || add/tx r2, r2, 1 .Llongjmp: .size longjmp,.Llongjmp-longjmp .stabs "",36,0,0,.Llongjmp-longjmp picolibc-1.8.11/libc/machine/epiphany/000077500000000000000000000000001513574234600175325ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/epiphany/setjmp.S000066400000000000000000000044541513574234600211670ustar00rootroot00000000000000/* setjmp and longjmp Copyright (c) 2011, Adapteva, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Adapteva nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include .file "setjmp.S" .section .text .align 4 .global _setjmp .type _setjmp, %function _setjmp: strd lr,[r0] strd r4,[r0,1] strd r6,[r0,2] strd r8,[r0,3] strd r10,[r0,4] strd r32,[r0,5] strd r34,[r0,6] strd r36,[r0,7] strd r38,[r0,8] str sp,[r0,18] mov r0,#0 rts .size _setjmp, .-_setjmp .global setjmp .set setjmp, _setjmp .global _longjmp _longjmp: ldrd lr,[r0] ; return address / r15 ldrd r4,[r0,1] ldrd r6,[r0,2] ldrd r8,[r0,3] ldrd r10,[r0,4] ldrd r32,[r0,5] ldrd r34,[r0,6] ldrd r36,[r0,7] ldrd r38,[r0,8] ldr sp,[r0,18] sub r1,r1,0 mov r0,#1 movne r0,r1 jr lr .size _longjmp, .-_longjmp .global longjmp .set longjmp, _longjmp picolibc-1.8.11/libc/machine/fr30/000077500000000000000000000000001513574234600164675ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/fr30/setjmp.S000066400000000000000000000027711513574234600201240ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include # setjmp/longjmp for FR30. The jmpbuf looks like this: # # Register jmpbuf offset # R8 0x00 # R9 0x04 # R10 0x08 # R11 0x0c # R12 0x10 # R13 0x14 # R14 (FP) 0x18 # R15 (SP) 0x1c # RP 0x20 .macro save reg st \reg,@r4 add #4,r4 .endm .macro restore reg ld @r4,\reg add #4,r4 .endm .text .global setjmp setjmp: save r8 save r9 save r10 save r11 save r12 save r13 save r14 save r15 mov RP,r5 st r5,@r4 # Return 0 to caller. ldi:8 #0,r4 ret .global longjmp longjmp: restore r8 restore r9 restore r10 restore r11 restore r12 restore r13 restore r14 restore r15 ld @r4,r4 mov r4,RP # If caller attempted to return 0, return 1 instead. mov r5,r4 or r4,r4 bne 1f ldi:8 #1,r4 1: ret picolibc-1.8.11/libc/machine/frv/000077500000000000000000000000001513574234600165125ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/frv/setjmp.S000066400000000000000000000051051513574234600201410ustar00rootroot00000000000000/* Copyright (c) 2002 Dave Brolley */ #include # setjmp/longjmp for Frv. The jmpbuf looks like this: # # Register jmpbuf offset # R16-R31 0x0-0x03c # R48-R63 0x40-0x7c # FR16-FR31 0x80-0xbc # FR48-FR63 0xc0-0xfc # LR 0x100 # SP 0x104 # FP 0x108 # # R8 contains the pointer to jmpbuf #include .text .global EXT(setjmp) .type EXT(setjmp),@function EXT(setjmp): stdi gr16, @(gr8,0) stdi gr18, @(gr8,8) stdi gr20, @(gr8,16) stdi gr22, @(gr8,24) stdi gr24, @(gr8,32) stdi gr26, @(gr8,40) stdi gr28, @(gr8,48) stdi gr30, @(gr8,56) #if __FRV_GPR__ != 32 stdi gr48, @(gr8,64) stdi gr50, @(gr8,72) stdi gr52, @(gr8,80) stdi gr54, @(gr8,88) stdi gr56, @(gr8,96) stdi gr58, @(gr8,104) stdi gr60, @(gr8,112) stdi gr62, @(gr8,120) #endif #if __FRV_FPR__ != 0 stdfi fr16, @(gr8,128) stdfi fr18, @(gr8,136) stdfi fr20, @(gr8,144) stdfi fr22, @(gr8,152) stdfi fr24, @(gr8,160) stdfi fr26, @(gr8,168) stdfi fr28, @(gr8,176) stdfi fr30, @(gr8,184) #if __FRV_FPR__ != 32 stdfi fr48, @(gr8,192) stdfi fr50, @(gr8,200) stdfi fr52, @(gr8,208) stdfi fr54, @(gr8,216) stdfi fr56, @(gr8,224) stdfi fr58, @(gr8,232) stdfi fr60, @(gr8,240) stdfi fr62, @(gr8,248) #endif #endif movsg lr, gr4 sti gr4, @(gr8,256) sti sp, @(gr8,260) sti fp, @(gr8,264) mov gr0,gr8 ret .Lend1: .size EXT(setjmp),.Lend1-EXT(setjmp) .global EXT(longjmp) .type EXT(longjmp),@function EXT(longjmp): lddi @(gr8,0), gr16 lddi @(gr8,8), gr18 lddi @(gr8,16), gr20 lddi @(gr8,24), gr22 lddi @(gr8,32), gr24 lddi @(gr8,40), gr26 lddi @(gr8,48), gr28 lddi @(gr8,56), gr30 #if __FRV_GPR__ != 32 lddi @(gr8,64), gr48 lddi @(gr8,72), gr50 lddi @(gr8,80), gr52 lddi @(gr8,88), gr54 lddi @(gr8,96), gr56 lddi @(gr8,104), gr58 lddi @(gr8,112), gr60 lddi @(gr8,120), gr62 #endif #if __FRV_FPR__ != 0 lddfi @(gr8,128), fr16 lddfi @(gr8,136), fr18 lddfi @(gr8,144), fr20 lddfi @(gr8,152), fr22 lddfi @(gr8,160), fr24 lddfi @(gr8,168), fr26 lddfi @(gr8,176), fr28 lddfi @(gr8,184), fr30 #if __FRV_FPR__ != 32 lddfi @(gr8,192), fr48 lddfi @(gr8,200), fr50 lddfi @(gr8,208), fr52 lddfi @(gr8,216), fr54 lddfi @(gr8,224), fr56 lddfi @(gr8,232), fr58 lddfi @(gr8,240), fr60 lddfi @(gr8,248), fr62 #endif #endif ldi @(gr8,256), gr4 movgs gr4,lr ldi @(gr8,260), sp ldi @(gr8,264), fp # Value to return is in r9. If zero, return 1 cmp gr9, gr0, icc0 setlos #1, gr8 ckne icc0, cc4 cmov gr9, gr8, cc4, 1 ret .Lend2: .size EXT(longjmp),.Lend2-EXT(longjmp) picolibc-1.8.11/libc/machine/ft32/000077500000000000000000000000001513574234600164735ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/ft32/memcpy.S000066400000000000000000000021111513574234600201040ustar00rootroot00000000000000/* A memcpy.c for FT32 Copyright (C) 2014 FTDI (support@ftdichip.com) The authors hereby grant permission to use, copy, modify, distribute, and license this software and its documentation for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions. No written agreement, license, or royalty fee is required for any of the authorized uses. Modifications to this software may be copyrighted by their authors and need not follow the licensing terms described here, provided that the new terms are clearly indicated on the first page of each file where they apply. */ #include .text .global memcpy .type memcpy,@function memcpy: ldk $r3,32764 1: cmp $r2,$r3 jmpc lte,2f memcpy.b $r0,$r1,$r3 add $r0,$r0,$r3 add $r1,$r1,$r3 sub $r2,$r2,$r3 jmp 1b 2: memcpy.b $r0,$r1,$r2 return .Lend2: .size memcpy,.Lend2-memcpy picolibc-1.8.11/libc/machine/ft32/memset.S000066400000000000000000000020551513574234600201130ustar00rootroot00000000000000/* A memset.c for FT32 Copyright (C) 2014 FTDI (support@ftdichip.com) The authors hereby grant permission to use, copy, modify, distribute, and license this software and its documentation for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions. No written agreement, license, or royalty fee is required for any of the authorized uses. Modifications to this software may be copyrighted by their authors and need not follow the licensing terms described here, provided that the new terms are clearly indicated on the first page of each file where they apply. */ #include .text .global memset .type memset,@function memset: ldk $r3,32764 1: cmp $r2,$r3 jmpc lte,2f memset.b $r0,$r1,$r3 add $r0,$r0,$r3 sub $r2,$r2,$r3 jmp 1b 2: memset.b $r0,$r1,$r2 return .Lend2: .size memset,.Lend2-memset picolibc-1.8.11/libc/machine/ft32/setjmp.S000066400000000000000000000053401513574234600201230ustar00rootroot00000000000000/* A setjmp.c for FT32 Copyright (C) 2014 FTDI (support@ftdichip.com) The authors hereby grant permission to use, copy, modify, distribute, and license this software and its documentation for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions. No written agreement, license, or royalty fee is required for any of the authorized uses. Modifications to this software may be copyrighted by their authors and need not follow the licensing terms described here, provided that the new terms are clearly indicated on the first page of each file where they apply. */ #include # setjmp/longjmp for FT32. # Total jumpbuf size is 108 bytes, or 27 words. # .text .global setjmp .type setjmp,@function setjmp: pop.l $r5 # return address in $r5 sti.l $r0,0,$r5 sti.l $r0,4,$r6 sti.l $r0,8,$r7 sti.l $r0,12,$r8 sti.l $r0,16,$r9 sti.l $r0,20,$r10 sti.l $r0,24,$r11 sti.l $r0,28,$r12 sti.l $r0,32,$r13 sti.l $r0,36,$r14 sti.l $r0,40,$r15 sti.l $r0,44,$r16 sti.l $r0,48,$r17 sti.l $r0,52,$r18 sti.l $r0,56,$r19 sti.l $r0,60,$r20 sti.l $r0,64,$r21 sti.l $r0,68,$r22 sti.l $r0,72,$r23 sti.l $r0,76,$r24 sti.l $r0,80,$r25 sti.l $r0,84,$r26 sti.l $r0,88,$r27 sti.l $r0,92,$r28 sti.l $r0,96,$r29 sti.l $r0,100,$r30 sti.l $r0,104,$r31 ldk.l $r0,0 jmpi $r5 .Lend1: .size setjmp,.Lend1-setjmp .global longjmp .type longjmp,@function longjmp: cmp.l $r1,0 jmpc nz,.nonz ldk.l $r1,1 .nonz: ldi.l $r5,$r0,0 ldi.l $r6,$r0,4 ldi.l $r7,$r0,8 ldi.l $r8,$r0,12 ldi.l $r9,$r0,16 ldi.l $r10,$r0,20 ldi.l $r11,$r0,24 ldi.l $r12,$r0,28 ldi.l $r13,$r0,32 ldi.l $r14,$r0,36 ldi.l $r15,$r0,40 ldi.l $r16,$r0,44 ldi.l $r17,$r0,48 ldi.l $r18,$r0,52 ldi.l $r19,$r0,56 ldi.l $r20,$r0,60 ldi.l $r21,$r0,64 ldi.l $r22,$r0,68 ldi.l $r23,$r0,72 ldi.l $r24,$r0,76 ldi.l $r25,$r0,80 ldi.l $r26,$r0,84 ldi.l $r27,$r0,88 ldi.l $r28,$r0,92 ldi.l $r29,$r0,96 ldi.l $r30,$r0,100 ldi.l $r31,$r0,104 move.l $r0,$r1 jmpi $r5 .Lend2: .size longjmp,.Lend2-longjmp picolibc-1.8.11/libc/machine/ft32/stpcmp.S000066400000000000000000000015711513574234600201310ustar00rootroot00000000000000/* A strlen.c for FT32 Copyright (C) 2014 FTDI (support@ftdichip.com) The authors hereby grant permission to use, copy, modify, distribute, and license this software and its documentation for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions. No written agreement, license, or royalty fee is required for any of the authorized uses. Modifications to this software may be copyrighted by their authors and need not follow the licensing terms described here, provided that the new terms are clearly indicated on the first page of each file where they apply. */ #include .text .global strlen .type strlen,@function strlen: strlen.b $r0,$r0 return .Lend2: .size strlen,.Lend2-strlen picolibc-1.8.11/libc/machine/ft32/strcmp.S000066400000000000000000000015751513574234600201370ustar00rootroot00000000000000/* A strcmp.c for FT32 Copyright (C) 2014 FTDI (support@ftdichip.com) The authors hereby grant permission to use, copy, modify, distribute, and license this software and its documentation for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions. No written agreement, license, or royalty fee is required for any of the authorized uses. Modifications to this software may be copyrighted by their authors and need not follow the licensing terms described here, provided that the new terms are clearly indicated on the first page of each file where they apply. */ #include .text .global strcmp .type strcmp,@function strcmp: strcmp.b $r0,$r0,$r1 return .Lend2: .size strcmp,.Lend2-strcmp picolibc-1.8.11/libc/machine/ft32/strcpy.S000066400000000000000000000016221513574234600201440ustar00rootroot00000000000000/* A strcpy.c for FT32 Copyright (C) 2014 FTDI (support@ftdichip.com) The authors hereby grant permission to use, copy, modify, distribute, and license this software and its documentation for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions. No written agreement, license, or royalty fee is required for any of the authorized uses. Modifications to this software may be copyrighted by their authors and need not follow the licensing terms described here, provided that the new terms are clearly indicated on the first page of each file where they apply. */ #include .text .global strcpy .type strcpy,@function strcpy: move.l $r5,$r0 stpcpy.b $r5,$r1 return .Lend2: .size strcpy,.Lend2-strcpy picolibc-1.8.11/libc/machine/ft32/strlen.S000066400000000000000000000015711513574234600201320ustar00rootroot00000000000000/* A strlen.c for FT32 Copyright (C) 2014 FTDI (support@ftdichip.com) The authors hereby grant permission to use, copy, modify, distribute, and license this software and its documentation for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions. No written agreement, license, or royalty fee is required for any of the authorized uses. Modifications to this software may be copyrighted by their authors and need not follow the licensing terms described here, provided that the new terms are clearly indicated on the first page of each file where they apply. */ #include .text .global strlen .type strlen,@function strlen: strlen.b $r0,$r0 return .Lend2: .size strlen,.Lend2-strlen picolibc-1.8.11/libc/machine/h8300/000077500000000000000000000000001513574234600164575ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/h8300/defines.h000066400000000000000000000054701513574234600202530ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #define A0 r0 #define A0L r0l #define A0H r0h #define A1 r1 #define A1L r1l #define A1H r1h #define A2 r2 #define A2L r2l #define A2H r2h #define A3 r3 #define A3L r3l #define A3H r3h #define S0 r4 #define S0L r4l #define S0H r4h #define S1 r5 #define S1L r5l #define S1H r5h #define S2 r6 #define S2L r6l #define S2H r6h #ifdef __H8300__ #define MOVP mov.w /* pointers are 16 bits */ #define ADDP add.w #define CMPP cmp.w #define PUSHP push #define POPP pop #define A0P r0 #define A1P r1 #define A2P r2 #define A3P r3 #define S0P r4 #define S1P r5 #define S2P r6 #endif /* __H8300__ */ #ifdef __H8300H__ #ifdef __NORMAL_MODE__ #define MOVP mov.w /* pointers are 16 bits */ #define ADDP add.w #define CMPP cmp.w #define PUSHP push #define POPP pop #define A0P r0 #define A1P r1 #define A2P r2 #define A3P r3 #define S0P r4 #define S1P r5 #define S2P r6 #else /* !__NORMAL_MODE__ */ #define MOVP mov.l /* pointers are 32 bits */ #define ADDP add.l #define CMPP cmp.l #define PUSHP push.l #define POPP pop.l #define A0P er0 #define A1P er1 #define A2P er2 #define A3P er3 #define S0P er4 #define S1P er5 #define S2P er6 #endif /* !__NORMAL_MODE__ */ #define A0E e0 #define A1E e1 #define A2E e2 #define A3E e3 #endif /* __H8300H__ */ #if defined(__H8300S__) || defined(__H8300SX__) #ifdef __NORMAL_MODE__ #define MOVP mov.w /* pointers are 16 bits */ #define ADDP add.w #define CMPP cmp.w #define PUSHP push #define POPP pop #define A0P r0 #define A1P r1 #define A2P r2 #define A3P r3 #define S0P r4 #define S1P r5 #define S2P r6 #else /* !__NORMAL_MODE__ */ #define MOVP mov.l /* pointers are 32 bits */ #define ADDP add.l #define CMPP cmp.l #define PUSHP push.l #define POPP pop.l #define A0P er0 #define A1P er1 #define A2P er2 #define A3P er3 #define S0P er4 #define S1P er5 #define S2P er6 #endif /* !__NORMAL_MODE__ */ #define A0E e0 #define A1E e1 #define A2E e2 #define A3E e3 #ifdef __NORMAL_MODE__ #define LEN(X) X #else #define LEN(X) e##X #endif #endif /* __H8300S__ */ picolibc-1.8.11/libc/machine/h8300/h8sx_strcpy.S000066400000000000000000000006001513574234600210750ustar00rootroot00000000000000/* Copyright (c) 2003 Richard Sandiford */ #include ; This file exists to provide a movsd implementation of strcpy(). ; Continue to use the generic version for targets other than h8sx. #ifdef __H8300SX__ #include "setarch.h" .global _strcpy _strcpy: stm.l er4-er6,@-er7 mov.l er0,er6 mov.l er1,er5 1: movsd 2f bra 1b 2: rts/l er4-er6 #endif picolibc-1.8.11/libc/machine/h8300/memcpy.S000066400000000000000000000077561513574234600201140ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include #include "setarch.h" #include "defines.h" #ifdef __H8300SX__ .global _memcpy _memcpy: stm.l er4-er6,@-er7 ; Set up source and destination pointers for movmd. mov.l er0,er6 mov.l er1,er5 ; See whether the copy is long enough to use the movmd.l code. ; Although the code can handle anything longer than 6 bytes, ; it can be more expensive than movmd.b for small moves. ; It's better to use a higher threshold to account for this. ; ; Note that the exact overhead of the movmd.l checks depends on ; the alignments of the length and pointers. They are faster when ; er0 & 3 == er1 & 3 == er2 & 3, faster still when these values ; are 0. This threshold is a compromise between the various cases. cmp #16,LEN(r2) blo simple ; movmd.l only works for even addresses. If one of the addresses ; is odd and the other is not, fall back on a simple move. bld #0,r5l bxor #0,r6l bcs simple ; Make the addresses even. bld #0,r5l bcc word_aligned mov.b @er5+,@er6+ sub #1,LEN(r2) word_aligned: ; See if copying one word would make the first operand longword ; aligned. Although this is only really worthwhile if it aligns ; the second operand as well, it's no worse if doesn't, so it ; hardly seems worth the overhead of a "band" check. bld #1,r6l bcc fast_copy mov.w @er5+,@er6+ sub #2,LEN(r2) fast_copy: ; Set (e)r4 to the number of longwords to copy. mov LEN(r2),LEN(r4) shlr #2,LEN(r4) #ifdef __NORMAL_MODE__ ; 16-bit pointers and size_ts: one movmd.l is enough. This code ; is never reached with r4 == 0. movmd.l and.w #3,r2 simple: mov.w r2,r4 beq quit movmd.b quit: rts/l er4-er6 #else ; Skip the first iteration if the number of longwords is divisible ; by 0x10000. mov.w r4,r4 beq fast_loop_next ; This loop copies r4 (!= 0) longwords the first time round and 65536 ; longwords on each iteration after that. fast_loop: movmd.l fast_loop_next: sub.w #1,e4 bhs fast_loop ; Mop up any left-over bytes. We could just fall through to the ; simple code after the "and" but the version below is quicker ; and only takes 10 more bytes. and.w #3,r2 beq quit mov.w r2,r4 movmd.b quit: rts/l er4-er6 simple: ; Simple bytewise copy. We need to handle all lengths, including zero. mov.w r2,r4 beq simple_loop_next simple_loop: movmd.b simple_loop_next: sub.w #1,e2 bhs simple_loop rts/l er4-er6 #endif #else .global _memcpy _memcpy: ; MOVP @(2/4,r7),A0P ; dst ; MOVP @(4/8,r7),A1P ; src ; MOVP @(6/12,r7),A2P ; len MOVP A0P,A3P ; keep copy of final dst ADDP A2P,A0P ; point to end of dst CMPP A0P,A3P ; see if anything to do beq quit ADDP A2P,A1P ; point to end of src ; lets see if we can do this in words or A0L,A2L ; or in the dst address or A3L,A2L ; or the length or A1L,A2L ; or the src address btst #0,A2L ; see if the lsb is zero bne byteloop wordloop: #ifdef __NORMAL_MODE__ sub #2,A1P #else subs #2,A1P ; point to word #endif mov.w @A1P,A2 ; get word mov.w A2,@-A0P ; save word CMPP A0P,A3P ; at the front again ? bne wordloop rts byteloop: #ifdef __NORMAL_MODE__ sub #1,A1P #else subs #1,A1P ; point to byte #endif mov.b @A1P,A2L ; get byte mov.b A2L,@-A0P ; save byte CMPP A0P,A3P ; at the front again ? bne byteloop ; return with A0 pointing to dst quit: rts #endif picolibc-1.8.11/libc/machine/h8300/memset.S000066400000000000000000000045731513574234600201060ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include #include "setarch.h" #include "defines.h" #if defined (__H8300SX__) .global _memset _memset: ; Use er3 is a temporary since er0 must remain unchanged on exit. mov.l er0,er3 ; Fill er1 with the byte to copy. mov.b r1l,r1h mov.w r1,e1 ; Account for any excess bytes and words that will be copied after ; the main loop. r2 >= 0 if there is a longword to copy. sub #4,LEN(r2) blo longs_done ; Copy one byte if doing so will make er3 word-aligned. ; This isn't needed for correctness but it makes the main loop ; slightly faster. bld #0,r3l bcc word_aligned mov.b r1l,@er3+ sub #1,LEN(r2) blo longs_done word_aligned: ; Likewise one word for longword alignment. bld #1,r3l bcc long_copy mov.w r1,@er3+ sub #2,LEN(r2) blo longs_done long_copy: ; Copy longwords. mov.l er1,@er3+ sub #4,LEN(r2) bhs long_copy longs_done: ; At this point, we need to copy r2 & 3 bytes. Copy a word ; if necessary. bld #1,r2l bcc words_done mov.w r1,@er3+ words_done: ; Copy a byte. bld #0,r2l bcc bytes_done mov.b r1l,@er3+ bytes_done: rts #else ; A0P pointer to cursor ; A1P thing to copy .global _memset _memset: ; MOVP @(2/4,r7),A2P ; dst ; MOVP @(4/8,r7),A1 ; src thing ; MOVP @(6/12,r7),A3P ; len MOVP A2P,A2P beq quit ; A3 points to the end of the area MOVP A0P,A3P ADDP A2P,A3P ; see if we can do it in words ; by oring in the start of the buffer to the end address or A0L,A2L btst #0,A2L bne byteloop ; we can do it a word at a time mov.b A1L,A1H wordloop: mov.w A1,@-A3P CMPP A3P,A0P bne wordloop quit: rts byteloop: mov.b A1L,@-A3P CMPP A3P,A0P bne byteloop rts #endif picolibc-1.8.11/libc/machine/h8300/reg_memcpy.S000066400000000000000000000024541513574234600207370ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include #include "setarch.h" #include "defines.h" ; dst A0 ; src A1 ; len A2 .global ___reg_memcpy ___reg_memcpy: MOVP A0P,A3P ; keep copy of result ADDP A2P,A0P ; point to end of dst ADDP A2P,A1P ; point to end of src CMPP A0P,A3P ; see if anything to do beq quit loop: #ifdef __NORMAL_MODE__ sub #1,A1P ; point to byte #else subs #1,A1P ; point to byte #endif mov.b @A1P,A2L ; get byte mov.b A2L,@-A0P ; save byte CMPP A0P,A3P ; at the front again ? bne loop ; return with A0 pointing to dst quit: rts picolibc-1.8.11/libc/machine/h8300/reg_memset.S000066400000000000000000000021221513574234600207270ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include #include "setarch.h" #include "defines.h" ; dst A0 ; src A1 ; len A2 .global ___reg_memset ___reg_memset: MOVP A0P,A3P MOVP A2P,A2P beq noset memloop: mov.b A1L,@A0P #ifdef __NORMAL_MODE__ add #1,A0P sub #1,A2P #else adds #1,A0P subs #1,A2P #endif MOVP A2P,A2P bne memloop noset: MOVP A3P,A0P rts picolibc-1.8.11/libc/machine/h8300/setarch.h000066400000000000000000000004671513574234600202700ustar00rootroot00000000000000/* Copyright (c) 2003 Kazu Hirata */ #ifdef __H8300H__ #ifdef __NORMAL_MODE__ .h8300hn #else .h8300h #endif #endif #ifdef __H8300S__ #ifdef __NORMAL_MODE__ .h8300sn #else .h8300s #endif #endif #ifdef __H8300SX__ #ifdef __NORMAL_MODE__ .h8300sxn #else .h8300sx #endif #endif picolibc-1.8.11/libc/machine/h8300/setjmp.S000066400000000000000000000034401513574234600201060ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include #include "setarch.h" .file "setjmp.S" .section .text .align 2 .global _setjmp _setjmp: #if defined(__H8300SX__) mov.l er7,@er0+ mov.l er6,@er0+ mov.l er5,@er0+ mov.l er4,@er0+ mov.l @sp,@er0 sub.l er0,er0 #elif defined(__H8300H__) || defined(__H8300S__) mov.l er7,@er0 mov.l er6,@(4,er0) mov.l er5,@(8,er0) mov.l er4,@(12,er0) mov.l @sp,er1 mov.l er1,@(16,er0) sub.l er0,er0 #else mov.w r7,@r0 mov.w r6,@(2,r0) mov.w r5,@(4,r0) mov.w r4,@(6,r0) mov.w @sp,r1 mov.w r1,@(8,r0) sub.w r0,r0 #endif rts .global _longjmp _longjmp: #if defined(__H8300H__) || defined (__H8300S__) || defined (__H8300SX__) mov.l @er0+,er7 mov.l @er0+,er6 mov.l @er0+,er5 mov.l @er0+,er4 #if defined(__H8300SX__) mov.l @er0,@sp #else mov.l @er0,er2 mov.l er2,@sp #endif #if (__INT_MAX__ <= 32767) mov.w r1,r0 #else mov.l er1,er0 #endif bne .L1 sub er0,er0 adds #1,er0 #else mov.w @r0+,r7 mov.w @r0+,r6 mov.w @r0+,r5 mov.w @r0+,r4 mov.w @r0,r2 mov.w r2,@sp mov.w r1,r0 bne .L1 mov.w #1,r0 #endif .L1: rts picolibc-1.8.11/libc/machine/h8300/strcmp.S000066400000000000000000000030361513574234600201150ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include #include "setarch.h" #include "defines.h" #if defined (__H8300SX__) .global _strcmp _strcmp: mov.l er0,er2 loop: mov.b @er2+,r0l beq eos sub.b @er1+,r0l beq loop exts.l #2,er0 rts eos: sub.b @er1,r0l exts.l #2,er0 rts #else .section .text .align 2 .global _strcmp _strcmp: MOVP A0P,A2P MOVP A1P,A3P .L5: mov.b @A2P+,A1L beq .L3 mov.b @A3P+,A0L cmp.b A0L,A1L beq .L5 #ifdef __NORMAL_MODE__ sub #1,A3P #else subs #1,A3P #endif .L3: mov.b @(-1,A2P),A0L mov.b @A3P,A1L sub.b A1L,A0L ; We have to sign extend the result to 32bits just in case ; we are using 32bit integers. #ifdef __H8300H__ exts.w r0 exts.l er0 #else #ifdef __H8300S__ exts.w r0 exts.l er0 #else bld #7,r0l subx r0h,r0h subx r1l,r1l subx r1h,r1h #endif #endif rts .end #endif picolibc-1.8.11/libc/machine/h8500/000077500000000000000000000000001513574234600164615ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/h8500/cmpsi.c000066400000000000000000000050601513574234600177410ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include union u { struct { short int msw; unsigned short lsw; } w; long l; }; union us { struct { short int msw; unsigned short lsw; } w; long l; }; int __cmpsi2(long arga, short int msw_b, unsigned short int lsw_b) { union u u; u.l = arga; if (u.w.msw != msw_b) { if (u.w.msw < msw_b) return 0; return 2; } if (u.w.lsw != lsw_b) { if (u.w.lsw < lsw_b) return 0; return 2; } return 1; } int __ucmpsi2(unsigned long arga, unsigned short int msw_b, unsigned short int lsw_b) { union us u; u.l = arga; if (u.w.msw != msw_b) { if (u.w.msw < msw_b) return 0; return 2; } if (u.w.lsw != lsw_b) { if (u.w.lsw < lsw_b) return 0; return 2; } return 1; } union pu { struct { char ignore; signed char msb; unsigned short lsw; } w; long l; }; union pun { struct { char ignore; unsigned char msb; unsigned short lsw; } w; long l; }; int __cmppsi2(long arga, long argb) { union pu a; union pu b; a.l = arga; b.l = argb; if (a.w.msb != b.w.msb) { if (a.w.msb < b.w.msb) return 0; return 2; } if (a.w.lsw != b.w.lsw) { if (a.w.lsw < b.w.lsw) return 0; return 2; } return 1; } int __ucmppsi2(long arga, long argb) { union pun a; union pun b; a.l = arga; b.l = argb; if (a.w.msb != b.w.msb) { if (a.w.msb < b.w.msb) return 0; return 2; } if (a.w.lsw != b.w.lsw) { if (a.w.lsw < b.w.lsw) return 0; return 2; } return 1; } picolibc-1.8.11/libc/machine/h8500/divhi3.S000066400000000000000000000025101513574234600177710ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .title "H8/500 DIVIDE" !! 2 byte integer Divide code for the H8/500 !! !! Steve Chamberlain !! sac@cygnus.com !! !! !! args in r1 and r4, result in r0/r1 #if __CODE__==32 #define RET prts #else #define RET rts #endif .global __divmodhi4 __divmodhi4: clr.w r0 tst.w r1 ! neg arg1 bpl PU neg.w r1 NU: tst.w r4 bmi NN NP: divxu.w r4,r0 neg.w r0 neg.w r1 RET NN: neg.w r4 divxu.w r4,r0 neg.w r0 ! get rem sign right RET PU: tst.w r4 bpl PP PN: neg.w r4 divxu.w r4,r0 neg.w r1 RET PP: divxu.w r4,r0 ! rem in r0, q in r1 RET picolibc-1.8.11/libc/machine/h8500/divsi3.c000066400000000000000000000060401513574234600200260ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include #define divnorm(num, den, sign) \ { \ if (num < 0) { \ num = -num; \ sign = 1; \ } else { \ sign = 0; \ } \ \ if (den < 0) { \ den = -den; \ sign = 1 - sign; \ } \ } unsigned long divmodsi4(int modwanted, unsigned long num, unsigned long den) { long int bit = 1; long int res = 0; long prevden; while (den < num && bit && !(den & (1L << 31))) { den <<= 1; bit <<= 1; } while (bit) { if (num >= den) { num -= den; res |= bit; } bit >>= 1; den >>= 1; } if (modwanted) return num; return res; } #define exitdiv(sign, res) \ if (sign) { \ res = -res; \ } \ return res; long __modsi3(long numerator, long denominator) { int sign = 0; long dividend; long modul; if (numerator < 0) { numerator = -numerator; sign = 1; } if (denominator < 0) { denominator = -denominator; } modul = divmodsi4(1, numerator, denominator); if (sign) return -modul; return modul; } long __divsi3(long numerator, long denominator) { int sign; long dividend; long modul; divnorm(numerator, denominator, sign); dividend = divmodsi4(0, numerator, denominator); exitdiv(sign, dividend); } long __umodsi3(unsigned long numerator, unsigned long denominator) { long dividend; long modul; modul = divmodsi4(1, numerator, denominator); return modul; } long __udivsi3(unsigned long numerator, unsigned long denominator) { int sign; long dividend; long modul; dividend = divmodsi4(0, numerator, denominator); return dividend; } #include #ifdef TEST main() { long int i, j, k, m; for (i = -10000; i < 10000; i += 8) { for (j = -10000; j < 10000; j += 11) { k = i / j; m = __divsi3(i, j); if (k != m) printf("fail %d %d %d %d\n", i, j, k, m); } } } #endif picolibc-1.8.11/libc/machine/h8500/mulhi3.c000066400000000000000000000017211513574234600200270ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include short __mulhi3(short a, short b) { int r; r = 0; while (a) { if (a & 1) { r += b; a >>= 1; b <<= 1; } } return r; } picolibc-1.8.11/libc/machine/h8500/mulsi3.c000066400000000000000000000031121513574234600200360ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include typedef union { struct { unsigned int msw; unsigned int lsw; } s; long v; } u; long __mulsi3(u a, u b) { int s; long pp1; long pp2; long r; if (a.s.msw == 0 && b.s.msw == 0) { return (long)a.s.lsw * b.s.lsw; } s = 0; if (a.v < 0) { s = 1; a.v = -a.v; } if (b.v < 0) { s = 1 - s; b.v = -b.v; } pp1 = (long)a.s.lsw * b.s.lsw; pp2 = (long)a.s.lsw * b.s.msw + (long)a.s.msw * b.s.lsw; pp1 += pp2 << 16; if (s) { pp1 = -pp1; } return pp1; } long __mulpsi3(long a, long b) { return a * b; } short __mulhi3(short a, short b) { int r; r = 0; while (a) { if (a & 1) { r += b; } b <<= 1; a >>= 1; } return r; } picolibc-1.8.11/libc/machine/h8500/negsi2.c000066400000000000000000000015011513574234600200110ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include long __negsi2(long x) { return ~x + 1; } picolibc-1.8.11/libc/machine/h8500/psi.S000066400000000000000000000065161513574234600174100ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* convert psi to si inplace Note that `fp' below isn't a segment register. It's r6, the frame pointer. */ #include #if __CODE__==32 #define RET prts #else #define RET rts #endif #define EXTPSISI_SN(r_msw,r_lsw,sp) ; \ .global __extpsisi##r_msw ; \ __extpsisi##r_msw: ; \ mov r_msw,r_lsw ; \ stc sp,r_msw ; \ RET EXTPSISI_SN(r2,r3,dp) EXTPSISI_SN(r4,r5,ep) #define ADDPSI_AR_RN(sr,an,r_msw,r_lsw) \ .global __addpsi##an##r_msw ; \ __addpsi##an##r_msw: ; \ stc sr,@-sp ; \ add an,r_lsw ; \ addx @sp+,r_msw ; \ RET ADDPSI_AR_RN(dp,r2,r0,r1) ADDPSI_AR_RN(dp,r2,r3,r4) ADDPSI_AR_RN(ep,r4,r0,r1) ADDPSI_AR_RN(ep,r4,r1,r2) ADDPSI_AR_RN(ep,r4,r3,r4) ADDPSI_AR_RN(ep,r4,r5,fp) ADDPSI_AR_RN(tp,fp,r0,r1) #define ADDPSI_RN_AR(r_msw,r_lsw,sr,an,t_msw,t_lsw) \ .global __addpsi##r_msw##an ; \ __addpsi##r_msw##an: ; \ mov.w t_msw,@-sp ; \ mov.w t_lsw,@-sp ; \ stc sr,t_msw ; \ mov an,t_lsw ; \ add r_lsw,t_lsw ; \ addx r_msw,t_msw ; \ ldc t_msw,sr ; \ mov.w t_lsw,an ; \ mov.w @sp+,t_lsw ; \ mov.w @sp+,t_msw ; \ RET ADDPSI_RN_AR(r0,r1,dp,r2,r4,r5) ADDPSI_RN_AR(r0,r1,ep,r4,r2,r3) #define EXTPSIHI_RN_RN(rm,r_msw,r_lsw) ; \ .global __extpsihi##rm##r_msw ; \ __extpsihi##rm##r_msw: ; \ mov rm,r_lsw ; \ clr.w r_msw ; \ RET EXTPSIHI_RN_RN(r3,r0,r1) EXTPSIHI_RN_RN(r4,r0,r1) EXTPSIHI_RN_RN(r5,r0,r1) EXTPSIHI_RN_RN(r2,r0,r1) /* ifdefed out, because gcc doesn't like the # character in the above macro. The macro expands into an assembly languange comment anyways, so it serves no useful purpose. */ #if 0 #define EXTPSIHI_RN_SN(rm,r_msw,r_lsw) ; \ .global __extpsihi##rm##r_lsw ; \ __extpsihi##rm##r_lsw: ; \ mov rm,r_lsw ; \ ldc \#0,r_msw ; \ RET EXTPSIHI_RN_SN(r0,dp,r2) EXTPSIHI_RN_SN(r0,ep,r4) EXTPSIHI_RN_SN(r1,dp,r2) EXTPSIHI_RN_SN(r1,ep,r4) EXTPSIHI_RN_SN(r3,dp,r2) EXTPSIHI_RN_SN(r3,ep,r4) EXTPSIHI_RN_SN(r5,dp,r2) EXTPSIHI_RN_SN(r5,ep,r4) EXTPSIHI_RN_SN(r2,ep,r4) #endif #define EXTPSISI_RN(r_msw,r_lsw) ; \ .global __extpsisi##r_msw ; \ __extpsisi##r_msw: ; \ RET EXTPSISI_RN(r0,r1) #define ADDPSI_SA_SB(sa,ra,sb,rb) ; \ .global __addpsi##ra##rb ; \ __addpsi##ra##rb: ; \ mov.w r0,@-sp ; \ mov.w r1,@-sp ; \ stc sa,r0 ; \ stc sb,r1 ; \ add.w ra,rb ; \ addx r0,r1 ; \ ldc r1,sb ; \ mov.w @sp+,r1 ; \ mov.w @sp+,r0 ; \ RET ADDPSI_SA_SB(dp,r2,ep,r4) ADDPSI_SA_SB(ep,r4,dp,r2) ADDPSI_SA_SB(tp,fp,dp,r2) ADDPSI_SA_SB(tp,fp,ep,r4) ADDPSI_SA_SB(dp,r2,dp,r2) .global __addpsir0r0 __addpsir0r0: add.w r1,r1 addx r0,r0 RET picolibc-1.8.11/libc/machine/h8500/setjmp.S000066400000000000000000000021071513574234600201070ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include ! .file "setjmp.S" .section .text .global _setjmp _setjmp: mov.w r7,@r0+ mov.w r6,@r0+ mov.w r5,@r0+ mov.w @sp,r1 mov.w r1,@r0 clr.w r0 rts .global _longjmp _longjmp: mov.w @r0+,r7 mov.w @r0+,r6 mov.w @r0+,r5 mov.w @r0,r2 mov.w r2,@sp mov.w r1,r0 tst.w r0 bne .L1 mov.w #1,r0 .L1: rts picolibc-1.8.11/libc/machine/h8500/shifts.c000066400000000000000000000023611513574234600201270ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include int __ashrhi3(int a, int b) { return a >> b; } int __ashlhi3(int a, int b) { return a << b; } unsigned __lshlhi3(unsigned int a, int b) { return a << b; } unsigned __lshrhi3(unsigned int a, int b) { return a >> b; } long __ashrsi3(long a, int b) { return a >> b; } long __ashlsi3(long a, int b) { return a << b; } unsigned __lshlsi3(unsigned long a, int b) { return a << b; } unsigned __lshrsi3(unsigned long a, int b) { return a >> b; } picolibc-1.8.11/libc/machine/hexagon/000077500000000000000000000000001513574234600173465ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/hexagon/longjmp.S000066400000000000000000000044241513574234600211440ustar00rootroot00000000000000/* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. SPDX-License-Identifier: BSD-3-Clause-Clear Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Qualcomm Technologies, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Hexagon implementation of setjmp */ .text .p2align 5 .globl longjmp .type longjmp, @function longjmp: r16=memw(r0++#4) r17=memw(r0++#4) r18=memw(r0++#4) r19=memw(r0++#4) r20=memw(r0++#4) r21=memw(r0++#4) r22=memw(r0++#4) r23=memw(r0++#4) r24=memw(r0++#4) r25=memw(r0++#4) r26=memw(r0++#4) r27=memw(r0++#4) r29=memw(r0++#4) r30=memw(r0++#4) r31=memw(r0++#4) r0 = r1 r1 = #0 p0 = cmp.eq(r0,r1) if (!p0) jumpr r31 /* not 0, return */ r0 = #1 /* oops, it was 0 */ jumpr r31 .size longjmp, . - longjmp picolibc-1.8.11/libc/machine/hexagon/meson.build000066400000000000000000000041501513574234600215100ustar00rootroot00000000000000# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. # SPDX-License-Identifier: BSD-3-Clause-Clear # # Redistribution and use in source and binary forms, with or without # modification, are permitted (subject to the limitations in the # disclaimer below) provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # * Neither the name of Qualcomm Technologies, Inc. nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE # GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT # HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. srcs_machine = [ 'setjmp.S', 'longjmp.S', 'tls.c', ] foreach params : targets target = params['name'] target_dir = params['dir'] target_c_args = params['c_args'] set_variable('lib_machine' + target, static_library('machine' + target, srcs_machine, pic: false, include_directories: inc, c_args: target_c_args + c_args + arg_fnobuiltin)) endforeach picolibc-1.8.11/libc/machine/hexagon/setjmp.S000066400000000000000000000043461513574234600210030ustar00rootroot00000000000000/* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. SPDX-License-Identifier: BSD-3-Clause-Clear Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Qualcomm Technologies, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Hexagon implementation of setjmp */ .text .p2align 5 .globl setjmp .type setjmp, @function setjmp: /* Save all the callee-preserved registers */ /* r0 has jmp_buf */ memw(r0++#4)=r16 memw(r0++#4)=r17 memw(r0++#4)=r18 memw(r0++#4)=r19 memw(r0++#4)=r20 memw(r0++#4)=r21 memw(r0++#4)=r22 memw(r0++#4)=r23 memw(r0++#4)=r24 memw(r0++#4)=r25 memw(r0++#4)=r26 memw(r0++#4)=r27 memw(r0++#4)=r29 memw(r0++#4)=r30 memw(r0++#4)=r31 r0 = #0 jumpr r31 .size setjmp, . - setjmp picolibc-1.8.11/libc/machine/hexagon/tls.c000066400000000000000000000042061513574234600203160ustar00rootroot00000000000000/* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. SPDX-License-Identifier: BSD-3-Clause-Clear Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Qualcomm Technologies, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #ifdef __THREAD_LOCAL_STORAGE_API extern char __tls_space_size[]; /* The Hexagon architecture uses the UGP register as the thread pointer. * Set UGP to the top of tls section i.e tls_base + tls_template_size */ void _set_tls(void *tls) { uintptr_t tls_base = (uintptr_t)tls; uintptr_t tls_template_size = (uintptr_t)__tls_space_size; __asm__("ugp=%0;" : : "r"(tls_base + tls_template_size)); } #endif picolibc-1.8.11/libc/machine/hppa/000077500000000000000000000000001513574234600166455ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/hppa/DEFS.h000066400000000000000000000112271513574234600175420ustar00rootroot00000000000000/* * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * and/or other materials related to such * distribution and use acknowledge that the software was developed * by the University of California, Berkeley. The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include "pcc_prefix.s" #define BLANK #define BANNER(str) BLANK.VERSION str #define ENTRY(Name) BLANK M_ENTRY(Name, PROF_ /**/ Name) #define ENTRYC(Name) BLANK M_ENTRYC(Name, PROF_ /**/ Name) #define EXIT(Name) BLANK M_EXIT(Name, PROF_ /**/ Name) #define EXITC(Name) BLANK M_EXITC(Name, PROF_ /**/ Name) #if 0 #define TEXT_SEGMENT .SPACE $TEXT$ !.SUBSPA $CODE$ #define RO_SEGMENT .SPACE $TEXT$ !.SUBSPA $lit$ #define DATA_SEGMENT .SPACE $PRIVATE$ !.SUBSPA $data$ #define BSS_SEGMENT .SPACE $PRIVATE$ !.SUBSPA $bss$ #else #define TEXT_SEGMENT .text #define RO_SEGMENT .rodata #define DATA_SEGMENT .data #define BSS_SEGMENT .bss #endif #ifdef PROF ; ; All four argument registers are saved into caller save registers; and restored after the call to _mcount.This is possible because; the mcount routine does not modify them, so we can.Mcount takes; 3 arguments; the first argument is the incoming 'rp', the second; is the starting address of the profiled routine, and the third is; the address of the PROF label(which is where mcount stores the; profile data).; #define M_ENTRY(name, prof) \ TEXT_SEGMENT !.label name !.PROC !.CALLINFO CALLER, SAVE_RP !.ENTRY !stw rp, \ -20(sp)!ldo 48(sp), sp !or arg0, r0, r19 !or arg1, r0, r20 !or arg2, r0, r21 !or arg3, r0, \ r22 !or rp, r0, arg0 !ldil L % name, r1 !ldo R % name(r1), \ arg1 !addil L % prof - $global$, dp !bl _mcount, rp !ldo R % prof - $global$(r1), \ arg2 !ldw - 68(sp), rp !ldo - 48(sp), sp !or r19, r0, arg0 !or r20, r0, arg1 !or r21, r0, \ arg2 !or r22, r0, arg3 ! #define M_ENTRYC(name, prof) \ TEXT_SEGMENT !.label name !.PROC !.CALLINFO CALLER, SAVE_RP !.ENTRY !stw rp, \ -20(sp)!ldo 128(sp), sp !or arg0, r0, r19 !or arg1, r0, r20 !or arg2, r0, r21 !or arg3, \ r0, r22 !or rp, r0, arg0 !ldil L % name, r1 !ldo R % name(r1), \ arg1 !addil L % prof - $global$, dp !bl _mcount, rp !ldo R % prof - $global$(r1), \ arg2 !ldw - 148(sp), rp !or r19, r0, arg0 !or r20, r0, arg1 !or r21, r0, arg2 !or r22, r0, \ arg3 ! ; ; The HPUX profiler uses a word for each entrypoint to store the profiling ; information.The setup code passes the address to the _mcount routine.; The EXIT macro defines a label(PROF_foo), and a word of storage.; #define M_EXIT(name, prof) \ bv, n r0(rp) !.EXIT !.PROCEND !.EXPORT name, \ ENTRY !DATA_SEGMENT !.label prof !.WORD 0 !.IMPORT $global$, DATA !.IMPORT _mcount, CODE #define M_EXITC(name, prof) \ bv r0(rp) !ldo - 128(sp), sp !.EXIT !.PROCEND !.EXPORT name, \ ENTRY !DATA_SEGMENT !.label prof !.WORD 0 !.IMPORT $global$, DATA !.IMPORT _mcount, CODE #else /* NOT profiling */ #define M_ENTRY(name, prof) TEXT_SEGMENT !.label name !.PROC !.CALLINFO !.ENTRY #define M_ENTRYC(name, prof) \ TEXT_SEGMENT !.label name !.PROC !.CALLINFO CALLER, SAVE_RP !.ENTRY !stw rp, \ -20(sp)!ldo 128(sp), sp #define M_EXIT(name, prof) bv, n r0(rp) !.EXIT !.PROCEND !.EXPORT name, ENTRY #define M_EXITC(name, prof) \ ldw - 148(sp), rp !bv r0(rp) !ldo - 128(sp), sp !.EXIT !.PROCEND !.EXPORT name, ENTRY #define ENTRY(Name) BLANK M_ENTRY(Name, PROF_ /**/ Name) #define ENTRYC(Name) BLANK M_ENTRYC(Name, PROF_ /**/ Name) #define EXIT(Name) BLANK M_EXIT(Name, PROF_ /**/ Name) #define EXITC(Name) BLANK M_EXITC(Name, PROF_ /**/ Name) #endif picolibc-1.8.11/libc/machine/hppa/memchr.S000066400000000000000000000025131513574234600202450ustar00rootroot00000000000000/* * (c) Copyright 1986 HEWLETT-PACKARD COMPANY * * To anyone who acknowledges that this file is provided "AS IS" * without any express or implied warranty: * permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies, and that the name of Hewlett-Packard Company not be * used in advertising or publicity pertaining to distribution * of the software without specific, written prior permission. * Hewlett-Packard Company makes no representations about the * suitability of this software for any purpose. */ /* SPECTRUM_ID: @(#)memchr.s 37.4 86/04/23 */ /* * memchr(s, c, n) * * returns pointer to first occurrence of char c * in first n characters of memory area s, * or null if c does not occur. */ #include #include "DEFS.h" #define FROM arg0 #define CHAR arg1 #define COUNT arg2 #define TEMP1 r19 ENTRY(memchr) comb,<= COUNT,r0,memchrexit /* return if count is zero */ copy r0,ret0 /* null if c not found in n chars */ depi 0,23,24,CHAR /* make char unsigned */ ldbs,ma 1(FROM),TEMP1 memchrloop: comb,=,n TEMP1,CHAR,memchrequal addib,<> -1,COUNT,memchrloop ldbs,ma 1(FROM),TEMP1 b,n memchrexit memchrequal: ldo -1(FROM),ret0 memchrexit: EXIT(memchr) picolibc-1.8.11/libc/machine/hppa/memcmp.S000066400000000000000000000157331513574234600202600ustar00rootroot00000000000000/* * (c) Copyright 1986 HEWLETT-PACKARD COMPANY * * To anyone who acknowledges that this file is provided "AS IS" * without any express or implied warranty: * permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies, and that the name of Hewlett-Packard Company not be * used in advertising or publicity pertaining to distribution * of the software without specific, written prior permission. * Hewlett-Packard Company makes no representations about the * suitability of this software for any purpose. */ /* memcmp(s1, s2, n) */ /* returns integer: < 0 iff s1 lexicographically less than s2 */ /* > 0 iff s1 lexicographically greater than s2 */ /* = 0 iff s1 lexicographically equal to s2 */ /* = 0 iff s1 lexicographically equal to s2 */ /* quit after n charachters */ #include #ifndef _NAMESPACE_CLEAN #define NOSECDEF /* prevents _memcmp from becoming primary entry */ #endif #include "DEFS.h" #define s1 26 #define s2 25 #define tmp1 19 #define s2word 20 #define tmp3 21 #define tmp7 22 #define s1word 29 #define save 1 #define tmp6 23 #define tmp5 28 #define count 24 ENTRY(memcmp) combt,<,n r0,count,search /*N <= 0 yields equality */ b done /**/ copy 0,ret0 /*return 0 (DELAY SLOT) */ search: combf,=,n s1,s2,findout /*s1 != s2? */ b done copy 0,ret0 /*return 0 (delay slot) */ findout: comibf,=,n 0,s1,checks1 /*s1 == NULL? */ ldbs 0(0,s2),ret0 /**/ b done /*quit */ sub 0,ret0,ret0 /*ret0 <- -*s2 */ checks1: comibf,=,n 0,s2,checkitout /*s2 == NULL? */ b done /* quit */ ldbs 0(0,s1),28 /* return *s1 */ checkitout: extru s2,31,2,tmp1 /* Extract the low two bits of the s2. */ extru s1,31,2,tmp5 /* Extract the low two bits of the s1 */ sub,= tmp5,tmp1,tmp3 /* Are s1 & s2 aligned with each other? */ b not_aligned /* It's more complicated (not_aligned) */ dep 0,31,2,s1 /* Compute word address of s1 (DELAY SLOT) */ dep 0,31,2,s2 /* Compute word address of s2 */ ldwm 4(0,s1),s1word /* get next s1 word s1+=4 */ combt,= tmp5,r0,skipmask /* skip masking, if we can */ ldwm 4(0,s2),s2word /* get next s2 word s2+=4 (DELAY SLOT) */ add tmp5,count,count /* bump count by the number of bytes */ /* we are going to mask */ sh3add tmp5,r0,save /* save now has number of bits to mask */ mtctl save,11 zvdepi -2,32,save /* load save with proper mask */ or save,s1word,s1word /* mask s1word (s1) */ or save,s2word,s2word /* mask s2word (s2) */ skipmask: combt,=,n s1word,s2word,checkN /* We may be done */ checkbyte: extru s1word,7,8,tmp3 /* get first byte (character) */ ckbyte2: extru s2word,7,8,tmp7 /* get first byte (character) */ combf,= tmp3,tmp7,done /* quit if first byte is not equal */ sub tmp3,tmp7,ret0 /* return difference (delay slot) */ addibt,<=,n -1,count,done /* have we checked N chars? ret0 == 0 */ extru s1word,15,8,tmp3 /* get second byte (character) */ extru s2word,15,8,tmp7 /* get second byte (character) */ combf,= tmp3,tmp7,done /* quit if second byte is not equal */ sub tmp3,tmp7,ret0 /* return difference (delay slot) */ addibt,<=,n -1,count,done /* have we checked N chars? */ extru s1word,23,8,tmp3 /* get third byte (character) */ extru s2word,23,8,tmp7 /* get third byte (character) */ combf,= tmp3,tmp7,done /* done if third byte is not equal */ sub tmp3,tmp7,ret0 /* return difference (delay slot) */ addibt,<=,n -1,count,done /* have we checked N chars? */ extru s1word,31,8,tmp3 /* get last byte (character) */ extru s2word,31,8,tmp7 /* get last byte (character) */ b done /* if we reach this point we know that */ sub tmp3,tmp7,ret0 /* the last character in the word is */ /* where the difference is, so return */ /* the difference and we're outta here */ checkN: addibt,<=,n -4,count,zero /* have we checked N chars? */ ldwm 4(0,s2),s2word /* get next s2 word s2+=4 */ b skipmask /* keep checking */ ldwm 4(0,s1),s1word /* get next s1 word s1+=4 */ not_aligned: dep r0,31,2,s2 /* Compute word address of s2 */ combt,<,n r0,tmp3,shifts1 /* Do we shift s1 or s2 */ sh3add tmp3,r0,tmp3 /* eight bits per byte so mul by 8 */ ldwm 4(0,s1),s1word /* get first word of s1 */ ldwm 4(0,s2),s2word /* get first word or s2 */ combt,=,n r0,tmp5,masks2 /* Do we need to mask beginning of s1 */ add tmp5,count,count /* bump count by the number of bytes */ /* we are going to mask */ sh3add tmp5,r0,save /* save now has number of bits to mask */ mtctl save,11 zvdepi -2,32,save /* load save with proper mask */ or save,s1word,s1word /**/ masks2: sh3add tmp1,r0,save /* save now has number of bits to mask */ mtctl save,11 zvdepi -2,32,save /* load save with proper mask */ or save,s2word,s2word /**/ subi 4,tmp1,tmp1 /* tmp1 now has the number of byte that */ /* are valid in s2word before the vshd */ mtctl tmp3,11 /* Move shift amount to CR11 */ more: combt,<=,n count,tmp1,chunk1 /* Can we do the vshd? */ ldwm 4(0,s2),tmp7 /* load second word to enable us to shift */ vshd s2word,tmp7,s2word /**/ combf,=,n s1word,s2word,ckbyte2 /**/ extru s1word,7,8,tmp3 /* get first byte (DELAY SLOT) */ addibt,<=,n -4,count,zero /* have we checked N chars? */ copy tmp7,s2word /**/ b more /* keep checking */ ldwm 4(0,s1),s1word /* get next s1 (DELAY SLOT) */ chunk1: vshd s2word,r0,s2word /* do an arithmetic shift left to position data */ b ckbyte2 /**/ extru s1word,7,8,tmp3 /**/ shifts1: sh3add tmp3,r0,tmp3 /* eight bits per byte so mul by 8 */ sub r0,tmp3,tmp3 /* Get negative value for left shift */ dep r0,31,2,s2 /* Compute word address of s2 */ ldwm 4(0,s2),s2word /* get first word of s2 */ ldwm 4(0,s1),s1word /* get first word or s1 */ combt,=,n r0,tmp1,masks1 /*Do we need to mask beginning of s2 */ add tmp1,count,count /*bump count by the number of bytes */ /* we are going to mask */ sh3add tmp1,r0,save /*save now has number of bits to mask */ mtctl save,11 zvdepi -2,32,save /*load save with proper mask */ or save,s2word,s2word /**/ masks1: sh3add tmp5,r0,save /*save now has number of bits to mask */ mtctl save,11 zvdepi -2,32,save /*load save with proper mask */ or save,s1word,s1word /**/ subi 4,tmp5,tmp5 /*tmp5 now has the number of byte that */ /*are valid in s1word before the vshd */ mtctl tmp3,11 /*Move shift amount to CR11 */ more1: combt,<=,n count,tmp5,chunk2 /*Can we do the vshd? */ ldwm 4(0,s1),tmp7 /*load second word to enable us to shift */ vshd s1word,tmp7,s1word /**/ combf,=,n s2word,s1word,ckbyte2 /**/ extru s1word,7,8,tmp3 /*get first byte (DELAY SLOT) */ addibt,<=,n -4,count,zero /*have we checked N chars? */ copy tmp7,s1word /**/ b more1 /*keep checking */ ldwm 4(0,s2),s2word /*get next s2 (DELAY SLOT) */ chunk2: vshd s1word,r0,s1word /**/ b ckbyte2 /**/ extru s1word,7,8,tmp3 /**/ zero: copy r0,ret0 done: EXIT(memcmp) picolibc-1.8.11/libc/machine/hppa/memcpy.S000066400000000000000000000147061513574234600202730ustar00rootroot00000000000000/* * (c) Copyright 1986 HEWLETT-PACKARD COMPANY * * To anyone who acknowledges that this file is provided "AS IS" * without any express or implied warranty: * permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies, and that the name of Hewlett-Packard Company not be * used in advertising or publicity pertaining to distribution * of the software without specific, written prior permission. * Hewlett-Packard Company makes no representations about the * suitability of this software for any purpose. */ /* HPUX_ID: @(#) $Revision$ */ /* * memcpy(s1, s2, n) * * Copy n characters from s2 to s1; returns s1. */ #include #define d_addr arg0 #define s_addr arg1 #define count arg2 #define tmp5 arg3 #define tmp1 r19 #define tmp2 r20 #define tmp3 r21 #define tmp4 r22 #define tmp6 r31 #include "DEFS.h" ENTRY(memcpy) comib,>= 5,count,byteloop /* If count is <= 6 don't get fancy.*/ movb,=,n d_addr,ret0,done /* The return value is defined to be the value of d_addr. DELAY SLOT */ /* if d_addr is null then exit */ extru s_addr,31,2,tmp1 /* Extract the low two bits of the source address. */ extru d_addr,31,2,tmp2 /* Extract the low two bits of the destination address. */ add count,tmp2,count /* pre increment the count to adjust for alignment of s1 */ comb,<> tmp2,tmp1,not_aligned /* see if s1 is aligned w.r.t. s2. */ dep 0,31,2,s_addr /* Compute the word address of the source. DELAY SLOT. */ /* aligned */ /* We will now begin the 16 byte at a time word move if count >= 16 ! */ /* Else we will branch to the 4 byte-at-a time word move ! */ addibt,<,n -16,count,chekchunk /* If count < 16 then we can't move 16 byte chunks ! */ /* actually we can legally move 13 or more bytes on the first loop. */ /* These loads and stores are done so as to prevent processor interlock. */ chunks: ldwm 16(0,s_addr),tmp1 /* tmp1 = *s_addr s_addr += 16 */ ldw -12(0,s_addr),tmp2 /* tmp2 = 2nd word */ ldw -8(0,s_addr),tmp3 /* tmp3 = 3rd word */ ldw -4(0,s_addr),tmp4 /* tmp4 = 4th word */ /* Now store the results ! */ stbys,b,m tmp1,4(0,d_addr) /* tmp1 = 1st word stored d_addr += 16 also take care of front porch. */ stwm tmp2,4(0,d_addr) /* tmp2 = 2nd word stored. */ stwm tmp3,4(0,d_addr) /* tmp3 = 3rd word stored. */ addibf,< -16,count,chunks /* If count is still >= 16 do another loop. */ stwm tmp4,4(0,d_addr) /* tmp4 = 4th word stored. DELAY SLOT */ chekchunk: addibt,<,n 12,count,back_porch /* since the count is already decremented by -16 we're testing */ /* to see if there are at least 4 bytes left ? */ subchunk: ldws,ma 4(s_addr),tmp1 /* tmp1 = *s_addr++ */ addibf,< -4,count,subchunk /* count -= 4 */ stbys,b,m tmp1,4(d_addr) /* *d_addr++ = tmp1 */ back_porch: addibt,=,n 4,count,done /* if count = 0 we're, of course, done ! */ ldws 0(s_addr),tmp1 /* load up the back_porch */ add d_addr,count,d_addr/* final store address is +1 too high ! */ bv 0(r2) /* return--were done. */ stbys,e tmp1,0(d_addr) /* kerplunk! whew ! */ /* Begin non_aligned code. (no refrence to politics) */ not_aligned: sub,>= tmp2,tmp1,tmp3 /* compute the shift quantity again and skip the load if tmp2 > tmp1. */ ldwm 4(0,s_addr),tmp1 /* load up the first word from the source. tmp1 = *s_addr++ */ zdep tmp3,28,29,tmp4 /* compute the number of bits to shift based on the number of bytes above. */ mtctl tmp4,11 /* load the shift count into cr11 = shift count register. */ addibt,<,n -16,count,chkchnk2 /* first step in pre adjustment of count for looping. */ chunk2: ldwm 16(0,s_addr),tmp2 /* get either first or second word . tmp2 = *s_addr++ */ ldw -12(s_addr),tmp3 ldw -8(s_addr),tmp4 ldw -4(s_addr),tmp5 vshd tmp1,tmp2,tmp6 /* position data ! */ stbys,b,m tmp6,4(0,d_addr) /* store ! */ vshd tmp2,tmp3,tmp6 /* position data ! */ stwm tmp6,4(0,d_addr) /* store ! */ vshd tmp3,tmp4,tmp6 /* position data ! */ stwm tmp6,4(0,d_addr) /* store ! */ vshd tmp4,tmp5,tmp6 /* position data ! */ stwm tmp6,4(0,d_addr) /* store the data ! */ addibf,< -16,count,chunk2 /* If count is still >= 16 do another loop. */ copy tmp5,tmp1 chkchnk2: addibt,<,n 12,count,bp_0 /* if we don't have 4 bytes left then do the back porch (bp_0) */ subchnk2: ldwm 4(0,s_addr),tmp2 /* get next word ! */ vshd tmp1,tmp2,tmp3 /* position data ! */ addibt,< -4,count,bp_1 /* decrement count and when count < 4 goto back_porch (bp_1) */ stbys,b,m tmp3,4(0,d_addr) /* store ! */ ldwm 4(0,s_addr),tmp1 /* get 4th word ! */ vshd tmp2,tmp1,tmp3 /* position data ! */ addib,>= -4,count,subchnk2 /* decrement count and when count <= 4 go to back porch (bp_2) */ stbys,b,m tmp3,4(0,d_addr) /* store the data ! */ bp_0: copy tmp1,tmp2 /* switch registers used in the shift process. */ bp_1: addibt,<=,n 4,count,done /* if count = -4 this implies that count = 0 -> done */ add d_addr,count,d_addr /* bump destination address to be +1 too high ! */ mfctl sar,tmp3 /* suppress final ldwm unless result used */ extru tmp3,28,2,tmp3 /* convert bitshift to byteshift */ sub,<= count,tmp3,r0 /* bytes unused if (count-byteshift <= 0*/ ldwm 4(0,s_addr),tmp1 /* get final word ! */ vshd tmp2,tmp1,tmp3 /* position data ! */ bv 0(r2) /* return */ stbys,e tmp3,0(0,d_addr) /* store the data ! */ /* here we do ye old byte-at-a-time moves. */ byteloop: comb,>=,n 0,count,done encore: ldbs,ma 1(s_addr),tmp1 addibf,= -1,count,encore stbs,ma tmp1,1(d_addr) done: EXIT(memcpy) picolibc-1.8.11/libc/machine/hppa/memset.S000066400000000000000000000047071513574234600202730ustar00rootroot00000000000000/* * (c) Copyright 1986 HEWLETT-PACKARD COMPANY * * To anyone who acknowledges that this file is provided "AS IS" * without any express or implied warranty: * permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies, and that the name of Hewlett-Packard Company not be * used in advertising or publicity pertaining to distribution * of the software without specific, written prior permission. * Hewlett-Packard Company makes no representations about the * suitability of this software for any purpose. */ /* SPECTRUM_ID: @(#)memset.s 37.4 86/08/25 */ /* * memset(s, c, n) * * Sets first n chars in memory area s to value of character c. * Returns s. */ #include #ifndef _NAMESPACE_CLEAN #define NOSECDEF /* prevent _memset from being defined as entry */ #endif #include "DEFS.h" #define TO arg0 #define FILLCHAR arg1 #define COUNT arg2 #define TMP r31 ENTRY(memset) comb,<= COUNT,r0,msexit /* return if count not positive */ copy TO,ret0 /* return value is start of copy */ comibf,<,n 5,COUNT,msbyteloop /* be straightforward */ dep FILLCHAR,23,8,FILLCHAR /* dup low byte */ dep FILLCHAR,15,16,FILLCHAR /* into high bytes */ add TO,COUNT,TMP /* TMP points just past fill area */ stbys,m FILLCHAR,0(TO) /* fill out first word */ /* * If we're pointing to high-order byte, no fill will happen, * but permissions will be checked. We don't want this (we * might be pointing at the beginning of a protected region), * so we branch around stbys if neither low bits are set. */ bb,<,n TMP,31,filend /* if low bit is set, stbys */ bb,>=,n TMP,30,endfil /* if next lowest bit isn't set */ /* (and lowest isn't, either) */ /* do not stbys */ filend: stbys,m,e FILLCHAR,0(TMP) /* fill out the last */ endfil: addi 4, TO, TO sub TMP,TO,COUNT /* will now divide by 4 */ comb,=,n COUNT,r0,msexit /* If count is zero ret. */ extru,<> COUNT,31,4,r1 b msquadloop depi 0,31,4,COUNT /* will now divide by 16 */ mswordloop: addib,<> -4,r1,mswordloop stws,ma FILLCHAR,4(TO) comb,=,n COUNT,r0,msexit /* If count is zero ret. */ msquadloop: stws,ma FILLCHAR,4(TO) stws,ma FILLCHAR,4(TO) stws,ma FILLCHAR,4(TO) addib,<> -16,COUNT,msquadloop stws,ma FILLCHAR,4(TO) b,n msexit msbyteloop: addib,<> -1,COUNT,msbyteloop stbs,ma FILLCHAR,1(TO) msexit: EXIT(memset) picolibc-1.8.11/libc/machine/hppa/pcc_prefix.s000066400000000000000000000162201513574234600211540ustar00rootroot00000000000000; ; (c) Copyright 1986 HEWLETT-PACKARD COMPANY ; ; To anyone who acknowledges that this file is provided "AS IS" ; without any express or implied warranty: ; permission to use, copy, modify, and distribute this file ; for any purpose is hereby granted without fee, provided that ; the above copyright notice and this notice appears in all ; copies, and that the name of Hewlett-Packard Company not be ; used in advertising or publicity pertaining to distribution ; of the software without specific, written prior permission. ; Hewlett-Packard Company makes no representations about the ; suitability of this software for any purpose. ; ; Standard Hardware Register Definitions for Use with Assembler ; version A.08.06 ; - fr16-31 added at Utah ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Hardware General Registers r0: .equ 0 r1: .equ 1 r2: .equ 2 r3: .equ 3 r4: .equ 4 r5: .equ 5 r6: .equ 6 r7: .equ 7 r8: .equ 8 r9: .equ 9 r10: .equ 10 r11: .equ 11 r12: .equ 12 r13: .equ 13 r14: .equ 14 r15: .equ 15 r16: .equ 16 r17: .equ 17 r18: .equ 18 r19: .equ 19 r20: .equ 20 r21: .equ 21 r22: .equ 22 r23: .equ 23 r24: .equ 24 r25: .equ 25 r26: .equ 26 r27: .equ 27 r28: .equ 28 r29: .equ 29 r30: .equ 30 r31: .equ 31 ; Hardware Space Registers sr0: .equ 0 sr1: .equ 1 sr2: .equ 2 sr3: .equ 3 sr4: .equ 4 sr5: .equ 5 sr6: .equ 6 sr7: .equ 7 ; Hardware Floating Point Registers fr0: .equ 0 fr1: .equ 1 fr2: .equ 2 fr3: .equ 3 fr4: .equ 4 fr5: .equ 5 fr6: .equ 6 fr7: .equ 7 fr8: .equ 8 fr9: .equ 9 fr10: .equ 10 fr11: .equ 11 fr12: .equ 12 fr13: .equ 13 fr14: .equ 14 fr15: .equ 15 fr16: .equ 16 fr17: .equ 17 fr18: .equ 18 fr19: .equ 19 fr20: .equ 20 fr21: .equ 21 fr22: .equ 22 fr23: .equ 23 fr24: .equ 24 fr25: .equ 25 fr26: .equ 26 fr27: .equ 27 fr28: .equ 28 fr29: .equ 29 fr30: .equ 30 fr31: .equ 31 ; Hardware Control Registers cr0: .equ 0 rctr: .equ 0 ; Recovery Counter Register cr8: .equ 8 ; Protection ID 1 pidr1: .equ 8 cr9: .equ 9 ; Protection ID 2 pidr2: .equ 9 cr10: .equ 10 ccr: .equ 10 ; Coprocessor Confiquration Register cr11: .equ 11 sar: .equ 11 ; Shift Amount Register cr12: .equ 12 pidr3: .equ 12 ; Protection ID 3 cr13: .equ 13 pidr4: .equ 13 ; Protection ID 4 cr14: .equ 14 iva: .equ 14 ; Interrupt Vector Address cr15: .equ 15 eiem: .equ 15 ; External Interrupt Enable Mask cr16: .equ 16 itmr: .equ 16 ; Interval Timer cr17: .equ 17 pcsq: .equ 17 ; Program Counter Space queue cr18: .equ 18 pcoq: .equ 18 ; Program Counter Offset queue cr19: .equ 19 iir: .equ 19 ; Interruption Instruction Register cr20: .equ 20 isr: .equ 20 ; Interruption Space Register cr21: .equ 21 ior: .equ 21 ; Interruption Offset Register cr22: .equ 22 ipsw: .equ 22 ; Interrpution Processor Status Word cr23: .equ 23 eirr: .equ 23 ; External Interrupt Request cr24: .equ 24 ppda: .equ 24 ; Physcial Page Directory Address tr0: .equ 24 ; Temporary register 0 cr25: .equ 25 hta: .equ 25 ; Hash Table Address tr1: .equ 25 ; Temporary register 1 cr26: .equ 26 tr2: .equ 26 ; Temporary register 2 cr27: .equ 27 tr3: .equ 27 ; Temporary register 3 cr28: .equ 28 tr4: .equ 28 ; Temporary register 4 cr29: .equ 29 tr5: .equ 29 ; Temporary register 5 cr30: .equ 30 tr6: .equ 30 ; Temporary register 6 cr31: .equ 31 tr7: .equ 31 ; Temporary register 7 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Procedure Call Convention ~ ; Register Definitions for Use with Assembler ~ ; version A.08.06 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Software Architecture General Registers rp: .equ r2 ; return pointer mrp: .equ r31 ; millicode return pointer ret0: .equ r28 ; return value ret1: .equ r29 ; return value (high part of double) sl: .equ r29 ; static link sp: .equ r30 ; stack pointer dp: .equ r27 ; data pointer arg0: .equ r26 ; argument arg1: .equ r25 ; argument or high part of double argument arg2: .equ r24 ; argument arg3: .equ r23 ; argument or high part of double argument ;_____________________________________________________________________________ ; Software Architecture Space Registers ; sr0 ; return link form BLE sret: .equ sr1 ; return value sarg: .equ sr1 ; argument ; sr4 ; PC SPACE tracker ; sr5 ; process private data ;_____________________________________________________________________________ ; Software Architecture Pseudo Registers previous_sp: .equ 64 ; old stack pointer (locates previous frame) #if 0 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Standard space and subspace definitions. version A.08.06 ; These are generally suitable for programs on HP_UX and HPE. ; Statements commented out are used when building such things as operating ; system kernels. ;;;;;;;;;;;;;;;; .SPACE $TEXT$, SPNUM=0,SORT=8 ; .subspa $FIRST$, QUAD=0,ALIGN=2048,ACCESS=0x2c,SORT=4,FIRST ; .subspa $REAL$, QUAD=0,ALIGN=8,ACCESS=0x2c,SORT=4,FIRST,LOCK .subspa $MILLICODE$, QUAD=0,ALIGN=8,ACCESS=0x2c,SORT=8 .subspa $LIT$, QUAD=0,ALIGN=8,ACCESS=0x2c,SORT=16 .subspa $CODE$, QUAD=0,ALIGN=8,ACCESS=0x2c,SORT=24 ; .subspa $UNWIND$, QUAD=0,ALIGN=4,ACCESS=0x2c,SORT=64 ; .subspa $RECOVER$, QUAD=0,ALIGN=4,ACCESS=0x2c,SORT=80 ; .subspa $RESERVED$, QUAD=0,ALIGN=8,ACCESS=0x73,SORT=82 ; .subspa $GATE$, QUAD=0,ALIGN=8,ACCESS=0x4c,SORT=84,CODE_ONLY ; Additional code subspaces should have ALIGN=8 for an interspace BV ; and should have SORT=24. ; ; For an incomplete executable (program bound to shared libraries), ; sort keys $GLOBAL$ -1 and $GLOBAL$ -2 are reserved for the $DLT$ ; and $PLT$ subspaces respectively. ;;;;;;;;;;;;;;; .SPACE $PRIVATE$, SPNUM=1,PRIVATE,SORT=16 .subspa $GLOBAL$, QUAD=1,ALIGN=8,ACCESS=0x1f,SORT=40 .import $global$ .subspa $SHORTDATA$, QUAD=1,ALIGN=8,ACCESS=0x1f,SORT=24 .subspa $DATA$, QUAD=1,ALIGN=8,ACCESS=0x1f,SORT=16 .subspa $PFA_COUNTER$, QUAD=1,ALIGN=4,ACCESS=0x1f,SORT=8 .subspa $SHORTBSS$, QUAD=1,ALIGN=8,ACCESS=0x1f,SORT=80,ZERO .subspa $BSS$, QUAD=1,ALIGN=8,ACCESS=0x1f,SORT=82,ZERO ; .subspa $PCB$, QUAD=1,ALIGN=8,ACCESS=0x10,SORT=82 ; .subspa $STACK$, QUAD=1,ALIGN=8,ACCESS=0x1f,SORT=82 ; .subspa $HEAP$, QUAD=1,ALIGN=8,ACCESS=0x1f,SORT=82 ;;;;;;;;;;;;;;;; ; .SPACE $PFA$, SPNUM=0,PRIVATE,UNLOADABLE,SORT=64 ; .subspa $PFA_ADDRESS$, ALIGN=4,ACCESS=0x2c,UNLOADABLE ;;;;;;;;;;;;;;;; ; .SPACE $DEBUG$, SPNUM=2,PRIVATE,UNLOADABLE,SORT=80 ; .subspa $HEADER$, ALIGN=4,ACCESS=0,UNLOADABLE,FIRST ; .subspa $GNTT$, ALIGN=4,ACCESS=0,UNLOADABLE ; .subspa $LNTT$, ALIGN=4,ACCESS=0,UNLOADABLE ; .subspa $SLT$, ALIGN=4,ACCESS=0,UNLOADABLE ; .subspa $VT$, ALIGN=4,ACCESS=0,UNLOADABLE ; To satisfy the copyright terms each .o will have a reference ; the the actual copyright. This will force the actual copyright ; message to be brought in from libgloss/hp-milli.s .space $PRIVATE$ .subspa $DATA$ #else .data #endif .import ___hp_free_copyright,data L$copyright .word ___hp_free_copyright picolibc-1.8.11/libc/machine/hppa/setjmp.S000066400000000000000000000101661513574234600202770ustar00rootroot00000000000000/* Copyright (c) 1995, 2002 Red Hat Incorporated. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * The name of Red Hat Incorporated may not be used to endorse * or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Note I don't know an easy way to get the FP version into the traditional C library and the non-FP version into the soft-float library. Maybe we'll have to have -msoft-float trigger something like -DSOFT_FLOAT if this issue ever arises. */ #include #include "DEFS.h" #if 0 .SPACE $PRIVATE$ .SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31 .SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82 .SPACE $TEXT$ .SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44 .SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY .IMPORT $global$,DATA .IMPORT $$dyncall,MILLICODE ; gcc_compiled.: #endif TEXT_SEGMENT .align 4 .EXPORT setjmp,ENTRY,PRIV_LEV=3,ARGW0=GR,RTNVAL=GR setjmp .PROC .CALLINFO FRAME=64,NO_CALLS,SAVE_SP,ENTRY_GR=3 .ENTRY stwm %r30,4(%r26) stwm %r2,4(%r26) stwm %r3,4(%r26) stwm %r4,4(%r26) stwm %r5,4(%r26) stwm %r6,4(%r26) stwm %r7,4(%r26) stwm %r8,4(%r26) stwm %r9,4(%r26) stwm %r10,4(%r26) stwm %r11,4(%r26) stwm %r12,4(%r26) stwm %r13,4(%r26) stwm %r14,4(%r26) stwm %r15,4(%r26) stwm %r16,4(%r26) stwm %r17,4(%r26) stwm %r18,4(%r26) stwm %r27,4(%r26) #ifdef FP ; jmp_buf may only have a 4 byte alignment, so handle FP stores ; very carefully. fstds %fr12,-16(%r30) ldw -16(%r30),%r28 stwm %r28,4(%r26) ldw -12(%r30),%r28 stwm %r28,4(%r26) fstds %fr13,-16(%r30) ldw -16(%r30),%r28 stwm %r28,4(%r26) ldw -12(%r30),%r28 stwm %r28,4(%r26) fstds %fr14,-16(%r30) ldw -16(%r30),%r28 stwm %r28,4(%r26) ldw -12(%r30),%r28 stwm %r28,4(%r26) fstds %fr15,-16(%r30) ldw -16(%r30),%r28 stwm %r28,4(%r26) ldw -12(%r30),%r28 stwm %r28,4(%r26) #endif bv 0(%r2) copy %r0,%r28 .EXIT .PROCEND .align 4 .EXPORT longjmp,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,RTNVAL=GR longjmp .PROC .CALLINFO FRAME=64,NO_CALLS,SAVE_SP,ENTRY_GR=3 .ENTRY ldwm 4(%r26),%r30 ldwm 4(%r26),%r2 ldwm 4(%r26),%r3 ldwm 4(%r26),%r4 ldwm 4(%r26),%r5 ldwm 4(%r26),%r6 ldwm 4(%r26),%r7 ldwm 4(%r26),%r8 ldwm 4(%r26),%r9 ldwm 4(%r26),%r10 ldwm 4(%r26),%r11 ldwm 4(%r26),%r12 ldwm 4(%r26),%r13 ldwm 4(%r26),%r14 ldwm 4(%r26),%r15 ldwm 4(%r26),%r16 ldwm 4(%r26),%r17 ldwm 4(%r26),%r18 ldwm 4(%r26),%r27 #ifdef FP ldwm 4(%r26),%r28 stw %r28,-16(%r30) ldwm 4(%r26),%r28 stw %r28,-12(%r30) fldds -16(%r30),%fr12 ldwm 4(%r26),%r28 stw %r28,-16(%r30) ldwm 4(%r26),%r28 stw %r28,-12(%r30) fldds -16(%r30),%fr13 ldwm 4(%r26),%r28 stw %r28,-16(%r30) ldwm 4(%r26),%r28 stw %r28,-12(%r30) fldds -16(%r30),%fr14 ldwm 4(%r26),%r28 stw %r28,-16(%r30) ldwm 4(%r26),%r28 stw %r28,-12(%r30) fldds -16(%r30),%fr15 #endif comclr,<> %r0,%r25,%r0 ldi 1,%r25 bv 0(%r2) copy %r25,%r28 .EXIT .PROCEND picolibc-1.8.11/libc/machine/hppa/strcat.S000066400000000000000000000122401513574234600202700ustar00rootroot00000000000000/* * (c) Copyright 1986 HEWLETT-PACKARD COMPANY * * To anyone who acknowledges that this file is provided "AS IS" * without any express or implied warranty: * permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies, and that the name of Hewlett-Packard Company not be * used in advertising or publicity pertaining to distribution * of the software without specific, written prior permission. * Hewlett-Packard Company makes no representations about the * suitability of this software for any purpose. */ /* HPUX_ID: @(#) $Revision$ */ /* * strcat(s1, s2) * * Concatenate s2 on the end of s1. S1's space must be large enough. * Return s1. */ #include #include "DEFS.h" #define d_addr r26 #define s_addr r25 #define tmp6 r24 #define tmp1 r19 #define tmp2 r20 #define tmp3 r21 #define tmp4 r22 #define tmp5 arg3 #define save r1 ENTRY(strcat) comb,= r0,s_addr,done /* quit if s2=NULL */ copy d_addr,ret0 /* The return value is the value of d_addr. DELAY SLOT*/ /* First look for end of s1 (d_addr) */ extru d_addr,31,2,tmp1 /* Extract the low two bits of the dest address. */ combt,= tmp1,r0,dont_mask dep 0,31,2,d_addr /*set word alignment */ ldwm 4(d_addr),tmp2 sh3add tmp1,r0,save /* build mask based on tmp1 */ mtctl save,11 zvdepi -2,32,save or save,tmp2,tmp2 uxor,nbz tmp2,r0,save search: b,n found_end /* nullified under uxor conditions above and below */ dont_mask: ldwm 4(d_addr),tmp2 comib,tr r0,r0,search uxor,nbz tmp2,r0,save found_end: /* at this point d_addr points to word */ extru,<> save,7,8,r0 /* following word with null */ addib,tr,n -4,d_addr,begin_copy /*set d_addr to end of s1 */ extru,<> save,15,8,r0 addib,tr,n -3,d_addr,begin_copy extru,<> save,23,8,r0 addi -1,d_addr,d_addr addi -1,d_addr,d_addr begin_copy: extru s_addr,31,2,tmp1 /* Extract the low two bits of the source address. */ extru d_addr,31,2,tmp6 /* Extract the low two bits of the destination address. */ sub,= tmp6,tmp1,tmp3 /* Compute the shift quantity and don't branch if tmp6=tmp1. */ b not_aligned /* Not_aligned says that shifts Will be needed. */ dep 0,31,2,s_addr /* Compute the word address of the source. DELAY SLOT. */ /* aligned */ combt,= tmp6,r0,skip_mask ldwm 4(0,s_addr),tmp1 /* tmp1 = *s_addr s_addr += 4 (DELAY SLOT) */ sh3add tmp6,r0,save mtctl save,r11 zvdepi -2,32,save or save,tmp1,tmp1 uxor,nbz tmp1,r0,save b,n first_null /* special case: null in first word */ b,n skip_mask2 chunks: b,n null_found /* delay slot for uxor below */ skip_mask2: stbys,b,m tmp1,4(d_addr) ldwm 4(s_addr),tmp1 skip_mask: comib,tr 0,0,chunks uxor,nbz tmp1,r0,save /* Begin non_aligned code. */ not_aligned: sh3add,>= tmp3,r0,tmp4 /* compute the shift amt.and skip load if tmp6 > tmp1. */ ldwm 4(0,s_addr),tmp1 /* load up the first word from the source. tmp1 = *s_addr++ */ ldwm 4(0,s_addr),tmp2 /* get either first or second word from source. */ combt,= tmp6,r0,chunk2 /* don't mask if whole word is valid */ mtctl tmp4,11 /* load the shift count into cr11 = shift count register. */ vshd tmp1,tmp2,tmp3 /* position data ! (delay slot) */ sh3add tmp6,r0,save /* setup r1 */ mtctl save,r11 /* set-up cr11 for mask */ zvdepi -2,32,save or save, tmp3, tmp3 uxor,nbz tmp3,r0,save b,n first_null2 b did_mask mtctl tmp4,11 /* re-load the shift count into cr11 */ chunk2: vshd tmp1,tmp2,tmp3 uxor,nbz tmp3, r0, save b,n null_found did_mask: stbys,b,m tmp3,4(0,d_addr) /* store ! */ ldwm 4(0,s_addr),tmp1 /* get next word ! */ vshd tmp2,tmp1,tmp3 /* position data ! */ uxor,nbz tmp3, r0, save b,n null_found stwm tmp3,4(d_addr) comib,tr 0,0,chunk2 ldwm 4(s_addr),tmp2 null_found: /* adjust d_addr and store final word */ extru,<> save,7,8,r0 addib,tr,n 1,d_addr,store_final extru,<> save,15,8,r0 addib,tr,n 2,d_addr,store_final extru,<> save,23,8,r0 addib,tr 3,d_addr,store_final2 bv 0(r2) stw save,0(d_addr) store_final: bv 0(r2) store_final2: stbys,e save,0(d_addr) /* delay slot */ first_null: /* null found in first word of aligned (wrt d_addr) */ addi -4,s_addr,s_addr ldbx tmp6(s_addr),tmp4 add tmp6,s_addr,s_addr comib,= 0,tmp4,done stbs,ma tmp4,1(d_addr) ldbs 1(s_addr),tmp4 comib,= 0,tmp4,done stbs,ma tmp4,1(d_addr) bv 0(r2) /* done */ stbs 0,0(d_addr) first_null2: /* null found in first word of non-aligned (wrt d_addr) */ addibt,= -1,tmp6,check3 /* check last 3 bytes of word */ extru save,15,8,tmp4 addibt,=,n -1,tmp6,check2 /* check last 2 bytes */ bv 0(r2) stbys,b save, 0(d_addr) check3: combt,= tmp4,r0,done stbs,ma tmp4,1(d_addr) check2: extru,<> save,23,8,tmp4 bv 0(r2) stbs,ma tmp4,1(d_addr) bv 0(r2) stbs r0,0(d_addr) done: EXIT(strcat) picolibc-1.8.11/libc/machine/hppa/strcmp.S000066400000000000000000000215611513574234600203060ustar00rootroot00000000000000/* * (c) Copyright 1986 HEWLETT-PACKARD COMPANY * * To anyone who acknowledges that this file is provided "AS IS" * without any express or implied warranty: * permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies, and that the name of Hewlett-Packard Company not be * used in advertising or publicity pertaining to distribution * of the software without specific, written prior permission. * Hewlett-Packard Company makes no representations about the * suitability of this software for any purpose. */ /* strcmp Jerry Huck Edgar Circenis */ /* * strcmp(s1, s2) * * returns integer: < 0 iff s1 lexicographically less than s2 * > 0 iff s1 lexicographically greater than s2 * = 0 iff s1 lexicographically equal to s2 */ #include #include "DEFS.h" #define s1 26 #define s2 25 #define tmp1 19 #define s2word 20 #define tmp3 21 #define tmp7 22 #define s1word 23 #define save 1 #define tmp6 24 #define tmp5 28 ENTRY(strcmp) comb,=,n s1,s2,samestring comib,=,n 0,s1,s1isnull comib,=,n 0,s2,s2isnull /* Hope for word alignment. Pick up low two bits of each adress */ extru,<> s1,31,2,tmp1 ldwm 4(s1),s1word dep,= s2,29,2,tmp1 b,n case_analysis /* Start looping until null is found in s1 or they mis-compare */ loop: ldwm 4(s2),s2word loop_plus: uxor,nbz s1word,r0,r0 /* Null in this? */ b,n nullins1 comb,=,n s1word,s2word,loop ldwm 4(s1),s1word /* The words do not compare equal and s1 does not have a null. Need to treat words as unsigned and generate either a positive or negative return value */ wordcomparereturn: comclr,>> s1word,s2word,ret0 /*Set ret0 to 0 and skip if greater*/ ldi -2,ret0 /*Set ret0 to -2 when less */ bv r0(rp) addi 1,ret0,ret0 /*Fix return value to be -1 or +1 */ /* s1 has a null. s2 has not been checked. */ nullins1: /*If s2 has no nulls this is simple, but assume that it might and fix up s1 to allow the word comparision to work by scanning s1 and duplicating all the bytes in s2 below that byte into the remainder of s1. A remainder only exists if the zero byte is found in the upper three bytes */ extru,<> s1word,7,8,r0 /*in the first byte? */ dep,tr s2word,31,24,s1word /*copy low 3 bytes of *s2 into *s1 */ extru,<> s1word,15,8,r0 /*in the second byte? */ dep,tr s2word,31,16,s1word /*copy low 2 bytes of *s2 into *s1 */ extru,<> s1word,23,8,r0 /*in the third byte? */ dep s2word,31,8,s1word /*copy low 1 byte of *s2 into *s1 */ /* Do the normal unsigned compare and return */ comclr,<> s1word,s2word,ret0 /*Set ret0 to 0 and skip if not equal */ bv,n r0(rp) comclr,>> s1word,s2word,ret0 /*Set ret0 to 0 and skip if greater*/ ldi -2,ret0 /*Set ret0 to -2 when less */ bv r0(rp) addi 1,ret0,ret0 /*Fix return value to be -1 or +1 */ /* s1 and s2 are the same string and therefore equal */ samestring: bv r0(rp) copy r0,ret0 /* s1 is null. Treat as string of nulls. Therefore return the negative of s2's first byte. s2 cannot be zero. */ s1isnull: ldbs 0(0,s2),ret0 bv r0(rp) sub 0,ret0,ret0 /* s2 is null. Treat as string of nulls. Therefore return s1's first byte. s1 cannot be zero. */ s2isnull: bv r0(rp) ldbs 0(0,s1),ret0 case_analysis: blr tmp1,r0 nop /* Case statement for non-aligned cases (we've already checked the aligned case. NOTE: for non-aligned cases, the absolute shift value gets loaded into tmp3. */ /* S2 S1 */ nop /* 00 00 can't happen */ nop b shifts2 /* 00 01 */ ldi 8,tmp3 /* load shift count (delay slot) */ b shifts2 /* 00 10 */ ldi 16,tmp3 /* load shift count (delay slot) */ b shifts2 /* 00 11 */ ldi 24,tmp3 /* load shift count (delay slot) */ b shifts1_0 /* 01 00 */ ldi 8,tmp3 /* load shift count (delay slot) */ b eq_align1 /* 01 01 */ ldbs,ma 1(s1),s1word b shifts2 /* 01 10 */ ldi 8,tmp3 /* load shift count (delay slot) */ b shifts2 /* 01 11 */ ldi 16,tmp3 /* load shift count (delay slot) */ b shifts1_0 /* 10 00 */ ldi 16,tmp3 /* load shift count (delay slot) */ b shifts1 /* 10 01 */ ldi 8,tmp3 /* load shift count (delay slot) */ b eq_align2 /* 10 10 */ ldhs,ma 2(s1),s1word b shifts2 /* 10 11 */ ldi 8,tmp3 /* load shift count (delay slot) */ b shifts1_0 /* 11 00 */ ldi 24,tmp3 /* load shift count (delay slot) */ b shifts1 /* 11 01 */ ldi 16,tmp3 /* load shift count (delay slot) */ b shifts1 /* 11 10 */ ldi 8,tmp3 /* load shift count (delay slot) */ ldbs,ma 1(s1),s1word /* 11 11 */ ldbs,ma 1(s2),s2word sub,= s1word,s2word,ret0 /* if not equal, we can return now */ bv,n r0(rp) comclr,<> s1word,r0,ret0 bv,n r0(rp) b loop /* fall into main loop */ ldwm 4(s1),s1word eq_align1: ldbs,ma 1(s2),s2word sub,= s1word,s2word,ret0 /* if not equal, we can return now */ bv,n r0(rp) comclr,<> s1word,r0,ret0 bv,n r0(rp) /* fall through to half-word aligned case */ ldhs,ma 2(s1),s1word /* load next halfword */ eq_align2: ldhs,ma 2(s2),s2word /* load next halfword */ /* form the mask: 0xffff0000 and mask leading nulls in s1word and s2word so that we can fall into the main loop with word aligned data */ ldi 16,save mtctl save,r11 zvdepi -2,32,save or save,s1word,s1word b loop_plus /* fall into main loop */ or save,s2word,s2word /* s2's alignment is greater than s1's alignment, so we will shift s1 */ shifts1_0: addi -4,s1,s1 /* fix up s1 due to earlier read */ shifts1: extru s1,31,2,tmp1 extru s2,31,2,tmp5 dep r0,31,2,s1 /* Compute word address of s1 */ dep r0,31,2,s2 /* Compute word address of s2 */ ldwm 4(s1),s1word /* get first word of s1 */ ldwm 4(s2),s2word /* get first word of s2 */ combt,=,n r0,tmp1,masks2 /* Do we need to mask beginning of s1 */ sh3add tmp1,r0,save /* save now has number of bits to mask */ mtctl save,r11 zvdepi -2,32,save /* load save with proper mask */ or save,s1word,s1word masks2: sh3add tmp5,r0,save /* save now has number of bits to mask */ mtctl save,r11 zvdepi -2,32,save /* load save with proper mask */ or save,s2word,s2word ldi -1,tmp7 /* load tmp7 with 0xffffffff */ mtctl tmp3,r11 /* Move shift amount to CR11 */ more: uxor,nbz s1word,r0,r0 /* Is there a null in s1? */ b ends1 vshd tmp7,s1word,save combf,=,n save,s2word,cmps1 ldwm 4(s1),tmp7 ldwm 4(s2),s2word uxor,nbz tmp7,r0,r0 /* is there a null in s1? */ b ends1_0 vshd s1word,tmp7,save combf,=,n save,s2word,cmps1 ldwm 4(s1),s1word b more ldwm 4(s2),s2word cmps1: movb,tr save,s1word,wordcomparereturn nop ends1_0: copy tmp7,s1word /* move tmp7 to s1word */ ends1: combf,=,n save,s2word,nullins1 /* branch if no match */ copy save,s1word /* delay slot */ /* At this point, we know that we've read a null */ /* from s1, so we can't read more from s1 */ uxor,nbz save,r0,r0 /* are the strings equal? */ b,n samestring vshd s1word,r0,s1word b nullins1 ldwm 4(s2),s2word /* s1's alignment is greater than s2's alignment, so we will shift s2 */ shifts2: extru s1,31,2,tmp1 extru s2,31,2,tmp5 dep r0,31,2,s1 /* Compute word address of s1 */ dep r0,31,2,s2 /* Compute word address of s2 */ ldwm 4(s2),s2word /* get first word of s2 */ ldwm 4(s1),s1word /* get first word of s1 */ combt,=,n r0,tmp5,masks1 /* Do we need to mask beginning of s2 */ sh3add tmp5,r0,save /* save now has number of bits to mask */ mtctl save,r11 zvdepi -2,32,save /* load save with proper mask */ or save,s2word,s2word masks1: sh3add tmp1,r0,save /* save now has number of bits to mask */ mtctl save,r11 zvdepi -2,32,save /* load save with proper mask */ or save,s1word,s1word ldi -1,tmp7 /* load tmp7 with 0xffffffff */ mtctl tmp3,r11 /* Move shift amount to CR11 */ more1: uxor,nbz s2word,r0,r0 /* is there a null in s2? */ b ends2 vshd tmp7,s2word,save combf,=,n s1word,save,cmps2 ldwm 4(s2),tmp7 ldwm 4(s1),s1word uxor,nbz tmp7,r0,r0 /* is there a null in s2? */ b ends2_0 vshd s2word,tmp7,save combf,=,n s1word,save,cmps2 ldwm 4(s2),s2word b more1 ldwm 4(s1),s1word cmps2: movb,tr save,s2word,wordcomparereturn nop ends2_0: copy tmp7,s2word /* move tmp7 to s2word */ ends2: combf,=,n s1word,save,nullins1 /* branch if no match */ copy save,s2word /* delay slot */ /* At this point, we know that we've read a null */ /* from s2, so we can't read more from s2 */ uxor,nbz save,r0,r0 /* are the strings equal? */ b,n samestring vshd s2word,r0,s2word b nullins1 ldwm 4(s1),s1word EXIT(strcmp) picolibc-1.8.11/libc/machine/hppa/strcpy.S000066400000000000000000000237601513574234600203250ustar00rootroot00000000000000/* * (c) Copyright 1986 HEWLETT-PACKARD COMPANY * * To anyone who acknowledges that this file is provided "AS IS" * without any express or implied warranty: * permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies, and that the name of Hewlett-Packard Company not be * used in advertising or publicity pertaining to distribution * of the software without specific, written prior permission. * Hewlett-Packard Company makes no representations about the * suitability of this software for any purpose. */ /* A faster strcpy. by Jerry Huck (aligned case) Daryl Odnert (equal-alignment case) Edgar Circenis (non-aligned case) */ /* * strcpy(s1, s2) * * Copy string s2 to s1. s1 must be large enough. * return s1 */ #include #include "DEFS.h" #define d_addr r26 #define s_addr r25 #define tmp6 r24 #define tmp1 r19 #define evenside r19 #define tmp2 r20 #define oddside r20 #define tmp3 r21 #define tmp4 r22 #define tmp5 arg3 #define save r1 ENTRY(strcpy) /* Do some quick alignment checking on and fast path both word aligned */ extru,<> s_addr,31,2,tmp6 /*Is source word aligned? */ ldwm 4(0,s_addr),oddside /*Assume yes and guess that it is double-word aligned. */ dep,= d_addr,29,2,tmp6 /*Is target word aligned? */ b case_analysis copy d_addr,ret0 /* Both are aligned. First source word already loaded assuming that source was oddword aligned. Fall through (therefore fastest) code shuffles the registers to join the main loop */ bothaligned: bb,>= s_addr,29,twoatatime /*Branch if source was odd aligned*/ uxor,nbz oddside,r0,save /* Even aligned source. save holds that operand. Do one iteration of the main copy loop juggling the registers to avoid one copy. */ b,n nullfound ldwm 4(s_addr),oddside stwm save,4(d_addr) uxor,nbz oddside,r0,save b,n nullfound ldwm 4(s_addr),evenside stwm oddside,4(d_addr) uxor,nbz evenside,r0,save b,n nullfound ldwm 4(s_addr),oddside /* Main loop body. Entry expects evenside still to be stored, oddside just loaded. */ loop: stwm evenside,4(d_addr) uxor,nbz oddside,r0,save /* mid loop entry */ twoatatime: b,n nullfound ldwm 4(s_addr),evenside stwm oddside,4(d_addr) uxor,sbz evenside,r0,save b loop ldwm 4(s_addr),oddside /* fall through when null found in evenside. oddside actually loaded */ nullfound: /* adjust d_addr and store final word */ extru,<> save,7,8,r0 /* pick up leftmost byte */ addib,tr,n 1,d_addr,store_final extru,<> save,15,8,r0 addib,tr,n 2,d_addr,store_final extru,<> save,23,8,r0 addib,tr 3,d_addr,store_final2 bv 0(rp) stw save,0(d_addr) store_final: bv 0(rp) store_final2: stbys,e save,0(d_addr) /* delay slot */ case_analysis: blr tmp6,r0 nop /* NOTE: the delay slots for the non-aligned cases load a */ /* shift quantity which is TGT-SRC into tmp3. */ /* Note also, the case for both strings being word aligned */ /* is already checked before the BLR is executed, so that */ /* case can never occur. */ /* TGT SRC */ nop /* 00 00 can't happen */ nop b neg_aligned_copy /* 00 01 */ ldi -1,tmp3 /* load shift quantity. delay slot */ b neg_aligned_copy /* 00 10 */ ldi -2,tmp3 /* load shift quantity. delay slot */ b neg_aligned_copy /* 00 11 */ ldi -3,tmp3 /* load shift quantity. delay slot */ b pos_aligned_copy0 /* 01 00 */ ldi 1,tmp3 /* load shift quantity. delay slot */ b equal_alignment_1 /* 01 01 */ ldbs,ma 1(s_addr),tmp1 b neg_aligned_copy /* 01 10 */ ldi -1,tmp3 /* load shift quantity. delay slot */ b neg_aligned_copy /* 01 11 */ ldi -2,tmp3 /* load shift quantity. delay slot */ b pos_aligned_copy0 /* 10 00 */ ldi 2,tmp3 /* load shift quantity. delay slot */ b pos_aligned_copy /* 10 01 */ ldi 1,tmp3 /* load shift quantity. delay slot */ b equal_alignment_2 /* 10 10 */ ldhs,ma 2(s_addr),tmp1 b neg_aligned_copy /* 10 11 */ ldi -1,tmp3 /* load shift quantity. delay slot */ b pos_aligned_copy0 /* 11 00 */ ldi 3,tmp3 /* load shift quantity. delay slot */ b pos_aligned_copy /* 11 01 */ ldi 2,tmp3 /* load shift quantity. delay slot */ b pos_aligned_copy /* 11 10 */ ldi 1,tmp3 /* load shift quantity. delay slot */ ldbs,ma 1(s_addr),tmp1 /* 11 11 */ comiclr,<> r0,tmp1,r0 bv 0(rp) /* return if 1st byte was null */ stbs,ma tmp1,1(d_addr) /* store a byte to dst string */ b bothaligned /* can now goto word_aligned */ ldwm 4(s_addr),oddside /* load next word of source */ equal_alignment_1: comiclr,<> r0,tmp1,r0 /* nullify next if tmp1 <> 0 */ bv 0(rp) /* return if null byte found */ stbs,ma tmp1,1(d_addr) /* store a byte to dst string */ ldhs,ma 2(s_addr),tmp1 /* load next halfword */ equal_alignment_2: extru,<> tmp1,23,8,tmp6 /* look at left byte of halfword */ bv 0(rp) /* return if 1st byte was null */ stbs,ma tmp6,1(d_addr) extru,<> tmp1,31,8,r0 bv 0(rp) /* return if 2nd byte was null */ stbs,ma tmp1,1(d_addr) b bothaligned ldwm 4(s_addr),oddside /* load next word */ /* source and destination are not aligned, so we do it the hard way. */ /* target alignment is greater than source alignment */ pos_aligned_copy0: addi -4,s_addr,s_addr pos_aligned_copy: extru d_addr,31,2,tmp6 /* Extract low 2 bits of the dest addr */ extru s_addr,31,2,tmp1 /* Extract low 2 bits of the src addr */ dep r0,31,2,s_addr /* Compute word address of the source. */ sh3add tmp3,r0,tmp4 /* compute shift amt */ ldwm 4(0,s_addr),tmp2 /* get 1st source word */ sh3add tmp1,r0,save /* setup mask shift amount */ mtctl save,r11 /* set-up cr11 for mask */ zvdepi -2,32,save /* create mask */ or save,tmp2,tmp2 /* mask unused bytes in src */ ldi -1,tmp1 /* load tmp1 with 0xffffffff */ mtctl tmp4,r11 /* shift count -> shift count reg */ vshd tmp1,tmp2,tmp3 /* position data ! */ uxor,nbz tmp3,r0,save b,n first_null uxor,nbz tmp2,r0,save b nullfound1 mtctl tmp4,r11 /* re-load shift cnt (delay slot) */ b loop_entry ldwm 4(0,s_addr),tmp1 /* get next word. delay slot */ neg_aligned_copy: extru d_addr,31,2,tmp6 /* Extract low 2 bits of the dest addr */ extru s_addr,31,2,tmp2 /* Extract low 2 bits of the src addr */ dep r0,31,2,s_addr /* Compute word address of the source. */ sh3add tmp3,r0,tmp4 /* compute shift amt */ ldwm 4(0,s_addr),tmp1 /* load first word from source. */ /* check to see if next word can be read safely */ sh3add tmp2,r0,save mtctl save,r11 /* shift count -> shift count reg */ zvdepi -2,32,save or save, tmp1, tmp1 uxor,nbz tmp1,r0,save /* any nulls in first word? */ b first_null0 mtctl tmp4,r11 ldwm 4(0,s_addr),tmp2 /* load second word from source */ combt,= tmp6,r0,chunk1 /* don't mask if whole word valid */ vshd tmp1,tmp2,tmp3 /* position data ! */ sh3add tmp6,r0,save /* setup r1 */ mtctl save,r11 /* set-up cr11 for mask */ zvdepi -2,32,save or save, tmp3, tmp3 uxor,nbz tmp3,r0,save b,n first_null uxor,nbz tmp2,r0,save b nullfound1 mtctl tmp4,r11 /* re-load shift cnt (delay slot) */ b loop_entry ldwm 4(0,s_addr),tmp1 /* get next word. delay slot */ chunk1: uxor,nbz tmp2,r0,save b nullfound0 vshd tmp1,tmp2,tmp3 did_mask: ldwm 4(0,s_addr),tmp1 /* get next word ! */ loop_entry: stbys,b,m tmp3,4(0,d_addr) /* store ! */ uxor,nbz tmp1, r0, save b nullfound2 vshd tmp2,tmp1,tmp3 /* position data ! */ ldwm 4(s_addr),tmp2 stwm tmp3,4(d_addr) uxor,sbz tmp2,r0,save b did_mask nullfound0: vshd tmp1,tmp2,tmp3 /* delay slot */ uxor,nbz tmp3,r0,save b,n nullfound nullfound1: stbys,b,m tmp3,4(0,d_addr) b nullfound vshd tmp2,r0,save /* delay slot */ nullfound2: uxor,nbz tmp3,r0,save b,n nullfound stwm tmp3,4(d_addr) b nullfound /* notice that delay slot is in next routine */ first_null0: /* null found in first word of non-aligned (wrt d_addr) */ vshd tmp1,r0,save /* delay slot */ combt,= tmp6,r0,check4 extru save,7,8,tmp4 first_null: addibt,= -1,tmp6,check3 /* check last 3 bytes of word */ extru save,15,8,tmp4 addibt,=,n -1,tmp6,check2 /* check last 2 bytes */ bv 0(rp) /* null in last byte--store and exit */ stbys,b save, 0(d_addr) check4: combt,= tmp4,r0,done stbs,ma tmp4,1(d_addr) extru,<> save,15,8,tmp4 check3: combt,= tmp4,r0,done stbs,ma tmp4,1(d_addr) check2: extru,<> save,23,8,tmp4 bv 0(rp) stbs,ma tmp4,1(d_addr) bv 0(rp) stbs r0,0(d_addr) done: EXIT(strcpy) picolibc-1.8.11/libc/machine/hppa/strlen.S000066400000000000000000000065011513574234600203020ustar00rootroot00000000000000/* * (c) Copyright 1986 HEWLETT-PACKARD COMPANY * * To anyone who acknowledges that this file is provided "AS IS" * without any express or implied warranty: * permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies, and that the name of Hewlett-Packard Company not be * used in advertising or publicity pertaining to distribution * of the software without specific, written prior permission. * Hewlett-Packard Company makes no representations about the * suitability of this software for any purpose. */ /* HPUX_ID = "@(#) $Revision$" */ /* strlen(s): Return length of string s */ #include #define start arg0 #define end ret0 #define tmp1 arg1 #define tmp2 arg2 #include "DEFS.h" ENTRY(strlen) movb,=,n start,end,$null_ptr depi 0,31,2,end comb,<> start,end,$not_aligned ldws,ma 4(end),tmp1 comib,tr 0,0,$loop /* avoid INDIGO two register interlock */ uxor,nbz 0,tmp1,0 $not_aligned: /* ; Tricky code. The problem is that the value of of the word ; including the start of the string has some garbage bytes that ; may be 0. We don't want them to stop the string scan. So ; we make those bytes non-zero (and any old non-zero value ; will do). Notice that the end pointer has been rounded ; down to a word boundary, and then incremented to the next ; word by the time we get here. Therefore, (start-end) has ; one of the values (-3, -2, or -1). Use uaddcm to do the ; subtraction (instead of sub), and the result will be ; (-4, -3, or -2). Multiply this by 8, and put into the ; shift register (which truncates to the last 5 bits) and ; the value will be (0, 8, or 16). Use this as a bit position, ; and drop a mask down into tmp1. All the garbage bytes will ; have at least 1 bit affected by the vdepi, so all the garbage ; in this first word will be non-zero garbage. */ uaddcm start,end,tmp2 /* tmp2 <- { -4, -3, -2 } */ sh3add tmp2,0,tmp2 /* tmp2 <- { -32, -24, -16 } */ mtsar tmp2 /* sar <- { 0, 8, 16 } */ vdepi -1,32,tmp1 uxor,nbz 0,tmp1,0 $loop: b,n $end_loop ldws,ma 4(end),tmp1 comib,tr 0,0,$loop /* avoid INDIGO two register interlock */ uxor,nbz 0,tmp1,0 $end_loop: /* adjust the end pointer to one past the end of the string */ extru,<> tmp1,7,8,0 addib,tr,n -3,end,$out extru,<> tmp1,15,8,0 addib,tr,n -2,end,$out extru,<> tmp1,23,8,0 addi -1,end,end $out: bv 0(rp) /* ; tricky code. the end pointer is just beyond the terminating ; null byte, so the length is (end-start-1). use uaddcm ; to do this in 1 instruction */ uaddcm end,start,ret0 $null_ptr: EXIT(strlen) picolibc-1.8.11/libc/machine/hppa/strncat.S000066400000000000000000000203771513574234600204600ustar00rootroot00000000000000/* * (c) Copyright 1986 HEWLETT-PACKARD COMPANY * * To anyone who acknowledges that this file is provided "AS IS" * without any express or implied warranty: * permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies, and that the name of Hewlett-Packard Company not be * used in advertising or publicity pertaining to distribution * of the software without specific, written prior permission. * Hewlett-Packard Company makes no representations about the * suitability of this software for any purpose. */ /*HPUX_ID: @(#) $Revision$ */ /* strncat(s1,s2,n) : concatonate at most n characters from s2 onto s1 */ #include #include "DEFS.h" #define d_addr r26 #define s_addr r25 #define count r24 #define tmp1 r19 #define tmp2 r20 #define tmp3 r21 #define tmp4 r22 #define tmp5 arg3 #define tmp6 r31 #define save r1 #define tmp7 ret1 /* source offset-- reset to orig source addr if not aligned */ ENTRY(strncat) comb,= r0,s_addr,quit /* quit if s2=NULL */ copy d_addr,ret0 /* The return value is the value of d_addr. DELAY SLOT*/ /* First look for end of s1 (d_addr) */ extru d_addr,31,2,tmp1 /* Extract the low two bits of the dest address. */ combt,= tmp1,r0,dont_mask dep 0,31,2,d_addr /*set word alignment */ ldwm 4(d_addr),tmp2 sh3add tmp1,r0,save /* build mask based on tmp1 */ mtctl save,11 zvdepi -2,32,save or save,tmp2,tmp2 uxor,nbz tmp2,r0,save search: b,n found_end /* nullified under uxor conditions above and below */ dont_mask: ldwm 4(d_addr),tmp2 comib,tr r0,r0,search uxor,nbz tmp2,r0,save found_end: /* at this point d_addr points to word */ extru,<> save,7,8,r0 /* following word with null */ addib,tr,n -4,d_addr,begin_copy /*set d_addr to end of s1 */ extru,<> save,15,8,r0 addib,tr,n -3,d_addr,begin_copy extru,<> save,23,8,r0 addi -1,d_addr,d_addr addi -1,d_addr,d_addr begin_copy: addibt,<,n -4,count,byteloop /* If count is <= 4 don't get fancy.*/ extru s_addr,31,2,tmp4 /* Extract the low two bits of the source address.*/ extru d_addr,31,2,tmp5 /* Extract the low two bits of the destination address.*/ add count,tmp5,count /* pre increment the count by the byte address so that the count is*/ copy s_addr,tmp6 /* save original s_addr in case we find null in first word */ copy s_addr, tmp7 /* save s_addr in case we find null before first store */ comb,<> tmp5,tmp4,not_aligned /* branch if tmp5<>tmp4. */ dep 0,31,2,s_addr /* Compute the word address of the source. DELAY SLOT.*/ /* aligned*/ combt,= tmp5,r0,skip_mask ldwm 4(0,s_addr),tmp1 /* tmp1 = *s_addr s_addr += 4 (DELAY SLOT)*/ sh3add tmp5,r0,save /* compute mask in save*/ mtctl save,11 zvdepi -2,32,save or save,tmp1,tmp1 /* or mask with data*/ uxor,nbz tmp1,r0,save /* check for null*/ b,n null1 addibt,< -4,count,back_porch stbys,b,m tmp1,4(0,d_addr) /* store word (delay slot)*/ chunks: ldwm 4(0,s_addr),tmp1 /* get a word*/ skip_mask: uxor,nbz tmp1,r0,save /* check for null*/ b,n align_null1 addibf,< -4,count,chunks stbys,b,m tmp1,4(0,d_addr) /* store word (delay slot)*/ back_porch: /* last word to store*/ addibt,=,n 4,count,done /* if count = 0 we're, of course, done !*/ ldws 0(s_addr),tmp1 /* load up the back_porch*/ sh3add count,r0, save /* setup right mask based on count*/ mtctl save,r11 zvdepi -2,32,save /*save now has left-hand mask*/ uaddcm r0,save,save /*form right hand mask */ or tmp1,save,tmp1 /*and insert data*/ uxor,nbz tmp1,r0,save /* check for null*/ b,n null2 add d_addr,count,d_addr/* final store address is +1 too high !*/ b done stbys,e tmp1,0(d_addr) /* done */ /* Begin non_aligned code. */ not_aligned: sub,>= tmp5,tmp4,tmp6 /* compute the shift amt.and skip load if tmp5 > tmp4.*/ ldwm 4(0,s_addr),tmp1 /* load up the first word from the source. tmp1 = *s_addr++*/ zdep tmp6,28,29,tmp4 /* compute the number of bits to shift */ mtctl tmp4,11 /* load the shift count into cr11 = shift count register.*/ addibt,<,n -4,count,chkchnk2 /* first step in pre adjustment of count for looping.*/ ldwm 4(0,s_addr),tmp2 /* get either first or second word from source. */ combt,= tmp5,r0,skip_mask4 /* don't mask if whole word is valid*/ vshd tmp1,tmp2,tmp3 /* position data ! (delay slot)*/ sh3add tmp5,r0,save /* setup r1*/ mtctl save,r11 /* setup mask in save*/ zvdepi -2,32,save or save, tmp3, tmp3 mtctl tmp4,11 /* re-load the shift count into cr11 */ skip_mask4: uxor,nbz tmp3, r0, save b,n null4 /* special case for first word */ copy r0, tmp5 /* zero out tmp5 so we don't try to mask again*/ copy r0, tmp7 /* zero out tmp7 so we don't try to use original s_addr anymore */ b continue stbys,b,m tmp3,4(0,d_addr) /* store ! */ chunk2: ldwm 4(0,s_addr),tmp2 vshd tmp1,tmp2,tmp3 skip_mask2: uxor,nbz tmp3, r0, save b,n null3 stbys,b,m tmp3,4(0,d_addr) /* store ! */ continue: ldwm 4(0,s_addr),tmp1 /* get 2nd word ! */ vshd tmp2,tmp1,tmp3 /* position data ! */ uxor,nbz tmp3, r0, save b,n null3 addibf,< -8,count,chunk2 /* If count is still >= 8 do another loop.*/ stbys,b,m tmp3,4(0,d_addr) /* store !*/ chkchnk2: addibt,<,n 4,count,bp_0 /* if we don't have 4 bytes left then do the back porch (bp_0)*/ subchnk2: /* we have less than 8 chars to copy*/ ldwm 4(0,s_addr),tmp2 /* get next word !*/ combt,= tmp5,r0,skip_mask3 vshd tmp1,tmp2,tmp3 /* position data !*/ sh3add tmp5,r0,save /* setup r1*/ mtctl save,r11 /* setup mask in save*/ zvdepi -2,32,save or save, tmp3, tmp3 mtctl tmp4,11 /* restore shift value again */ skip_mask3: uxor,nbz tmp3,r0,save b,n null3 copy r0,tmp5 /* zero out tmp5 so null3 does correct alignment */ copy r0,tmp7 /* zero out tmp7 so we don't use orignal s_addr since no longer valid */ b bp_1 /* we now have less than 4 bytes to move*/ stbys,b,m tmp3,4(0,d_addr) /* store !*/ bp_0: copy tmp1,tmp2 /* switch registers for shift process */ addibt,<=,n 4,count,done /* if count = -4 this implies that count = 0 -> done */ bp_1: ldwm 4(0,s_addr),tmp1 /* get final word ! */ vshd tmp2,tmp1,tmp3 /* position data !*/ uxor,nbz tmp3,r0,save /* if no-byte-zero */ b,n bp_null /* don't goto no_null-find which null instead */ no_null: add d_addr,count,d_addr /* set up d_addr for stbys,e */ b done /* were done*/ stbys,e tmp3,0(0,d_addr) /* store the data !*/ /* here we do ye old byte-at-a-time moves.*/ align_null1: b byteloop addi -4,s_addr,s_addr null1: copy tmp6,s_addr /* restore orig s_addr (aligned only) */ byteloop: addibt,= 4,count,done null2: ldbs,ma 1(s_addr),tmp1 encore: combt,=,n tmp1,r0, done stbs,ma tmp1,1(d_addr) addibf,=,n -1,count,encore ldbs,ma 1(s_addr),tmp1 b,n done bp_null: addi -4,count,count /* fudge count 'cause byteloop will re-increment */ null3: /* not_aligned case reset s_addr and finish byte-wise */ combt,=,n r0,tmp7,null3a /* if tmp7 is not valid address then branch below */ b byteloop /* otherwise reset s_addr to tmp7 and finish */ copy tmp7, s_addr null3a: /* right shift target */ addibt,<,n 0,tmp6,null3b /* if left shifting */ sub r0,tmp6,tmp6 /* do null3b code */ addi -4,tmp6,tmp6 b byteloop add tmp6,s_addr,s_addr /* reset s_addr by 4 + shift_amt */ null3b: subi -8,tmp6,tmp6 add tmp5,tmp6,tmp6 /* adjust by the dest offset if this is our first store */ b byteloop add tmp6,s_addr,s_addr /* adjust s_addr by (8-shift_amt-dest_off) */ null4: add,> tmp6,r0,tmp6 /* if left shift */ b,n null3 /* then do null3 */ b byteloop addi -4,s_addr,s_addr /* adj source only by 4 */ done: bv 0(r2) stbs r0,0(d_addr) quit: EXIT(strncat) picolibc-1.8.11/libc/machine/hppa/strncmp.S000066400000000000000000000164031513574234600204630ustar00rootroot00000000000000/* * (c) Copyright 1986 HEWLETT-PACKARD COMPANY * * To anyone who acknowledges that this file is provided "AS IS" * without any express or implied warranty: * permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies, and that the name of Hewlett-Packard Company not be * used in advertising or publicity pertaining to distribution * of the software without specific, written prior permission. * Hewlett-Packard Company makes no representations about the * suitability of this software for any purpose. */ /* strcmp(s1, s2) */ /* returns integer: < 0 iff s1 lexicographically less than s2 */ /* > 0 iff s1 lexicographically greater than s2 */ /* = 0 iff s1 lexicographically equal to s2 */ /* = 0 iff s1 lexicographically equal to s2 */ /* quit after n charachters */ #include #include "DEFS.h" #define s1 26 #define s2 25 #define tmp1 19 #define s2word 20 #define tmp3 21 #define tmp7 22 #define s1word 29 #define save 1 #define tmp6 23 #define tmp5 28 #define count 24 ENTRY(strncmp) combt,<,n r0,count,search /* N <= 0 yields equality */ bv r0(rp) /* */ copy 0,ret0 /* return 0 (DELAY SLOT) */ search: combf,=,n s1,s2,findout /* s1 != s2? */ bv r0(rp) /* */ copy 0,ret0 /* return 0 (delay slot) */ findout: comibf,=,n 0,s1,checks1 /* s1 == NULL? */ ldbs 0(0,s2),ret0 /* */ bv r0(rp) /* */ subi 0,ret0,ret0 /* ret0 <- -*s2 */ checks1: comibf,=,n 0,s2,checkitout /* s2 == NULL? */ bv r0(rp) /* */ ldbs 0(0,s1),28 /* return *s1 */ checkitout: extru s2,31,2,tmp1 /* Extract the low two bits of the s2. */ extru s1,31,2,tmp5 /* Extract the low two bits of the s1 */ sub,= tmp5,tmp1,tmp3 /* Are s1 & s2 aligned with each other? */ b not_aligned /* It's more complicated (not_aligned) */ dep 0,31,2,s1 /* Compute word address of s1 (DELAY SLOT) */ dep 0,31,2,s2 /* Compute word address of s2 */ ldwm 4(0,s1),s1word /* get next s1 word s1+=4 */ combt,= tmp5,r0,skipmask /* skip masking, if we can */ ldwm 4(0,s2),s2word /* get next s2 word s2+=4 (DELAY SLOT) */ add tmp5,count,count /* bump count by the number of bytes */ /* we are going to mask */ sh3add tmp5,r0,save /* save now has number of bits to mask */ mtctl save,11 zvdepi -2,32,save /* load save with proper mask */ or save,s1word,s1word /* mask s1word (s1) */ or save,s2word,s2word /* mask s2word (s2) */ skipmask: combt,=,n s1word,s2word,chknulls /* are these words equal? */ checkbyte: extru s1word,7,8,tmp3 /* get first byte (character) */ ckbyte2: extru s2word,7,8,tmp7 /* get first byte (character) */ combf,= tmp3,tmp7,done /* quit if first byte is not equal */ sub tmp3,tmp7,ret0 /* return difference (delay slot) */ comibt,=,n 0,tmp3,done /* have we reached the end of string */ /* if so done ret0 already has zero */ addibt,<=,n -1,count,done /* have we checked N chars? ret0 == 0 */ extru s1word,15,8,tmp3 /* get second byte (character) */ extru s2word,15,8,tmp7 /* get second byte (character) */ combf,= tmp3,tmp7,done /* quit if second byte is not equal */ sub tmp3,tmp7,ret0 /* return difference (delay slot) */ comibt,=,n 0,tmp3,done /* have we reached the end of string */ /* if so done ret0 already has zero */ addibt,<=,n -1,count,done /* have we checked N chars? */ extru s1word,23,8,tmp3 /* get third byte (character) */ extru s2word,23,8,tmp7 /* get third byte (character) */ combf,= tmp3,tmp7,done /* done if third byte is not equal */ sub tmp3,tmp7,ret0 /* return difference (delay slot) */ comibt,=,n 0,tmp3,done /* have we reached the end of string */ /* if so done ret0 already has zero */ addibt,<=,n -1,count,done /* have we checked N chars? */ extru s1word,31,8,tmp3 /* get last byte (character) */ extru s2word,31,8,tmp7 /* get last byte (character) */ bv r0(rp) /* */ sub tmp3,tmp7,ret0 /* the last characters in the word is */ /* where the difference is, so return */ /* the difference and we're outta here */ chknulls: addibt,<=,n -4,count,zero /* have we checked N chars? */ uxor,nbz s1word,0,0 /* don't have to check s2 Just quit */ bv r0(rp) /* */ copy 0,28 /* return 0 */ ldwm 4(0,s2),s2word /* get next s2 word s2+=4 */ b skipmask /* keep checking */ ldwm 4(0,s1),s1word /* get next s1 word s1+=4 */ not_aligned: dep r0,31,2,s2 /* Compute word address of s2 */ combt,<,n r0,tmp3,shifts1 /* Do we shift s1 or s2 */ sh3add tmp3,r0,tmp3 /* eight bits per byte so mul by 8 */ ldwm 4(0,s1),s1word /* get first word of s1 */ ldwm 4(0,s2),s2word /* get first word or s2 */ combt,=,n r0,tmp5,masks2 /* Do we need to mask beginning of s1 */ add tmp5,count,count /* bump count by the number of bytes */ /* we are going to mask */ sh3add tmp5,r0,save /* save now has number of bits to mask */ mtctl save,11 zvdepi -2,32,save /* load save with proper mask */ or save,s1word,s1word /* */ masks2: sh3add tmp1,r0,save /* save now has number of bits to mask */ mtctl save,11 zvdepi -2,32,save /* load save with proper mask */ or save,s2word,s2word /* */ mtctl tmp3,11 /* Move shift amount to CR11 */ more: uxor,nbz s2word,r0,r0 /* Is there a null in first word */ b,n chunk1 /* */ ldwm 4(0,s2),tmp7 /* load second word to enable us to shift */ vshd s2word,tmp7,s2word /* */ combf,=,n s1word,s2word,ckbyte2 /* */ extru s1word,7,8,tmp3 /* get first byte (DELAY SLOT) */ addibt,<=,n -4,count,zero /* have we checked N chars? */ uxor,nbz s1word,0,0 /* even though they're equal we could be done */ b,n zero copy tmp7,s2word /* */ b more /* keep checking */ ldwm 4(0,s1),s1word /* get next s1 (DELAY SLOT) */ chunk1: vshd s2word,r0,s2word /* */ b ckbyte2 /* */ extru s1word,7,8,tmp3 /* */ shifts1: sh3add tmp3,r0,tmp3 /* eight bits per byte so mul by 4 */ sub r0,tmp3,tmp3 /* Get negative value for left shift */ ldwm 4(0,s2),s2word /* get first word of s2 */ ldwm 4(0,s1),s1word /* get first word or s1 */ combt,=,n r0,tmp1,masks1 /* Do we need to mask beginning of s2 */ add tmp1,count,count /* bump count by the number of bytes */ /* we are going to mask */ sh3add tmp1,r0,save /* save now has number of bits to mask */ mtctl save,11 zvdepi -2,32,save /* load save with proper mask */ or save,s2word,s2word /* */ masks1: sh3add tmp5,r0,save /* save now has number of bits to mask */ mtctl save,11 zvdepi -2,32,save /* load save with proper mask */ or save,s1word,s1word /* */ mtctl tmp3,11 /* Move shift amount to CR11 */ more1: uxor,nbz s1word,r0,r0 /* Is there a null in first byte */ b,n chunk2 /* */ ldwm 4(0,s1),tmp7 /* load second word to enable us to shift */ vshd s1word,tmp7,s1word /* */ combf,=,n s2word,s1word,ckbyte2 /* */ extru s1word,7,8,tmp3 /* get first byte (DELAY SLOT) */ addibt,<=,n -4,count,zero /* have we checked N chars? */ uxor,nbz s2word,0,0 /* even though they're equal we could be done */ b,n zero /* zero ret0 and quit */ copy tmp7,s1word /* */ b more1 /* keep checking */ ldwm 4(0,s2),s2word /* get next s2 (DELAY SLOT) */ chunk2: vshd s1word,r0,s1word /* */ b ckbyte2 /* */ extru s1word,7,8,tmp3 /* */ zero: copy r0,ret0 done: EXIT(strncmp) picolibc-1.8.11/libc/machine/hppa/strncpy.S000066400000000000000000000212461513574234600205000ustar00rootroot00000000000000/* * (c) Copyright 1986 HEWLETT-PACKARD COMPANY * * To anyone who acknowledges that this file is provided "AS IS" * without any express or implied warranty: * permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies, and that the name of Hewlett-Packard Company not be * used in advertising or publicity pertaining to distribution * of the software without specific, written prior permission. * Hewlett-Packard Company makes no representations about the * suitability of this software for any purpose. */ /* HPUX_ID: @(#) $Revision$ */ /* * strncpy(s1, s2, n) * * Copy s2 to s1, truncating or null-padding to always copy n bytes * return s1 */ #include #include "DEFS.h" #define d_addr r26 #define s_addr r25 #define count r24 #define tmp1 r19 #define tmp2 r20 #define tmp3 r21 #define tmp4 r22 #define tmp5 arg3 #define save r1 ENTRY(strncpy) combt,= s_addr,r0,pad_null_bytes1 /* if s2==NULL then pad nulls and exit */ copy d_addr,ret0 /* The return value is defined to be the value of d_addr. DELAY SLOT*/ addibt,<,n -4,count,byteloop /* If count is <= 4 don't get fancy.*/ extru s_addr,31,2,tmp1 /* Extract the low two bits of the source address.*/ extru d_addr,31,2,tmp5 /* Extract the low two bits of the destination address.*/ add count,tmp5,count /* pre increment the count by the byte address so that the count is*/ comb,<> tmp5,tmp1,not_aligned /* branch if tmp5<>tmp1. */ dep 0,31,2,s_addr /* Compute the word address of the source. DELAY SLOT.*/ /* aligned*/ combt,= tmp5,r0,skip_mask ldwm 4(0,s_addr),tmp1 /* tmp1 = *s_addr s_addr += 4 (DELAY SLOT)*/ sh3add tmp5,r0,save /* compute mask in save*/ mtctl save,11 zvdepi -2,32,save b skip_mask /* don't reload tmp1*/ or save,tmp1,tmp1 /* or mask with data*/ chunks: ldwm 4(0,s_addr),tmp1 /* get a word*/ skip_mask: uxor,nbz tmp1,r0,save /* check for null*/ b,n null1 addibf,< -4,count,chunks stbys,b,m tmp1,4(0,d_addr) /* store word (delay slot)*/ /* back_porch last word to store*/ addibt,=,n 4,count,done /* if count = 0 we're, of course, done !*/ ldws 0(s_addr),tmp1 /* load up the back_porch*/ add d_addr,count,d_addr/* final store address is +1 too high !*/ sh3add count,r0, save /* setup right mask based on count*/ mtctl save,r11 zvdepi -2,32,save /*save now has left-hand mask*/ uaddcm r0,save,save /*form right hand mask */ or tmp1,save,tmp1 /*and insert data*/ uxor,nbz tmp1,r0,save /* check for null*/ b,n null2 bv 0(r2) stbys,e tmp1,0(d_addr) /* done */ /* Begin non_aligned code. */ not_aligned: sub,>= tmp5,tmp1,tmp3 /* compute the shift amt.and skip load if tmp5 > tmp1.*/ ldwm 4(0,s_addr),tmp1 /* load up the first word from the source. tmp1 = *s_addr++*/ zdep tmp3,28,29,tmp4 /* compute the number of bits to shift */ mtctl tmp4,11 /* load the shift count into cr11 = shift count register.*/ addibt,<,n -4,count,chkchnk2 /* first step in pre adjustment of count for looping.*/ ldwm 4(0,s_addr),tmp2 /* get either first or second word from source. */ combt,= tmp5,r0,skip_mask2 /* don't mask if whole word is valid*/ vshd tmp1,tmp2,tmp3 /* position data ! (delay slot)*/ sh3add tmp5,r0,save /* setup r1*/ mtctl save,r11 /* setup mask in save*/ zvdepi -2,32,save or save, tmp3, tmp3 mtctl tmp4,11 /* re-load the shift count into cr11 */ b skip_mask2 copy r0, tmp5 /* zero out tmp5 so we don't try to mask again*/ chunk2: ldwm 4(0,s_addr),tmp2 vshd tmp1,tmp2,tmp3 skip_mask2: uxor,nbz tmp3, r0, save b,n null3 stbys,b,m tmp3,4(0,d_addr) /* store ! */ ldwm 4(0,s_addr),tmp1 /* get 2nd word ! */ vshd tmp2,tmp1,tmp3 /* position data ! */ uxor,nbz tmp3, r0, save b,n null4 addibf,< -8,count,chunk2 /* If count is still >= 8 do another loop.*/ stbys,b,m tmp3,4(0,d_addr) /* store !*/ chkchnk2: addibt,<,n 4,count,bp_0 /* if we don't have 4 bytes left then do the back porch (bp_0)*/ subchnk2: /* we have less than 8 chars to copy*/ ldwm 4(0,s_addr),tmp2 /* get next word !*/ combt,= tmp5,r0,skip_mask3 vshd tmp1,tmp2,tmp3 /* position data !*/ sh3add tmp5,r0,save /* setup r1*/ mtctl save,r11 /* setup mask in save*/ zvdepi -2,32,save or save, tmp3, tmp3 mtctl tmp4,11 /* restore shift value again */ copy r0, tmp5 /* zero out tmp5 so we don't try to mask again*/ skip_mask3: uxor,nbz tmp3,r0,save b,n null4 b bp_1 /* we now have less than 4 bytes to move*/ stbys,b,m tmp3,4(0,d_addr) /* store !*/ bp_0: copy tmp1,tmp2 /* switch registers used in the shift process.*/ addibt,<=,n 4,count,done /* if count = -4 this implies that count = 0 -> done */ bp_1: ldwm 4(0,s_addr),tmp1 /* get final word ! */ vshd tmp2,tmp1,tmp3 /* position data !*/ uxor,sbz tmp3,r0,save /* if some-byte-zero */ b no_null /* don't goto no_null-find which null instead */ add d_addr,count,d_addr /* get d_addr ready for stbys,e */ extru,<> save,7,8,r0 b found_null5 copy r0, tmp5 extru,<> save,15,8,r0 b found_null5 ldil 0x1FE000,tmp5 /* setup mask (FF000000)*/ extru,<> save,23,8,r0 b found_null5 ldil 0x1FFFE0,tmp5 /* setup mask (FFFF0000)*/ ldo -1(r0),tmp5 /* setup mask (FFFFFFFF)*/ found_null5: and tmp3,tmp5,tmp3 /* zero out tmp5 based on mask in tmp5*/ no_null: bv 0(r2) /* were done*/ stbys,e tmp3,0(0,d_addr) /* store the data !*/ /* here we do ye old byte-at-a-time moves.*/ byteloop: addibt,=,n 4,count,done comb,= 0,s_addr,done stbs r0,0(d_addr) /* store null in case s_addr == NULL */ ldbs,ma 1(s_addr),tmp1 encore: combt,=,n tmp1,r0, pad_null_bytes1 stbs,ma tmp1,1(d_addr) addibf,=,n -1,count,encore ldbs,ma 1(s_addr),tmp1 b,n done pnb_1: addibt,=,n 4,count,done /* if count was already 0 then we're done*/ pad_null_bytes1: combt,=,n count,r0,done /* if count==0 then exit */ pad_null_bytes2: addibf,= -1,count,pad_null_bytes2 stbs,ma r0,1(d_addr) b,n done pad_nulls: addibf,<=,n -4,count,pad_nulls stwm r0,4(d_addr) b,n pnb_1 null1: extru,<> save,7,8,r0 b found_null1 copy r0, tmp5 extru,<> save,15,8,r0 b found_null1 ldil 0x1FE000,tmp5 /* setup mask (FF000000)*/ extru,<> save,23,8,r0 b found_null1 ldil 0x1FFFE0,tmp5 /* setup mask (FFFF0000)*/ ldo -1(r0),tmp5 /* setup mask (FFFFFFFF)*/ found_null1: and tmp1,tmp5,tmp1 /*zero out tmp1 according to mask*/ b pad_nulls /* nullify remaining count bytes*/ stbys,b,m tmp1,4(0,d_addr) /* first word (account for alignment)*/ null2: /* back porch case. We have less than 4 bytes to go.*/ extru,<> save,7,8,r0 /* is null in 1st byte? */ b found_null2 copy r0, tmp5 extru,<> save,15,8,r0 /* is null in 2nd byte? */ b found_null2 ldil 0x1FE000,tmp5 /* setup mask (FF000000)*/ b found_null2 /* null must be in 3rd byte */ ldil 0x1FFFE0,tmp5 /* setup mask (FFFF0000)*/ found_null2: and tmp1,tmp5,tmp1 /*zero out tmp1 according to mask*/ bv 0(r2) /* we're done*/ stbys,e tmp1,0(0,d_addr) /* last word (back porch)*/ null3: /* not_aligned case where null is found in first of two words--adjust count*/ extru,<> save,7,8,r0 b found_null3 copy r0, tmp5 extru,<> save,15,8,r0 b found_null3 ldil 0x1FE000,tmp5 /* setup mask (FF000000)*/ extru,<> save,23,8,r0 b found_null3 ldil 0x1FFFE0,tmp5 /* setup mask (FFFF0000)*/ ldo -1(r0),tmp5 /* setup mask (FFFFFFFF)*/ found_null3: addi 4,count,count /* fix count since null is in first of two words*/ and tmp3,tmp5,tmp3 /*zero out tmp3 according to mask*/ b pad_nulls /* nullify remaining count bytes*/ stbys,b,m tmp3,4(d_addr) null4: /* not_aligned case where null is found in second of two words*/ extru,<> save,7,8,r0 b found_null4 copy r0, tmp5 extru,<> save,15,8,r0 b found_null4 ldil 0x1FE000,tmp5 /* setup mask (FF000000)*/ extru,<> save,23,8,r0 b found_null4 ldil 0x1FFFE0,tmp5 /* setup mask (FFFF0000)*/ ldo -1(r0),tmp5 /* setup mask (FFFFFFFF)*/ found_null4: and tmp3,tmp5,tmp3 /*zero out tmp4 according to mask*/ b pad_nulls /* nullify remaining count bytes*/ stbys,b,m tmp3,4(d_addr) done: EXIT(strncpy) picolibc-1.8.11/libc/machine/i960/000077500000000000000000000000001513574234600164045ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/i960/memccpy.S000066400000000000000000000113721513574234600201710ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "memccpy.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1989,1993 Intel Corp., all rights reserved */ /* procedure memccpy (optimized assembler version for the 80960K series) dest_addr = memccpy (dest_addr, src_addr, char, len) copy len bytes pointed to by src_addr to the space pointed to by dest_addr, stopping if char is copied. If char is copied, return address of byte after char in dest string; else null. Undefined behavior will occur if the end of the source array is in the last two words of the program's allocated memory space. This is so because the routine fetches ahead. Disallowing the fetch ahead would impose a severe performance penalty. Undefined behavior will also occur if the source and destination strings overlap. Strategy: Fetch the source array by words and store them by words to the destination array, until there are fewer than three bytes left to copy. Then, using the last word of the source (the one that contains the remaining 0, 1, 2, or 3 bytes to be copied), store a byte at a time until Ldone. Tactics: 1) Do NOT try to fetch and store the words in a word aligned manner because, in my judgement, the performance degradation experienced due to non-aligned accesses does NOT outweigh the time and complexity added by the preamble and convoluted body that would be necessary to assure alignment. This is supported by the intuition that most source and destination arrays (even more true of most big source arrays) will be word aligned to begin with. 2) Rather than decrementing len to zero, I calculate the address of the byte after the last byte of the destination array, and quit when the destination byte pointer passes that. */ .globl _memccpy .leafproc _memccpy, __memccpy .align 2 _memccpy: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __memccpy: mov g14, g13 # preserve return address cmpibge 0,g3,Lexit_char_not_found addo g3,g1,g3 # compute beyond end of src ld (g1), g7 # fetch first word of source lda 0xff,g5 # mask for char and g5,g2,g2 # extract only char shlo 8,g2,g6 or g2,g6,g6 shlo 16,g6,g4 or g6,g4,g6 # word of char b Lwloop_b Lwloop_a: ld (g1), g7 # fetch ahead next word of source st g4, (g0) # store word to dest addo 4, g0, g0 # post-increment dest pointer Lwloop_b: # word copying loop addo 4, g1, g1 # pre-increment src pointer cmpo g3, g1 # is len <= 3 ? mov g7, g4 # keep a copy of the current word bl Lcloop_setup # quit word loop if less than 4 bytes scanbyte g6, g7 # check for char bno Lwloop_a # continue word loop if char not found. Lcloop_setup: subo 4, g1, g1 # back down src pointer cmpobe g1, g3, Lexit_char_not_found Lcloop_a: # character copying loop (len < 3) and g5,g4,g7 # check the byte against char cmpo g7,g2 stob g7,(g0) # store the byte addo 1, g0, g0 be Lexit_char_found addo 1,g1,g1 cmpo g1,g3 shro 8,g4,g4 # position next byte bne Lcloop_a Lexit_char_not_found: mov 0, g0 Lexit_char_found: lda 0,g14 bx (g13) # g0 = dest array address; g14 = 0 Lrett: ret /* end of memccpy */ picolibc-1.8.11/libc/machine/i960/memccpy_ca.S000066400000000000000000000177021513574234600206370ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "mccpy_ca.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1989,1993 Intel Corp., all rights reserved */ /* procedure memccpy (optimized assembler version for the 80960CA) dest_addr = memccpy (dest_addr, src_addr, char, len) copy len bytes pointed to by src_addr to the space pointed to by dest_addr, stopping if char is copied. If char is copied, return address of byte after char in dest string; else null. Undefined behavior will occur if the end of the source array is in the last two words of the program's allocated memory space. This is so because the routine fetches ahead. Disallowing the fetch ahead would impose a severe performance penalty. Undefined behavior will also occur if the source and destination strings overlap. This program handles five cases: 1) both arguments start on a word boundary 2) neither are word aligned, but they are offset by the same amount 3) source is word aligned, destination is not 4) destination is word aligned, source is not 5) neither is word aligned, and they are offset by differing amounts At the time of this writing, only g0 thru g7 and g13 are available for use in this leafproc; other registers would have to be saved and restored. These nine registers, plus tricky use of g14 are sufficient to implement the routine. */ #if __i960_BIG_ENDIAN__ #define MSW g6 #define LSW g7 #else #define LSW g6 #define MSW g7 #endif .globl _memccpy .leafproc _memccpy, __memccpy .align 2 _memccpy: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __memccpy: notand g1,3,g5 # extract word addr of start of src lda (g14),g13 # preserve return address cmpibge.f 0,g3,Lexit_char_not_found # Lexit if # of bytes to move is <= 0 cmpo g5,g1 # check alignment of src ld (g5),LSW # fetch word containing at least first byte notand g0,3,g4 # extract word addr of start of dest lda 4(g5),g5 # advance src word addr shlo 24,g2,g2 # reduce char to single byte bne.f Lcase_245 # branch if src is NOT word aligned Lcase_13: cmpobe.t g0,g4,Lcase_1_setup # branch if dest word aligned Lcase_3: # src is word aligned; dest is not mov LSW,MSW # make copy of first word of src addo 4,g4,g1 # move dest word ptr to first word boundary lda 32,g14 # initialize shift count to zero Lcase_25: Lcase_3_cloop_at_start: # character copying loop for start of dest str cmpdeci 0,g3,g3 # is max_bytes exhausted? #if __i960_BIG_ENDIAN__ lda -8(g14),g14 # augment the shift counter #else lda 8(g14),g14 # augment the shift counter #endif be.f Lexit_char_not_found # Lexit if max_bytes is exhausted #if __i960_BIG_ENDIAN__ rotate 8,MSW,MSW # move next byte into position for extraction #endif shlo 24,MSW,g4 stob MSW,(g0) # store the byte in dest cmpo g4,g2 lda 1(g0),g0 # post-increment dest ptr #if ! __i960_BIG_ENDIAN__ shro 8,MSW,MSW # move next byte into position for extraction #endif be.f Lexit_char_found # Lexit if char found cmpobne.t g1,g0,Lcase_3_cloop_at_start # branch if reached word boundary ld (g5),MSW # fetch msw of operand for double shift Lcase_4: shro 8,g2,g4 or g4,g2,g1 shro 16,g1,g4 or g4,g1,g4 #if __i960_BIG_ENDIAN__ cmpobne 0,g14,Lcase_3_wloop Lcase_3_wloop2: cmpi g3,4 # less than four bytes to move? lda 4(g5),g5 # post-increment src word addr mov LSW,g1 # extract 4 bytes of src bl.f Lcase_13_cloop_setup # branch if < four bytes left to move scanbyte g4,g1 # branch if word has char in it bo.f Lcase_13_cloop_setup mov MSW,LSW # move msw to lsw ld (g5),MSW # pre-fetch msw of operand for double shift subi 4,g3,g3 # decrease max_byte count by the 4 bytes moved st g1,(g0) # store 4 bytes to dest addo 4,g0,g0 # post-increment dest ptr b Lcase_3_wloop2 #endif Lcase_3_wloop: cmpi g3,4 # less than four bytes to move? lda 4(g5),g5 # post-increment src word addr eshro g14,g6,g1 # extract 4 bytes of src bl.f Lcase_13_cloop_setup # branch if < four bytes left to move scanbyte g4,g1 # branch if word has char in it bo.f Lcase_13_cloop_setup mov MSW,LSW # move msw to lsw ld (g5),MSW # pre-fetch msw of operand for double shift subi 4,g3,g3 # decrease max_byte count by the 4 bytes moved st g1,(g0) # store 4 bytes to dest addo 4,g0,g0 # post-increment dest ptr b Lcase_3_wloop Lcase_1_setup: subo 4,g0,g0 # store is pre-incrementing; back up dest addr shro 8,g2,g4 or g4,g2,MSW shro 16,MSW,g4 or g4,MSW,g4 b Lcase_1 Lcase_1_wloop: # word copying loop subi 4,g3,g3 # decrease max_byte count by the 4 bytes moved ld (g5),LSW # pre-fetch next word of src addo 4,g5,g5 # post-increment src addr st g1,(g0) # store word in dest string Lcase_1: # src and dest are word aligned cmpi g3,4 # check for fewer than four bytes to move addo 4,g0,g0 # pre-increment dest addr lda (LSW),g1 # keep a copy of the src word bl.f Lcase_13_cloop_setup # branch if less than four bytes to copy scanbyte LSW,g4 # branch if char is not in foursome bno.t Lcase_1_wloop Lcase_13_cloop_setup: cmpibe.f 0,g3,Lexit_char_not_found # Lexit if max_bytes is exhausted Lcase_1_cloop: #if __i960_BIG_ENDIAN__ rotate 8,g1,g1 # move next byte into position for extraction #endif shlo 24,g1,g4 stob g1,(g0) # store the byte in dest cmpo g4,g2 lda 1(g0),g0 # post-increment dest byte addr subi 1,g3,g3 be.f Lexit_char_found # Lexit if char reached cmpi 0,g3 #if ! __i960_BIG_ENDIAN__ shro 8,g1,g1 # move next byte into position for extraction #endif bne.t Lcase_1_cloop # continue if len not exhausted Lexit_char_not_found: mov 0,g0 Lexit_char_found: lda 0,g14 bx (g13) # g0 = dest array address; g14 = 0 Lrett: ret Lcase_245: cmpo g0,g4 # check alignment of dest ld (g5),MSW # pre-fetch second half and 3,g1,g1 # compute shift count shlo 3,g1,g14 #if __i960_BIG_ENDIAN__ subo g14,0,g14 # adjust shift count for big endian #endif be.t Lcase_4 # branch if dest is word aligned or g4,g1,g1 # is src earlier in word, later, or sync w/ dst cmpo g0,g1 # < indicates first word of dest has more bytes /* than first word of source. */ eshro g14,g6,g4 # extract four bytes lda 4(g0),g1 # move dest word addr to first word boundary #if __i960_BIG_ENDIAN__ bge.f 1f #else bg.f 1f #endif mov MSW,LSW lda 4(g5),g5 # move src word addr to second word boundary 1: notand g1,3,g1 mov g4,MSW b Lcase_25 /* end of memccpy */ picolibc-1.8.11/libc/machine/i960/memchr.S000066400000000000000000000113721513574234600200070ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "memchr.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure memchr (optimized assembler version for the 80960K series) src_addr = memchr (src_addr, char, max_bytes) searching from src_addr for a span of max_bytes bytes, return a pointer to the first byte in the source array that contains the indicated char. Return null if the char is not found. Undefined behavior will occur if the last byte of the source array is in the last two words of the program's allocated memory space. This is so because memchr fetches ahead. Disallowing the fetch ahead would impose a severe performance penalty. Strategy: Fetch the source array by words and scanbyte the words for the char until either a word with the byte is found or max_bytes is exhausted. In the former case, move through the word to find the matching byte and return its memory address. In the latter case, return zero (null). Tactics: 1) Do NOT try to fetch the words in a word aligned manner because, in my judgement, the performance degradation experienced due to non-aligned accesses does NOT outweigh the time and complexity added by the preamble that would be necessary to assure alignment. This is supported by the intuition that most source arrays (even more true of most big source arrays) will be word aligned to begin with. 2) Rather than decrementing max_bytes to zero, I calculate the address of the byte after the last byte of the source array, and quit when the source byte pointer passes that. Refining, actually I calculate the address of the fifth byte after the last byte of the source array, because the source byte pointer is ahead of the actual examination point due to fetch ahead. */ .globl _memchr .globl __memchr .leafproc _memchr, __memchr .align 2 _memchr: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __memchr: mov g14,g13 # preserve return address lda 0xff,g7 # byte extraction mask and g1,g7,g1 # make char an 8-bit ordinal mov 0,g14 # conform to register linkage standard cmpibge 0,g2,Lnot_found # do nothing if max_bytes <= 0 addo 4,g0,g6 # post-increment src word pointer addo g2,g6,g2 # compute ending address from start and len ld (g0),g4 # fetch first word shlo 8,g1,g3 # broadcast the char to four bytes or g1,g3,g3 shlo 16,g3,g5 or g3,g5,g3 Lsearch_for_word_with_char: mov g4,g5 # keep a copy of word scanbyte g3,g5 # check for byte with char ld (g6),g4 # fetch next word of src bo Lsearch_for_char # branch if null found addo 4,g6,g6 # post-increment src word pointer cmpobge g2,g6,Lsearch_for_word_with_char # branch if max_bytes > 3 Lnot_found: mov 0,g0 # char not found. Return null bx (g13) # g0 = addr of char in src (or null); g14 = 0 Lrett: ret Lsearch_for_char: cmpobe.f g6,g2,Lnot_found # quit if max_bytes exhausted and g5,g7,g0 # extract byte cmpo g1,g0 # is it char? addo 1,g6,g6 # bump src byte ptr shro 8,g5,g5 # shift word to position next byte bne.t Lsearch_for_char subo 5,g6,g0 # back up the byte pointer bx (g13) /* end of memchr */ picolibc-1.8.11/libc/machine/i960/memchr_ca.S000066400000000000000000000124241513574234600204510ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "memchr_ca.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure memchr (optimized assembler version for the CA) src_addr = memchr (src_addr, char, max_bytes) searching from src_addr for max_bytes bytes, return a pointer to the first byte that contains the indicated byte in the source string. Return null if the byte is not found. Undefined behavior will occur if the end of the source string (i.e. the terminating null byte) is in the last two words of the program's allocated memory space. This is so because, in several cases, memchr will fetch ahead. Disallowing the fetch ahead would impose a severe performance penalty. This program handles two cases: 1) the argument starts on a word boundary 2) the argument doesn't start on a word boundary At the time of this writing, only g0 thru g7 and g13 are available for use in this leafproc; other registers would have to be saved and restored. These nine registers, plus tricky use of g14 are sufficient to implement the routine. The registers are used as follows: g0 src ptr; upon return it is a pointer to the matching byte, or null g1 char to seek g2 maximum number of bytes to check g3 char to seek, broadcast to all four bytes g4 word of the source string g5 copy of the word g6 mask to avoid unimportant bytes in first word g7 byte extraction mask g13 return address g14 */ .globl _memchr .globl __memchr .leafproc _memchr, __memchr .align 2 _memchr: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __memchr: mov g14,g13 # preserve return address lda 0xff,g7 # byte extraction mask and g1,g7,g1 # make char an 8-bit ordinal lda 0,g14 # conform to register linkage standard cmpibge.f 0,g2,Lnot_found # do nothing if max_bytes <= 0 addo g0,g2,g2 # compute ending address from start and len and g0,3,g6 # extract byte offset of src notand g0,3,g0 # extract word addr of start of src shlo 8,g1,g3 # broadcast the char to four bytes ld (g0),g4 # fetch word containing at least first byte or g1,g3,g3 shlo 16,g3,g5 cmpo g1,g7 # is char being sought 0xff? or g5,g3,g3 shlo 3,g6,g6 # get shift count for making mask for first word subi 1,0,g5 # mask initially all ones #if __i960_BIG_ENDIAN__ shro g6,g5,g5 # get mask for bytes needed from first word #else shlo g6,g5,g5 # get mask for bytes needed from first word #endif notor g4,g5,g4 # set unneeded bytes to all ones be.f Lsearch_for_0xff # branch if seeking 0xff Lsearch_for_word_with_char: scanbyte g3,g4 # check for byte with char lda 4(g0),g0 # pre-increment src word pointer mov g4,g5 # keep a copy of word ld (g0),g4 # fetch next word of src bo.f Lsearch_for_char # branch if null found cmpoble.t g0,g2,Lsearch_for_word_with_char # branch if not null Lnot_found: mov 0,g0 # char not found. Return null Lexit_code: bx (g13) # g0 = addr of char in src (or null); g14 = 0 Lrett: ret Lsearch_for_char: subo 4,g0,g0 # back up the byte pointer Lsearch_for_char.a: cmpobe.f g0,g2,Lnot_found # quit if max_bytes exhausted #if __i960_BIG_ENDIAN__ rotate 8,g5,g5 # shift word to position next byte #endif and g5,g7,g6 # extract byte cmpo g1,g6 # is it char? lda 1(g0),g0 # bump src byte ptr #if ! __i960_BIG_ENDIAN__ shro 8,g5,g5 # shift word to position next byte #endif bne.t Lsearch_for_char.a subo 1,g0,g0 # back up the byte pointer b Lexit_code Lsearch_for_0xff: lda 0xf0f0f0f0,g6 # make first comparison mask for char=-1 case. or g6,g5,g6 and g4,g6,g4 # make unimportant bytes of first word 0x0f b Lsearch_for_word_with_char /* end of memchr */ picolibc-1.8.11/libc/machine/i960/memcmp.S000066400000000000000000000110531513574234600200060ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "memcmp.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure memcmp (optimized assembler version for the 80960K series) result = memcmp (src1_addr, src2_addr, max_bytes) compare the byte array pointed to by src1_addr to the byte array pointed to by src2_addr. Return 0 iff the arrays are equal, -1 iff src1_addr is lexicographically less than src2_addr, and 1 iff it is lexicographically greater. Do not compare more than max_bytes bytes. Undefined behavior will occur if the end of either source array is in the last two words of the program's allocated memory space. This is so because memcmp fetches ahead. Disallowing the fetch ahead would impose a severe performance penalty. Strategy: Fetch the source strings by words and compare the words until either a differing word is found or max_bytes is exhausted. In the former case, move through the words to find the differing byte and return plus or minus one, appropriately. In the latter case, return zero (equality). Tactics: 1) Do NOT try to fetch the words in a word aligned manner because, in my judgement, the performance degradation experienced due to non-aligned accesses does NOT outweigh the time and complexity added by the preamble that would be necessary to assure alignment. This is supported by the intuition that most source arrays (even more true of most big source arrays) will be word aligned to begin with. 2) Rather than decrementing max_bytes to zero, I calculate the address of the byte after the last byte of the source_1 array, and quit when the source byte pointer passes that. */ .globl _memcmp .globl __memcmp .leafproc _memcmp,__memcmp .align 2 _memcmp: #ifndef __PIC lda .Lrett,g14 #else lda .Lrett-(.+8)(ip),g14 #endif __memcmp: mov g14,g13 # preserve return address ldconst 0,g14 # conform to register conventions cmpibge 0,g2,Lequal_exit # quit if max_bytes <= 0 addo g0,g2,g2 # calculate byte addr of byte after last in src1 .Lwloop: cmpo g0,g2 ld (g0), g5 # fetch word of source_1 bge Lequal_exit # quit (equal) if max_bytes exhausted ld (g1), g3 # fetch word of source_2 addo 4,g0,g0 # post-increment source_1 byte ptr addo 4,g1,g1 # post-increment source_2 byte ptr cmpobe g5,g3,.Lwloop # branch if source words are equal ldconst 0xff,g4 # byte extraction mask subo 4,g0,g0 # back up src1 pointer .Lcloop: and g4,g5,g7 # extract and compare individual bytes and g4,g3,g6 cmpobne g7,g6,.diff # branch if they are different shlo 8,g4,g4 # position mask for next extraction addo 1,g0,g0 cmpobl g0,g2,.Lcloop # quit if max_bytes is exhausted Lequal_exit: mov 0,g0 bx (g13) .Lrett: ret .diff: bl .neg # arrays differ at current byte. /* return 1 or -1 appropriately */ mov 1,g0 bx (g13) .neg: subi 1,0,g0 .Lexit: bx (g13) /* end or memcmp */ picolibc-1.8.11/libc/machine/i960/memcmp_ca.S000066400000000000000000000153701513574234600204570ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "memcm_ca.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1992,1993 Intel Corp., all rights reserved */ /* procedure memcmp (optimized assembler version for the CA) result = memcmp (src1_addr, src2_addr, max_bytes) compare the byte array pointed to by src1_addr to the byte array pointed to by src2_addr. Return 0 iff the arrays are equal, -1 if src1_addr is lexicly less than src2_addr, and 1 if it is lexicly greater. Do not compare more than max_bytes bytes. Undefined behavior will occur if the end of either source array is in the last word of the program's allocated memory space. This is so because, in several cases, memcmp will fetch ahead one word. Disallowing the fetch ahead would impose a severe performance penalty. This program handles five cases: 1) both arguments start on a word boundary 2) neither are word aligned, but they are offset by the same amount 3) source1 is word aligned, source2 is not 4) source2 is word aligned, source1 is not 5) neither is word aligned, and they are offset by differing amounts At the time of this writing, only g0 thru g7 and g14 are available for use in this leafproc; other registers would have to be saved and restored. These nine registers are sufficient to implement the routine. The registers are used as follows: g0 original src1 ptr; extracted word; return result g1 src2 ptr; byt extraction mask g2 maximum number of bytes to compare g3 src2 word ptr Little endian g4 lsw of src1 g5 msw of src1 g6 src2 word g7 src1 word ptr Big endian g4 msw of src1 g5 lsw of src1 g6 src1 word ptr g7 src2 word g13 return address g14 shift count */ #if __i960_BIG_ENDIAN__ #define MSW g4 #define LSW g5 #define SRC1 g6 #define SRC2 g7 #else #define LSW g4 #define MSW g5 #define SRC2 g6 #define SRC1 g7 #endif .globl _memcmp .globl __memcmp .leafproc _memcmp, __memcmp .align 2 _memcmp: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __memcmp: Lrestart: #if __i960_BIG_ENDIAN__ subo 1,g0,SRC1 notand SRC1,3,SRC1 # extract word addr of start of src1 #else notand g0,3,SRC1 # extract word addr of start of src1 #endif lda (g14),g13 # preserve return address cmpibge.f 0,g2,Lequal_exit # return equality if number bytes 0 notand g1,3,g3 # extract word addr of start of src2 ld (SRC1),LSW # fetch word with at least first byte of src1 cmpo g3,g1 # check alignment of src2 ld 4(SRC1),MSW # fetch second word of src1 shlo 3,g0,g14 # compute shift count for src1 #if __i960_BIG_ENDIAN__ subo g14,0,g14 # adjust shift count for big endian. #endif ld (g3),SRC2 # fetch word with at least first byte of src2 eshro g14,g4,LSW # extract word of src1 lda 8(SRC1),SRC1 # advance src1 word addr bne.f Lsrc2_unaligned # branch if src2 is NOT word aligned mov LSW,g0 # at least src2 is word aligned lda 0xff,g1 Lwloop: # word comparing loop cmpo SRC2,g0 # compare src1 and src2 words lda 4(g3),g3 # pre-increment src2 addr mov MSW,LSW # move msw of src1 to lsw ld (SRC1),MSW # pre-fetch next msw of src1 subi 4,g2,g2 # decrement maximum byte count bne.f Lcloop # branch if src1 and src2 unequal cmpi 0,g2 ld (g3),SRC2 # pre-fetch next word of src2 eshro g14,g4,g0 # extract word of src1 lda 4(SRC1),SRC1 # post-increment src1 addr bl.t Lwloop # branch if max_bytes not reached yet b Lequal_exit # strings were equal up through max_bytes Lcloop_setup: # setup for coming from Lsrc2_unaligned mov LSW,g0 # restore extracted src1 word subo 4,g2,g2 # make up for later re-incrementing lda 0xff,g1 # byte extraction mask Lcloop: # character comparing loop #if __i960_BIG_ENDIAN__ rotate 24,g1,g1 # shift mask for next byte #endif and SRC2,g1,g3 # extract next char of src2 and g0,g1,LSW # extract next char of src1 cmpobne.f LSW,g3,.diff # check for equality #if ! __i960_BIG_ENDIAN__ shlo 8,g1,g1 # shift mask for next byte #endif subi 1,g2,g2 # decrement character counter b Lcloop # branch if null not reached Lequal_exit: # words are equal up thru null byte mov 0,g14 # conform to register conventions lda 0,g0 # return zero, indicating equality bx (g13) # return Lrett: ret .diff: addo 4,g2,g2 # to make up for extra decrement in loop lda 0,g14 bl Lless_than_exit Lgreater_than_exit: cmpibge.f 0,g2,Lequal_exit # branch if difference is beyond max_bytes mov 1,g0 bx (g13) # g0 = 1 (src1 > src2) Lless_than_exit: cmpibge.f 0,g2,Lequal_exit # branch if difference is beyond max_bytes subi 1,0,g0 bx (g13) # g0 = -1 (src1 < src2) Lsrc2_unaligned: notor g1,3,g14 # first step in computing new src1 ptr ld 4(g3),SRC1 # fetch second word of src2 shlo 3,g1,MSW # compute shift count for src2 #if __i960_BIG_ENDIAN__ subo MSW,0,MSW #endif eshro MSW,g6,SRC2 # extract word of src2 cmpo LSW,SRC2 # compare src1 and src2 words lda 4(g3),g1 # set new src2 ptr bne.f Lcloop_setup # first four bytes differ subo g14,g0,g0 # second (final) step in computing new src1 ptr addi g14,g2,g2 # compute new max_bytes too lda (g13),g14 # prepare return pointer for Lrestart b Lrestart # continue with both string fetches shifted picolibc-1.8.11/libc/machine/i960/memcpy.S000066400000000000000000000133641513574234600200310ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "memcpy.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure memmove (optimized assembler version for the 80960K series) procedure memcpy (optimized assembler version for the 80960K series) dest_addr = memmove (dest_addr, src_addr, len) dest_addr = memcpy (dest_addr, src_addr, len) copy len bytes pointed to by src_addr to the space pointed to by dest_addr. Return the original dest_addr. These routines will work even if the arrays overlap. The standard requires this of memmove, but memcpy is allowed to fail if overlap is present. Nevertheless, it is implemented the same as memmove because the overhead is trifling. Undefined behavior will occur if the end of the source array is in the last two words of the program's allocated memory space. This is so because the routine fetches ahead. Disallowing the fetch ahead would impose a severe performance penalty. Strategy: Fetch the source array by words and store them by words to the destination array, until there are fewer than three bytes left to copy. Then, using the last word of the source (the one that contains the remaining 0, 1, 2, or 3 bytes to be copied), store a byte at a time until Ldone. Tactics: 1) Do NOT try to fetch and store the words in a word aligned manner because, in my judgement, the performance degradation experienced due to non-aligned accesses does NOT outweigh the time and complexity added by the preamble and convoluted body that would be necessary to assure alignment. This is supported by the intuition that most source and destination arrays (even more true of most big source arrays) will be word aligned to begin with. 2) For non-overlapping arrays, rather than decrementing len to zero, I calculate the address of the byte after the last byte of the destination array, and quit when the destination byte pointer passes that. 3) For overlapping arrays where the source starts at a lower address than the destination the move is performed in reverse order. 4) Overlapping arrays where the source starts at a higher address are treated like non-overlapping case. Where the two arrays exactly coincide, the routine is short-circuited; no move is Ldone at all. This costs only one cycle. */ .globl _memcpy, _memmove .globl __memcpy, __memmove .leafproc _memmove, __memmove .leafproc _memcpy, __memcpy .align 2 _memmove: _memcpy: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __memmove: __memcpy: mov g14, g13 # preserve return address cmpibge 0,g2,Lexit # exit if number of bytes to move is <= zero. cmpo g0,g1 # does start of dest overlap end of src? addo g2,g1,g3 be Lexit # no move necessary if src and dest are same concmpo g3,g0 addo g2, g0, g6 bg Lbackwards # if overlap, then do move backwards ld (g1), g7 # fetch first word of source mov g0, g5 b Lwloop_b Lwloop_a: ld (g1), g7 # fetch ahead next word of source st g4, (g5) # store word to dest addo 4, g5, g5 # post-increment dest pointer Lwloop_b: # word copying loop addo 4, g1, g1 # pre-increment src pointer cmpo g3, g1 # is len <= 3 ? mov g7, g4 # keep a copy of the current word bge Lwloop_a # loop if more than 3 bytes to move cmpobe g6, g5, Lexit # quit if no more bytes to move Lcloop_a: # character copying loop (len < 3) stob g4, (g5) # store a byte shro 8, g4, g4 # position next byte for storing addo 1, g5, g5 cmpobne g6, g5, Lcloop_a # quit if no more bytes to move Lexit: mov 0, g14 bx (g13) # g0 = dest array address; g14 = 0 Lrett: ret Lwloop.a: subo 4, g6, g6 # pre-decrement dest pointer st g7, (g6) # store word to dest Lbackwards: # word copying loop subo 4, g3, g3 # pre-decrement src pointer cmpo g1, g3 # is len <= 3? ld (g3), g7 # fetch ahead next word of source ble Lwloop.a # loop if more than 3 bytes to move cmpobe g6, g0, Lexit # quit if no more bytes to move Lcloop.a: subo 1, g6, g6 rotate 8, g7, g7 # position byte for storing stob g7, (g6) # store byte cmpobne g6, g0, Lcloop.a # quit if no more bytes to move b Lexit /* end of memmove */ picolibc-1.8.11/libc/machine/i960/memcpy_ca.S000066400000000000000000000277311513574234600204770ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "memcp_ca.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1992,1993 Intel Corp., all rights reserved */ /* procedure memmove (optimized assembler version for the CA) procedure memcpy (optimized assembler version for the CA) dest_addr = memmove (dest_addr, src_addr, len) dest_addr = memcpy (dest_addr, src_addr, len) copy len bytes pointed to by src_addr to the space pointed to by dest_addr. Return the original dest_addr. Memcpy will fail if the source and destination string overlap (in particular, if the end of the source is overlapped by the beginning of the destination). The behavior is undefined. This is acceptable according to the draft C standard. Memmove will not fail if overlap exists. Undefined behavior will also occur if the end of the source string (i.e. the terminating null byte) is in the last word of the program's allocated memory space. This is so because, in several cases, the routine will fetch ahead one word. Disallowing the fetch ahead would impose a severe performance penalty. This program handles five cases: 1) both arguments start on a word boundary 2) neither are word aligned, but they are offset by the same amount 3) source is word aligned, destination is not 4) destination is word aligned, source is not 5) neither is word aligned, and they are offset by differing amounts At the time of this writing, only g0 thru g7 and g13 are available for use in this leafproc; other registers would have to be saved and restored. These nine registers, plus tricky use of g14 are sufficient to implement the routine. The registers are used as follows: g0 dest ptr; not modified, so that it may be returned g1 src ptr; shift count g2 len g3 src ptr (word aligned) g4 dest ptr (word aligned) g5 -4 for Lbackwards move Little endian g6 lsw of double word for extraction of 4 bytes g7 msw of double word for extraction of 4 bytes Big endian g6 msw of double word for extraction of 4 bytes g7 lsw of double word for extraction of 4 bytes g13 return address g14 byte extracted. */ #if __i960_BIG_ENDIAN__ #define MSW g6 #define LSW g7 #else #define LSW g6 #define MSW g7 #endif .globl _memmove, _memcpy .globl __memmove, __memcpy .leafproc _memmove, __memmove .leafproc _memcpy, __memcpy .align 2 _memcpy: _memmove: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __memcpy: __memmove: cmpibge.f 0,g2,Lquick_exit # Lexit if number of bytes to move is <= zero. cmpo g0,g1 # if dest starts earlier than src ... lda (g14),g13 # preserve return address addo g2,g1,g5 # compute addr of byte after last byte of src be.f Lexit_code # no move necessary if src and dest are same concmpo g5,g0 # ... or if dest starts after end of src ... notand g1,3,g3 # extract word addr of start of src bg.f Lbackwards # ... then drop thru, else do move backwards cmpo g3,g1 # check alignment of src ld (g3),LSW # fetch word containing at least first byte notand g0,3,g4 # extract word addr of start of dest lda 4(g3),g3 # advance src word addr bne.f Lcase_245 # branch if src is NOT word aligned Lcase_13: cmpo g0,g4 # check alignment of dest subo 4,g4,g4 # store is pre-incrementing; back up dest addr be.t Lcase_1 # branch if dest word aligned Lcase_3: # src is word aligned; dest is not addo 8,g4,g4 # move dest word ptr to first word boundary lda (g0),g1 # copy dest byte ptr mov LSW,MSW # make copy of first word of src lda 32,g14 # initialize shift count to zero (mod 32) Lcase_25: Lcase_3_cloop_at_start: # character copying loop for start of dest str cmpdeci 0,g2,g2 # is max_bytes exhausted? be.f Lexit_code # Lexit if max_bytes is exhausted #if __i960_BIG_ENDIAN__ rotate 8,MSW,MSW # move next byte into position for extraction subo 8,g14,g14 # augment the shift counter stob MSW,(g1) # store the byte in dest #else addo 8,g14,g14 # augment the shift counter stob MSW,(g1) # store the byte in dest shro 8,MSW,MSW # move next byte into position for extraction #endif lda 1(g1),g1 # post-increment dest ptr cmpobne.t g1,g4,Lcase_3_cloop_at_start # branch if reached word boundary ld (g3),MSW # fetch msw of operand for double shift Lcase_4: Lcase_3_wloop: cmpi g2,4 # less than four bytes to move? lda 4(g3),g3 # post-increment src word addr eshro g14,g6,g1 # extract 4 bytes of src bl.f Lcase_3_cloop # branch if < four bytes left to move mov MSW,LSW # move msw to lsw ld (g3),MSW # pre-fetch msw of operand for double shift subi 4,g2,g2 # decrease max_byte count by the 4 bytes moved st g1,(g4) # store 4 bytes to dest addo 4,g4,g4 # post-increment dest ptr b Lcase_3_wloop Lcase_1_wloop: # word copying loop subi 4,g2,g2 # decrease max_byte count by the 4 bytes moved ld (g3),LSW # pre-fetch next word of src addo 4,g3,g3 # post-increment src addr st g1,(g4) # store word in dest string Lcase_1: # src and dest are word aligned cmpi g2,4 # check for fewer than four bytes to move addo 4,g4,g4 # pre-increment dest addr lda (LSW),g1 # keep a copy of the src word bge.t Lcase_1_wloop # branch if at least four bytes to copy Lcase_3_cloop: cmpibe.f 0,g2,Lexit_code # Lexit if max_bytes is exhausted Lcase_1_cloop: #if __i960_BIG_ENDIAN__ rotate 8,g1,g1 # move next byte into position for extraction #endif subi 1,g2,g2 stob g1,(g4) # store the byte in dest cmpi 0,g2 lda 1(g4),g4 # post-increment dest byte addr #if ! __i960_BIG_ENDIAN__ shro 8,g1,g1 # move next byte into position for extraction #endif bne.t Lcase_1_cloop # Lexit if max_bytes is exhausted Lexit_code: mov 0,g14 # conform to register conventions bx (g13) # g0 = addr of dest; g14 = 0 Lrett: ret Lcase_245: cmpo g0,g4 # check alignment of dest ld (g3),MSW # pre-fetch second half and 3,g1,g1 # compute shift count shlo 3,g1,g14 #if __i960_BIG_ENDIAN__ subo g14,0,g14 # adjust shift count for big endian #endif be.t Lcase_4 # branch if dest is word aligned or g4,g1,g1 # is src earlier in word, later, or sync w/ dst cmpo g0,g1 # < indicates first word of dest has more bytes lda 4(g4),g4 # move dest word addr to first word boundary eshro g14,g6,g5 # extract four bytes lda (g0),g1 #if __i960_BIG_ENDIAN__ bge.f 1f #else bg.f 1f #endif mov MSW,LSW lda 4(g3),g3 # move src word addr to second word boundary 1: mov g5,MSW b Lcase_25 Lbackwards: notand g5,3,MSW # extract word addr of byte after end of src cmpo MSW,g5 # check alignment of end of src subo 4,MSW,g3 # retreat src word addr addo g2,g0,g1 # compute addr of byte after end of dest notand g1,3,g4 # extract word addr of start of dest bne.f Lcase.245 # branch if src is NOT word aligned Lcase.13: cmpo g1,g4 # check alignment of dest ld (g3),MSW # fetch last word of src subo 4,g3,g3 # retreat src word addr be.t Lcase.1 # branch if dest word aligned Lcase.3: # src is word aligned; dest is not mov MSW,LSW # make copy of first word of src lda 32,g14 # initialize shift count to zero (mod 32) Lcase.25: Lcase.3_cloop_at_start: # character copying loop for start of dest str cmpdeci 0,g2,g2 # is max.bytes exhausted? be.f Lexit_code # Lexit if max_bytes is exhausted #if ! __i960_BIG_ENDIAN__ rotate 8,LSW,LSW # move next byte into position for storing #endif lda -1(g1),g1 # pre-decrement dest ptr cmpo g1,g4 # have we reached word boundary in dest yet? stob LSW,(g1) # store the byte in dest #if __i960_BIG_ENDIAN__ shro 8,LSW,LSW # move next byte into position for storing addo 8,g14,g14 # augment the shift counter #else subo 8,g14,g14 # augment the shift counter #endif bne.t Lcase.3_cloop_at_start # branch if reached word boundary? ld (g3),LSW # fetch lsw of operand for double shift #if __i960_BIG_ENDIAN__ cmpobne 0,g14,Lcase.3_wloop Lcase.3_wloop2: cmpi g2,4 # less than four bytes to move? lda -4(g3),g3 # post-decrement src word addr mov MSW,g1 # extract 4 bytes of src lda (LSW),MSW # move lsw to msw subo 4,g4,g4 # pre-decrement dest ptr bl.f Lcase.3_cloop # branch if < four bytes left to move ld (g3),LSW # pre-fetch lsw of operand for double shift subi 4,g2,g2 # decrease max.byte count by the 4 bytes moved st g1,(g4) # store 4 bytes to dest b Lcase.3_wloop2 #endif Lcase.4: Lcase.3_wloop: cmpi g2,4 # less than four bytes to move? lda -4(g3),g3 # post-decrement src word addr eshro g14,g6,g1 # extract 4 bytes of src lda (LSW),MSW # move lsw to msw subo 4,g4,g4 # pre-decrement dest ptr bl.f Lcase.3_cloop # branch if < four bytes left to move ld (g3),LSW # pre-fetch lsw of operand for double shift subi 4,g2,g2 # decrease max.byte count by the 4 bytes moved st g1,(g4) # store 4 bytes to dest b Lcase.3_wloop Lcase.1_wloop: # word copying loop subi 4,g2,g2 # decrease max.byte count by the 4 bytes moved ld (g3),MSW # pre-fetch next word of src subo 4,g3,g3 # post-decrement src addr st g1,(g4) # store word in dest string Lcase.1: # src and dest are word aligned cmpi g2,4 # check for fewer than four bytes to move subo 4,g4,g4 # pre-decrement dest addr lda (MSW),g1 # keep a copy of the src word bge.t Lcase.1_wloop # branch if at least four bytes to copy Lcase.3_cloop: cmpibe.f 0,g2,Lexit_code # Lexit if max_bytes is exhausted #if ! __i960_BIG_ENDIAN__ rotate 8,g1,g1 # move next byte into position for storing #endif lda 4(g4),g4 # pre-decremented dest addr 4 too much Lcase.1_cloop: subi 1,g4,g4 # pre-decrement dest byte addr cmpi g4,g0 # has dest ptr reached beginning of dest? stob g1,(g4) # store the byte in dest #if __i960_BIG_ENDIAN__ shro 8,g1,g1 # move next byte into position for storing #else rotate 8,g1,g1 # move next byte into position for storing #endif bne.t Lcase.1_cloop # Lexit if move is completed b Lexit_code Lcase.245: cmpo g1,g4 # check alignment of dest ld (MSW),MSW # pre-fetch word with at least last byte and 3,g5,g5 # compute shift count ld (g3),LSW # pre-fetch second to last word shlo 3,g5,g14 #if __i960_BIG_ENDIAN__ subo g14,0,g14 # adjust shift count for big endian #endif be.t Lcase.4 # branch if dest is word aligned or g4,g5,g5 # is src earlier in word, later, or sync w/ dst cmpo g1,g5 # < indicates last word of dest has less bytes eshro g14,g6,g5 # extract four bytes bl.t 1f mov LSW,MSW #if ! __i960_BIG_ENDIAN__ be.t 1f #endif subo 4,g3,g3 # move src word addr to second word boundary 1: mov g5,LSW b Lcase.25 Lquick_exit: mov g14,g13 b Lexit_code /* end of memmove */ picolibc-1.8.11/libc/machine/i960/memset.S000066400000000000000000000076301513574234600200300ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "memset.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1989,1993 Intel Corp., all rights reserved */ /* procedure memset (optimized assembler version: 80960K series, 80960CA) dest_addr = memset (dest_addr, char, len) Fill len bytes pointed to by dest_addr with the value of char. Return the original address of dest_addr. This program avoids performing unaligned accesses. It stores from zero to seven bytes, and then stores aligned longwords, and then stores from zero to seven bytes, as necessary to store len bytes starting at dest_addr. At the time of this writing, only g0 thru g7 and g13 are available for use in this leafproc; other registers would have to be saved and restored. These nine registers, plus tricky use of g14 are sufficient to implement the routine. */ .globl _memset .globl __memset .leafproc _memset, __memset .align 2 _memset: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __memset: cmpo 7,g2 # are there fewer than seven characters to move? lda (g14),g13 # save return address notand g0,7,g3 # test for non-aligned dest_ptr lda 0,g14 # conform to register conventions shlo 24,g1,g4 # prepare word of char lda (g0),g6 # preserve dest_ptr for return shro 8,g4,g5 bge.f Lcloop_setup cmpo g3,g0 # is dest longword aligned lda 7(g3),g3 # bump dest_ptr to next longword boundary or g4,g5,g4 be.t Lwloop_setup Lbgn_cloop: cmpo g6,g3 # Have we reached longword boundary? stob g1,(g6) # store one byte of char subo 1,g2,g2 # decrement len lda 1(g6),g6 # increment dest_ptr bne.t Lbgn_cloop # loop if more bytes to store before longword cmpobge.f 7,g2,Lcloop Lwloop_setup: shro 16,g4,g5 or g4,g5,g4 mov g4,g5 # now have a longword of char Lwloop: cmpo 15,g2 # Do we have to store more longwords? stl g4,(g6) # Store longword of char subo 8,g2,g2 # Decrement len lda 8(g6),g6 # Increment dest_ptr bl.t Lwloop # loop if more longwords to store Lcloop_setup: cmpobge.t 0,g2,Lexit Lcloop: cmpo 1,g2 # Is len exhausted? stob g1,(g6) # Store byte subo 1,g2,g2 # Decrement len lda 1(g6),g6 # Increment dest_ptr bne.t Lcloop # loop if more bytes to store Lexit: bx (g13) Lrett: ret /* end of memset */ picolibc-1.8.11/libc/machine/i960/setjmp.S000066400000000000000000000075441513574234600200440ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ /******************************************************************************/ /* */ /* setjmp(), longjmp() */ /* */ /******************************************************************************/ #include .file "setjmp.as" .text /* .link_pix */ .align 4 .globl _setjmp _setjmp: flushreg andnot 0xf,pfp,g1 /* get pfp, mask out return status bits */ st g1, 0x58(g0) /* save fp of caller*/ /* save globals not killed by the calling convention */ stq g8, 0x40(g0) /* save g8-g11*/ st g12, 0x50(g0) /* save g12*/ st g14, 0x54(g0) /* save g14*/ /* save previous frame local registers */ ldq (g1), g4 /* get previous frame pfp, sp, rip, r3 */ stq g4, (g0) /* save pfp, sp, rip, r3 */ ldq 0x10(g1), g4 /* get previous frame r4-r7 */ stq g4, 0x10(g0) /* save r4-r7 */ ldq 0x20(g1), g4 /* get previous frame r8-r11 */ stq g4, 0x20(g0) /* save r8-r11 */ ldq 0x30(g1), g4 /* get previous frame r12-r15 */ stq g4, 0x30(g0) /* save r12-r15 */ mov 0, g0 /* return 0 */ ret /* * fake a return to the place that called the corresponding _setjmp */ .align 4 .globl _longjmp _longjmp: call 0f /* ensure there is at least one stack frame */ 0: flushreg /* do this before swapping stack */ ld 0x58(g0), pfp /* get fp of caller of setjmp */ /* restore local registers * the following code modifies the frame of the function which originally * called setjmp. */ ldq (g0), g4 /* get pfp, sp, rip, r3 */ stq g4, (pfp) /* restore pfp, sp, rip, r3 */ ldq 0x10(g0), g4 /* get r4-r7 */ stq g4, 0x10(pfp) /* restore r4-r7 */ ldq 0x20(g0), g4 /* get r8-r11 */ stq g4, 0x20(pfp) /* restore r8-r11 */ ldq 0x30(g0), g4 /* get r12-r15 */ stq g4, 0x30(pfp) /* restore r12-r15 */ /* restore global registers */ ldq 0x40(g0), g8 /* get old g8-g11 values */ ld 0x50(g0), g12 /* get old g12 value */ ld 0x54(g0), g14 /* get old g14 value */ mov g1, g0 /* get return value */ cmpo g0, 0 /* make sure it is not zero */ bne 0f mov 1, g0 /* return 1 by default */ 0: ret /* return to caller of _setjmp */ picolibc-1.8.11/libc/machine/i960/strchr.S000066400000000000000000000104431513574234600200370ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "strchr.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure strchr (optimized assembler version for the 80960K series) src_addr = strchr (src_addr, char) return a pointer to the first byte that contains the indicated byte in the source string. Return null if the byte is not found. Undefined behavior will occur if the end of the source string (i.e. the terminating null byte) is in the last two words of the program's allocated memory space. This is so because strchr fetches ahead. Disallowing the fetch ahead would impose a severe performance penalty. Strategy: Fetch the source string by words and scanbyte the words for the char until either a word with the byte is found or the null byte is encountered. In the former case, move through the word to find the matching byte and return its memory address. In the latter case, return zero (null). Tactics: 1) Do NOT try to fetch the words in a word aligned manner because, in my judgement, the performance degradation experienced due to non-aligned accesses does NOT outweigh the time and complexity added by the preamble that would be necessary to assure alignment. This is supported by the intuition that most source arrays (even more true of most big source arrays) will be word aligned to begin with. */ .globl _strchr .globl __strchr .leafproc _strchr, __strchr .align 2 _strchr: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __strchr: ld (g0),g4 # fetch first word lda 0xff,g7 # byte extraction mask and g1,g7,g1 # make char an 8-bit ordinal shlo 8,g1,g2 # broadcast the char to four bytes or g1,g2,g2 shlo 16,g2,g5 or g2,g5,g3 mov g14,g13 # preserve return address addo 4,g0,g0 # post-increment src pointer mov 0,g14 # conform to register linkage standard Lsearch_for_word_with_char_or_null: mov g4,g5 # copy word scanbyte g3,g5 # check for byte with char ld (g0),g4 # fetch next word of src bo Lsearch_for_char # branch if char found scanbyte 0,g5 # check for null byte addo 4,g0,g0 # post-increment src pointer bno Lsearch_for_word_with_char_or_null # branch if not null Lnot_found: mov 0,g0 # char not found. Return null Lexit_code: bx (g13) # g0 = addr of char in src (or null); g14 = 0 Lrett: ret Lsearch_for_char: subo 5,g0,g0 # back up the byte pointer Lsearch_for_char.a: and g5,g7,g6 # extract byte cmpo g1,g6 # is it char? addo 1,g0,g0 # bump src byte ptr shro 8,g5,g5 # shift word to position next byte be Lexit_code cmpobne 0,g6,Lsearch_for_char.a # quit if null comes before char b Lnot_found /* end of strchr */ picolibc-1.8.11/libc/machine/i960/strchr_ca.S000066400000000000000000000122111513574234600204750ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "strch_ca.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure strchr (optimized assembler version for the CA) src_addr = strchr (src_addr, char) return a pointer to the first byte that contains the indicated byte in the source string. Return null if the byte is not found. Undefined behavior will occur if the end of the source string (i.e. the terminating null byte) is in the last two words of the program's allocated memory space. This is so because, in several cases, strchr will fetch ahead. Disallowing the fetch ahead would impose a severe performance penalty. This program handles two cases: 1) the argument starts on a word boundary 2) the argument doesn't start on a word boundary At the time of this writing, only g0 thru g7 and g13 are available for use in this leafproc; other registers would have to be saved and restored. These nine registers, plus tricky use of g14 are sufficient to implement the routine. The registers are used as follows: g0 src ptr; upon return it is a pointer to the matching byte, or null g1 char to seek g2 mask to avoid unimportant bytes in first word g3 char to seek, broadcast to all four bytes g4 word of the source string g5 copy of the word g6 extracted character g7 byte extraction mask g13 return address g14 */ .globl _strchr .globl __strchr .leafproc _strchr, __strchr .align 2 _strchr: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __strchr: lda 0xff,g7 # byte extraction mask and g1,g7,g1 # make char an 8-bit ordinal shlo 8,g1,g2 # broadcast the char to four bytes or g1,g2,g2 shlo 16,g2,g4 cmpo g1,g7 # is char being sought 0xff? or g4,g2,g3 lda (g14),g13 # preserve return address notand g0,3,g5 # extract word addr of start of src lda 0,g14 # conform to register linkage standard and g0,3,g6 # extract byte offset of src ld (g5),g4 # fetch word containing at least first byte shlo 3,g6,g6 # get shift count for making mask for first word lda 4(g5),g0 # post-increment src word pointer subi 1,0,g5 # mask initially all ones #if __i960_BIG_ENDIAN__ shro g6,g5,g5 # get mask for bytes needed from first word #else shlo g6,g5,g5 # get mask for bytes needed from first word #endif notor g4,g5,g4 # set unneeded bytes to all ones be.f Lsearch_for_0xff # branch if seeking 0xff Lsearch_for_word_with_char_or_null: scanbyte g3,g4 # check for byte with char lda (g4),g5 # copy word ld (g0),g4 # fetch next word of src bo.f Lsearch_for_char # branch if null found scanbyte 0,g5 # check for null byte lda 4(g0),g0 # post-increment src word pointer bno.t Lsearch_for_word_with_char_or_null # branch if not null Lnot_found: mov 0,g0 # char not found. Return null Lexit_code: bx (g13) # g0 = addr of char in src (or null); g14 = 0 Lrett: ret Lsearch_for_char: subo 5,g0,g0 # back up the byte pointer Lsearch_for_char.a: #if __i960_BIG_ENDIAN__ rotate 8,g5,g5 # shift word to position next byte #endif and g5,g7,g6 # extract byte cmpo g1,g6 # is it char? lda 1(g0),g0 # bump src byte ptr #if ! __i960_BIG_ENDIAN__ shro 8,g5,g5 # shift word to position next byte #endif be.f Lexit_code cmpobne.t 0,g6,Lsearch_for_char.a # quit if null comes before char b Lnot_found Lsearch_for_0xff: lda 0xf0f0f0f0,g2 # make first comparison mask for char=-1 case. or g5,g2,g2 and g4,g2,g4 # make unimportant bytes of first word 0x0f b Lsearch_for_word_with_char_or_null /* end of strchr */ picolibc-1.8.11/libc/machine/i960/strcmp.S000066400000000000000000000105031513574234600200370ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "strcmp.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure strcmp (optimized assembler version for the 80960K Series) result = strcmp (src1_addr, src2_addr) compare the null terminated string pointed to by src1_addr to the string pointed to by src2_addr. Return 0 iff the strings are equal, -1 if src1_addr is lexicographically less than src2_addr, and 1 if it is lexicographically greater. Undefined behavior will occur if the end of either source string (i.e. the terminating null byte) is in the last two words of the program's allocated memory space. This is so because strcmp fetches ahead. Disallowing the fetch ahead would impose a severe performance penalty. Strategy: Fetch the source strings by words and compare the words until either differing words are found or the null byte is encountered. In either case, move through the word until either the differing byte if found, in which case return -1 or 1 appropriately; or the null byte is encountered, in which case, return zero (equality). Tactics: 1) Do NOT try to fetch the words in a word aligned manner because, in my judgement, the performance degradation experienced due to non-aligned accesses does NOT outweigh the time and complexity added by the preamble and convoluted body that would be necessary to assure alignment. This is supported by the intuition that many source strings will be word aligned to begin with. */ .globl _strcmp .globl __strcmp .leafproc _strcmp,__strcmp .align 2 _strcmp: #ifndef __PIC lda .Lrett,g14 #else lda .Lrett-(.+8)(ip),g14 #endif __strcmp: ld (g0), g5 # fetch first word of source_1 mov g14,g7 # preserve return address ldconst 0,g14 # conform to register conventions ldconst 0xff,g4 # byte extraction mask .Lwloop: addo 4,g0,g0 # post-increment source_1 byte ptr ld (g1), g3 # fetch word of source_2 scanbyte 0,g5 # does word have a null byte? mov g5,g2 # save a copy of the source_1 word be .Lcloop # branch if null byte encountered cmpo g2,g3 # are the source words the same? addo 4,g1,g1 # post-increment source_2 byte ptr ld (g0), g5 # fetch ahead next word of source_1 be .Lwloop # fall thru if words are unequal .Lcloop: and g4,g2,g5 # extract and compare individual bytes and g4,g3,g6 cmpobne g5,g6,.diff # if they differ, go return 1 or -1 cmpo 0,g6 # they are the same. Are they null? shlo 8,g4,g4 # position mask for next extraction bne .Lcloop # loop if null not encountered mov 0,g0 # return equality bx (g7) .Lrett: ret .diff: bl .neg mov 1,g0 bx (g7) .neg: subi 1,0,g0 .Lexit: bx (g7) picolibc-1.8.11/libc/machine/i960/strcmp_ca.S000066400000000000000000000175371513574234600205200ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "strcm_ca.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure strcmp (optimized assembler version for the CA) result = strcmp (src1_addr, src2_addr) compare the null terminated string pointed to by src1_addr to the string space pointed to by src2_addr. Return 0 iff the strings are equal, -1 if src1_addr is lexicly less than src2_addr, and 1 if it is lexicly greater. Undefined behavior will occur if the end of either source string (i.e. the terminating null byte) is in the last word of the program's allocated memory space. This is so because, in several cases, strcmp will fetch ahead one word. Disallowing the fetch ahead would impose a severe performance penalty. This program handles five cases: 1) both arguments start on a word boundary 2) neither are word aligned, but they are offset by the same amount 3) source1 is word aligned, source2 is not 4) source2 is word aligned, source1 is not 5) neither is word aligned, and they are offset by differing amounts At the time of this writing, only g0 thru g7 and g14 are available for use in this leafproc; other registers would have to be saved and restored. These nine registers are sufficient to implement the routine. The registers are used as follows: g0 original src1 ptr; return result g1 src2 ptr; 0xff -- byte extraction mask g2 src1 word ptr g3 src2 word ptr Little endian: g4 lsw of src1 g5 msw of src1 g6 src2 word g7 extracted src1 Big endian: g4 msw of src1 g5 lsw of src1 g6 extracted src1 g7 src2 word g13 return address g14 shift count */ #if __i960_BIG_ENDIAN__ #define MSW g4 #define LSW g5 #define SRC1 g6 #define SRC2 g7 #else #define LSW g4 #define MSW g5 #define SRC2 g6 #define SRC1 g7 #endif .globl _strcmp .globl __strcmp .leafproc _strcmp, __strcmp .align 2 _strcmp: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __strcmp: Lrestart: notand g0,3,g2 # extract word addr of start of src1 lda (g14),g13 # preserve return address #if __i960_BIG_ENDIAN__ cmpo g0,g2 # check alignment of src1 #endif ld (g2),LSW # fetch word with at least first byte of src1 notand g1,3,g3 # extract word addr of start of src2 ld 4(g2),MSW # fetch second word of src1 #if __i960_BIG_ENDIAN__ bne Lsrc1_unaligned # branch if src1 is unaligned cmpo g3,g1 # check alignment of src2 ld (g3),SRC2 # fetch word with at least first byte of src2 mov LSW,SRC1 # extract word of src1 lda 8(g2),g2 # advance src1 word addr bne.f Lsrc2_unaligned # branch if src2 is NOT word aligned /* src2 is word aligned */ Lwloop2: # word comparing loop cmpo SRC2,SRC1 # compare src1 and src2 words lda 0xff000000,g1 # byte extraction mask mov MSW,LSW # move msw of src1 to lsw ld (g2),MSW # pre-fetch next msw of src1 addo 4,g2,g2 # post-increment src1 addr lda 4(g3),g3 # pre-increment src2 addr bne.f Lcloop # branch if src1 and src2 unequal scanbyte 0,SRC1 # check for null byte in src1 word ld (g3),SRC2 # pre-fetch next word of src2 mov LSW,SRC1 # extract word of src1 lda 0,g0 # prepare to return zero, indicating equality bno.t Lwloop2 # branch if null byte not encountered /* words were equal and contained null byte */ mov 0,g14 # conform to register conventions bx (g13) # return Lsrc1_unaligned: #endif cmpo g3,g1 # check alignment of src2 ld (g3),SRC2 # fetch word with at least first byte of src2 shlo 3,g0,g14 # compute shift count for src1 #if __i960_BIG_ENDIAN__ subo g14,0,g14 # 32 - shift count for big endian. #endif eshro g14,g4,SRC1 # extract word of src1 lda 8(g2),g2 # advance src1 word addr bne.f Lsrc2_unaligned # branch if src2 is NOT word aligned /* at least src2 is word aligned */ Lwloop: # word comparing loop cmpo SRC2,SRC1 # compare src1 and src2 words #if __i960_BIG_ENDIAN__ lda 0xff000000,g1 # byte extraction mask #else lda 0xff,g1 # byte extraction mask #endif mov MSW,LSW # move msw of src1 to lsw ld (g2),MSW # pre-fetch next msw of src1 addo 4,g2,g2 # post-increment src1 addr lda 4(g3),g3 # pre-increment src2 addr bne.f Lcloop # branch if src1 and src2 unequal scanbyte 0,SRC1 # check for null byte in src1 word ld (g3),SRC2 # pre-fetch next word of src2 eshro g14,g4,SRC1 # extract word of src1 lda 0,g0 # prepare to return zero, indicating equality bno.t Lwloop # branch if null byte not encountered /* words were equal and contained null byte */ mov 0,g14 # conform to register conventions bx (g13) # return Lcloop_setup: # setup for coming from Lsrc2_unaligned mov LSW,SRC1 # restore extracted src1 word #if __i960_BIG_ENDIAN__ lda 0xff000000,g1 # byte extraction mask #else lda 0xff,g1 # byte extraction mask #endif Lcloop: # character comparing loop and SRC2,g1,g3 # extract next char of src2 and SRC1,g1,g0 # extract next char of src1 cmpobne.f g0,g3,.diff # check for equality cmpo 0,g0 # check for null byte #if __i960_BIG_ENDIAN__ shro 8,g1,g1 # shift mask for next byte #else shlo 8,g1,g1 # shift mask for next byte #endif bne.t Lcloop # branch if null not reached /* words are equal up thru null byte */ mov 0,g14 bx (g13) # g0 = 0 (src1 == src2) Lrett: ret .diff: mov 0,g14 bl Lless_than_exit Lgreater_than_exit: mov 1,g0 bx (g13) # g0 = 1 (src1 > src2) Lless_than_exit: subi 1,0,g0 bx (g13) # g0 = -1 (src1 < src2) Lsrc2_unaligned: mov SRC1,LSW # retain src1 extracted word ld 4(g3),SRC1 # fetch second word of src2 shlo 3,g1,MSW # compute shift count for src2 #if __i960_BIG_ENDIAN__ subo MSW,0,MSW # 32 - shift count for big endian. #endif eshro MSW,g6,SRC2 # extract word of src2 cmpo LSW,SRC2 # compare src1 and src2 words notor g1,3,MSW # first step in computing new src1 ptr lda 4(g3),g1 # set new src2 ptr bne.f Lcloop_setup # first four bytes differ scanbyte 0,LSW # check for null byte lda (g13),g14 # prepare return pointer for Lrestart subo MSW,g0,g0 # second (final) step in computing new src1 ptr bno.t Lrestart # if null byte not encountered, continue /* with both string fetches shifted such that */ /* src2 is now word aligned. */ mov 0,g14 # conform to register conventions. lda 0,g0 # return indicator of equality. bx (g13) picolibc-1.8.11/libc/machine/i960/strcpy.S000066400000000000000000000145431513574234600200630ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "strcpy.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure strcpy (optimized assembler version for the 80960K series) procedure strcat (optimized assembler version for the 80960K series) dest_addr = strcpy (dest_addr, src_addr) copy the null terminated string pointed to by src_addr to the string space pointed to by dest_addr. Return the original dest_addr. This routine will fail if the source and destination string overlap (in particular, if the end of the source is overlapped by the beginning of the destination). The behavior is undefined. This is acceptable according to the draft C standard. Undefined behavior will also occur if the end of the source string (i.e. the terminating null byte) is in the last two words of the program's allocated memory space. This is so because strcpy fetches ahead. Disallowing the fetch ahead would impose a severe performance penalty. Strategy: Fetch the source string and store the destination string by words until the null byte is encountered. When the word with the null byte is reached, store it by bytes up through the null byte only. Tactics: 1) Do NOT try to fetch and store the words in a word aligned manner because, in my judgement, the performance degradation experienced due to non-aligned accesses does NOT outweigh the time and complexity added by the preamble and convoluted body that would be necessary to assure alignment. This is supported by the intuition that most source and destination strings will be word aligned to begin with. procedure strcat dest_addr = strcat (dest_addr, src_addr) Appends the string pointed to by src_addr to the string pointed to by dest_addr. The first character of the source string is copied to the location initially occupied by the trailing null byte of the destination string. Thereafter, characters are copied from the source to the destination up thru the null byte that trails the source string. See the strcpy routine, above, for its caveats, as they apply here too. Strategy: Skip to the end (null byte) of the destination string, and then drop into the strcpy code. Tactics: Skipping to the null byte is Ldone by reading the destination string in long-words and scanbyte'ing them, then examining the bytes of the word that contains the null byte, until the address of the null byte is known. Then we drop into the strcpy routine. It is probable (approx. three out of four times) that the destination string as strcpy sees it will NOT be word aligned (i.e. that the null byte won't be the last byte of a word). But it is not worth the complication to that routine to force word aligned memory accesses to be gaurenteed. */ .globl _strcpy, _strcat .globl __strcpy, __strcat .leafproc _strcpy,__strcpy .leafproc _strcat,__strcat .align 2 _strcat: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __strcat: mov g14,g13 # preserve return address ldl (g0),g4 # fetch first two words addo 8,g0,g2 # post-increment src word pointer lda 0xff,g3 # byte extraction mask Lsearch_for_word_with_null_byte: scanbyte 0,g4 # check for null byte mov g5,g7 # copy second word bo.f Lsearch_for_null # branch if null found scanbyte 0,g7 # check for null byte ldl (g2),g4 # fetch next pair of word of src addo 8,g2,g2 # post-increment src word pointer bno Lsearch_for_word_with_null_byte # branch if null not found yet subo 4,g2,g2 # back up the byte pointer mov g7,g4 # move word with null to search word Lsearch_for_null: subo 9,g2,g5 # back up the byte pointer Lsearch_for_null.a: and g4,g3,g6 # extract byte cmpo 0,g6 # is it null? addo 1,g5,g5 # bump src byte ptr shro 8,g4,g4 # shift word to position next byte bne Lsearch_for_null.a b Lend_of_dest_found _strcpy: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __strcpy: mov g0, g5 Lend_of_dest_found: ld (g1), g2 # fetch first word of source mov g14,g6 # preserve return address lda 0xff, g3 # byte extraction mask = 0xff; Lwloop: # word copying loop addo 4, g1, g1 # post-increment source ptr scanbyte 0, g2 # does source word contain null byte? mov g2, g4 # save a copy of the source word be Lcloop # branch if null present ld (g1), g2 # pre-fetch next word of source st g4, (g5) # store current word addo 4, g5, g5 # post-increment dest ptr b Lwloop Lcloop: # character copying loop and g3, g4, g14 # extract next char shro 8, g4, g4 # position word for next byte extraction cmpo 0, g14 # is it null? stob g14, (g5) # store the byte addo 1, g5, g5 # post-increment dest ptr bne Lcloop # quit if null encountered bx (g6) # g0 = dest string address; g14 = 0 Lrett: ret picolibc-1.8.11/libc/machine/i960/strcpy_ca.S000066400000000000000000000233621513574234600205250ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "strcp_ca.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure strcpy (optimized assembler version for the CA) dest_addr = strcpy (dest_addr, src_addr) copy the null terminated string pointed to by src_addr to the string space pointed to by dest_addr. Return the original dest_addr. This routine will fail if the source and destination string overlap (in particular, if the end of the source is overlapped by the beginning of the destination). The behavior is undefined. This is acceptable according to the draft C standard. Undefined behavior will also occur if the end of the source string (i.e. the terminating null byte) is in the last word of the program's allocated memory space. This is so because, in several cases, strcpy will fetch ahead one word. Disallowing the fetch ahead would impose a severe performance penalty. This program handles five cases: 1) both arguments start on a word boundary 2) neither are word aligned, but they are offset by the same amount 3) source is word aligned, destination is not 4) destination is word aligned, source is not 5) neither is word aligned, and they are offset by differing amounts At the time of this writing, only g0 thru g7 and g13 are available for use in this leafproc; other registers would have to be saved and restored. These nine registers, plus tricky use of g14 are sufficient to implement the routine. The registers are used as follows: g0 original dest ptr; not modified, so that it may be returned. g1 src ptr; shift count g2 dest ptr; 4 bytes of src g3 src ptr (word aligned) g4 dest ptr (word aligned) g5 0xff -- byte extraction mask g6 lsw of double word for extraction of 4 bytes (little endian) msw of double word for extraction of 4 bytes (big endian) g7 msw of double word for extraction of 4 bytes (little endian) lsw of double word for extraction of 4 bytes (big endian) g13 return address g14 byte extracted. When reaches null byte, which is zero, we will be in conformance with register conventions, and can return to the caller with a clear conscience. procedure strcat dest_addr = strcat (dest_addr, src_addr) Appends the string pointed to by src_addr to the string pointed to by dest_addr. The first character of the source string is copied to the location initially occupied by the trailing null byte of the destination string. Thereafter, characters are copied from the source to the destination up thru the null byte that trails the source string. */ #if __i960_BIG_ENDIAN__ #define MSW g6 #define LSW g7 #else #define LSW g6 #define MSW g7 #endif .globl _strcpy, _strcat .globl __strcpy, __strcat .leafproc _strcpy, __strcpy .leafproc _strcat, __strcat .align 2 _strcat: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __strcat: notand g0,3,g4 # extract word addr of start of dest lda (g14),g13 # preserve return address and g0,3,LSW # extract byte offset of dest ld (g4),MSW # fetch word containing at least first byte shlo 3,LSW,g14 # get shift count for making mask for first word subi 1,0,LSW # mask initially all ones #if __i960_BIG_ENDIAN__ shro g14,LSW,LSW # get mask for bytes needed from first word lda 0xff000000,g5 # byte extraction mask #else shlo g14,LSW,LSW # get mask for bytes needed from first word lda 0xff,g5 # byte extraction mask #endif notor MSW,LSW,MSW # set unneeded bytes to all ones Lsearch_for_word_with_null: scanbyte 0,MSW # check for null byte lda 4(g4),g4 # post-increment dest word pointer mov MSW,LSW # keep a copy of current word ld (g4),MSW # fetch next word of dest bno.t Lsearch_for_word_with_null # branch if null not found yet and g5,LSW,g14 # extract byte cmpo 0,g14 # branch if null is first byte of word subo 4,g4,g4 # move dest word ptr back to word with null notand g1,3,g3 # extract word addr of start of src lda (g4),g2 # set dest byte ptr to 1st byte of word w/ null be.f Lcase_14 Lsearch_for_null: #if __i960_BIG_ENDIAN__ shro 8,g5,g5 # move mask down to next byte #else shlo 8,g5,g5 # move mask up to next byte #endif lda 1(g2),g2 # move dest byte ptr to next byte and g5,LSW,g14 # extract byte cmpobne.t 0,g14,Lsearch_for_null # branch if null is not yet found lda 0xff,g5 # byte extraction mask b Lcase_235.a _strcpy: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __strcpy: notand g0,3,g4 # extract word addr of start of dest lda (g14),g13 # preserve return address cmpo g0,g4 # check alignment of dest lda 0xff,g5 # load mask for byte extraction notand g1,3,g3 # extract word addr of start of src bne.f Lcase_235 # branch if dest is NOT word aligned Lcase_14: cmpo g3,g1 # check alignment of src ld (g3),LSW # fetch word containing at least first byte shlo 3,g1,g1 # compute shift count lda 4(g3),g3 # advance src word addr #if __i960_BIG_ENDIAN__ lda 0xff,g5 # byte extraction mask #endif bne.f Lcase_4 # branch if src is NOT word aligned Lcase_1: # src and dest are word aligned subo 4,g4,g4 # store is pre-incrementing; back up dest addr Lcase_1_wloop: # word copying loop scanbyte 0,LSW # check for null byte in src word lda (LSW),g2 # keep a copy of the src word addo 4,g4,g4 # pre-increment dest addr ld (g3),LSW # pre-fetch next word of src addo 4,g3,g3 # post-increment src addr bo.f Lcase_1_cloop # branch if word contains null byte st g2,(g4) # store word in dest string b Lcase_1_wloop Lcase_3_cloop: Lcase_1_cloop: # character copying loop #if __i960_BIG_ENDIAN__ rotate 8,g2,g2 # move next byte into position for extraction and g5,g2,g14 # extract next char #else and g5,g2,g14 # extract next char shro 8,g2,g2 # move next byte into position for extraction #endif cmpo 0,g14 # check for null byte stob g14,(g4) # store the byte in dest lda 1(g4),g4 # post-increment dest byte addr bne.t Lcase_1_cloop # branch if null not reached Lexit_code: bx (g13) # g0 = addr of dest; g14 = 0 Lrett: ret Lcase_3: # src is word aligned; dest is not addo 4,g4,g4 # move dest word ptr to first word boundary mov LSW,MSW # make copy of first word of src lda 0,g1 # initialize shift count to zero Lcase_25: Lcase_3_cloop_at_start: # character copying loop for start of dest str #if __i960_BIG_ENDIAN__ rotate 8,MSW,MSW # move next byte into position for extraction and g5,MSW,g14 # extract next char #else and g5,MSW,g14 # extract next char shro 8,MSW,MSW # move next byte into position for extraction #endif cmpo 0,g14 # check for null byte stob g14,(g2) # store the byte in dest lda 1(g2),g2 # post-increment dest ptr be.f Lexit_code # branch if null byte reached cmpo g2,g4 # have we reached word boundary in dest? lda 8(g1),g1 # augment the shift counter bne.t Lcase_3_cloop_at_start Lcase_4: ld (g3),MSW # fetch msw of operand for double shift #if __i960_BIG_ENDIAN__ subo g1,0,g1 # Adjust shift count for big endian. #endif Lcase_3_wloop: eshro g1,g6,g2 # extract 4 bytes of src lda 4(g3),g3 # post-increment src word addr scanbyte 0,g2 # check for null byte lda (MSW),LSW # move msw to lsw ld (g3),MSW # pre-fetch msw of operand for double shift bo.f Lcase_3_cloop # branch if word contains null byte st g2,(g4) # store 4 bytes to dest addo 4,g4,g4 # post-increment dest ptr b Lcase_3_wloop Lcase_235: lda (g0),g2 # copy dest ptr Lcase_235.a: cmpo g3,g1 # check alignment of src ld (g3),LSW # fetch word containing at least first byte and 3,g1,g14 # compute shift count lda 4(g3),g3 # advance src word addr shlo 3,g14,g1 be.t Lcase_3 # branch if dest is word aligned or g4,g14,g14 # is src earlier in word, later, or sync w/ dst ld (g3),MSW # pre-fetch second half cmpo g2,g14 # < indicates first word of dest has more bytes lda 4(g4),g4 # move dest word addr to first word boundary /* than first word of source. */ #if __i960_BIG_ENDIAN__ subo g1,0,g14 # Adjust shift count for big endian. eshro g14,g6,g14 # extract four bytes bge.f 1f #else eshro g1,g6,g14 # extract four bytes bg.f 1f #endif mov MSW,LSW lda 4(g3),g3 # move src word addr to second word boundary 1: mov g14,MSW b Lcase_25 /* end of strcpy */ picolibc-1.8.11/libc/machine/i960/strcspn.S000066400000000000000000000062021513574234600202240ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "strcspn.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1989,1993 Intel Corp., all rights reserved */ /* procedure strcspn (optimized assembler version: 80960K series, 80960CA) len = strcspn (string, charset) Return the number of characters in the maximum leading segment of string which consists solely of characters NOT from charset. At the time of this writing, only g0 thru g7 and g13 are available for use in this leafproc; other registers would have to be saved and restored. These nine registers, plus tricky use of g14 are sufficient to implement the routine. */ .globl _strcspn .globl __strcspn .leafproc _strcspn, __strcspn .align 2 _strcspn: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __strcspn: mov g14,g13 # save return address lda (g0),g3 # copy string pointer mov 0,g14 # conform to register conventions Lnext_char: ldob (g3),g7 # fetch next character of string addo 1,g1,g2 # g2 will be the charset ptr ldob (g1),g6 # fetch first character of charset cmpobe.f 0,g7,Lexit # quit if at end of string Lscan_set: cmpo g6,g7 # is charset char same as string char? ldob (g2),g5 # fetch next charset char addo 1,g2,g2 # bump charset ptr be.f Lexit cmpo g6,0 # is charset exhausted? lda (g5),g6 bne.t Lscan_set # check next character of charset addo 1,g3,g3 # check next character of string b Lnext_char Lexit: subo g0,g3,g0 # compute string length bx (g13) Lrett: ret /* end of strcspn */ picolibc-1.8.11/libc/machine/i960/strdup.S000066400000000000000000000047071513574234600200610ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "strdup.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1989,1993 Intel Corp., all rights reserved */ /* procedure strdup (optimized assembler version: 80960K series, 80960CA) dest_addr = strdup (src_addr) Allocate memory and copy thereto the string pointed to by src_addr. Return the address of the copy, or null if unable to perform the operation. */ .text .align 2 .globl _strdup _strdup: mov g0,r3 # Keep a copy of the original string addr callj _strlen # Determine how much to allocate addo 1,g0,g0 # Add one byte for the null byte at end callj _malloc # Allocate the storage cmpo 0,g0 mov r3,g1 # Original string addr is now src for copy bne.t _strcpy # Jump if allocation was successful ret # Return the null ptr otherwise /* end of strdup */ picolibc-1.8.11/libc/machine/i960/strlen.S000066400000000000000000000077451513574234600200540ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "strlen.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure strlen (optimized assembler version for the 80960K series) src_addr = strlen (src_addr) return the number of bytes that precede the null byte in the string pointed to by src_addr. Undefined behavior will occur if the end of the source string (i.e. the terminating null byte) is in the last four words of the program's allocated memory space. This is so because strlen fetches ahead several words. Disallowing the fetch ahead would impose a severe performance penalty. Strategy: Fetch the source array by long-words and scanbyte the words for the null byte until found. Examine the word in which the null byte is found, to determine its actual position, and return the length. Tactics: 1) Do NOT try to fetch the words in a word aligned manner because, in my judgement, the performance degradation experienced due to non-aligned accesses does NOT outweigh the time and complexity added by the preamble that would be necessary to assure alignment. This is supported by the intuition that many source strings will be word aligned to begin with. */ .globl _strlen .globl __strlen .leafproc _strlen, __strlen .align 2 _strlen: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __strlen: mov g14,g13 # preserve return address ldl (g0),g4 # fetch first two words addo 8,g0,g2 # post-increment src word pointer lda 0xff,g3 # byte extraction mask Lsearch_for_word_with_null_byte: scanbyte 0,g4 # check for null byte mov g5,g7 # copy second word bo.f Lsearch_for_null # branch if null found scanbyte 0,g7 # check for null byte ldl (g2),g4 # fetch next pair of word of src addo 8,g2,g2 # post-increment src word pointer bno Lsearch_for_word_with_null_byte # branch if null not found yet subo 4,g2,g2 # back up the byte pointer mov g7,g4 # move word with null to search word Lsearch_for_null: subo 9,g2,g2 # back up the byte pointer Lsearch_for_null.a: and g4,g3,g14 # extract byte cmpo 0,g14 # is it null? addo 1,g2,g2 # bump src byte ptr shro 8,g4,g4 # shift word to position next byte bne Lsearch_for_null.a Lexit_code: subo g0,g2,g0 # calculate string length bx (g13) # g0 = addr of src; g14 = 0 Lrett: ret /* end of strlen */ picolibc-1.8.11/libc/machine/i960/strlen_ca.S000066400000000000000000000117511513574234600205070ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "strle_ca.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure strlen (optimized assembler version for the CA) src_addr = strlen (src_addr) return the number of bytes that precede the null byte in the string pointed to by src_addr. Undefined behavior will occur if the end of the source string (i.e. the terminating null byte) is in the last four words of the program's allocated memory space. This is so because, in several cases, strlen will fetch ahead several words. Disallowing the fetch ahead would impose a severe performance penalty. This program handles two cases: 1) the argument starts on a word boundary 2) the argument doesn't start on a word boundary At the time of this writing, only g0 thru g7 and g13 are available for use in this leafproc; other registers would have to be saved and restored. These nine registers, plus tricky use of g14 are sufficient to implement the routine. The registers are used as follows: g0 original src ptr; upon return it is the byte count. g1 g2 src ptr g3 mask g4 even word of the source string g5 odd word of the source string g6 copy of even word, shift count g7 copy of odd word g13 return address g14 byte extracted. */ .globl _strlen .globl __strlen .leafproc _strlen, __strlen .align 2 _strlen: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __strlen: notand g0,3,g2 # extract word addr of start of src lda (g14),g13 # preserve return address and g0,3,g7 # extract byte offset of src ld (g2),g5 # fetch word containing at least first byte shlo 3,g7,g7 # get shift count for making mask for first word lda 4(g2),g2 # post-increment src word pointer subi 1,0,g3 # mask initially all ones chkbit 2,g2 # are we on an even word boundary or an odd one? #if __i960_BIG_ENDIAN__ shro g7,g3,g3 # get mask for bytes needed from first word notor g5,g3,g7 # set unneeded bytes to all ones lda 0xff000000,g3 # byte extraction mask #else shlo g7,g3,g3 # get mask for bytes needed from first word notor g5,g3,g7 # set unneeded bytes to all ones lda 0xff,g3 # byte extraction mask #endif bno.f Lodd_word # branch if first word is odd mov g7,g4 # move first word to copy thereof ld (g2),g5 # load odd word lda 4(g2),g2 # post-increment src word pointer Leven_word: scanbyte 0,g4 # check for null byte movl g4,g6 # copy both words Lodd_word: # trickery! if we branch here, following branch /* instruction will fall thru, as we want, */ /* effecting the load of g4 and g5 only. */ ldl (g2),g4 # fetch next pair of word of src bo.f Lsearch_for_null # branch if null found scanbyte 0,g7 # check for null byte lda 8(g2),g2 # post-increment src word pointer bno.t Leven_word # branch if null not found yet subo 4,g2,g2 # back up the byte pointer lda (g7),g6 # move odd word to search word Lsearch_for_null: subo 9,g2,g2 # back up the byte pointer Lsearch_for_null.a: and g6,g3,g14 # extract byte cmpo 0,g14 # is it null? lda 1(g2),g2 # bump src byte ptr #if __i960_BIG_ENDIAN__ shlo 8,g6,g6 # shift word to position next byte #else shro 8,g6,g6 # shift word to position next byte #endif bne.t Lsearch_for_null.a Lexit_code: subo g0,g2,g0 # calculate string length bx (g13) # g0 = addr of src; g14 = 0 Lrett: ret /* end of strlen */ picolibc-1.8.11/libc/machine/i960/strncat.S000066400000000000000000000132541513574234600202130ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "strncat.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure strncat (optimized assembler version for the 80960K Series) dest_addr = strncat (dest_addr, src_addr, max_bytes) append the null terminated string pointed to by src_addr to the null terminated string pointed to by dest_addr. Return the original dest_addr. If the source string is longer than max_bytes, then append only max_bytes bytes, and tack on a null byte on the end. This routine will fail if the source and destination string overlap (in particular, if the end of the source is overlapped by the beginning of the destination). The behavior is undefined. This is acceptable according to the draft C standard. Undefined behavior will also occur if the end of the source string (i.e. the terminating null byte) is in the last two words of the program's allocated memory space. This is so because strncat fetches ahead. Disallowing the fetch ahead would impose a severe performance penalty. Strategy: First, skip to the null byte in the destination string. Then fetch the source string by words and store them by words to the destination string, until there are fewer than three bytes left to copy. Then, using the last word of the source (the one that contains the remaining 0, 1, 2, or 3 bytes to be copied), store a byte at a time until Ldone. If, before exhausting the max_byte count, the null byte is encountered in the source string, then just copy up thru the null byte. Tactics: 1) Do NOT try to fetch and store the words in a word aligned manner because, in my judgement, the performance degradation experienced due to non-aligned accesses does NOT outweigh the time and complexity added by the preamble and convoluted body that would be necessary to assure alignment. */ .globl _strncat .globl __strncat .leafproc _strncat,__strncat .align 2 _strncat: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __strncat: mov g14,g6 cmpibge 0, g2, Lno_operation # Lexit early if max_bytes <= 0 mov g0, g5 Lskip_word_loop: ld (g5), g7 # fetch word of dest string addo 4, g5, g5 # post-increment dest ptr scanbyte 0, g7 # does it contain null byte? bno Lskip_word_loop # if not, loop subo 5, g5, g5 # adjust dest ptr lda 0xff, g3 # byte extraction mask = 0xff; Lskip_byte_loop: and g7, g3, g14 # extract byte of last word of dest string cmpo 0, g14 # is it null? addo 1, g5, g5 # adjust dest ptr shro 8, g7, g7 # position next byte for extraction bne Lskip_byte_loop # loop if null not found yet ld (g1), g7 # fetch first word of source string Lwloop: # word copying loop cmpo 4, g2 # max_bytes < 4 ? addo 4, g1, g1 # post-increment source ptr bge Lcloop.a # branch if less than 4 bytes to move scanbyte 0, g7 # is null byte reached yet? mov g7, g4 # keep a copy of the source word be Lcloop # branch if null byte reached ld (g1), g7 # pre-fetch next word of source subo 4, g2, g2 # reduce max_byte counter st g4, (g5) # store current word addo 4, g5, g5 # post-increment destination ptr b Lwloop Lcloop.b: addo 1, g5, g5 # post-increment destination ptr shro 8, g7, g7 # position next byte for extraction Lcloop: # character copying loop (max_byte > 3) and g3, g7, g4 # extract character cmpo 0, g4 # is it null? stob g4, (g5) # store it bne Lcloop.b # loop if null not encountered yet bx (g6) # g0 = dest string address; g14 = 0 Lrett: ret Lcloop.c: addo 1, g5, g5 # post-increment destination ptr shro 8, g7, g7 # position next byte for extraction Lcloop.a: # character copying loop (max_byte <= 3) cmpdeco 0,g2,g2 # max_byte == 0? and g3, g7, g4 # extract character be Ldone # store null and Lexit if max_byte exhausted cmpo 0, g4 # is it null? stob g4, (g5) # store it bne Lcloop.c # loop if null not encountered yet Ldone: stob g14, (g5) # store trailing null bx (g6) # g0 = dest string address; g14 = 0 Lno_operation: mov 0, g14 # conform to register conventions bx (g6) /* end of strncat */ picolibc-1.8.11/libc/machine/i960/strncat_ca.S000066400000000000000000000243161513574234600206570ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "sncat_ca.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure strncat (optimized assembler version for the CA) dest_addr = strncat (dest_addr, src_addr, max_bytes) append the null terminated string pointed to by src_addr to the null terminated string pointed to by dest_addr. Return the original dest_addr. If the source string is longer than max_bytes, then append only max_bytes bytes, and tack on a null byte on the end This routine will fail if the source and destination string overlap (in particular, if the end of the source is overlapped by the beginning of the destination). The behavior is undefined. This is acceptable according to the draft C standard. Undefined behavior will also occur if the end of the source string (i.e. the terminating null byte) is in the last word of the program's allocated memory space. This is so because, in several cases, strncat will fetch ahead one word. Disallowing the fetch ahead would impose a severe performance penalty. This program handles five cases: 1) both arguments start on a word boundary 2) neither are word aligned, but they are offset by the same amount 3) source is word aligned, destination is not 4) destination is word aligned, source is not 5) neither is word aligned, and they are offset by differing amounts At the time of this writing, only g0 thru g7 and g13 are available for use in this leafproc; other registers would have to be saved and restored. These nine registers, plus tricky use of g14 are sufficient to implement the routine. The registers are used as follows: g0 original dest ptr; not modified, so that it may be returned. g1 src ptr; shift count g2 max_bytes g3 src ptr (word aligned) g4 dest ptr (word aligned) g5 0xff -- byte extraction mask Little endian: g6 lsw of double word for extraction of 4 bytes g7 msw of double word for extraction of 4 bytes Big endian: g6 msw of double word for extraction of 4 bytes g7 lsw of double word for extraction of 4 bytes g13 return address g14 byte extracted. */ #if __i960_BIG_ENDIAN__ #define MSW g6 #define LSW g7 #else #define LSW g6 #define MSW g7 #endif .globl _strncat .globl __strncat .leafproc _strncat, __strncat .align 2 _strncat: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __strncat: notand g0,3,g4 # extract word addr of start of dest lda (g14),g13 # preserve return address cmpibge.f 0,g2,Lexit_code # Lexit if number of bytes to move is <= zero. and g0,3,LSW # extract byte offset of dest ld (g4),MSW # fetch word containing at least first byte shlo 3,LSW,g14 # get shift count for making mask for first word subi 1,0,LSW # mask initially all ones #if __i960_BIG_ENDIAN__ shro g14,LSW,LSW # get mask for bytes needed from first word #else shlo g14,LSW,LSW # get mask for bytes needed from first word #endif notor MSW,LSW,MSW # set unneeded bytes to all ones lda 0xff,g5 # byte extraction mask Lsearch_for_word_with_null: scanbyte 0,MSW # check for null byte lda 4(g4),g4 # post-increment dest word pointer mov MSW,LSW # keep a copy of current word ld (g4),MSW # fetch next word of dest bno.t Lsearch_for_word_with_null # branch if null not found yet #if __i960_BIG_ENDIAN__ shro 24,LSW,g14 # extract byte #else and g5,LSW,g14 # extract byte #endif cmpo 0,g14 # branch if null is first byte of word subo 4,g4,g4 # move dest word ptr to word with null notand g1,3,g3 # extract word addr of start of src bne.t Lsearch_for_null Lcase_14: cmpo g1,g3 # check alignment of source ld (g3),LSW # fetch first word of source shlo 3,g1,g14 # compute shift count lda 4(g3),g3 # post-increment src addr bne.f Lcase_4 # branch if source is unaligned Lcase_1: Lcase_1_wloop: # word copying loop cmpi g2,4 # check for fewer than four bytes to move lda (LSW),g1 # keep a copy of the src word bl.f Lcase_1_cloop # branch if fewer than four bytes to copy scanbyte 0,g1 # check for null byte in src word ld (g3),LSW # pre-fetch next word of src addo 4,g3,g3 # post-increment src addr bo.f Lcase_1_cloop # branch if word contains null byte subi 4,g2,g2 # decrease max_byte count by the 4 bytes moved st g1,(g4) # store word in dest string addo 4,g4,g4 # post-increment dest addr b Lcase_1_wloop Lcase_3_cloop: Lcase_1_cloop: # character copying loop (max_bytes <= 3) cmpdeci 0,g2,g2 # is max_bytes exhausted? #if __i960_BIG_ENDIAN__ rotate 8,g1,g1 # move next byte into position for extraction #endif and g5,g1,g14 # extract next char be.f Lstore_null # if max_bytes is exhausted, store null and quit cmpo 0,g14 # check for null byte stob g14,(g4) # store the byte in dest #if ! __i960_BIG_ENDIAN__ shro 8,g1,g1 # move next byte into position for extraction #endif lda 1(g4),g4 # post-increment dest byte addr bne.t Lcase_1_cloop # branch if null not reached bx (g13) # Lexit (g14 == 0) Lstore_null: mov 0,g14 # store null, and set g14 to zero stob g14,(g4) bx (g13) Lsearch_for_null: #if __i960_BIG_ENDIAN__ shlo 8,LSW,LSW # check next byte shro 24,LSW,g14 #else shlo 8,g5,g5 # move mask up to next byte and g5,LSW,g14 # extract byte #endif lda 1(g4),g4 # move dest byte ptr to next byte cmpobne.t 0,g14,Lsearch_for_null # branch if null is not yet found Lcase_235: cmpo g1,g3 # check alignment of src ld (g3),LSW # pre-fetch word with start of src and 3,g1,g1 # compute shift count lda 0xff,g5 # load mask for byte extraction shlo 3,g1,g14 lda 4(g3),g3 # post-increment src word counter be.t Lcase_3 # branch if src is word aligned and g4,3,MSW # extract byte offset for dest string cmpo MSW,g1 # < indicates first word of dest has more bytes /* than first word of source. */ ld (g3),MSW # fetch second word of src #if __i960_BIG_ENDIAN__ subo g14,0,g14 # adjust shift count for big endian #endif eshro g14,g6,g5 # extract four bytes #if __i960_BIG_ENDIAN__ bge.f 1f #else bg.f 1f #endif mov MSW,LSW lda 4(g3),g3 # move src word addr to second word boundary 1: mov g5,MSW lda 0xff,g5 b Lcase_25 Lcase_3: # src is word aligned; dest is not mov LSW,MSW # make copy of first word of src lda 32,g14 # initialize shift count to zero (mod 32) Lcase_25: Lcase_3_cloop_at_start: # character copying loop for start of dest str cmpdeci 0,g2,g2 # is max_bytes exhausted? #if __i960_BIG_ENDIAN__ shro 24,MSW,g5 # extract next char #else and g5,MSW,g5 # extract next char #endif be.f Lstore_null # Lexit if max_bytes is exhausted cmpo 0,g5 # check for null byte stob g5,(g4) # store the byte in dest addo 1,g4,g4 # post-increment dest ptr lda 0xff,g5 # re-initialize byte extraction mask notand g4,3,g1 # extract word address be.t Lexit_code # Lexit if null byte reached cmpo g1,g4 # have we reached word boundary in dest yet? #if __i960_BIG_ENDIAN__ lda -8(g14),g14 # augment the shift counter rotate 8,MSW,MSW # move next byte into position for extraction #else lda 8(g14),g14 # augment the shift counter shro 8,MSW,MSW # move next byte into position for extraction #endif bne.t Lcase_3_cloop_at_start # branch if reached word boundary? #if __i960_BIG_ENDIAN__ cmpo 0,g14 ld (g3),MSW # fetch msw of operand for double shift bne Lcase_3_wloop # branch if src is still unaligned. Lcase_3_wloop2: cmpi g2,4 # less than four bytes to move? mov LSW,g1 # extract 4 bytes of src lda 4(g3),g3 # post-increment src word addr bl.f Lcase_3_cloop # branch if < four bytes left to move scanbyte 0,g1 # check for null byte mov MSW,LSW # move msw to lsw ld (g3),MSW # pre-fetch msw of operand for double shift bo.f Lcase_3_cloop # branch if word contains null byte subi 4,g2,g2 # decrease max_byte count by the 4 bytes moved st g1,(g4) # store 4 bytes to dest addo 4,g4,g4 # post-increment dest ptr b Lcase_3_wloop2 Lcase_4: subo g14,0,g14 # adjust shift count for big endian #else Lcase_4: #endif ld (g3),MSW # fetch msw of operand for double shift Lcase_3_wloop: cmpi g2,4 # less than four bytes to move? eshro g14,g6,g1 # extract 4 bytes of src lda 4(g3),g3 # post-increment src word addr bl.f Lcase_3_cloop # branch if < four bytes left to move scanbyte 0,g1 # check for null byte mov MSW,LSW # move msw to lsw ld (g3),MSW # pre-fetch msw of operand for double shift bo.f Lcase_3_cloop # branch if word contains null byte subi 4,g2,g2 # decrease max_byte count by the 4 bytes moved st g1,(g4) # store 4 bytes to dest addo 4,g4,g4 # post-increment dest ptr b Lcase_3_wloop Lexit_code: mov 0,g14 # conform to register conventions bx (g13) # g0 = addr of dest; g14 = 0 Lrett: ret /* end of strncat */ picolibc-1.8.11/libc/machine/i960/strncmp.S000066400000000000000000000107711513574234600202240ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "strncmp.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure strncmp (optimized assembler version for the 80960K Series) result = strncmp (src1_addr, src2_addr, max_bytes) compare the null terminated string pointed to by src1_addr to the string pointed to by src2_addr. Return 0 iff the strings are equal, -1 if src1_addr is lexicographically less than src2_addr, and 1 if it is lexicographically greater. Do not compare more than max_bytes bytes. Undefined behavior will occur if the end of either source string (i.e. the terminating null byte) is in the last two words of the program's allocated memory space. This is so because strncmp will fetch ahead. Disallowing the fetch ahead would impose a severe performance penalty. Strategy: Fetch and compare the strings by words and go to a character comparison loop as soon as a pair of words differ. If the words are equal up through either the exhaustion of max_bytes or the presence of the null byte, return 0 (equality). Otherwise, the character comparator will return -1 or 1 for inequality, or 0 if the differing byte is after the null byte or after the exhaustion of max_bytes. Tactics: 1) Do NOT try to fetch the words in a word aligned manner because, in my judgement, the performance degradation experienced due to non-aligned accesses does NOT outweigh the time and complexity added by the preamble and convoluted body that would be necessary to assure alignment. */ .globl _strncmp .globl __strncmp .leafproc _strncmp,__strncmp .align 2 _strncmp: #ifndef __PIC lda .Lrett,g14 #else lda .Lrett-(.+8)(ip),g14 #endif __strncmp: mov g14,g13 ldconst 0,g14 cmpibge 0,g2,Lequal_exit # Lexit early if max_bytes <= 0 addo g2,g0,g2 .Lwloop: cmpo g0,g2 # are max_bytes exhausted? ld (g0), g5 # fetch word of source_1 bge Lequal_exit # Lexit (equality) if max_bytes exhausted ld (g1), g3 # fetch word of source_2 addo 4,g0,g0 # post-increment source_1 ptr scanbyte 0,g5 # is a null byte present? addo 4,g1,g1 # post-increment source_1 ptr be .Lcloop.a # perform char comparator if null byte found cmpobe g5,g3,.Lwloop # perform char comparator if words are unequal .Lcloop.a: subo 4,g0,g0 # adjust max_byte counter ldconst 0xff,g4 # byte extraction mask .Lcloop: and g4,g5,g7 # compare individual bytes and g4,g3,g6 cmpobne g7,g6,.diff # if different, return -1 or 1 cmpo 0,g6 # they are equal. are they null? shlo 8,g4,g4 # position mask to extract next byte be Lequal_exit # if they are null, Lexit (equality) addo 1,g0,g0 # is max_bytes exhausted? cmpobl g0,g2,.Lcloop # if not, loop. if so, Lexit (equality) Lequal_exit: mov 0,g0 bx (g13) .Lrett: ret .diff: bl .neg mov 1,g0 bx (g13) .neg: subi 1,0,g0 .Lexit: bx (g13) /* end of strncmp */ picolibc-1.8.11/libc/machine/i960/strncmp_ca.S000066400000000000000000000205671513574234600206730ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "sncmp_ca.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure strncmp (optimized assembler version for the CA) result = strncmp (src1_addr, src2_addr, max_bytes) compare the null terminated string pointed to by src1_addr to the string space pointed to by src2_addr. Return 0 iff the strings are equal, -1 if src1_addr is lexicly less than src2_addr, and 1 if it is lexicly greater. Do not compare more than max_bytes bytes. Undefined behavior will occur if the end of either source string (i.e. the terminating null byte) is in the last word of the program's allocated memory space. This is so because, in several cases, strncmp will fetch ahead one word. Disallowing the fetch ahead would impose a severe performance penalty. This program handles five cases: 1) both arguments start on a word boundary 2) neither are word aligned, but they are offset by the same amount 3) source1 is word aligned, source2 is not 4) source2 is word aligned, source1 is not 5) neither is word aligned, and they are offset by differing amounts At the time of this writing, only g0 thru g7 and g14 are available for use in this leafproc; other registers would have to be saved and restored. These nine registers are sufficient to implement the routine. The registers are used as follows: g0 original src1 ptr; extracted word; return result g1 src2 ptr; 0xff -- byte extraction mask g2 maximum number of bytes to compare g3 src2 word ptr Little endian: g4 lsw of src1 g5 msw of src1 g6 src2 word g7 src1 word ptr Big endian: g4 msw of src1 g5 lsw of src1 g6 src1 word ptr g7 src2 word g13 return address g14 shift count */ #if __i960_BIG_ENDIAN__ #define MSW g4 #define LSW g5 #define SRC1 g6 #define SRC2 g7 #else #define LSW g4 #define MSW g5 #define SRC2 g6 #define SRC1 g7 #endif .globl _strncmp .globl __strncmp .leafproc _strncmp, __strncmp .align 2 _strncmp: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __strncmp: Lrestart: notand g0,3,SRC1 # extract word addr of start of src1 lda (g14),g13 # preserve return address cmpibge.f 0,g2,Lequal_exit # return equality if number of bytes to /* compare is none. */ #if __i960_BIG_ENDIAN__ cmpo g0,SRC1 # check alignment of src1 #endif ld (SRC1),LSW # fetch word with at least first byte of src1 notand g1,3,g3 # extract word addr of start of src2 ld 4(SRC1),MSW # fetch second word of src1 #if __i960_BIG_ENDIAN__ bne Lsrc1_unaligned # branch if src1 is unaligned cmpo g3,g1 # check alignment of src2 ld (g3),SRC2 # fetch word with at least first byte of src2 shlo 3,g0,g14 # compute shift count for src1 subo g14,0,g14 # adjust shift count for big endian lda 8(SRC1),SRC1 # advance src1 word addr bne.f Lsrc2_unaligned # branch if src2 is NOT word aligned /* src2 is word aligned */ mov LSW,g0 Lwloop2: # word comparing loop cmpo SRC2,g0 # compare src1 and src2 words lda 0xff000000,g1 # byte extraction mask mov MSW,LSW # move msw of src1 to lsw ld (SRC1),MSW # pre-fetch next msw of src1 addo 4,SRC1,SRC1 # post-increment src1 addr lda 4(g3),g3 # pre-increment src2 addr bne.f Lcloop # branch if src1 and src2 unequal scanbyte 0,g0 # check for null byte in src1 word ld (g3),SRC2 # pre-fetch next word of src2 mov LSW,g0 # extract word of src1 subi 4,g2,g2 # decrement maximum byte count bo.f Lequal_exit # branch if null byte encountered cmpibl.t 0,g2,Lwloop2 # branch if max_bytes not reached yet b Lequal_exit # strings were equal up through max_bytes Lsrc1_unaligned: #endif cmpo g3,g1 # check alignment of src2 ld (g3),SRC2 # fetch word with at least first byte of src2 shlo 3,g0,g14 # compute shift count for src1 #if __i960_BIG_ENDIAN__ subo g14,0,g14 # adjust shift count for big endian #endif eshro g14,g4,LSW # extract word of src1 lda 8(SRC1),SRC1 # advance src1 word addr bne.f Lsrc2_unaligned # branch if src2 is NOT word aligned /* at least src2 is word aligned */ mov LSW,g0 Lwloop: # word comparing loop cmpo SRC2,g0 # compare src1 and src2 words #if __i960_BIG_ENDIAN__ lda 0xff000000,g1 # byte extraction mask #else lda 0xff,g1 # byte extraction mask #endif mov MSW,LSW # move msw of src1 to lsw ld (SRC1),MSW # pre-fetch next msw of src1 addo 4,SRC1,SRC1 # post-increment src1 addr lda 4(g3),g3 # pre-increment src2 addr bne.f Lcloop # branch if src1 and src2 unequal scanbyte 0,g0 # check for null byte in src1 word ld (g3),SRC2 # pre-fetch next word of src2 eshro g14,g4,g0 # extract word of src1 subi 4,g2,g2 # decrement maximum byte count bo.f Lequal_exit # branch if null byte encountered cmpibl.t 0,g2,Lwloop # branch if max_bytes not reached yet b Lequal_exit # strings were equal up through max_bytes Lcloop_setup: # setup for coming from Lsrc2_unaligned mov LSW,g0 # restore extracted src1 word #if __i960_BIG_ENDIAN__ lda 0xff000000,g1 # byte extraction mask #else lda 0xff,g1 # byte extraction mask #endif Lcloop: # character comparing loop and SRC2,g1,g3 # extract next char of src2 and g0,g1,LSW # extract next char of src1 cmpobne.f LSW,g3,.diff # check for equality cmpo 0,LSW # check for null byte #if __i960_BIG_ENDIAN__ shro 8,g1,g1 # shift mask for next byte #else shlo 8,g1,g1 # shift mask for next byte #endif subi 1,g2,g2 # decrement character counter bne.t Lcloop # branch if null not reached /* words are equal up thru null byte */ Lequal_exit: mov 0,g14 # conform to register conventions lda 0,g0 # return zero, indicating equality bx (g13) # return Lrett: ret .diff: mov 0,g14 bl Lless_than_exit Lgreater_than_exit: cmpibge.f 0,g2,Lequal_exit # branch if difference is beyond max_bytes mov 1,g0 bx (g13) # g0 = 1 (src1 > src2) Lless_than_exit: cmpibge.f 0,g2,Lequal_exit # branch if difference is beyond max_bytes subi 1,0,g0 bx (g13) # g0 = -1 (src1 < src2) Lsrc2_unaligned: notor g1,3,g14 # first step in computing new src1 ptr ld 4(g3),SRC1 # fetch second word of src2 shlo 3,g1,MSW # compute shift count for src2 #if __i960_BIG_ENDIAN__ subo MSW,0,MSW # adjust shift count for big endian #endif eshro MSW,g6,SRC2 # extract word of src2 cmpo LSW,SRC2 # compare src1 and src2 words lda 4(g3),g1 # set new src2 ptr bne.f Lcloop_setup # first four bytes differ scanbyte 0,LSW # check for null byte subo g14,g0,g0 # second (final) step in computing new src1 ptr addi g14,g2,g2 # compute new max_bytes too lda (g13),g14 # prepare return pointer for Lrestart bno.t Lrestart # if null byte not encountered, continue /* with both string fetches shifted such that*/ /* src2 is now word aligned.*/ mov 0,g14 # conform to register conventions. lda 0,g0 # return indicator of equality. bx (g13) picolibc-1.8.11/libc/machine/i960/strncpy.S000066400000000000000000000131021513574234600202270ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "strncpy.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure strncpy (optimized assembler version for the 80960K Series) dest_addr = strncpy (dest_addr, src_addr, max_bytes) copy the null terminated string pointed to by src_addr to the string pointed to by dest_addr. Return the original dest_addr. If the source string is shorter than max_bytes, then null-pad the destination string. If it is longer than max_bytes, the copy stops at max_bytes bytes (and no terminating null appears in the destination string). This routine will fail if the source and destination string overlap (in particular, if the end of the source is overlapped by the beginning of the destination). The behavior is undefined. This is acceptable according to the draft C standard. Undefined behavior will also occur if the end of the source string (i.e. the terminating null byte) is in the last two words of the program's allocated memory space. This is so because strncpy fetches ahead. Disallowing the fetch ahead would impose a severe performance penalty. Strategy: Fetch and store the strings by words and go to a character move loop as soon as a null byte is encountered. If max_bytes is exhausted first, then terminate after moving only max_bytes (with the last 0, 1, 2, or 3 bytes moved as single bytes, not as a word). Otherwise, the character move loop moves the last bytes or the source string, and then null-pads the destination string until max_bytes is exhausted. Tactics: 1) Do NOT try to fetch the words in a word aligned manner because, in my judgement, the performance degradation experienced due to non-aligned accesses does NOT outweigh the time and complexity added by the preamble and convoluted body that would be necessary to assure alignment. 2) When the null byte is encountered in a source word, null out the higher-numbered bytes in that word, store the word in the destination, and go to the word null-padder, which may eventually go to the byte null-padder. */ .globl _strncpy .globl __strncpy .leafproc _strncpy,__strncpy .align 2 _strncpy: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __strncpy: mov g14, g13 cmpibge 0,g2,Lexit # quit early if max_bytes <= 0 ld (g1), g7 # fetch the first word of the source mov g0, g5 lda 0xff, g3 # byte extraction mask addo g1, g2, g6 addo g2, g5, g2 Lwloop: # word copying loop addo 4, g1, g1 # post-increment source ptr cmpo g6, g1 # max_bytes < 4 ? mov g7, g4 # keep a copy of source word bl Lcloop.a # if less than four bytes to go, go to char loop scanbyte 0, g4 # null byte found? ld (g1), g7 # pre-fetch next word of the source be Lcloop.c # go to char loop if null encountered st g4, (g5) # store current word addo 4, g5, g5 # post-increment destination ptr b Lwloop Lcloop.a: # character copying loop (max_bytes < 3) and g3, g4, g14 # extract byte Lcloop.b: cmpo g2, g5 # max_bytes <= 0 ? shro 8, g4, g4 # position word to extract next byte be Lexit # exit if max_bytes exhausted cmpo 0, g14 # is it null? stob g14, (g5) # store it addo 1, g5, g5 # post-increment dest ptr bne Lcloop.a # branch if we are NOT null padding b Lcloop.b # branch if we are null padding Lexit: mov 0, g14 bx (g13) # g0 = dest string address; g14 = 0 Lrett: ret Lcloop.c: # character copying loop and g3, g4, g14 # extract byte cmpo 0, g14 # is it null? mov g3, g7 # save mask shlo 8, g3, g3 # shift mask to next byte position bne Lcloop.c # loop until null found subo 1, g7, g3 # mask to null pad after null byte and g3, g4, g4 # null-out stuff after null byte st g4, (g5) # store last part of src and first of null-pad subo 8,g2,g6 # adjust max_byte counter Lzwloop: cmpo g5, g6 # max_bytes < 4 ? addo 4, g5, g5 bg Lcloop.b # if so, goto character loop st g14, (g5) # store four null bytes b Lzwloop /* end of strncpy */ picolibc-1.8.11/libc/machine/i960/strncpy_ca.S000066400000000000000000000237641513574234600207110ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "sncpy_ca.s" #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure strncpy (optimized assembler version for the CA) dest_addr = strncpy (dest_addr, src_addr, max_bytes) copy the null terminated string pointed to by src_addr to the string space pointed to by dest_addr. Return the original dest_addr. If the source string is shorter than max_bytes, then null-pad the destination string. This routine will fail if the source and destination string overlap (in particular, if the end of the source is overlapped by the beginning of the destination). The behavior is undefined. This is acceptable according to the draft C standard. Undefined behavior will also occur if the end of the source string (i.e. the terminating null byte) is in the last word of the program's allocated memory space. This is so because, in several cases, strcpy will fetch ahead one word. Disallowing the fetch ahead would impose a severe performance penalty. This program handles five cases: 1) both arguments start on a word boundary 2) neither are word aligned, but they are offset by the same amount 3) source is word aligned, destination is not 4) destination is word aligned, source is not 5) neither is word aligned, and they are offset by differing amounts At the time of this writing, only g0 thru g7 and g13 are available for use in this leafproc; other registers would have to be saved and restored. These nine registers, plus tricky use of g14 are sufficient to implement the routine. The registers are used as follows: g0 original dest ptr; not modified, so that it may be returned. g1 src ptr; shift count g2 max_bytes g3 src ptr (word aligned) g4 dest ptr (word aligned) g5 0xff -- byte extraction mask Little endian: g6 lsw of double word for extraction of 4 bytes g7 msw of double word for extraction of 4 bytes Big endian: g6 msw of double word for extraction of 4 bytes g7 lsw of double word for extraction of 4 bytes g13 return address g14 byte extracted. */ #if __i960_BIG_ENDIAN__ #define MSW g6 #define LSW g7 #else #define LSW g6 #define MSW g7 #endif .globl _strncpy .globl __strncpy .leafproc _strncpy, __strncpy .align 2 _strncpy: #ifndef __PIC lda Lrett,g14 #else lda Lrett-(.+8)(ip),g14 #endif __strncpy: notand g1,3,g3 # extract word addr of start of src lda (g14),g13 # preserve return address cmpibge.f 0,g2,Lexit_code # Lexit if number of bytes to move is <= zero. cmpo g3,g1 # check alignment of src ld (g3),LSW # fetch word containing at least first byte notand g0,3,g4 # extract word addr of start of dest lda 4(g3),g3 # advance src word addr bne.f Lcase_245 # branch if src is NOT word aligned Lcase_13: cmpo g0,g4 # check alignment of dest lda 0xff,g5 # load mask for byte extraction subo 4,g4,g4 # store is pre-incrementing; back up dest addr bne.f Lcase_3 # branch if dest not word aligned Lcase_1: # src and dest are word aligned Lcase_1_wloop: # word copying loop cmpi g2,4 # check for fewer than four bytes to move lda (LSW),g1 # keep a copy of the src word addo 4,g4,g4 # pre-increment dest addr bl.f Lcase_1_cloop.a # branch if fewer than four bytes to copy scanbyte 0,g1 # check for null byte in src word ld (g3),LSW # pre-fetch next word of src subi 4,g2,g2 # decrease max_byte count by the 4 bytes moved bo.f Lcase_1_cloop.c # branch if word contains null byte addo 4,g3,g3 # post-increment src addr st g1,(g4) # store word in dest string b Lcase_1_wloop Lcase_3_cloop.a: Lcase_1_cloop.a: # character copying loop (max_bytes <= 3) #if __i960_BIG_ENDIAN__ rotate 8,g1,g1 # move next byte into position for extraction #endif and g5,g1,g14 # extract next char Lcase_1_cloop.b: cmpdeci 0,g2,g2 # is max_bytes exhausted? be.f Lexit_code # Lexit if max_bytes is exhausted cmpo 0,g14 # check for null byte stob g14,(g4) # store the byte in dest #if ! __i960_BIG_ENDIAN__ shro 8,g1,g1 # move next byte into position for extraction #endif lda 1(g4),g4 # post-increment dest byte addr bne.t Lcase_1_cloop.a # branch if null not reached b Lcase_1_cloop.b Lexit_code: mov 0,g14 # conform to register conventions bx (g13) # g0 = addr of dest; g14 = 0 Lrett: ret Lcase_1_cloop.c: Lcase_3_cloop.c: #if __i960_BIG_ENDIAN__ rotate 24,g5,g5 # move mask into position for testing next byte #endif and g5,g1,g14 # extract next char cmpo 0,g14 # check for null byte #if ! __i960_BIG_ENDIAN__ lda (g5),LSW # keep a copy of the current mask shlo 8,g5,g5 # move mask into position for testing next byte #endif bne.t Lcase_1_cloop.c # branch if null not reached #if __i960_BIG_ENDIAN__ subo 1,g5,g5 # null pad. andnot g5,g1,g1 # last bytes to copy, and null pad rest of word #else subo 1,LSW,g5 # mask to get last bytes to copy, and null pad and g5,g1,g1 # last bytes to copy, and null pad rest of word #endif st g1,(g4) Lcase_1_zwloop: # zero word loop cmpi g2,4 # check for fewer than four bytes to move addo 4,g4,g4 # pre-increment dest addr bl.f Lcase_1_cloop.b # branch if fewer than four bytes to copy subo 4,g2,g2 # decrease max_byte count by the 4 bytes moved st g14,(g4) # store word in dest string b Lcase_1_zwloop Lcase_3: # src is word aligned; dest is not addo 8,g4,g4 # move dest word ptr to first word boundary lda (g0),g1 # copy dest byte ptr mov LSW,MSW # make copy of first word of src lda 32,g14 # initialize shift count to zero (mod 32) Lcase_25: Lcase_3_cloop_at_start: # character copying loop for start of dest str cmpdeci 0,g2,g2 # is max_bytes exhausted? #if __i960_BIG_ENDIAN__ shro 24,MSW,g5 # extract next char #else and g5,MSW,g5 # extract next char #endif be.f Lexit_code # Lexit if max_bytes is exhausted cmpo 0,g5 # check for null byte stob g5,(g1) # store the byte in dest addo 1,g1,g1 # post-increment dest ptr lda 0xff,g5 # re-initialize byte extraction mask bne.t 1f # drop thru if null byte reached (to pad) movl 0,g6 # blank out remainder of input buffer 1: cmpo g1,g4 # have we reached word boundary in dest yet? #if __i960_BIG_ENDIAN__ lda -8(g14),g14 # augment the shift counter rotate 8,MSW,MSW # move next byte into position for extraction #else lda 8(g14),g14 # augment the shift counter shro 8,MSW,MSW # move next byte into position for extraction #endif bne.t Lcase_3_cloop_at_start # branch if reached word boundary? ld (g3),MSW # fetch msw of operand for double shift Lcase_4: #if __i960_BIG_ENDIAN__ cmpobne 0,g14,Lcase_3_wloop # branch if src is still unaligned. Lcase_3_wloop2: cmpi g2,4 # less than four bytes to move? lda (LSW),g1 # extract 4 bytes of src lda 4(g3),g3 # post-increment src word addr bl.f Lcase_3_cloop.a # branch if < four bytes left to move scanbyte 0,g1 # check for null byte lda (MSW),LSW # move msw to lsw subi 4,g2,g2 # decrease max_byte count by the 4 bytes moved ld (g3),MSW # pre-fetch msw of operand for double shift bo.f Lcase_3_cloop.c # branch if word contains null byte st g1,(g4) # store 4 bytes to dest addo 4,g4,g4 # post-increment dest ptr b Lcase_3_wloop2 #endif Lcase_3_wloop: cmpi g2,4 # less than four bytes to move? eshro g14,g6,g1 # extract 4 bytes of src lda 4(g3),g3 # post-increment src word addr bl.f Lcase_3_cloop.a # branch if < four bytes left to move scanbyte 0,g1 # check for null byte lda (MSW),LSW # move msw to lsw subi 4,g2,g2 # decrease max_byte count by the 4 bytes moved ld (g3),MSW # pre-fetch msw of operand for double shift bo.f Lcase_3_cloop.c # branch if word contains null byte st g1,(g4) # store 4 bytes to dest addo 4,g4,g4 # post-increment dest ptr b Lcase_3_wloop Lcase_245: cmpo g0,g4 # check alignment of dest ld (g3),MSW # pre-fetch second half and 3,g1,g1 # compute shift count lda 0xff,g5 # load mask for byte extraction #if __i960_BIG_ENDIAN__ subo g1,4,g14 # adjust shift count for big endian. shlo 3,g14,g14 #else shlo 3,g1,g14 #endif be.t Lcase_4 # branch if dest is word aligned or g4,g1,g1 # is src earlier in word, later, or sync w/ dst cmpo g0,g1 # < indicates first word of dest has more bytes /* than first word of source. */ lda 4(g4),g4 # move dest word addr to first word boundary eshro g14,g6,g5 # extract four bytes lda (g0),g1 bg.f 1f mov MSW,LSW lda 4(g3),g3 # move src word addr to second word boundary 1: mov g5,MSW lda 0xff,g5 b Lcase_25 /* end of strncpy */ picolibc-1.8.11/libc/machine/i960/strpbrk.S000066400000000000000000000066021513574234600202230ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ /* * (c) copyright 1989,1993 Intel Corp., all rights reserved */ /* procedure strpbrk (optimized assembler version: 80960K series, 80960CA) char_addr = strpbrk (string, brkset_string) Return the address of the first character in string that is NOT in the brkset_string. Return NULL if none exists. At the time of this writing, only g0 thru g7 and g13 are available for use in this leafproc; other registers would have to be saved and restored. These nine registers, plus tricky use of g14 are sufficient to implement the routine. This routine stays out of g3 and g4 altogether. They may be used by the strtok routine, which calls this routine in an incestuous way. */ #include #ifdef __PIC .pic #endif #ifdef __PID .pid #endif .file "strprk.s" .globl _strpbrk .globl __strpbrk .leafproc _strpbrk, __strpbrk .align 2 _strpbrk: #ifdef __PIC lda Lrett-(.+8)(ip),g14 b __strpbrk #else lda Lrett,g14 b __strpbrk #endif Lrett: ret __strpbrk: Lnext_char_strpbrk: addo 1,g1,g2 # g2 will be the brkset ptr ldob (g0),g7 # fetch next character of string ldob (g1),g6 # fetch first character of brkset cmpobe.f 0,g7,Lexit_char_not_found # quit if at end of string Lscan_set_strpbrk: cmpo g6,g7 # is brkset char equal to string char? ldob (g2),g5 # fetch next brkset char addo 1,g2,g2 # bump brkset ptr be.f Lexit_char_found cmpo g6,0 # is brkset_string exhausted? lda (g5),g6 bne.t Lscan_set_strpbrk # check next character of brkset addo 1,g0,g0 # check next character of string b Lnext_char_strpbrk Lexit_char_not_found: mov 0,g0 # return null if brkset char not found in string Lexit_char_found: mov g14,g13 # save return address lda 0,g14 # conform to register conventions bx (g13) /* end of strpbrk */ picolibc-1.8.11/libc/machine/i960/strrchr.S000066400000000000000000000116561513574234600202300ustar00rootroot00000000000000/******************************************************************************* * * Copyright (c) 1993 Intel Corporation * * Intel hereby grants you permission to copy, modify, and distribute this * software and its documentation. Intel grants this permission provided * that the above copyright notice appears in all copies and that both the * copyright notice and this permission notice appear in supporting * documentation. In addition, Intel grants this permission provided that * you prominently mark as "not part of the original" any modifications * made to this software or documentation, and that the name of Intel * Corporation not be used in advertising or publicity pertaining to * distribution of the software or the documentation without specific, * written prior permission. * * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or * representations regarding the use of, or the results of the use of, * the software and documentation in terms of correctness, accuracy, * reliability, currentness, or otherwise; and you rely on the software, * documentation and results solely at your own risk. * * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS, * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER. * ******************************************************************************/ #include .file "strrchr.s" #ifdef __i960_BIG_ENDIAN__ #error "This does not work in big-endian" #endif #ifdef __PIC .pic #endif #ifdef __PID .pid #endif /* * (c) copyright 1988,1993 Intel Corp., all rights reserved */ /* procedure strrchr (optimized assembler version for the 80960K series) src_addr = strrchr (src_addr, char) return a pointer to the last byte that contains the indicated byte in the source string. Return null if the byte is not found. Undefined behavior will occur if the end of the source string (i.e. the terminating null byte) is in the last two words of the program's allocated memory space. This is so because strrchr fetches ahead. Disallowing the fetch ahead would impose a severe performance penalty. Strategy: Fetch the source string by words and scanbyte the words for the char until either a word with the byte is found or the null byte is encountered. In the former case, move through the word to find the matching byte and save its memory address, then continue the search. In the latter case, return the saved address, or zero (null) if none was ever found to save. Tactics: 1) Do NOT try to fetch the words in a word aligned manner because, in my judgement, the performance degradation experienced due to non-aligned accesses does NOT outweigh the time and complexity added by the preamble that would be necessary to assure alignment. This is supported by the intuition that most source arrays (even more true of most big source arrays) will be word aligned to begin with. */ .globl _strrchr .globl __strrchr .leafproc _strrchr, __strrchr .align 2 _strrchr: #ifdef __PIC lda Lrett-(.+8)(ip),g14 #else lda Lrett,g14 #endif __strrchr: ld (g0),g4 # fetch first word lda 0xff,g7 # byte extraction mask and g1,g7,g1 # make char an 8-bit ordinal shlo 8,g1,g2 # broadcast the char to four bytes or g1,g2,g2 shlo 16,g2,g5 or g2,g5,g3 mov g14,g13 # preserve return address addo 4,g0,g2 # post-increment src pointer mov 1,g0 # prepare to return null pointer mov g3,g6 # prepare to return null pointer Lsearch_for_word_with_char_or_null: mov g4,g5 # copy word scanbyte 0,g5 # check for null byte ld (g2),g4 # fetch next word of src bo Lword_has_null # branch if null found scanbyte g3,g5 # check for byte with char addo 4,g2,g2 # post-increment src pointer bno Lsearch_for_word_with_char_or_null # branch if no copy of char mov g5,g6 # save word that has char in it (at least once) subo 4,g2,g0 # save addr of byte after word with char b Lsearch_for_word_with_char_or_null Lword_has_null: subo 4,g2,g2 # move src pointer back to word with null Lfind_null: addo 1,g2,g2 # advance src pointer to byte after current and g7,g5,g14 # extract next byte cmpo g1,g14 # is current byte char? shro 8,g5,g5 # position next byte for extraction bne 1f # skip if not char sought after mov g2,g0 # save addr of byte after char mov g3,g6 # save word of all char to short circuit search 1: cmpobne 0,g14,Lfind_null # is current byte null? Lfind_last_char: rotate 8,g6,g6 # position next highest byte and g7,g6,g5 # extract byte subo 1,g0,g0 # move pointer to that byte (or nullify) cmpobne g5,g1,Lfind_last_char # branch if not at char bx (g13) # g0 = addr of char in src (or null); g14 = 0 Lrett: ret /* end of strrchr */ picolibc-1.8.11/libc/machine/iq2000/000077500000000000000000000000001513574234600166305ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/iq2000/setjmp.S000066400000000000000000000016111513574234600202550ustar00rootroot00000000000000/* Copyright (c) 2003 Anthony Green */ /* This is a simple version of setjmp and longjmp for iq2000. */ /* int setjmp (jmp_buf); */ #include .globl setjmp .ent setjmp setjmp: sw r16,0(r4) /* rs0 */ sw r17,4(r4) /* rs1 */ sw r18,8(r4) /* rs2 */ sw r19,12(r4) /* rs3 */ sw r20,16(r4) /* rs4 */ sw r21,20(r4) /* rs5 */ sw r22,24(r4) /* rs6 */ sw r23,28(r4) /* rs7 */ sw r30,32(r4) /* rs8 */ sw r29,36(r4) sw r31,40(r4) move r2,r0 j r31 .end setjmp /* volatile void longjmp (jmp_buf, int); */ .globl longjmp .ent longjmp longjmp: lw r16,0(r4) /* rs0 */ lw r17,4(r4) /* rs1 */ lw r18,8(r4) /* rs2 */ lw r19,12(r4) /* rs3 */ lw r20,16(r4) /* rs4 */ lw r21,20(r4) /* rs5 */ lw r22,24(r4) /* rs6 */ lw r23,28(r4) /* rs7 */ lw r30,32(r4) /* rs8 */ lw r29,36(r4) lw r31,40(r4) bne r5,r0,1f li r5,1 1: move r2,r5 j r31 .end longjmp picolibc-1.8.11/libc/machine/lm32/000077500000000000000000000000001513574234600164725ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/lm32/meson.build000066400000000000000000000032111513574234600206310ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2024 Jiaxun Yang # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'setjmp.S', ] src_machine = files(srcs_machine) picolibc-1.8.11/libc/machine/lm32/setjmp.S000066400000000000000000000057431513574234600201310ustar00rootroot00000000000000/* * Copyright (c) 2008 Jon Beniston * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must 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. */ /* setjmp/longjmp for LatticeMico32. */ #include .section .text .align 4 .globl setjmp .type setjmp,@function /* setjmp: save all callee saves into jmp_buf r1 - Address of jmp_buf */ setjmp: sw (r1+0), r11 sw (r1+4), r12 sw (r1+8), r13 sw (r1+12), r14 sw (r1+16), r15 sw (r1+20), r16 sw (r1+24), r17 sw (r1+28), r18 sw (r1+32), r19 sw (r1+36), r20 sw (r1+40), r21 sw (r1+44), r22 sw (r1+48), r23 sw (r1+52), r24 sw (r1+56), r25 sw (r1+60), gp sw (r1+64), fp sw (r1+68), sp sw (r1+72), ra mvi r1, 0 ret .size setjmp, . - setjmp /* longjmp: restore all callee saves from jmp_buf r1 - Address of jmb_buf r2 - Value to return with */ .global longjmp .type longjmp,@function .align 4 longjmp: lw r11, (r1+0) lw r12, (r1+4) lw r13, (r1+8) lw r14, (r1+12) lw r15, (r1+16) lw r16, (r1+20) lw r17, (r1+24) lw r18, (r1+28) lw r19, (r1+32) lw r20, (r1+36) lw r21, (r1+40) lw r22, (r1+44) lw r23, (r1+48) lw r24, (r1+52) lw r25, (r1+56) lw gp, (r1+60) lw fp, (r1+64) lw sp, (r1+68) lw ra, (r1+72) mv r1, r2 # Return 1 if the argument is zero cmpe r1, r0, r2 add r1, r1, r2 ret .size longjmp, . - longjmp picolibc-1.8.11/libc/machine/loongarch/000077500000000000000000000000001513574234600176715ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/loongarch/CMakeLists.txt000066400000000000000000000032051513574234600224310ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2026 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # add_subdirectory(machine) picolibc_sources_flags("-fno-builtin" setjmp.S tls.c ) picolibc-1.8.11/libc/machine/loongarch/asm.h000066400000000000000000000045661513574234600206350ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Jiaxun Yang * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SYS_ASM_H #define _SYS_ASM_H /* * Macros to handle different pointer/register sizes for 32/64-bit code */ #if __loongarch_grlen == 64 # define PTRLOG 3 # define SZREG 8 # define REG_S st.d # define REG_L ld.d # define ADDI addi.d # define ADD add.d #elif __loongarch_grlen == 32 # define PTRLOG 2 # define SZREG 4 # define REG_S st.w # define REG_L ld.w # define ADDI addi.w # define ADD add.w #else # error __loongarch_grlen must equal 32 or 64 #endif #ifndef __loongarch_soft_float # if defined(__loongarch_single_float) # define SZFREG 4 # define FREG_L fld.s # define FREG_S fst.s # elif defined(__loongarch_double_float) # define SZFREG 8 # define FREG_L fld.d # define FREG_S fst.d # else # error unsupported FRLEN # endif #endif #endif /* sys/asm.h */ picolibc-1.8.11/libc/machine/loongarch/machine/000077500000000000000000000000001513574234600212755ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/loongarch/machine/CMakeLists.txt000066400000000000000000000031471513574234600240420ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2026 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_headers(machine fenv.h fenv-fp.h math.h ) picolibc-1.8.11/libc/machine/loongarch/machine/_fpmath.h000066400000000000000000000046551513574234600230760ustar00rootroot00000000000000/*- * Copyright (c) 2002, 2003 David Schultz * Copyright (c) 2014 The FreeBSD Foundation * Copyright (c) 2024 Jiaxun Yang * 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$ */ /* * Change unsigned int/long used by FreeBSD to fixed width types because * ilp32 has a different size for unsigned long. --joel (20 Aug 2022) */ #include union IEEEl2bits { long double e; struct { uint64_t manl : 64; uint64_t manh : 48; uint32_t exp : 15; uint32_t sign : 1; } bits; /* TODO andrew: Check the packing here */ struct { uint64_t manl : 64; uint64_t manh : 48; uint32_t expsign : 16; } xbits; }; #define LDBL_NBIT 0 #define LDBL_IMPLICIT_NBIT #define mask_nbit_l(u) ((void)0) #define LDBL_MANH_SIZE 48 #define LDBL_MANL_SIZE 64 #define LDBL_TO_ARRAY32(u, a) \ do { \ (a)[0] = (uint32_t)(u).bits.manl; \ (a)[1] = (uint32_t)((u).bits.manl >> 32); \ (a)[2] = (uint32_t)(u).bits.manh; \ (a)[3] = (uint32_t)((u).bits.manh >> 32); \ } while (0) picolibc-1.8.11/libc/machine/loongarch/machine/fenv-fp.h000066400000000000000000000326421513574234600230160ustar00rootroot00000000000000/* (c) Copyright 2017 Michael R. Neilly (c) Copyright 2024 Jiaxun Yang All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/feclearexcept.html * Referred to as 'feclearexcept.html below. * * "The feclearexcept() function shall attempt to clear the supported * floating-point exceptions represented by excepts." */ #define _FPU_DEFAULT 0x0 #define _FPU_IEEE 0x1F __declare_fenv_inline(int) feclearexcept(int excepts) { int fcsr; excepts &= FE_ALL_EXCEPT; _movfcsr2gr(fcsr); fcsr &= ~(excepts | (excepts << _FCSR_CAUSE_LSHIFT)); _movgr2fcsr(fcsr); /* Per 'feclearexcept.html * "If the argument is zero or if all the specified exceptions were * successfully cleared, feclearexcept() shall return zero. Otherwise, * it shall return a non-zero value." */ return 0; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/fegetenv.html * Referred to as 'fegetenv.html below. * * "The fegetenv() function shall attempt to store the current * floating-point environment in the object pointed to by envp." * */ __declare_fenv_inline(int) fegetenv(fenv_t *envp) { /* Get the current environment (FCSR) */ int fcsr; _movfcsr2gr(fcsr); *envp = fcsr; /* Per 'fegetenv.html: * * "If the representation was successfully stored, fegetenv() shall * return zero. Otherwise, it shall return a non-zero value. */ return 0; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/fegetexceptflag.html * Referred to as 'fegetexceptflag.html below. * * "The fegetexceptflag() function shall attempt to store an * implementation-defined representation of the states of the * floating-point status flags indicated by the argument excepts in * the object pointed to by the argument flagp." */ __declare_fenv_inline(int) fegetexceptflag(fexcept_t *flagp, int excepts) { int fcsr; _movfcsr2gr(fcsr); *flagp = fcsr & excepts & FE_ALL_EXCEPT; /* Per 'fegetexceptflag.html: * * "If the representation was successfully stored, fegetexceptflag() * shall return zero. Otherwise, it shall return a non-zero * value." */ return 0; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/fegetround.html * Referred to as 'fegetround.html below. * * "The fegetround() function shall get the current rounding direction." */ __declare_fenv_inline(int) fegetround(void) { /* Get current rounding mode */ int fcsr; _movfcsr2gr(fcsr); /* Per 'fegetround.html: * * "The fegetround() function shall return the value of the rounding * direction macro representing the current rounding direction or a * negative value if there is no such rounding direction macro or * the current rounding direction is not determinable." */ /* Return the rounding mode */ return fcsr & FE_RMODE_MASK; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/feholdexcept.html * Referred to as 'feholdexcept.html below. * * "The feholdexcept() function shall save the current floating-point * environment in the object pointed to by envp, clear the * floating-point status flags, and then install a non-stop (continue * on floating-point exceptions) mode, if available, for all * floating-point exceptions." */ __declare_fenv_inline(int) feholdexcept(fenv_t *envp) { /* Store the current FP environment in envp*/ int fcsr; _movfcsr2gr(fcsr); *envp = fcsr; /* Clear all exception enable bits and flags. */ fcsr &= ~(FE_ALL_EXCEPT >> _FCSR_ENABLE_RSHIFT | FE_ALL_EXCEPT); _movgr2fcsr(fcsr); /* Per 'feholdexcept.html: * * "The feholdexcept() function shall return zero if and only if * non-stop floating-point exception handling was successfully * installed." */ return 0; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/feraiseexcept.html * Referred to as 'feraiseexcept.html below. * * "The feraiseexcept() function shall attempt to raise the supported * floating-point exceptions represented by the excepts argument. The * order in which these floating-point exceptions are raised is * unspecified, except that if the excepts argument represents IEC * 60559 valid coincident floating-point exceptions for atomic * operations (namely overflow and inexact, or underflow and inexact), * then overflow or underflow shall be raised before inexact. Whether * the feraiseexcept() function additionally raises the inexact * floating-point exception whenever it raises the overflow or * underflow floating-point exception is implementation-defined." */ __declare_fenv_inline(int) feraiseexcept(int excepts) { const float fp_zero = 0.0f; const float fp_one = 1.0f; const float fp_max = __FLT_MAX__; const float fp_min = __FLT_MIN__; const float fp_1e32 = 1.0e32f; const float fp_two = 2.0f; const float fp_three = 3.0f; if (FE_INVALID & excepts) __asm__ __volatile__("fdiv.s $f0,%0,%0\n\t" : : "f"(fp_zero) : "$f0"); if (FE_DIVBYZERO & excepts) __asm__ __volatile__("fdiv.s $f0,%0,%1\n\t" : : "f"(fp_one), "f"(fp_zero) : "$f0"); if (FE_OVERFLOW & excepts) __asm__ __volatile__("fadd.s $f0,%0,%1\n\t" : : "f"(fp_max), "f"(fp_1e32) : "$f0"); if (FE_UNDERFLOW & excepts) __asm__ __volatile__("fdiv.s $f0,%0,%1\n\t" : : "f"(fp_min), "f"(fp_three) : "$f0"); if (FE_INEXACT & excepts) __asm__ __volatile__("fdiv.s $f0, %0, %1\n\t" : : "f"(fp_two), "f"(fp_three) : "$f0"); /* Per 'feraiseexcept.html: * "If the argument is zero or if all the specified exceptions were * successfully raised, feraiseexcept() shall return * zero. Otherwise, it shall return a non-zero value." */ return 0; } __declare_fenv_inline(int) fesetexcept(int excepts) { int fcsr; _movfcsr2gr(fcsr); fcsr |= excepts & FE_ALL_EXCEPT; _movgr2fcsr(fcsr); return 0; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/fegetenv.html * Referred to as 'fegetenv.html below. * * "The fegetenv() function shall attempt to store the current * floating-point environment in the object pointed to by envp. * * The fesetenv() function shall attempt to establish the * floating-point environment represented by the object pointed to by * envp. The argument envp shall point to an object set by a call to * fegetenv() or feholdexcept(), or equal a floating-point environment * macro. The fesetenv() function does not raise floating-point * exceptions, but only installs the state of the floating-point * status flags represented through its argument." */ __declare_fenv_inline(int) fesetenv(const fenv_t *envp) { /* Set environment (FCSR) */ fenv_t fcsr; /* Hazard handling */ _movfcsr2gr(fcsr); fcsr = *envp; _movgr2fcsr(fcsr); /* Per 'fegetenv.html: * * "If the environment was successfully established, fesetenv() * shall return zero. Otherwise, it shall return a non-zero value. */ return 0; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/fesetexceptflag.html * Referred to as 'fesetexceptflag.html below. * * "The fesetexceptflag() function shall attempt to set the * floating-point status flags indicated by the argument excepts to * the states stored in the object pointed to by flagp. The value * pointed to by flagp shall have been set by a previous call to * fegetexceptflag() whose second argument represented at least those * floating-point exceptions represented by the argument excepts. This * function does not raise floating-point exceptions, but only sets * the state of the flags." * */ __declare_fenv_inline(int) fesetexceptflag(const fexcept_t *flagp, int excepts) { int fcsr; _movfcsr2gr(fcsr); excepts &= FE_ALL_EXCEPT; fcsr = (fcsr & ~excepts) | (*flagp & excepts); _movgr2fcsr(fcsr); /* Per 'fesetexceptflag.html: * * "If the excepts argument is zero or if all the specified * exceptions were successfully set, fesetexceptflag() shall return * zero. Otherwise, it shall return a non-zero value." */ return 0; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/fesetround.html * Referred to as 'fegetenv.html below. * * "The fesetround() function shall establish the rounding direction * represented by its argument round. If the argument is not equal to * the value of a rounding direction macro, the rounding direction is * not changed." */ __declare_fenv_inline(int) fesetround(int round) { int fcsr; if ((round & ~FE_RMODE_MASK) != 0) return -1; _movfcsr2gr(fcsr); fcsr &= ~FE_RMODE_MASK; fcsr |= round; _movgr2fcsr(fcsr); /* Per 'fesetround.html: * * "The fesetround() function shall return a zero value if and only * if the requested rounding direction was established." */ return 0; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/9699919799/functions/fetestexcept.html * * "The fetestexcept() function shall determine which of a specified * subset of the floating-point exception flags are currently set. The * excepts argument specifies the floating-point status flags to be * queried." */ __declare_fenv_inline(int) fetestexcept(int excepts) { int fcsr; _movfcsr2gr(fcsr); /* "The fetestexcept() function shall return the value of the * bitwise-inclusive OR of the floating-point exception macros * corresponding to the currently set floating-point exceptions * included in excepts." */ return (fcsr & excepts & FE_ALL_EXCEPT); } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/9699919799/functions/feupdateenv.html * * "The feupdateenv() function shall attempt to save the currently * raised floating-point exceptions in its automatic storage, attempt * to install the floating-point environment represented by the object * pointed to by envp, and then attempt to raise the saved * floating-point exceptions. The argument envp shall point to an * object set by a call to feholdexcept() or fegetenv(), or equal a * floating-point environment macro." */ __declare_fenv_inline(int) feupdateenv(const fenv_t *envp) { int fcsr; _movfcsr2gr(fcsr); fesetenv(envp); feraiseexcept(fcsr & FE_ALL_EXCEPT); /* "The feupdateenv() function shall return a zero value if and only * if all the required actions were successfully carried out." */ return 0; } __declare_fenv_inline(int) feenableexcept(int excepts) { int fcsr, old_excepts; _movfcsr2gr(fcsr); old_excepts = (fcsr << _FCSR_ENABLE_RSHIFT) & FE_ALL_EXCEPT; excepts &= FE_ALL_EXCEPT; fcsr |= excepts >> _FCSR_ENABLE_RSHIFT; _movgr2fcsr(fcsr); return old_excepts; } __declare_fenv_inline(int) fedisableexcept(int excepts) { int fcsr, old_excepts; _movfcsr2gr(fcsr); old_excepts = (fcsr << _FCSR_ENABLE_RSHIFT) & FE_ALL_EXCEPT; excepts &= FE_ALL_EXCEPT; fcsr &= ~(excepts >> _FCSR_ENABLE_RSHIFT); _movgr2fcsr(fcsr); return old_excepts; } __declare_fenv_inline(int) fegetexcept(void) { int fcsr; _movfcsr2gr(fcsr); return (fcsr << _FCSR_ENABLE_RSHIFT) & FE_ALL_EXCEPT; } picolibc-1.8.11/libc/machine/loongarch/machine/fenv.h000066400000000000000000000077641513574234600224220ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Jiaxun Yang * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MACHINE_FENV_H #define _MACHINE_FENV_H #include typedef unsigned int fenv_t; typedef unsigned int fexcept_t; #ifndef __loongarch_soft_float /* LoongArch FPU floating point control register bits. * * 31-29 -> reserved (read as 0, can not changed by software) * 28 -> cause bit for invalid exception * 27 -> cause bit for division by zero exception * 26 -> cause bit for overflow exception * 25 -> cause bit for underflow exception * 24 -> cause bit for inexact exception * 23-21 -> reserved (read as 0, can not changed by software) * 20 -> flag invalid exception * 19 -> flag division by zero exception * 18 -> flag overflow exception * 17 -> flag underflow exception * 16 -> flag inexact exception * 9-8 -> rounding control * 7-5 -> reserved (read as 0, can not changed by software) * 4 -> enable exception for invalid exception * 3 -> enable exception for division by zero exception * 2 -> enable exception for overflow exception * 1 -> enable exception for underflow exception * 0 -> enable exception for inexact exception * * * Rounding Control: * 00 - rounding ties to even (RNE) * 01 - rounding toward zero (RZ) * 10 - rounding (up) toward plus infinity (RP) * 11 - rounding (down) toward minus infinity (RM) */ /* Masks for interrupts. */ #define _FCSR_CAUSE_LSHIFT 8 #define _FCSR_ENABLE_RSHIFT 16 #define FE_INEXACT 0x010000 #define FE_UNDERFLOW 0x020000 #define FE_OVERFLOW 0x040000 #define FE_DIVBYZERO 0x080000 #define FE_INVALID 0x100000 /* Flush denormalized numbers to zero. */ #define FE_ALL_EXCEPT (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT) /* Rounding control. */ #define FE_TONEAREST 0x000 #define FE_TOWARDZERO 0x100 #define FE_UPWARD 0x200 #define FE_DOWNWARD 0x300 #define FE_RMODE_MASK 0x300 #define _movfcsr2gr(cw) __asm__ volatile("movfcsr2gr %0,$fcsr0" : "=r"(cw)) #define _movgr2fcsr(cw) __asm__ volatile("movgr2fcsr $fcsr0,%0" : : "r"(cw)) #else #define FE_TONEAREST 0 #endif #if !defined(__declare_fenv_inline) && defined(__declare_extern_inline) #define __declare_fenv_inline(type) __declare_extern_inline(type) #endif #ifdef __declare_fenv_inline #ifndef __loongarch_soft_float #include #else #include #endif #endif #endif /* _MACHINE_FENV_H */ picolibc-1.8.11/libc/machine/loongarch/machine/math.h000066400000000000000000000171201513574234600224000ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 2024 Jiaxun Yang * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MACHINE_MATH_H_ #define _MACHINE_MATH_H_ #ifndef __loongarch_soft_float #ifdef __MATH_ERRNO #include #endif #define _FCLASS_SNAN (1 << 0) #define _FCLASS_QNAN (1 << 1) #define _FCLASS_MINF (1 << 2) #define _FCLASS_MNORM (1 << 3) #define _FCLASS_MSUBNORM (1 << 4) #define _FCLASS_MZERO (1 << 5) #define _FCLASS_PINF (1 << 6) #define _FCLASS_PNORM (1 << 7) #define _FCLASS_PSUBNORM (1 << 8) #define _FCLASS_PZERO (1 << 9) #define _FCLASS_ZERO (_FCLASS_MZERO | _FCLASS_PZERO) #define _FCLASS_SUBNORM (_FCLASS_MSUBNORM | _FCLASS_PSUBNORM) #define _FCLASS_NORM (_FCLASS_MNORM | _FCLASS_PNORM) #define _FCLASS_INF (_FCLASS_MINF | _FCLASS_PINF) #define _FCLASS_NAN (_FCLASS_SNAN | _FCLASS_QNAN) #if __loongarch_frlen >= 64 /* anything with a 64-bit FPU has FMA */ #define __HAVE_FAST_FMA 1 #define _fclass_d(_x) \ (__extension__({ \ long __fclass; \ __asm__("fclass.d %0, %1" : "=f"(__fclass) : "f"(_x)); \ __fclass; \ })) #endif #if __loongarch_frlen >= 32 /* anything with a 32-bit FPU has FMAF */ #define __HAVE_FAST_FMAF 1 #define _fclass_f(_x) \ (__extension__({ \ long __fclass; \ __asm__("fclass.s %0, %1" : "=f"(__fclass) : "f"(_x)); \ __fclass; \ })) #endif #ifdef __declare_extern_inline #if __loongarch_frlen >= 64 /* Double-precision functions */ __declare_extern_inline(double) copysign(double x, double y) { double result; __asm__("fcopysign.d\t%0, %1, %2" : "=f"(result) : "f"(x), "f"(y)); return result; } __declare_extern_inline(double) fabs(double x) { double result; __asm__("fabs.d\t%0, %1" : "=f"(result) : "f"(x)); return result; } __declare_extern_inline(double) fmax(double x, double y) { double result; if (issignaling(x) || issignaling(y)) return x + y; __asm__ volatile("fmax.d\t%0, %1, %2" : "=f"(result) : "f"(x), "f"(y)); return result; } __declare_extern_inline(double) fmin(double x, double y) { double result; if (issignaling(x) || issignaling(y)) return x + y; __asm__ volatile("fmin.d\t%0, %1, %2" : "=f"(result) : "f"(x), "f"(y)); return result; } __declare_extern_inline(int) __finite(double x) { long fclass = _fclass_d(x); return (fclass & (_FCLASS_INF | _FCLASS_NAN)) == 0; } __declare_extern_inline(int) finite(double x) { return __finite(x); } __declare_extern_inline(int) __isinfd(double x) { long fclass = _fclass_d(x); return (fclass & _FCLASS_INF) != 0; } __declare_extern_inline(int) __isnand(double x) { long fclass = _fclass_d(x); return (fclass & _FCLASS_NAN) != 0; } __declare_extern_inline(int) __fpclassifyd(double x) { long fclass = _fclass_d(x); if (fclass & _FCLASS_ZERO) return FP_ZERO; else if (fclass & _FCLASS_NORM) return FP_NORMAL; else if (fclass & _FCLASS_SUBNORM) return FP_SUBNORMAL; else if (fclass & _FCLASS_INF) return FP_INFINITE; else return FP_NAN; } __declare_extern_inline(double) sqrt(double x) { double result; #ifdef __MATH_ERRNO if (isless(x, 0.0)) errno = EDOM; #endif __asm__ volatile("fsqrt.d %0, %1" : "=f"(result) : "f"(x)); return result; } __declare_extern_inline(double) fma(double x, double y, double z) { double result; __asm__ volatile("fmadd.d %0, %1, %2, %3" : "=f"(result) : "f"(x), "f"(y), "f"(z)); return result; } #endif /* __loongarch_frlen >= 64 */ #if __loongarch_frlen >= 32 /* Single-precision functions */ __declare_extern_inline(float) copysignf(float x, float y) { float result; __asm__("fcopysign.s\t%0, %1, %2" : "=f"(result) : "f"(x), "f"(y)); return result; } __declare_extern_inline(float) fabsf(float x) { float result; __asm__("fabs.s\t%0, %1" : "=f"(result) : "f"(x)); return result; } __declare_extern_inline(float) fmaxf(float x, float y) { float result; if (issignaling(x) || issignaling(y)) return x + y; __asm__ volatile("fmax.s\t%0, %1, %2" : "=f"(result) : "f"(x), "f"(y)); return result; } __declare_extern_inline(float) fminf(float x, float y) { float result; if (issignaling(x) || issignaling(y)) return x + y; __asm__ volatile("fmin.s\t%0, %1, %2" : "=f"(result) : "f"(x), "f"(y)); return result; } __declare_extern_inline(int) __finitef(float x) { long fclass = _fclass_f(x); return (fclass & (_FCLASS_INF | _FCLASS_NAN)) == 0; } __declare_extern_inline(int) finitef(float x) { return __finitef(x); } __declare_extern_inline(int) __isinff(float x) { long fclass = _fclass_f(x); return (fclass & _FCLASS_INF) != 0; } __declare_extern_inline(int) __isnanf(float x) { long fclass = _fclass_f(x); return (fclass & _FCLASS_NAN) != 0; } __declare_extern_inline(int) __fpclassifyf(float x) { long fclass = _fclass_f(x); if (fclass & _FCLASS_ZERO) return FP_ZERO; else if (fclass & _FCLASS_NORM) return FP_NORMAL; else if (fclass & _FCLASS_SUBNORM) return FP_SUBNORMAL; else if (fclass & _FCLASS_INF) return FP_INFINITE; else return FP_NAN; } __declare_extern_inline(float) sqrtf(float x) { float result; #ifdef __MATH_ERRNO if (isless(x, 0.0f)) errno = EDOM; #endif __asm__ volatile("fsqrt.s %0, %1" : "=f"(result) : "f"(x)); return result; } __declare_extern_inline(float) fmaf(float x, float y, float z) { float result; __asm__ volatile("fmadd.s %0, %1, %2, %3" : "=f"(result) : "f"(x), "f"(y), "f"(z)); return result; } #endif /* __loongarch_frlen >= 32 */ #endif /* defined(__GNUC_GNU_INLINE__) || defined(__GNUC_STDC_INLINE__) */ #endif /* __loongarch_frlen */ #endif /* _MACHINE_MATH_H_ */ picolibc-1.8.11/libc/machine/loongarch/machine/meson.build000066400000000000000000000034561513574234600234470ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2020 Keith Packard # Copyright © 2024 Jiaxun Yang # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_machine_headers_machine = [ 'fenv.h', 'fenv-fp.h', 'math.h' ] if really_install install_headers(inc_machine_headers_machine, install_dir: include_dir / 'machine') endif picolibc-1.8.11/libc/machine/loongarch/meson.build000066400000000000000000000037561513574234600220460ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # Copyright © 2024 Jiaxun Yang # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'setjmp.S', 'tls.c', ] subdir('machine') foreach params : targets target = params['name'] target_dir = params['dir'] target_c_args = params['c_args'] set_variable('lib_machine' + target, static_library('machine' + target, srcs_machine, pic: false, include_directories: inc, c_args: target_c_args + c_args + arg_fnobuiltin + arg_fnolto)) endforeach picolibc-1.8.11/libc/machine/loongarch/setjmp.S000066400000000000000000000050331513574234600213200ustar00rootroot00000000000000/* Copyright (c) 2024 Jiaxun Yang This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #include #include "asm.h" /* Align up for FPR to avoid unaligned access on grlen == 32 & frlen == 64 */ #define ALIGN_UP(x, align) (((x) + (align) - 1) & ~((align) - 1)) #define FR_OFFSET ALIGN_UP((13*SZREG), SZFREG) /* int setjmp (jmp_buf); */ .section .text.setjmp .globl setjmp .type setjmp, @function setjmp: REG_S $ra, $a0, 0*SZREG REG_S $sp, $a0, 1*SZREG REG_S $r21, $a0, 2*SZREG /* r21 is reserved */ REG_S $fp, $a0, 3*SZREG REG_S $s0, $a0, 4*SZREG REG_S $s1, $a0, 5*SZREG REG_S $s2, $a0, 6*SZREG REG_S $s3, $a0, 7*SZREG REG_S $s4, $a0, 8*SZREG REG_S $s5, $a0, 9*SZREG REG_S $s6, $a0, 10*SZREG REG_S $s7, $a0, 11*SZREG REG_S $s8, $a0, 12*SZREG #ifndef __loongarch_soft_float FREG_S $fs0, $a0, FR_OFFSET + 0*SZFREG FREG_S $fs1, $a0, FR_OFFSET + 1*SZFREG FREG_S $fs2, $a0, FR_OFFSET + 2*SZFREG FREG_S $fs3, $a0, FR_OFFSET + 3*SZFREG FREG_S $fs4, $a0, FR_OFFSET + 4*SZFREG FREG_S $fs5, $a0, FR_OFFSET + 5*SZFREG FREG_S $fs6, $a0, FR_OFFSET + 6*SZFREG FREG_S $fs7, $a0, FR_OFFSET + 7*SZFREG #endif li.w $a0, 0 jirl $zero, $ra, 0 .size setjmp, .-setjmp /* volatile void longjmp (jmp_buf, int); */ .section .text.longjmp .globl longjmp .type longjmp, @function longjmp: REG_L $ra, $a0, 0*SZREG REG_L $sp, $a0, 1*SZREG REG_L $r21, $a0, 2*SZREG REG_L $fp, $a0, 3*SZREG REG_L $s0, $a0, 4*SZREG REG_L $s1, $a0, 5*SZREG REG_L $s2, $a0, 6*SZREG REG_L $s3, $a0, 7*SZREG REG_L $s4, $a0, 8*SZREG REG_L $s5, $a0, 9*SZREG REG_L $s6, $a0, 10*SZREG REG_L $s7, $a0, 11*SZREG REG_L $s8, $a0, 12*SZREG #ifndef __loongarch_soft_float FREG_L $fs0, $a0, FR_OFFSET + 0*SZFREG FREG_L $fs1, $a0, FR_OFFSET + 1*SZFREG FREG_L $fs2, $a0, FR_OFFSET + 2*SZFREG FREG_L $fs3, $a0, FR_OFFSET + 3*SZFREG FREG_L $fs4, $a0, FR_OFFSET + 4*SZFREG FREG_L $fs5, $a0, FR_OFFSET + 5*SZFREG FREG_L $fs6, $a0, FR_OFFSET + 6*SZFREG FREG_L $fs7, $a0, FR_OFFSET + 7*SZFREG #endif sltui $a0, $a1, 1 ADD $a0, $a0, $a1 # a0 = (a1 == 0) ? 1 : a1 jirl $zero, $ra, 0 .size longjmp, .-longjmp picolibc-1.8.11/libc/machine/loongarch/tls.c000066400000000000000000000034011513574234600206350ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #ifdef __THREAD_LOCAL_STORAGE_API void _set_tls(void *tls) { __asm__("or $tp,%0,$r0" : : "r"(tls)); } #endif picolibc-1.8.11/libc/machine/m32c/000077500000000000000000000000001513574234600164615ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/m32c/setjmp.S000066400000000000000000000075401513574234600201150ustar00rootroot00000000000000/* Copyright (c) 2005 Red Hat Incorporated. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #if defined(__r8c_cpu__) || defined(__m16c_cpu__) #define A16 1 #endif /* We implement setjmp/longjmp much like the way gcc implements exceptions - we create new stack frames, then switch to them and return. Thus, the two setjmp's below each push all the relevent registers, then copy the whole frame into the buffer (first $sp is moved, then smovf copies the frame itself), and the two longjmps restore $sp, copy the frame back into place, and issue the same return as the setjmp would have used. Since the sizes of registers differs between the 16 and 24 bit models, we provide separate implementations for each rather than trying to parameterize them. Jump buffer sizes: 21 bytes for 16 bit, 34 bytes for 24 bit. */ .text #ifdef A16 /* 16 bit versions */ .global _setjmp _setjmp: enter #0 pushm r1,r2,r3,a0,a1,sb,fb ; At this point, the stack looks like this: ; ... [pc:3] [oldfb:2] [r1:2] [r2:2] [r3:2] [a0:2] [a1:2] [sb:2] [fb:2] */ mov.w r1,a1 ; a1 is the destination of smovf mov.b #0,r1h stc sp,a0 ; r1h:a0 is the source of smovf mov.w a0,[a1] add.w #2,a1 mov.w #19,r3 ; plus two for sp later smovf.b ; Return 0 to caller. mov.w #0,r0 popm r1,r2,r3,a0,a1,sb,fb exitd .global _longjmp _longjmp: enter #0 mov.w r1,a0 ; pointer to jump buf mov.w r2,r0 ; setjmp's "new" return value mov.b #0,r1h ; r1h: a0 is the source, now jmpbuf mov.w [a0],a1 ; dest is new stack ldc a1,sp add.w #2,a0 mov.w #19,r3 smovf.b ;; now return to our caller with this newly restored frame popm r1,r2,r3,a0,a1,sb,fb exitd #else /* 24 bit versions */ .global _setjmp _setjmp: enter #0 pushm r1,r2,r3,a0,a1,sb,fb ; At this point, the stack looks like this: ; ... [jbuf:4] [pc:4] [oldfb:4] [r1:2] [r2:2] [r3:2] [a0:4] [a1:4] [sb:4] [fb:4] */ mov.l 8[fb],a1 ; a1 is the destination of smovf stc sp,a0 ; r1h:a0 is the source of smovf mov.l a0,[a1] add.l #4,a1 mov.w #30,r3 ; plus two for sp later smovf.b ; Return 0 to caller. mov.w #0,r0 popm r1,r2,r3,a0,a1,sb,fb exitd .global _longjmp _longjmp: enter #0 ; ... [rv:2] [jbuf:4] [pc:4] [oldfb:4] mov.l 8[fb],a0 ; pointer to jump buf mov.w 12[fb],r0 ; setjmp's "new" return value mov.l [a0],a1 ; dest is new stack ldc a1,sp add.l #4,a0 mov.w #30,r3 smovf.b ;; now return to our caller with this newly restored frame popm r1,r2,r3,a0,a1,sb,fb exitd #endif picolibc-1.8.11/libc/machine/m32r/000077500000000000000000000000001513574234600165005ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/m32r/setjmp.S000066400000000000000000000030651513574234600201320ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include # setjmp/longjmp for m32r. The jmpbuf looks like this: # # Register jmpbuf offset # reserved 0x00 # R8 0x04 # R9 0x08 # R10 0x0c # R11 0x10 # R12 0x14 # R13 (FP) 0x18 # R14 (LR) 0x1c # R15 (SP) 0x20 # reserved 0x24 .text .global setjmp setjmp: ;addi r0, #-4 ; commented out as first word is reserved ;st r1, @+r0 st r8, @+r0 st r9, @+r0 st r10, @+r0 st r11, @+r0 st r12, @+r0 st r13, @+r0 st r14, @+r0 st r15, @+r0 # Return 0 to caller. ldi r0, #0 jmp lr .global longjmp longjmp: addi r0, #4 ; first word is reserved ;ld r1, @r0+ ld r8, @r0+ ld r9, @r0+ ld r10, @r0+ ld r11, @r0+ ld r12, @r0+ ld r13, @r0+ ld r2, @r0+ ; return address ld r15, @r0+ # If caller attempted to return 0, return 1 instead. mv r0, r1 bnez r0, .Lnonzero ldi r0, #1 .Lnonzero: jmp r2 picolibc-1.8.11/libc/machine/m68hc11/000077500000000000000000000000001513574234600170045ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/m68hc11/setjmp.S000066400000000000000000000041651513574234600204400ustar00rootroot00000000000000/* setjmp/longjmp routines for M68HC11 & M68HC12. * Copyright (C) 1999, 2000, 2001, 2002 Stephane Carrez (stcarrez@nerim.fr) * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #if __INT__ == 32 # define val 4 # define INT32(X) X #else # define val 2 # define INT32(X) #endif #ifdef mc6811 # define REG(X) *X #else # define REG(X) X #endif .sect .text .global setjmp .global longjmp #ifdef mc6811 setjmp: xgdx tsy ldd 0,y std 0,x sty 2,x ldd REG(_.frame) std 4,x ldd REG(_.d1) std 6,x ldd REG(_.d2) std 8,x ldd REG(_.d3) std 10,x ldd REG(_.d4) std 12,x ldd REG(_.d5) std 14,x ldd REG(_.d6) std 16,x ldd REG(_.d7) std 18,x ldd REG(_.d8) std 20,x INT32( ldx #0) clra clrb rts #else setjmp: xgdx movw 0,sp,2,x+ sts 2,x+ movw _.frame,2,x+ movw _.d1,2,x+ movw _.d2,2,x+ movw _.d3,2,x+ movw _.d4,2,x+ movw _.d5,2,x+ movw _.d6,2,x+ movw _.d7,2,x+ movw _.d8,2,x+ INT32( ldx #0) clra clrb rts #endif #ifdef mc6811 longjmp: xgdx tsy ldd val,y bne do_jump ldd #1 do_jump: xgdy ldd 4,x std REG(_.frame) ldd 6,x std REG(_.d1) ldd 8,x std REG(_.d2) ldd 10,x std REG(_.d3) ldd 12,x std REG(_.d4) ldd 14,x std REG(_.d5) ldd 16,x std REG(_.d6) ldd 18,x std REG(_.d7) ldd 20,x std REG(_.d8) ldd 0,x ldx 2,x txs std 0,x INT32( ldx #0) xgdy rts #else longjmp: xgdx ldy val,sp bne do_jump ldy #1 do_jump: ldd 4,x+ movw 2,x+,_.frame movw 0,x,_.d1 movw 2,x,_.d2 movw 4,x,_.d3 movw 6,x,_.d4 movw 8,x,_.d5 movw 10,x,_.d6 movw 12,x,_.d7 movw 14,x,_.d8 ldx -4,x txs std 0,x INT32( ldx #0) xgdy rts #endif picolibc-1.8.11/libc/machine/m68k/000077500000000000000000000000001513574234600165025ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/m68k/CMakeLists.txt000066400000000000000000000033251513574234600212450ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2023 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. add_subdirectory(machine) picolibc_sources_flags("-fno-builtin" interrupt.c memcpy.S memset.S read_tp.S set_tls.c setjmp.S strcpy.c strlen.c tls.c ) picolibc-1.8.11/libc/machine/m68k/interrupt.c000066400000000000000000000054331513574234600207070ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include static void m68k_halt_isr(void) { for (;;) ; } static void m68k_ignore_isr(void) { } void _start(void); extern char __stack[]; #define isr(name) void m68k_##name##_isr(void) __attribute__((weak, alias("m68k_ignore_isr"))); #define isr_halt(name) void m68k_##name##_isr(void) __attribute__((weak, alias("m68k_halt_isr"))); isr_halt(access_fault); isr_halt(address_error); isr_halt(illegal_instruction); isr_halt(divide_by_zero); isr(chk); isr(trap); isr_halt(fp_branch_uc); isr_halt(fp_inexact); isr_halt(fp_divide_by_zero); isr_halt(fp_underflow); isr_halt(fp_operand_error); isr_halt(fp_overflow); isr_halt(fp_signaling_nan); isr_halt(fp_unimplemented_data); #define i(id, name) [id] = m68k_##name##_isr __section(".data.init.enter") void * const __exception_vector[] = { [0] = __stack, [1] = _start, i(2, access_fault), i(3, address_error), i(4, illegal_instruction), i(5, divide_by_zero), i(6, chk), i(7, trap), i(48, fp_branch_uc), i(49, fp_inexact), i(50, fp_divide_by_zero), i(51, fp_underflow), i(52, fp_operand_error), i(53, fp_overflow), i(54, fp_signaling_nan), i(55, fp_unimplemented_data), }; picolibc-1.8.11/libc/machine/m68k/m68kasm.h000066400000000000000000000015661513574234600201510ustar00rootroot00000000000000/* Copyright (c) 2008 Jeff Johnston */ /* These are predefined by new versions of GNU cpp. */ #ifndef __USER_LABEL_PREFIX__ #define __USER_LABEL_PREFIX__ _ #endif #ifndef __REGISTER_PREFIX__ #define __REGISTER_PREFIX__ #endif /* ANSI concatenation macros. */ #define CONCAT1(a, b) CONCAT2(a, b) #define CONCAT2(a, b) a ## b /* Use the right prefix for global labels. */ #define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x) /* Use the right prefix for registers. */ #define REG(x) CONCAT1 (__REGISTER_PREFIX__, x) #define d0 REG (d0) #define d1 REG (d1) #define d2 REG (d2) #define d3 REG (d3) #define d4 REG (d4) #define d5 REG (d5) #define d6 REG (d6) #define d7 REG (d7) #define a0 REG (a0) #define a1 REG (a1) #define a2 REG (a2) #define a3 REG (a3) #define a4 REG (a4) #define a5 REG (a5) #define a6 REG (a6) #define fp REG (fp) #define sp REG (sp) picolibc-1.8.11/libc/machine/m68k/machine/000077500000000000000000000000001513574234600201065ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/m68k/machine/CMakeLists.txt000066400000000000000000000031361513574234600226510ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_headers(machine fenv.h fenv-fp.h ) picolibc-1.8.11/libc/machine/m68k/machine/fenv-fp.h000066400000000000000000000160201513574234600216170ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2023 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _M68K_EXCEPT_SHIFT 6 __declare_fenv_inline(int) feclearexcept(int excepts) { /* Mask excepts to be sure only supported flag bits are set */ excepts &= FE_ALL_EXCEPT; /* Clear the requested flags */ fexcept_t fpsr; __asm__ volatile("fmove.l %%fpsr, %0" : "=d"(fpsr)); fpsr &= ~excepts; __asm__ volatile("fmove.l %0, %%fpsr" : : "d"(fpsr)); return 0; } __declare_fenv_inline(int) fegetenv(fenv_t *envp) { /* Get the current fpcr and fpsr */ fenv_t fpcr; fexcept_t fpsr; __asm__ volatile("fmove.l %%fpcr, %0" : "=d"(fpcr)); __asm__ volatile("fmove.l %%fpsr, %0" : "=d"(fpsr)); /* Mix the exceptions and rounding mode together */ *envp = (fpcr & 0xff00) | ((fpcr >> 4) & 3) | (fpsr & 0xf8); return 0; } __declare_fenv_inline(int) fegetexceptflag(fexcept_t *flagp, int excepts) { /* Mask excepts to be sure only supported flag bits are set */ excepts &= FE_ALL_EXCEPT; /* Read the current fpsr */ fexcept_t fpsr; __asm__ volatile("fmove.l %%fpsr, %0" : "=d"(fpsr)); *flagp = (fpsr & excepts); return 0; } __declare_fenv_inline(int) fegetround(void) { fenv_t fpcr; __asm__ volatile("fmove.l %%fpcr, %0" : "=d"(fpcr)); return (fpcr >> 4) & 3; } __declare_fenv_inline(int) feholdexcept(fenv_t *envp) { fenv_t fpcr; fexcept_t fpsr; __asm__ volatile("fmove.l %%fpcr, %0" : "=d"(fpcr)); __asm__ volatile("fmove.l %%fpsr, %0" : "=d"(fpsr)); int excepts = fpsr & FE_ALL_EXCEPT; *envp = (fpcr & 0xff00) | ((fpcr >> 4) & 3) | (fpsr & 0xf8); /* map except flags to except enables and clear them */ fpcr &= ~(excepts << 6); fpsr &= ~excepts; /* Save to registers */ __asm__ volatile("fmove.l %0, %%fpcr" : : "d"(fpcr)); __asm__ volatile("fmove.l %0, %%fpsr" : : "d"(fpsr)); return 0; } __declare_fenv_inline(int) feraiseexcept(int excepts) { /* Mask excepts to be sure only supported flag bits are set */ excepts &= FE_ALL_EXCEPT; /* Set the requested exception flags */ fexcept_t fpsr; __asm__ volatile("fmove.l %%fpsr, %0" : "=d"(fpsr)); fpsr |= excepts; __asm__ volatile("fmove.l %0, %%fpsr" : : "d"(fpsr)); return 0; } __declare_fenv_inline(int) fesetexcept(int excepts) { return feraiseexcept(excepts); } __declare_fenv_inline(int) fesetenv(const fenv_t *envp) { fenv_t env = *envp; /* Get current fpcr and fpsr */ fenv_t fpcr; fexcept_t fpsr; __asm__ volatile("fmove.l %%fpcr, %0" : "=d"(fpcr)); __asm__ volatile("fmove.l %%fpsr, %0" : "=d"(fpsr)); /* Set the rounding mode */ fpcr = (fpcr & ~(0x3 << 4)) | (env & 3); /* Set the exception enables */ fpcr = (fpcr & 0xff) | (env & 0xff00); /* Set the exceptions */ fpsr = (fpsr & ~0xf8) | (env & 0xf8); /* Save to registers */ __asm__ volatile("fmove.l %0, %%fpcr" : : "d"(fpcr)); __asm__ volatile("fmove.l %0, %%fpsr" : : "d"(fpsr)); return 0; } __declare_fenv_inline(int) fesetexceptflag(const fexcept_t *flagp, int excepts) { excepts &= FE_ALL_EXCEPT; fexcept_t fpsr; __asm__ volatile("fmove.l %%fpsr, %0" : "=d"(fpsr)); fpsr &= ~excepts; fpsr |= (*flagp & excepts); __asm__ volatile("fmove.l %0, %%fpsr" : : "d"(fpsr)); return 0; } __declare_fenv_inline(int) fesetround(int rounding_mode) { fenv_t fpcr; if (rounding_mode & ~3) return 1; __asm__ volatile("fmove.l %%fpcr, %0" : "=d"(fpcr)); fpcr = (fpcr & ~(3 << 4)) | (rounding_mode << 4); __asm__ volatile("fmove.l %0, %%fpcr" : : "d"(fpcr)); return 0; } __declare_fenv_inline(int) fetestexcept(int excepts) { /* Mask excepts to be sure only supported flag bits are set */ excepts &= FE_ALL_EXCEPT; /* Read the current fpsr */ fexcept_t fpsr; __asm__ volatile("fmove.l %%fpsr, %0" : "=d"(fpsr)); return (fpsr & excepts); } __declare_fenv_inline(int) feupdateenv(const fenv_t *envp) { fenv_t env = *envp; /* Get current fpcr and fpsr */ fenv_t fpcr; fexcept_t fpsr; __asm__ volatile("fmove.l %%fpcr, %0" : "=d"(fpcr)); __asm__ volatile("fmove.l %%fpsr, %0" : "=d"(fpsr)); /* Set the rounding mode */ fpcr = (fpcr & ~(0x3 << 4)) | (env & 3); /* Set the exception enables */ fpcr = (fpcr & 0xff) | (env & 0xff00); /* Merge in exceptions */ fpsr |= (env & 0xf8); /* Save to registers */ __asm__ volatile("fmove.l %0, %%fpcr" : : "d"(fpcr)); __asm__ volatile("fmove.l %0, %%fpsr" : : "d"(fpsr)); return 0; } __declare_fenv_inline(int) feenableexcept(int excepts) { fenv_t old_fpcr, new_fpcr; __asm__ volatile("fmove.l %%fpcr, %0" : "=d"(old_fpcr)); /* Enable exceptions */ new_fpcr = old_fpcr | ((excepts & FE_ALL_EXCEPT) << _M68K_EXCEPT_SHIFT); __asm__ volatile("fmove.l %0, %%fpcr" : : "d"(new_fpcr)); return (old_fpcr >> _M68K_EXCEPT_SHIFT) & FE_ALL_EXCEPT; } __declare_fenv_inline(int) fedisableexcept(int excepts) { fenv_t old_fpcr, new_fpcr; __asm__ volatile("fmove.l %%fpcr, %0" : "=d"(old_fpcr)); /* Disable exceptions */ new_fpcr = old_fpcr & ~((excepts & FE_ALL_EXCEPT) << _M68K_EXCEPT_SHIFT); __asm__ volatile("fmove.l %0, %%fpcr" : : "d"(new_fpcr)); return (old_fpcr >> _M68K_EXCEPT_SHIFT) & FE_ALL_EXCEPT; } __declare_fenv_inline(int) fegetexcept(void) { fenv_t fpcr; __asm__ volatile("fmove.l %%fpcr, %0" : "=d"(fpcr)); return (fpcr >> _M68K_EXCEPT_SHIFT) & FE_ALL_EXCEPT; } picolibc-1.8.11/libc/machine/m68k/machine/fenv.h000066400000000000000000000047131513574234600212220ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2023 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MACHINE_FENV_H_ #define _MACHINE_FENV_H_ #include _BEGIN_STD_C typedef int fenv_t; typedef int fexcept_t; #if defined(__HAVE_68881__) #define FE_INVALID 0x0080 #define FE_OVERFLOW 0x0040 #define FE_UNDERFLOW 0x0020 #define FE_DIVBYZERO 0x0010 #define FE_INEXACT 0x0008 #define FE_ALL_EXCEPT (FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW | FE_DIVBYZERO | FE_INEXACT) #define FE_TONEAREST 0x0000 #define FE_TOWARDZERO 0x0001 #define FE_DOWNWARD 0x0002 #define FE_UPWARD 0x0003 #else #define FE_TONEAREST 0x0000 #endif #if !defined(__declare_fenv_inline) && defined(__declare_extern_inline) #define __declare_fenv_inline(type) __declare_extern_inline(type) #endif #ifdef __declare_fenv_inline #if defined(__HAVE_68881__) #include #else #include #endif #endif _END_STD_C #endif /* _MACHINE_FENV_H_ */ picolibc-1.8.11/libc/machine/m68k/machine/meson.build000066400000000000000000000033421513574234600222520ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2024 Keith Packard, # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_sys_headers_machine = [ 'fenv.h', 'fenv-fp.h' ] if really_install install_headers(inc_sys_headers_machine, install_dir: include_dir / 'machine') endif picolibc-1.8.11/libc/machine/m68k/memcpy.S000066400000000000000000000056761513574234600201360ustar00rootroot00000000000000/* a-memcpy.s -- memcpy, optimised for m68k asm * * Copyright (c) 2007 mocom software GmbH & Co KG) * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include "m68kasm.h" #if defined (__mcoldfire__) || defined (__mc68020__) || defined (__mc68030__) || defined (__mc68040__) || defined (__mc68060__) # define MISALIGNED_OK 1 #else # define MISALIGNED_OK 0 #endif .text .align 4 .globl SYM(memcpy) .type SYM(memcpy), @function /* memcpy, optimised * * strategy: * - no argument testing (the original memcpy from the GNU lib does * no checking either) * - make sure the destination pointer (the write pointer) is long word * aligned. This is the best you can do, because writing to unaligned * addresses can be the most costfull thing you could do. * - Once you have figured that out, we do a little loop unrolling * to further improve speed. */ SYM(memcpy): move.l 4(sp),a0 | dest ptr move.l 8(sp),a1 | src ptr move.l 12(sp),d1 | len cmp.l #8,d1 | if fewer than 8 bytes to transfer, blo .Lresidue | do not optimise #if !MISALIGNED_OK /* Goto .Lresidue if either dest or src is not 4-byte aligned */ move.l a0,d0 and.l #3,d0 bne .Lresidue move.l a1,d0 and.l #3,d0 bne .Lresidue #else /* MISALIGNED_OK */ /* align dest */ move.l a0,d0 | copy of dest neg.l d0 and.l #3,d0 | look for the lower two only beq 2f | is aligned? sub.l d0,d1 lsr.l #1,d0 | word align needed? bcc 1f move.b (a1)+,(a0)+ 1: lsr.l #1,d0 | long align needed? bcc 2f move.w (a1)+,(a0)+ 2: #endif /* !MISALIGNED_OK */ /* long word transfers */ move.l d1,d0 and.l #3,d1 | byte residue lsr.l #3,d0 bcc 1f | carry set for 4-byte residue move.l (a1)+,(a0)+ 1: lsr.l #1,d0 | number of 16-byte transfers bcc .Lcopy | carry set for 8-byte residue bra .Lcopy8 1: move.l (a1)+,(a0)+ move.l (a1)+,(a0)+ .Lcopy8: move.l (a1)+,(a0)+ move.l (a1)+,(a0)+ .Lcopy: #if !defined (__mcoldfire__) dbra d0,1b sub.l #0x10000,d0 #else subq.l #1,d0 #endif bpl 1b bra .Lresidue 1: move.b (a1)+,(a0)+ | move residue bytes .Lresidue: #if !defined (__mcoldfire__) dbra d1,1b | loop until done sub.l #0x10000,d1 #else subq.l #1,d1 #endif bpl 1b move.l 4(sp),a0 | return value move.l a0,d0 | in both a0 and d0 rts .size SYM(memcpy), . - SYM(memcpy) #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/m68k/memset.S000066400000000000000000000052121513574234600201200ustar00rootroot00000000000000/* a-memset.s -- memset, optimised for fido asm * * Copyright (c) 2007 mocom software GmbH & Co KG) * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include "m68kasm.h" .text .align 4 .globl SYM(memset) .type SYM(memset), @function | memset, optimised | | strategy: | - no argument testing (the original memcpy from the GNU lib does | no checking either) | - make sure the destination pointer (the write pointer) is long word | aligned. This is the best you can do, because writing to unaligned | addresses can be the most costfull thing one could do. | - we fill long word wise if possible | | VG, 2006 | | bugfixes: | - distribution of byte value improved - in cases someone gives | non-byte value | - residue byte transfer was not working | | VG, April 2007 | SYM(memset): move.l 4(sp),a0 | dest ptr move.l 8(sp),d0 | value move.l 12(sp),d1 | len cmp.l #16,d1 blo .Lbset | below, byte fills | move.l d2,-(sp) | need a register move.b d0,d2 | distribute low byte to all byte in word lsl.l #8,d0 move.b d2,d0 move.w d0,d2 swap d0 | rotate 16 move.w d2,d0 | move.l a0,d2 | copy of src neg.l d2 | 1 2 3 ==> 3 2 1 and.l #3,d2 beq 2f | is aligned | sub.l d2,d1 | fix length lsr.l #1,d2 | word align needed? bcc 1f move.b d0,(a0)+ | fill byte 1: lsr.l #1,d2 | long align needed? bcc 2f move.w d0,(a0)+ | fill word 2: move.l d1,d2 | number of long transfers (at least 3) lsr.l #2,d2 subq.l #1,d2 1: move.l d0,(a0)+ | fill long words .Llset: #if !defined (__mcoldfire__) dbra d2,1b | loop until done sub.l #0x10000,d2 #else subq.l #1,d2 #endif bpl 1b and.l #3,d1 | residue byte transfers, fixed move.l (sp)+,d2 | restore d2 bra .Lbset 1: move.b d0,(a0)+ | fill residue bytes .Lbset: #if !defined (__mcoldfire__) dbra d1,1b | loop until done sub.l #0x10000,d1 #else subq.l #1,d1 #endif bpl 1b move.l 4(sp),a0 | return value move.l a0,d0 | in both a0 and d0 rts .size SYM(memset), . - SYM(memset) #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/m68k/meson.build000066400000000000000000000040321513574234600206430ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2020 Thomas Daede # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'interrupt.c', 'memcpy.S', 'memset.S', 'read_tp.S', 'set_tls.c', 'setjmp.S', 'strcpy.c', 'strlen.c', 'tls.c', ] subdir('machine') foreach params : targets target = params['name'] target_dir = params['dir'] target_c_args = params['c_args'] set_variable('lib_machine' + target, static_library('machine' + target, srcs_machine, pic: false, include_directories: inc, c_args: target_c_args + c_args + arg_fnobuiltin + arg_fnolto)) endforeach picolibc-1.8.11/libc/machine/m68k/read_tp.S000066400000000000000000000035561513574234600202550ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #ifdef __THREAD_LOCAL_STORAGE .section .text.__m68k_read_tp,"ax",@progbits .align 2 .globl __m68k_read_tp .type __m6k_read_tp, @function __m68k_read_tp: .cfi_startproc move.l __tls,%a0 rts .cfi_endproc .size __m68k_read_tp, . - __m68k_read_tp #endif picolibc-1.8.11/libc/machine/m68k/set_tls.c000066400000000000000000000034071513574234600203270ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #ifdef __THREAD_LOCAL_STORAGE_API #include "tls-local.h" #define TP_OFFSET 0x7000 void _set_tls(void *tls) { __tls = (uint8_t *)tls + TP_OFFSET; } #endif picolibc-1.8.11/libc/machine/m68k/setjmp.S000066400000000000000000000035631513574234600201370ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include #include "m68kasm.h" .global SYM (setjmp) .type SYM (setjmp), @function .global SYM (longjmp) .type SYM (longjmp), @function SYM (setjmp): moveal sp@(4),a0 movel sp@(0),a0@(12) movel sp,a0@(8) moveml d2-d7/a2-a6,a0@(20) clrl d0 rts .size SYM(setjmp), . - SYM(setjmp) SYM (longjmp): moveal sp@(4),a0 movel sp@(8),d0 bne 1f movel &1,d0 1: moveml a0@(20),d2-d7/a2-a6 moveal a0@(8),sp movel a0@(12),sp@ rts .size SYM(longjmp), . - SYM(longjmp) #ifdef M68881 .global SYM (setjmp_68881) .type SYM (setjmp_68881), @function .global SYM (longjmp_68881) .type SYM (longjmp_68881), @function SYM (setjmp_68881): moveal sp@(4),a0 movel sp@(0),a0@(12) movel sp,a0@(8) moveml d2-d7/a2-a6,a0@(20) fmovemx fp2-fp7,a0@(64) clrl d0 rts .size SYM(setjmp_68881), . - SYM(setjmp_68881) SYM (longjmp_68881): moveal sp@(4),a0 fmovemx a0@(64),fp2-fp7 movel sp@(8),d0 bne 1f movel &1,d0 1: moveml a0@(20),d2-d7/a2-a6 moveal a0@(8),sp movel a0@(12),sp@ rts .size SYM(longjmp_68881), . - SYM(longjmp_68881) #endif #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/m68k/strcpy.c000066400000000000000000000031071513574234600201730ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* * C library strcpy routine * * This routine has been optimized for the CPU32+. * It should run on all 68k machines. * * W. Eric Norum * Saskatchewan Accelerator Laboratory * University of Saskatchewan * Saskatoon, Saskatchewan, CANADA * eric@skatter.usask.ca */ #include #include /* * Copy bytes using CPU32+ loop mode if possible */ #undef strcpy char * strcpy(char *to, const char *from) { char *pto = to; unsigned int n = 0xFFFF; __asm__ volatile("1:\n" "\tmove.b (%0)+,(%1)+\n" #if defined(__mcpu32__) "\tdbeq %2,1b\n" #endif "\tbne.b 1b\n" : "=a"(from), "=a"(pto), "=d"(n) : "0"(from), "1"(pto), "2"(n) : "cc", "memory"); return to; } picolibc-1.8.11/libc/machine/m68k/strlen.c000066400000000000000000000030131513574234600201520ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* * C library strlen routine * * This routine has been optimized for the CPU32+. * It should run on all 68k machines. * * W. Eric Norum * Saskatchewan Accelerator Laboratory * University of Saskatchewan * Saskatoon, Saskatchewan, CANADA * eric@skatter.usask.ca */ #include #include /* * Test bytes using CPU32+ loop mode if possible. */ size_t strlen(const char *str) { unsigned int n = ~0; const char *cp = str; __asm__ volatile("1:\n" "\ttst.b (%0)+\n" #if defined(__mcpu32__) "\tdbeq %1,1b\n" #endif "\tbne.b 1b\n" : "=a"(cp), "=d"(n) : "0"(cp), "1"(n) : "cc"); return (cp - str) - 1; } picolibc-1.8.11/libc/machine/m68k/tls-local.h000066400000000000000000000033611513574234600205500ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _TLS_LOCAL_H_ #define _TLS_LOCAL_H_ extern void *__tls; void _set_tls(void *); void *__m68k_read_tp(void); #endif /* _TLS_LOCAL_H_ */ picolibc-1.8.11/libc/machine/m68k/tls.c000066400000000000000000000032631513574234600174540ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #ifdef __THREAD_LOCAL_STORAGE #include "tls-local.h" void *__tls; #endif picolibc-1.8.11/libc/machine/m88k/000077500000000000000000000000001513574234600165045ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/m88k/setjmp.S000066400000000000000000000035351513574234600201400ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* This is a simple version of setjmp and longjmp. Ian Lance Taylor, Cygnus Support, 15 July 1993. */ /* We need to save the address of the return instruction, which is in r1, as well as general register r14 through r25. If we are compiling for the 88110 with the extended register file, we also need to save registers x22 through x29. The jmp_buf should be 52 bytes long in the one case, 84 bytes in the other. */ /* int setjmp (jmp_buf); */ #include globl _setjmp _setjmp: st r1,r2,0 st.d r14,r2,4 st.d r16,r2,12 st.d r18,r2,20 st.d r20,r2,28 st.d r22,r2,36 st.d r24,r2,44 #ifdef __m88110__ /* These instructions are just a guess, and gas doesn't support them anyhow. */ st.d x22,r2,52 st.d x24,r2,60 st.d x26,r2,68 st.d x28,r2,76 #endif jmp r1 global _longjmp _longjmp: ld r1,r2,0 ld.d r14,r2,4 ld.d r16,r2,12 ld.d r18,r2,20 ld.d r20,r2,28 ld.d r22,r2,36 ld.d r24,r2,44 #ifdef __m88110__ /* These instructions are just a guess, and gas doesn't support them anyhow. */ ld.d x22,r2,52 ld.d x24,r2,60 ld.d x26,r2,68 ld.d x28,r2,76 #endif jmp r1 picolibc-1.8.11/libc/machine/mep/000077500000000000000000000000001513574234600164765ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/mep/setjmp.S000066400000000000000000000041141513574234600201240ustar00rootroot00000000000000/* Copyright (c) 2003 DJ Delorie, Red Hat Inc. */ #include # # Setjmp/longjmp for MeP # # # 19 32-bit words in the jmpbuf: # $0 # $1 # ... # $15 # $pc # $hi # $lo # # Note that $0 is saved but not restored. It can't be restored # as it's the return value of setjmp, but we save it in case # some application wants to see it in the jmp_buf. Ideally, # we should not need to save anything that is call-clobbered, # but you never know what the user is going to tell gcc with -f # options. .noregerr .text .globl setjmp .type setjmp,@function setjmp: # $1 is the address of the buffer. We return 0 in $0. sw $0, ($1) sw $1, 4($1) sw $2, 8($1) sw $3, 12($1) sw $4, 16($1) sw $5, 20($1) sw $6, 24($1) sw $7, 28($1) sw $8, 32($1) sw $9, 36($1) sw $10, 40($1) sw $11, 44($1) sw $12, 48($1) sw $13, 52($1) sw $14, 56($1) sw $15, 60($1) ldc $0, $lp sw $0, 64($1) ldc $0, $opt sra $0, 24 and3 $0, $0, 3 beqz $0, sj_skip_hilo ldc $0, $hi sw $0, 68($1) ldc $0, $lo sw $0, 72($1) sj_skip_hilo: mov $0, 0 ret .globl longjmp .type longjmp,@function longjmp: # $1 is the address of the buffer. $2 is the value setjmp # returns. We do not faithfully restore $0 or $lp, because # the act of calling setjmp clobbered those anyway. bnez $2, rv_not_zero mov $2, 1 rv_not_zero: # We restore $sp first so we can save the return value there, # otherwise we'd need to have another unrestored register. lw $15, 60($1) add3 $sp, $sp, -4 sw $2, ($sp) # Now restore the general registers. lw $2, 8($1) lw $3, 12($1) lw $4, 16($1) lw $5, 20($1) lw $6, 24($1) lw $7, 28($1) lw $8, 32($1) lw $9, 36($1) lw $10, 40($1) lw $11, 44($1) lw $12, 48($1) lw $13, 52($1) lw $14, 56($1) # We restore $pc's value to $lp so that we can just ret later. lw $0, 64($1) stc $0, $lp ldc $0, $opt sra $0, 24 and3 $0, $0, 3 beqz $0, lj_skip_hilo lw $0, 68($1) stc $0, $hi lw $0, 72($1) stc $0, $lo lj_skip_hilo: # Restore $1 lw $1, 8($1) # Get the return value off the stack, and restore the stack. lw $0, ($sp) add3 $sp, $sp, 4 ret picolibc-1.8.11/libc/machine/microblaze/000077500000000000000000000000001513574234600200445ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/microblaze/CMakeLists.txt000066400000000000000000000033141513574234600226050ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2023 Advanced Micro Devices, Inc. (AMD) # Copyright © 2023 Alp Sayin # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources_flags("-fno-builtin" abort.c longjmp.S setjmp.S strcmp.S strcpy.c strlen.c ) picolibc-1.8.11/libc/machine/microblaze/abort.c000066400000000000000000000055571513574234600213330ustar00rootroot00000000000000/* Copyright (c) 2001, 2009 Xilinx, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of Xilinx nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* NetWare can not use this implementation of abort. It provides its own version of abort in clib.nlm. If we can not use clib.nlm, then we must write abort in sys/netware. */ #include #ifdef ABORT_PROVIDED int _dummy_abort = 1; #else /* FUNCTION <>---abnormal termination of a program INDEX abort SYNOPSIS #include void abort(void); DESCRIPTION Use <> to signal that your program has detected a condition it cannot deal with. Normally, <> ends your program's execution. Before terminating your program, <> raises the exception <> (using `<>'). If you have used <> to register an exception handler for this condition, that handler has the opportunity to retain control, thereby avoiding program termination. In this implementation, <> does not perform any stream- or file-related cleanup (the host environment may do so; if not, you can arrange for your program to do its own cleanup with a <> exception handler). RETURNS <> does not return to its caller. PORTABILITY ANSI C requires <>. Supporting OS subroutines required: <<_exit>> and optionally, <>. */ #include #include #include void abort(void) { #ifdef ABORT_MESSAGE write(2, "Abort called\n", sizeof("Abort called\n") - 1); #endif while (1) { exit(1); } } #endif picolibc-1.8.11/libc/machine/microblaze/longjmp.S000066400000000000000000000054071513574234600216440ustar00rootroot00000000000000/* Copyright (c) 2001, 2009 Xilinx, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of Xilinx nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * longjmp - non-local jump to a saved stack context * args - r5 - jmp_buf * r6 - val * * jmpbuf frame structure * --------------------- * * +-------------+ + 0 * | r1 | * +-------------+ + 4 * | r13 | * | . | * | . | * | . | * | r31 | * +-------------+ + 80 * | . | * | . | */ #include .globl longjmp .section .text .align 2 .ent longjmp longjmp: lwi r1, r5, 0 lwi r13, r5, 4 lwi r14, r5, 8 lwi r15, r5, 12 lwi r16, r5, 16 lwi r17, r5, 20 lwi r18, r5, 24 lwi r19, r5, 28 lwi r20, r5, 32 lwi r21, r5, 36 lwi r22, r5, 40 lwi r23, r5, 44 lwi r24, r5, 48 lwi r25, r5, 52 lwi r26, r5, 56 lwi r27, r5, 60 lwi r28, r5, 64 lwi r29, r5, 68 lwi r30, r5, 72 lwi r31, r5, 76 rtsd r15, 8 or r3, r0, r6 .end longjmp picolibc-1.8.11/libc/machine/microblaze/mb_endian.h000066400000000000000000000012131513574234600221260ustar00rootroot00000000000000/* Copyright (c) 2013 Corinna Vinschen */ #ifndef __MB_ENDIAN_H #define __MB_ENDIAN_H /* Convenience macros for loading and store 4 bytes in a byte invariant way with * a singe instruction. Endianess affects this and we rely on MicroBlaze * load/store reverse instructions to do the trick on little-endian systems. */ #ifdef __LITTLE_ENDIAN__ #define LOAD4BYTES(rD, rA, rB) "\tlwr\t" rD ", " rA ", " rB "\n" #define STORE4BYTES(rD, rA, rB) "\tswr\t" rD ", " rA ", " rB "\n" #else #define LOAD4BYTES(rD, rA, rB) "\tlw\t" rD ", " rA ", " rB "\n" #define STORE4BYTES(rD, rA, rB) "\tsw\t" rD ", " rA ", " rB "\n" #endif #endif picolibc-1.8.11/libc/machine/microblaze/meson.build000066400000000000000000000033521513574234600222110ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2023 Advanced Micro Devices, Inc. (AMD) # Copyright © 2023 Alp Sayin # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'abort.c', 'longjmp.S', 'setjmp.S', 'strcmp.c', 'strcpy.c', 'strlen.c', ] src_machine = files(srcs_machine) picolibc-1.8.11/libc/machine/microblaze/setjmp.S000066400000000000000000000053571513574234600215040ustar00rootroot00000000000000/* Copyright (c) 2001, 2009 Xilinx, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of Xilinx nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * setjmp - save stack context for non-local goto * args - r5 - jmp_buf * * jmpbuf frame structure * --------------------- * * +-------------+ + 0 * | r1 | * +-------------+ + 4 * | r13 | * | . | * | . | * | . | * | r31 | * +-------------+ + 80 * | . | * | . | */ #include .globl setjmp .section .text .align 2 .ent setjmp setjmp: swi r1, r5, 0 swi r13, r5, 4 swi r14, r5, 8 swi r15, r5, 12 swi r16, r5, 16 swi r17, r5, 20 swi r18, r5, 24 swi r19, r5, 28 swi r20, r5, 32 swi r21, r5, 36 swi r22, r5, 40 swi r23, r5, 44 swi r24, r5, 48 swi r25, r5, 52 swi r26, r5, 56 swi r27, r5, 60 swi r28, r5, 64 swi r29, r5, 68 swi r30, r5, 72 swi r31, r5, 76 rtsd r15, 8 or r3, r0, r0 .end setjmp picolibc-1.8.11/libc/machine/microblaze/strcmp.c000066400000000000000000000203301513574234600215160ustar00rootroot00000000000000/* Copyright (c) 2009 Xilinx, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of Xilinx nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. FUNCTION <>---character string compare INDEX strcmp SYNOPSIS #include int strcmp(const char *<[a]>, const char *<[b]>); DESCRIPTION <> compares the string at <[a]> to the string at <[b]>. RETURNS If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>, <> returns a number greater than zero. If the two strings match, <> returns zero. If <<*<[a]>>> sorts lexicographically before <<*<[b]>>>, <> returns a number less than zero. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF strcmp ansi pure */ #include #include #include /* Nonzero if either X or Y is not aligned on a "long" boundary. */ #define UNALIGNED(X, Y) (((long)X & (sizeof(long) - 1)) | ((long)Y & (sizeof(long) - 1))) /* DETECTNULL returns nonzero if (long)X contains a NULL byte. */ #if LONG_MAX == 2147483647L #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) #else #if LONG_MAX == 9223372036854775807L #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) #else #error long int is not a 32bit or 64bit type. #endif #endif #ifndef DETECTNULL #error long int is not a 32bit or 64bit byte #endif int strcmp(const char *s1, const char *s2) { #ifndef HAVE_HW_PCMP #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; } return (*(unsigned char *)s1) - (*(unsigned char *)s2); #else unsigned long *a1; unsigned long *a2; /* If s1 or s2 are unaligned, then compare bytes. */ if (!UNALIGNED(s1, s2)) { /* If s1 and s2 are word-aligned, compare them a word at a time. */ a1 = (unsigned long *)s1; a2 = (unsigned long *)s2; while (*a1 == *a2) { /* To get here, *a1 == *a2, thus if we find a null in *a1, then the strings must be equal, so return zero. */ if (DETECTNULL(*a1)) return 0; a1++; a2++; } /* A difference was detected in last few bytes of s1, so search bytewise */ s1 = (char *)a1; s2 = (char *)a2; } while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; } return (*(unsigned char *)s1) - (*(unsigned char *)s2); #endif /* not __PREFER_SIZE_OVER_SPEED */ #else #include "mb_endian.h" __asm__ volatile( " \n\ or r9, r0, r0 /* Index register */\n\ check_alignment: \n\ andi r3, r5, 3 \n\ andi r4, r6, 3 \n\ bnei r3, try_align_args \n\ bnei r4, regular_strcmp /* At this point we don't have a choice */ \n\ cmp_loop: \n" LOAD4BYTES( "r3", "r5", "r9") LOAD4BYTES( "r4", "r6", "r9") " \n\ pcmpbf r7, r3, r0 /* See if there is Null byte */ \n\ bnei r7, end_cmp_loop /* IF yes (r7 > 0) use byte compares in end_cmp_loop */ \n\ cmpu r7, r4, r3 /* ELSE compare whole word */ \n\ bnei r7, end_cmp \n\ brid cmp_loop \n\ addik r9, r9, 4 /* delay slot */ \n\ end_cmp_loop: \n\ lbu r3, r5, r9 /* byte compare loop */ \n\ lbu r4, r6, r9 \n\ cmpu r7, r4, r3 /* Compare bytes */ \n\ bnei r7, end_cmp_early \n\ bneid r3, end_cmp_loop /* If reached null on one string, terminate */ \n\ addik r9, r9, 1 /* delay slot */ \n\ end_cmp_early: \n\ rtsd r15, 8 \n\ or r3, r0, r7 \n\ try_align_args: \n\ xor r7, r4, r3 \n\ bnei r7, regular_strcmp /* cannot align args */ \n\ rsubik r10, r3, 4 /* Number of initial bytes to align */ \n\ align_loop: \n\ lbu r3, r5, r9 \n\ lbu r4, r6, r9 \n\ cmpu r7, r4, r3 \n\ bnei r7, end_cmp \n\ beqi r3, end_cmp \n\ addik r10, r10, -1 \n\ beqid r10, cmp_loop \n\ addik r9, r9, 1 \n\ bri align_loop \n\ regular_strcmp: \n\ lbu r3, r5, r9 \n\ lbu r4, r6, r9 \n\ cmpu r7, r4, r3 \n\ bnei r7, end_cmp \n\ beqi r3, end_cmp \n\ brid regular_strcmp \n\ addik r9, r9, 1 \n\ end_cmp: \n\ rtsd r15, 8 \n\ or r3, r0, r7 /* Return strcmp result */"); #endif /* ! HAVE_HW_PCMP */ } picolibc-1.8.11/libc/machine/microblaze/strcpy.c000066400000000000000000000141151513574234600215360ustar00rootroot00000000000000/* Copyright (c) 2009 Xilinx, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of Xilinx nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. FUNCTION <>---copy string INDEX strcpy SYNOPSIS #include char *strcpy(char *restrict <[dst]>, const char *restrict <[src]>); DESCRIPTION <> copies the string pointed to by <[src]> (including the terminating null character) to the array pointed to by <[dst]>. RETURNS This function returns the initial value of <[dst]>. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF strcpy ansi pure */ #include #include #include /*SUPPRESS 560*/ /*SUPPRESS 530*/ /* Nonzero if either X or Y is not aligned on a "long" boundary. */ #define UNALIGNED(X, Y) (((long)X & (sizeof(long) - 1)) | ((long)Y & (sizeof(long) - 1))) #if LONG_MAX == 2147483647L #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) #else #if LONG_MAX == 9223372036854775807L /* Nonzero if X (a long int) contains a NULL byte. */ #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) #else #error long int is not a 32bit or 64bit type. #endif #endif #ifndef DETECTNULL #error long int is not a 32bit or 64bit byte #endif char * strcpy(char * __restrict dst0, const char * __restrict src0) { #ifndef HAVE_HW_PCMP #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) char *s = dst0; while ((*dst0++ = *src0++)) ; return s; #else char *dst = dst0; const char *src = src0; long *aligned_dst; const long *aligned_src; /* If SRC or DEST is unaligned, then copy bytes. */ if (!UNALIGNED(src, dst)) { aligned_dst = (long *)dst; aligned_src = (long *)src; /* SRC and DEST are both "long int" aligned, try to do "long int" sized copies. */ while (!DETECTNULL(*aligned_src)) { *aligned_dst++ = *aligned_src++; } dst = (char *)aligned_dst; src = (char *)aligned_src; } while ((*dst++ = *src++)) ; return dst0; #endif /* not __PREFER_SIZE_OVER_SPEED */ #else #include "mb_endian.h" __asm__ volatile(" \n\ or r9, r0, r0 /* Index register */ \n\ check_alignment: \n\ andi r3, r5, 3 \n\ andi r4, r6, 3 \n\ bnei r3, try_align_args \n\ bnei r4, regular_strcpy /* At this point we dont have a choice */ \n\ cpy_loop: \n" LOAD4BYTES("r3", "r6", "r9") " \n\ pcmpbf r4, r0, r3 \n\ bnei r4, cpy_bytes /* If r4 != 0, then null present within string */\n" STORE4BYTES( "r3", "r5", "r9") " \n\ brid cpy_loop \n\ addik r9, r9, 4 \n\ cpy_bytes: \n\ lbu r3, r6, r9 \n\ sb r3, r5, r9 \n\ addik r4, r4, -1 \n\ bneid r4, cpy_bytes \n\ addik r9, r9, 1 /* delay slot */\n\ cpy_null: \n\ rtsd r15, 8 \n\ or r3, r0, r5 /* Return strcpy result */\n\ try_align_args: \n\ xor r7, r4, r3 \n\ bnei r7, regular_strcpy /* cannot align args */\n\ rsubik r10, r3, 4 /* Number of initial bytes to align */\n\ align_loop: \n\ lbu r3, r6, r9 \n\ sb r3, r5, r9 \n\ beqid r3, end_cpy /* Break if we have seen null character */\n\ addik r10, r10, -1 \n\ bneid r10, align_loop \n\ addik r9, r9, 1 \n\ bri cpy_loop \n\ regular_strcpy: \n\ lbu r3, r6, r9 \n\ sb r3, r5, r9 \n\ bneid r3, regular_strcpy \n\ addik r9, r9, 1 \n\ end_cpy: \n\ rtsd r15, 8 \n\ or r3, r0, r5 /* Return strcpy result */"); #endif /* ! HAVE_HW_PCMP */ } picolibc-1.8.11/libc/machine/microblaze/strlen.c000066400000000000000000000124321513574234600215210ustar00rootroot00000000000000/* Copyright (c) 2009 Xilinx, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of Xilinx nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. FUNCTION <>---character string length INDEX strlen SYNOPSIS #include size_t strlen(const char *<[str]>); DESCRIPTION The <> function works out the length of the string starting at <<*<[str]>>> by counting chararacters until it reaches a <> character. RETURNS <> returns the character count. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF strlen ansi pure */ #include #include #include #define LBLOCKSIZE (sizeof(long)) #define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) #if LONG_MAX == 2147483647L #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) #else #if LONG_MAX == 9223372036854775807L /* Nonzero if X (a long int) contains a NULL byte. */ #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) #else #error long int is not a 32bit or 64bit type. #endif #endif #ifndef DETECTNULL #error long int is not a 32bit or 64bit byte #endif size_t strlen(const char *str) { #ifndef HAVE_HW_PCMP #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) const char *start = str; while (*str) str++; return str - start; #else const char *start = str; unsigned long *aligned_addr; if (!UNALIGNED(str)) { /* If the string is word-aligned, we can check for the presence of a null in each word-sized block. */ aligned_addr = (unsigned long *)str; while (!DETECTNULL(*aligned_addr)) aligned_addr++; /* Once a null is detected, we check each byte in that block for a precise position of the null. */ str = (char *)aligned_addr; } while (*str) str++; return str - start; #endif /* not __PREFER_SIZE_OVER_SPEED */ #else #include "mb_endian.h" __asm__ volatile(" \n\ or r9, r0, r0 /* Index register */ \n\ check_alignment: \n\ andi r3, r5, 3 \n\ bnei r3, align_arg \n\ len_loop: \n" LOAD4BYTES( "r3", "r5", "r9") " \n\ pcmpbf r4, r3, r0 \n\ bnei r4, end_len \n\ brid len_loop \n\ addik r9, r9, 4 \n\ end_len: \n\ lbu r3, r5, r9 \n\ beqi r3, done_len \n\ brid end_len \n\ addik r9, r9, 1 \n\ done_len: \n\ rtsd r15, 8 \n\ or r3, r0, r9 /* Return len */ \n\ align_arg: \n\ rsubik r10, r3, 4 \n\ align_loop: \n\ lbu r3, r5, r9 \n\ beqid r3, done_len \n\ addik r10, r10, -1 \n\ bneid r10, align_loop \n\ addik r9, r9, 1 \n\ bri len_loop"); #endif /* ! HAVE_HW_PCMP */ } picolibc-1.8.11/libc/machine/mips/000077500000000000000000000000001513574234600166655ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/mips/CMakeLists.txt000066400000000000000000000032751513574234600214340ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # add_subdirectory(machine) picolibc_sources_flags("-fno-builtin" memcpy.S memset.S setjmp.S strcmp.S strlen.c strncpy.c tls.c ) picolibc-1.8.11/libc/machine/mips/machine/000077500000000000000000000000001513574234600202715ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/mips/machine/CMakeLists.txt000066400000000000000000000031611513574234600230320ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_headers(machine asm.h fenv.h fenv-fp.h regdef.h ) picolibc-1.8.11/libc/machine/mips/machine/asm.h000066400000000000000000000241601513574234600212250ustar00rootroot00000000000000/* * Copyright (c) 1996-2007 MIPS Technologies, Inc. * Copyright (C) 2009 CodeSourcery, LLC. * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright * notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with * the distribution. * * Neither the name of MIPS Technologies Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * asm.h: various macros to help assembly language writers */ #ifndef _MIPS_ASM_H_ #define _MIPS_ASM_H_ /* ABI specific stack frame layout and manipulation. */ #if _MIPS_SIM==_ABIO32 && ! __mips64 /* Standard O32 */ #define SZREG 4 /* saved register size */ #define REG_S sw /* store saved register */ #define REG_L lw /* load saved register */ #define SZARG 4 /* argument register size */ #define NARGSAVE 4 /* arg register space on caller stack */ #define ALSZ 7 /* stack alignment - 1 */ #define ALMASK (~7) /* stack alignment mask */ #define LOG2_STACK_ALGN 3 /* log2(8) */ #define SZPTR 4 /* pointer size */ #define LOG2_SZPTR 2 /* log2(4) */ #define PTR_S sw /* store pointer */ #define PTR_L lw /* load pointer */ #define PTR_SUBU subu /* decrement pointer */ #define PTR_ADDU addu /* increment pointer */ #define PTR .word /* pointer type pseudo */ #elif _MIPS_SIM==_ABIO32 && __mips64 /* Algorithmics O32+64-bit */ #define SZREG 8 /* saved register size */ #define REG_S sd /* store saved register */ #define REG_L ld /* load saved register */ #define SZARG 4 /* argument register size */ #define NARGSAVE 4 /* arg register space on caller stack */ #define ALSZ 7 /* stack alignment - 1 */ #define ALMASK (~7) /* stack alignment mask */ #define LOG2_STACK_ALGN 3 /* log2(8) */ #define SZPTR 4 /* pointer size */ #define LOG2_SZPTR 2 /* log2(4) */ #define PTR_S sw /* store pointer */ #define PTR_L lw /* load pointer */ #define PTR_SUBU subu /* decrement pointer */ #define PTR_ADDU addu /* increment pointer */ #define PTR .word /* pointer type pseudo */ #elif _MIPS_SIM==_ABIO64 /* Cygnus O64 */ #define SZREG 8 /* saved register size */ #define REG_S sd /* store saved register */ #define REG_L ld /* load saved register */ #define SZARG 8 /* argument register size */ #define NARGSAVE 4 /* arg register space on caller stack */ #define ALSZ 7 /* stack alignment - 1 */ #define ALMASK (~7) /* stack alignment mask */ #define LOG2_STACK_ALGN 3 /* log2(8) */ #define SZPTR 4 /* pointer size */ #define LOG2_SZPTR 2 /* log2(4) */ #define PTR_S sw /* store pointer */ #define PTR_L lw /* load pointer */ #define PTR_SUBU subu /* decrement pointer */ #define PTR_ADDU addu /* increment pointer */ #define PTR .word /* pointer type pseudo */ #elif _MIPS_SIM==_ABIN32 /* Standard N32 */ #define SZREG 8 /* saved register size */ #define REG_S sd /* store saved register */ #define REG_L ld /* load saved register */ #define SZARG 8 /* argument register size */ #define NARGSAVE 0 /* arg register space on caller stack */ #define ALSZ 15 /* stack alignment - 1 */ #define ALMASK (~15) /* stack alignment mask */ #define LOG2_STACK_ALGN 4 /* log2(16) */ #define SZPTR 4 /* pointer size */ #define LOG2_SZPTR 2 /* log2(4) */ #define PTR_S sw /* store pointer */ #define PTR_L lw /* load pointer */ #define PTR_SUBU subu /* decrement pointer (SGI uses sub) */ #define PTR_ADDU addu /* increment pointer (SGI uses add) */ #define PTR .word /* pointer type pseudo */ #elif _MIPS_SIM==_ABI64 /* Standard N64 */ #define SZREG 8 /* saved register size */ #define REG_S sd /* store saved register */ #define REG_L ld /* load saved register */ #define SZARG 8 /* argument register size */ #define NARGSAVE 0 /* arg register space on caller stack */ #define ALSZ 15 /* stack alignment - 1 */ #define ALMASK (~15) /* stack alignment mask */ #define LOG2_STACK_ALGN 4 /* log2(16) */ #define SZPTR 8 /* pointer size */ #define LOG2_SZPTR 3 /* log2(8) */ #define PTR_S sd /* store pointer */ #define PTR_L ld /* load pointer */ #define PTR_SUBU dsubu /* decrement pointer */ #define PTR_ADDU daddu /* increment pointer */ #define PTR .dword /* pointer type pseudo */ #else #error Unknown ABI #endif /* Concatenate two names. */ #ifdef __STDC__ # define _ASMCONCAT(A, B) A ## B #else # define _ASMCONCAT(A, B) A/**/B #endif /* Name of reset code section. */ #ifndef _RESET_SECTION # define _RESET_SECTION .section .reset, "ax", @progbits #endif #ifndef _RESET_SECTION_NAMED /* No function section support for now, since binutils fails to cope with external branches. */ # define _RESET_SECTION_NAMED(name) .pushsection .reset, "ax", @progbits #endif /* Name of boot code section. */ #ifndef _BOOT_SECTION # define _BOOT_SECTION .section .boot, "ax", @progbits #endif #ifndef _BOOT_SECTION_NAMED /* No function section support for now, since binutils fails to cope with external branches. */ # define _BOOT_SECTION_NAMED(name) .pushsection .boot, "ax", @progbits #endif /* Name of standard code section. */ #ifndef _NORMAL_SECTION_UNNAMED # define _NORMAL_SECTION_UNNAMED .section .text, "ax", @progbits #endif #ifndef _NORMAL_SECTION_NAMED # ifdef _FUNCTION_SECTIONS_ # define _NORMAL_SECTION_NAMED(name) .pushsection .text ##.name, "ax", @progbits # else # define _NORMAL_SECTION_NAMED(name) .pushsection .text, "ax", @progbits # endif #endif /* Default code section. */ #ifndef _TEXT_SECTION_NAMED # if defined(_RESETCODE) # define _TEXT_SECTION_NAMED _RESET_SECTION_NAMED # elif defined(_BOOTCODE) # define _TEXT_SECTION_NAMED _BOOT_SECTION_NAMED # else # define _TEXT_SECTION_NAMED _NORMAL_SECTION_NAMED # endif #endif #ifndef _TEXT_SECTION # if defined(_RESETCODE) # define _TEXT_SECTION _RESET_SECTION # elif defined(_BOOTCODE) # define _TEXT_SECTION _BOOT_SECTION # else # define _TEXT_SECTION _NORMAL_SECTION_UNNAMED # endif _TEXT_SECTION #endif /* * Leaf functions declarations. */ /* Global leaf function. */ #define LEAF(name) \ _TEXT_SECTION_NAMED(name); \ .globl name; \ .balign 4; \ .ent name; \ name: /* Static/Local leaf function. */ #define SLEAF(name) \ _TEXT_SECTION_NAMED(name); \ .balign 4; \ .ent name; \ name: /* Weak leaf function. */ #define WLEAF(name) \ _TEXT_SECTION_NAMED(name); \ .weakext name; \ .balign 4; \ .ent name; \ name: /* Weak alias leaf function. */ #define ALEAF(name,alias) \ _TEXT_SECTION_NAMED(name); \ .weakext alias,name; \ .balign 4; \ .ent name; \ name: /* * Alternative function entrypoints. */ /* Global alternative entrypoint. */ #define AENT(name) \ .globl name; \ .balign 4; \ .aent name; \ name: #define XLEAF(name) AENT(name) /* Local/static alternative entrypoint. */ #define SAENT(name) \ .balign 4; \ .aent name; \ name: #define SXLEAF(name) SAENT(name) /* * Leaf functions declarations. */ /* Global nested function. */ #define NESTED(name, framesz, rareg) \ _TEXT_SECTION_NAMED(name); \ .globl name; \ .balign 4; \ .ent name; \ .frame sp, framesz, rareg; \ name: /* Static/Local nested function. */ #define SNESTED(name, framesz, rareg) \ _TEXT_SECTION_NAMED(name); \ .balign 4; \ .ent name; \ .frame sp, framesz, rareg; \ name: /* Weak nested function. */ #define WNESTED(name, framesz, rareg) \ _TEXT_SECTION_NAMED(name); \ .weakext name; \ .balign 4; \ .ent name; \ .frame sp, framesz, rareg; \ name: /* Weak alias nested function. */ #define ANESTED(name, alias, framesz, rareg) \ _TEXT_SECTION_NAMED(name); \ .weakext alias, name; \ .balign 4; \ .ent name; \ .frame sp, framesz, rareg; \ name: /* * Function termination */ #define END(name) \ .size name,.-name; \ .end name; \ .popsection #define SEND(name) END(name) #define WEND(name) END(name) #define AEND(name,alias) END(name) /* * Global data declaration. */ #define EXPORT(name) \ .globl name; \ .type name,@object; \ name: /* * Global data declaration with size. */ #define EXPORTS(name,sz) \ .globl name; \ .type name,@object; \ .size name,sz; \ name: /* * Weak data declaration with size. */ #define WEXPORT(name,sz) \ .weakext name; \ .type name,@object; \ .size name,sz; \ name: /* * Global data reference with size. */ #define IMPORT(name, size) \ .extern name,size /* * Global zeroed data. */ #define BSS(name,size) \ .type name,@object; \ .comm name,size /* * Local zeroed data. */ #define LBSS(name,size) \ .lcomm name,size /* * Insert call to _mcount if profiling. */ #ifdef __PROFILING__ #define _MCOUNT \ .set push; \ .set noat; \ move $1,$31; \ jal _mcount; \ .set pop #else #define _MCOUNT #endif #endif picolibc-1.8.11/libc/machine/mips/machine/fenv-fp.h000066400000000000000000000105671513574234600220140ustar00rootroot00000000000000/*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2004-2005 David Schultz * 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$ */ __declare_fenv_inline(int) feclearexcept(int excepts) { fexcept_t fcsr; excepts &= FE_ALL_EXCEPT; __cfc1(fcsr); fcsr &= ~(excepts | (excepts << _FCSR_CAUSE_SHIFT)); __ctc1(fcsr); return (0); } __declare_fenv_inline(int) fegetexceptflag(fexcept_t *flagp, int excepts) { fexcept_t fcsr; excepts &= FE_ALL_EXCEPT; __cfc1(fcsr); *flagp = fcsr & excepts; return (0); } __declare_fenv_inline(int) fesetexceptflag(const fexcept_t *flagp, int excepts) { fexcept_t fcsr; excepts &= FE_ALL_EXCEPT; __cfc1(fcsr); fcsr &= ~excepts; fcsr |= *flagp & excepts; __ctc1(fcsr); return (0); } __declare_fenv_inline(int) feraiseexcept(int excepts) { fexcept_t fcsr; excepts &= FE_ALL_EXCEPT; __cfc1(fcsr); fcsr |= excepts | (excepts << _FCSR_CAUSE_SHIFT); __ctc1(fcsr); return (0); } __declare_fenv_inline(int) fesetexcept(int excepts) { fexcept_t fcsr; excepts &= FE_ALL_EXCEPT; __cfc1(fcsr); fcsr |= excepts | (excepts << _FCSR_CAUSE_SHIFT); __ctc1(fcsr); return (0); } __declare_fenv_inline(int) fetestexcept(int excepts) { fexcept_t fcsr; excepts &= FE_ALL_EXCEPT; __cfc1(fcsr); return (fcsr & excepts); } __declare_fenv_inline(int) fegetround(void) { fexcept_t fcsr; __cfc1(fcsr); return (fcsr & _ROUND_MASK); } __declare_fenv_inline(int) fesetround(int rounding_mode) { fexcept_t fcsr; if (rounding_mode & ~_ROUND_MASK) return (-1); __cfc1(fcsr); fcsr &= ~_ROUND_MASK; fcsr |= rounding_mode; __ctc1(fcsr); return (0); } __declare_fenv_inline(int) fegetenv(fenv_t *envp) { __cfc1(*envp); return (0); } __declare_fenv_inline(int) feholdexcept(fenv_t *envp) { fexcept_t fcsr; __cfc1(fcsr); *envp = fcsr; fcsr &= ~(FE_ALL_EXCEPT | _FCSR_ENABLE_MASK); __ctc1(fcsr); return (0); } __declare_fenv_inline(int) fesetenv(const fenv_t *envp) { __ctc1(*envp); return (0); } __declare_fenv_inline(int) feupdateenv(const fenv_t *envp) { fexcept_t fcsr; __cfc1(fcsr); fesetenv(envp); feraiseexcept(fcsr); return (0); } #if __BSD_VISIBLE /* We currently provide no external definitions of the functions below. */ __declare_fenv_inline(int) feenableexcept(int __mask) { fenv_t __old_fcsr, __new_fcsr; __cfc1(__old_fcsr); __new_fcsr = __old_fcsr | (__mask & FE_ALL_EXCEPT) << _FCSR_ENABLE_SHIFT; __ctc1(__new_fcsr); return ((__old_fcsr >> _FCSR_ENABLE_SHIFT) & FE_ALL_EXCEPT); } __declare_fenv_inline(int) fedisableexcept(int __mask) { fenv_t __old_fcsr, __new_fcsr; __cfc1(__old_fcsr); __new_fcsr = __old_fcsr & ~((__mask & FE_ALL_EXCEPT) << _FCSR_ENABLE_SHIFT); __ctc1(__new_fcsr); return ((__old_fcsr >> _FCSR_ENABLE_SHIFT) & FE_ALL_EXCEPT); } __declare_fenv_inline(int) fegetexcept(void) { fexcept_t fcsr; __cfc1(fcsr); return ((fcsr & _FCSR_ENABLE_MASK) >> _FCSR_ENABLE_SHIFT); } #endif /* __BSD_VISIBLE */ picolibc-1.8.11/libc/machine/mips/machine/fenv.h000066400000000000000000000056371513574234600214130ustar00rootroot00000000000000/*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2004-2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _MACHINE_FENV_H_ #define _MACHINE_FENV_H_ #include #if !defined(__mips_soft_float) && !defined(__mips_hard_float) #error compiler didnt set soft/hard float macros #endif _BEGIN_STD_C typedef int fenv_t; typedef int fexcept_t; #ifndef __mips_soft_float /* Exception flags */ #define _FCSR_CAUSE_SHIFT 10 #define FE_INVALID 0x0040 #define FE_DIVBYZERO 0x0020 #define FE_OVERFLOW 0x0010 #define FE_UNDERFLOW 0x0008 #define FE_INEXACT 0x0004 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) /* Rounding modes */ #define FE_TONEAREST 0x0000 #define FE_TOWARDZERO 0x0001 #define FE_UPWARD 0x0002 #define FE_DOWNWARD 0x0003 #define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO) /* We need to be able to map status flag positions to mask flag positions */ #define _FCSR_ENABLE_SHIFT 5 #define _FCSR_ENABLE_MASK (FE_ALL_EXCEPT << _FCSR_ENABLE_SHIFT) #define __cfc1(__fcsr) __asm__ __volatile__("cfc1 %0, $31" : "=r"(__fcsr)) #define __ctc1(__fcsr) __asm__ __volatile__("ctc1 %0, $31" ::"r"(__fcsr)) #else #define FE_TONEAREST 0x0000 #endif /* !__mips_soft_float */ #if !defined(__declare_fenv_inline) && defined(__declare_extern_inline) #define __declare_fenv_inline(type) __declare_extern_inline(type) #endif #ifdef __declare_fenv_inline #ifdef __mips_soft_float #include #else #include #endif #endif _END_STD_C #endif /* !_FENV_H_ */ picolibc-1.8.11/libc/machine/mips/machine/meson.build000066400000000000000000000034021513574234600224320ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_machine_headers_machine = [ 'asm.h', 'fenv.h', 'fenv-fp.h', 'regdef.h', ] if really_install install_headers(inc_machine_headers_machine, install_dir: include_dir / 'machine') endif picolibc-1.8.11/libc/machine/mips/machine/regdef.h000066400000000000000000000054411513574234600217020ustar00rootroot00000000000000/* * Copyright (c) 1996-2007 MIPS Technologies, Inc. * Copyright (C) 2009 CodeSourcery, LLC. * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright * notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with * the distribution. * * Neither the name of MIPS Technologies Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * regdef.h : MIPS Rx000 symbolic register names for assembler */ #ifndef _MIPS_REGDEF_H_ #define _MIPS_REGDEF_H_ #define zero $0 #define AT $1 #define v0 $2 #define v1 $3 #define a0 $4 #define a1 $5 #define a2 $6 #define a3 $7 #if _MIPS_SIM == _ABIN32 || _MIPS_SIM == _ABI64 || _MIPS_SIM == _ABIEABI #define a4 $8 #define a5 $9 #define a6 $10 #define a7 $11 #define t0 $12 #define t1 $13 #define t2 $14 #define t3 $15 #define ta0 $8 /* alias for $a4 */ #define ta1 $9 /* alias for $a5 */ #define ta2 $10 /* alias for $a6 */ #define ta3 $11 /* alias for $a7 */ #else #define t0 $8 #define t1 $9 #define t2 $10 #define t3 $11 #define t4 $12 #define t5 $13 #define t6 $14 #define t7 $15 #define ta0 $12 /* alias for $t4 */ #define ta1 $13 /* alias for $t5 */ #define ta2 $14 /* alias for $t6 */ #define ta3 $15 /* alias for $t7 */ #endif #define s0 $16 #define s1 $17 #define s2 $18 #define s3 $19 #define s4 $20 #define s5 $21 #define s6 $22 #define s7 $23 #define s8 $30 /* == fp */ #define t8 $24 #define t9 $25 #define k0 $26 #define k1 $27 #define gp $28 #define sp $29 #define fp $30 #define ra $31 #endif picolibc-1.8.11/libc/machine/mips/memcpy.S000066400000000000000000000626451513574234600203200ustar00rootroot00000000000000/* * Copyright (c) 2012-2015 * MIPS Technologies, Inc., California. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #ifdef ANDROID_CHANGES # include "machine/asm.h" # include "machine/regdef.h" # define USE_MEMMOVE_FOR_OVERLAP # define PREFETCH_LOAD_HINT PREFETCH_HINT_LOAD_STREAMED # define PREFETCH_STORE_HINT PREFETCH_HINT_PREPAREFORSTORE #elif _LIBC # include "machine/asm.h" # include "machine/regdef.h" # define PREFETCH_LOAD_HINT PREFETCH_HINT_LOAD_STREAMED # define PREFETCH_STORE_HINT PREFETCH_HINT_PREPAREFORSTORE #else # include # include #endif /* Check to see if the MIPS architecture we are compiling for supports * prefetching. */ #if (__mips == 4) || (__mips == 5) || (__mips == 32) || (__mips == 64) # ifndef DISABLE_PREFETCH # define USE_PREFETCH # endif #endif #if defined(_MIPS_SIM) && ((_MIPS_SIM == _ABI64) || (_MIPS_SIM == _ABIN32)) # ifndef DISABLE_DOUBLE # define USE_DOUBLE # endif #endif #if __mips_isa_rev > 5 # if (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE) # undef PREFETCH_STORE_HINT # define PREFETCH_STORE_HINT PREFETCH_HINT_STORE_STREAMED # endif # define R6_CODE #endif /* Some asm.h files do not have the L macro definition. */ #ifndef L # if _MIPS_SIM == _ABIO32 # define L(label) $L ## label # else # define L(label) .L ## label # endif #endif /* Some asm.h files do not have the PTR_ADDIU macro definition. */ #ifndef PTR_ADDIU # ifdef USE_DOUBLE # define PTR_ADDIU daddiu # else # define PTR_ADDIU addiu # endif #endif /* Some asm.h files do not have the PTR_SRA macro definition. */ #ifndef PTR_SRA # ifdef USE_DOUBLE # define PTR_SRA dsra # else # define PTR_SRA sra # endif #endif /* New R6 instructions that may not be in asm.h. */ #ifndef PTR_LSA # if _MIPS_SIM == _ABI64 # define PTR_LSA dlsa # else # define PTR_LSA lsa # endif #endif /* * Using PREFETCH_HINT_LOAD_STREAMED instead of PREFETCH_LOAD on load * prefetches appears to offer a slight preformance advantage. * * Using PREFETCH_HINT_PREPAREFORSTORE instead of PREFETCH_STORE * or PREFETCH_STORE_STREAMED offers a large performance advantage * but PREPAREFORSTORE has some special restrictions to consider. * * Prefetch with the 'prepare for store' hint does not copy a memory * location into the cache, it just allocates a cache line and zeros * it out. This means that if you do not write to the entire cache * line before writing it out to memory some data will get zero'ed out * when the cache line is written back to memory and data will be lost. * * Also if you are using this memcpy to copy overlapping buffers it may * not behave correctly when using the 'prepare for store' hint. If you * use the 'prepare for store' prefetch on a memory area that is in the * memcpy source (as well as the memcpy destination), then you will get * some data zero'ed out before you have a chance to read it and data will * be lost. * * If you are going to use this memcpy routine with the 'prepare for store' * prefetch you may want to set USE_MEMMOVE_FOR_OVERLAP in order to avoid * the problem of running memcpy on overlapping buffers. * * There are ifdef'ed sections of this memcpy to make sure that it does not * do prefetches on cache lines that are not going to be completely written. * This code is only needed and only used when PREFETCH_STORE_HINT is set to * PREFETCH_HINT_PREPAREFORSTORE. This code assumes that cache lines are * 32 bytes and if the cache line is larger it will not work correctly. */ #ifdef USE_PREFETCH # define PREFETCH_HINT_LOAD 0 # define PREFETCH_HINT_STORE 1 # define PREFETCH_HINT_LOAD_STREAMED 4 # define PREFETCH_HINT_STORE_STREAMED 5 # define PREFETCH_HINT_LOAD_RETAINED 6 # define PREFETCH_HINT_STORE_RETAINED 7 # define PREFETCH_HINT_WRITEBACK_INVAL 25 # define PREFETCH_HINT_PREPAREFORSTORE 30 /* * If we have not picked out what hints to use at this point use the * standard load and store prefetch hints. */ # ifndef PREFETCH_STORE_HINT # define PREFETCH_STORE_HINT PREFETCH_HINT_STORE # endif # ifndef PREFETCH_LOAD_HINT # define PREFETCH_LOAD_HINT PREFETCH_HINT_LOAD # endif /* * We double everything when USE_DOUBLE is true so we do 2 prefetches to * get 64 bytes in that case. The assumption is that each individual * prefetch brings in 32 bytes. */ # ifdef USE_DOUBLE # define PREFETCH_CHUNK 64 # define PREFETCH_FOR_LOAD(chunk, reg) \ pref PREFETCH_LOAD_HINT, (chunk)*64(reg); \ pref PREFETCH_LOAD_HINT, ((chunk)*64)+32(reg) # define PREFETCH_FOR_STORE(chunk, reg) \ pref PREFETCH_STORE_HINT, (chunk)*64(reg); \ pref PREFETCH_STORE_HINT, ((chunk)*64)+32(reg) # else # define PREFETCH_CHUNK 32 # define PREFETCH_FOR_LOAD(chunk, reg) \ pref PREFETCH_LOAD_HINT, (chunk)*32(reg) # define PREFETCH_FOR_STORE(chunk, reg) \ pref PREFETCH_STORE_HINT, (chunk)*32(reg) # endif /* MAX_PREFETCH_SIZE is the maximum size of a prefetch, it must not be less * than PREFETCH_CHUNK, the assumed size of each prefetch. If the real size * of a prefetch is greater than MAX_PREFETCH_SIZE and the PREPAREFORSTORE * hint is used, the code will not work correctly. If PREPAREFORSTORE is not * used then MAX_PREFETCH_SIZE does not matter. */ # define MAX_PREFETCH_SIZE 128 /* PREFETCH_LIMIT is set based on the fact that we never use an offset greater * than 5 on a STORE prefetch and that a single prefetch can never be larger * than MAX_PREFETCH_SIZE. We add the extra 32 when USE_DOUBLE is set because * we actually do two prefetches in that case, one 32 bytes after the other. */ # ifdef USE_DOUBLE # define PREFETCH_LIMIT (5 * PREFETCH_CHUNK) + 32 + MAX_PREFETCH_SIZE # else # define PREFETCH_LIMIT (5 * PREFETCH_CHUNK) + MAX_PREFETCH_SIZE # endif # if (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE) \ && ((PREFETCH_CHUNK * 4) < MAX_PREFETCH_SIZE) /* We cannot handle this because the initial prefetches may fetch bytes that * are before the buffer being copied. We start copies with an offset * of 4 so avoid this situation when using PREPAREFORSTORE. */ #error "PREFETCH_CHUNK is too large and/or MAX_PREFETCH_SIZE is too small." # endif #else /* USE_PREFETCH not defined */ # define PREFETCH_FOR_LOAD(offset, reg) # define PREFETCH_FOR_STORE(offset, reg) #endif /* Allow the routine to be named something else if desired. */ #ifndef MEMCPY_NAME # define MEMCPY_NAME memcpy #endif /* We use these 32/64 bit registers as temporaries to do the copying. */ #define REG0 t0 #define REG1 t1 #define REG2 t2 #define REG3 t3 #if defined(_MIPS_SIM) && (_MIPS_SIM == _ABIO32 || _MIPS_SIM == _ABIO64) # define REG4 t4 # define REG5 t5 # define REG6 t6 # define REG7 t7 #else # define REG4 ta0 # define REG5 ta1 # define REG6 ta2 # define REG7 ta3 #endif /* We load/store 64 bits at a time when USE_DOUBLE is true. * The C_ prefix stands for CHUNK and is used to avoid macro name * conflicts with system header files. */ #ifdef USE_DOUBLE # define C_ST sd # define C_LD ld # if __MIPSEB # define C_LDHI ldl /* high part is left in big-endian */ # define C_STHI sdl /* high part is left in big-endian */ # define C_LDLO ldr /* low part is right in big-endian */ # define C_STLO sdr /* low part is right in big-endian */ # else # define C_LDHI ldr /* high part is right in little-endian */ # define C_STHI sdr /* high part is right in little-endian */ # define C_LDLO ldl /* low part is left in little-endian */ # define C_STLO sdl /* low part is left in little-endian */ # endif # define C_ALIGN dalign /* r6 align instruction */ #else # define C_ST sw # define C_LD lw # if __MIPSEB # define C_LDHI lwl /* high part is left in big-endian */ # define C_STHI swl /* high part is left in big-endian */ # define C_LDLO lwr /* low part is right in big-endian */ # define C_STLO swr /* low part is right in big-endian */ # else # define C_LDHI lwr /* high part is right in little-endian */ # define C_STHI swr /* high part is right in little-endian */ # define C_LDLO lwl /* low part is left in little-endian */ # define C_STLO swl /* low part is left in little-endian */ # endif # define C_ALIGN align /* r6 align instruction */ #endif /* Bookkeeping values for 32 vs. 64 bit mode. */ #ifdef USE_DOUBLE # define NSIZE 8 # define NSIZEMASK 0x3f # define NSIZEDMASK 0x7f #else # define NSIZE 4 # define NSIZEMASK 0x1f # define NSIZEDMASK 0x3f #endif #define UNIT(unit) ((unit)*NSIZE) #define UNITM1(unit) (((unit)*NSIZE)-1) #ifdef ANDROID_CHANGES LEAF(MEMCPY_NAME, 0) #else LEAF(MEMCPY_NAME) #endif .set nomips16 .set noreorder /* * Below we handle the case where memcpy is called with overlapping src and dst. * Although memcpy is not required to handle this case, some parts of Android * like Skia rely on such usage. We call memmove to handle such cases. */ #ifdef USE_MEMMOVE_FOR_OVERLAP PTR_SUBU t0,a0,a1 PTR_SRA t2,t0,31 xor t1,t0,t2 PTR_SUBU t0,t1,t2 sltu t2,t0,a2 beq t2,zero,L(memcpy) la t9,memmove jr t9 nop L(memcpy): #endif /* * If the size is less than 2*NSIZE (8 or 16), go to L(lastb). Regardless of * size, copy dst pointer to v0 for the return value. */ slti t2,a2,(2 * NSIZE) bne t2,zero,L(lasts) #if defined(RETURN_FIRST_PREFETCH) || defined(RETURN_LAST_PREFETCH) move v0,zero #else move v0,a0 #endif #ifndef R6_CODE /* * If src and dst have different alignments, go to L(unaligned), if they * have the same alignment (but are not actually aligned) do a partial * load/store to make them aligned. If they are both already aligned * we can start copying at L(aligned). */ xor t8,a1,a0 andi t8,t8,(NSIZE-1) /* t8 is a0/a1 word-displacement */ bne t8,zero,L(unaligned) PTR_SUBU a3, zero, a0 andi a3,a3,(NSIZE-1) /* copy a3 bytes to align a0/a1 */ beq a3,zero,L(aligned) /* if a3=0, it is already aligned */ PTR_SUBU a2,a2,a3 /* a2 is the remining bytes count */ C_LDHI t8,0(a1) PTR_ADDU a1,a1,a3 C_STHI t8,0(a0) PTR_ADDU a0,a0,a3 #else /* R6_CODE */ /* * Align the destination and hope that the source gets aligned too. If it * doesn't we jump to L(r6_unaligned*) to do unaligned copies using the r6 * align instruction. */ andi t8,a0,7 lapc t9,L(atable) PTR_LSA t9,t8,t9,2 jrc t9 L(atable): bc L(lb0) bc L(lb7) bc L(lb6) bc L(lb5) bc L(lb4) bc L(lb3) bc L(lb2) bc L(lb1) L(lb7): lb a3, 6(a1) sb a3, 6(a0) L(lb6): lb a3, 5(a1) sb a3, 5(a0) L(lb5): lb a3, 4(a1) sb a3, 4(a0) L(lb4): lb a3, 3(a1) sb a3, 3(a0) L(lb3): lb a3, 2(a1) sb a3, 2(a0) L(lb2): lb a3, 1(a1) sb a3, 1(a0) L(lb1): lb a3, 0(a1) sb a3, 0(a0) li t9,8 subu t8,t9,t8 PTR_SUBU a2,a2,t8 PTR_ADDU a0,a0,t8 PTR_ADDU a1,a1,t8 L(lb0): andi t8,a1,(NSIZE-1) lapc t9,L(jtable) PTR_LSA t9,t8,t9,2 jrc t9 L(jtable): bc L(aligned) bc L(r6_unaligned1) bc L(r6_unaligned2) bc L(r6_unaligned3) # ifdef USE_DOUBLE bc L(r6_unaligned4) bc L(r6_unaligned5) bc L(r6_unaligned6) bc L(r6_unaligned7) # endif #endif /* R6_CODE */ L(aligned): /* * Now dst/src are both aligned to (word or double word) aligned addresses * Set a2 to count how many bytes we have to copy after all the 64/128 byte * chunks are copied and a3 to the dst pointer after all the 64/128 byte * chunks have been copied. We will loop, incrementing a0 and a1 until a0 * equals a3. */ andi t8,a2,NSIZEDMASK /* any whole 64-byte/128-byte chunks? */ beq a2,t8,L(chkw) /* if a2==t8, no 64-byte/128-byte chunks */ PTR_SUBU a3,a2,t8 /* subtract from a2 the reminder */ PTR_ADDU a3,a0,a3 /* Now a3 is the final dst after loop */ /* When in the loop we may prefetch with the 'prepare to store' hint, * in this case the a0+x should not be past the "t0-32" address. This * means: for x=128 the last "safe" a0 address is "t0-160". Alternatively, * for x=64 the last "safe" a0 address is "t0-96" In the current version we * will use "prefetch hint,128(a0)", so "t0-160" is the limit. */ #if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE) PTR_ADDU t0,a0,a2 /* t0 is the "past the end" address */ PTR_SUBU t9,t0,PREFETCH_LIMIT /* t9 is the "last safe pref" address */ #endif PREFETCH_FOR_LOAD (0, a1) PREFETCH_FOR_LOAD (1, a1) PREFETCH_FOR_LOAD (2, a1) PREFETCH_FOR_LOAD (3, a1) #if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT != PREFETCH_HINT_PREPAREFORSTORE) PREFETCH_FOR_STORE (1, a0) PREFETCH_FOR_STORE (2, a0) PREFETCH_FOR_STORE (3, a0) #endif #if defined(RETURN_FIRST_PREFETCH) && defined(USE_PREFETCH) # if PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE sltu v1,t9,a0 bgtz v1,L(skip_set) nop PTR_ADDIU v0,a0,(PREFETCH_CHUNK*4) L(skip_set): # else PTR_ADDIU v0,a0,(PREFETCH_CHUNK*1) # endif #endif #if defined(RETURN_LAST_PREFETCH) && defined(USE_PREFETCH) \ && (PREFETCH_STORE_HINT != PREFETCH_HINT_PREPAREFORSTORE) PTR_ADDIU v0,a0,(PREFETCH_CHUNK*3) # ifdef USE_DOUBLE PTR_ADDIU v0,v0,32 # endif #endif L(loop16w): C_LD t0,UNIT(0)(a1) #if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE) sltu v1,t9,a0 /* If a0 > t9 don't use next prefetch */ bgtz v1,L(skip_pref) #endif C_LD t1,UNIT(1)(a1) #ifndef R6_CODE PREFETCH_FOR_STORE (4, a0) PREFETCH_FOR_STORE (5, a0) #else PREFETCH_FOR_STORE (2, a0) #endif #if defined(RETURN_LAST_PREFETCH) && defined(USE_PREFETCH) PTR_ADDIU v0,a0,(PREFETCH_CHUNK*5) # ifdef USE_DOUBLE PTR_ADDIU v0,v0,32 # endif #endif L(skip_pref): C_LD REG2,UNIT(2)(a1) C_LD REG3,UNIT(3)(a1) C_LD REG4,UNIT(4)(a1) C_LD REG5,UNIT(5)(a1) C_LD REG6,UNIT(6)(a1) C_LD REG7,UNIT(7)(a1) #ifndef R6_CODE PREFETCH_FOR_LOAD (4, a1) #else PREFETCH_FOR_LOAD (3, a1) #endif C_ST t0,UNIT(0)(a0) C_ST t1,UNIT(1)(a0) C_ST REG2,UNIT(2)(a0) C_ST REG3,UNIT(3)(a0) C_ST REG4,UNIT(4)(a0) C_ST REG5,UNIT(5)(a0) C_ST REG6,UNIT(6)(a0) C_ST REG7,UNIT(7)(a0) C_LD t0,UNIT(8)(a1) C_LD t1,UNIT(9)(a1) C_LD REG2,UNIT(10)(a1) C_LD REG3,UNIT(11)(a1) C_LD REG4,UNIT(12)(a1) C_LD REG5,UNIT(13)(a1) C_LD REG6,UNIT(14)(a1) C_LD REG7,UNIT(15)(a1) #ifndef R6_CODE PREFETCH_FOR_LOAD (5, a1) #endif C_ST t0,UNIT(8)(a0) C_ST t1,UNIT(9)(a0) C_ST REG2,UNIT(10)(a0) C_ST REG3,UNIT(11)(a0) C_ST REG4,UNIT(12)(a0) C_ST REG5,UNIT(13)(a0) C_ST REG6,UNIT(14)(a0) C_ST REG7,UNIT(15)(a0) PTR_ADDIU a0,a0,UNIT(16) /* adding 64/128 to dest */ bne a0,a3,L(loop16w) PTR_ADDIU a1,a1,UNIT(16) /* adding 64/128 to src */ move a2,t8 /* Here we have src and dest word-aligned but less than 64-bytes or * 128 bytes to go. Check for a 32(64) byte chunk and copy if if there * is one. Otherwise jump down to L(chk1w) to handle the tail end of * the copy. */ L(chkw): PREFETCH_FOR_LOAD (0, a1) andi t8,a2,NSIZEMASK /* Is there a 32-byte/64-byte chunk. */ /* The t8 is the reminder count past 32-bytes */ beq a2,t8,L(chk1w) /* When a2=t8, no 32-byte chunk */ nop C_LD t0,UNIT(0)(a1) C_LD t1,UNIT(1)(a1) C_LD REG2,UNIT(2)(a1) C_LD REG3,UNIT(3)(a1) C_LD REG4,UNIT(4)(a1) C_LD REG5,UNIT(5)(a1) C_LD REG6,UNIT(6)(a1) C_LD REG7,UNIT(7)(a1) PTR_ADDIU a1,a1,UNIT(8) C_ST t0,UNIT(0)(a0) C_ST t1,UNIT(1)(a0) C_ST REG2,UNIT(2)(a0) C_ST REG3,UNIT(3)(a0) C_ST REG4,UNIT(4)(a0) C_ST REG5,UNIT(5)(a0) C_ST REG6,UNIT(6)(a0) C_ST REG7,UNIT(7)(a0) PTR_ADDIU a0,a0,UNIT(8) /* * Here we have less than 32(64) bytes to copy. Set up for a loop to * copy one word (or double word) at a time. Set a2 to count how many * bytes we have to copy after all the word (or double word) chunks are * copied and a3 to the dst pointer after all the (d)word chunks have * been copied. We will loop, incrementing a0 and a1 until a0 equals a3. */ L(chk1w): andi a2,t8,(NSIZE-1) /* a2 is the reminder past one (d)word chunks */ beq a2,t8,L(lastw) PTR_SUBU a3,t8,a2 /* a3 is count of bytes in one (d)word chunks */ PTR_ADDU a3,a0,a3 /* a3 is the dst address after loop */ /* copying in words (4-byte or 8-byte chunks) */ L(wordCopy_loop): C_LD REG3,UNIT(0)(a1) PTR_ADDIU a0,a0,UNIT(1) PTR_ADDIU a1,a1,UNIT(1) bne a0,a3,L(wordCopy_loop) C_ST REG3,UNIT(-1)(a0) /* If we have been copying double words, see if we can copy a single word before doing byte copies. We can have, at most, one word to copy. */ L(lastw): #ifdef USE_DOUBLE andi t8,a2,3 /* a2 is the remainder past 4 byte chunks. */ beq t8,a2,L(lastb) move a2,t8 lw REG3,0(a1) sw REG3,0(a0) PTR_ADDIU a0,a0,4 PTR_ADDIU a1,a1,4 #endif /* Copy the last 8 (or 16) bytes */ L(lastb): blez a2,L(leave) PTR_ADDU a3,a0,a2 /* a3 is the last dst address */ L(lastbloop): lb v1,0(a1) PTR_ADDIU a0,a0,1 PTR_ADDIU a1,a1,1 bne a0,a3,L(lastbloop) sb v1,-1(a0) L(leave): j ra nop /* We jump here with a memcpy of less than 8 or 16 bytes, depending on whether or not USE_DOUBLE is defined. Instead of just doing byte copies, check the alignment and size and use lw/sw if possible. Otherwise, do byte copies. */ L(lasts): andi t8,a2,3 beq t8,a2,L(lastb) andi t9,a0,3 bne t9,zero,L(lastb) andi t9,a1,3 bne t9,zero,L(lastb) PTR_SUBU a3,a2,t8 PTR_ADDU a3,a0,a3 L(wcopy_loop): lw REG3,0(a1) PTR_ADDIU a0,a0,4 PTR_ADDIU a1,a1,4 bne a0,a3,L(wcopy_loop) sw REG3,-4(a0) b L(lastb) move a2,t8 #ifndef R6_CODE /* * UNALIGNED case, got here with a3 = "negu a0" * This code is nearly identical to the aligned code above * but only the destination (not the source) gets aligned * so we need to do partial loads of the source followed * by normal stores to the destination (once we have aligned * the destination). */ L(unaligned): andi a3,a3,(NSIZE-1) /* copy a3 bytes to align a0/a1 */ beqz a3,L(ua_chk16w) /* if a3=0, it is already aligned */ PTR_SUBU a2,a2,a3 /* a2 is the remining bytes count */ C_LDHI v1,UNIT(0)(a1) C_LDLO v1,UNITM1(1)(a1) PTR_ADDU a1,a1,a3 C_STHI v1,UNIT(0)(a0) PTR_ADDU a0,a0,a3 /* * Now the destination (but not the source) is aligned * Set a2 to count how many bytes we have to copy after all the 64/128 byte * chunks are copied and a3 to the dst pointer after all the 64/128 byte * chunks have been copied. We will loop, incrementing a0 and a1 until a0 * equals a3. */ L(ua_chk16w): andi t8,a2,NSIZEDMASK /* any whole 64-byte/128-byte chunks? */ beq a2,t8,L(ua_chkw) /* if a2==t8, no 64-byte/128-byte chunks */ PTR_SUBU a3,a2,t8 /* subtract from a2 the reminder */ PTR_ADDU a3,a0,a3 /* Now a3 is the final dst after loop */ # if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE) PTR_ADDU t0,a0,a2 /* t0 is the "past the end" address */ PTR_SUBU t9,t0,PREFETCH_LIMIT /* t9 is the "last safe pref" address */ # endif PREFETCH_FOR_LOAD (0, a1) PREFETCH_FOR_LOAD (1, a1) PREFETCH_FOR_LOAD (2, a1) # if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT != PREFETCH_HINT_PREPAREFORSTORE) PREFETCH_FOR_STORE (1, a0) PREFETCH_FOR_STORE (2, a0) PREFETCH_FOR_STORE (3, a0) # endif # if defined(RETURN_FIRST_PREFETCH) && defined(USE_PREFETCH) # if (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE) sltu v1,t9,a0 bgtz v1,L(ua_skip_set) nop PTR_ADDIU v0,a0,(PREFETCH_CHUNK*4) L(ua_skip_set): # else PTR_ADDIU v0,a0,(PREFETCH_CHUNK*1) # endif # endif L(ua_loop16w): PREFETCH_FOR_LOAD (3, a1) C_LDHI t0,UNIT(0)(a1) C_LDHI t1,UNIT(1)(a1) C_LDHI REG2,UNIT(2)(a1) # if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE) sltu v1,t9,a0 bgtz v1,L(ua_skip_pref) # endif C_LDHI REG3,UNIT(3)(a1) PREFETCH_FOR_STORE (4, a0) PREFETCH_FOR_STORE (5, a0) L(ua_skip_pref): C_LDHI REG4,UNIT(4)(a1) C_LDHI REG5,UNIT(5)(a1) C_LDHI REG6,UNIT(6)(a1) C_LDHI REG7,UNIT(7)(a1) C_LDLO t0,UNITM1(1)(a1) C_LDLO t1,UNITM1(2)(a1) C_LDLO REG2,UNITM1(3)(a1) C_LDLO REG3,UNITM1(4)(a1) C_LDLO REG4,UNITM1(5)(a1) C_LDLO REG5,UNITM1(6)(a1) C_LDLO REG6,UNITM1(7)(a1) C_LDLO REG7,UNITM1(8)(a1) PREFETCH_FOR_LOAD (4, a1) C_ST t0,UNIT(0)(a0) C_ST t1,UNIT(1)(a0) C_ST REG2,UNIT(2)(a0) C_ST REG3,UNIT(3)(a0) C_ST REG4,UNIT(4)(a0) C_ST REG5,UNIT(5)(a0) C_ST REG6,UNIT(6)(a0) C_ST REG7,UNIT(7)(a0) C_LDHI t0,UNIT(8)(a1) C_LDHI t1,UNIT(9)(a1) C_LDHI REG2,UNIT(10)(a1) C_LDHI REG3,UNIT(11)(a1) C_LDHI REG4,UNIT(12)(a1) C_LDHI REG5,UNIT(13)(a1) C_LDHI REG6,UNIT(14)(a1) C_LDHI REG7,UNIT(15)(a1) C_LDLO t0,UNITM1(9)(a1) C_LDLO t1,UNITM1(10)(a1) C_LDLO REG2,UNITM1(11)(a1) C_LDLO REG3,UNITM1(12)(a1) C_LDLO REG4,UNITM1(13)(a1) C_LDLO REG5,UNITM1(14)(a1) C_LDLO REG6,UNITM1(15)(a1) C_LDLO REG7,UNITM1(16)(a1) PREFETCH_FOR_LOAD (5, a1) C_ST t0,UNIT(8)(a0) C_ST t1,UNIT(9)(a0) C_ST REG2,UNIT(10)(a0) C_ST REG3,UNIT(11)(a0) C_ST REG4,UNIT(12)(a0) C_ST REG5,UNIT(13)(a0) C_ST REG6,UNIT(14)(a0) C_ST REG7,UNIT(15)(a0) PTR_ADDIU a0,a0,UNIT(16) /* adding 64/128 to dest */ bne a0,a3,L(ua_loop16w) PTR_ADDIU a1,a1,UNIT(16) /* adding 64/128 to src */ move a2,t8 /* Here we have src and dest word-aligned but less than 64-bytes or * 128 bytes to go. Check for a 32(64) byte chunk and copy if if there * is one. Otherwise jump down to L(ua_chk1w) to handle the tail end of * the copy. */ L(ua_chkw): PREFETCH_FOR_LOAD (0, a1) andi t8,a2,NSIZEMASK /* Is there a 32-byte/64-byte chunk. */ /* t8 is the reminder count past 32-bytes */ beq a2,t8,L(ua_chk1w) /* When a2=t8, no 32-byte chunk */ nop C_LDHI t0,UNIT(0)(a1) C_LDHI t1,UNIT(1)(a1) C_LDHI REG2,UNIT(2)(a1) C_LDHI REG3,UNIT(3)(a1) C_LDHI REG4,UNIT(4)(a1) C_LDHI REG5,UNIT(5)(a1) C_LDHI REG6,UNIT(6)(a1) C_LDHI REG7,UNIT(7)(a1) C_LDLO t0,UNITM1(1)(a1) C_LDLO t1,UNITM1(2)(a1) C_LDLO REG2,UNITM1(3)(a1) C_LDLO REG3,UNITM1(4)(a1) C_LDLO REG4,UNITM1(5)(a1) C_LDLO REG5,UNITM1(6)(a1) C_LDLO REG6,UNITM1(7)(a1) C_LDLO REG7,UNITM1(8)(a1) PTR_ADDIU a1,a1,UNIT(8) C_ST t0,UNIT(0)(a0) C_ST t1,UNIT(1)(a0) C_ST REG2,UNIT(2)(a0) C_ST REG3,UNIT(3)(a0) C_ST REG4,UNIT(4)(a0) C_ST REG5,UNIT(5)(a0) C_ST REG6,UNIT(6)(a0) C_ST REG7,UNIT(7)(a0) PTR_ADDIU a0,a0,UNIT(8) /* * Here we have less than 32(64) bytes to copy. Set up for a loop to * copy one word (or double word) at a time. */ L(ua_chk1w): andi a2,t8,(NSIZE-1) /* a2 is the reminder past one (d)word chunks */ beq a2,t8,L(ua_smallCopy) PTR_SUBU a3,t8,a2 /* a3 is count of bytes in one (d)word chunks */ PTR_ADDU a3,a0,a3 /* a3 is the dst address after loop */ /* copying in words (4-byte or 8-byte chunks) */ L(ua_wordCopy_loop): C_LDHI v1,UNIT(0)(a1) C_LDLO v1,UNITM1(1)(a1) PTR_ADDIU a0,a0,UNIT(1) PTR_ADDIU a1,a1,UNIT(1) bne a0,a3,L(ua_wordCopy_loop) C_ST v1,UNIT(-1)(a0) /* Copy the last 8 (or 16) bytes */ L(ua_smallCopy): beqz a2,L(leave) PTR_ADDU a3,a0,a2 /* a3 is the last dst address */ L(ua_smallCopy_loop): lb v1,0(a1) PTR_ADDIU a0,a0,1 PTR_ADDIU a1,a1,1 bne a0,a3,L(ua_smallCopy_loop) sb v1,-1(a0) j ra nop #else /* R6_CODE */ # if __MIPSEB # define SWAP_REGS(X,Y) X, Y # define ALIGN_OFFSET(N) (N) # else # define SWAP_REGS(X,Y) Y, X # define ALIGN_OFFSET(N) (NSIZE-N) # endif # define R6_UNALIGNED_WORD_COPY(BYTEOFFSET) \ andi REG7, a2, (NSIZE-1);/* REG7 is # of bytes to by bytes. */ \ beq REG7, a2, L(lastb); /* Check for bytes to copy by word */ \ PTR_SUBU a3, a2, REG7; /* a3 is number of bytes to be copied in */ \ /* (d)word chunks. */ \ move a2, REG7; /* a2 is # of bytes to copy byte by byte */ \ /* after word loop is finished. */ \ PTR_ADDU REG6, a0, a3; /* REG6 is the dst address after loop. */ \ PTR_SUBU REG2, a1, t8; /* REG2 is the aligned src address. */ \ PTR_ADDU a1, a1, a3; /* a1 is addr of source after word loop. */ \ C_LD t0, UNIT(0)(REG2); /* Load first part of source. */ \ L(r6_ua_wordcopy##BYTEOFFSET): \ C_LD t1, UNIT(1)(REG2); /* Load second part of source. */ \ C_ALIGN REG3, SWAP_REGS(t1,t0), ALIGN_OFFSET(BYTEOFFSET); \ PTR_ADDIU a0, a0, UNIT(1); /* Increment destination pointer. */ \ PTR_ADDIU REG2, REG2, UNIT(1); /* Increment aligned source pointer.*/ \ move t0, t1; /* Move second part of source to first. */ \ bne a0, REG6,L(r6_ua_wordcopy##BYTEOFFSET); \ C_ST REG3, UNIT(-1)(a0); \ j L(lastb); \ nop /* We are generating R6 code, the destination is 4 byte aligned and the source is not 4 byte aligned. t8 is 1, 2, or 3 depending on the alignment of the source. */ L(r6_unaligned1): R6_UNALIGNED_WORD_COPY(1) L(r6_unaligned2): R6_UNALIGNED_WORD_COPY(2) L(r6_unaligned3): R6_UNALIGNED_WORD_COPY(3) # ifdef USE_DOUBLE L(r6_unaligned4): R6_UNALIGNED_WORD_COPY(4) L(r6_unaligned5): R6_UNALIGNED_WORD_COPY(5) L(r6_unaligned6): R6_UNALIGNED_WORD_COPY(6) L(r6_unaligned7): R6_UNALIGNED_WORD_COPY(7) # endif #endif /* R6_CODE */ .set at .set reorder END(MEMCPY_NAME) picolibc-1.8.11/libc/machine/mips/memset.S000066400000000000000000000321721513574234600203100ustar00rootroot00000000000000/* * Copyright (c) 2013 * MIPS Technologies, Inc., California. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #ifdef ANDROID_CHANGES # include "machine/asm.h" # include "machine/regdef.h" # define PREFETCH_STORE_HINT PREFETCH_HINT_PREPAREFORSTORE #elif _LIBC # include "machine/asm.h" # include "machine/regdef.h" # define PREFETCH_STORE_HINT PREFETCH_HINT_PREPAREFORSTORE #else # include # include #endif /* Check to see if the MIPS architecture we are compiling for supports prefetching. */ #if (__mips == 4) || (__mips == 5) || (__mips == 32) || (__mips == 64) # ifndef DISABLE_PREFETCH # define USE_PREFETCH # endif #endif #if defined(_MIPS_SIM) && ((_MIPS_SIM == _ABI64) || (_MIPS_SIM == _ABIN32)) # ifndef DISABLE_DOUBLE # define USE_DOUBLE # endif #endif #ifndef USE_DOUBLE # ifndef DISABLE_DOUBLE_ALIGN # define DOUBLE_ALIGN # endif #endif /* Some asm.h files do not have the L macro definition. */ #ifndef L # if _MIPS_SIM == _ABIO32 # define L(label) $L ## label # else # define L(label) .L ## label # endif #endif /* Some asm.h files do not have the PTR_ADDIU macro definition. */ #ifndef PTR_ADDIU # ifdef USE_DOUBLE # define PTR_ADDIU daddiu # else # define PTR_ADDIU addiu # endif #endif /* New R6 instructions that may not be in asm.h. */ #ifndef PTR_LSA # if _MIPS_SIM == _ABI64 # define PTR_LSA dlsa # else # define PTR_LSA lsa # endif #endif /* Using PREFETCH_HINT_PREPAREFORSTORE instead of PREFETCH_STORE or PREFETCH_STORE_STREAMED offers a large performance advantage but PREPAREFORSTORE has some special restrictions to consider. Prefetch with the 'prepare for store' hint does not copy a memory location into the cache, it just allocates a cache line and zeros it out. This means that if you do not write to the entire cache line before writing it out to memory some data will get zero'ed out when the cache line is written back to memory and data will be lost. There are ifdef'ed sections of this memcpy to make sure that it does not do prefetches on cache lines that are not going to be completely written. This code is only needed and only used when PREFETCH_STORE_HINT is set to PREFETCH_HINT_PREPAREFORSTORE. This code assumes that cache lines are less than MAX_PREFETCH_SIZE bytes and if the cache line is larger it will not work correctly. */ #ifdef USE_PREFETCH # define PREFETCH_HINT_STORE 1 # define PREFETCH_HINT_STORE_STREAMED 5 # define PREFETCH_HINT_STORE_RETAINED 7 # define PREFETCH_HINT_PREPAREFORSTORE 30 /* If we have not picked out what hints to use at this point use the standard load and store prefetch hints. */ # ifndef PREFETCH_STORE_HINT # define PREFETCH_STORE_HINT PREFETCH_HINT_STORE # endif /* We double everything when USE_DOUBLE is true so we do 2 prefetches to get 64 bytes in that case. The assumption is that each individual prefetch brings in 32 bytes. */ # ifdef USE_DOUBLE # define PREFETCH_CHUNK 64 # define PREFETCH_FOR_STORE(chunk, reg) \ pref PREFETCH_STORE_HINT, (chunk)*64(reg); \ pref PREFETCH_STORE_HINT, ((chunk)*64)+32(reg) # else # define PREFETCH_CHUNK 32 # define PREFETCH_FOR_STORE(chunk, reg) \ pref PREFETCH_STORE_HINT, (chunk)*32(reg) # endif /* MAX_PREFETCH_SIZE is the maximum size of a prefetch, it must not be less than PREFETCH_CHUNK, the assumed size of each prefetch. If the real size of a prefetch is greater than MAX_PREFETCH_SIZE and the PREPAREFORSTORE hint is used, the code will not work correctly. If PREPAREFORSTORE is not used than MAX_PREFETCH_SIZE does not matter. */ # define MAX_PREFETCH_SIZE 128 /* PREFETCH_LIMIT is set based on the fact that we never use an offset greater than 5 on a STORE prefetch and that a single prefetch can never be larger than MAX_PREFETCH_SIZE. We add the extra 32 when USE_DOUBLE is set because we actually do two prefetches in that case, one 32 bytes after the other. */ # ifdef USE_DOUBLE # define PREFETCH_LIMIT (5 * PREFETCH_CHUNK) + 32 + MAX_PREFETCH_SIZE # else # define PREFETCH_LIMIT (5 * PREFETCH_CHUNK) + MAX_PREFETCH_SIZE # endif # if (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE) \ && ((PREFETCH_CHUNK * 4) < MAX_PREFETCH_SIZE) /* We cannot handle this because the initial prefetches may fetch bytes that are before the buffer being copied. We start copies with an offset of 4 so avoid this situation when using PREPAREFORSTORE. */ # error "PREFETCH_CHUNK is too large and/or MAX_PREFETCH_SIZE is too small." # endif #else /* USE_PREFETCH not defined */ # define PREFETCH_FOR_STORE(offset, reg) #endif #if __mips_isa_rev > 5 # if (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE) # undef PREFETCH_STORE_HINT # define PREFETCH_STORE_HINT PREFETCH_HINT_STORE_STREAMED # endif # define R6_CODE #endif /* Allow the routine to be named something else if desired. */ #ifndef MEMSET_NAME # define MEMSET_NAME memset #endif /* We load/store 64 bits at a time when USE_DOUBLE is true. The C_ prefix stands for CHUNK and is used to avoid macro name conflicts with system header files. */ #ifdef USE_DOUBLE # define C_ST sd # if __MIPSEB # define C_STHI sdl /* high part is left in big-endian */ # else # define C_STHI sdr /* high part is right in little-endian */ # endif #else # define C_ST sw # if __MIPSEB # define C_STHI swl /* high part is left in big-endian */ # else # define C_STHI swr /* high part is right in little-endian */ # endif #endif /* Bookkeeping values for 32 vs. 64 bit mode. */ #ifdef USE_DOUBLE # define NSIZE 8 # define NSIZEMASK 0x3f # define NSIZEDMASK 0x7f #else # define NSIZE 4 # define NSIZEMASK 0x1f # define NSIZEDMASK 0x3f #endif #define UNIT(unit) ((unit)*NSIZE) #define UNITM1(unit) (((unit)*NSIZE)-1) #ifdef ANDROID_CHANGES LEAF(MEMSET_NAME,0) #else LEAF(MEMSET_NAME) #endif .set nomips16 .set noreorder /* If the size is less than 2*NSIZE (8 or 16), go to L(lastb). Regardless of size, copy dst pointer to v0 for the return value. */ slti t2,a2,(2 * NSIZE) bne t2,zero,L(lastb) move v0,a0 /* If memset value is not zero, we copy it to all the bytes in a 32 or 64 bit word. */ beq a1,zero,L(set0) /* If memset value is zero no smear */ PTR_SUBU a3,zero,a0 nop /* smear byte into 32 or 64 bit word */ #if ((__mips == 64) || (__mips == 32)) && (__mips_isa_rev >= 2) # ifdef USE_DOUBLE dins a1, a1, 8, 8 /* Replicate fill byte into half-word. */ dins a1, a1, 16, 16 /* Replicate fill byte into word. */ dins a1, a1, 32, 32 /* Replicate fill byte into dbl word. */ # else ins a1, a1, 8, 8 /* Replicate fill byte into half-word. */ ins a1, a1, 16, 16 /* Replicate fill byte into word. */ # endif #else # ifdef USE_DOUBLE and a1,0xff dsll t2,a1,8 or a1,t2 dsll t2,a1,16 or a1,t2 dsll t2,a1,32 or a1,t2 # else and a1,0xff sll t2,a1,8 or a1,t2 sll t2,a1,16 or a1,t2 # endif #endif /* If the destination address is not aligned do a partial store to get it aligned. If it is already aligned just jump to L(aligned). */ L(set0): #ifndef R6_CODE andi t2,a3,(NSIZE-1) /* word-unaligned address? */ beq t2,zero,L(aligned) /* t2 is the unalignment count */ PTR_SUBU a2,a2,t2 C_STHI a1,0(a0) PTR_ADDU a0,a0,t2 #else /* R6_CODE */ andi t2,a0,(NSIZE-1) lapc t9,L(atable) PTR_LSA t9,t2,t9,2 jrc t9 L(atable): bc L(aligned) # ifdef USE_DOUBLE bc L(lb7) bc L(lb6) bc L(lb5) bc L(lb4) # endif bc L(lb3) bc L(lb2) bc L(lb1) L(lb7): sb a1,6(a0) L(lb6): sb a1,5(a0) L(lb5): sb a1,4(a0) L(lb4): sb a1,3(a0) L(lb3): sb a1,2(a0) L(lb2): sb a1,1(a0) L(lb1): sb a1,0(a0) li t9,NSIZE subu t2,t9,t2 PTR_SUBU a2,a2,t2 PTR_ADDU a0,a0,t2 #endif /* R6_CODE */ L(aligned): /* If USE_DOUBLE is not set we may still want to align the data on a 16 byte boundry instead of an 8 byte boundry to maximize the opportunity of proAptiv chips to do memory bonding (combining two sequential 4 byte stores into one 8 byte store). We know there are at least 4 bytes left to store or we would have jumped to L(lastb) earlier in the code. */ #ifdef DOUBLE_ALIGN andi t2,a3,4 beq t2,zero,L(double_aligned) PTR_SUBU a2,a2,t2 sw a1,0(a0) PTR_ADDU a0,a0,t2 L(double_aligned): #endif /* Now the destination is aligned to (word or double word) aligned address Set a2 to count how many bytes we have to copy after all the 64/128 byte chunks are copied and a3 to the dest pointer after all the 64/128 byte chunks have been copied. We will loop, incrementing a0 until it equals a3. */ andi t8,a2,NSIZEDMASK /* any whole 64-byte/128-byte chunks? */ beq a2,t8,L(chkw) /* if a2==t8, no 64-byte/128-byte chunks */ PTR_SUBU a3,a2,t8 /* subtract from a2 the reminder */ PTR_ADDU a3,a0,a3 /* Now a3 is the final dst after loop */ /* When in the loop we may prefetch with the 'prepare to store' hint, in this case the a0+x should not be past the "t0-32" address. This means: for x=128 the last "safe" a0 address is "t0-160". Alternatively, for x=64 the last "safe" a0 address is "t0-96" In the current version we will use "prefetch hint,128(a0)", so "t0-160" is the limit. */ #if defined(USE_PREFETCH) \ && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE) PTR_ADDU t0,a0,a2 /* t0 is the "past the end" address */ PTR_SUBU t9,t0,PREFETCH_LIMIT /* t9 is the "last safe pref" address */ #endif #if defined(USE_PREFETCH) \ && (PREFETCH_STORE_HINT != PREFETCH_HINT_PREPAREFORSTORE) PREFETCH_FOR_STORE (1, a0) PREFETCH_FOR_STORE (2, a0) PREFETCH_FOR_STORE (3, a0) #endif L(loop16w): #if defined(USE_PREFETCH) \ && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE) sltu v1,t9,a0 /* If a0 > t9 don't use next prefetch */ bgtz v1,L(skip_pref) nop #endif #ifndef R6_CODE PREFETCH_FOR_STORE (4, a0) PREFETCH_FOR_STORE (5, a0) #else PREFETCH_FOR_STORE (2, a0) #endif L(skip_pref): C_ST a1,UNIT(0)(a0) C_ST a1,UNIT(1)(a0) C_ST a1,UNIT(2)(a0) C_ST a1,UNIT(3)(a0) C_ST a1,UNIT(4)(a0) C_ST a1,UNIT(5)(a0) C_ST a1,UNIT(6)(a0) C_ST a1,UNIT(7)(a0) C_ST a1,UNIT(8)(a0) C_ST a1,UNIT(9)(a0) C_ST a1,UNIT(10)(a0) C_ST a1,UNIT(11)(a0) C_ST a1,UNIT(12)(a0) C_ST a1,UNIT(13)(a0) C_ST a1,UNIT(14)(a0) C_ST a1,UNIT(15)(a0) PTR_ADDIU a0,a0,UNIT(16) /* adding 64/128 to dest */ bne a0,a3,L(loop16w) nop move a2,t8 /* Here we have dest word-aligned but less than 64-bytes or 128 bytes to go. Check for a 32(64) byte chunk and copy if if there is one. Otherwise jump down to L(chk1w) to handle the tail end of the copy. */ L(chkw): andi t8,a2,NSIZEMASK /* is there a 32-byte/64-byte chunk. */ /* the t8 is the reminder count past 32-bytes */ beq a2,t8,L(chk1w)/* when a2==t8, no 32-byte chunk */ nop C_ST a1,UNIT(0)(a0) C_ST a1,UNIT(1)(a0) C_ST a1,UNIT(2)(a0) C_ST a1,UNIT(3)(a0) C_ST a1,UNIT(4)(a0) C_ST a1,UNIT(5)(a0) C_ST a1,UNIT(6)(a0) C_ST a1,UNIT(7)(a0) PTR_ADDIU a0,a0,UNIT(8) /* Here we have less than 32(64) bytes to set. Set up for a loop to copy one word (or double word) at a time. Set a2 to count how many bytes we have to copy after all the word (or double word) chunks are copied and a3 to the dest pointer after all the (d)word chunks have been copied. We will loop, incrementing a0 until a0 equals a3. */ L(chk1w): andi a2,t8,(NSIZE-1) /* a2 is the reminder past one (d)word chunks */ beq a2,t8,L(lastb) PTR_SUBU a3,t8,a2 /* a3 is count of bytes in one (d)word chunks */ PTR_ADDU a3,a0,a3 /* a3 is the dst address after loop */ /* copying in words (4-byte or 8 byte chunks) */ L(wordCopy_loop): PTR_ADDIU a0,a0,UNIT(1) bne a0,a3,L(wordCopy_loop) C_ST a1,UNIT(-1)(a0) /* Copy the last 8 (or 16) bytes */ L(lastb): blez a2,L(leave) PTR_ADDU a3,a0,a2 /* a3 is the last dst address */ L(lastbloop): PTR_ADDIU a0,a0,1 bne a0,a3,L(lastbloop) sb a1,-1(a0) L(leave): j ra nop .set at .set reorder END(MEMSET_NAME) picolibc-1.8.11/libc/machine/mips/meson.build000066400000000000000000000033261513574234600210330ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'memcpy.S', 'memset.S', 'setjmp.S', 'strcmp.S', 'strlen.c', 'strncpy.c', 'tls.c', ] subdir('machine') src_machine = files(srcs_machine) picolibc-1.8.11/libc/machine/mips/setjmp.S000066400000000000000000000112451513574234600203160ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* This is a simple version of setjmp and longjmp for MIPS 32 and 64. Ian Lance Taylor, Cygnus Support, 13 May 1993. */ #include #ifdef __mips16 /* This file contains 32 bit assembly code. */ .set nomips16 #endif #define GPR_LAYOUT \ GPR_OFFSET ($16, 0); \ GPR_OFFSET ($17, 1); \ GPR_OFFSET ($18, 2); \ GPR_OFFSET ($19, 3); \ GPR_OFFSET ($20, 4); \ GPR_OFFSET ($21, 5); \ GPR_OFFSET ($22, 6); \ GPR_OFFSET ($23, 7); \ GPR_OFFSET ($29, 8); \ GPR_OFFSET ($30, 9); \ GPR_OFFSET ($31, 10) #define NUM_GPRS_SAVED 11 #ifdef __mips_hard_float #if _MIPS_SIM == _ABIN32 #define FPR_LAYOUT \ FPR_OFFSET ($f20, 0); \ FPR_OFFSET ($f22, 1); \ FPR_OFFSET ($f24, 2); \ FPR_OFFSET ($f26, 3); \ FPR_OFFSET ($f28, 4); \ FPR_OFFSET ($f30, 5); #elif _MIPS_SIM == _ABI64 #define FPR_LAYOUT \ FPR_OFFSET ($f24, 0); \ FPR_OFFSET ($f25, 1); \ FPR_OFFSET ($f26, 2); \ FPR_OFFSET ($f27, 3); \ FPR_OFFSET ($f28, 4); \ FPR_OFFSET ($f29, 5); \ FPR_OFFSET ($f30, 6); \ FPR_OFFSET ($f31, 7); #elif __mips_fpr == 0 || __mips_fpr == 64 /* This deals with the o32 FPXX and FP64 cases. Here we must use SDC1 and LDC1 to access the FPRs. These instructions require 8-byte aligned addresses. Unfortunately, the MIPS jmp_buf only guarantees 4-byte alignment and this cannot be increased without breaking compatibility with pre-existing objects built against newlib. There are 11 GPRS saved in the jmp_buf so a buffer that happens to be 8-byte aligned ends up leaving the FPR slots 4-byte aligned and an (only) 4-byte aligned buffer leads to the FPR slots being 8-byte aligned! To resolve this, we move the location of $31 to the last slot in the jmp_buf when the overall buffer is 8-byte aligned. $31 is simply loaded/stored twice to avoid adding complexity to the GPR_LAYOUT macro above as well as FPR_LAYOUT. The location of the last slot is index 22 which is calculated from there being 11 GPRs saved and then 12 FPRs saved so the index of the last FPR is 11+11. The base of the jmp_buf is modified in $4 to allow the FPR_OFFSET macros to just use the usual constant slot numbers regardless of whether the realignment happened or not. */ #define FPR_LAYOUT \ and $8, $4, 4; \ beq $8, $0, 1f; \ GPR_OFFSET ($31, 22); \ addiu $4, $4, -4; \ 1: \ FPR_OFFSET ($f20, 0); \ FPR_OFFSET ($f22, 2); \ FPR_OFFSET ($f24, 4); \ FPR_OFFSET ($f26, 6); \ FPR_OFFSET ($f28, 8); \ FPR_OFFSET ($f30, 10); #else /* Assuming _MIPS_SIM == _ABIO32 */ #define FPR_LAYOUT \ FPR_OFFSET ($f20, 0); \ FPR_OFFSET ($f21, 1); \ FPR_OFFSET ($f22, 2); \ FPR_OFFSET ($f23, 3); \ FPR_OFFSET ($f24, 4); \ FPR_OFFSET ($f25, 5); \ FPR_OFFSET ($f26, 6); \ FPR_OFFSET ($f27, 7); \ FPR_OFFSET ($f28, 8); \ FPR_OFFSET ($f29, 9); \ FPR_OFFSET ($f30, 10); \ FPR_OFFSET ($f31, 11); #endif #else #define FPR_LAYOUT #endif #ifdef __mips64 #define BYTES_PER_WORD 8 #define LOAD_GPR ld #define LOAD_FPR ldc1 #define STORE_GPR sd #define STORE_FPR sdc1 #else #define LOAD_GPR lw #define STORE_GPR sw #define BYTES_PER_WORD 4 #if __mips_fpr == 0 || __mips_fpr == 64 #define LOAD_FPR ldc1 #define STORE_FPR sdc1 #else #define LOAD_FPR lwc1 #define STORE_FPR swc1 #endif #endif #define GPOFF(INDEX) (INDEX * BYTES_PER_WORD) #define FPOFF(INDEX) ((INDEX + NUM_GPRS_SAVED) * BYTES_PER_WORD) /* int setjmp (jmp_buf); */ .globl setjmp .ent setjmp setjmp: .frame $sp,0,$31 #define GPR_OFFSET(REG, INDEX) STORE_GPR REG,GPOFF(INDEX)($4) #define FPR_OFFSET(REG, INDEX) STORE_FPR REG,FPOFF(INDEX)($4) GPR_LAYOUT FPR_LAYOUT #undef GPR_OFFSET #undef FPR_OFFSET move $2,$0 j $31 .end setjmp /* volatile void longjmp (jmp_buf, int); */ .globl longjmp .ent longjmp longjmp: .frame $sp,0,$31 #define GPR_OFFSET(REG, INDEX) LOAD_GPR REG,GPOFF(INDEX)($4) #define FPR_OFFSET(REG, INDEX) LOAD_FPR REG,FPOFF(INDEX)($4) GPR_LAYOUT FPR_LAYOUT #undef GPR_OFFSET #undef FPR_OFFSET bne $5,$0,1f li $5,1 1: move $2,$5 j $31 .end longjmp picolibc-1.8.11/libc/machine/mips/strcmp.S000066400000000000000000000134301513574234600203220ustar00rootroot00000000000000/* * Copyright (c) 2014 * Imagination Technologies Limited. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY IMAGINATION TECHNOLOGIES LIMITED ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL IMAGINATION TECHNOLOGIES LIMITED BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #ifdef ANDROID_CHANGES # include "machine/asm.h" # include "machine/regdef.h" #elif _LIBC # include "machine/asm.h" # include "machine/regdef.h" #else # include # include #endif /* Technically strcmp should not read past the end of the strings being compared. We will read a full word that may contain excess bits beyond the NULL string terminator but unless ENABLE_READAHEAD is set, we will not read the next word after the end of string. Setting ENABLE_READAHEAD will improve performance but is technically illegal based on the definition of strcmp. */ #ifdef ENABLE_READAHEAD # define DELAY_READ #else # define DELAY_READ nop #endif /* Testing on a little endian machine showed using CLZ was a performance loss, so we are not turning it on by default. */ #if defined(ENABLE_CLZ) && (__mips_isa_rev > 1) # define USE_CLZ #endif /* Some asm.h files do not have the L macro definition. */ #ifndef L # if _MIPS_SIM == _ABIO32 # define L(label) $L ## label # else # define L(label) .L ## label # endif #endif /* Some asm.h files do not have the PTR_ADDIU macro definition. */ #ifndef PTR_ADDIU # ifdef USE_DOUBLE # define PTR_ADDIU daddiu # else # define PTR_ADDIU addiu # endif #endif /* Allow the routine to be named something else if desired. */ #ifndef STRCMP_NAME # define STRCMP_NAME strcmp #endif #ifdef ANDROID_CHANGES LEAF(STRCMP_NAME, 0) #else LEAF(STRCMP_NAME) #endif .set nomips16 .set noreorder or t0, a0, a1 andi t0,0x3 bne t0, zero, L(byteloop) /* Both strings are 4 byte aligned at this point. */ lui t8, 0x0101 ori t8, t8, 0x0101 lui t9, 0x7f7f ori t9, 0x7f7f #define STRCMP32(OFFSET) \ lw v0, OFFSET(a0); \ lw v1, OFFSET(a1); \ subu t0, v0, t8; \ bne v0, v1, L(worddiff); \ nor t1, v0, t9; \ and t0, t0, t1; \ bne t0, zero, L(returnzero) L(wordloop): STRCMP32(0) DELAY_READ STRCMP32(4) DELAY_READ STRCMP32(8) DELAY_READ STRCMP32(12) DELAY_READ STRCMP32(16) DELAY_READ STRCMP32(20) DELAY_READ STRCMP32(24) DELAY_READ STRCMP32(28) PTR_ADDIU a0, a0, 32 b L(wordloop) PTR_ADDIU a1, a1, 32 L(returnzero): j ra move v0, zero L(worddiff): #ifdef USE_CLZ subu t0, v0, t8 nor t1, v0, t9 and t1, t0, t1 xor t0, v0, v1 or t0, t0, t1 # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ wsbh t0, t0 rotr t0, t0, 16 # endif clz t1, t0 and t1, 0xf8 # if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ neg t1 addu t1, 24 # endif rotrv v0, v0, t1 rotrv v1, v1, t1 and v0, v0, 0xff and v1, v1, 0xff j ra subu v0, v0, v1 #else /* USE_CLZ */ # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ andi t0, v0, 0xff beq t0, zero, L(wexit01) andi t1, v1, 0xff bne t0, t1, L(wexit01) srl t8, v0, 8 srl t9, v1, 8 andi t8, t8, 0xff beq t8, zero, L(wexit89) andi t9, t9, 0xff bne t8, t9, L(wexit89) srl t0, v0, 16 srl t1, v1, 16 andi t0, t0, 0xff beq t0, zero, L(wexit01) andi t1, t1, 0xff bne t0, t1, L(wexit01) srl t8, v0, 24 srl t9, v1, 24 # else /* __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ */ srl t0, v0, 24 beq t0, zero, L(wexit01) srl t1, v1, 24 bne t0, t1, L(wexit01) srl t8, v0, 16 srl t9, v1, 16 andi t8, t8, 0xff beq t8, zero, L(wexit89) andi t9, t9, 0xff bne t8, t9, L(wexit89) srl t0, v0, 8 srl t1, v1, 8 andi t0, t0, 0xff beq t0, zero, L(wexit01) andi t1, t1, 0xff bne t0, t1, L(wexit01) andi t8, v0, 0xff andi t9, v1, 0xff # endif /* __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ */ L(wexit89): j ra subu v0, t8, t9 L(wexit01): j ra subu v0, t0, t1 #endif /* USE_CLZ */ /* It might seem better to do the 'beq' instruction between the two 'lbu' instructions so that the nop is not needed but testing showed that this code is actually faster (based on glibc strcmp test). */ #define BYTECMP01(OFFSET) \ lbu v0, OFFSET(a0); \ lbu v1, OFFSET(a1); \ beq v0, zero, L(bexit01); \ nop; \ bne v0, v1, L(bexit01) #define BYTECMP89(OFFSET) \ lbu t8, OFFSET(a0); \ lbu t9, OFFSET(a1); \ beq t8, zero, L(bexit89); \ nop; \ bne t8, t9, L(bexit89) L(byteloop): BYTECMP01(0) BYTECMP89(1) BYTECMP01(2) BYTECMP89(3) BYTECMP01(4) BYTECMP89(5) BYTECMP01(6) BYTECMP89(7) PTR_ADDIU a0, a0, 8 b L(byteloop) PTR_ADDIU a1, a1, 8 L(bexit01): j ra subu v0, v0, v1 L(bexit89): j ra subu v0, t8, t9 .set at .set reorder END(STRCMP_NAME) picolibc-1.8.11/libc/machine/mips/strlen.c000066400000000000000000000036521513574234600203460ustar00rootroot00000000000000/* * strlen.c -- strlen function. On at least some MIPS chips, a simple * strlen is faster than the 'optimized' C version. * * Copyright (c) 2001, 2002 Red Hat, Inc. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include #include /* MIPS16 needs to come first. */ #if defined(__mips16) size_t strlen(const char *str) { const char *start = str; while (*str++ != '\0') ; return str - start - 1; } #elif defined(__mips64) __asm__("" /* 64-bit MIPS targets */ " .set noreorder\n" " .set nomacro\n" " .globl strlen\n" " .ent strlen\n" "strlen:\n" " daddiu $2,$4,1\n" "\n" "1: lbu $3,0($4)\n" " bnez $3,1b\n" " daddiu $4,$4,1\n" "\n" " jr $31\n" " dsubu $2,$4,$2\n" " .end strlen\n" " .set macro\n" " .set reorder\n"); #else __asm__("" /* 32-bit MIPS targets */ " .set noreorder\n" " .set nomacro\n" " .globl strlen\n" " .ent strlen\n" "strlen:\n" " addiu $2,$4,1\n" "\n" "1: lbu $3,0($4)\n" #if defined(_R3000) " nop \n" #endif " bnez $3,1b\n" " addiu $4,$4,1\n" "\n" " jr $31\n" " subu $2,$4,$2\n" " .end strlen\n" " .set macro\n" " .set reorder\n"); #endif picolibc-1.8.11/libc/machine/mips/strncpy.c000066400000000000000000000145751513574234600205470ustar00rootroot00000000000000/* * strncpy.S -- strncmp function. On at least some MIPS chips, you get better * code by hand unrolling the loops, and by using store words to zero the * remainder of the buffer than the default newlib C version. * * Copyright (c) 2001 Red Hat, Inc. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include #include #include #include #if !defined(__GNUC__) || (__GNUC__ < 3) #define __builtin_expect(a, b) a #else #ifdef __mips64 /* Don't use limits test for the size of long, in order to allow the use of 64-bit stores on MIPS3 machines, even if -mlong32 was used. */ typedef unsigned word_type __attribute__((mode(DI))); #else typedef unsigned word_type __attribute__((mode(SI))); #endif typedef unsigned si_type __attribute__((mode(SI))); typedef unsigned hi_type __attribute__((mode(HI))); #ifndef UNROLL_FACTOR #define UNROLL_FACTOR 4 #elif (UNROLL_FACTOR != 2) && (UNROLL_FACTOR != 4) #error "UNROLL_FACTOR must be 2 or 4" #endif #endif char * strncpy(char *dst0, const char *src0, size_t count) { #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) || defined(__mips16) \ || !defined(__GNUC__) || (__GNUC__ < 3) char *dst, *end; const char *src; int ch; dst = dst0; src = src0; end = dst + count; while (dst != end) { *dst++ = ch = *src++; if (__builtin_expect(ch == '\0', 0)) { while (dst != end) *dst++ = '\0'; break; } } return dst0; #else unsigned char *dst; unsigned char *end; const unsigned char *src; int ch0, ch1; #if UNROLL_FACTOR > 2 int ch2, ch3; #endif int ch; int odd_bytes; dst = (unsigned char *)dst0; src = (unsigned const char *)src0; /* Take care of any odd bytes in the source data because we * want to unroll where we read ahead 2 or 4 bytes at a time and then * check each byte for the null terminator. This can result in * a segfault for the case where the source pointer is unaligned, * the null terminator is in valid memory, but reading 2 or 4 bytes at a * time blindly eventually goes outside of valid memory. */ while (((uintptr_t)src & (UNROLL_FACTOR - 1)) != 0 && count > 0) { *dst++ = ch = *src++; --count; if (ch == '\0') { end = dst + count; while (dst != end) *dst++ = '\0'; return dst0; } } if (__builtin_expect(count >= 4, 1)) { odd_bytes = (count & (UNROLL_FACTOR - 1)); count -= odd_bytes; do { ch0 = src[0]; ch1 = src[1]; #if UNROLL_FACTOR > 2 ch2 = src[2]; ch3 = src[3]; #endif src += UNROLL_FACTOR; count -= UNROLL_FACTOR; dst[0] = ch0; if (ch0 == '\0') goto found_null0; dst[1] = ch1; if (ch1 == '\0') goto found_null1; #if UNROLL_FACTOR > 2 dst[2] = ch2; if (ch2 == '\0') goto found_null2; dst[3] = ch3; if (ch3 == '\0') goto found_null3; #endif dst += UNROLL_FACTOR; } while (count); /* fall through, count == 0, no null found, deal with last bytes */ count = odd_bytes; } end = dst + count; while (dst != end) { *dst++ = ch = *src++; if (ch == '\0') { while (dst != end) *dst++ = '\0'; break; } } return dst0; /* Found null byte in first byte, count has been decremented by 4, null has been stored in dst[0]. */ found_null0: count++; /* add 1 to cover remaining byte */ dst -= 1; /* adjust dst += 4 gets correct ptr */ /* Found null byte in second byte, count has been decremented by 4, null has been stored in dst[1]. */ found_null1: #if UNROLL_FACTOR > 2 count++; /* add 1 to cover remaining byte */ dst -= 1; /* adjust dst += 4 gets correct ptr */ /* Found null byte in third byte, count has been decremented by 4, null has been stored in dst[2]. */ found_null2: count++; /* add 1 to cover remaining byte */ dst -= 1; /* adjust dst += 4 gets correct ptr */ /* Found null byte in fourth byte, count is accurate, dst has not been updated yet. */ found_null3: #endif count += odd_bytes; /* restore odd byte count */ dst += UNROLL_FACTOR; /* Zero fill remainder of the array. Unroll the loop, and use word/dword stores where we can. */ while (count && (((long)dst) & (sizeof(word_type) - 1)) != 0) { count--; *dst++ = 0; } while (count >= UNROLL_FACTOR * sizeof(word_type)) { count -= UNROLL_FACTOR * sizeof(word_type); dst += UNROLL_FACTOR * sizeof(word_type); #if UNROLL_FACTOR > 2 ((word_type *)(void *)dst)[-4] = 0; ((word_type *)(void *)dst)[-3] = 0; #endif ((word_type *)(void *)dst)[-2] = 0; ((word_type *)(void *)dst)[-1] = 0; } #if UNROLL_FACTOR > 2 if (count >= 2 * sizeof(word_type)) { count -= 2 * sizeof(word_type); ((word_type *)(void *)dst)[0] = 0; ((word_type *)(void *)dst)[1] = 0; dst += 2 * sizeof(word_type); } #endif if (count >= sizeof(word_type)) { count -= sizeof(word_type); ((word_type *)(void *)dst)[0] = 0; dst += sizeof(word_type); } #ifdef __mips64 if (count >= sizeof(si_type)) { count -= sizeof(si_type); ((si_type *)(void *)dst)[0] = 0; dst += sizeof(si_type); } #endif if (count >= sizeof(hi_type)) { count -= sizeof(hi_type); ((hi_type *)(void *)dst)[0] = 0; dst += sizeof(hi_type); } if (count) *dst = '\0'; return dst0; #endif } picolibc-1.8.11/libc/machine/mips/tls.c000066400000000000000000000036671513574234600176470ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #ifdef __THREAD_LOCAL_STORAGE_API void _set_tls(void *tls) { __asm__(".set push\n" #if _MIPS_SZPTR == 32 ".set mips32r2\n" #else ".set mips64r2\n" #endif "mtc0 %z0, $4, %1\n" ".set pop" : : "Jr"(tls), "i"(2)); } #endif picolibc-1.8.11/libc/machine/mn10200/000077500000000000000000000000001513574234600167125ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/mn10200/setjmp.S000066400000000000000000000022551513574234600203440ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .file "setjmp.S" .section .text .align 1 .global _setjmp _setjmp: mov d0,a0 movx d2,(0,a0) movx d3,(4,a0) mov a1,(8,a0) mov a2,(12,a0) mov a3,(16,a0) movx (0,a3),d0 movx d0,(20,a0) sub d0,d0 rts .global _longjmp _longjmp: mov d0,a0 movx (0,a0),d2 movx (4,a0),d3 mov (8,a0),a1 mov (12,a0),a2 mov (16,a0),a3 movx (20,a0),d0 movx d0,(0,a3) cmp 0,d1 bne L1 mov 1,d1 L1: mov d1,d0 rts picolibc-1.8.11/libc/machine/mn10300/000077500000000000000000000000001513574234600167135ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/mn10300/memchr.S000066400000000000000000000051321513574234600203130ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .file "memchr.S" .section .text .global _memchr .type _memchr,@function _memchr: movm [d2,d3,a2,a3],(sp) .Lend_of_prologue: mov d0,a0 mov d1,d2 mov (28,sp),a1 #ifndef __OPTIMIZE_SIZE__ cmp 3,a1 bls .L44 mov a0,d3 btst 3,d3 bne .L44 mov a0,a2 mov 0,a3 clr d1 setlb mov a3,d0 asl 8,d0 mov d2,a3 add d0,a3 inc d1 cmp 3,d1 lls cmp 3,a1 bls .L48 .L33: mov (a2),d0 mov a3,d3 xor d3,d0 mov d0,d1 not d1 add -16843009,d0 and d1,d0 btst -2139062144,d0 beq .L34 mov a2,a0 clr d1 setlb movbu (a0),d0 cmp d2,d0 beq .Lepilogue inc a0 inc d1 cmp 3,d1 lls .L34: add -4,a1 inc4 a2 cmp 3,a1 bhi .L33 .L48: mov a2,a0 .L44: #endif cmp 0,a1 beq .L50 setlb movbu (a0),d0 cmp d2,d0 beq .Lepilogue inc a0 sub 1,a1 lne .L50: mov 0,a0 .Lepilogue: ret [d2,d3,a2,a3],16 .Lend_of_memchr: .size _memchr, .Lend_of_memchr - _memchr .section .debug_frame,"",@progbits .Lstart_of_debug_frame: # Common Information Entry (CIE) .4byte .Lend_of_CIE - .Lstart_of_CIE # CIE Length .Lstart_of_CIE: .4byte 0xffffffff # CIE Identifier Tag .byte 0x1 # CIE Version .ascii "\0" # CIE Augmentation .uleb128 0x1 # CIE Code Alignment Factor .sleb128 -4 # CIE Data Alignment Factor .byte 0x32 # CIE RA Column .byte 0xc # DW_CFA_def_cfa .uleb128 0x9 .uleb128 0x0 .byte 0xb2 # DW_CFA_offset, column 0x32 .uleb128 0x0 .align 2 .Lend_of_CIE: # Frame Description Entry (FDE) .4byte .Lend_of_FDE - .Lstart_of_FDE # FDE Length .Lstart_of_FDE: .4byte .Lstart_of_debug_frame # FDE CIE offset .4byte _memchr # FDE initial location .4byte .Lend_of_memchr - _memchr # FDE address range .byte 0x4 # DW_CFA_advance_loc4 .4byte .Lend_of_prologue - _memchr .byte 0xe # DW_CFA_def_cfa_offset .uleb128 0x4 .byte 0x87 # DW_CFA_offset, column 0x7 .uleb128 0x1 .align 2 .Lend_of_FDE: picolibc-1.8.11/libc/machine/mn10300/memcmp.S000066400000000000000000000045451513574234600203250ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .file "memcmp.S" .section .text .global _memcmp .type _memcmp,@function _memcmp: movm [d2,d3,a2,a3],(sp) .Lend_of_prologue: mov d0,a0 mov d1,a1 mov (28,sp),a2 #ifndef __OPTIMIZE_SIZE__ cmp 3,a2 bls .L22 mov a1,d2 or d2,d0 btst 3,d0 bne .L22 setlb mov (a0),d1 mov (a1),d0 cmp d0,d1 bne .L22 inc4 a0 inc4 a1 add -4,a2 cmp 3,a2 lhi .L22: #endif cmp 0,a2 beq .L24 setlb movbu (a0),d3 movbu (a1),d2 cmp d2,d3 beq .L23 mov d3,d0 sub d2,d0 jmp .Lepilogue .L23: inc a0 inc a1 sub 1,a2 lne .L24: clr d0 .Lepilogue: ret [d2,d3,a2,a3],16 .Lend_of_func: .size _memcmp, .Lend_of_func - _memcmp .section .debug_frame,"",@progbits .Lstart_of_debug_frame: # Common Information Entry (CIE) .4byte .Lend_of_CIE - .Lstart_of_CIE # CIE Length .Lstart_of_CIE: .4byte 0xffffffff # CIE Identifier Tag .byte 0x1 # CIE Version .ascii "\0" # CIE Augmentation .uleb128 0x1 # CIE Code Alignment Factor .sleb128 -4 # CIE Data Alignment Factor .byte 0x32 # CIE RA Column .byte 0xc # DW_CFA_def_cfa .uleb128 0x9 .uleb128 0x0 .byte 0xb2 # DW_CFA_offset, column 0x32 .uleb128 0x0 .align 2 .Lend_of_CIE: # Frame Description Entry (FDE) .4byte .Lend_of_FDE - .Lstart_of_FDE # FDE Length .Lstart_of_FDE: .4byte .Lstart_of_debug_frame # FDE CIE offset .4byte _memcmp # FDE initial location .4byte .Lend_of_func - _memcmp # FDE address range .byte 0x4 # DW_CFA_advance_loc4 .4byte .Lend_of_prologue - _memcmp .byte 0xe # DW_CFA_def_cfa_offset .uleb128 0x4 .byte 0x87 # DW_CFA_offset, column 0x7 .uleb128 0x1 .align 2 .Lend_of_FDE: picolibc-1.8.11/libc/machine/mn10300/memcpy.S000066400000000000000000000050211513574234600203270ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .file "memcpy.S" .section .text .global _memcpy .type _memcpy,@function _memcpy: movm [d2,d3,a2,a3],(sp) .Lend_of_prologue: mov d0,d2 mov d1,a0 mov d2,a1 mov (28,sp),d1 #ifndef __OPTIMIZE_SIZE__ mov a0,d0 or d2,d0 btst 3,d0 bne .L37 cmp 15,d1 bls .L34 setlb mov (a0),d0 mov d0,(a1) inc4 a0 inc4 a1 mov (a0),d0 mov d0,(a1) inc4 a0 inc4 a1 mov (a0),d0 mov d0,(a1) inc4 a0 inc4 a1 mov (a0),d0 mov d0,(a1) inc4 a0 inc4 a1 add -16,d1 cmp 15,d1 lhi .L34: cmp 3,d1 bls .L37 setlb mov (a0),d0 mov d0,(a1) inc4 a0 inc4 a1 add -4,d1 cmp 3,d1 lhi .L37: #endif cmp 0,d1 beq .L36 setlb movbu (a0),d0 movbu d0,(a1) inc a0 inc a1 sub 1,d1 lne .L36: mov d2,a0 .Lepilogue: ret [d2,d3,a2,a3],16 .Lend_of_memcpy: .size _memcpy, .Lend_of_memcpy - _memcpy .section .debug_frame,"",@progbits .Lstart_of_debug_frame: # Common Information Entry (CIE) .4byte .Lend_of_CIE - .Lstart_of_CIE # CIE Length .Lstart_of_CIE: .4byte 0xffffffff # CIE Identifier Tag .byte 0x1 # CIE Version .ascii "\0" # CIE Augmentation .uleb128 0x1 # CIE Code Alignment Factor .sleb128 -4 # CIE Data Alignment Factor .byte 0x32 # CIE RA Column .byte 0xc # DW_CFA_def_cfa .uleb128 0x9 .uleb128 0x0 .byte 0xb2 # DW_CFA_offset, column 0x32 .uleb128 0x0 .align 2 .Lend_of_CIE: # Frame Description Entry (FDE) .4byte .Lend_of_FDE - .Lstart_of_FDE # FDE Length .Lstart_of_FDE: .4byte .Lstart_of_debug_frame # FDE CIE offset .4byte _memcpy # FDE initial location .4byte .Lend_of_memcpy - _memcpy # FDE address range .byte 0x4 # DW_CFA_advance_loc4 .4byte .Lend_of_prologue - _memcpy .byte 0xe # DW_CFA_def_cfa_offset .uleb128 0x4 .byte 0x87 # DW_CFA_offset, column 0x7 .uleb128 0x1 .align 2 .Lend_of_FDE: picolibc-1.8.11/libc/machine/mn10300/memset.S000066400000000000000000000050651513574234600203370ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .file "memset.S" .section .text .global _memset .type _memset,@function _memset: movm [d2,d3,a2,a3], (sp) .Lend_of_prologue: mov d0, d3 mov d1, d2 mov (28, sp),a1 mov d3, a0 #ifndef __OPTIMIZE_SIZE__ cmp 3, a1 bls .L41 btst 3, d3 bne .L41 extbu d2 mov d2, d1 asl 8, d1 or d2, d1 mov d1, d0 asl 16, d0 or d0, d1 cmp 15, a1 bls .L36 setlb mov d1, (a0) inc4 a0 mov d1, (a0) inc4 a0 mov d1, (a0) inc4 a0 mov d1, (a0) inc4 a0 add -16, a1 cmp 15, a1 lhi .L36: cmp 3, a1 bls .L41 setlb mov d1, (a0) inc4 a0 add -4, a1 cmp 3, a1 lhi .L41: #endif cmp 0, a1 beq .Lepilogue setlb movbu d2, (a0) inc a0 sub 1, a1 lne .Lepilogue: mov d3,a0 ret [d2,d3,a2,a3], 16 .Lend_of_memset: .size _memset, .Lend_of_memset - _memset .section .debug_frame,"",@progbits .Lstart_of_debug_frame: # Common Information Entry (CIE) .4byte .Lend_of_CIE - .Lstart_of_CIE # CIE Length .Lstart_of_CIE: .4byte 0xffffffff # CIE Identifier Tag .byte 0x1 # CIE Version .ascii "\0" # CIE Augmentation .uleb128 0x1 # CIE Code Alignment Factor .sleb128 -4 # CIE Data Alignment Factor .byte 0x32 # CIE RA Column .byte 0xc # DW_CFA_def_cfa .uleb128 0x9 .uleb128 0x0 .byte 0xb2 # DW_CFA_offset, column 0x32 .uleb128 0x0 .align 2 .Lend_of_CIE: # Frame Description Entry (FDE) .4byte .Lend_of_FDE - .Lstart_of_FDE # FDE Length .Lstart_of_FDE: .4byte .Lstart_of_debug_frame # FDE CIE offset .4byte _memset # FDE initial location .4byte .Lend_of_memset - _memset # FDE address range .byte 0x4 # DW_CFA_advance_loc4 .4byte .Lend_of_prologue - _memset .byte 0xe # DW_CFA_def_cfa_offset .uleb128 0x4 .byte 0x87 # DW_CFA_offset, column 0x7 .uleb128 0x1 .align 2 .Lend_of_FDE: picolibc-1.8.11/libc/machine/mn10300/setjmp.S000066400000000000000000000041031513574234600203370ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .file "setjmp.S" .section .text .align 1 .global _setjmp #ifdef __AM33__ #ifdef __AM33_2__ .am33_2 #else .am33 #endif #endif _setjmp: mov d0,a0 mov d2,(0,a0) mov d3,(4,a0) mov mdr,d1 mov d1,(8,a0) mov a2,(12,a0) mov a3,(16,a0) mov sp,a1 mov a1,(20,a0) #ifdef __AM33__ add 24,a0 mov r4,(a0+) mov r5,(a0+) mov r6,(a0+) mov r7,(a0+) #ifdef __AM33_2__ fmov fs4,(a0+) fmov fs5,(a0+) fmov fs6,(a0+) fmov fs7,(a0+) fmov fs8,(a0+) fmov fs9,(a0+) fmov fs10,(a0+) fmov fs11,(a0+) fmov fs12,(a0+) fmov fs13,(a0+) fmov fs14,(a0+) fmov fs15,(a0+) fmov fs16,(a0+) fmov fs17,(a0+) fmov fs18,(a0+) fmov fs19,(a0+) #endif #endif sub d0,d0 rets .global _longjmp _longjmp: mov d0,a0 mov (8,a0),d2 mov d2,mdr mov (0,a0),d2 mov (4,a0),d3 mov (12,a0),a2 mov (16,a0),a3 mov (20,a0),a1 mov a1,sp #ifdef __AM33__ add 24,a0 mov (a0+),r4 mov (a0+),r5 mov (a0+),r6 mov (a0+),r7 #ifdef __AM33_2__ fmov (a0+),fs4 fmov (a0+),fs5 fmov (a0+),fs6 fmov (a0+),fs7 fmov (a0+),fs8 fmov (a0+),fs9 fmov (a0+),fs10 fmov (a0+),fs11 fmov (a0+),fs12 fmov (a0+),fs13 fmov (a0+),fs14 fmov (a0+),fs15 fmov (a0+),fs16 fmov (a0+),fs17 fmov (a0+),fs18 fmov (a0+),fs19 #endif #endif cmp 0,d1 bne L1 mov 1,d1 L1: mov d1,d0 retf [],0 picolibc-1.8.11/libc/machine/mn10300/strchr.S000066400000000000000000000054441513574234600203530ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .file "strchr.S" .section .text .global _strchr .type _strchr,@function _strchr: movm [d2,d3,a2,a3],(sp) add -12,sp .Lend_of_prologue: mov d0,a1 movbu d1,(7,sp) #ifndef __OPTIMIZE_SIZE__ btst 3,d0 bne .L20 clr d0 setlb mov sp,a2 mov d0,d3 add d3,a2 mov a2,a0 add 12,a0 movbu (7,sp),d3 movbu d3,(-4,a0) inc d0 cmp 3,d0 lls mov a1,a0 mov -16843009,a1 mov (a0),d2 mov a1,d1 add d2,d1 mov d2,d0 not d0 and d0,d1 mov -2139062144,d3 mov d3,(0,sp) btst -2139062144,d1 bne .L27 jmp .L38 .L28: inc4 a0 mov (a0),d2 mov a1,d1 add d2,d1 mov d2,d0 not d0 and d0,d1 mov (0,sp),d3 and d3,d1 bne .L27 .L38: mov (8,sp),d0 xor d2,d0 mov a1,d1 add d0,d1 not d0 and d0,d1 and d3,d1 beq .L28 .L27: mov a0,a1 .L20: #endif movbu (a1),d0 cmp 0,d0 beq .L32 movbu (7,sp),d1 setlb cmp d1,d0 beq .L36 inc a1 movbu (a1),d0 cmp 0,d0 lne .L32: movbu (7,sp),d0 movbu (a1),d3 cmp d0,d3 beq .L36 mov 0,a0 jmp .Lepilogue .L36: mov a1,a0 .Lepilogue: ret [d2,d3,a2,a3],28 .Lend_of_strchr: .size _strchr, .Lend_of_strchr - _strchr .section .debug_frame,"",@progbits .Lstart_of_debug_frame: # Common Information Entry (CIE) .4byte .Lend_of_CIE - .Lstart_of_CIE # CIE Length .Lstart_of_CIE: .4byte 0xffffffff # CIE Identifier Tag .byte 0x1 # CIE Version .ascii "\0" # CIE Augmentation .uleb128 0x1 # CIE Code Alignment Factor .sleb128 -4 # CIE Data Alignment Factor .byte 0x32 # CIE RA Column .byte 0xc # DW_CFA_def_cfa .uleb128 0x9 .uleb128 0x0 .byte 0xb2 # DW_CFA_offset, column 0x32 .uleb128 0x0 .align 2 .Lend_of_CIE: # Frame Description Entry (FDE) .4byte .Lend_of_FDE - .Lstart_of_FDE # FDE Length .Lstart_of_FDE: .4byte .Lstart_of_debug_frame # FDE CIE offset .4byte _strchr # FDE initial location .4byte .Lend_of_strchr - _strchr # FDE address range .byte 0x4 # DW_CFA_advance_loc4 .4byte .Lend_of_prologue - _strchr .byte 0xe # DW_CFA_def_cfa_offset .uleb128 0x4 .byte 0x87 # DW_CFA_offset, column 0x7 .uleb128 0x1 .align 2 .Lend_of_FDE: picolibc-1.8.11/libc/machine/mn10300/strcmp.S000066400000000000000000000046301513574234600203520ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .file "strcmp.S" .section .text .global _strcmp .type _strcmp,@function _strcmp: movm [d2,d3,a2,a3],(sp) .Lend_of_prologue: mov d0,a0 mov d1,a1 #ifndef __OPTIMIZE_SIZE__ or d1,d0 btst 3,d0 bne .L11 mov (a0),d1 mov (a1),d0 cmp d0,d1 bne .L11 mov -16843009,d3 setlb mov (a0),d0 mov d3,d1 add d0,d1 not d0 and d0,d1 and -2139062144,d1 beq .L6 clr d0 jmp .Lepilogue .L6: inc4 a0 inc4 a1 mov (a0),d1 mov (a1),d0 cmp d0,d1 leq .L11: #endif setlb movbu (a1),d2 movbu (a0),d0 cmp 0,d0 beq .L9 cmp d2,d0 bne .L9 inc a0 inc a1 lra .L9: sub d2,d0 .Lepilogue: ret [d2,d3,a2,a3],16 .Lend_of_strcmp: .size _strcmp, .Lend_of_strcmp - _strcmp .section .debug_frame,"",@progbits .Lstart_of_debug_frame: # Common Information Entry (CIE) .4byte .Lend_of_CIE - .Lstart_of_CIE # CIE Length .Lstart_of_CIE: .4byte 0xffffffff # CIE Identifier Tag .byte 0x1 # CIE Version .ascii "\0" # CIE Augmentation .uleb128 0x1 # CIE Code Alignment Factor .sleb128 -4 # CIE Data Alignment Factor .byte 0x32 # CIE RA Column .byte 0xc # DW_CFA_def_cfa .uleb128 0x9 .uleb128 0x0 .byte 0xb2 # DW_CFA_offset, column 0x32 .uleb128 0x0 .align 2 .Lend_of_CIE: # Frame Description Entry (FDE) .4byte .Lend_of_FDE - .Lstart_of_FDE # FDE Length .Lstart_of_FDE: .4byte .Lstart_of_debug_frame # FDE CIE offset .4byte _strcmp # FDE initial location .4byte .Lend_of_strcmp - _strcmp # FDE address range .byte 0x4 # DW_CFA_advance_loc4 .4byte .Lend_of_prologue - _strcmp .byte 0xe # DW_CFA_def_cfa_offset .uleb128 0x4 .byte 0x87 # DW_CFA_offset, column 0x7 .uleb128 0x1 .align 2 .Lend_of_FDE: picolibc-1.8.11/libc/machine/mn10300/strcpy.S000066400000000000000000000046121513574234600203660ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .file "strcpy.S" .section .text .global _strcpy .type _strcpy,@function _strcpy: movm [d2,d3,a2,a3],(sp) .Lend_of_prologue: mov d0,d3 mov d1,a0 mov d3,a1 mov a0,d0 #ifndef __OPTIMIZE_SIZE__ or d3,d0 btst 3,d0 bne .L2 mov (a0),d0 mov -16843009,a2 mov a2,d1 add d0,d1 not d0 and d0,d1 mov -2139062144,d2 btst -2139062144,d1 bne .L2 setlb mov (a0),d0 mov d0,(a1) inc4 a0 inc4 a1 mov (a0),d0 mov a2,d1 add d0,d1 not d0 and d0,d1 and d2,d1 leq .L2: #endif setlb movbu (a0),d0 movbu d0,(a1) inc a0 inc a1 cmp 0,d0 lne mov d3,a0 .Lepilogue: ret [d2,d3,a2,a3],16 .Lend_of_strcpy: .size _strcpy, .Lend_of_strcpy - _strcpy .section .debug_frame,"",@progbits .Lstart_of_debug_frame: # Common Information Entry (CIE) .4byte .Lend_of_CIE - .Lstart_of_CIE # CIE Length .Lstart_of_CIE: .4byte 0xffffffff # CIE Identifier Tag .byte 0x1 # CIE Version .ascii "\0" # CIE Augmentation .uleb128 0x1 # CIE Code Alignment Factor .sleb128 -4 # CIE Data Alignment Factor .byte 0x32 # CIE RA Column .byte 0xc # DW_CFA_def_cfa .uleb128 0x9 .uleb128 0x0 .byte 0xb2 # DW_CFA_offset, column 0x32 .uleb128 0x0 .align 2 .Lend_of_CIE: # Frame Description Entry (FDE) .4byte .Lend_of_FDE - .Lstart_of_FDE # FDE Length .Lstart_of_FDE: .4byte .Lstart_of_debug_frame # FDE CIE offset .4byte _strcpy # FDE initial location .4byte .Lend_of_strcpy - _strcpy # FDE address range .byte 0x4 # DW_CFA_advance_loc4 .4byte .Lend_of_prologue - _strcpy .byte 0xe # DW_CFA_def_cfa_offset .uleb128 0x4 .byte 0x87 # DW_CFA_offset, column 0x7 .uleb128 0x1 .align 2 .Lend_of_FDE: picolibc-1.8.11/libc/machine/mn10300/strlen.S000066400000000000000000000045131513574234600203510ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .file "strlen.S" .section .text .global _strlen .type _strlen,@function _strlen: movm [d2,d3,a2,a3],(sp) .Lend_of_prologue: mov d0,a0 mov a0,a2 #ifndef __OPTIMIZE_SIZE__ btst 3,d0 bne .L21 mov (a0),d0 mov -16843009,a1 mov a1,d1 add d0,d1 not d0 and d0,d1 mov -2139062144,d2 btst -2139062144,d1 bne .L21 setlb inc4 a0 mov (a0),d0 mov a1,d1 add d0,d1 not d0 and d0,d1 and d2,d1 leq jmp .L21 #endif .L19: inc a0 .L21: movbu (a0),d3 cmp 0,d3 bne .L19 sub a2,a0 mov a0,d0 .Lepilogue: ret [d2,d3,a2,a3],16 .Lend_of_strlen: .size _strlen, .Lend_of_strlen - _strlen .section .debug_frame,"",@progbits .Lstart_of_debug_frame: # Common Information Entry (CIE) .4byte .Lend_of_CIE - .Lstart_of_CIE # CIE Length .Lstart_of_CIE: .4byte 0xffffffff # CIE Identifier Tag .byte 0x1 # CIE Version .ascii "\0" # CIE Augmentation .uleb128 0x1 # CIE Code Alignment Factor .sleb128 -4 # CIE Data Alignment Factor .byte 0x32 # CIE RA Column .byte 0xc # DW_CFA_def_cfa .uleb128 0x9 .uleb128 0x0 .byte 0xb2 # DW_CFA_offset, column 0x32 .uleb128 0x0 .align 2 .Lend_of_CIE: # Frame Description Entry (FDE) .4byte .Lend_of_FDE - .Lstart_of_FDE # FDE Length .Lstart_of_FDE: .4byte .Lstart_of_debug_frame # FDE CIE offset .4byte _strlen # FDE initial location .4byte .Lend_of_strlen - _strlen # FDE address range .byte 0x4 # DW_CFA_advance_loc4 .4byte .Lend_of_prologue - _strlen .byte 0xe # DW_CFA_def_cfa_offset .uleb128 0x4 .byte 0x87 # DW_CFA_offset, column 0x7 .uleb128 0x1 .align 2 .Lend_of_FDE: picolibc-1.8.11/libc/machine/moxie/000077500000000000000000000000001513574234600170365ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/moxie/setjmp.S000066400000000000000000000037221513574234600204700ustar00rootroot00000000000000/* A setjmp.c for Moxie Copyright (C) 2009, 2019 Anthony Green The authors hereby grant permission to use, copy, modify, distribute, and license this software and its documentation for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions. No written agreement, license, or royalty fee is required for any of the authorized uses. Modifications to this software may be copyrighted by their authors and need not follow the licensing terms described here, provided that the new terms are clearly indicated on the first page of each file where they apply. */ #include # setjmp/longjmp for moxie. The jmpbuf looks like this: # # Register jmpbuf offset # $r6 0x00 # $r7 0x04 # $r8 0x08 # $r9 0x0c # $r10 0x10 # $fp 0x14 # $sp 0x18 # stack frame fp 0x1c # stack frame ra 0x20 # stack frame sc 0x25 .text .global setjmp .type setjmp,@function setjmp: st.l ($r0), $r6 sto.l 0x04($r0), $r7 sto.l 0x08($r0), $r8 sto.l 0x0c($r0), $r9 sto.l 0x10($r0), $r10 sto.l 0x14($r0), $sp sto.l 0x18($r0), $fp ldo.l $r1, 0x00($fp) sto.l 0x1c($r0), $r1 ldo.l $r1, 0x04($fp) sto.l 0x20($r0), $r1 ldo.l $r1, 0x08($fp) sto.l 0x24($r0), $r1 xor $r0, $r0 ret .Lend1: .size setjmp,.Lend1-setjmp .global longjmp .type longjmp,@function longjmp: ldo.l $r6, 0x00($r0) ldo.l $r7, 0x04($r0) ldo.l $r8, 0x08($r0) ldo.l $r9, 0x0c($r0) ldo.l $r10, 0x10($r0) ldo.l $sp, 0x14($r0) ldo.l $fp, 0x18($r0) ldo.l $r2, 0x1c($r0) sto.l 0x0($fp), $r2 ldo.l $r2, 0x20($r0) sto.l 0x4($fp), $r2 ldo.l $r2, 0x24($r0) sto.l 0x8($fp), $r2 ldo.l $r2, 0x08($r0) mov $r0, $r1 xor $r2, $r2 cmp $r0, $r2 beq .Lreturn1 ret .Lreturn1: inc $r0, 1 ret .Lend2: .size longjmp,.Lend2-longjmp picolibc-1.8.11/libc/machine/msp430/000077500000000000000000000000001513574234600167435ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/msp430/CMakeLists.txt000066400000000000000000000031601513574234600215030ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2026 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources_flags("-fno-builtin" interrupt.S setjmp.S ) picolibc-1.8.11/libc/machine/msp430/interrupt.S000066400000000000000000000002631513574234600211240ustar00rootroot00000000000000#include .text .section .rodata.vector .globl __interrupt_vector __interrupt_vector: .fill 31, 2, 0 .word _start .size __interrupt_vector,.-__interrupt_vector picolibc-1.8.11/libc/machine/msp430/meson.build000066400000000000000000000036721513574234600211150ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'interrupt.S', 'setjmp.S', ] foreach params : targets target = params['name'] target_dir = params['dir'] target_c_args = params['c_args'] set_variable('lib_machine' + target, static_library('machine' + target, srcs_machine, pic: false, include_directories: inc, c_args: target_c_args + c_args + arg_fnobuiltin)) endforeach picolibc-1.8.11/libc/machine/msp430/setjmp.S000066400000000000000000000045611513574234600203770ustar00rootroot00000000000000/* Copyright (c) 2013 Red Hat, Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the BSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. Any Red Hat trademarks that are incorporated in the source code or documentation are not subject to the BSD License and may only be used or replicated with the express permission of Red Hat, Inc. */ #include # setjmp/longjmp for msp430. The jmpbuf looks like this: # # Register Jmpbuf offset # small large # r0 (pc) 0x00 0x00 # r1 (sp) 0x02 0x04 # r4 0x04 0x08 # r5 0x06 0x0c # r6 0x08 0x10 # r7 0x0a 0x14 # r8 0x0c 0x18 # r9 0x0e 0x1c # r10 0x10 0x20 .text .global setjmp setjmp: ; Upon entry r12 points to the jump buffer. ; Returns 0 to caller. #if defined __MSP430X_LARGE__ mova @r1, r13 mova r13, 0(r12) mova r1, 4(r12) mova r4, 8(r12) mova r5, 12(r12) mova r6, 16(r12) mova r7, 20(r12) mova r8, 24(r12) mova r9, 28(r12) mova r10, 32(r12) clr r12 reta #else ;; Get the return address off the stack mov.w @r1, r13 mov.w r13, 0(r12) mov.w r1, 2(r12) mov.w r4, 4(r12) mov.w r5, 6(r12) mov.w r6, 8(r12) mov.w r7, 10(r12) mov.w r8, 12(r12) mov.w r9, 14(r12) mov.w r10, 16(r12) clr r12 ret #endif .size setjmp , . - setjmp .global longjmp longjmp: ; Upon entry r12 points to the jump buffer and ; r13 contains the value to be returned by setjmp. #if defined __MSP430X_LARGE__ mova @r12+, r14 mova @r12+, r1 mova @r12+, r4 mova @r12+, r5 mova @r12+, r6 mova @r12+, r7 mova @r12+, r8 mova @r12+, r9 mova @r12+, r10 #else mov.w @r12+, r14 mov.w @r12+, r1 mov.w @r12+, r4 mov.w @r12+, r5 mov.w @r12+, r6 mov.w @r12+, r7 mov.w @r12+, r8 mov.w @r12+, r9 mov.w @r12+, r10 #endif ; If caller attempts to return 0, return 1 instead. cmp.w #0, r13 jne .Lnot_zero mov.w #1, r13 .Lnot_zero: mov.w r13, r12 #if defined __MSP430X_LARGE__ adda #4, r1 mova r14, r0 #else add.w #2, r1 mov.w r14, r0 #endif .size longjmp , . - longjmp picolibc-1.8.11/libc/machine/mt/000077500000000000000000000000001513574234600163355ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/mt/setjmp.S000066400000000000000000000030311513574234600177600ustar00rootroot00000000000000/* Copyright (c) 2005 Aldy Hernandez */ #include # setjmp/longjmp for mt. # # The jmpbuf looks like this: # # Register jmpbuf offset # R0 --- -- # R1 0x4 4 # R2 0x8 8 # R3 0xc 12 # R4 0x10 16 # R5 0x14 20 # R6 0x18 24 # R7 0x1c 28 # R8 0x20 32 # R9 ---- -- # R10 ---- -- # R11 0x2c 44 # R12 0x30 48 # R13 0x34 52 # R14 0x38 56 # R15 0x3c 60 # # R1 contains the pointer to jmpbuf .text .global setjmp .type setjmp ,@function setjmp: stw r1, r1, #4 or r0, r0, r0 stw r2, r1, #8 or r0, r0, r0 stw r3, r1, #12 or r0, r0, r0 stw r4, r1, #16 or r0, r0, r0 stw r5, r1, #20 or r0, r0, r0 stw r6, r1, #24 or r0, r0, r0 stw r7, r1, #28 or r0, r0, r0 stw r8, r1, #32 or r0, r0, r0 stw r11, r1, #44 or r0, r0, r0 stw r12, r1, #48 or r0, r0, r0 stw r13, r1, #52 or r0, r0, r0 stw r14, r1, #56 or r0, r0, r0 stw r15, r1, #60 jal r0, r14 addi r11, r0, #0 .Lend1: .size setjmp,.Lend1-setjmp .global longjmp .type longjmp,@function longjmp: or r9, r1, r1 or r11, r2, r2 ldw r1, r1, #4 or r0, r0, r0 ldw r2, r1, #8 or r0, r0, r0 ldw r3, r1, #12 or r0, r0, r0 ldw r4, r1, #16 or r0, r0, r0 ldw r5, r1, #20 or r0, r0, r0 ldw r6, r1, #24 or r0, r0, r0 ldw r7, r1, #28 or r0, r0, r0 ldw r8, r1, #32 or r0, r0, r0 ldw r12, r1, #48 or r0, r0, r0 ldw r13, r1, #52 or r0, r0, r0 ldw r14, r1, #56 or r0, r0, r0 ldw r15, r1, #60 brne r0, r11, .L01 or r0, r0, r0 addi r11, r0, #1 .L01: jal r0, r14 or r0, r0, r0 .Lend2: .size longjmp,.Lend2-longjmp2 picolibc-1.8.11/libc/machine/nds32/000077500000000000000000000000001513574234600166465ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/nds32/abort.c000066400000000000000000000041671513574234600201310ustar00rootroot00000000000000/* Copyright (c) 2013 Andes Technology Corporation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of the company may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>---abnormal termination of a program INDEX abort SYNOPSIS #include void abort(void); DESCRIPTION Use <> to signal that your program has detected a condition it cannot deal with. Normally, <> ends your program's execution. In general implementation, <> raises the exception <>. But for nds32 target, currently it is not necessary for MCU platform. We can just call <<_exit>> to terminate program. RETURNS <> does not return to its caller. PORTABILITY ANSI C requires <>. Supporting OS subroutines required: <<_exit>>. */ #include #include void abort(void) { while (1) { _exit(1); } } picolibc-1.8.11/libc/machine/nds32/memcpy.S000066400000000000000000000053041513574234600202660ustar00rootroot00000000000000/* Copyright (c) 2013 Andes Technology Corporation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of the company may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Function: memcpy - copy memory regions Syntax: void *memcpy(void *s1, const void *s2, size_t n); Description: The memcpy function copies n characters from the object pointed to by s2 into the object pointed to by s1. If copying takes place between objects that overlap, the behavior is undefined. Return value: The memcpy function returns the value of s1. */ #include .text .align 2 .globl memcpy .type memcpy, @function memcpy: /* Corner cases. If *s1 equals *s2 or size_t is zero, just go return. */ beq $r0, $r1, .Lend_memcpy beqz $r2, .Lend_memcpy /* Keep *s1 as return value. Set $r3 as how many words to copy. Set $r2 as how many bytes are less than a word. */ move $r5, $r0 srli $r3, $r2, 2 andi $r2, $r2, 3 beqz $r3, .Lbyte_copy .Lword_copy: /* Do the word copy $r3 times. Then, do the byte copy $r2 times. */ lmw.bim $r4, [$r1], $r4, 0 addi $r3, $r3, -1 smw.bim $r4, [$r5], $r4, 0 bnez $r3, .Lword_copy /* Loop again ? */ beqz $r2, .Lend_memcpy /* Fall THRU or go return ? */ .Lbyte_copy: /* Do the byte copy $r2 times. */ lbi.bi $r4, [$r1], 1 addi $r2, $r2, -1 sbi.bi $r4, [$r5], 1 bnez $r2, .Lbyte_copy /* Loop again ? */ .Lend_memcpy: ret .size memcpy, .-memcpy picolibc-1.8.11/libc/machine/nds32/memset.S000066400000000000000000000057521513574234600202750ustar00rootroot00000000000000/* Copyright (c) 2013 Andes Technology Corporation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of the company may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Function: memset - fill memory with a constant byte Syntax: void *memset(void *s, int c, size_t n); Description: The memset function copies the value of c (converted to an unsigned char) into each of the first n characters of the object pointed to by s. Return value: The memset function returns the value of s. */ #include .text .align 2 .globl memset .type memset, @function memset: /* Corner case. If n is zero, just go return. */ beqz $r2, .Lend_memset /* Keep $r0 as return value. Set $r4 as how many words to copy. Set $r2 as how many bytes are less than a word. */ move $r5, $r0 srli $r4, $r2, 2 andi $r2, $r2, 3 beqz $r4, .Lbyte_set /* Set $r1 a word-size pattern composed of the value of c (converted to an unsigned char). Convert ??????ab to abababab. */ andi $r1, $r1, 0xff /* Set $r1 = 000000ab. */ slli $r3, $r1, 8 /* Set $r3 = 0000ab00. */ or $r1, $r1, $r3 /* Set $r1 = 0000abab. */ slli $r3, $r1, 16 /* Set $r3 = abab0000. */ or $r1, $r1, $r3 /* Set $r1 = abababab. */ .Lword_set: /* Do the word set $r4 times. Then, do the byte set $r2 times. */ addi $r4, $r4, -1 smw.bim $r1, [$r5], $r1 /* Set a word-size. */ bnez $r4, .Lword_set /* Loop again ? */ beqz $r2, .Lend_memset /* Fall THRU or go return ? */ .Lbyte_set: /* Do the byte set $r2 times. */ addi $r2, $r2, -1 sbi.p $r1, [$r5], 1 /* Set a byte-size. */ bnez $r2, .Lbyte_set /* Loop again ? */ .Lend_memset: ret .size memset, .-memset picolibc-1.8.11/libc/machine/nds32/setjmp.S000066400000000000000000000116051513574234600202770ustar00rootroot00000000000000/* Copyright (c) 2013 Andes Technology Corporation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of the company may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The setjmp/longjmp for nds32. The usage of thirty-two 32-bit General Purpose Registers (GPR): $r28 : $fp $r29 : $gp $r30 : $lp $r31 : $sp caller-save registers: $r0 ~ $r5, $r16 ~ $r23 callee-save registers: $r6 ~ $r10, $r11 ~ $r14 reserved for assembler : $r15 reserved for other use : $r24, $r25, $r26, $r27 Save all callee-save registers and $fp, $gp, $lp and $sp is enough in theory. For debugging issue, the layout of jum_buf in here should be in sync with GDB. The $r16 ~ $r19 are used to store D0/D1, keep them for backward-compatible. */ /* int setjmp(jmp_buf env); */ #include .text .align 2 .global setjmp .type setjmp, @function setjmp: #if __NDS32_REDUCED_REGS__ smw.bim $r6, [$r0], $r10, #0b0000 addi $r0, $r0, #32 /* Leave room to keep jum_buf all the same. */ smw.bim $r31, [$r0], $r31, #0b1111 #else smw.bim $r6, [$r0], $r14, #0b0000 smw.bim $r16, [$r0], $r19, #0b1111 #endif #if __NDS32_EXT_FPU_SP__ || __NDS32_EXT_FPU_DP__ /* Extract $fpcfg.freg (b[3:2]), then save into jmp_buf. */ fmfcfg $r2 slli $r2, $r2, #28 srli $r2, $r2, #30 swi.bi $r2, [$r0], #4 /* Make sure $r0 is double-word-aligned. */ addi $r0, $r0, #7 bitci $r0, $r0, #7 /* Case switch according to $fpcfg.freg */ beqz $r2, .LCFG0_save /* Branch if $fpcfg.freg = 0b00. */ xori $r15, $r2, #0b10 beqz $r15, .LCFG2_save /* Branch $fpcfg.freg = 0b10. */ srli $r2, $r2, #0b01 beqz $r2, .LCFG1_save /* Branch if $fpcfg.freg = 0b01. */ /* Fall-through if $fpcfg.freg = 0b11. */ .LCFG3_save: fsdi.bi $fd31, [$r0], #8 fsdi.bi $fd29, [$r0], #8 fsdi.bi $fd27, [$r0], #8 fsdi.bi $fd25, [$r0], #8 fsdi.bi $fd23, [$r0], #8 fsdi.bi $fd21, [$r0], #8 fsdi.bi $fd19, [$r0], #8 fsdi.bi $fd17, [$r0], #8 .LCFG2_save: fsdi.bi $fd15, [$r0], #8 fsdi.bi $fd13, [$r0], #8 fsdi.bi $fd11, [$r0], #8 fsdi.bi $fd9, [$r0], #8 .LCFG1_save: fsdi.bi $fd7, [$r0], #8 fsdi.bi $fd5, [$r0], #8 .LCFG0_save: fsdi.bi $fd3, [$r0], #8 #endif /* Set return value to zero. */ movi $r0, 0 ret .size setjmp, .-setjmp /* void longjmp(jmp_buf env, int val); */ .text .align 2 .global longjmp .type longjmp, @function longjmp: #if __NDS32_REDUCED_REGS__ lmw.bim $r6, [$r0], $r10, #0b0000 addi $r0, $r0, #32 lmw.bim $r31, [$r0], $r31, #0b1111 #else lmw.bim $r6, [$r0], $r14, #0b0000 lmw.bim $r16, [$r0], $r19, #0b1111 #endif #if __NDS32_EXT_FPU_SP__ || __NDS32_EXT_FPU_DP__ /* Restore value of $fpcfg.freg (b[3:2]). */ lwi.bi $r2, [$r0], #4 /* Make sure $r0 is double-word-aligned. */ addi $r0, $r0, #7 bitci $r0, $r0, #7 /* Case switch according to $fpcfg.freg */ beqz $r2, .LCFG0_restore /* Branch if $fpcfg.freg = 0b00. */ xori $r15, $r2, #0b10 beqz $r15, .LCFG2_restore /* Branch $fpcfg.freg = 0b10. */ srli $r2, $r2, #0b01 beqz $r2, .LCFG1_restore /* Branch if $fpcfg.freg = 0b01. */ /* Fall-through if $fpcfg.freg = 0b11. */ .LCFG3_restore: fldi.bi $fd31, [$r0], #8 fldi.bi $fd29, [$r0], #8 fldi.bi $fd27, [$r0], #8 fldi.bi $fd25, [$r0], #8 fldi.bi $fd23, [$r0], #8 fldi.bi $fd21, [$r0], #8 fldi.bi $fd19, [$r0], #8 fldi.bi $fd17, [$r0], #8 .LCFG2_restore: fldi.bi $fd15, [$r0], #8 fldi.bi $fd13, [$r0], #8 fldi.bi $fd11, [$r0], #8 fldi.bi $fd9, [$r0], #8 .LCFG1_restore: fldi.bi $fd7, [$r0], #8 fldi.bi $fd5, [$r0], #8 .LCFG0_restore: fldi.bi $fd3, [$r0], #8 #endif /* Set val as return value. If the value val is 0, 1 will be returned instead. */ movi $r0, 1 cmovn $r0, $r1, $r1 /* r0=(r1!=0)? r1: r0 */ ret .size longjmp, .-longjmp picolibc-1.8.11/libc/machine/nds32/strcmp.S000066400000000000000000000066751513574234600203200ustar00rootroot00000000000000/* Copyright (c) 2013 Andes Technology Corporation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of the company may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Function: strcmp - compare two strings. Syntax: int strcmp(const char *s1, const char *s2); Description: This function compares the two strings s1 and s2. It returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2. Return value: strcmp returns an integer less than, equal to, or greater than zero if s1 (or the first n bytes thereof) is found, respectively, to be less than, to match, or be greater than s2. */ #include .text .align 2 .globl strcmp .type strcmp, @function strcmp: /* If s1 or s2 are unaligned, then compare bytes. */ or $r5, $r1, $r0 andi $r5, $r5, #3 bnez $r5, .Lbyte_mode /* If s1 and s2 are word-aligned, compare them a word at a time. */ lwi $r5, [$r0+(0)] lwi $r3, [$r1+(0)] bne $r5, $r3, .Lbyte_mode /* A difference was detected, so search bytewise. */ /* It's more efficient to set bit mask outside the word_mode loop. */ sethi $r4, hi20(0xFEFEFEFF) /* Set $r4 as -0x01010101. */ ori $r4, $r4, lo12(0xFEFEFEFF) sethi $r2, hi20(0x80808080) ori $r2, $r2, lo12(0x80808080) b .Ldetect_null .align 2 .Lword_mode: lmw.aim $r5, [$r0], $r5 lmw.aim $r3, [$r1], $r3 bne $r5, $r3, .Lbyte_mode .Ldetect_null: /* #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) DETECTNULL returns nonzero if (long)X contains a NULL byte. */ nor $r3, $r5, $r5 /* r3 = ~(X) */ add $r5, $r5, $r4 /* r2 = ((X) - 0x01010101) */ and $r5, $r5, $r3 /* r2 = ~(X) & ((X) - 0x01010101) */ and $r5, $r5, $r2 /* r2= r2 & 0x80808080 */ beqz $r5, .Lword_mode /* No NULL byte, compare next word. */ /* To get here, *a1 == *a2, thus if we find a null in *a1, then the strings must be equal, so return zero. */ movi $r0, #0 ret .Lbyte_mode: /* Byte-mode compare. */ lbi.bi $r5, [$r0], #1 lbi.bi $r3, [$r1], #1 bne $r5, $r3, 1f /* Mismatch, done. */ bnez $r5, .Lbyte_mode 1: sub $r0, $r5, $r3 ret .size strcmp, .-strcmp picolibc-1.8.11/libc/machine/nds32/strcpy.S000066400000000000000000000055061513574234600203240ustar00rootroot00000000000000/* Copyright (c) 2013 Andes Technology Corporation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of the company may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Function: strcpy - copy a string. Syntax: char *strcpy(char *dest, const char *src); Description: This function copies the string pointed to by src into the array point to by dest (include the teminating null character). Return value: strcpy returns the dest as given. */ #include .text .align 2 .globl strcpy .type strcpy, @function strcpy: move $r3, $r0 /* Keep r0 as reture value. */ /* If SRC or DEST is unaligned, then copy bytes. */ or $r2, $r1, $r0 andi $r2, $r2, #3 bnez $r2, .Lbyte_mode .Lword_mode: /* SRC and DEST are both "long int" aligned, try to do "long int" sized copies. */ /* #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) DETECTNULL returns nonzero if (long)X contains a NULL byte. */ lwi $r2, [$r1+(0)] /* r2 is X */ sethi $r4, hi20(0xFEFEFEFF) ori $r4, $r4, lo12(0xFEFEFEFF) add $r4, $r2, $r4 /* r4 = ((X) - 0x01010101) */ nor $r5, $r2, $r2 /* r5 = ~(X) */ and $r4, $r5, $r4 /* r4 = ~(X) & ((X) - 0x01010101) */ sethi $r5, hi20(0x80808080) ori $r5, $r5, lo12(0x80808080) and $r4, $r4, $r5 /* r4 = r4 & 0x80808080 */ bnez $r4, .Lbyte_mode /* Contains a NULL byte. */ swi.bi $r2, [$r3], #4 addi $r1, $r1, #4 b .Lword_mode .Lbyte_mode: lbi.bi $r4, [$r1], #1 /* r4 <- *src++ */ sbi.bi $r4, [$r3], #1 /* r4 -> *dest++ */ bnez $r4, .Lbyte_mode ret .size strcpy, .-strcpy picolibc-1.8.11/libc/machine/necv70/000077500000000000000000000000001513574234600170175ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/necv70/fastmath.S000066400000000000000000000066761513574234600207710ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .globl _fast_sin _fast_sin: fsin.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_sinf _fast_sinf: fsin.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_cos _fast_cos: fcos.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_cosf _fast_cosf: fcos.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_tan _fast_tan: ftan.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_tanf _fast_tanf: ftan.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_fabs _fast_fabs: fabs.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_fabsf _fast_fabsf: fabs.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_sqrt _fast_sqrt: fsqrt.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_sqrtf _fast_sqrtf: fsqrt.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_acos _fast_acos: facos.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_acosf _fast_acosf: facos.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_asin _fast_asin: fasin.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_asinf _fast_asinf: fasin.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_atan _fast_atan: fatan.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_atanf _fast_atanf: fatan.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_cosh _fast_cosh: fcosh.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_coshf _fast_coshf: fcosh.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_sinh _fast_sinh: fsin.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_sinhf _fast_sinhf: fsin.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_tanh _fast_tanh: ftanh.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_tanhf _fast_tanhf: ftanh.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_atanh _fast_atanh: fatanh.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_atanhf _fast_atanhf: fatanh.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_exp2 _fast_exp2: fexp2.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_exp2f _fast_exp2f: fexp2.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_exp10 _fast_exp10: fexp10.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_exp10f _fast_exp10f: fexp10.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_expe _fast_expe: fexpe.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_expef _fast_expef: fexpe.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_log2 _fast_log2: flog2.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_log2f _fast_log2f: flog2.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_log10 _fast_log10: flog10.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_log10f _fast_log10f: flog10.s [ap],[ap] mov.w [ap],r0 ret #0 .globl _fast_loge _fast_loge: floge.l [ap],[ap] mov.d [ap],r0 ret #0 .globl _fast_logef _fast_logef: floge.s [ap],[ap] mov.w [ap],r0 ret #0 picolibc-1.8.11/libc/machine/necv70/machine/000077500000000000000000000000001513574234600204235ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/necv70/machine/registers.h000066400000000000000000000021661513574234600226100ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ typedef struct { int fp_rounding : 2; /* fp rounding control */ int integer_rounding : 1; /* integer rounding */ int rfu : 1; /* reserved */ int fp_trap : 5; /* floating point trap bits */ int otm : 1; int rfu2 : 3; int att : 3; int rfu3 : 16; } v60_tkcw_type; picolibc-1.8.11/libc/machine/necv70/necv70.tex000066400000000000000000000074161513574234600206530ustar00rootroot00000000000000# #Copyright (c) 1990 The Regents of the University of California. #All rights reserved. # #Redistribution and use in source and binary forms are permitted #provided that the above copyright notice and this paragraph are #duplicated in all such forms and that any documentation, #and/or other materials related to such #distribution and use acknowledge that the software was developed #by the University of California, Berkeley. The name of the #University may not be used to endorse or promote products derived #from this software without specific prior written permission. #THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR #IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED #WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # @node machine,,syscalls,Top @chapter NEC V70 Specific Functions The NEC V70 has machine instructions for fast IEEE floating-point arithmetic, including operations normally provided by the library. When you use the @file{/usr/include/fastmath.h} header file, the names of several library math functions are redefined to call the @code{fastmath} routine (using the corresponding V70 machine instructions) whenever possible. For example, @example #include double sqsin(x) double x; @{ return sin(x*x); @} @end example expands into the code @example @dots{} double sqsin(x) double x; @{ return fast_sin(x*x); @} @end example The library has an entry @code{fast_sin} which uses the machine instruction @code{fsin.l} to perform the operation. Note that the built-in instructions cannot set @code{errno} in the same way that the C coded functions do. Refer to a V70 instruction manual to see how errors are generated and handled. Also, the library provides true @code{float} entry points. The @code{fast_sinf} entry point really performs a @code{fsin.s} operation. Because of this, the instructions are only useful when using code compiled with an ANSI C compiler. The prototypes and definitions for the floating-point versions of the math library routines are only defined if compiling a module with an ANSI C compiler. @page @section Entry points The functions provided by @file{fastmath.h} are @example double fast_sin(double); /* fsin.l */ double fast_cos(double); /* fcos.l */ double fast_tan(double); /* ftan.l */ double fast_asin(double); /* fasin.l */ double fast_acos(double); /* facos.l */ double fast_atan(double); /* fatan.l */ double fast_sinh(double); /* fsinh.l */ double fast_cosh(double); /* fcosh.l */ double fast_tanh(double); /* ftanh.l */ double fast_asinh(double); /* fasinh.l */ double fast_acosh(double); /* facosh.l */ double fast_atanh(double); /* fatanh.l */ double fast_fabs(double); /* fabs.l */ double fast_sqrt(double); /* fsqrt.l */ double fast_exp2(double); /* fexp2.l */ double fast_exp10(double); /* fexp10.l */ double fast_expe(double); /* fexpe.l */ double fast_log10(double); /* flog10.l */ double fast_log2(double); /* flog2.l */ double fast_loge(double); /* floge.l */ float fast_sinf(float); /* fsin.s */ float fast_cosf(float); /* fcos.s */ float fast_tanf(float); /* ftan.s */ float fast_asinf(float); /* fasin.s */ float fast_acosf(float); /* facos.s */ float fast_atanf(float); /* fatan.s */ float fast_sinhf(float); /* fsinh.s */ float fast_coshf(float); /* fcosh.s */ float fast_tanhf(float); /* ftanh.s */ float fast_asinhf(float); /* fasinh.s */ float fast_acoshf(float); /* facosh.s */ float fast_atanhf(float); /* fatanh.s */ float fast_fabsf(float); /* fabs.s */ float fast_sqrtf(float); /* fsqrt.s */ float fast_exp2f(float); /* fexp2.s */ float fast_exp10f(float); /* fexp10.s */ float fast_expef(float); /* fexpe.s */ float fast_log10f(float); /* flog10.s */ float fast_log2f(float); /* flog2.s */ float fast_logef(float); /* floge.s */ @end example picolibc-1.8.11/libc/machine/necv70/setjmp.S000066400000000000000000000024051513574234600204460ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .globl _setjmp _setjmp: mov.w [ap],r0 mov.d r15,[r0+] mov.d r17,[r0+] mov.d r19,[r0+] mov.d r21,[r0+] mov.d r23,[r0+] mov.w -0x4[ap],[r0+] mov.w fp,[r0+] mov.w ap,[r0+] mov.w -0x8[ap],[r0] xor.w r0,r0 ret #0x0 .globl _longjmp _longjmp: mov.w 0x4[ap],r0 mov.w [ap],r1 mov.d [r1+],r15 mov.d [r1+],r17 mov.d [r1+],r19 mov.d [r1+],r21 mov.d [r1+],r23 mov.d [r1+],ap mov.w [r1+],sp test.w r0 jne noz mov.w #0x1,r0 noz: jmp [0x0[r1]] picolibc-1.8.11/libc/machine/nios2/000077500000000000000000000000001513574234600167475ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/nios2/CMakeLists.txt000066400000000000000000000031151513574234600215070ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources( setjmp.s ) picolibc-1.8.11/libc/machine/nios2/meson.build000066400000000000000000000031611513574234600211120ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'setjmp.s', ] src_machine = files(srcs_machine) picolibc-1.8.11/libc/machine/nios2/setjmp.s000066400000000000000000000046671513574234600204520ustar00rootroot00000000000000;/* ; * C library -- _setjmp, _longjmp ; * ; * _longjmp(a,v) ; * will generate a "return(v?v:1)" from ; * the last call to ; * _setjmp(a) ; * by unwinding the call stack. ; * The previous signal state is NOT restored. ; * ; * ; * Copyright (c) 2003 Altera Corporation ; * All rights reserved. ; * ; * Redistribution and use in source and binary forms, with or without ; * modification, are permitted provided that the following conditions ; * are met: ; * ; * o Redistributions of source code must retain the above copyright ; * notice, this list of conditions and the following disclaimer. ; * o Redistributions in binary form must reproduce the above copyright ; * notice, this list of conditions and the following disclaimer in the ; * documentation and/or other materials provided with the distribution. ; * o Neither the name of Altera Corporation nor the names of its ; * contributors may be used to endorse or promote products derived from ; * this software without specific prior written permission. ; * ; * THIS SOFTWARE IS PROVIDED BY ALTERA CORPORATION, THE COPYRIGHT HOLDER, ; * AND ITS CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, ; * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY ; * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ; * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ; * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, ; * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS ; * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ; * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR ; * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE ; * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ; */ .section .text .align 3 .globl setjmp .type setjmp,@function .globl longjmp .type longjmp,@function setjmp: stw r16, 0(r4) stw r17, 4(r4) stw r18, 8(r4) stw r19, 12(r4) stw r20, 16(r4) stw r21, 20(r4) stw r22, 24(r4) stw r23, 28(r4) stw gp, 32(r4) stw sp, 36(r4) stw fp, 40(r4) stw ra, 44(r4) mov r2, zero ret longjmp: ldw r16, 0(r4) ldw r17, 4(r4) ldw r18, 8(r4) ldw r19, 12(r4) ldw r20, 16(r4) ldw r21, 20(r4) ldw r22, 24(r4) ldw r23, 28(r4) ldw gp, 32(r4) ldw sp, 36(r4) ldw fp, 40(r4) ldw ra, 44(r4) mov r2, r5 bne r2, zero, 1f movi r2, 1 1: ret picolibc-1.8.11/libc/machine/nvptx/000077500000000000000000000000001513574234600170745ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/nvptx/_exit.c000066400000000000000000000026451513574234600203570ustar00rootroot00000000000000/* * Support file for nvptx in newlib. * Copyright (c) 2014-2018 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include #include /* Sadly, PTX doesn't support weak declarations, only weak definitions. Weakly define it here in case we're not using crt0 (for instance in offloading). You probably shouldn't be calling 'exit' in an offloaded region anyway, but that'd be a runtime error, not a link error. */ int * __attribute((weak)) __exitval_ptr; void __noreturn _exit(int status) { if (__exitval_ptr) { *__exitval_ptr = status; for (;;) asm("exit;" ::: "memory"); } else /* offloading */ { /* Map to 'abort'; see '[nvptx] "exit" in offloaded region doesn't terminate process'. */ abort(); } } picolibc-1.8.11/libc/machine/nvptx/abort.c000066400000000000000000000014551513574234600203540ustar00rootroot00000000000000/* * Support file for nvptx in newlib. * Copyright (c) 2014-2018 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include void __noreturn abort(void) { for (;;) __builtin_trap(); } picolibc-1.8.11/libc/machine/nvptx/assert.c000066400000000000000000000022351513574234600205430ustar00rootroot00000000000000/* * Support file for nvptx in newlib. * Copyright (c) 2016-2018 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include #include #include #ifndef __HAVE_ASSERT_FUNC /* func can be NULL, in which case no function information is given. */ void __assert_func(const char *file, int line, const char *func, const char *failedexpr) { abort(); /* NOTREACHED */ } #endif /* __HAVE_ASSERT_FUNC */ void __assert(const char *file, int line, const char *failedexpr) { __assert_func(file, line, NULL, failedexpr); /* NOTREACHED */ } picolibc-1.8.11/libc/machine/nvptx/calloc.c000066400000000000000000000016121513574234600204750ustar00rootroot00000000000000/* * Support file for nvptx in newlib. * Copyright (c) 2014-2018 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include #include void * calloc(size_t size, size_t len) { void *p = malloc(size * len); if (!p) return p; return memset(p, 0, size * len); } picolibc-1.8.11/libc/machine/nvptx/callocr.c000066400000000000000000000015061513574234600206610ustar00rootroot00000000000000/* * Support file for nvptx in newlib. * Copyright (c) 2014-2018 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include void * _calloc_r(struct _reent *ptr, size_t size, size_t len) { return calloc(size, len); } picolibc-1.8.11/libc/machine/nvptx/clock.c000066400000000000000000000007041513574234600203340ustar00rootroot00000000000000/* clock.c * Support file for nvptx in newlib. */ #include #include clock_t clock() { unsigned long long now; #if __PTX_SM__ >= 310 asm volatile("mov.u64 %0, %%globaltimer;" : "=r"(now)); return now / ((1000000000ull) / CLOCKS_PER_SEC); #else asm volatile("mov.u64 %0, %%clock64;" : "=r"(now)); // Assume a GPU base clock frequency of 1250MHz. return now / ((1250000000ull) / CLOCKS_PER_SEC); #endif } picolibc-1.8.11/libc/machine/nvptx/free.c000066400000000000000000000016571513574234600201720ustar00rootroot00000000000000/* * Support file for nvptx in newlib. * Copyright (c) 2016-2018 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include /* The CUDA-provided free. */ void sys_free(void *) __asm__("free"); /* The user-visible free (renamed by compiler). */ void free(void *ptr) { if (ptr) sys_free((long long *)ptr - 1); } picolibc-1.8.11/libc/machine/nvptx/malloc.c000066400000000000000000000020031513574234600205020ustar00rootroot00000000000000/* * Support file for nvptx in newlib. * Copyright (c) 2016-2018 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include /* The CUDA-provided malloc. */ void *sys_malloc(size_t) __asm__("malloc"); /* The user-visible malloc (renamed by compiler). */ void * malloc(size_t size) { long long *ptr = sys_malloc(size + sizeof(long long)); if (ptr) *(size_t *)ptr++ = size; return ptr; } picolibc-1.8.11/libc/machine/nvptx/mallocr.c000066400000000000000000000015471513574234600207000ustar00rootroot00000000000000/* * Support file for nvptx in newlib. * Copyright (c) 2014-2018 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include void * _malloc_r(struct _reent *r, size_t n) { return malloc(n); } void _free_r(struct _reent *r, void *p) { free(p); } picolibc-1.8.11/libc/machine/nvptx/misc.c000066400000000000000000000027341513574234600202010ustar00rootroot00000000000000/* * Support file for nvptx in newlib. * Copyright (c) 2014-2018 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include #include #include #include #undef errno extern int errno; int close(int fd) { return -1; } int fstat(int fd, struct stat *buf) { return -1; } int gettimeofday(struct timeval *tv, void *tz) { return -1; } int getpid(void) { return 0; } int isatty(int fd) { return fd == 1; } int kill(int pid, int sig) { errno = ESRCH; return -1; } off_t lseek(int fd, off_t offset, int whence) { return 0; } int open(const char *pathname, int flags, ...) { return -1; } int read(int fd, void *buf, size_t count) { return 0; } int stat(const char *file, struct stat *pstat) { errno = EACCES; return -1; } void sync(void) { } int unlink(const char *pathname) { return -1; } picolibc-1.8.11/libc/machine/nvptx/printf.c000066400000000000000000000016641513574234600205510ustar00rootroot00000000000000/* * Support file for nvptx in newlib. * Copyright (c) 2015-2018 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include extern int vprintf(const char *, va_list); int printf(const char *fmt, ...) { va_list args; int res; va_start(args, fmt); res = vprintf(fmt, args); va_end(args); return res; } picolibc-1.8.11/libc/machine/nvptx/putchar.c000066400000000000000000000017031513574234600207070ustar00rootroot00000000000000/* * Support file for nvptx in newlib. * Copyright (c) 2015-2018 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include extern int vprintf(const char *, va_list); int putchar(int c) { unsigned valist[1]; c = (unsigned char)c; valist[0] = c; int ret = vprintf("%c", valist); if (ret < 0) c = -1; return c; } picolibc-1.8.11/libc/machine/nvptx/puts.c000066400000000000000000000015771513574234600202450ustar00rootroot00000000000000/* * Support file for nvptx in newlib. * Copyright (c) 2015-2018 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include extern int vprintf(const char *, va_list); int puts(const char *str) { void *valist[1]; valist[0] = str; return vprintf("%s\n", valist); } picolibc-1.8.11/libc/machine/nvptx/realloc.c000066400000000000000000000021161513574234600206610ustar00rootroot00000000000000/* * Support file for nvptx in newlib. * Copyright (c) 2016-2018 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include void * realloc(void *old_ptr, size_t new_size) { void *new_ptr = malloc(new_size); if (old_ptr && new_ptr) { size_t old_size = *(size_t *)((long long *)old_ptr - 1); size_t copy_size = old_size > new_size ? new_size : old_size; __builtin_memcpy(new_ptr, old_ptr, copy_size); free(old_ptr); } return new_ptr; } picolibc-1.8.11/libc/machine/nvptx/reallocr.c000066400000000000000000000015051513574234600210440ustar00rootroot00000000000000/* * Support file for nvptx in newlib. * Copyright (c) 2014-2018 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include void * _realloc_r(struct _reent *r, void *p, size_t n) __nothrow { return realloc(p, n); } picolibc-1.8.11/libc/machine/nvptx/write.c000066400000000000000000000020501513574234600203670ustar00rootroot00000000000000/* * Support file for nvptx in newlib. * Copyright (c) 2014-2018 Mentor Graphics. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ #include #include #include #include #include ssize_t write(int fd, const void *buf, size_t count) { size_t i; char *b = (char *)buf; if (fd != 1 && fd != 2) { errno = EBADF; return -1; } for (i = 0; i < count; i++) printf("%c", b[i]); return (ssize_t)count; } picolibc-1.8.11/libc/machine/or1k/000077500000000000000000000000001513574234600165715ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/or1k/CMakeLists.txt000066400000000000000000000032071513574234600213330ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2025 NVIDIA Corporation # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources_flags("-fno-builtin" setjmp.S tls.c ) picolibc-1.8.11/libc/machine/or1k/meson.build000066400000000000000000000032321513574234600207330ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2025 NVIDIA Corporation # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'setjmp.S', 'tls.c', ] src_machine = files(srcs_machine) picolibc-1.8.11/libc/machine/or1k/setjmp.S000066400000000000000000000056741513574234600202330ustar00rootroot00000000000000/* Copyright (c) 2014, Hesham ALMatary 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 COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include .align 4 .global setjmp .type setjmp,@function setjmp: l.sw 0(r3), r1 l.sw 4(r3), r2 /* Skip r3-r8 as they are not preserved across function calls */ l.sw 8(r3), r9 /* Skip r10 as it's preserved to be used by TLS */ /* Skip r11, setjmp always set it to 0 */ /* The following set if registers are preserved across function calls */ l.sw 12(r3), r14 l.sw 16(r3), r16 l.sw 20(r3), r18 l.sw 24(r3), r20 l.sw 28(r3), r22 l.sw 32(r3), r24 l.sw 36(r3), r26 l.sw 40(r3), r28 l.sw 44(r3), r30 /* Save Status Register */ l.mfspr r13, r0, 17 l.sw 48(r3), r13 /* Set result register to 0 and jump */ // Different cases for optional delay slot #if defined(__OR1K_NODELAY__) l.addi r11, r0, 0 l.jr r9 #elif defined(__OR1K_DELAY__) l.jr r9 l.addi r11, r0, 0 #else l.addi r11, r0, 0 l.jr r9 l.nop #endif .align 4 .global longjmp .type longjmp,@function longjmp: /* If the second argument to longjmp is zero, set return address to 1, otherwise set it to the value of the second argument */ l.addi r11, r0, 1 l.sfeq r4, r0 l.bf 1f l.nop l.addi r11, r4, 0 /* Load status register */ 1: l.lwz r15, 48(r3) l.mtspr r0, r15, 17 l.lwz r1, 0(r3) l.lwz r2, 4(r3) /* Skip r3-r8 as they are not preserved across function calls */ l.lwz r9, 8(r3) /* Skip r11 as it's always set by longjmp */ l.lwz r14, 12(r3) l.lwz r16, 16(r3) l.lwz r18, 20(r3) l.lwz r20, 24(r3) l.lwz r22, 28(r3) l.lwz r24, 32(r3) l.lwz r26, 36(r3) l.lwz r28, 40(r3) // Different cases for optional delay slot #if defined(__OR1K_NODELAY__) l.lwz r30, 44(r3) l.jr r9 #elif defined(__OR1K_DELAY__) l.jr r9 l.lwz r30, 44(r3) #else l.lwz r30, 44(r3) l.jr r9 l.nop #endif picolibc-1.8.11/libc/machine/or1k/tls.c000066400000000000000000000042431513574234600175420ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #ifdef __THREAD_LOCAL_STORAGE_API /* The size of the thread control block. * TLS relocations are generated relative to * a location this far *before* the first thread * variable (!) * NB: The actual size before tp also includes padding * to align up to the alignment of .tdata/.tbss. */ #define TCB_SIZE 16 extern char __or1k_tls_tcb_offset; #define TP_OFFSET ((size_t)&__or1k_tls_tcb_offset - TCB_SIZE) void _set_tls(void *tls) { tls = (uint8_t *)tls - TP_OFFSET; __asm__("l.or r10, %0, %0" : : "r"(tls)); } #endif picolibc-1.8.11/libc/machine/powerpc/000077500000000000000000000000001513574234600173745ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/powerpc/CMakeLists.txt000066400000000000000000000032171513574234600221370ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # add_subdirectory(machine) picolibc_sources_flags("-fno-builtin" hwcap.c setjmp.S tls.c ) picolibc-1.8.11/libc/machine/powerpc/hwcap.c000066400000000000000000000032701513574234600206440ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ void __parse_hwcap_and_convert_at_platform(void); void __parse_hwcap_and_convert_at_platform(void) { } picolibc-1.8.11/libc/machine/powerpc/machine/000077500000000000000000000000001513574234600210005ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/powerpc/machine/CMakeLists.txt000066400000000000000000000031361513574234600235430ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_headers(machine fenv.h fenv-fp.h ) picolibc-1.8.11/libc/machine/powerpc/machine/_ssp_tls.h000066400000000000000000000051451513574234600230040ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MACHINE__SSP_TLS_H_ #define _MACHINE__SSP_TLS_H_ #include #if !defined(__PPC__) || !defined(__THREAD_LOCAL_STORAGE_STACK_GUARD) #error #endif /* * PowerPC uses a thread-local variable, but located *below* the * regular TLS block. There are two register-sized values. This will * end up allocated in the .data segment to make sure there is space * for it, then we do some pointer arithmetic using a TLS symbol * created by the linker that points at the start of the .tdata * segment. */ struct __stack_chk_guard { uintptr_t v[2]; } __stack_chk_guard __section(".stack_chk"); #ifdef __GNUCLIKE_PRAGMA_DIAGNOSTIC #pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wunknown-warning-option" #pragma GCC diagnostic ignored "-Wanalyzer-out-of-bounds" #pragma GCC diagnostic ignored "-Warray-bounds" #pragma GCC diagnostic ignored "-Wstringop-overflow" #endif extern _Thread_local char __tls_first[]; #define __stack_chk_guard (((struct __stack_chk_guard *)__tls_first)[-1].v[0]) #endif picolibc-1.8.11/libc/machine/powerpc/machine/fenv-fp.h000066400000000000000000000107331513574234600225160ustar00rootroot00000000000000/*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2004-2005 David Schultz * 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$ */ __declare_fenv_inline(int) feclearexcept(int excepts) { union __fpscr __r; if (excepts & FE_INVALID) excepts |= FE_ALL_INVALID; __mffs(&__r); __r.__bits.__reg &= ~excepts; __mtfsf(__r); return (0); } __declare_fenv_inline(int) fegetexceptflag(fexcept_t *flagp, int excepts) { union __fpscr __r; __mffs(&__r); *flagp = __r.__bits.__reg & excepts; return (0); } __declare_fenv_inline(int) fesetexceptflag(const fexcept_t *flagp, int excepts) { union __fpscr __r; if (excepts & FE_INVALID) excepts |= FE_ALL_EXCEPT; __mffs(&__r); __r.__bits.__reg &= ~excepts; __r.__bits.__reg |= *flagp & excepts; __mtfsf(__r); return (0); } __declare_fenv_inline(int) feraiseexcept(int excepts) { union __fpscr __r; if (excepts & FE_INVALID) excepts |= FE_VXSOFT; __mffs(&__r); __r.__bits.__reg |= excepts; __mtfsf(__r); return (0); } __declare_fenv_inline(int) fesetexcept(int excepts) { return feraiseexcept(excepts); } __declare_fenv_inline(int) fetestexcept(int excepts) { union __fpscr __r; __mffs(&__r); return (__r.__bits.__reg & excepts); } __declare_fenv_inline(int) fegetround(void) { union __fpscr __r; __mffs(&__r); return (__r.__bits.__reg & _ROUND_MASK); } __declare_fenv_inline(int) fesetround(int rounding_mode) { union __fpscr __r; if (rounding_mode & ~_ROUND_MASK) return (-1); __mffs(&__r); __r.__bits.__reg &= ~_ROUND_MASK; __r.__bits.__reg |= rounding_mode; __mtfsf(__r); return (0); } __declare_fenv_inline(int) fegetenv(fenv_t *envp) { union __fpscr __r; __mffs(&__r); *envp = __r.__bits.__reg; return (0); } __declare_fenv_inline(int) feholdexcept(fenv_t *envp) { union __fpscr __r; __mffs(&__r); *envp = __r.__bits.__reg; __r.__bits.__reg &= ~(FE_ALL_EXCEPT | _ENABLE_MASK); __mtfsf(__r); return (0); } __declare_fenv_inline(int) fesetenv(const fenv_t *envp) { union __fpscr __r; __r.__bits.__reg = *envp; __mtfsf(__r); return (0); } __declare_fenv_inline(int) feupdateenv(const fenv_t *envp) { union __fpscr __r; __mffs(&__r); __r.__bits.__reg &= FE_ALL_EXCEPT; __r.__bits.__reg |= *envp; __mtfsf(__r); return (0); } #if __BSD_VISIBLE __declare_fenv_inline(int) feenableexcept(int __mask) { union __fpscr __r; fenv_t __oldmask; __mffs(&__r); __oldmask = __r.__bits.__reg; __r.__bits.__reg |= (__mask & FE_ALL_EXCEPT) >> _FPUSW_SHIFT; __mtfsf(__r); return ((__oldmask & _ENABLE_MASK) << _FPUSW_SHIFT); } __declare_fenv_inline(int) fedisableexcept(int __mask) { union __fpscr __r; fenv_t __oldmask; __mffs(&__r); __oldmask = __r.__bits.__reg; __r.__bits.__reg &= ~((__mask & FE_ALL_EXCEPT) >> _FPUSW_SHIFT); __mtfsf(__r); return ((__oldmask & _ENABLE_MASK) << _FPUSW_SHIFT); } __declare_fenv_inline(int) fegetexcept(void) { union __fpscr __r; __mffs(&__r); return ((__r.__bits.__reg & _ENABLE_MASK) << _FPUSW_SHIFT); } #endif /* __BSD_VISIBLE */ picolibc-1.8.11/libc/machine/powerpc/machine/fenv.h000066400000000000000000000104351513574234600221120ustar00rootroot00000000000000/*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2004-2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _MACHINE_FENV_H_ #define _MACHINE_FENV_H_ #include _BEGIN_STD_C typedef int fenv_t; typedef int fexcept_t; /* Exception flags */ #define FE_INEXACT 0x02000000 #define FE_DIVBYZERO 0x04000000 #define FE_UNDERFLOW 0x08000000 #define FE_OVERFLOW 0x10000000 #define FE_INVALID 0x20000000 /* all types of invalid FP ops */ /* * The PowerPC architecture has extra invalid flags that indicate the * specific type of invalid operation occurred. These flags may be * tested, set, and cleared---but not masked---separately. All of * these bits are cleared when FE_INVALID is cleared, but only * FE_VXSOFT is set when FE_INVALID is explicitly set in software. */ #define FE_VXCVI 0x00000100 /* invalid integer convert */ #define FE_VXSQRT 0x00000200 /* square root of a negative */ #define FE_VXSOFT 0x00000400 /* software-requested exception */ #define FE_VXVC 0x00080000 /* ordered comparison involving NaN */ #define FE_VXIMZ 0x00100000 /* inf * 0 */ #define FE_VXZDZ 0x00200000 /* 0 / 0 */ #define FE_VXIDI 0x00400000 /* inf / inf */ #define FE_VXISI 0x00800000 /* inf - inf */ #define FE_VXSNAN 0x01000000 /* operation on a signalling NaN */ #define FE_ALL_INVALID \ (FE_VXCVI | FE_VXSQRT | FE_VXSOFT | FE_VXVC | FE_VXIMZ | FE_VXZDZ | FE_VXIDI | FE_VXISI \ | FE_VXSNAN | FE_INVALID) #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_ALL_INVALID | FE_OVERFLOW | FE_UNDERFLOW) /* Rounding modes */ #define FE_TONEAREST 0x0000 #define FE_TOWARDZERO 0x0001 #define FE_UPWARD 0x0002 #define FE_DOWNWARD 0x0003 #define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO) /* We need to be able to map status flag positions to mask flag positions */ #define _FPUSW_SHIFT 22 #define _ENABLE_MASK \ ((FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) >> _FPUSW_SHIFT) #ifndef _SOFT_FLOAT #ifdef __SPE__ #define __mffs(__env) __asm__ __volatile__("mfspr %0, 512" : "=r"((__env)->__bits.__reg)) #define __mtfsf(__env) __asm__ __volatile__("mtspr 512,%0;isync" ::"r"((__env).__bits.__reg)) #else #define __mffs(__env) __asm__ __volatile__("mffs %0" : "=f"((__env)->__d)) #define __mtfsf(__env) __asm__ __volatile__("mtfsf 255,%0" ::"f"((__env).__d)) #endif #else #define __mffs(__env) #define __mtfsf(__env) #endif union __fpscr { double __d; struct { #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ fenv_t __reg; __uint32_t __junk; #else __uint32_t __junk; fenv_t __reg; #endif } __bits; }; #if !defined(__declare_fenv_inline) && defined(__declare_extern_inline) #define __declare_fenv_inline(type) __declare_extern_inline(type) #endif #ifdef __declare_fenv_inline #include #endif _END_STD_C #endif /* !_MACHINE_FENV_H_ */ picolibc-1.8.11/libc/machine/powerpc/machine/meson.build000066400000000000000000000033511513574234600231440ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_machine_headers_machine = [ 'fenv.h', 'fenv-fp.h', ] if really_install install_headers(inc_machine_headers_machine, install_dir: include_dir / 'machine') endif picolibc-1.8.11/libc/machine/powerpc/meson.build000066400000000000000000000041251513574234600215400ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Ash Logan, Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ # 'atosfix16.c', # 'atosfix32.c', # 'atosfix64.c', # 'atoufix16.c', # 'atoufix32.c', # 'atoufix64.c', 'hwcap.c', 'setjmp.S', 'tls.c', # 'strtosfix16.c', # 'strtosfix32.c', # 'strtosfix64.c', # 'strtoufix16.c', # 'strtoufix32.c', # 'strtoufix64.c', # 'ufix64toa.c', # These don't work with picolibc's stdio/malloc/locking # 'vec_calloc.c', # 'vec_free.c', # 'vec_malloc.c', # 'vec_mallocr.c', # 'vec_realloc.c', # 'vfprintf.c', # 'vfscanf.c', ] subdir('machine') src_machine = files(srcs_machine) picolibc-1.8.11/libc/machine/powerpc/setjmp.S000066400000000000000000000257641513574234600210400ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* This is a simple version of setjmp and longjmp for the PowerPC. Ian Lance Taylor, Cygnus Support, 9 Feb 1994. Modified by Jeff Johnston, Red Hat Inc. 2 Oct 2001. Modified by Sebastian Huber, embedded brains GmbH. 22 Sep 2022. */ #include #include "ppc-asm.h" FUNC_START(setjmp) #ifdef __ALTIVEC__ addi 3,3,15 # align Altivec to 16 byte boundary #if __powerpc64__ clrrdi 3,3,4 #else rlwinm 3,3,0,0,27 #endif #else addi 3,3,7 # align to 8 byte boundary #if __powerpc64__ clrrdi 3,3,3 #else rlwinm 3,3,0,0,28 #endif #endif #if __SPE__ /* If we are E500, then save 64-bit registers. */ evstdd 1,0(3) # offset 0 evstdd 2,8(3) # offset 8 evstdd 13,16(3) # offset 16 evstdd 14,24(3) # offset 24 evstdd 15,32(3) # offset 32 evstdd 16,40(3) # offset 40 evstdd 17,48(3) # offset 48 evstdd 18,56(3) # offset 56 evstdd 19,64(3) # offset 64 evstdd 20,72(3) # offset 72 evstdd 21,80(3) # offset 80 evstdd 22,88(3) # offset 88 evstdd 23,96(3) # offset 96 evstdd 24,104(3) # offset 104 evstdd 25,112(3) # offset 112 evstdd 26,120(3) # offset 120 evstdd 27,128(3) # offset 128 evstdd 28,136(3) # offset 136 evstdd 29,144(3) # offset 144 evstdd 30,152(3) # offset 152 evstdd 31,160(3) # offset 160 /* Add 164 to r3 to account for the amount of data we just stored. Note that we are not adding 168 because the next store instruction uses an offset of 4. */ addi 3,3,164 #elif __powerpc64__ /* In the first store, add 8 to r3 so that the subsequent floating point stores are aligned on an 8 byte boundary and the Altivec stores are aligned on a 16 byte boundary. */ stdu 1,8(3) # offset 8 stdu 2,8(3) # offset 16 stdu 13,8(3) # offset 24 stdu 14,8(3) # offset 32 stdu 15,8(3) # offset 40 stdu 16,8(3) # offset 48 stdu 17,8(3) # offset 56 stdu 18,8(3) # offset 64 stdu 19,8(3) # offset 72 stdu 20,8(3) # offset 80 stdu 21,8(3) # offset 88 stdu 22,8(3) # offset 96 stdu 23,8(3) # offset 104 stdu 24,8(3) # offset 112 stdu 25,8(3) # offset 120 stdu 26,8(3) # offset 128 stdu 27,8(3) # offset 136 stdu 28,8(3) # offset 144 stdu 29,8(3) # offset 152 stdu 30,8(3) # offset 160 stdu 31,8(3) # offset 168 mflr 4 stdu 4,8(3) # offset 176 mfcr 4 stwu 4,8(3) # offset 184 #else stw 1,0(3) # offset 0 stwu 2,4(3) # offset 4 stwu 13,4(3) # offset 8 stwu 14,4(3) # offset 12 stwu 15,4(3) # offset 16 stwu 16,4(3) # offset 20 stwu 17,4(3) # offset 24 stwu 18,4(3) # offset 28 stwu 19,4(3) # offset 32 stwu 20,4(3) # offset 36 stwu 21,4(3) # offset 40 stwu 22,4(3) # offset 44 stwu 23,4(3) # offset 48 stwu 24,4(3) # offset 52 stwu 25,4(3) # offset 56 stwu 26,4(3) # offset 60 stwu 27,4(3) # offset 64 stwu 28,4(3) # offset 68 stwu 29,4(3) # offset 72 stwu 30,4(3) # offset 76 stwu 31,4(3) # offset 80 #endif #if !__powerpc64__ /* If __SPE__, then add 84 to the offset shown from this point on until the end of this function. This difference comes from the fact that we save 21 64-bit registers instead of 21 32-bit registers above. */ mflr 4 stwu 4,4(3) # offset 84 mfcr 4 stwu 4,4(3) # offset 88 # one word pad to get floating point aligned on 8 byte boundary #endif /* Check whether we need to save FPRs. Checking __NO_FPRS__ on its own would be enough for GCC 4.1 and above, but older compilers only define _SOFT_FLOAT, so check both. */ #if !defined (__NO_FPRS__) && !defined (_SOFT_FLOAT) #if defined (__rtems__) && !defined (__PPC_CPU_E6500__) /* For some RTEMS multilibs, the FPU and Altivec units are disabled during interrupt handling. Do not save and restore the corresponding registers in this case. */ mfmsr 5 andi. 5,5,0x2000 beq 1f #endif /* If __powerpc64__, then add 96 to the offset shown from this point on until the end of this function. This difference comes from the fact that we save 23 64-bit registers instead of 23 32-bit registers above and we take alignement requirements of floating point and Altivec stores into account. */ stfdu 14,8(3) # offset 96 stfdu 15,8(3) # offset 104 stfdu 16,8(3) # offset 112 stfdu 17,8(3) # offset 120 stfdu 18,8(3) # offset 128 stfdu 19,8(3) # offset 136 stfdu 20,8(3) # offset 144 stfdu 21,8(3) # offset 152 stfdu 22,8(3) # offset 160 stfdu 23,8(3) # offset 168 stfdu 24,8(3) # offset 176 stfdu 25,8(3) # offset 184 stfdu 26,8(3) # offset 192 stfdu 27,8(3) # offset 200 stfdu 28,8(3) # offset 208 stfdu 29,8(3) # offset 216 stfdu 30,8(3) # offset 224 stfdu 31,8(3) # offset 232 1: #endif /* This requires a total of 21 * 4 + 18 * 8 + 4 + 4 + 4 bytes == 60 * 4 bytes == 240 bytes. */ #ifdef __ALTIVEC__ #if defined (__rtems__) && !defined (__PPC_CPU_E6500__) mfmsr 5 andis. 5,5,0x200 beq 1f #endif /* save Altivec vrsave and vr20-vr31 registers */ mfspr 4,256 # vrsave register stwu 4,16(3) # offset 248 addi 3,3,8 stvx 20,0,3 # offset 256 addi 3,3,16 stvx 21,0,3 # offset 272 addi 3,3,16 stvx 22,0,3 # offset 288 addi 3,3,16 stvx 23,0,3 # offset 304 addi 3,3,16 stvx 24,0,3 # offset 320 addi 3,3,16 stvx 25,0,3 # offset 336 addi 3,3,16 stvx 26,0,3 # offset 352 addi 3,3,16 stvx 27,0,3 # offset 368 addi 3,3,16 stvx 28,0,3 # offset 384 addi 3,3,16 stvx 29,0,3 # offset 400 addi 3,3,16 stvx 30,0,3 # offset 416 addi 3,3,16 stvx 31,0,3 # offset 432 1: /* This requires a total of 240 + 8 + 8 + 12 * 16 == 448 bytes. */ #endif li 3,0 blr FUNC_END(setjmp) FUNC_START(longjmp) #ifdef __ALTIVEC__ addi 3,3,15 # align Altivec to 16 byte boundary #if __powerpc64__ clrrdi 3,3,4 #else rlwinm 3,3,0,0,27 #endif #else addi 3,3,7 # align to 8 byte boundary #if __powerpc64__ clrrdi 3,3,3 #else rlwinm 3,3,0,0,28 #endif #endif #if __SPE__ /* If we are E500, then restore 64-bit registers. */ evldd 1,0(3) # offset 0 evldd 2,8(3) # offset 8 evldd 13,16(3) # offset 16 evldd 14,24(3) # offset 24 evldd 15,32(3) # offset 32 evldd 16,40(3) # offset 40 evldd 17,48(3) # offset 48 evldd 18,56(3) # offset 56 evldd 19,64(3) # offset 64 evldd 20,72(3) # offset 72 evldd 21,80(3) # offset 80 evldd 22,88(3) # offset 88 evldd 23,96(3) # offset 96 evldd 24,104(3) # offset 104 evldd 25,112(3) # offset 112 evldd 26,120(3) # offset 120 evldd 27,128(3) # offset 128 evldd 28,136(3) # offset 136 evldd 29,144(3) # offset 144 evldd 30,152(3) # offset 152 evldd 31,160(3) # offset 160 /* Add 164 to r3 to account for the amount of data we just loaded. Note that we are not adding 168 because the next load instruction uses an offset of 4. */ addi 3,3,164 #elif __powerpc64__ /* In the first load, add 8 to r3 so that the subsequent floating point loades are aligned on an 8 byte boundary and the Altivec loads are aligned on a 16 byte boundary. */ ldu 1,8(3) # offset 8 ldu 2,8(3) # offset 16 ldu 13,8(3) # offset 24 ldu 14,8(3) # offset 32 ldu 15,8(3) # offset 40 ldu 16,8(3) # offset 48 ldu 17,8(3) # offset 56 ldu 18,8(3) # offset 64 ldu 19,8(3) # offset 72 ldu 20,8(3) # offset 80 ldu 21,8(3) # offset 88 ldu 22,8(3) # offset 96 ldu 23,8(3) # offset 104 ldu 24,8(3) # offset 112 ldu 25,8(3) # offset 120 ldu 26,8(3) # offset 128 ldu 27,8(3) # offset 136 ldu 28,8(3) # offset 144 ldu 29,8(3) # offset 152 ldu 30,8(3) # offset 160 ldu 31,8(3) # offset 168 ldu 5,8(3) # offset 176 mtlr 5 lwzu 5,8(3) # offset 184 mtcrf 255,5 #else lwz 1,0(3) # offset 0 lwzu 2,4(3) # offset 4 lwzu 13,4(3) # offset 8 lwzu 14,4(3) # offset 12 lwzu 15,4(3) # offset 16 lwzu 16,4(3) # offset 20 lwzu 17,4(3) # offset 24 lwzu 18,4(3) # offset 28 lwzu 19,4(3) # offset 32 lwzu 20,4(3) # offset 36 lwzu 21,4(3) # offset 40 lwzu 22,4(3) # offset 44 lwzu 23,4(3) # offset 48 lwzu 24,4(3) # offset 52 lwzu 25,4(3) # offset 56 lwzu 26,4(3) # offset 60 lwzu 27,4(3) # offset 64 lwzu 28,4(3) # offset 68 lwzu 29,4(3) # offset 72 lwzu 30,4(3) # offset 76 lwzu 31,4(3) # offset 80 #endif /* If __SPE__, then add 84 to the offset shown from this point on until the end of this function. This difference comes from the fact that we restore 22 64-bit registers instead of 22 32-bit registers above. */ #if !__powerpc64__ lwzu 5,4(3) # offset 84 mtlr 5 lwzu 5,4(3) # offset 88 mtcrf 255,5 # one word pad to get floating point aligned on 8 byte boundary #endif /* Check whether we need to restore FPRs. Checking __NO_FPRS__ on its own would be enough for GCC 4.1 and above, but older compilers only define _SOFT_FLOAT, so check both. */ #if !defined (__NO_FPRS__) && !defined (_SOFT_FLOAT) #if defined (__rtems__) && !defined (__PPC_CPU_E6500__) mfmsr 5 andi. 5,5,0x2000 beq 1f #endif /* If __powerpc64__, then add 96 to the offset shown from this point on until the end of this function. This difference comes from the fact that we restore 23 64-bit registers instead of 23 32-bit registers above and we take alignement requirements of floating point and Altivec loads into account. */ lfdu 14,8(3) # offset 96 lfdu 15,8(3) # offset 104 lfdu 16,8(3) # offset 112 lfdu 17,8(3) # offset 120 lfdu 18,8(3) # offset 128 lfdu 19,8(3) # offset 136 lfdu 20,8(3) # offset 144 lfdu 21,8(3) # offset 152 lfdu 22,8(3) # offset 160 lfdu 23,8(3) # offset 168 lfdu 24,8(3) # offset 176 lfdu 25,8(3) # offset 184 lfdu 26,8(3) # offset 192 lfdu 27,8(3) # offset 200 lfdu 28,8(3) # offset 208 lfdu 29,8(3) # offset 216 lfdu 30,8(3) # offset 224 lfdu 31,8(3) # offset 232 1: #endif #ifdef __ALTIVEC__ #if defined (__rtems__) && !defined (__PPC_CPU_E6500__) mfmsr 5 andis. 5,5,0x200 beq 1f #endif /* restore Altivec vrsave and v20-v31 registers */ lwzu 5,16(3) # offset 248 mtspr 256,5 # vrsave addi 3,3,8 lvx 20,0,3 # offset 256 addi 3,3,16 lvx 21,0,3 # offset 272 addi 3,3,16 lvx 22,0,3 # offset 288 addi 3,3,16 lvx 23,0,3 # offset 304 addi 3,3,16 lvx 24,0,3 # offset 320 addi 3,3,16 lvx 25,0,3 # offset 336 addi 3,3,16 lvx 26,0,3 # offset 352 addi 3,3,16 lvx 27,0,3 # offset 368 addi 3,3,16 lvx 28,0,3 # offset 384 addi 3,3,16 lvx 29,0,3 # offset 400 addi 3,3,16 lvx 30,0,3 # offset 416 addi 3,3,16 lvx 31,0,3 # offset 432 1: #endif mr. 3,4 bclr+ 4,2 li 3,1 blr FUNC_END(longjmp) picolibc-1.8.11/libc/machine/powerpc/tls.c000066400000000000000000000040661513574234600203500ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #ifdef __THREAD_LOCAL_STORAGE_API /* * This will be the size of __stack_chk_guard if in use. If not * present, then we'll assume stack checking is disabled, and the * missing symbol value, 0, will work fine. */ extern char __tls_head_size[] __weak; #define TP_OFFSET 0x7000 void _set_tls(void *tls) { tls = (uint8_t *)tls + TP_OFFSET + (uintptr_t)__tls_head_size; __asm__("mr 13, %0" : : "r"(tls)); } #endif picolibc-1.8.11/libc/machine/pru/000077500000000000000000000000001513574234600165235ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/pru/setjmp.s000066400000000000000000000033411513574234600202120ustar00rootroot00000000000000/* SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2018-2019 Dimitar Dimitrov * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ .section .text .align 3 .globl setjmp .type setjmp,@function .globl longjmp .type longjmp,@function setjmp: sbbo r2, r14, 0, 4*12 /* SP, RA, FP, r5-r13 */ ldi r14, 0 ret longjmp: lbbo r2, r14, 0, 4*12 /* SP, RA, FP, r5-r13 */ mov r14, r15 /* copy second arg to return location */ qbne 1f, r14, 0 /* per stdC, we cannot return 0 */ ldi r14, 1 1: ret picolibc-1.8.11/libc/machine/riscv/000077500000000000000000000000001513574234600170435ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/riscv/CMakeLists.txt000066400000000000000000000033711513574234600216070ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # add_subdirectory(machine) picolibc_sources_flags("-fno-builtin" ieeefp.c memcpy-asm.S memcpy.c memmove.S memmove.c memset.S setjmp.S stpcpy.c strcmp.S strcpy.c strlen.c tls.c ) picolibc-1.8.11/libc/machine/riscv/asm.h000066400000000000000000000025361513574234600200020ustar00rootroot00000000000000/* Copyright (c) 2017 SiFive Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #ifndef _SYS_ASM_H #define _SYS_ASM_H /* * Macros to handle different pointer/register sizes for 32/64-bit code */ #if __riscv_xlen == 64 # define PTRLOG 3 # define SZREG 8 # define REG_S sd # define REG_L ld #elif __riscv_xlen == 32 # define PTRLOG 2 # define SZREG 4 # define REG_S sw # define REG_L lw #else # error __riscv_xlen must equal 32 or 64 #endif #ifndef __riscv_float_abi_soft /* For ABI uniformity, reserve 8 bytes for floats, even if double-precision floating-point is not supported in hardware. */ # define SZFREG 8 # ifdef __riscv_float_abi_single # define FREG_L flw # define FREG_S fsw # elif defined(__riscv_float_abi_double) # define FREG_L fld # define FREG_S fsd # elif defined(__riscv_float_abi_quad) # define FREG_L flq # define FREG_S fsq # else # error unsupported FLEN # endif #endif #endif /* sys/asm.h */ picolibc-1.8.11/libc/machine/riscv/ieeefp.c000066400000000000000000000063211513574234600204460ustar00rootroot00000000000000/* Copyright (c) 2017 SiFive Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #define _BSD_SOURCE #include #include #if defined(__riscv_flen) || defined(__riscv_zfinx) static void fssr(unsigned value) { __asm__ volatile("fscsr %0" ::"r"(value)); } static unsigned frsr(void) { unsigned value; __asm__ volatile("frcsr %0" : "=r"(value)); return value; } static fp_rnd frm_fp_rnd(unsigned frm) { switch (frm) { case 0: return FP_RN; case 1: return FP_RZ; case 2: return FP_RM; case 3: return FP_RP; /* 4 ~ 7 is invalid value, so just retun FP_RP. */ default: return FP_RP; } } static fp_except frm_fp_except(unsigned except) { fp_except fp = 0; if (except & (1 << 0)) fp |= FP_X_IMP; if (except & (1 << 1)) fp |= FP_X_UFL; if (except & (1 << 2)) fp |= FP_X_OFL; if (except & (1 << 3)) fp |= FP_X_DX; if (except & (1 << 4)) fp |= FP_X_INV; return fp; } static unsigned frm_except(fp_except fp) { unsigned except = 0; if (fp & FP_X_IMP) except |= (1 << 0); if (fp & FP_X_UFL) except |= (1 << 1); if (fp & FP_X_OFL) except |= (1 << 2); if (fp & FP_X_DX) except |= (1 << 3); if (fp & FP_X_INV) except |= (1 << 4); return except; } #endif /* __riscv_flen */ fp_except fpgetmask(void) { return 0; } fp_rnd fpgetround(void) { #if defined(__riscv_flen) || defined(__riscv_zfinx) unsigned rm = (frsr() >> 5) & 0x7; return frm_fp_rnd(rm); #else return FP_RZ; #endif /* __riscv_flen */ } fp_except fpgetsticky(void) { #if defined(__riscv_flen) || defined(__riscv_zfinx) return frm_fp_except(frsr()); #else return 0; #endif /* __riscv_flen */ } fp_except fpsetmask(fp_except mask) { (void)mask; return -1; } fp_rnd fpsetround(fp_rnd rnd_dir) { #if defined(__riscv_flen) || defined(__riscv_zfinx) unsigned fsr = frsr(); unsigned rm = (fsr >> 5) & 0x7; unsigned new_rm; switch (rnd_dir) { case FP_RN: new_rm = 0; break; case FP_RZ: new_rm = 1; break; case FP_RM: new_rm = 2; break; case FP_RP: new_rm = 3; break; default: return -1; } fssr(new_rm << 5 | (fsr & 0x1f)); return frm_fp_rnd(rm); #else (void)rnd_dir; return -1; #endif /* __riscv_flen */ } fp_except fpsetsticky(fp_except sticky) { #if defined(__riscv_flen) || defined(__riscv_zfinx) unsigned fsr = frsr(); fssr(frm_except(sticky) | (fsr & ~0x1f)); return frm_fp_except(fsr); #else (void)sticky; return -1; #endif /* __riscv_flen */ } fp_rdi fpgetroundtoi(void) { return 0; } fp_rdi fpsetroundtoi(fp_rdi rdi) { (void)rdi; return -1; } picolibc-1.8.11/libc/machine/riscv/machine/000077500000000000000000000000001513574234600204475ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/riscv/machine/CMakeLists.txt000066400000000000000000000031471513574234600232140ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_headers(machine fenv.h fenv-fp.h math.h ) picolibc-1.8.11/libc/machine/riscv/machine/_fpmath.h000066400000000000000000000045611513574234600222440ustar00rootroot00000000000000/*- * Copyright (c) 2002, 2003 David Schultz * Copyright (c) 2014 The FreeBSD Foundation * 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$ */ /* * Change unsigned int/long used by FreeBSD to fixed width types because * ilp32 has a different size for unsigned long. --joel (20 Aug 2022) */ #include union IEEEl2bits { long double e; struct { uint64_t manl : 64; uint64_t manh : 48; uint32_t exp : 15; uint32_t sign : 1; } bits; /* TODO andrew: Check the packing here */ struct { uint64_t manl : 64; uint64_t manh : 48; uint32_t expsign : 16; } xbits; }; #define LDBL_NBIT 0 #define LDBL_IMPLICIT_NBIT #define mask_nbit_l(u) ((void)0) #define LDBL_MANH_SIZE 48 #define LDBL_MANL_SIZE 64 #define LDBL_TO_ARRAY32(u, a) \ do { \ (a)[0] = (uint32_t)(u).bits.manl; \ (a)[1] = (uint32_t)((u).bits.manl >> 32); \ (a)[2] = (uint32_t)(u).bits.manh; \ (a)[3] = (uint32_t)((u).bits.manh >> 32); \ } while (0) picolibc-1.8.11/libc/machine/riscv/machine/fenv-fp.h000066400000000000000000000345441513574234600221730ustar00rootroot00000000000000/* (c) Copyright 2017 Michael R. Neilly All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/feclearexcept.html * Referred to as 'feclearexcept.html below. * * "The feclearexcept() function shall attempt to clear the supported * floating-point exceptions represented by excepts." */ __declare_fenv_inline(int) feclearexcept(int excepts) { /* Mask excepts to be sure only supported flag bits are set */ excepts &= FE_ALL_EXCEPT; /* Per "The RISC-V Instruction Set Manual: Volume I: User-Level ISA: * Version 2.1": * * "The CSRRC (Atomic Read and Clear Bits in CSR) instruction reads * the value of the CSR, zeroextends the value to XLEN bits, and * writes it to integer register rd. The initial value in integer * register rs1 is treated as a bit mask that specifies bit * positions to be cleared in the CSR. Any bit that is high in rs1 * will cause the corresponding bit to be cleared in the CSR, if * that CSR bit is writable. Other bits in the CSR are unaffected." */ /* Clear the requested flags */ __asm__ volatile("csrrc zero, fflags, %0" : : "r"(excepts)); /* Per 'feclearexcept.html * "If the argument is zero or if all the specified exceptions were * successfully cleared, feclearexcept() shall return zero. Otherwise, * it shall return a non-zero value." */ return 0; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/fegetenv.html * Referred to as 'fegetenv.html below. * * "The fegetenv() function shall attempt to store the current * floating-point environment in the object pointed to by envp." * */ __declare_fenv_inline(int) fegetenv(fenv_t *envp) { /* Get the current environment (FCSR) */ fenv_t fcsr; __asm__ volatile("frcsr %0" : "=r"(fcsr)); /* Store FCSR in envp */ *envp = fcsr; /* Per 'fegetenv.html: * * "If the representation was successfully stored, fegetenv() shall * return zero. Otherwise, it shall return a non-zero value. */ return 0; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/fegetexceptflag.html * Referred to as 'fegetexceptflag.html below. * * "The fegetexceptflag() function shall attempt to store an * implementation-defined representation of the states of the * floating-point status flags indicated by the argument excepts in * the object pointed to by the argument flagp." */ __declare_fenv_inline(int) fegetexceptflag(fexcept_t *flagp, int excepts) { /* Mask excepts to be sure only supported flag bits are set */ excepts &= FE_ALL_EXCEPT; /* Get current exception flags */ fexcept_t flags; __asm__ volatile("frflags %0" : "=r"(flags)); /* Return the requested flags in flagp */ *flagp = flags & excepts; /* Per 'fegetexceptflag.html: * * "If the representation was successfully stored, fegetexceptflag() * shall return zero. Otherwise, it shall return a non-zero * value." */ return 0; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/fegetround.html * Referred to as 'fegetround.html below. * * "The fegetround() function shall get the current rounding direction." */ __declare_fenv_inline(int) fegetround(void) { /* Get current rounding mode */ fenv_t frm; __asm__ volatile("frrm %0" : "=r"(frm)); /* Per 'fegetround.html: * * "The fegetround() function shall return the value of the rounding * direction macro representing the current rounding direction or a * negative value if there is no such rounding direction macro or * the current rounding direction is not determinable." */ /* Return the rounding mode */ return frm; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/feholdexcept.html * Referred to as 'feholdexcept.html below. * * "The feholdexcept() function shall save the current floating-point * environment in the object pointed to by envp, clear the * floating-point status flags, and then install a non-stop (continue * on floating-point exceptions) mode, if available, for all * floating-point exceptions." */ __declare_fenv_inline(int) feholdexcept(fenv_t *envp) { /* Store the current FP environment in envp*/ fenv_t fcsr; __asm__ volatile("frcsr %0" : "=r"(fcsr)); *envp = fcsr; /* Clear all flags */ __asm__ volatile("csrrc zero, fflags, %0" : : "r"(FE_ALL_EXCEPT)); /* RISC-V does not raise FP traps so it is always in a "non-stop" mode */ /* Per 'feholdexcept.html: * * "The feholdexcept() function shall return zero if and only if * non-stop floating-point exception handling was successfully * installed." */ return 0; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/feraiseexcept.html * Referred to as 'feraiseexcept.html below. * * "The feraiseexcept() function shall attempt to raise the supported * floating-point exceptions represented by the excepts argument. The * order in which these floating-point exceptions are raised is * unspecified, except that if the excepts argument represents IEC * 60559 valid coincident floating-point exceptions for atomic * operations (namely overflow and inexact, or underflow and inexact), * then overflow or underflow shall be raised before inexact. Whether * the feraiseexcept() function additionally raises the inexact * floating-point exception whenever it raises the overflow or * underflow floating-point exception is implementation-defined." */ __declare_fenv_inline(int) feraiseexcept(int excepts) { /* Mask excepts to be sure only supported flag bits are set */ excepts &= FE_ALL_EXCEPT; /* Set the requested exception flags */ __asm__ volatile("csrs fflags, %0" : : "r"(excepts)); /* Per 'feraiseexcept.html: * "If the argument is zero or if all the specified exceptions were * successfully raised, feraiseexcept() shall return * zero. Otherwise, it shall return a non-zero value." */ /* Per "The RISC-V Instruction Set Manual: Volume I: User-Level ISA: * Version 2.1": * * "As allowed by the standard, we do not support traps on * floating-point exceptions in the base ISA, but instead require * explicit checks of the flags in software." * */ return 0; } __declare_fenv_inline(int) fesetexcept(int excepts) { return feraiseexcept(excepts); } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/fegetenv.html * Referred to as 'fegetenv.html below. * * "The fegetenv() function shall attempt to store the current * floating-point environment in the object pointed to by envp. * * The fesetenv() function shall attempt to establish the * floating-point environment represented by the object pointed to by * envp. The argument envp shall point to an object set by a call to * fegetenv() or feholdexcept(), or equal a floating-point environment * macro. The fesetenv() function does not raise floating-point * exceptions, but only installs the state of the floating-point * status flags represented through its argument." */ __declare_fenv_inline(int) fesetenv(const fenv_t *envp) { /* Set environment (FCSR) */ fenv_t fcsr = *envp; __asm__ volatile("fscsr %0" : : "r"(fcsr)); /* Per 'fegetenv.html: * * "If the environment was successfully established, fesetenv() * shall return zero. Otherwise, it shall return a non-zero value. */ return 0; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/fesetexceptflag.html * Referred to as 'fesetexceptflag.html below. * * "The fesetexceptflag() function shall attempt to set the * floating-point status flags indicated by the argument excepts to * the states stored in the object pointed to by flagp. The value * pointed to by flagp shall have been set by a previous call to * fegetexceptflag() whose second argument represented at least those * floating-point exceptions represented by the argument excepts. This * function does not raise floating-point exceptions, but only sets * the state of the flags." * */ __declare_fenv_inline(int) fesetexceptflag(const fexcept_t *flagp, int excepts) { /* Mask excepts to be sure only supported flag bits are set */ excepts &= FE_ALL_EXCEPT; /* Set the requested flags */ fexcept_t flags = *flagp & FE_ALL_EXCEPT; /* Set new the flags */ __asm__ volatile("csrc fflags, %0" : : "r"(excepts)); __asm__ volatile("csrs fflags, %0" : : "r"(flags & excepts)); /* Per 'fesetexceptflag.html: * * "If the excepts argument is zero or if all the specified * exceptions were successfully set, fesetexceptflag() shall return * zero. Otherwise, it shall return a non-zero value." */ return 0; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/009695399/functions/fesetround.html * Referred to as 'fegetenv.html below. * * "The fesetround() function shall establish the rounding direction * represented by its argument round. If the argument is not equal to * the value of a rounding direction macro, the rounding direction is * not changed." */ __declare_fenv_inline(int) fesetround(int round) { int status = 1; switch (round) { case FE_TONEAREST_MM: /* Intentional fall-through */ case FE_UPWARD: /* Intentional fall-through */ case FE_DOWNWARD: /* Intentional fall-through */ case FE_TOWARDZERO: /* Intentional fall-through */ case FE_TONEAREST: /* Set the rounding mode */ __asm__ volatile("fsrm %0" : : "r"(round)); /* status 0 to indicate successful processing of rounding mode */ status = 0; break; default: break; } /* Per 'fesetround.html: * * "The fesetround() function shall return a zero value if and only * if the requested rounding direction was established." */ return status; } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/9699919799/functions/fetestexcept.html * * "The fetestexcept() function shall determine which of a specified * subset of the floating-point exception flags are currently set. The * excepts argument specifies the floating-point status flags to be * queried." */ __declare_fenv_inline(int) fetestexcept(int excepts) { /* Mask excepts to be sure only supported flag bits are set */ excepts &= FE_ALL_EXCEPT; /* Read the current flags */ fexcept_t flags; __asm__ volatile("frflags %0" : "=r"(flags)); /* "The fetestexcept() function shall return the value of the * bitwise-inclusive OR of the floating-point exception macros * corresponding to the currently set floating-point exceptions * included in excepts." */ return (flags & excepts); } /* This implementation is intended to comply with the following * specification: * * http://pubs.opengroup.org/onlinepubs/9699919799/functions/feupdateenv.html * * "The feupdateenv() function shall attempt to save the currently * raised floating-point exceptions in its automatic storage, attempt * to install the floating-point environment represented by the object * pointed to by envp, and then attempt to raise the saved * floating-point exceptions. The argument envp shall point to an * object set by a call to feholdexcept() or fegetenv(), or equal a * floating-point environment macro." */ __declare_fenv_inline(int) feupdateenv(const fenv_t *envp) { /* Get current exception flags */ fexcept_t flags; __asm__ volatile("frflags %0" : "=r"(flags)); /* Set the environment as requested */ fenv_t fcsr = *envp; /* Environment to install */ __asm__ volatile("fscsr %0" : : "r"(fcsr)); /* Install environment */ /* OR in the saved exception flags */ __asm__ volatile("csrs fflags, %0" : : "r"(flags)); /* "The feupdateenv() function shall return a zero value if and only * if all the required actions were successfully carried out." */ return 0; } __declare_fenv_inline(int) feenableexcept(int excepts) { return excepts == 0 ? 0 : -1; } __declare_fenv_inline(int) fedisableexcept(int excepts) { (void)excepts; return excepts == 0 ? 0 : -1; } __declare_fenv_inline(int) fegetexcept(void) { return 0; } picolibc-1.8.11/libc/machine/riscv/machine/fenv.h000066400000000000000000000060361513574234600215630ustar00rootroot00000000000000/* Copyright (c) 2017 SiFive Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #ifndef _MACHINE_FENV_H #define _MACHINE_FENV_H #include #if defined(__riscv_flen) || defined(__riscv_zfinx) /* Per "The RISC-V Instruction Set Manual: Volume I: User-Level ISA: * Version 2.1", Section 8.2, "Floating-Point Control and Status * Register": * * Flag Mnemonic Flag Meaning * ------------- ----------------- * NV Invalid Operation * DZ Divide by Zero * OF Overflow * UF Underflow * NX Inexact */ #define FE_INVALID 0x00000010 #define FE_DIVBYZERO 0x00000008 #define FE_OVERFLOW 0x00000004 #define FE_UNDERFLOW 0x00000002 #define FE_INEXACT 0x00000001 #define FE_ALL_EXCEPT (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT) /* Per "The RISC-V Instruction Set Manual: Volume I: User-Level ISA: * Version 2.1", Section 8.2, "Floating-Point Control and Status * Register": * * Rounding Mode Mnemonic Meaning Meaning * ------------- ---------------- ------- * 000 RNE Round to Nearest, ties to Even * 001 RTZ Round towards Zero * 010 RDN Round Down (towards −∞) * 011 RUP Round Up (towards +∞) * 100 RMM Round to Nearest, ties to Max Magnitude * 101 Invalid. Reserved for future use. * 110 Invalid. Reserved for future use. * 111 In instruction’s rm field, selects dynamic rounding mode; * In Rounding Mode register, Invalid */ #define FE_TONEAREST_MM 0x00000004 #define FE_UPWARD 0x00000003 #define FE_DOWNWARD 0x00000002 #define FE_TOWARDZERO 0x00000001 #define FE_TONEAREST 0x00000000 #define FE_RMODE_MASK 0x7 #else #define FE_TONEAREST 0 #endif /* Per "The RISC-V Instruction Set Manual: Volume I: User-Level ISA: * Version 2.1": * * "The F extension adds 32 floating-point registers, f0–f31, each 32 * bits wide, and a floating-point control and status register fcsr, * which contains the operating mode and exception status of the * floating-point unit." */ typedef size_t fenv_t; typedef size_t fexcept_t; #if !defined(__declare_fenv_inline) && defined(__declare_extern_inline) #define __declare_fenv_inline(type) __declare_extern_inline(type) #endif #ifdef __declare_fenv_inline #if defined(__riscv_flen) || defined(__riscv_zfinx) #include #else #include #endif #endif #endif /* _MACHINE_FENV_H */ picolibc-1.8.11/libc/machine/riscv/machine/math.h000066400000000000000000000174221513574234600215570ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MACHINE_MATH_H_ #define _MACHINE_MATH_H_ #if defined(__riscv_flen) || defined(__riscv_zfinx) #if (__riscv_flen >= 64) || defined(__riscv_zdinx) #define __RISCV_HARD_FLOAT 64 #else #define __RISCV_HARD_FLOAT 32 #endif #ifdef __MATH_ERRNO #include #endif #define FCLASS_NEG_INF (1 << 0) #define FCLASS_NEG_NORMAL (1 << 1) #define FCLASS_NEG_SUBNORMAL (1 << 2) #define FCLASS_NEG_ZERO (1 << 3) #define FCLASS_POS_ZERO (1 << 4) #define FCLASS_POS_SUBNORMAL (1 << 5) #define FCLASS_POS_NORMAL (1 << 6) #define FCLASS_POS_INF (1 << 7) #define FCLASS_SNAN (1 << 8) #define FCLASS_QNAN (1 << 9) #define FCLASS_INF (FCLASS_NEG_INF | FCLASS_POS_INF) #define FCLASS_ZERO (FCLASS_NEG_ZERO | FCLASS_POS_ZERO) #define FCLASS_NORMAL (FCLASS_NEG_NORMAL | FCLASS_POS_NORMAL) #define FCLASS_SUBNORMAL (FCLASS_NEG_SUBNORMAL | FCLASS_POS_SUBNORMAL) #define FCLASS_NAN (FCLASS_SNAN | FCLASS_QNAN) #if __RISCV_HARD_FLOAT >= 64 /* anything with a 64-bit FPU has FMA */ #define __HAVE_FAST_FMA 1 #define _fclass_d(_x) \ (__extension__({ \ long __fclass; \ __asm__("fclass.d %0, %1" : "=r"(__fclass) : "f"(_x)); \ __fclass; \ })) #endif #if __RISCV_HARD_FLOAT >= 32 /* anything with a 32-bit FPU has FMAF */ #define __HAVE_FAST_FMAF 1 #define _fclass_f(_x) \ (__extension__({ \ long __fclass; \ __asm__("fclass.s %0, %1" : "=r"(__fclass) : "f"(_x)); \ __fclass; \ })) #endif #ifdef __declare_extern_inline #if __RISCV_HARD_FLOAT >= 64 /* Double-precision functions */ __declare_extern_inline(double) copysign(double x, double y) { double result; __asm__("fsgnj.d\t%0, %1, %2" : "=f"(result) : "f"(x), "f"(y)); return result; } __declare_extern_inline(double) fabs(double x) { double result; __asm__("fabs.d\t%0, %1" : "=f"(result) : "f"(x)); return result; } __declare_extern_inline(double) fmax(double x, double y) { double result; if (issignaling(x) || issignaling(y)) return x + y; __asm__ volatile("fmax.d\t%0, %1, %2" : "=f"(result) : "f"(x), "f"(y)); return result; } __declare_extern_inline(double) fmin(double x, double y) { double result; if (issignaling(x) || issignaling(y)) return x + y; __asm__ volatile("fmin.d\t%0, %1, %2" : "=f"(result) : "f"(x), "f"(y)); return result; } __declare_extern_inline(int) __finite(double x) { long fclass = _fclass_d(x); return (fclass & (FCLASS_INF | FCLASS_NAN)) == 0; } __declare_extern_inline(int) finite(double x) { return __finite(x); } __declare_extern_inline(int) __isinfd(double x) { long fclass = _fclass_d(x); return (fclass & FCLASS_INF) != 0; } __declare_extern_inline(int) __isnand(double x) { long fclass = _fclass_d(x); return (fclass & FCLASS_NAN) != 0; } __declare_extern_inline(int) __fpclassifyd(double x) { long fclass = _fclass_d(x); if (fclass & FCLASS_ZERO) return FP_ZERO; else if (fclass & FCLASS_NORMAL) return FP_NORMAL; else if (fclass & FCLASS_SUBNORMAL) return FP_SUBNORMAL; else if (fclass & FCLASS_INF) return FP_INFINITE; else return FP_NAN; } __declare_extern_inline(double) sqrt(double x) { double result; #ifdef __MATH_ERRNO if (isless(x, 0.0)) errno = EDOM; #endif __asm__ volatile("fsqrt.d %0, %1" : "=f"(result) : "f"(x)); return result; } __declare_extern_inline(double) fma(double x, double y, double z) { double result; __asm__ volatile("fmadd.d %0, %1, %2, %3" : "=f"(result) : "f"(x), "f"(y), "f"(z)); return result; } #endif /* __RISCV_HARD_FLOAT >= 64 */ #if __RISCV_HARD_FLOAT >= 32 /* Single-precision functions */ __declare_extern_inline(float) copysignf(float x, float y) { float result; __asm__("fsgnj.s\t%0, %1, %2" : "=f"(result) : "f"(x), "f"(y)); return result; } __declare_extern_inline(float) fabsf(float x) { float result; __asm__("fabs.s\t%0, %1" : "=f"(result) : "f"(x)); return result; } __declare_extern_inline(float) fmaxf(float x, float y) { float result; if (issignaling(x) || issignaling(y)) return x + y; __asm__ volatile("fmax.s\t%0, %1, %2" : "=f"(result) : "f"(x), "f"(y)); return result; } __declare_extern_inline(float) fminf(float x, float y) { float result; if (issignaling(x) || issignaling(y)) return x + y; __asm__ volatile("fmin.s\t%0, %1, %2" : "=f"(result) : "f"(x), "f"(y)); return result; } __declare_extern_inline(int) __finitef(float x) { long fclass = _fclass_f(x); return (fclass & (FCLASS_INF | FCLASS_NAN)) == 0; } __declare_extern_inline(int) finitef(float x) { return __finitef(x); } __declare_extern_inline(int) __isinff(float x) { long fclass = _fclass_f(x); return (fclass & FCLASS_INF) != 0; } __declare_extern_inline(int) __isnanf(float x) { long fclass = _fclass_f(x); return (fclass & FCLASS_NAN) != 0; } __declare_extern_inline(int) __fpclassifyf(float x) { long fclass = _fclass_f(x); if (fclass & FCLASS_ZERO) return FP_ZERO; else if (fclass & FCLASS_NORMAL) return FP_NORMAL; else if (fclass & FCLASS_SUBNORMAL) return FP_SUBNORMAL; else if (fclass & FCLASS_INF) return FP_INFINITE; else return FP_NAN; } __declare_extern_inline(float) sqrtf(float x) { float result; #ifdef __MATH_ERRNO if (isless(x, 0.0f)) errno = EDOM; #endif __asm__ volatile("fsqrt.s %0, %1" : "=f"(result) : "f"(x)); return result; } __declare_extern_inline(float) fmaf(float x, float y, float z) { float result; __asm__ volatile("fmadd.s %0, %1, %2, %3" : "=f"(result) : "f"(x), "f"(y), "f"(z)); return result; } #endif /* __RISCV_HARD_FLOAT >= 32 */ #endif /* defined(__GNUC_GNU_INLINE__) || defined(__GNUC_STDC_INLINE__) */ #endif /* __RISCV_HARD_FLOAT */ #endif /* _MACHINE_MATH_H_ */ picolibc-1.8.11/libc/machine/riscv/machine/meson.build000066400000000000000000000033641513574234600226170ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2020 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_machine_headers_machine = [ 'fenv.h', 'fenv-fp.h', 'math.h' ] if really_install install_headers(inc_machine_headers_machine, install_dir: include_dir / 'machine') endif picolibc-1.8.11/libc/machine/riscv/memcpy-asm.S000066400000000000000000000015331513574234600212410ustar00rootroot00000000000000/* Copyright (c) 2019 SiFive Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #include "rv_string.h" #ifdef _MACHINE_RISCV_MEMCPY_ASM_ .section .text.memcpy .global memcpy .type memcpy, @function memcpy: mv a3, a0 beqz a2, 2f 1: lbu a4, 0(a1) sb a4, 0(a3) addi a2, a2, -1 addi a3, a3, 1 addi a1, a1, 1 bnez a2, 1b 2: ret .size memcpy, .-memcpy #endif /* _MACHINE_RISCV_MEMCPY_ASM_ */ picolibc-1.8.11/libc/machine/riscv/memcpy.c000066400000000000000000000105001513574234600204750ustar00rootroot00000000000000/* Copyright (c) 2017 SiFive Inc. All rights reserved. Copyright (c) 2025 Mahmoud Abumandour This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #include "rv_string.h" #ifdef _MACHINE_RISCV_MEMCPY_C_ #include #include #include "../../string/local.h" #include "asm.h" #include "xlenint.h" #define unlikely(X) __builtin_expect(!!(X), 0) static inline void __libc_memcpy_bytewise(unsigned char *dst, const unsigned char *src, const size_t sz) { const unsigned char *end = dst + sz; while (dst < end) *dst++ = *src++; } #ifndef __riscv_misaligned_fast static uintxlen_t __libc_load_xlen(const void *src) { const unsigned char *p = (const unsigned char *)src; uintxlen_t ret = 0; unsigned char b0 = *p++; unsigned char b1 = *p++; unsigned char b2 = *p++; unsigned char b3 = *p++; ret = (uintxlen_t)b0 | ((uintxlen_t)b1 << 8) | ((uintxlen_t)b2 << 16) | ((uintxlen_t)b3 << 24); #if __riscv_xlen == 64 unsigned char b4 = *p++; unsigned char b5 = *p++; unsigned char b6 = *p++; unsigned char b7 = *p++; ret |= ((uintxlen_t)b4 << 32) | ((uintxlen_t)b5 << 40) | ((uintxlen_t)b6 << 48) | ((uintxlen_t)b7 << 56); #endif return ret; } #endif #undef memcpy void * __no_builtin #if __riscv_misaligned_slow || __riscv_misaligned_fast __disable_sanitizer #endif memcpy(void * __restrict aa, const void * __restrict bb, size_t n) { unsigned char *a = (unsigned char *)aa; const unsigned char *b = (const unsigned char *)bb; unsigned char *end = a + n; uintptr_t msk = SZREG - 1; if (n < SZREG) { if (__builtin_expect(a < end, 1)) __libc_memcpy_bytewise(a, b, n); return aa; } /* * If misaligned access is slow or prohibited, and the alignments of the source * and destination are different, we align the destination to do XLEN stores. * This uses only one aligned store for every four (or eight for XLEN == 64) * bytes of data. */ #ifndef __riscv_misaligned_fast if (unlikely((((uintptr_t)a & msk) != ((uintptr_t)b & msk)))) { size_t dst_pad = (uintptr_t)a & msk; dst_pad = (SZREG - dst_pad) & msk; __libc_memcpy_bytewise(a, b, dst_pad); a += dst_pad; b += dst_pad; uintxlen_t *la = (uintxlen_t *)a; const unsigned char *cb = (const unsigned char *)b; uintxlen_t *lend = (uintxlen_t *)((uintptr_t)end & ~msk); while (la < lend) { *la++ = __libc_load_xlen(cb); cb += SZREG; } a = (unsigned char *)la; b = (const unsigned char *)cb; if (unlikely(a < end)) __libc_memcpy_bytewise(a, b, end - a); return aa; } #endif if (unlikely(((uintptr_t)a & msk) != 0)) { size_t pad = SZREG - ((uintptr_t)a & msk); __libc_memcpy_bytewise(a, b, pad); a += pad; b += pad; } uintxlen_t *la = (uintxlen_t *)a; const uintxlen_t *lb = (const uintxlen_t *)b; uintxlen_t *lend = (uintxlen_t *)((uintptr_t)end & ~msk); if (unlikely(lend - la > 8)) { while (lend - la > 8) { uintxlen_t b0 = *lb++; uintxlen_t b1 = *lb++; uintxlen_t b2 = *lb++; uintxlen_t b3 = *lb++; uintxlen_t b4 = *lb++; uintxlen_t b5 = *lb++; uintxlen_t b6 = *lb++; uintxlen_t b7 = *lb++; uintxlen_t b8 = *lb++; *la++ = b0; *la++ = b1; *la++ = b2; *la++ = b3; *la++ = b4; *la++ = b5; *la++ = b6; *la++ = b7; *la++ = b8; } } a = (unsigned char *)la; b = (const unsigned char *)lb; if (unlikely(a < end)) __libc_memcpy_bytewise(a, b, end - a); return aa; } #endif /* _MACHINE_RISCV_MEMCPY_C_ */ picolibc-1.8.11/libc/machine/riscv/memmove.S000066400000000000000000000036661513574234600206470ustar00rootroot00000000000000/* Copyright (c) 2019 SiFive Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #include "rv_string.h" #ifdef _MACHINE_RISCV_MEMMOVE_ASM_ .section .text.memmove .global memmove .type memmove, @function memmove: beqz a2, .Ldone /* in case there are 0 bytes to be copied, return immediately */ mv a4, a0 /* copy the destination address over to a4, since memmove should return that address in a0 at the end */ li a3, 1 bgtu a1, a0, .Lcopy /* in case of source address > destination address, copy from start to end of the specified memory area */ li a3, -1 /* otherwhise, start copying from the end of the specified memory area in order to prevent data loss in case of overlapping memory areas.*/ add a4, a4, a2 /* add the number of bytes to be copied to both addresses. this gives us the address one byte past the end of the memory area we want to copy, */ add a1, a1, a2 /* therefore we need to subtract 1 from both addresses in the next step before starting the copying process. */ .Lincrement: add a4, a4, a3 /* in case of source address < destination address, increment both addresses by -1 before copying any data to obtain the correct start addresses */ add a1, a1, a3 .Lcopy: lbu a5, 0(a1) addi a2, a2, -1 /* copy bytes as long as a2 (= the number of bytes to be copied) > 0. the increment is done here to relax the RAW dependency between load and store */ sb a5, 0(a4) bnez a2, .Lincrement .Ldone: ret .size memmove, .-memmove #endif /* _MACHINE_RISCV_MEMMOVE_ASM_ */ picolibc-1.8.11/libc/machine/riscv/memmove.c000066400000000000000000000011631513574234600206550ustar00rootroot00000000000000/* Copyright (c) 2019 SiFive Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #include "rv_string.h" #ifdef _MACHINE_RISCV_MEMMOVE_GENERIC_ #include "../../string/memmove.c" #endif picolibc-1.8.11/libc/machine/riscv/memset.S000066400000000000000000000153361513574234600204710ustar00rootroot00000000000000/* Copyright (c) 2017 SiFive Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #include #include "asm.h" #define BYTE_TBL_SZ 31 #define WORD_TBL_SZ 32 #if __riscv_zilsd /* Move size */ #define MV_SZ 8 /* Store instruction */ #define RG_ST sd /* Zilsd and Zclsd require an even numbered register */ #define REG_SPLAT a4 #else #define MV_SZ SZREG #define RG_ST REG_S #define REG_SPLAT a1 #endif /* Use an extended register for Zilsd and Zclsd if available since a5 is used for the odd numbered register, in order to eliminate an li instruction */ #if __riscv_zilsd && !__riscv_abi_rve #define REG_TABLE a6 #else #define REG_TABLE a5 #endif .section .text.memset .global memset .type memset, @function memset: #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) mv a3, a0 beqz a2, .Ldone .Lset: sb a1, 0(a3) addi a2, a2, -1 addi a3, a3, 1 bnez a2, .Lset .Ldone: ret #else li REG_TABLE, BYTE_TBL_SZ mv a3, a0 /* If there aren't many bytes, copy them individually to reduce overhead */ bleu a2, REG_TABLE, .Lcopy_bytes and a4, a3, MV_SZ - 1 beqz a4, .Lword_check /* Jump into the byte table depending on the number of bytes that need to be written */ 1: auipc t0, %pcrel_hi(.Ltable_misaligned) /* Instructions in the tables are forced to be four bytes, so scale count by 4 */ #if __riscv_zba sh2add t0, a4, t0 #else sll t1, a4, 2 add t0, t0, t1 #endif /* Save the return address because we aren't exiting the function yet */ mv t1, ra jalr t0, %pcrel_lo(1b) /* Update pointer and count by what was written */ mv ra, t1 add a4, a4, -MV_SZ add a2, a2, a4 sub a3, a3, a4 /* Access is now aligned. Check we can copy words. */ bleu a2, REG_TABLE, .Lcopy_bytes .Lword_check: /* Don't need to splat special case of zero */ bnez a1, .Lsplat_byte #if __riscv_zilsd mv REG_SPLAT, a1 #endif j .Lcopy_words_init /* Align labels to four bytes after unconditional jumps to avoid any penalties when jumping to 32-bit instructions that aren't 4-byte aligned */ .p2align 2 .Lsplat_byte: #if __riscv_zbkb packh REG_SPLAT, a1, a1 #if __riscv_xlen == 64 packw REG_SPLAT, REG_SPLAT, REG_SPLAT #endif pack REG_SPLAT, REG_SPLAT, REG_SPLAT #else and a1, a1, 0xFF sll t0, a1, 8 or a1, a1, t0 sll t0, a1, 16 or REG_SPLAT, a1, t0 #if __riscv_xlen == 64 sll t0, REG_SPLAT, 32 or REG_SPLAT, REG_SPLAT, t0 #endif #endif .Lcopy_words_init: #if __riscv_zilsd /* Odd register of even-odd pair */ mv a5, REG_SPLAT #endif /* Calculate end address */ and t0, a2, ~(MV_SZ - 1) add t1, a3, t0 /* The idea behind the table of word copies is that first we calculate any remainder of bytes that need to be copied by the table that aren't an entire table length. That's copied first. After that, runs of the entire table are performed. */ and t0, t0, (WORD_TBL_SZ - 1) * MV_SZ /* Skip if there's no remainder */ beqz t0, .Ltable_bigly neg t0, t0 add t0, t0, WORD_TBL_SZ * MV_SZ /* Adjust start address with offset */ sub a3, a3, t0 1: auipc t2, %pcrel_hi(.Ltable_bigly) #if MV_SZ == 8 /* If eight bytes are being copied with each store, we need to divide the table offset in half */ srl t0, t0, 1 #endif add t2, t2, t0 jr t2, %pcrel_lo(1b) .p2align 2 .Ltable_bigly: /* Force the instructions to be four bytes to avoid an extra instruction that would be needed to halve the offset for sw */ .option push .option norvc RG_ST REG_SPLAT, MV_SZ*0(a3) RG_ST REG_SPLAT, MV_SZ*1(a3) RG_ST REG_SPLAT, MV_SZ*2(a3) RG_ST REG_SPLAT, MV_SZ*3(a3) RG_ST REG_SPLAT, MV_SZ*4(a3) RG_ST REG_SPLAT, MV_SZ*5(a3) RG_ST REG_SPLAT, MV_SZ*6(a3) RG_ST REG_SPLAT, MV_SZ*7(a3) RG_ST REG_SPLAT, MV_SZ*8(a3) RG_ST REG_SPLAT, MV_SZ*9(a3) RG_ST REG_SPLAT, MV_SZ*10(a3) RG_ST REG_SPLAT, MV_SZ*11(a3) RG_ST REG_SPLAT, MV_SZ*12(a3) RG_ST REG_SPLAT, MV_SZ*13(a3) RG_ST REG_SPLAT, MV_SZ*14(a3) RG_ST REG_SPLAT, MV_SZ*15(a3) RG_ST REG_SPLAT, MV_SZ*16(a3) RG_ST REG_SPLAT, MV_SZ*17(a3) RG_ST REG_SPLAT, MV_SZ*18(a3) RG_ST REG_SPLAT, MV_SZ*19(a3) RG_ST REG_SPLAT, MV_SZ*20(a3) RG_ST REG_SPLAT, MV_SZ*21(a3) RG_ST REG_SPLAT, MV_SZ*22(a3) RG_ST REG_SPLAT, MV_SZ*23(a3) RG_ST REG_SPLAT, MV_SZ*24(a3) RG_ST REG_SPLAT, MV_SZ*25(a3) RG_ST REG_SPLAT, MV_SZ*26(a3) RG_ST REG_SPLAT, MV_SZ*27(a3) RG_ST REG_SPLAT, MV_SZ*28(a3) RG_ST REG_SPLAT, MV_SZ*29(a3) RG_ST REG_SPLAT, MV_SZ*30(a3) RG_ST REG_SPLAT, MV_SZ*31(a3) .option pop /* Update the pointer and copy data if needed */ add a3, a3, MV_SZ * WORD_TBL_SZ bltu a3, t1, .Ltable_bigly /* Copy any remaining bytes */ and a2, a2, MV_SZ - 1 beqz a2, .Lexit #if __riscv_zilsd && __riscv_abi_rve /* Restore table size if necessary */ li REG_TABLE, BYTE_TBL_SZ #endif .Lcopy_bytes: auipc t0, %pcrel_hi(.Ltable_tiny) sub a2, REG_TABLE, a2 /* Instructions in the tables are forced to be four bytes, so scale count by 4 */ #if __riscv_zba sh2add t0, a2, t0 #else sll a2, a2, 2 add t0, t0, a2 #endif /* Don't save the return address because we're exiting after the jump */ jr t0, %pcrel_lo(.Lcopy_bytes) .p2align 2 .Ltable_tiny: /* norvc is needed because the immediate is only two bits in size for c.sb, and without it the table would have a mix of 2- and 4-byte instructions when Zcb is available */ .option push .option norvc sb a1, 30(a3) sb a1, 29(a3) sb a1, 28(a3) sb a1, 27(a3) sb a1, 26(a3) sb a1, 25(a3) sb a1, 24(a3) sb a1, 23(a3) sb a1, 22(a3) sb a1, 21(a3) sb a1, 20(a3) sb a1, 19(a3) sb a1, 18(a3) sb a1, 17(a3) sb a1, 16(a3) sb a1, 15(a3) sb a1, 14(a3) sb a1, 13(a3) sb a1, 12(a3) sb a1, 11(a3) sb a1, 10(a3) sb a1, 9(a3) sb a1, 8(a3) #if MV_SZ == 8 .Ltable_misaligned: #endif sb a1, 7(a3) sb a1, 6(a3) sb a1, 5(a3) sb a1, 4(a3) #if MV_SZ == 4 .Ltable_misaligned: #endif sb a1, 3(a3) sb a1, 2(a3) sb a1, 1(a3) sb a1, 0(a3) .option pop .Lexit: ret #endif .size memset, .-memset picolibc-1.8.11/libc/machine/riscv/meson.build000066400000000000000000000041161513574234600212070ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'ieeefp.c', 'memcpy-asm.S', 'memcpy.c', 'memmove.S', 'memmove.c', 'memset.S', 'setjmp.S', 'stpcpy.c', 'strcmp.S', 'strcpy.c', 'strlen.c', 'tls.c', ] ieeefp_funcs = true subdir('machine') foreach params : targets target = params['name'] target_dir = params['dir'] target_c_args = params['c_args'] set_variable('lib_machine' + target, static_library('machine' + target, srcs_machine, pic: false, include_directories: inc, c_args: target_c_args + c_args + arg_fnobuiltin)) endforeach picolibc-1.8.11/libc/machine/riscv/rv_strcpy.h000066400000000000000000000104621513574234600212520ustar00rootroot00000000000000/* Copyright (c) 2017 SiFive Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #ifndef _RV_STRCPY_H #define _RV_STRCPY_H #include #include #include "xlenint.h" #if __riscv_zbb // Determine which intrinsics to use based on XLEN and endianness #if __riscv_xlen == 64 #if __has_builtin(__builtin_riscv_orc_b_64) #define __LIBC_RISCV_ZBB_ORC_B(x) __builtin_riscv_orc_b_64(x) #endif #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #if __has_builtin(__builtin_riscv_ctz_64) #define __LIBC_RISCV_ZBB_CNT_Z(x) __builtin_riscv_ctz_64(x) #endif #else #if __has_builtin(__builtin_riscv_clz_64) #define __LIBC_RISCV_ZBB_CNT_Z(x) __builtin_riscv_clz_64(x) #endif #endif #else #if __has_builtin(__builtin_riscv_orc_b_32) #define __LIBC_RISCV_ZBB_ORC_B(x) __builtin_riscv_orc_b_32(x) #endif #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #if __has_builtin(__builtin_riscv_ctz_32) #define __LIBC_RISCV_ZBB_CNT_Z(x) __builtin_riscv_ctz_32(x) #endif #else #if __has_builtin(__builtin_riscv_clz_32) #define __LIBC_RISCV_ZBB_CNT_Z(x) __builtin_riscv_clz_32(x) #endif #endif #endif #endif static __inline uintxlen_t __libc_detect_null(uintxlen_t w) { #ifdef __LIBC_RISCV_ZBB_ORC_B /* If there are any zeros in each byte of the register, all bits will be unset for that byte value, otherwise, all bits will be set. If the value is -1, all bits are set, meaning no null byte was found. */ return __LIBC_RISCV_ZBB_ORC_B(w) != (uintxlen_t)-1; #else uintxlen_t mask = 0x7f7f7f7f; #if __riscv_xlen == 64 mask = ((mask << 16) << 16) | mask; #endif return ~(((w & mask) + mask) | w | mask); #endif } static __inline #if __riscv_misaligned_slow || __riscv_misaligned_fast __disable_sanitizer #endif char * __libc_strcpy(char *dst, const char *src, bool ret_start) { char *dst0 = dst; #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) #if !(__riscv_misaligned_slow || __riscv_misaligned_fast) int misaligned = ((uintxlen_t)dst | (uintxlen_t)src) & (sizeof(uintxlen_t) - 1); if (__builtin_expect(!misaligned, 1)) #endif { uintxlen_t *pdst = (uintxlen_t *)dst; const uintxlen_t *psrc = (const uintxlen_t *)src; uintxlen_t s; while (!__libc_detect_null(s = *psrc)) { *pdst++ = s; psrc++; } dst = (char *)pdst; #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define SBYTE(s, i) ((char)((s) >> ((i) * 8))) #else #define SBYTE(s, i) ((char)((s) >> ((sizeof(s) - 1 - (i)) * 8))) #endif if (ret_start) { if (!(*dst++ = SBYTE(s, 0))) return dst0; if (!(*dst++ = SBYTE(s, 1))) return dst0; if (!(*dst++ = SBYTE(s, 2))) return dst0; #if __riscv_xlen == 64 if (!(*dst++ = SBYTE(s, 3))) return dst0; if (!(*dst++ = SBYTE(s, 4))) return dst0; if (!(*dst++ = SBYTE(s, 5))) return dst0; if (!(*dst++ = SBYTE(s, 6))) return dst0; #endif } else { if (!(*dst++ = SBYTE(s, 0))) return dst - 1; if (!(*dst++ = SBYTE(s, 1))) return dst - 1; if (!(*dst++ = SBYTE(s, 2))) return dst - 1; #if __riscv_xlen == 64 if (!(*dst++ = SBYTE(s, 3))) return dst - 1; if (!(*dst++ = SBYTE(s, 4))) return dst - 1; if (!(*dst++ = SBYTE(s, 5))) return dst - 1; if (!(*dst++ = SBYTE(s, 6))) return dst - 1; #endif dst0 = dst; } *dst = 0; return dst0; } #endif /* not PREFER_SIZE_OVER_SPEED */ char ch; do { ch = *src; src++; dst++; *(dst - 1) = ch; } while (ch); return ret_start ? dst0 : dst - 1; } #endif /* _RV_STRCPY_H */ picolibc-1.8.11/libc/machine/riscv/rv_string.h000066400000000000000000000024741513574234600212400ustar00rootroot00000000000000/* Copyright (c) 2017 SiFive Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. Changes from Qualcomm Technologies, Inc. are provided under the following license: Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. SPDX-License-Identifier: BSD-3-Clause-Clear */ #ifndef _RV_STRING_H_ #define _RV_STRING_H_ /* This file defines macros to choose a specific custom implementation for * 'string.h' APIs. The specialization is segretated per API to allow for * different and/or complex scenarios for each API. */ #include #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) #define _MACHINE_RISCV_MEMCPY_ASM_ #else #define _MACHINE_RISCV_MEMCPY_C_ #endif #if !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) #define _MACHINE_RISCV_MEMMOVE_GENERIC_ #else #define _MACHINE_RISCV_MEMMOVE_ASM_ #endif #endif /* _RV_STRING_H_ */ picolibc-1.8.11/libc/machine/riscv/setjmp.S000066400000000000000000000064711513574234600205010ustar00rootroot00000000000000/* Copyright (c) 2017 SiFive Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #include #include "asm.h" /* int setjmp (jmp_buf); */ .section .text.setjmp .globl setjmp .type setjmp, @function setjmp: REG_S ra, 0*SZREG(a0) #if __riscv_xlen == 32 && (__riscv_zilsd) && (__riscv_misaligned_fast) sd s0, 1*SZREG(a0) #else REG_S s0, 1*SZREG(a0) REG_S s1, 2*SZREG(a0) #endif #ifndef __riscv_abi_rve #if __riscv_xlen == 32 && (__riscv_zilsd) && (__riscv_misaligned_fast) sd s2, 3*SZREG(a0) sd s4, 5*SZREG(a0) sd s6, 7*SZREG(a0) sd s8, 9*SZREG(a0) sd s10,11*SZREG(a0) #else REG_S s2, 3*SZREG(a0) REG_S s3, 4*SZREG(a0) REG_S s4, 5*SZREG(a0) REG_S s5, 6*SZREG(a0) REG_S s6, 7*SZREG(a0) REG_S s7, 8*SZREG(a0) REG_S s8, 9*SZREG(a0) REG_S s9, 10*SZREG(a0) REG_S s10,11*SZREG(a0) REG_S s11,12*SZREG(a0) #endif REG_S sp, 13*SZREG(a0) #else REG_S sp, 3*SZREG(a0) #endif #ifndef __riscv_float_abi_soft FREG_S fs0, 14*SZREG+ 0*SZFREG(a0) FREG_S fs1, 14*SZREG+ 1*SZFREG(a0) FREG_S fs2, 14*SZREG+ 2*SZFREG(a0) FREG_S fs3, 14*SZREG+ 3*SZFREG(a0) FREG_S fs4, 14*SZREG+ 4*SZFREG(a0) FREG_S fs5, 14*SZREG+ 5*SZFREG(a0) FREG_S fs6, 14*SZREG+ 6*SZFREG(a0) FREG_S fs7, 14*SZREG+ 7*SZFREG(a0) FREG_S fs8, 14*SZREG+ 8*SZFREG(a0) FREG_S fs9, 14*SZREG+ 9*SZFREG(a0) FREG_S fs10,14*SZREG+10*SZFREG(a0) FREG_S fs11,14*SZREG+11*SZFREG(a0) #endif li a0, 0 ret .size setjmp, .-setjmp /* volatile void longjmp (jmp_buf, int); */ .section .text.longjmp .globl longjmp .type longjmp, @function longjmp: REG_L ra, 0*SZREG(a0) #if __riscv_xlen == 32 && (__riscv_zilsd) && (__riscv_misaligned_fast) ld s0, 1*SZREG(a0) #else REG_L s0, 1*SZREG(a0) REG_L s1, 2*SZREG(a0) #endif #ifndef __riscv_abi_rve #if __riscv_xlen == 32 && (__riscv_zilsd) && (__riscv_misaligned_fast) ld s2, 3*SZREG(a0) ld s4, 5*SZREG(a0) ld s6, 7*SZREG(a0) ld s8, 9*SZREG(a0) ld s10,11*SZREG(a0) #else REG_L s2, 3*SZREG(a0) REG_L s3, 4*SZREG(a0) REG_L s4, 5*SZREG(a0) REG_L s5, 6*SZREG(a0) REG_L s6, 7*SZREG(a0) REG_L s7, 8*SZREG(a0) REG_L s8, 9*SZREG(a0) REG_L s9, 10*SZREG(a0) REG_L s10,11*SZREG(a0) REG_L s11,12*SZREG(a0) #endif REG_L sp, 13*SZREG(a0) #else REG_L sp, 3*SZREG(a0) #endif #ifndef __riscv_float_abi_soft FREG_L fs0, 14*SZREG+ 0*SZFREG(a0) FREG_L fs1, 14*SZREG+ 1*SZFREG(a0) FREG_L fs2, 14*SZREG+ 2*SZFREG(a0) FREG_L fs3, 14*SZREG+ 3*SZFREG(a0) FREG_L fs4, 14*SZREG+ 4*SZFREG(a0) FREG_L fs5, 14*SZREG+ 5*SZFREG(a0) FREG_L fs6, 14*SZREG+ 6*SZFREG(a0) FREG_L fs7, 14*SZREG+ 7*SZFREG(a0) FREG_L fs8, 14*SZREG+ 8*SZFREG(a0) FREG_L fs9, 14*SZREG+ 9*SZFREG(a0) FREG_L fs10,14*SZREG+10*SZFREG(a0) FREG_L fs11,14*SZREG+11*SZFREG(a0) #endif seqz a0, a1 add a0, a0, a1 # a0 = (a1 == 0) ? 1 : a1 ret .size longjmp, .-longjmp picolibc-1.8.11/libc/machine/riscv/stpcpy.c000066400000000000000000000012701513574234600205310ustar00rootroot00000000000000/* Copyright (c) 2025 SiFive Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #define _DEFAULT_SOURCE #include #include "rv_strcpy.h" #undef stpcpy char * stpcpy(char *dst, const char *src) { return __libc_strcpy(dst, src, false); } picolibc-1.8.11/libc/machine/riscv/strcmp.S000066400000000000000000000124731513574234600205060ustar00rootroot00000000000000/* Copyright (c) 2017 SiFive Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #include #include "asm.h" .section .text.strcmp .globl strcmp .type strcmp, @function strcmp: #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) .Lcompare: lbu a2, 0(a0) lbu a3, 0(a1) addi a0, a0, 1 addi a1, a1, 1 bne a2, a3, .Lreturn_diff bnez a2, .Lcompare .Lreturn_diff: sub a0, a2, a3 ret .size strcmp, .-strcmp #else li t2, -1 #if !(__riscv_misaligned_slow || __riscv_misaligned_fast) or a4, a0, a1 and a4, a4, SZREG-1 bnez a4, .Lmisaligned #endif #ifndef __riscv_zbb #if SZREG == 4 li a5, 0x7f7f7f7f #else ld a5, mask #endif #endif .macro check_one_word i n REG_L a2, \i*SZREG(a0) REG_L a3, \i*SZREG(a1) #ifdef __riscv_zbb orc.b a4, a2 #else and a4, a2, a5 or t1, a2, a5 add a4, a4, a5 or a4, a4, t1 #endif bne a4, t2, .Lnull\i .if \i+1-\n bne a2, a3, .Lmismatch .else add a0, a0, \n*SZREG add a1, a1, \n*SZREG beq a2, a3, .Lloop # fall through to .Lmismatch .endif .endm .macro foundnull i n .ifne \i .Lnull\i: add a0, a0, \i*SZREG add a1, a1, \i*SZREG .ifeq \i-1 .Lnull0: .endif bne a2, a3, .Lmisaligned li a0, 0 ret .endif .endm .Lloop: # examine full words at a time, favoring strings of a couple dozen chars #if __riscv_xlen == 32 check_one_word 0 5 check_one_word 1 5 check_one_word 2 5 check_one_word 3 5 check_one_word 4 5 #else check_one_word 0 3 check_one_word 1 3 check_one_word 2 3 #endif # backwards branch to .Lloop contained above .Lmismatch: # words don't match, but a2 has no null byte. #if __riscv_zbb xor a4, a2, a3 # find differing bits # Check system endianness # If little-endian, use Count Trailing Zeros (ctz) # If big-endian, use Count Leading Zeros (clz) # This helps identify the position of the first differing byte between a2 and a3. # For example, in little-endian, least significant byte comes first. # So trailing zeros help find which byte position differs. # In big-endian, most significant byte comes first, so leading zeros are used. # The position will then be used to extract the differing byte. #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ctz a5, a4 #else clz a5, a4 #endif andi a5, a5, -8 # find position of bit offset to the start of the byte where the first difference occurs # Shift a2 and a3 right by a5 bits to bring the target byte to the LSB, and isolate the byte of interest srl a2, a2, a5 and a2, a2, 0xff srl a3, a3, a5 and a3, a3, 0xff sub a0, a2, a3 # Calculate and return the difference in the isolated bytes ret #else #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #if __riscv_xlen == 64 sll a4, a2, 48 sll a5, a3, 48 bne a4, a5, .Lmismatch_upper sll a4, a2, 32 sll a5, a3, 32 bne a4, a5, .Lmismatch_upper #endif sll a4, a2, 16 sll a5, a3, 16 bne a4, a5, .Lmismatch_upper srl a4, a2, 8*SZREG-16 srl a5, a3, 8*SZREG-16 sub a0, a4, a5 and a1, a0, 0xff bnez a1, .Lfinal_upper_diff ret .Lmismatch_upper: srl a4, a4, 8*SZREG-16 srl a5, a5, 8*SZREG-16 sub a0, a4, a5 and a1, a0, 0xff bnez a1, .Lfinal_upper_diff ret .Lfinal_upper_diff: and a4, a4, 0xff and a5, a5, 0xff sub a0, a4, a5 ret #else #if __riscv_xlen == 64 srl a4, a2, 48 srl a5, a3, 48 bne a4, a5, .Lmismatch_lower srl a4, a2, 32 srl a5, a3, 32 bne a4, a5, .Lmismatch_lower #endif srl a4, a2, 16 srl a5, a3, 16 bne a4, a5, .Lmismatch_lower srl a4, a2, 8 srl a5, a3, 8 bne a4, a5, .Lbyte_diff and a4, a2, 0xff and a5, a3, 0xff .Lbyte_diff: sub a0, a4, a5 ret .Lmismatch_lower: srl a2, a4, 8 srl a3, a5, 8 bne a2, a3, .Lfinal_lower_diff and a2, a4, 0xff and a3, a5, 0xff .Lfinal_lower_diff: sub a0, a2, a3 ret #endif #endif .Lmisaligned: # misaligned lbu a2, 0(a0) lbu a3, 0(a1) add a0, a0, 1 add a1, a1, 1 bne a2, a3, .Lmisaligned_diff bnez a2, .Lmisaligned .Lmisaligned_diff: sub a0, a2, a3 ret # cases in which a null byte was detected #if __riscv_xlen == 32 foundnull 0 5 foundnull 1 5 foundnull 2 5 foundnull 3 5 foundnull 4 5 #else foundnull 0 3 foundnull 1 3 foundnull 2 3 #endif #if !defined(__riscv_zbb) && SZREG != 4 .align 3 mask: .dword 0x7f7f7f7f7f7f7f7f #endif .size strcmp, .-strcmp #endif picolibc-1.8.11/libc/machine/riscv/strcpy.c000066400000000000000000000012371513574234600205360ustar00rootroot00000000000000/* Copyright (c) 2017 SiFive Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #include #include "rv_strcpy.h" #undef strcpy char * strcpy(char *dst, const char *src) { return __libc_strcpy(dst, src, true); } picolibc-1.8.11/libc/machine/riscv/strlen.c000066400000000000000000000031161513574234600205170ustar00rootroot00000000000000/* Copyright (c) 2017 SiFive Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the FreeBSD License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license is available at http://www.opensource.org/licenses. */ #include #include #include #include "rv_strcpy.h" size_t strlen(const char *str) { const char *start = str; #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) while (*str++) ; return str - start - 1; #else if (__builtin_expect((uintxlen_t)str & (sizeof(uintxlen_t) - 1), 0)) do { char ch = *str; str++; if (!ch) return str - start - 1; } while ((uintxlen_t)str & (sizeof(uintxlen_t) - 1)); uintxlen_t *ps = (uintxlen_t *)str; uintxlen_t psval; while (!__libc_detect_null((psval = *ps))) ps++; __asm__ volatile("" : "+r"(ps)); /* prevent "optimization" */ str = (const char *)ps; #if defined(__LIBC_RISCV_ZBB_ORC_B) && defined(__LIBC_RISCV_ZBB_CNT_Z) psval = ~__LIBC_RISCV_ZBB_ORC_B(psval); psval = __LIBC_RISCV_ZBB_CNT_Z(psval); str += (psval >> 3); #else while (psval & 0xff) { psval >>= 8; str++; } #endif return str - start; #endif /* not PREFER_SIZE_OVER_SPEED */ } picolibc-1.8.11/libc/machine/riscv/tls.c000066400000000000000000000034731513574234600200200ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #ifdef __THREAD_LOCAL_STORAGE_API /* This code is duplicated in picocrt/machine/riscv/crt0.c */ void _set_tls(void *tls) { __asm__("mv tp, %0" : : "r"(tls)); } #endif picolibc-1.8.11/libc/machine/riscv/xlenint.h000066400000000000000000000003641513574234600207000ustar00rootroot00000000000000#ifndef _XLENINT_H #define _XLENINT_H #include #if __riscv_xlen == 64 typedef uint64_t uintxlen_t; #elif __riscv_xlen == 32 typedef uint32_t uintxlen_t; #else #error __riscv_xlen must equal 32 or 64 #endif #endif /* _XLENINT_H */ picolibc-1.8.11/libc/machine/rl78/000077500000000000000000000000001513574234600165115ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/rl78/setjmp.S000066400000000000000000000071041513574234600201410ustar00rootroot00000000000000/* Copyright (c) 2011 Red Hat Incorporated. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #ifdef __RL78_G10__ ; clobberable r8 = 0xffec8 r9 = 0xffec9 r10 = 0xffeca r11 = 0xffecb r12 = 0xffecc r13 = 0xffecd r14 = 0xffece r15 = 0xffecf ; preserved r16 = 0xffed0 r17 = 0xffed1 r18 = 0xffed2 r19 = 0xffed3 r20 = 0xffed4 r21 = 0xffed5 r22 = 0xffed6 r23 = 0xffed7 #else ; clobberable r8 = 0xffef0 r9 = 0xffef1 r10 = 0xffef2 r11 = 0xffef3 r12 = 0xffef4 r13 = 0xffef5 r14 = 0xffef6 r15 = 0xffef7 ; preserved r16 = 0xffee8 r17 = 0xffee9 r18 = 0xffeea r19 = 0xffeeb r20 = 0xffeec r21 = 0xffeed r22 = 0xffeee r23 = 0xffeef #endif /* The jump buffer has the following structure: R0 .. R23 3*8 bytes SP 2 bytes ES 1 byte CS 1 byte PC 4 bytes */ .macro _saveb ofs,reg mov a,\reg mov [hl+\ofs],a .endm .macro _save ofs,reg movw ax,\reg movw [hl+\ofs],ax .endm .global _setjmp .type _setjmp, @function _setjmp: ;; R8 = setjmp (jmp_buf *[sp+4].w) ;; must return zero !! push ax push hl push ax movw ax, [sp+10] movw hl, ax pop ax movw [hl], ax _save 2, bc _save 4, de pop ax movw [hl+6], ax _save 8, r8 _save 10, r10 _save 12, r12 _save 14, r14 _save 16, r16 _save 18, r18 _save 20, r20 _save 22, r22 ;; The sp we have now includes one more pushed reg, plus $PC movw ax, sp addw ax, #6 movw [hl+24], ax _saveb 26, es _saveb 27, cs _save 28, [sp+2] _save 30, [sp+4] clrw ax movw r8, ax pop ax ret .size _setjmp, . - _setjmp .macro _loadb ofs,reg mov a,[hl+\ofs] mov \reg,a .endm .macro _load ofs,reg movw ax,[hl+\ofs] movw \reg,ax .endm .macro _push ofs movw ax,[hl+\ofs] push ax .endm .global _longjmp .type _longjmp, @function _longjmp: ;; noreturn longjmp (jmp_buf *[sp+4].w, int [sp+6].w) movw ax, [sp+6] cmpw ax,#0 sknz onew ax movw r8, ax movw ax, [sp+4] movw hl, ax movw ax, [hl+24] movw sp, ax ; this is the *new* stack _push 30 ; high half of PC _push 28 ; low half of PC _push 6 ; HL _push 0 ; AX _load 2, bc _load 4, de _load 10, r10 _load 12, r12 _load 14, r14 _load 16, r16 _load 18, r18 _load 20, r20 _load 22, r22 _loadb 26, es _loadb 27, cs pop ax pop hl ret ; pops PC (4 bytes) .size _longjmp, . - _longjmp picolibc-1.8.11/libc/machine/rx/000077500000000000000000000000001513574234600163465ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/rx/CMakeLists.txt000066400000000000000000000036001513574234600211050ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2024 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources_flags(-fno-builtin memchr.S memcpy.S memmove.S mempcpy.S memset.S setjmp.S strcat.S strcmp.S strcpy.S strlen.S strncat.S strncmp.S strncpy.S interrupt.c memchr.c memcpy.c memmove.c mempcpy.c memset.c strcat.c strcmp.c strcpy.c strlen.c strncat.c strncmp.c strncpy.c ) picolibc-1.8.11/libc/machine/rx/interrupt.c000066400000000000000000000164341513574234600205560ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Renesas Electronics Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ extern void _start(void); /* Exception functions */ void rx_halt_exception(void); void rx_halt_exception(void) { for (;;) ; } #define exception(name) \ void rx_##name##_exception(void) __attribute__((weak, alias("rx_ignore_exception"))); #define exception_halt(name) \ void rx_##name##_exception(void) __attribute__((weak, alias("rx_halt_exception"))); exception_halt(privilege); exception_halt(access); exception_halt(illegal); exception_halt(address); exception_halt(fpu); exception_halt(nmi); void _start(void); #define e(addr, name) [(addr) / 4] = (void (*)(void))rx_##name##_exception void * const __exception_vector[] __attribute__((section(".rodata.fvectors"))) = { e(0x50, privilege), e(0x54, access), e(0x5c, illegal), e(0x60, address), e(0x64, fpu), e(0x78, nmi), [0x7c / 4] = _start, }; void rx_halt_isr(void); void rx_halt_isr(void) { for (;;) ; } #define isr(name) void rx_##name##_isr(void) __attribute__((weak, alias("rx_halt_isr"))) isr(0); isr(1); isr(2); isr(3); isr(4); isr(5); isr(6); isr(7); isr(8); isr(9); isr(10); isr(11); isr(12); isr(13); isr(14); isr(15); isr(16); isr(17); isr(18); isr(19); isr(20); isr(21); isr(22); isr(23); isr(24); isr(25); isr(26); isr(27); isr(28); isr(29); isr(30); isr(31); isr(32); isr(33); isr(34); isr(35); isr(36); isr(37); isr(38); isr(39); isr(40); isr(41); isr(42); isr(43); isr(44); isr(45); isr(46); isr(47); isr(48); isr(49); isr(50); isr(51); isr(52); isr(53); isr(54); isr(55); isr(56); isr(57); isr(58); isr(59); isr(60); isr(61); isr(62); isr(63); isr(64); isr(65); isr(66); isr(67); isr(68); isr(69); isr(70); isr(71); isr(72); isr(73); isr(74); isr(75); isr(76); isr(77); isr(78); isr(79); isr(80); isr(81); isr(82); isr(83); isr(84); isr(85); isr(86); isr(87); isr(88); isr(89); isr(90); isr(91); isr(92); isr(93); isr(94); isr(95); isr(96); isr(97); isr(98); isr(99); isr(100); isr(101); isr(102); isr(103); isr(104); isr(105); isr(106); isr(107); isr(108); isr(109); isr(110); isr(111); isr(112); isr(113); isr(114); isr(115); isr(116); isr(117); isr(118); isr(119); isr(120); isr(121); isr(122); isr(123); isr(124); isr(125); isr(126); isr(127); isr(128); isr(129); isr(130); isr(131); isr(132); isr(133); isr(134); isr(135); isr(136); isr(137); isr(138); isr(139); isr(140); isr(141); isr(142); isr(143); isr(144); isr(145); isr(146); isr(147); isr(148); isr(149); isr(150); isr(151); isr(152); isr(153); isr(154); isr(155); isr(156); isr(157); isr(158); isr(159); isr(160); isr(161); isr(162); isr(163); isr(164); isr(165); isr(166); isr(167); isr(168); isr(169); isr(170); isr(171); isr(172); isr(173); isr(174); isr(175); isr(176); isr(177); isr(178); isr(179); isr(180); isr(181); isr(182); isr(183); isr(184); isr(185); isr(186); isr(187); isr(188); isr(189); isr(190); isr(191); isr(192); isr(193); isr(194); isr(195); isr(196); isr(197); isr(198); isr(199); isr(200); isr(201); isr(202); isr(203); isr(204); isr(205); isr(206); isr(207); isr(208); isr(209); isr(210); isr(211); isr(212); isr(213); isr(214); isr(215); isr(216); isr(217); isr(218); isr(219); isr(220); isr(221); isr(222); isr(223); isr(224); isr(225); isr(226); isr(227); isr(228); isr(229); isr(230); isr(231); isr(232); isr(233); isr(234); isr(235); isr(236); isr(237); isr(238); isr(239); isr(240); isr(241); isr(242); isr(243); isr(244); isr(245); isr(246); isr(247); isr(248); isr(249); isr(250); isr(251); isr(252); isr(253); isr(254); isr(255); #define i(v) [v] = (void (*)(void))rx_##v##_isr void * const __interrupt_vector[256] = { i(0), i(1), i(2), i(3), i(4), i(5), i(6), i(7), i(8), i(9), i(10), i(11), i(12), i(13), i(14), i(15), i(16), i(17), i(18), i(19), i(20), i(21), i(22), i(23), i(24), i(25), i(26), i(27), i(28), i(29), i(30), i(31), i(32), i(33), i(34), i(35), i(36), i(37), i(38), i(39), i(40), i(41), i(42), i(43), i(44), i(45), i(46), i(47), i(48), i(49), i(50), i(51), i(52), i(53), i(54), i(55), i(56), i(57), i(58), i(59), i(60), i(61), i(62), i(63), i(64), i(65), i(66), i(67), i(68), i(69), i(70), i(71), i(72), i(73), i(74), i(75), i(76), i(77), i(78), i(79), i(80), i(81), i(82), i(83), i(84), i(85), i(86), i(87), i(88), i(89), i(90), i(91), i(92), i(93), i(94), i(95), i(96), i(97), i(98), i(99), i(100), i(101), i(102), i(103), i(104), i(105), i(106), i(107), i(108), i(109), i(110), i(111), i(112), i(113), i(114), i(115), i(116), i(117), i(118), i(119), i(120), i(121), i(122), i(123), i(124), i(125), i(126), i(127), i(128), i(129), i(130), i(131), i(132), i(133), i(134), i(135), i(136), i(137), i(138), i(139), i(140), i(141), i(142), i(143), i(144), i(145), i(146), i(147), i(148), i(149), i(150), i(151), i(152), i(153), i(154), i(155), i(156), i(157), i(158), i(159), i(160), i(161), i(162), i(163), i(164), i(165), i(166), i(167), i(168), i(169), i(170), i(171), i(172), i(173), i(174), i(175), i(176), i(177), i(178), i(179), i(180), i(181), i(182), i(183), i(184), i(185), i(186), i(187), i(188), i(189), i(190), i(191), i(192), i(193), i(194), i(195), i(196), i(197), i(198), i(199), i(200), i(201), i(202), i(203), i(204), i(205), i(206), i(207), i(208), i(209), i(210), i(211), i(212), i(213), i(214), i(215), i(216), i(217), i(218), i(219), i(220), i(221), i(222), i(223), i(224), i(225), i(226), i(227), i(228), i(229), i(230), i(231), i(232), i(233), i(234), i(235), i(236), i(237), i(238), i(239), i(240), i(241), i(242), i(243), i(244), i(245), i(246), i(247), i(248), i(249), i(250), i(251), i(252), i(253), i(254), i(255), }; picolibc-1.8.11/libc/machine/rx/memchr.S000066400000000000000000000012671513574234600177530ustar00rootroot00000000000000/* Copyright (c) 2009 Nick Clifton */ #include #ifdef __RX_ALLOW_STRING_INSNS__ .file "memchr.S" .section .text.memchr .global _memchr .type _memchr,@function _memchr: ;; R1: string pointer ;; R2: byte sought ;; R3: max number to scan and #255, r2 cmp #0, r3 ; If r3 is 0 suntil.b will do nothing and not set any flags... stz #1, r1 ; ...so store 1 into r1. It will be decremented by the SUB later. suntil.b ; Search until *r1 == r2 or r3 bytes have been examined. stnz #1, r1 ; If no match was found return NULL. sub #1, r1 ; suntil.b leaves r1 pointing at the address *after* the match. rts .size _memchr, . - _memchr #endif picolibc-1.8.11/libc/machine/rx/memchr.c000066400000000000000000000001411513574234600177610ustar00rootroot00000000000000#include #ifndef __RX_ALLOW_STRING_INSNS__ #include "../../string/memchr.c" #endif picolibc-1.8.11/libc/machine/rx/memcpy.S000066400000000000000000000005731513574234600177710ustar00rootroot00000000000000/* Copyright (c) 2009 Nick Clifton */ #include #ifdef __RX_ALLOW_STRING_INSNS__ .file "memcpy.S" .section .text.memcpy .global _memcpy .type _memcpy,@function _memcpy: mov r1, r4 ; Save a copy of DEST smovf ; Copy R2 (source) to R1 (dest). Stop after R3 bytes. mov r4, r1 ; Return DEST rts .size _memcpy, . - _memcpy #endif picolibc-1.8.11/libc/machine/rx/memcpy.c000066400000000000000000000001411513574234600200000ustar00rootroot00000000000000#include #ifndef __RX_ALLOW_STRING_INSNS__ #include "../../string/memcpy.c" #endif picolibc-1.8.11/libc/machine/rx/memmove.S000066400000000000000000000013441513574234600201410ustar00rootroot00000000000000/* Copyright (c) 2009 Nick Clifton */ #include #ifdef __RX_ALLOW_STRING_INSNS__ .file "memmove.S" .section .text.memmove .global _memmove .type _memmove,@function _memmove: ;; R1: DEST ;; R2: SRC ;; R3: COUNT mov r1, r4 ; Save a copy of DEST cmp r1, r2 blt 2f ; If SRC (r2) is less than DEST (r1) then copy backwards smovf 1: mov r4, r1 ; Return DEST rts 2: add r3, r1 ; The SMOVB instructions requires the DEST in r1 and the add r3, r2 ; SRC in r2 but it needs them to point the last bytes of sub #1, r2 ; the regions involved not the first bytes, hence these sub #1, r1 ; additions and subtractions. smovb bra 1b .size _memmove, . - _memmove #endif /* SMOVF allowed. */ picolibc-1.8.11/libc/machine/rx/memmove.c000066400000000000000000000001421513574234600201540ustar00rootroot00000000000000#include #ifndef __RX_ALLOW_STRING_INSNS__ #include "../../string/memmove.c" #endif picolibc-1.8.11/libc/machine/rx/mempcpy.S000066400000000000000000000004071513574234600201450ustar00rootroot00000000000000/* Copyright (c) 2009 Nick Clifton */ #include #ifdef __RX_ALLOW_STRING_INSNS__ .file "mempcpy.S" .section .text.mempcpy .global _mempcpy .type _mempcpy,@function _mempcpy: smovf rts .size _mempcpy, . - _mempcpy #endif picolibc-1.8.11/libc/machine/rx/mempcpy.c000066400000000000000000000001421513574234600201610ustar00rootroot00000000000000#include #ifndef __RX_ALLOW_STRING_INSNS__ #include "../../string/mempcpy.c" #endif picolibc-1.8.11/libc/machine/rx/memset.S000066400000000000000000000004321513574234600177630ustar00rootroot00000000000000/* Copyright (c) 2009 Nick Clifton */ #include #ifdef __RX_ALLOW_STRING_INSNS__ .file "memset.S" .section .text.memset .global _memset .type _memset,@function _memset: mov r1, r4 sstr.b mov r4, r1 rts .size _memset, . - _memset #endif picolibc-1.8.11/libc/machine/rx/memset.c000066400000000000000000000001411513574234600200000ustar00rootroot00000000000000#include #ifndef __RX_ALLOW_STRING_INSNS__ #include "../../string/memset.c" #endif picolibc-1.8.11/libc/machine/rx/meson.build000066400000000000000000000044231513574234600205130ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2025 Renesas Electronics Corporation # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'memchr.S', 'memcpy.S', 'memmove.S', 'mempcpy.S', 'memset.S', 'setjmp.S', 'strcat.S', 'strcmp.S', 'strcpy.S', 'strlen.S', 'strncat.S', 'strncmp.S', 'strncpy.S', 'interrupt.c', 'memchr.c', 'memcpy.c', 'memmove.c', 'mempcpy.c', 'memset.c', 'strcat.c', 'strcmp.c', 'strcpy.c', 'strlen.c', 'strncat.c', 'strncmp.c', 'strncpy.c', ] foreach params : targets target = params['name'] target_dir = params['dir'] target_c_args = params['c_args'] set_variable('lib_machine' + target, static_library('machine' + target, srcs_machine, pic: false, include_directories: inc, c_args: target_c_args + c_args + arg_fnobuiltin + arg_fnolto)) endforeach picolibc-1.8.11/libc/machine/rx/setjmp.S000066400000000000000000000040121513574234600177710ustar00rootroot00000000000000/* Copyright (c) 2009 Nick Clifton */ #include # setjmp/longjmp for Renesas RX. # # The jmpbuf looks like this: # # Register jmpbuf offset # R0 0x0 # R1 0x4 # R2 0x8 # R3 0xc # R4 0x10 # R5 0x14 # R6 0x18 # R7 0x1c # R8 0x20 # R9 0x24 # R10 0x28 # R11 0x2c # R12 0x30 # R13 0x34 # R14 0x38 # R15 0x3c # PC 0x40 # # R1 contains the pointer to jmpbuf: # # int R1 = setjmp (jmp_buf R1) # void longjmp (jmp_buf R1, int R2) # # The ABI allows for R1-R5 to be clobbered by functions. We must be # careful to always leave the stack in a usable state in case an # interrupt happens. .section .text.setjmp .global _setjmp .type _setjmp, @function _setjmp: mov.l r0, [r1] ; save all the general registers mov.l r1, 0x4[r1] ; longjmp won't use this, but someone else might. mov.l r2, 0x8[r1] mov.l r3, 0xc[r1] mov.l r4, 0x10[r1] mov.l r5, 0x14[r1] mov.l r6, 0x18[r1] mov.l r7, 0x1c[r1] mov.l r8, 0x20[r1] mov.l r9, 0x24[r1] mov.l r10, 0x28[r1] mov.l r11, 0x2c[r1] mov.l r12, 0x30[r1] mov.l r13, 0x34[r1] mov.l r14, 0x38[r1] mov.l r15, 0x3c[r1] mov.l [r0], r2 ; get return address off the stack mov.l r2, 0x40[r1] ; PC mov #0, r1 ; Return 0. rts .Lend1: .size _setjmp, .Lend1 - _setjmp .section .text.longjmp .global _longjmp .type _longjmp, @function _longjmp: tst r2, r2 ; Set the Z flag if r2 is 0. stz #1, r2 ; If the Z flag was set put 1 into the return register. mov r2, 4[r1] ; Put r2 (our return value) into the setjmp buffer as r1. mov.l [r1], r0 ; Restore the stack - there's a slot for PC mov.l 0x40[r1], r2 ; Get the saved PC mov.l r2, [r0] ; Overwrite the old return address mov.l 0x3c[r1], r15 mov.l 0x38[r1], r14 mov.l 0x34[r1], r13 mov.l 0x30[r1], r12 mov.l 0x2c[r1], r11 mov.l 0x28[r1], r10 mov.l 0x24[r1], r9 mov.l 0x20[r1], r8 mov.l 0x1c[r1], r7 mov.l 0x18[r1], r6 mov.l 0x14[r1], r5 mov.l 0x10[r1], r4 mov.l 0xc[r1], r3 mov.l 0x8[r1], r2 mov.l 0x4[r1], r1 ; This sets up the new return value rts .Lend2: .size _longjmp, .Lend2 - _longjmp picolibc-1.8.11/libc/machine/rx/strcat.S000066400000000000000000000014741513574234600200000ustar00rootroot00000000000000/* Copyright (c) 2009 Nick Clifton */ #include #ifdef __RX_ALLOW_STRING_INSNS__ .file "strcat.S" .section .text.strcat .global _strcat .type _strcat,@function _strcat: ;; On entry: r1 => Destination ;; r2 => Source mov r1, r4 ; Save a copy of the dest pointer. mov r2, r5 ; Save a copy of the source pointer. mov #0, r2 ; Search for the NUL byte. mov #-1, r3 ; Limit on the number of bytes examined. suntil.b ; Find the end of the destination string. sub #1, r1 ; suntil.b leaves r1 pointing to the byte beyond the match. mov #-1, r3 ; Set a limit on the number of bytes copied. mov r5, r2 ; Restore the source pointer. smovu ; Copy source to destination mov r4, r1 ; Return the original dest pointer. rts .size _strcat, . - _strcat #endif picolibc-1.8.11/libc/machine/rx/strcat.c000066400000000000000000000001411513574234600200060ustar00rootroot00000000000000#include #ifndef __RX_ALLOW_STRING_INSNS__ #include "../../string/strcat.c" #endif picolibc-1.8.11/libc/machine/rx/strcmp.S000066400000000000000000000010411513574234600177760ustar00rootroot00000000000000/* Copyright (c) 2009 Nick Clifton */ #include #ifdef __RX_ALLOW_STRING_INSNS__ .file "strcmp.S" .section .text.strcmp .global _strcmp .type _strcmp,@function _strcmp: mov #-1, r3 ; Strictly speaking this is incorrect, but I doubt if anyone will ever know. scmpu ; Perform the string comparison bnc 1f ; If Carry is not set skip over scne.L r1 ; Set result based on Z flag rts ; 1: ; mov #-1,r1 ; Carry not set, result should be negative rts ; .size _strcmp, . - _strcmp #endif picolibc-1.8.11/libc/machine/rx/strcmp.c000066400000000000000000000001411513574234600200160ustar00rootroot00000000000000#include #ifndef __RX_ALLOW_STRING_INSNS__ #include "../../string/strcmp.c" #endif picolibc-1.8.11/libc/machine/rx/strcpy.S000066400000000000000000000006171513574234600200220ustar00rootroot00000000000000/* Copyright (c) 2009 Nick Clifton */ #include #ifdef __RX_ALLOW_STRING_INSNS__ .file "strcpy.S" .section .text.strcpy .global _strcpy .type _strcpy,@function _strcpy: ;; R1: dest ;; R2: source mov r1, r4 mov #-1, r3 ; Strictly speaking this is incorrect, but I doubt if anyone will ever know. smovu mov r4, r1 rts .size _strcpy, . - _strcpy #endif picolibc-1.8.11/libc/machine/rx/strcpy.c000066400000000000000000000001411513574234600200320ustar00rootroot00000000000000#include #ifndef __RX_ALLOW_STRING_INSNS__ #include "../../string/strcpy.c" #endif picolibc-1.8.11/libc/machine/rx/strlen.S000066400000000000000000000012321513574234600177770ustar00rootroot00000000000000/* Copyright (c) 2009 Nick Clifton */ #include #ifdef __RX_ALLOW_STRING_INSNS__ .file "strlen.S" .section .text.strlen .global _strlen .type _strlen,@function _strlen: add #0, r1, r4 ; Save a copy of the string start address and set the condition flags. beq null_string ; Test for a NULL pointer. mov #-1, r3 ; Set a limit on the number of bytes examined. mov #0, r2 ; Stop searching when we find a NUL byte. suntil.b ; Search until *r1 == r2 sub #1, r1 ; suntil.b leaves r1 pointing to the byte beyond the match. null_string: sub r4, r1 ; Compute the length. rts .size _strlen, . - _strlen #endif picolibc-1.8.11/libc/machine/rx/strlen.c000066400000000000000000000001411513574234600200150ustar00rootroot00000000000000#include #ifndef __RX_ALLOW_STRING_INSNS__ #include "../../string/strlen.c" #endif picolibc-1.8.11/libc/machine/rx/strncat.S000066400000000000000000000027061513574234600201550ustar00rootroot00000000000000/* Copyright (c) 2009 Nick Clifton */ #include #ifdef __RX_ALLOW_STRING_INSNS__ .file "strncat.S" .section .text.strncat .global _strncat .type _strncat,@function _strncat: ;; On entry: r1 => Destination ;; r2 => Source ;; r3 => Max number of bytes to copy mov r1, r4 ; Save a copy of the dest pointer. mov r2, r5 ; Save a copy of the source pointer. mov r3, r14 ; Save a copy of the byte count. mov #0, r2 ; Search for the NUL byte. mov #-1, r3 ; Search until we run out of memory. suntil.b ; Find the end of the destination string. sub #1, r1 ; suntil.b leaves r1 pointing to the byte beyond the NUL. mov r14, r3 ; Restore the limit on the number of bytes copied. mov r5, r2 ; Restore the source pointer. mov r1, r5 ; Save a copy of the dest pointer. smovu ; Copy source to destination. add #0, r14, r3 ; Restore the number of bytes to copy (again), but this time set the Z flag as well. beq 1f ; If we copied 0 bytes then we already know that the dest string is NUL terminated, so we do not have to do anything. mov #0, r2 ; Otherwise we must check to see if a NUL byte mov r5, r1 ; was included in the bytes that were copied. suntil.b beq 1f ; Z flag is set if a match was found. add r14, r5 ; Point at byte after end of copied bytes. mov.b #0, [r5] ; Store a NUL there. 1: mov r4, r1 ; Return the original dest pointer. rts .size _strncat, . - _strncat #endif picolibc-1.8.11/libc/machine/rx/strncat.c000066400000000000000000000001421513574234600201650ustar00rootroot00000000000000#include #ifndef __RX_ALLOW_STRING_INSNS__ #include "../../string/strncat.c" #endif picolibc-1.8.11/libc/machine/rx/strncmp.S000066400000000000000000000011011513574234600201510ustar00rootroot00000000000000/* Copyright (c) 2009 Nick Clifton */ #include #ifdef __RX_ALLOW_STRING_INSNS__ .file "strncmp.S" .section .text.strncmp .global _strncmp .type _strncmp,@function _strncmp: ;; R1: string1 ;; R2: string2 ;; R3: max number of bytes to compare setpsw z ; Set flags in case len is 0 setpsw c scmpu ; Perform the string comparison bnc 1f ; If Carry is not set skip over scne.L r1 ; Set result based on Z flag rts ; 1: ; mov #-1,r1 ; Carry not set, result should be negative rts ; .size _strncmp, . - _strncmp #endif picolibc-1.8.11/libc/machine/rx/strncmp.c000066400000000000000000000001421513574234600201750ustar00rootroot00000000000000#include #ifndef __RX_ALLOW_STRING_INSNS__ #include "../../string/strncmp.c" #endif picolibc-1.8.11/libc/machine/rx/strncpy.S000066400000000000000000000013261513574234600201760ustar00rootroot00000000000000/* Copyright (c) 2009 Nick Clifton */ #include #ifdef __RX_ALLOW_STRING_INSNS__ .file "strncpy.S" .section .text.strncpy .global _strncpy .type _strncpy,@function _strncpy: mov r1, r4 ; Save a copy of the dest pointer. mov r3, r5 ; Save a copy of the byte count smovu ; Copy the bytes cmp #0, r3 ; If we have copied the number of bytes requested beq 1f ; then skip the next bit: add r4, r5, r1 ; Point to the last byte that we are supposed to write. sub r3, r1 ; Subtract the number of bytes left to be written. mov #0, r2 ; Fill the remaining bytes with NULs, sstr.b 1: mov r4, r1 ; Return the destination pointer rts .size _strncpy, . - _strncpy #endif picolibc-1.8.11/libc/machine/rx/strncpy.c000066400000000000000000000001421513574234600202110ustar00rootroot00000000000000#include #ifndef __RX_ALLOW_STRING_INSNS__ #include "../../string/strncpy.c" #endif picolibc-1.8.11/libc/machine/sh/000077500000000000000000000000001513574234600163275ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/sh/CMakeLists.txt000066400000000000000000000033241513574234600210710ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2024 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # add_subdirectory(machine) picolibc_sources_flags("-fno-builtin" memcpy.S memset.S setjmp.S strcmp.S strcpy.S strlen.S strncpy.S strncpy.c tls.c ) picolibc-1.8.11/libc/machine/sh/asm.h000066400000000000000000000033451513574234600172650ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifdef __STDC__ # define _C_LABEL(x) _ ## x #else # define _C_LABEL(x) _/**/x #endif #define _ASM_LABEL(x) x #if __SH5__ # if __SH5__ == 32 && __SHMEDIA__ # define TEXT .section .text..SHmedia32, "ax" # else # define TEXT .text # endif # define _ENTRY(name) \ TEXT; .balign 8; .globl name; name: #else #define _ENTRY(name) \ .text; .align 2; .globl name; name: #endif /* __SH5__ */ #define ENTRY(name) \ _ENTRY(_C_LABEL(name)) #if (defined (__sh2__) || defined (__SH2E__) || defined (__sh3__) || defined (__SH3E__) \ || defined (__SH4_SINGLE__) || defined (__SH4__)) \ || defined (__SH4_SINGLE_ONLY__) || defined (__SH5__) || defined (__SH2A__) #define DELAYED_BRANCHES #define SL(branch, dest, in_slot, in_slot_arg2) \ branch##.s dest; in_slot, in_slot_arg2 #else #define SL(branch, dest, in_slot, in_slot_arg2) \ in_slot, in_slot_arg2; branch dest #endif #ifdef __LITTLE_ENDIAN__ #define SHHI shlld #define SHLO shlrd #else #define SHHI shlrd #define SHLO shlld #endif picolibc-1.8.11/libc/machine/sh/machine/000077500000000000000000000000001513574234600177335ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/sh/machine/CMakeLists.txt000066400000000000000000000031361513574234600224760ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2024 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_headers(machine fenv.h fenv-fp.h ) picolibc-1.8.11/libc/machine/sh/machine/fenv-fp.h000066400000000000000000000110111513574234600214370ustar00rootroot00000000000000/*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2004-2005 David Schultz * Copyright (c) 2013 Andrew Turner * 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$ */ #define _SH_FPU_MASK_SHIFT 5 #define _SH_FPU_ROUND_MASK 3 #define _sh_get_fpscr(fpscr) __asm__ volatile("sts fpscr,%0" : "=r"(fpscr)) #define _sh_set_fpscr(fpscr) __asm__ volatile("lds %0,fpscr" : : "r"(fpscr)) __declare_fenv_inline(int) feclearexcept(int excepts) { fexcept_t fpscr; _sh_get_fpscr(fpscr); fpscr &= ~excepts; _sh_set_fpscr(fpscr); return (0); } __declare_fenv_inline(int) fedisableexcept(int __mask) { fenv_t __old_fpsr, __new_fpsr; _sh_get_fpscr(__old_fpsr); __new_fpsr = __old_fpsr & ~((__mask & FE_ALL_EXCEPT) << _SH_FPU_MASK_SHIFT); _sh_set_fpscr(__new_fpsr); return ((__old_fpsr >> _SH_FPU_MASK_SHIFT) & FE_ALL_EXCEPT); } __declare_fenv_inline(int) feenableexcept(int __mask) { fenv_t __old_fpsr, __new_fpsr, __check_fpsr; _sh_get_fpscr(__old_fpsr); __new_fpsr = __old_fpsr | ((__mask & FE_ALL_EXCEPT) << _SH_FPU_MASK_SHIFT); _sh_set_fpscr(__new_fpsr); _sh_get_fpscr(__check_fpsr); if (__check_fpsr != __new_fpsr) return -1; return ((__old_fpsr >> _SH_FPU_MASK_SHIFT) & FE_ALL_EXCEPT); } __declare_fenv_inline(int) fegetenv(fenv_t *envp) { fenv_t __env; _sh_get_fpscr(__env); *envp = __env; return (0); } __declare_fenv_inline(int) fegetexcept(void) { fenv_t fpscr; _sh_get_fpscr(fpscr); return (fpscr & FE_ALL_EXCEPT); } __declare_fenv_inline(int) fegetexceptflag(fexcept_t *flagp, int excepts) { fexcept_t fpscr; _sh_get_fpscr(fpscr); *flagp = fpscr & excepts; return (0); } __declare_fenv_inline(int) fegetround(void) { fenv_t fpscr; _sh_get_fpscr(fpscr); return (fpscr & _SH_FPU_ROUND_MASK); } __declare_fenv_inline(int) feholdexcept(fenv_t *envp) { fenv_t __env; _sh_get_fpscr(__env); *envp = __env; __env &= ~(FE_ALL_EXCEPT); _sh_set_fpscr(__env); return (0); } __declare_fenv_inline(int) fesetenv(const fenv_t *envp) { _sh_set_fpscr(*envp); return (0); } __declare_fenv_inline(int) fesetexceptflag(const fexcept_t *flagp, int excepts) { fexcept_t fpscr; _sh_get_fpscr(fpscr); fpscr &= ~excepts; fpscr |= *flagp & excepts; _sh_set_fpscr(fpscr); return (0); } __declare_fenv_inline(int) feraiseexcept(int excepts) { fexcept_t __ex = excepts; fesetexceptflag(&__ex, excepts); return (0); } __declare_fenv_inline(int) fesetexcept(int excepts) { return feraiseexcept(excepts); } __declare_fenv_inline(int) fesetround(int round) { fenv_t fpscr; if (round & ~_SH_FPU_ROUND_MASK) return (1); _sh_get_fpscr(fpscr); fpscr &= ~(_SH_FPU_ROUND_MASK); fpscr |= round; _sh_set_fpscr(fpscr); return (0); } __declare_fenv_inline(int) fetestexcept(int excepts) { fexcept_t fpscr; _sh_get_fpscr(fpscr); return (fpscr & excepts); } __declare_fenv_inline(int) feupdateenv(const fenv_t *envp) { fexcept_t fpscr; _sh_get_fpscr(fpscr); _sh_set_fpscr(*envp); feraiseexcept(fpscr & FE_ALL_EXCEPT); return (0); } #undef _SH_FPU_ROUND_MASK #undef _SH_FPU_MASK_SHIFT #undef _sh_get_fpscr #undef _sh_set_fpscr picolibc-1.8.11/libc/machine/sh/machine/fenv.h000066400000000000000000000051451513574234600210470ustar00rootroot00000000000000/*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2004-2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _MACHINE_FENV_H_ #define _MACHINE_FENV_H_ 1 #include _BEGIN_STD_C typedef int fenv_t; typedef int fexcept_t; #ifdef __SH_FPU_ANY__ #ifdef __SH2E__ #define __LONG_DOUBLE_NOROUND #define __LONG_DOUBLE_NOEXCEPT #if __SIZEOF_DOUBLE__ > 4 #define __DOUBLE_NOROUND #define __DOUBLE_NOEXCEPT #endif #endif #ifdef __SH4_SINGLE_ONLY__ #define __LONG_DOUBLE_NOROUND #define __LONG_DOUBLE_NOEXCEPT #endif /* Exception flags */ #define FE_INVALID 0x0040 #define FE_DIVBYZERO 0x0020 #if defined(__SH2E__) #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INVALID) #else #define FE_OVERFLOW 0x0010 #define FE_UNDERFLOW 0x0008 #define FE_INEXACT 0x0004 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) #endif /* Rounding modes */ #define FE_TONEAREST 0x0000 #define FE_TOWARDZERO 0x0001 #else #define FE_TONEAREST 0x0000 #endif #if !defined(__declare_fenv_inline) && defined(__declare_extern_inline) #define __declare_fenv_inline(type) __declare_extern_inline(type) #endif #ifdef __declare_fenv_inline #ifdef __SH_FPU_ANY__ #include #else #include #endif #endif _END_STD_C #endif /* _MACHINE_FENV_H_ */ picolibc-1.8.11/libc/machine/sh/machine/meson.build000066400000000000000000000033511513574234600220770ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2024 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_machine_headers_machine = [ 'fenv.h', 'fenv-fp.h', ] if really_install install_headers(inc_machine_headers_machine, install_dir: include_dir / 'machine') endif picolibc-1.8.11/libc/machine/sh/memcpy.S000066400000000000000000000171111513574234600177460ustar00rootroot00000000000000#include ! ! Fast SH memcpy ! ! by Toshiyasu Morita (tm@netcom.com) ! hacked by J"orn Rernnecke (joern.rennecke@superh.com) ("o for o-umlaut) /* SH5 code Copyright 2002 SuperH Ltd. */ ! ! Entry: ARG0: destination pointer ! ARG1: source pointer ! ARG3: byte count ! ! Exit: RESULT: destination pointer ! any other registers in the range r0-r7: trashed ! ! Notes: Usually one wants to do small reads and write a longword, but ! unfortunately it is difficult in some cases to concatanate bytes ! into a longword on the SH, so this does a longword read and small ! writes. ! ! This implementation makes two assumptions about how it is called: ! ! 1.: If the byte count is nonzero, the address of the last byte to be ! copied is unsigned greater than the address of the first byte to ! be copied. This could be easily swapped for a signed comparison, ! but the algorithm used needs some comparison. ! ! 2.: When there are two or three bytes in the last word of an 11-or-more ! bytes memory chunk to b copied, the rest of the word can be read ! without side effects. ! This could be easily changed by increasing the minumum size of ! a fast memcpy and the amount subtracted from r7 before L_2l_loop be 2, ! however, this would cost a few extra cyles on average. ! For SHmedia, the assumption is that any quadword can be read in its ! enirety if at least one byte is included in the copy. ! #include "asm.h" ENTRY(memcpy) #if __SHMEDIA__ #define LDUAQ(P,O,D0,D1) ldlo.q P,O,D0; ldhi.q P,O+7,D1 #define STUAQ(P,O,D0,D1) stlo.q P,O,D0; sthi.q P,O+7,D1 #define LDUAL(P,O,D0,D1) ldlo.l P,O,D0; ldhi.l P,O+3,D1 #define STUAL(P,O,D0,D1) stlo.l P,O,D0; sthi.l P,O+3,D1 ld.b r3,0,r63 pta/l Large,tr0 movi 25,r0 bgeu/u r4,r0,tr0 nsb r4,r0 shlli r0,5,r0 movi (L1-L0+63*32 + 1) & 0xffff,r1 sub r1, r0, r0 L0: ptrel r0,tr0 add r2,r4,r5 ptabs r18,tr1 add r3,r4,r6 blink tr0,r63 .balign 8 L1: /* 0 byte memcpy */ blink tr1,r63 L4_7: /* 4..7 byte memcpy cntd. */ stlo.l r2, 0, r0 or r6, r7, r6 sthi.l r5, -1, r6 stlo.l r5, -4, r6 blink tr1,r63 L2_3: /* 2 or 3 byte memcpy cntd. */ st.b r5,-1,r6 blink tr1,r63 /* 1 byte memcpy */ ld.b r3,0,r0 st.b r2,0,r0 blink tr1,r63 L8_15: /* 8..15 byte memcpy cntd. */ stlo.q r2, 0, r0 or r6, r7, r6 sthi.q r5, -1, r6 stlo.q r5, -8, r6 blink tr1,r63 /* 2 or 3 byte memcpy */ ld.b r3,0,r0 ld.b r2,0,r63 ld.b r3,1,r1 st.b r2,0,r0 pta/l L2_3,tr0 ld.b r6,-1,r6 st.b r2,1,r1 blink tr0, r63 /* 4 .. 7 byte memcpy */ LDUAL (r3, 0, r0, r1) pta L4_7, tr0 ldlo.l r6, -4, r7 or r0, r1, r0 sthi.l r2, 3, r0 ldhi.l r6, -1, r6 blink tr0, r63 /* 8 .. 15 byte memcpy */ LDUAQ (r3, 0, r0, r1) pta L8_15, tr0 ldlo.q r6, -8, r7 or r0, r1, r0 sthi.q r2, 7, r0 ldhi.q r6, -1, r6 blink tr0, r63 /* 16 .. 24 byte memcpy */ LDUAQ (r3, 0, r0, r1) LDUAQ (r3, 8, r8, r9) or r0, r1, r0 sthi.q r2, 7, r0 or r8, r9, r8 sthi.q r2, 15, r8 ldlo.q r6, -8, r7 ldhi.q r6, -1, r6 stlo.q r2, 8, r8 stlo.q r2, 0, r0 or r6, r7, r6 sthi.q r5, -1, r6 stlo.q r5, -8, r6 blink tr1,r63 Large: ld.b r2, 0, r63 pta/l Loop_ua, tr1 ori r3, -8, r7 sub r2, r7, r22 sub r3, r2, r6 add r2, r4, r5 ldlo.q r3, 0, r0 addi r5, -16, r5 movi 64+8, r27 // could subtract r7 from that. stlo.q r2, 0, r0 sthi.q r2, 7, r0 ldx.q r22, r6, r0 bgtu/l r27, r4, tr1 addi r5, -48, r27 pta/l Loop_line, tr0 addi r6, 64, r36 addi r6, -24, r19 addi r6, -16, r20 addi r6, -8, r21 Loop_line: ldx.q r22, r36, r63 alloco r22, 32 addi r22, 32, r22 ldx.q r22, r19, r23 sthi.q r22, -25, r0 ldx.q r22, r20, r24 ldx.q r22, r21, r25 stlo.q r22, -32, r0 ldx.q r22, r6, r0 sthi.q r22, -17, r23 sthi.q r22, -9, r24 sthi.q r22, -1, r25 stlo.q r22, -24, r23 stlo.q r22, -16, r24 stlo.q r22, -8, r25 bgeu r27, r22, tr0 Loop_ua: addi r22, 8, r22 sthi.q r22, -1, r0 stlo.q r22, -8, r0 ldx.q r22, r6, r0 bgtu/l r5, r22, tr1 add r3, r4, r7 ldlo.q r7, -8, r1 sthi.q r22, 7, r0 ldhi.q r7, -1, r7 ptabs r18,tr1 stlo.q r22, 0, r0 or r1, r7, r1 sthi.q r5, 15, r1 stlo.q r5, 8, r1 blink tr1, r63 #else /* ! SHMEDIA, i.e. SH1 .. SH4 / SHcompact */ #ifdef __SH5__ #define DST r2 #define SRC r3 #define COUNT r4 #define TMP0 r5 #define TMP1 r6 #define RESULT r2 #else #define DST r4 #define SRC r5 #define COUNT r6 #define TMP0 r2 #define TMP1 r3 #define RESULT r0 #endif #ifdef __LITTLE_ENDIAN__ ! Little endian version copies with increasing addresses. mov DST,TMP1 ! Save return value mov #11,r0 ! Check if small number of bytes cmp/hs r0,COUNT ! COUNT becomes src end address SL(bf, L_small, add SRC,COUNT) mov #1,r1 tst r1,SRC ! check if source even SL(bt, L_even, mov COUNT,r7) mov.b @SRC+,r0 ! no, make it even. mov.b r0,@DST add #1,DST L_even: tst r1,DST ! check if destination is even add #-3,r7 SL(bf, L_odddst, mov #2,r1) tst r1,DST ! check if destination is 4-byte aligned mov DST,r0 SL(bt, L_al4dst, sub SRC,r0) mov.w @SRC+,TMP0 mov.w TMP0,@DST ! add #2,DST DST is dead here. L_al4dst: tst r1,SRC bt L_al4both mov.w @SRC+,r1 swap.w r1,r1 add #-6,r0 add #-6,r7 ! r7 := src end address minus 9. .align 2 L_2l_loop: mov.l @SRC+,TMP0 ! Read & write two longwords per iteration xtrct TMP0,r1 mov.l r1,@(r0,SRC) cmp/hs r7,SRC mov.l @SRC+,r1 xtrct r1,TMP0 mov.l TMP0,@(r0,SRC) bf L_2l_loop add #-2,SRC bra L_cleanup add #5,r0 L_al4both: add #-4,r0 .align 2 L_al4both_loop: mov.l @SRC+,DST ! Read longword, write longword per iteration cmp/hs r7,SRC SL(bf, L_al4both_loop, mov.l DST,@(r0,SRC)) bra L_cleanup add #3,r0 L_odddst: tst r1,SRC SL(bt, L_al4src, add #-1,DST) mov.w @SRC+,r0 mov.b r0,@(1,DST) shlr8 r0 mov.b r0,@(2,DST) add #2,DST L_al4src: .align 2 L_odd_loop: mov.l @SRC+,r0 ! Read longword, write byte, word, byte per iteration cmp/hs r7,SRC mov.b r0,@(1,DST) shlr8 r0 mov.w r0,@(2,DST) shlr16 r0 mov.b r0,@(4,DST) SL(bf, L_odd_loop, add #4,DST) .align 2 ! avoid nop in more frequently executed code. L_cleanup2: mov DST,r0 sub SRC,r0 L_cleanup: cmp/eq COUNT,SRC bt L_ready .align 2 L_cleanup_loop: mov.b @SRC+,r1 cmp/eq COUNT,SRC mov.b r1,@(r0,SRC) bf L_cleanup_loop L_ready: rts mov TMP1,RESULT L_small: bra L_cleanup2 add #-1,DST #else /* ! __LITTLE_ENDIAN__ */ ! Big endian version copies with decreasing addresses. mov DST,r0 add COUNT,r0 sub DST,SRC mov #11,r1 cmp/hs r1,COUNT SL(bf, L_small, add #-1,SRC) mov SRC,TMP1 add r0,TMP1 shlr TMP1 SL(bt, L_even, mov DST,r7) mov.b @(r0,SRC),TMP0 add #-1,TMP1 mov.b TMP0,@-r0 L_even: tst #1,r0 add #-1,SRC SL(bf, L_odddst, add #8,r7) tst #2,r0 bt L_al4dst add #-1,TMP1 mov.w @(r0,SRC),r1 mov.w r1,@-r0 L_al4dst: shlr TMP1 bt L_al4both mov.w @(r0,SRC),r1 swap.w r1,r1 add #4,r7 add #-4,SRC .align 2 L_2l_loop: mov.l @(r0,SRC),TMP0 xtrct TMP0,r1 mov.l r1,@-r0 cmp/hs r7,r0 mov.l @(r0,SRC),r1 xtrct r1,TMP0 mov.l TMP0,@-r0 bt L_2l_loop bra L_cleanup add #5,SRC nop ! avoid nop in executed code. L_al4both: add #-2,SRC .align 2 L_al4both_loop: mov.l @(r0,SRC),r1 cmp/hs r7,r0 SL(bt, L_al4both_loop, mov.l r1,@-r0) bra L_cleanup add #3,SRC nop ! avoid nop in executed code. L_odddst: shlr TMP1 bt L_al4src mov.w @(r0,SRC),r1 mov.b r1,@-r0 shlr8 r1 mov.b r1,@-r0 L_al4src: add #-2,SRC .align 2 L_odd_loop: mov.l @(r0,SRC),TMP0 cmp/hs r7,r0 mov.b TMP0,@-r0 shlr8 TMP0 mov.w TMP0,@-r0 shlr16 TMP0 mov.b TMP0,@-r0 bt L_odd_loop add #3,SRC L_cleanup: L_small: cmp/eq DST,r0 bt L_ready add #1,DST .align 2 L_cleanup_loop: mov.b @(r0,SRC),TMP0 cmp/eq DST,r0 mov.b TMP0,@-r0 bf L_cleanup_loop L_ready: rts mov r0,RESULT #endif /* ! __LITTLE_ENDIAN__ */ #endif /* ! SHMEDIA */ picolibc-1.8.11/libc/machine/sh/memset.S000066400000000000000000000062221513574234600177470ustar00rootroot00000000000000#include ! ! Fast SH memset ! ! by Toshiyasu Morita (tm@netcom.com) ! ! SH5 code by J"orn Rennecke (joern.rennecke@superh.com) /* Copyright 2002 SuperH Ltd. */ ! #include "asm.h" ENTRY(memset) #if __SHMEDIA__ pta/l multiquad, tr0 ptabs r18, tr2 andi r2, -8, r25 add r2, r4, r5 addi r5, -1, r20 // calculate end address. andi r20, -8, r20 cmveq r4, r25, r20 bne/u r25, r20, tr0 // multiquad ! This sequence could clobber volatile objects that are in the same ! quadword as a very short char array. ! ldlo.q r2, 0, r7 ! shlli r4, 2, r4 ! movi -1, r8 ! SHHI r8, r4, r8 ! SHHI r8, r4, r8 ! mcmv r7, r8, r3 ! stlo.q r2, 0, r3 pta/l setlongs, tr0 movi 4, r8 bgeu/u r4, r8, tr0 pta/l endset, tr0 beqi/u r4, 0, tr0 st.b r2, 0, r3 beqi/u r4, 1, tr0 nop st.b r2, 1, r3 beqi/l r4, 2, tr0 st.b r2,2,r3 endset: blink tr2, r63 setlongs: mshflo.b r3, r3, r3 mperm.w r3, r63, r3 // Fill pattern now in every byte of r3 stlo.l r2, 0, r3 nop nop sthi.l r5, -1, r3 blink tr2, r63 multiquad: mshflo.b r3, r3, r3 mperm.w r3, r63, r3 // Fill pattern now in every byte of r3 pta/l lastquad, tr0 stlo.q r2, 0, r3 sub r20, r25, r24 movi 64, r9 beqi/u r24, 8, tr0 // lastquad pta/l loop, tr1 addi r20, -7*8, r8 // loop end address; This might overflow, so we need // to use a different test before we start the loop bgeu/u r24, r9, tr1// loop st.q r25, 8, r3 shlri r24, 4, r24 st.q r20, -8, r3 beqi/u r24, 1, tr0 // lastquad st.q r25, 16, r3 st.q r20, -16, r3 beqi/u r24, 2, tr0 // lastquad st.q r25, 24, r3 st.q r20, -24, r3 lastquad: sthi.q r5, -1, r3 blink tr2,r63 loop: alloco r25, 32 st.q r25, 8, r3 st.q r25, 16, r3 st.q r25, 24, r3 st.q r25, 32, r3 addi r25, 32, r25 bgeu/l r8, r25, tr1 // loop st.q r20, -40, r3 st.q r20, -32, r3 st.q r20, -24, r3 st.q r20, -16, r3 st.q r20, -8, r3 sthi.q r5, -1, r3 blink tr2,r63 #else /* ! SHMEDIA, i.e. SH1 .. SH4 / SHcompact */ ! Entry: r4: destination pointer ! r5: fill value ! r6: byte count ! ! Exit: r0-r3: trashed ! ! This assumes that the first four bytes of the address space (0..3) are ! reserved - usually by the linker script. Otherwise, we would had to check ! for the case of objects of the size 12..15 at address 0..3 . #ifdef __SH5__ #define DST r2 #define VAL r3 #define CNT r4 #define TMP r5 #else #define DST r4 #define VAL r5 #define CNT r6 #define TMP r2 #endif mov #12,r0 ! Check for small number of bytes cmp/gt CNT,r0 mov DST,r0 SL(bt, L_store_byte_loop_check0, add DST,CNT) tst #3,r0 ! Align destination SL(bt, L_dup_bytes, extu.b r5,r5) .balignw 4,0x0009 L_align_loop: mov.b VAL,@r0 add #1,r0 tst #3,r0 bf L_align_loop L_dup_bytes: swap.b VAL,TMP ! Duplicate bytes across longword or TMP,VAL swap.w VAL,TMP or TMP,VAL add #-16,CNT .balignw 4,0x0009 L_store_long_loop: mov.l VAL,@r0 ! Store double longs to memory cmp/hs CNT,r0 mov.l VAL,@(4,r0) SL(bf, L_store_long_loop, add #8,r0) add #16,CNT L_store_byte_loop_check0: cmp/eq CNT,r0 bt L_exit .balignw 4,0x0009 L_store_byte_loop: mov.b VAL,@r0 ! Store bytes to memory add #1,r0 cmp/eq CNT,r0 bf L_store_byte_loop L_exit: rts mov r4,r0 #endif /* ! SHMEDIA */ picolibc-1.8.11/libc/machine/sh/meson.build000066400000000000000000000033661513574234600205010ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2023 Adrian Siekierka # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'memcpy.S', 'memset.S', 'setjmp.S', 'strcmp.S', 'strcpy.S', 'strlen.S', 'strncpy.S', 'strncpy.c', 'tls.c', ] subdir('machine') src_machine = files(srcs_machine) picolibc-1.8.11/libc/machine/sh/setjmp.S000066400000000000000000000106021513574234600177540ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* We want to pretend we're in SHmedia mode, even when assembling for SHcompact. */ #include #if __SH5__ == 32 && ! __SHMEDIA__ # undef __SHMEDIA__ # define __SHMEDIA__ 1 #endif #if __SHMEDIA__ .mode SHmedia #endif #include "asm.h" ENTRY(setjmp) #if __SH5__ ptabs r18, tr0 gettr tr5, r5 gettr tr6, r6 gettr tr7, r7 st.q r2, 0*8, r18 st.q r2, 1*8, r10 st.q r2, 2*8, r11 st.q r2, 3*8, r12 st.q r2, 4*8, r13 st.q r2, 5*8, r14 st.q r2, 6*8, r15 st.q r2, 7*8, r28 st.q r2, 8*8, r29 st.q r2, 9*8, r30 st.q r2, 10*8, r31 st.q r2, 11*8, r32 st.q r2, 12*8, r33 st.q r2, 13*8, r34 st.q r2, 14*8, r35 st.q r2, 15*8, r44 st.q r2, 16*8, r45 st.q r2, 17*8, r46 st.q r2, 18*8, r47 st.q r2, 19*8, r48 st.q r2, 20*8, r49 st.q r2, 21*8, r50 st.q r2, 22*8, r51 st.q r2, 23*8, r52 st.q r2, 24*8, r53 st.q r2, 25*8, r54 st.q r2, 26*8, r55 st.q r2, 27*8, r56 st.q r2, 28*8, r57 st.q r2, 29*8, r58 st.q r2, 30*8, r59 st.q r2, 31*8, r5 st.q r2, 32*8, r6 st.q r2, 33*8, r7 #if ! __SH4_NOFPU__ fst.d r2, 34*8, dr12 fst.d r2, 35*8, dr14 fst.d r2, 36*8, dr36 fst.d r2, 37*8, dr38 fst.d r2, 38*8, dr40 fst.d r2, 39*8, dr42 fst.d r2, 40*8, dr44 fst.d r2, 41*8, dr46 fst.d r2, 42*8, dr48 fst.d r2, 43*8, dr50 fst.d r2, 44*8, dr52 fst.d r2, 45*8, dr54 fst.d r2, 46*8, dr56 fst.d r2, 47*8, dr58 fst.d r2, 48*8, dr60 fst.d r2, 49*8, dr62 #endif movi 0, r2 blink tr0, r63 #else #if defined (__SH2E__) || defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__) add #(13*4),r4 #else add #(9*4),r4 #endif sts.l pr,@-r4 #if defined (__SH2E__) || defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__) fmov.s fr15,@-r4 ! call saved floating point registers fmov.s fr14,@-r4 fmov.s fr13,@-r4 fmov.s fr12,@-r4 #endif mov.l r15,@-r4 ! call saved integer registers mov.l r14,@-r4 mov.l r13,@-r4 mov.l r12,@-r4 mov.l r11,@-r4 mov.l r10,@-r4 mov.l r9,@-r4 mov.l r8,@-r4 rts mov #0,r0 #endif /* __SH5__ */ ENTRY(longjmp) #if __SH5__ ld.q r2, 0*8, r18 ptabs r18, tr0 ld.q r2, 1*8, r10 ld.q r2, 2*8, r11 ld.q r2, 3*8, r12 ld.q r2, 4*8, r13 ld.q r2, 5*8, r14 ld.q r2, 6*8, r15 ld.q r2, 7*8, r28 ld.q r2, 8*8, r29 ld.q r2, 9*8, r30 ld.q r2, 10*8, r31 ld.q r2, 11*8, r32 ld.q r2, 12*8, r33 ld.q r2, 13*8, r34 ld.q r2, 14*8, r35 ld.q r2, 15*8, r44 ld.q r2, 16*8, r45 ld.q r2, 17*8, r46 ld.q r2, 18*8, r47 ld.q r2, 19*8, r48 ld.q r2, 20*8, r49 ld.q r2, 21*8, r50 ld.q r2, 22*8, r51 ld.q r2, 23*8, r52 ld.q r2, 24*8, r53 ld.q r2, 25*8, r54 ld.q r2, 26*8, r55 ld.q r2, 27*8, r56 ld.q r2, 28*8, r57 ld.q r2, 29*8, r58 ld.q r2, 30*8, r59 ld.q r2, 31*8, r5 ld.q r2, 32*8, r6 ld.q r2, 33*8, r7 ptabs r5, tr5 ptabs r6, tr6 ptabs r7, tr7 #if ! __SH4_NOFPU__ fld.d r2, 34*8, dr12 fld.d r2, 35*8, dr14 fld.d r2, 36*8, dr36 fld.d r2, 37*8, dr38 fld.d r2, 38*8, dr40 fld.d r2, 39*8, dr42 fld.d r2, 40*8, dr44 fld.d r2, 41*8, dr46 fld.d r2, 42*8, dr48 fld.d r2, 43*8, dr50 fld.d r2, 44*8, dr52 fld.d r2, 45*8, dr54 fld.d r2, 46*8, dr56 fld.d r2, 47*8, dr58 fld.d r2, 48*8, dr60 fld.d r2, 49*8, dr62 #endif movi 1, r2 cmvne r3, r3, r2 blink tr0, r63 #else mov.l @r4+,r8 mov.l @r4+,r9 mov.l @r4+,r10 mov.l @r4+,r11 mov.l @r4+,r12 mov.l @r4+,r13 mov.l @r4+,r14 mov.l @r4+,r15 #if defined (__SH2E__) || defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__) fmov.s @r4+,fr12 ! call saved floating point registers fmov.s @r4+,fr13 fmov.s @r4+,fr14 fmov.s @r4+,fr15 #endif lds.l @r4+,pr mov r5,r0 tst r0,r0 bf retr4 movt r0 retr4: rts nop #endif /* __SH5__ */ picolibc-1.8.11/libc/machine/sh/strcmp.S000066400000000000000000000100271513574234600177630ustar00rootroot00000000000000/* SH5 code Copyright 2002 SuperH Ltd. */ #include #include "asm.h" ENTRY(strcmp) #if __SHMEDIA__ ld.ub r2,0,r4 pt/l quickret0,tr0 ld.ub r3,0,r5 ptabs r18,tr2 beqi/u r4,0,tr0 ld.ub r2,1,r6 bne/u r4,r5,tr0 pt/l quickret1,tr1 ld.ub r3,1,r7 beqi/u r6,0,tr1 ld.ub r2,2,r4 bne/u r6,r7,tr1 ld.ub r3,2,r5 beqi/u r4,0,tr0 ld.ub r2,3,r6 bne/u r4,r5,tr0 ld.ub r3,3,r7 beqi/u r6,0,tr1 ld.ub r2,4,r4 bne/u r6,r7,tr1 ld.ub r3,4,r5 beqi/u r4,0,tr0 ld.ub r2,5,r6 bne/u r4,r5,tr0 ld.ub r3,5,r7 beqi/u r6,0,tr1 ld.ub r2,6,r4 bne/u r6,r7,tr1 ld.ub r3,6,r5 beqi/u r4,0,tr0 ld.ub r2,7,r6 bne/u r4,r5,tr0 ld.ub r3,7,r7 beqi/u r6,0,tr1 sub r3,r2,r3 bne/u r6,r7,tr1 andi r2,-8,r2 add r3,r2,r3 ldlo.q r3,8,r23 pt r23_zero,tr0 shlli r3,3,r22 sub r63,r22,r20 movi 0x101,r6 mperm.w r6,r63,r6 SHLO r6,r22,r7 msubs.ub r7,r23,r8 pt loop,tr1 bnei/u r8,0,tr0 // r23_zero pt found_zero,tr0 addi r3,15,r3 andi r3,-8,r3 sub r3,r2,r3 bne/l r7,r6,tr1 // loop /* The strings are aligned to each other. */ /* It is possible to have a loop with six cycles / iteration by re-ordering the exit conditions, but then it needs extra time and/or code to sort out the r4 != r5 case. */ pt al_loop,tr1 pt al_found_zero,tr0 al_loop: ld.q r2,8,r4 ldx.q r2,r3,r5 addi r2,8,r2 mcmpeq.b r63,r4,r8 pt cmp_quad,tr3 bnei/u r8,0,tr0 // al_found_zero beq/l r4,r5,tr1 // al_loop blink tr3,r63 // cmp_quad .balign 8 quickret0: sub r4,r5,r2 blink tr2,r63 quickret1: sub r6,r7,r2 blink tr2,r63 loop: ld.q r2,8,r4 ldx.q r2,r3,r19 addi r2,8,r2 msubs.ub r6,r4,r8 mcmpeq.b r63,r19,r9 SHHI r19,r20,r21 or r21,r23,r5 SHLO r19,r22,r23 bne/u r8,r9,tr0 // found_zero beq/l r4,r5,tr1 // loop cmp_quad: #ifdef __LITTLE_ENDIAN__ byterev r4,r4 byterev r5,r5 #endif cmpgtu r4,r5,r6 cmpgtu r5,r4,r7 sub r6,r7,r2 blink tr2,r63 found_zero: pt zero_now,tr0 pt cmp_quad,tr1 SHHI r9,r20,r7 bne/u r8,r7,tr0 // zero_now bne/u r4,r5,tr1 // cmp_quad SHLO r9,r22,r8 r23_zero: ld.q r2,8,r4 add r23,r63,r5 zero_now: al_found_zero: /* We konw that one of the values has at lest one zero, and r8 holds an 0x01 or 0xff mask for every zero found in one of the operands. If both operands have the first zero in the same place, this mask allows us to truncate the comparison to the valid bytes in the strings. If the first zero is in different places, it doesn't matter if some invalid bytes are included, since the comparison of the zero with the non-zero will determine the outcome. */ #ifdef __LITTLE_ENDIAN__ shlli r8,8,r8 addi r8,-1,r9 andc r9,r8,r8 and r8,r4,r4 and r8,r5,r5 #else shlri r8,1,r8 nsb r8,r8 addi r8,8,r8 andi r8,56,r8 sub r63,r8,r8 shlrd r4,r8,r4 shlrd r5,r8,r5 #endif #ifdef __LITTLE_ENDIAN__ byterev r4,r4 byterev r5,r5 #endif cmpgtu r4,r5,r6 cmpgtu r5,r4,r7 sub r6,r7,r2 blink tr2,r63 #else /* ! __SHMEDIA__, i.e. SH 1..4 / SHcompact */ #ifdef __SH5__ #define STR1 r2 #define STR2 r3 #define RESULT r2 #define TMP r4 #else ! Entry: r4: string1 ! r5: string2 ! Exit: r0: result ! r1-r2,r4-r5: clobbered #define STR1 r4 #define STR2 r5 #define RESULT r0 #define TMP r2 #endif /* __SH5__ */ mov STR1,r0 or STR2,r0 tst #3,r0 bf L_setup_char_loop mov #0,r0 #ifdef DELAYED_BRANCHES mov.l @STR1+,r1 .align 2 Longword_loop: mov.l @STR2+,TMP cmp/str r0,r1 bt Longword_loop_end cmp/eq r1,TMP bt.s Longword_loop mov.l @STR1+,r1 add #-4, STR1 Longword_loop_end: add #-4, STR1 add #-4, STR2 L_setup_char_loop: mov.b @STR1+,r0 .align 2 L_char_loop: mov.b @STR2+,r1 tst r0,r0 bt L_return cmp/eq r0,r1 bt.s L_char_loop mov.b @STR1+,r0 add #-2,STR1 mov.b @STR1,r0 #else /* ! DELAYED_BRANCHES */ .align 2 Longword_loop: mov.l @r4+,r1 mov.l @r5+,r2 cmp/str r0,r1 bt Longword_loop_end cmp/eq r1,r2 bt Longword_loop Longword_loop_end: add #-4, r4 add #-4, r5 .align 2 L_setup_char_loop: L_char_loop: mov.b @r4+,r0 mov.b @r5+,r1 tst r0,r0 bt L_return cmp/eq r0,r1 bt L_char_loop #endif L_return: extu.b r0,RESULT extu.b r1,r1 rts sub r1,RESULT #endif /* ! __SHMEDIA__ */ picolibc-1.8.11/libc/machine/sh/strcpy.S000066400000000000000000000047671513574234600200150ustar00rootroot00000000000000#include ! Entry: arg0: destination ! arg1: source ! Exit: result: destination ! /* SH5 code Copyright 2002 SuperH Ltd. */ #include "asm.h" ENTRY(strcpy) #if __SHMEDIA__ pta/l shortstring,tr1 ldlo.q r3,0,r4 ptabs r18,tr4 shlli r3,3,r7 addi r2, 8, r0 mcmpeq.b r4,r63,r6 SHHI r6,r7,r6 bnei/u r6,0,tr1 // shortstring pta/l no_lddst, tr2 ori r3,-8,r23 sub r2, r23, r0 sub r3, r2, r21 addi r21, 8, r20 ldx.q r0, r21, r5 pta/l loop, tr0 ori r2,-8,r22 mcmpeq.b r5, r63, r6 bgt/u r22, r23, tr2 // no_lddst // r22 < r23 : Need to do a load from the destination. // r22 == r23 : Doesn't actually need to load from destination, // but still can be handled here. ldlo.q r2, 0, r9 movi -1, r8 SHLO r8, r7, r8 mcmv r4, r8, r9 stlo.q r2, 0, r9 beqi/l r6, 0, tr0 // loop add r5, r63, r4 addi r0, 8, r0 blink tr1, r63 // shortstring no_lddst: // r22 > r23: note that for r22 == r23 the sthi.q would clobber // bytes before the destination region. stlo.q r2, 0, r4 SHHI r4, r7, r4 sthi.q r0, -1, r4 beqi/l r6, 0, tr0 // loop add r5, r63, r4 addi r0, 8, r0 shortstring: #ifndef __LITTLE_ENDIAN__ pta/l shortstring2,tr1 byterev r4,r4 #endif shortstring2: st.b r0,-8,r4 andi r4,0xff,r5 shlri r4,8,r4 addi r0,1,r0 bnei/l r5,0,tr1 blink tr4,r63 // return .balign 8 loop: stlo.q r0, 0, r5 ldx.q r0, r20, r4 addi r0, 16, r0 sthi.q r0, -9, r5 mcmpeq.b r4, r63, r6 bnei/u r6, 0, tr1 // shortstring ldx.q r0, r21, r5 stlo.q r0, -8, r4 sthi.q r0, -1, r4 mcmpeq.b r5, r63, r6 beqi/l r6, 0, tr0 // loop add r5, r63, r4 addi r0, 8, r0 blink tr1, r63 // shortstring #else /* ! __SHMEDIA__, i.e. SH 1..4 / SHcompact */ #ifdef __SH5__ #define DST r2 #define SRC r3 #define TMP r4 #define RESULT R2 ! r0,r1,r3,r4: clobbered #else #define DST r4 #define SRC r5 #define TMP r2 #define RESULT r0 ! r1-r2,r5: clobbered #endif mov DST,r0 or SRC,r0 tst #3,r0 SL(bf, L_setup_char_loop, mov DST,r0) mov.l @SRC+,r1 mov #0,TMP cmp/str TMP,r1 SL(bt, Longword_loop_end, sub SRC,r0) .align 2 Longword_loop: mov.l r1,@(r0,SRC) mov.l @SRC+,r1 cmp/str TMP,r1 bt Longword_loop_end mov.l r1,@(r0,SRC) mov.l @SRC+,r1 cmp/str TMP,r1 bf Longword_loop Longword_loop_end: add #-4,SRC add #3,r0 .align 2 L_char_loop: mov.b @SRC+,r1 L_char_loop_start: tst r1,r1 SL(bf, L_char_loop, mov.b r1,@(r0,SRC)) rts mov DST,RESULT L_setup_char_loop: mov.b @SRC+,r1 bra L_char_loop_start sub SRC,r0 #endif /* ! __SHMEDIA__ */ picolibc-1.8.11/libc/machine/sh/strlen.S000066400000000000000000000025651513574234600177720ustar00rootroot00000000000000#include ! Entry: arg0: string start address ! Exit: result: length ! /* Copyright 2002 SuperH Ltd. */ #include "asm.h" ENTRY(strlen) #if __SHMEDIA__ ldlo.q r2,0,r3 ptabs/l r18,tr0 pta/l loop,tr1 andi r2,-8,r0 shlli r2,3,r1 mcmpeq.b r3,r63,r3 SHHI r3,r1,r4 beqi/u r4,0,tr1 // loop #ifdef __LITTLE_ENDIAN__ movi -1,r2 addi r3,-1,r4 msad.ubq r3,r4,r2 #else shlri r3,1,r3 nsb r3,r3 shlri r3,3,r2 #endif blink tr0,r63 loop: ldlo.q r0,8,r3 addi r0,8,r0 ldlo.q r0,8,r63 mcmpeq.b r3,r63,r3 beqi/l r3,0,tr1 // loop sub r0,r2,r2 #ifdef __LITTLE_ENDIAN__ addi r3,-1,r4 addi r2,-1,r2 msad.ubq r3,r4,r2 #else shlri r3,1,r3 nsb r3,r3 shlri r3,3,r3 add r2,r3,r2 #endif blink tr0,r63 #else /* ! __SHMEDIA__, i.e. SH 1..4 / SHcompact */ #ifdef __SH5__ #define STR_INIT r2 #define STR_ORIG r0 #define STR_COPY STR_ORIG #define MASK r1 #define TMP r3 #define RESULT r2 ! r0,r1,r3: clobbered #else #define STR_INIT r4 #define STR_ORIG STR_INIT #define STR_COPY STR #define MASK r1 #define TMP r3 #define RESULT r0 ! r1,r3: clobbered #endif #define STR RESULT mov #3,MASK and STR_INIT,MASK tst MASK,MASK SL(bf, L_char_loop, mov STR_INIT, STR_COPY) L_word_loop: mov.l @STR+,TMP cmp/str MASK,TMP bf L_word_loop add #-4,STR L_char_loop: mov.b @STR+,TMP tst TMP,TMP bf L_char_loop add #-1,STR rts sub STR_ORIG,STR #endif /* ! __SHMEDIA__ */ picolibc-1.8.11/libc/machine/sh/strncpy.S000066400000000000000000000115501513574234600201570ustar00rootroot00000000000000/* Copyright 2003 SuperH Ltd. */ #include #include "asm.h" #ifdef __SH5__ #if __SHMEDIA__ #ifdef __LITTLE_ENDIAN__ #define ZPAD_MASK(src, dst) addi src, -1, dst #else #define ZPAD_MASK(src, dst) \ byterev src, dst; addi dst, -1, dst; byterev dst, dst #endif /* We assume that the destination is not in the first 16 bytes of memory. A typical linker script will put the text section first, and as this code is longer that 16 bytes, you have to get out of your way to put data there. */ ENTRY(strncpy) pt L_small, tr2 ldlo.q r3, 0, r0 shlli r3, 3, r19 mcmpeq.b r0, r63, r1 SHHI r1, r19, r7 add r2, r4, r20 addi r20, -8, r5 /* If the size is greater than 8, we know we can read beyond the first (possibly partial) quadword, and write out a full first and last (possibly unaligned and/or overlapping) quadword. */ bge/u r2, r5, tr2 // L_small pt L_found0, tr0 addi r2, 8, r22 bnei/u r7, 0, tr0 // L_found0 ori r3, -8, r38 pt L_end_early, tr1 sub r2, r38, r22 stlo.q r2, 0, r0 sthi.q r2, 7, r0 sub r3, r2, r6 ldx.q r22, r6, r0 /* Before each iteration, check that we can store in full the next quad we are about to fetch. */ addi r5, -8, r36 bgtu/u r22, r36, tr1 // L_end_early pt L_scan0, tr1 L_scan0: addi r22, 8, r22 mcmpeq.b r0, r63, r1 stlo.q r22, -8, r0 bnei/u r1, 0, tr0 // L_found0 sthi.q r22, -1, r0 ldx.q r22, r6, r0 bgeu/l r36, r22, tr1 // L_scan0 L_end: // At end; we might re-read a few bytes when we fetch the last quad. // branch mispredict, so load is ready now. mcmpeq.b r0, r63, r1 addi r22, 8, r22 bnei/u r1, 0, tr0 // L_found0 add r3, r4, r7 ldlo.q r7, -8, r1 ldhi.q r7, -1, r7 ptabs r18, tr0 stlo.q r22, -8, r0 or r1, r7, r1 mcmpeq.b r1, r63, r7 sthi.q r22, -1, r0 ZPAD_MASK (r7, r7) and r1, r7, r1 // mask out non-zero bytes after first zero byte stlo.q r20, -8, r1 sthi.q r20, -1, r1 blink tr0, r63 L_end_early: /* Check if we can store the current quad in full. */ pt L_end, tr1 add r3, r4, r7 bgtu/u r5, r22, tr1 // L_end // Not really unlikely, but gap is short. /* If not, that means we can just proceed to process the last quad. Two pipeline stalls are unavoidable, as we don't have enough ILP. */ ldlo.q r7, -8, r1 ldhi.q r7, -1, r7 ptabs r18, tr0 or r1, r7, r1 mcmpeq.b r1, r63, r7 ZPAD_MASK (r7, r7) and r1, r7, r1 // mask out non-zero bytes after first zero byte stlo.q r20, -8, r1 sthi.q r20, -1, r1 blink tr0, r63 L_found0: // r0: string to store, not yet zero-padding normalized. // r1: result of mcmpeq.b r0, r63, r1. // r22: store address plus 8. I.e. address where zero padding beyond the // string in r0 goes. // r20: store end address. // r5: store end address minus 8. pt L_write0_multiquad, tr0 ZPAD_MASK (r1, r1) and r0, r1, r0 // mask out non-zero bytes after first zero byte stlo.q r22, -8, r0 sthi.q r22, -1, r0 andi r22, -8, r1 // Check if zeros to write fit in one quad word. bgtu/l r5, r1, tr0 // L_write0_multiquad ptabs r18, tr1 sub r20, r22, r1 shlli r1, 2, r1 // Do shift in two steps so that 64 bit case is SHLO r0, r1, r0 // handled correctly. SHLO r0, r1, r0 sthi.q r20, -1, r0 blink tr1, r63 L_write0_multiquad: pt L_write0_loop, tr0 ptabs r18, tr1 stlo.q r22, 0, r63 sthi.q r20, -1, r63 addi r1, 8, r1 bgeu/l r5, r1, tr0 // L_write0_loop blink tr1, r63 L_write0_loop: st.q r1, 0 ,r63 addi r1, 8, r1 bgeu/l r5, r1, tr0 // L_write0_loop blink tr1, r63 L_small: // r0: string to store, not yet zero-padding normalized. // r1: result of mcmpeq.b r0, r63, r1. // r7: nonzero indicates relevant zero found r0. // r2: store address. // r3: read address. // r4: size, max 8 // r20: store end address. // r5: store end address minus 8. pt L_nohi, tr0 pt L_small_storelong, tr1 ptabs r18, tr2 sub r63, r4, r23 bnei/u r7, 0, tr0 // L_nohi ori r3, -8, r7 bge/l r23, r7, tr0 // L_nohi ldhi.q r3, 7, r1 or r0, r1, r0 mcmpeq.b r0, r63, r1 L_nohi: ZPAD_MASK (r1, r1) and r0, r1, r0 movi 4, r19 bge/u r4, r19, tr1 // L_small_storelong pt L_small_end, tr0 #ifndef __LITTLE_ENDIAN__ byterev r0, r0 #endif beqi/u r4, 0, tr0 // L_small_end st.b r2, 0, r0 beqi/u r4, 1, tr0 // L_small_end shlri r0, 8, r0 st.b r2, 1, r0 beqi/u r4, 2, tr0 // L_small_end shlri r0, 8, r0 st.b r2, 2, r0 L_small_end: blink tr2, r63 L_small_storelong: shlli r23, 3, r7 SHHI r0, r7, r1 #ifdef __LITTLE_ENDIAN__ shlri r1, 32, r1 #else shlri r0, 32, r0 #endif stlo.l r2, 0, r0 sthi.l r2, 3, r0 stlo.l r20, -4, r1 sthi.l r20, -1, r1 blink tr2, r63 #else /* SHcompact */ /* This code is optimized for size. Instruction selection is SH5 specific. SH4 should use a different version. */ ENTRY(strncpy) mov #0, r6 cmp/eq r4, r6 bt return mov r2, r5 add #-1, r5 add r5, r4 loop: bt/s found0 add #1, r5 mov.b @r3+, r1 found0: cmp/eq r5,r4 mov.b r1, @r5 bf/s loop cmp/eq r1, r6 return: rts nop #endif /* SHcompact */ #endif /* __SH5__ */ picolibc-1.8.11/libc/machine/sh/strncpy.c000066400000000000000000000001461513574234600201760ustar00rootroot00000000000000#include #if !defined(__SH5__) || !__SHMEDIA__ #include "../../string/strncpy.c" #endif picolibc-1.8.11/libc/machine/sh/tls.c000066400000000000000000000043171513574234600173020ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #ifdef __THREAD_LOCAL_STORAGE_API /* The size of the thread control block. * TLS relocations are generated relative to * a location 2 pointers *before* the first thread * variable. * NB: The actual size before tp also includes padding * to align up to the alignment of .tdata/.tbss. We * let the linker compute the offset; see how that's done * in picolibc.ld.in */ extern char __sh32_tls_tcb_offset; #define TP_OFFSET ((size_t)&__sh32_tls_tcb_offset) void _set_tls(void *tls) { tls = (uint8_t *)tls - TP_OFFSET; __asm__("ldc %0,gbr" : : "r"(tls)); } #endif picolibc-1.8.11/libc/machine/sparc/000077500000000000000000000000001513574234600170255ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/sparc/CMakeLists.txt000066400000000000000000000032511513574234600215660ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # add_subdirectory(machine) picolibc_sources_flags("-fno-builtin" interrupt.S setjmp.S scan.c shuffle.c tls.c ) picolibc-1.8.11/libc/machine/sparc/interrupt.S000066400000000000000000000145641513574234600212170ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #define SPARC_NWIN 8 #define PSR_VER_BIT 24 #define PSR_PIL_BIT 8 #define PSR_VER (0xf << PSR_VER_BIT) #define PSR_EF (1 << 12) #define PSR_S (1 << 7) #define PSR_PS (1 << 6) #define PSR_ET (1 << 5) #define PSR_PIL (0xf << PSR_PIL_BIT) #define PSR_CWP 0x1f #define TRAP(func) \ rd %psr, %l0 ; \ sethi %hi(_sparc_ ## func ## _isr), %l4 ;\ jmp %l4+%lo(_sparc_ ## func ## _isr) ;\ rd %tbr, %l6 ; #define TRAP_IN_TRAP \ ta 0x00 ; \ nop ; \ nop ; \ nop ; #define TRAP_HALT(name) \ TRAP(name) ; \ .weak _sparc_ ## name ## _isr ; \ .equ _sparc_ ## name ## _isr, _sparc_halt_isr ; .section .data.init.enter .globl __weak_interrupt_vector __weak_interrupt_vector: TRAP(reset) TRAP_HALT(instruction_access_exception) TRAP_HALT(illegal_instruction) TRAP_HALT(priveledged_instruction) TRAP_HALT(fp_disabled) #ifdef _FLAT TRAP_HALT(window_overflow) TRAP_HALT(window_underflow) #else TRAP(window_overflow) TRAP(window_underflow) #endif TRAP_HALT(mem_address_not_aligned) TRAP_HALT(fp_exception) TRAP_HALT(data_access_exception) TRAP_HALT(tag_overflow) TRAP_HALT(watchpoint_detected) TRAP_HALT(trap_0c) TRAP_HALT(trap_0d) TRAP_HALT(trap_0e) TRAP_HALT(trap_0f) TRAP_HALT(trap_10) . = __weak_interrupt_vector + 0x80 * 16 TRAP_HALT(syscall) TRAP_HALT(breakpoint) TRAP_HALT(divide_by_zero) #ifdef _FLAT TRAP_HALT(window_flush) #else TRAP(window_flush) #endif TRAP_HALT(clean_windows) .size __weak_interrupt_vector, . - __weak_interrupt_vector .weak __interrupt_vector .equ __interrupt_vector, __weak_interrupt_vector .text .align 4 .global _sparc_reset_isr .type _sparc_reset_isr, #function _sparc_reset_isr: sethi %hi(_start), %g4 jmp %g4+%lo(_start) nop .size _sparc_reset_isr, .-_sparc_reset_isr .global _sparc_halt_isr .type _sparc_halt_isr, #function _sparc_halt_isr: ta 0x00 ba _sparc_halt_isr nop .size _sparc_halt_isr, .-_sparc_halt_isr .global _sparc_window_overflow_isr .type _sparc_window_overflow_isr, #function _sparc_window_overflow_isr: /* Enter the window to be stored. */ save /* Save local register set. */ std %l0, [%sp + 0x00] std %l2, [%sp + 0x08] std %l4, [%sp + 0x10] rd %wim, %l3 std %l6, [%sp + 0x18] /* l2 := WIM << (NWIN-1) */ sll %l3, (SPARC_NWIN-1), %l2 /* Save input register set. */ std %i0, [%sp + 0x20] /* l3 := WIM >> 1 */ srl %l3, 1, %l3 std %i2, [%sp + 0x28] /* WIM := (WIM >> 1) ^ (WIM << (NWIN-1)) */ wr %l3, %l2, %wim /* NOTE: 3 instruction before restore (delayed write instruction) */ std %i4, [%sp + 0x30] nop std %i6, [%sp + 0x38] /* Go back to trap window. */ restore /* Re-execute save. */ jmp %l1 rett %l2 .size _sparc_window_overflow_isr, .-_sparc_window_overflow_isr .global _sparc_window_underflow_isr .type _sparc_window_underflow_isr, #function _sparc_window_underflow_isr: rd %wim, %l3 /* l4 := WIM << 1 */ sll %l3, 1, %l4 /* l5 := WIM >> (NWIN-1) */ srl %l3, (SPARC_NWIN-1), %l5 /* WIM := (WIM << 1) ^ (WIM >> (NWIN-1)) */ wr %l4, %l5, %wim /* WIM is implicitly read so nops are needed. */ nop nop nop /* Enter the window to restore requires two restore instructions. */ restore restore ldd [%sp + 0x00], %l0 ldd [%sp + 0x08], %l2 ldd [%sp + 0x10], %l4 ldd [%sp + 0x18], %l6 ldd [%sp + 0x20], %i0 ldd [%sp + 0x28], %i2 ldd [%sp + 0x30], %i4 ldd [%sp + 0x38], %i6 /* Go back to the trap window. */ save save /* Re-execute restore. */ jmp %l1 rett %l2 .size _sparc_window_underflow_isr, .-_sparc_window_underflow_isr .global _sparc_window_flush_isr .type _sparc_window_flush_isr, #function _sparc_window_flush_isr: /* * push a few registers which are needed later to the stack using * sp from the window we trapped from (which is fp in this window) */ sub %fp, 0x10, %fp std %l0, [%fp + 0x40 + 0x00] st %l2, [%fp + 0x40 + 0x08] st %g1, [%fp + 0x40 + 0x0c] restore /* In window where we trapped from. This window will not be flushed. */ /* Set highest processor interrupt level and enable traps. */ rd %psr, %g1 or %g1, PSR_PIL, %g1 wr %g1, PSR_ET, %psr nop nop /* Execute "save" NWINDOWS-1 times. */ set SPARC_NWIN-2, %g1 1: save cmp %g1, %g0 bne 1b sub %g1, 1, %g1 /* Execute "restore" NWINDOWS-1 times. */ set SPARC_NWIN-2, %g1 2: restore cmp %g1, %g0 bne 2b sub %g1, 1, %g1 save /* pop registers from stack which are used for the trap return */ ldd [%fp + 0x40 + 0x00], %l0 ld [%fp + 0x40 + 0x08], %l2 ld [%fp + 0x40 + 0x0c], %g1 add %fp, 0x10, %fp /* Restore %psr as it was on trap entry. */ wr %l0, %psr nop nop nop jmp %l2 rett %l2 + 4 .size _sparc_window_flush_isr, .-_sparc_window_flush_isr picolibc-1.8.11/libc/machine/sparc/machine/000077500000000000000000000000001513574234600204315ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/sparc/machine/CMakeLists.txt000066400000000000000000000031531513574234600231730ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_headers(machine fenv.h fenv-fp.h sparclet.h ) picolibc-1.8.11/libc/machine/sparc/machine/fenv-fp.h000066400000000000000000000167651513574234600221620ustar00rootroot00000000000000/* $NetBSD: fenv.c,v 1.2 2017/03/22 23:11:09 chs Exp $ */ /*- * Copyright (c) 2004-2005 David Schultz * 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 */ /* Load floating-point state register (32bits) */ #define __ldfsr(__r) __asm__ __volatile__("ld %0, %%fsr" : : "m"(__r)) /* Save floating-point state register (32bits) */ #define __stfsr(__r) __asm__ __volatile__("st %%fsr, %0" : "=m"(*(__r))) /* * The feclearexcept() function clears the supported floating-point exceptions * represented by `excepts'. */ __declare_fenv_inline(int) feclearexcept(int excepts) { fexcept_t r; int ex; ex = excepts & FE_ALL_EXCEPT; __stfsr(&r); r &= ~ex; __ldfsr(r); /* Success */ return 0; } /* * The fegetexceptflag() function stores an implementation-defined * representation of the states of the floating-point status flags indicated * by the argument excepts in the object pointed to by the argument flagp. */ __declare_fenv_inline(int) fegetexceptflag(fexcept_t *flagp, int excepts) { fexcept_t r; int ex; ex = excepts & FE_ALL_EXCEPT; __stfsr(&r); *flagp = r & ex; /* Success */ return 0; } /* * This function sets the floating-point status flags indicated by the argument * `excepts' to the states stored in the object pointed to by `flagp'. It does * NOT raise any floating-point exceptions, but only sets the state of the flags. */ __declare_fenv_inline(int) fesetexceptflag(const fexcept_t *flagp, int excepts) { fexcept_t r; int ex; ex = excepts & FE_ALL_EXCEPT; __stfsr(&r); r &= ~ex; r |= *flagp & ex; __ldfsr(r); /* Success */ return 0; } __declare_fenv_inline(int) fesetexcept(int excepts) { fexcept_t __ex = excepts; return fesetexceptflag(&__ex, excepts); } /* * The feraiseexcept() function raises the supported floating-point exceptions * represented by the argument `excepts'. * * The order in which these floating-point exceptions are raised is unspecified * (by the standard). */ __declare_fenv_inline(int) feraiseexcept(int excepts) { volatile double d; int ex; ex = excepts & FE_ALL_EXCEPT; /* * With a compiler that supports the FENV_ACCESS pragma properly, simple * expressions like '0.0 / 0.0' should be sufficient to generate traps. * Unfortunately, we need to bring a volatile variable into the equation * to prevent incorrect optimizations. */ if (ex & FE_INVALID) { d = 0.0; d = 0.0 / d; } if (ex & FE_DIVBYZERO) { d = 0.0; d = 1.0 / d; } if (ex & FE_OVERFLOW) { d = 0x1.ffp1023; d *= 2.0; } if (ex & FE_UNDERFLOW) { d = 0x1p-1022; d /= 0x1p1023; } if (ex & FE_INEXACT) { d = 0x1p-1022; d += 1.0; } /* Success */ return 0; } /* * The fetestexcept() function determines which of a specified subset of the * floating-point exception flags are currently set. The `excepts' argument * specifies the floating-point status flags to be queried. */ __declare_fenv_inline(int) fetestexcept(int excepts) { fexcept_t r; __stfsr(&r); return r & (excepts & FE_ALL_EXCEPT); } /* * The fegetround() function gets the current rounding direction. */ __declare_fenv_inline(int) fegetround(void) { fenv_t r; __stfsr(&r); return (r >> _ROUND_SHIFT) & _ROUND_MASK; } /* * The fesetround() function establishes the rounding direction represented by * its argument `round'. If the argument is not equal to the value of a rounding * direction macro, the rounding direction is not changed. */ __declare_fenv_inline(int) fesetround(int round) { fenv_t r; if (round & ~_ROUND_MASK) return -1; __stfsr(&r); r &= ~(_ROUND_MASK << _ROUND_SHIFT); r |= round << _ROUND_SHIFT; __ldfsr(r); /* Success */ return 0; } /* * The fegetenv() function attempts to store the current floating-point * environment in the object pointed to by envp. */ __declare_fenv_inline(int) fegetenv(fenv_t *envp) { __stfsr(envp); /* Success */ return 0; } /* * The feholdexcept() function saves the current floating-point environment * in the object pointed to by envp, clears the floating-point status flags, and * then installs a non-stop (continue on floating-point exceptions) mode, if * available, for all floating-point exceptions. */ __declare_fenv_inline(int) feholdexcept(fenv_t *envp) { fenv_t r; __stfsr(&r); *envp = r; r &= ~(FE_ALL_EXCEPT | _ENABLE_MASK); __ldfsr(r); /* Success */ return 0; } /* * The fesetenv() function attempts to establish the floating-point environment * represented by the object pointed to by envp. The argument `envp' points * to an object set by a call to fegetenv() or feholdexcept(), or equal a * floating-point environment macro. The fesetenv() function does not raise * floating-point exceptions, but only installs the state of the floating-point * status flags represented through its argument. */ __declare_fenv_inline(int) fesetenv(const fenv_t *envp) { __ldfsr(*envp); /* Success */ return 0; } /* * The feupdateenv() function saves the currently raised floating-point * exceptions in its automatic storage, installs the floating-point environment * represented by the object pointed to by `envp', and then raises the saved * floating-point exceptions. The argument `envp' shall point to an object set * by a call to feholdexcept() or fegetenv(), or equal a floating-point * environment macro. */ __declare_fenv_inline(int) feupdateenv(const fenv_t *envp) { fexcept_t r; __stfsr(&r); __ldfsr(*envp); feraiseexcept(r & FE_ALL_EXCEPT); /* Success */ return 0; } /* * The following functions are extentions to the standard */ __declare_fenv_inline(int) feenableexcept(int mask) { fenv_t old_r, new_r; __stfsr(&old_r); new_r = old_r | ((mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT); __ldfsr(new_r); return (old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT; } __declare_fenv_inline(int) fedisableexcept(int mask) { fenv_t old_r, new_r; __stfsr(&old_r); new_r = old_r & ~((mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT); __ldfsr(new_r); return (old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT; } __declare_fenv_inline(int) fegetexcept(void) { fenv_t r; __stfsr(&r); return (r & _ENABLE_MASK) >> _FPUSW_SHIFT; } picolibc-1.8.11/libc/machine/sparc/machine/fenv.h000066400000000000000000000063751513574234600215530ustar00rootroot00000000000000/* $NetBSD: fenv.h,v 1.2 2017/01/14 12:00:13 martin Exp $ */ /*- * Copyright (c) 2004-2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _MACHINE_FENV_H_ #define _MACHINE_FENV_H_ _BEGIN_STD_C #ifdef _SOFT_FLOAT typedef int fenv_t; typedef int fexcept_t; #define FE_TONEAREST 0 /* round to nearest representable number */ #else #ifdef __arch64__ typedef __UINT64_TYPE__ fenv_t; typedef __UINT64_TYPE__ fexcept_t; #else typedef __UINT32_TYPE__ fenv_t; typedef __UINT32_TYPE__ fexcept_t; #endif /* * Exception flags * * Symbols are defined in such a way, to correspond to the accrued * exception bits (aexc) fields of FSR. */ #define FE_INEXACT 0x00000020 /* 0000100000 */ #define FE_DIVBYZERO 0x00000040 /* 0001000000 */ #define FE_UNDERFLOW 0x00000080 /* 0010000000 */ #define FE_OVERFLOW 0x00000100 /* 0100000000 */ #define FE_INVALID 0x00000200 /* 1000000000 */ #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) /* * Rounding modes * * We can't just use the hardware bit values here, because that would * make FE_UPWARD and FE_DOWNWARD negative, which is not allowed. */ #define FE_TONEAREST 0 /* round to nearest representable number */ #define FE_TOWARDZERO 1 /* round to zero (truncate) */ #define FE_UPWARD 2 /* round toward positive infinity */ #define FE_DOWNWARD 3 /* round toward negative infinity */ #define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO) #define _ROUND_SHIFT 30 /* We need to be able to map status flag positions to mask flag positions */ #define _FPUSW_SHIFT 18 #define _ENABLE_MASK (FE_ALL_EXCEPT << _FPUSW_SHIFT) #endif /* !_SOFT_FLOAT */ #if !defined(__declare_fenv_inline) && defined(__declare_extern_inline) #define __declare_fenv_inline(type) __declare_extern_inline(type) #endif #ifdef __declare_fenv_inline #ifdef _SOFT_FLOAT #include #else #include #endif #endif _END_STD_C #endif /* !_MACHINE_FENV_H_ */ picolibc-1.8.11/libc/machine/sparc/machine/meson.build000066400000000000000000000033711513574234600225770ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_machine_headers_machine = [ 'fenv.h', 'fenv-fp.h', 'sparclet.h', ] if really_install install_headers(inc_machine_headers_machine, install_dir: include_dir / 'machine') endif picolibc-1.8.11/libc/machine/sparc/machine/sparclet.h000066400000000000000000000024651513574234600224260ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* Various stuff for the sparclet processor. This file is in the public domain. */ #ifndef _MACHINE_SPARCLET_H_ #define _MACHINE_SPARCLET_H_ #ifdef __sparclet__ /* sparclet scan instruction */ extern __inline int scan(int a, int b) { int res; __asm__("scan %1,%2,%0" : "=r"(res) : "r"(a), "r"(b)); return res; } /* sparclet shuffle instruction */ extern __inline int shuffle(int a, int b) { int res; __asm__("shuffle %1,%2,%0" : "=r"(res) : "r"(a), "r"(b)); return res; } #endif /* __sparclet__ */ #endif /* _MACHINE_SPARCLET_H_ */ picolibc-1.8.11/libc/machine/sparc/meson.build000066400000000000000000000032731513574234600211740ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'interrupt.S', 'scan.c', 'setjmp.S', 'shuffle.c', 'tls.c', ] src_machine = files(srcs_machine) subdir('machine') picolibc-1.8.11/libc/machine/sparc/scan.c000066400000000000000000000020011513574234600201060ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* Cover function to sparclet `scan' instruction. This file is in the public domain. */ #include #ifdef __sparclet__ int scan(int a, int b) { int res; __asm__("scan %1,%2,%0" : "=r"(res) : "r"(a), "r"(b)); return res; } #endif picolibc-1.8.11/libc/machine/sparc/setjmp.S000066400000000000000000000123221513574234600204530ustar00rootroot00000000000000/* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * Modified for incorporation into newlib by Joel Sherrill * (joel@OARcorp.com), On-Line Applications Research, 1995. * Did the following: * + merged in DEFS.h * + removed error check since it prevented using this setjmp * to "context switch" * + added the support for the "user label" and "register" prefix * * This software was developed by the Computer Systems Engineering group * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and * contributed to Berkeley. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * from: $Header$ */ #include #if defined(LIBC_SCCS) && !defined(lint) .asciz "@(#)_setjmp.s 8.1 (Berkeley) 6/4/93" #endif /* LIBC_SCCS and not lint */ /* * Recent versions of GNU cpp define variables which indicate the * need for underscores and percents. If not using GNU cpp or * the version does not support this, then you will obviously * have to define these as appropriate. */ #ifndef __USER_LABEL_PREFIX__ #define __USER_LABEL_PREFIX__ _ #endif #ifndef __REGISTER_PREFIX__ #define __REGISTER_PREFIX__ #endif /* ANSI concatenation macros. */ #define CONCAT1(a, b) CONCAT2(a, b) #define CONCAT2(a, b) a ## b /* Use the right prefix for global labels. */ #define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x) /********************************************************************* ********************************************************************* * Contents of DEFS.h * ********************************************************************* *********************************************************************/ #ifdef PROF #define ENTRY(x) \ .align 4; .globl SYM(x); .proc 1; SYM(x):; .data; .align 4; 1: .long 0; \ .text; save %sp,-96,%sp; sethi %hi(1b),%o0; call mcount; \ or %lo(1b),%o0,%o0; restore #else #define ENTRY(x) \ .align 4; .globl SYM(x); .proc 1; SYM(x): #endif /********************************************************************* ********************************************************************* * END of DEFS.h * ********************************************************************* *********************************************************************/ /* * C library -- _setjmp, _longjmp * * _longjmp(a,v) * will generate a "return(v?v:1)" from * the last call to * _setjmp(a) * by unwinding the call stack. * The previous signal state is NOT restored. */ /* #include "DEFS.h" */ ENTRY(setjmp) ENTRY(_setjmp) #ifndef _FLAT ta 0x03 /* Flush registers, just in case another stack is used after the setjmp(). */ #endif st %sp, [%o0] /* caller's stack pointer */ st %i7, [%o0+4] /* caller's return pc */ st %fp, [%o0+8] /* store caller's frame pointer */ st %o7, [%o0+12] retl clr %o0 ! return 0 ENTRY(longjmp) ENTRY(_longjmp) #ifndef _FLAT ta 0x03 /* flush registers */ #endif addcc %o1, %g0, %g1 ! compute v ? v : 1 in a global register be,a 0f mov 1, %g1 0: ld [%o0], %sp /* caller's stack pointer */ ldd [%sp], %l0 ldd [%sp+8], %l2 ldd [%sp+16], %l4 ldd [%sp+24], %l6 ldd [%sp+32], %i0 ldd [%sp+40], %i2 ldd [%sp+48], %i4 ld [%o0+4], %i7 /* caller's return pc */ ld [%o0+8], %fp /* caller's frame pointer */ ld [%o0+12], %o7 jmp %o7 + 8 ! success, return %g1 mov %g1, %o0 picolibc-1.8.11/libc/machine/sparc/shuffle.c000066400000000000000000000020121513574234600206200ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* Cover function to sparclet `shuffle' instruction. This file is in the public domain. */ #include #ifdef __sparclet__ int shuffle(int a, int b) { int res; __asm__("shuffle %1,%2,%0" : "=r"(res) : "r"(a), "r"(b)); return res; } #endif picolibc-1.8.11/libc/machine/sparc/tls.c000066400000000000000000000034671513574234600200050ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #ifdef __THREAD_LOCAL_STORAGE_API extern char __tls_size[]; void _set_tls(void *tls) { char *ctls = tls; __asm__("mov %0, %%g7" : : "r"(ctls + (uintptr_t)__tls_size)); } #endif picolibc-1.8.11/libc/machine/spu/000077500000000000000000000000001513574234600165245ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/spu/assert.c000066400000000000000000000020641513574234600201730ustar00rootroot00000000000000/* Copyright (c) 2008 Patrick Mansfield */ #include #include #include #include /* * SPU specific assert: just directly call exit(6), and use fprintf. That * way we do not pull in the abort, signal.o code, nor (the likely * otherwise unused) fiprintf. */ /* func can be NULL, in which case no function information is given. */ void __assert_func(const char *file, int line, const char *func, const char *failedexpr) { fprintf(stderr, "assertion \"%s\" failed: file \"%s\", line %d%s%s\n", failedexpr, file, line, func ? ", function: " : "", func ? func : ""); /* * On the SPU, we do not have signaling. Previously, standard newlib * abort code was used. That eventually leads to a kill(SIGABRT), and * for SPU too an exit(SIGABRT). SIGABRT was 6, so just use that value * here. */ exit(6); /* NOTREACHED */ } void __assert(const char *file, int line, const char *failedexpr) { __assert_func(file, line, NULL, failedexpr); /* NOTREACHED */ } picolibc-1.8.11/libc/machine/spu/c99ppe.h000066400000000000000000000076541513574234600200220ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #ifndef __ASSEMBLER__ #include #include #endif /* !__ASSEMBLER__ */ #define SPE_C99_SIGNALCODE 0x2100 #define SPE_C99_OP_SHIFT 24 #define SPE_C99_OP_MASK 0xff #define SPE_C99_DATA_MASK 0xffffff #define SPE_C99_CLEARERR 1 #define SPE_C99_FCLOSE 2 #define SPE_C99_FEOF 3 #define SPE_C99_FERROR 4 #define SPE_C99_FFLUSH 5 #define SPE_C99_FGETC 6 #define SPE_C99_FGETPOS 7 #define SPE_C99_FGETS 8 #define SPE_C99_FILENO 9 #define SPE_C99_FOPEN 10 // implemented #define SPE_C99_FPUTC 11 #define SPE_C99_FPUTS 12 #define SPE_C99_FREAD 13 #define SPE_C99_FREOPEN 14 #define SPE_C99_FSEEK 15 #define SPE_C99_FSETPOS 16 #define SPE_C99_FTELL 17 #define SPE_C99_FWRITE 18 #define SPE_C99_GETC 19 #define SPE_C99_GETCHAR 20 #define SPE_C99_GETS 21 #define SPE_C99_PERROR 22 #define SPE_C99_PUTC 23 #define SPE_C99_PUTCHAR 24 #define SPE_C99_PUTS 25 #define SPE_C99_REMOVE 26 #define SPE_C99_RENAME 27 #define SPE_C99_REWIND 28 #define SPE_C99_SETBUF 29 #define SPE_C99_SETVBUF 30 #define SPE_C99_SYSTEM 31 // not yet implemented in newlib #define SPE_C99_TMPFILE 32 #define SPE_C99_TMPNAM 33 #define SPE_C99_UNGETC 34 #define SPE_C99_VFPRINTF 35 #define SPE_C99_VFSCANF 36 #define SPE_C99_VPRINTF 37 #define SPE_C99_VSCANF 38 #define SPE_C99_VSNPRINTF 39 #define SPE_C99_VSPRINTF 40 #define SPE_C99_VSSCANF 41 #define SPE_C99_LAST_OPCODE 42 #define SPE_C99_NR_OPCODES ((SPE_C99_LAST_OPCODE - SPE_C99_CLEARERR) + 1) #define SPE_STDIN 1 #define SPE_STDOUT 2 #define SPE_STDERR 3 #define SPE_FOPEN_MAX FOPEN_MAX #ifdef __ASSEMBLER__ #define SPE_STACK_REGS \ 72 /* Number of registers preserved in stack \ in case of variable argument API. */ #else /* !__ASSEMBLER__ */ struct spe_reg128 { unsigned int slot[4]; }; void __sinit(struct _reent *); FILE *__sfp(struct _reent *); #define __sfp_free(fp) ((fp)->_fp = 0) #define CHECK_INIT(ptr) \ do { \ if (!_REENT_IS_NULL(ptr) && !_REENT_CLEANUP(ptr)) \ __sinit(ptr); \ } while (0) #define CHECK_STR_INIT(ptr) /* currently, do nothing */ #endif /* __ASSEMBLER__ */ picolibc-1.8.11/libc/machine/spu/calloc_ea.c000066400000000000000000000037771513574234600206100ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "ea_internal.h" #include typedef struct { unsigned long long nmemb; unsigned int pad0[2]; unsigned long long length; unsigned int pad1[2]; } calloc_ea_t; COMPAT_EA_ALIAS(calloc_ea); __ea void * calloc_ea(size_ea_t nmemb, size_ea_t length) { calloc_ea_t args; args.nmemb = (unsigned long long)nmemb; args.length = (unsigned long long)length; __send_to_ppe(JSRE_LIBEA_SIGNALCODE, SPE_LIBEA_CALLOC, &args); return ull_to_eavoid(args.nmemb); } picolibc-1.8.11/libc/machine/spu/clearerr.c000066400000000000000000000033261513574234600204730ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" void clearerr(FILE *fp) { int ret; CHECK_INIT(_REENT); ret = fp->_fp; __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_CLEARERR, &ret); return; } picolibc-1.8.11/libc/machine/spu/creat.c000066400000000000000000000005271513574234600177720ustar00rootroot00000000000000/* Copyright (c) 2007 Patrick Mansfield */ /* creat() "system call" */ /* copied from libc/posix/creat.c */ /* This is needed by f2c and therefore the SPEC benchmarks. */ #include #include int creat(const char *path, mode_t mode) { return open(path, O_WRONLY | O_CREAT | O_TRUNC, mode); } picolibc-1.8.11/libc/machine/spu/ea_internal.h000066400000000000000000000114761513574234600211670ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __EA_INTERNAL_H #define __EA_INTERNAL_H #include #define JSRE_POSIX1_SIGNALCODE 0x2101 #define SPE_POSIX1_FTOK 0x05 #define SPE_POSIX1_MMAP 0x0b #define SPE_POSIX1_MUNMAP 0x0e /* implemented to here */ #define SPE_POSIX1_MREMAP 0x0c #define SPE_POSIX1_MSYNC 0x0d #define SPE_POSIX1_SHMGET 0x14 #define SPE_POSIX1_SHMCTL 0x12 #define SPE_POSIX1_SHMAT 0x11 #define SPE_POSIX1_SHMDT 0x13 #define SPE_POSIX1_SHM_OPEN 0x15 #define SPE_POSIX1_SHM_UNLINK 0x16 #define JSRE_LIBEA_SIGNALCODE 0x2105 #define SPE_LIBEA_CALLOC 0x01 #define SPE_LIBEA_FREE 0x02 #define SPE_LIBEA_MALLOC 0x03 #define SPE_LIBEA_REALLOC 0x04 #define SPE_LIBEA_POSIX_MEMALIGN 0x05 #define PAD_INT 3 #ifdef __EA64__ #define PAD_LONG 2 #else /* 32 bit */ #define PAD_LONG 3 #endif #define ROUND_UP_NEXT_128(x) (((x) + 128) & (~127)) #define ROUND_DOWN_128(x) ((x) & (~127)) /* Macro that generates an __ea alias. */ #ifdef __EA64__ #define COMPAT_EA_ALIAS(name) __asm__(".global\t__" #name "64\n\t.set\t__" #name "64," #name) #else #define COMPAT_EA_ALIAS(name) __asm__(".global\t__" #name "32\n\t.set\t__" #name "32," #name) #endif static inline __ea void * round_down_128_ea(__ea void *x) { size_ea_t tmp = (size_ea_t)x; tmp &= (~127); return (__ea void *)tmp; } static inline __ea void * round_up_next_128_ea(__ea void *x) { size_ea_t tmp = (size_ea_t)x; tmp += 128; tmp &= (~127); return (__ea void *)tmp; } #define __cache_fetch_dirty_all(x) __cache_fetch_dirty(round_down_128_ea(x), 128) /* please optimize, this hurts my eyes */ static inline size_t three_way_min(size_t x, size_t y, size_t z) { if (x < y) if (x < z) return x; else return z; else if (y < z) return y; else return z; } #undef eavoid_to_ul #define eavoid_to_ul(X) \ ({ \ unsigned long _y; \ __asm__("# %0 %1" : "=r"(_y) : "0"(X)); \ _y; \ }) #undef eavoid_to_ull #define eavoid_to_ull(X) \ ({ \ unsigned long long _y; \ __asm__("# %0 %1" : "=r"(_y) : "0"(X)); \ _y; \ }) #ifdef __EA32__ #undef ull_to_eavoid #define ull_to_eavoid(X) \ ({ \ __ea void *_y; \ unsigned long long X2; \ (X2) = (X) << 32; \ __asm__("# %0 %1" : "=r"(_y) : "0"(X2)); \ _y; \ }) #else /*__EA64__*/ #define ull_to_eavoid(X) \ ({ \ __ea void *_y; \ __asm__("# %0 %1" : "=r"(_y) : "0"(X)); \ _y; \ }) #endif #undef ul_to_eavoid #define ul_to_eavoid(X) \ ({ \ __ea void *_y; \ __asm__("# %0 %1" : "=r"(_y) : "0"(X)); \ _y; \ }) #endif /*__EA_INTERNAL_H*/ picolibc-1.8.11/libc/machine/spu/fclose.c000066400000000000000000000033571513574234600201530ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" int fclose(FILE *fp) { int ret; CHECK_INIT(_REENT); ret = fp->_fp; ret = __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FCLOSE, &ret); __sfp_free(fp); return ret; } picolibc-1.8.11/libc/machine/spu/fdopen.c000066400000000000000000000031431513574234600201440ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2009 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include /* Just a stub for now. */ FILE * fdopen(int fd, const char *mode) { errno = ENOSYS; return NULL; } picolibc-1.8.11/libc/machine/spu/feof.c000066400000000000000000000033171513574234600176130ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" int feof(FILE *fp) { int result; CHECK_INIT(_REENT); result = fp->_fp; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FEOF, &result); } picolibc-1.8.11/libc/machine/spu/ferror.c000066400000000000000000000033231513574234600201700ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" int ferror(FILE *fp) { int result; CHECK_INIT(_REENT); result = fp->_fp; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FERROR, &result); } picolibc-1.8.11/libc/machine/spu/fflush.c000066400000000000000000000033231513574234600201600ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" int fflush(FILE *fp) { int result; CHECK_INIT(_REENT); result = fp->_fp; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FFLUSH, &result); } picolibc-1.8.11/libc/machine/spu/fgetc.c000066400000000000000000000033211513574234600177570ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" int fgetc(FILE *fp) { int result; CHECK_INIT(_REENT); result = fp->_fp; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FGETC, &result); } picolibc-1.8.11/libc/machine/spu/fgetpos.c000066400000000000000000000035721513574234600203460ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" typedef struct { int fp; unsigned int pad0[3]; _fpos_t *pos; } c99_fgetpos_t; int fgetpos(FILE * __restrict fp, _fpos_t * __restrict pos) { c99_fgetpos_t arg; CHECK_INIT(_REENT); arg.fp = fp->_fp; arg.pos = pos; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FGETPOS, &arg); } picolibc-1.8.11/libc/machine/spu/fgets.c000066400000000000000000000037031513574234600200030ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" typedef struct { char *buf; unsigned int pad0[3]; int n; unsigned int pad1[3]; int fp; } c99_fgets_t; char * fgets(char * __restrict buf, int n, FILE * __restrict fp) { c99_fgets_t args; CHECK_INIT(_REENT); args.buf = buf; args.n = n; args.fp = fp->_fp; return (char *)__send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FGETS, &args); } picolibc-1.8.11/libc/machine/spu/fileno.c000066400000000000000000000033131513574234600201440ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" int fileno(FILE *fp) { int ret; CHECK_INIT(_REENT); ret = fp->_fp; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FILENO, &ret); } picolibc-1.8.11/libc/machine/spu/fiprintf.S000066400000000000000000000031051513574234600204700ustar00rootroot00000000000000/* Copyright (c) 2007, Toshiba Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of Toshiba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #define fprintf fiprintf #include "fprintf.S" picolibc-1.8.11/libc/machine/spu/fiscanf.S000066400000000000000000000031021513574234600202550ustar00rootroot00000000000000/* Copyright (c) 2007, Toshiba Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of Toshiba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #define fscanf fiscanf #include "fscanf.S" picolibc-1.8.11/libc/machine/spu/fopen.c000066400000000000000000000042541513574234600200040ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" typedef struct { const char *file; unsigned int pad0[3]; const char *mode; unsigned int pad1[3]; } c99_fopen_t; FILE * fopen(const char * __restrict file, const char * __restrict mode) { int ret; c99_fopen_t args; FILE *fp; struct _reent *ptr = _REENT; CHECK_INIT(ptr); fp = __sfp(ptr); if (!fp) { return NULL; } args.file = file; args.mode = mode; ret = __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FOPEN, &args); if (ret) { fp->_fp = ret; return fp; } else { __sfp_free(fp); return NULL; } } picolibc-1.8.11/libc/machine/spu/fprintf.S000066400000000000000000000043411513574234600203220ustar00rootroot00000000000000/* Copyright (c) 2007, Toshiba Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of Toshiba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "c99ppe.h" .text .align 4 GLOBL fprintf .type fprintf, @function fprintf: stqd $0, 16($sp) /* save caller address */ il $2, 2 /* number of fixed arguments */ brsl $0, __stack_reg_va /* save register to the stack frame */ brsl $0, __check_init lqd $3, 16*2($sp) /* $3 <- saved FP on the stack frame */ lqd $2, 0($3) /* FP = fp->_fp */ rotqby $2, $2, $3 stqd $2, 16*2($sp) /* replace FP on the stack frame */ il $3, SPE_C99_SIGNALCODE il $4, SPE_C99_VFPRINTF ai $5, $sp, 16*2 /* data ($3 save address) */ brsl $0, __send_to_ppe il $2, 16*(SPE_STACK_REGS+2+2) a $sp, $sp, $2 lqd $0, 16($sp) /* load caller address */ bi $0 /* return to caller */ .size fprintf, .-fprintf picolibc-1.8.11/libc/machine/spu/fputc.c000066400000000000000000000036271513574234600200210ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" typedef struct { int ch; unsigned int pad0[3]; int fp; unsigned int pad1[3]; } c99_fputc_t; int fputc(c, fp) int c; register FILE *fp; { c99_fputc_t args; CHECK_INIT(_REENT); args.ch = c; args.fp = fp->_fp; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FPUTC, &args); } picolibc-1.8.11/libc/machine/spu/fputs.c000066400000000000000000000036131513574234600200340ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" typedef struct { const char *s; unsigned int pad0[3]; int fp; unsigned int pad1[3]; } c99_fputs_t; int fputs(char const * __restrict s, FILE * __restrict fp) { c99_fputs_t args; CHECK_INIT(_REENT); args.s = s; args.fp = fp->_fp; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FPUTS, &args); } picolibc-1.8.11/libc/machine/spu/fread.c000066400000000000000000000040421513574234600177510ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" typedef struct { char *buf; unsigned int pad0[3]; size_t size; unsigned int pad1[3]; size_t count; unsigned int pad2[3]; int fp; } c99_fread_t; size_t fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict fp) { c99_fread_t args; CHECK_INIT(_REENT); args.buf = buf; args.size = size; args.count = count; args.fp = fp->_fp; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FREAD, &args); } picolibc-1.8.11/libc/machine/spu/free_ea.c000066400000000000000000000037121513574234600202610ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "ea_internal.h" #include #include extern void __cache_flush(void) __weak; COMPAT_EA_ALIAS(free_ea); void free_ea(__ea void *ptr) { unsigned long long ptr_arg; ptr_arg = (unsigned long long)(size_ea_t)ptr; /* Flush cache only if the application really uses the software cache. */ if (__cache_flush) __cache_flush(); __send_to_ppe(JSRE_LIBEA_SIGNALCODE, SPE_LIBEA_FREE, &ptr_arg); return; } picolibc-1.8.11/libc/machine/spu/freopen.c000066400000000000000000000041751513574234600203350ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" typedef struct { const char *file; unsigned int pad0[3]; const char *mode; unsigned int pad1[3]; int fp; } c99_freopen_t; FILE * freopen(const char * __restrict file, const char * __restrict mode, FILE * __restrict fp) { int ret; c99_freopen_t args; CHECK_INIT(_REENT); args.file = file; args.mode = mode; args.fp = fp->_fp; ret = __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FREOPEN, &args); if (ret) { fp->_fp = ret; return fp; } else { __sfp_free(fp); return NULL; } } picolibc-1.8.11/libc/machine/spu/fscanf.S000066400000000000000000000043331513574234600201130ustar00rootroot00000000000000/* Copyright (c) 2007, Toshiba Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of Toshiba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "c99ppe.h" .text .align 4 GLOBL fscanf .type fscanf, @function fscanf: stqd $0, 16($sp) /* save caller address */ il $2, 2 /* number of fixed arguments */ brsl $0, __stack_reg_va /* save register to the stack frame */ brsl $0, __check_init lqd $3, 16*2($sp) /* $3 <- saved FP on the stack frame */ lqd $2, 0($3) /* FP = fp->_fp */ rotqby $2, $2, $3 stqd $2, 16*2($sp) /* replace FP on the stack frame */ il $3, SPE_C99_SIGNALCODE il $4, SPE_C99_VFSCANF ai $5, $sp, 16*2 /* data ($3 save address) */ brsl $0, __send_to_ppe il $2, 16*(SPE_STACK_REGS+2+2) a $sp, $sp, $2 lqd $0, 16($sp) /* load caller address */ bi $0 /* return to caller */ .size fscanf, .-fscanf picolibc-1.8.11/libc/machine/spu/fseek.c000066400000000000000000000037101513574234600177660ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" typedef struct { int fp; unsigned int pad0[3]; long offset; unsigned int pad1[3]; int whence; } c99_fseek_t; int fseek(register FILE *fp, long offset, int whence) { c99_fseek_t args; CHECK_INIT(_REENT); args.fp = fp->_fp; args.offset = offset; args.whence = whence; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FSEEK, &args); } picolibc-1.8.11/libc/machine/spu/fsetpos.c000066400000000000000000000035641513574234600203630ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" typedef struct { int fp; unsigned int pad0[3]; const _fpos_t *pos; } c99_fsetpos_t; int fsetpos(FILE *iop, const _fpos_t *pos) { c99_fsetpos_t args; CHECK_INIT(_REENT); args.fp = iop->_fp; args.pos = pos; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FSETPOS, &args); } picolibc-1.8.11/libc/machine/spu/ftell.c000066400000000000000000000033121513574234600177750ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" long ftell(FILE *fp) { long ret; CHECK_INIT(_REENT); ret = fp->_fp; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FTELL, &ret); } picolibc-1.8.11/libc/machine/spu/fwrite.c000066400000000000000000000040401513574234600201660ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" typedef struct { const char *buf; unsigned int pad0[3]; size_t size; unsigned int pad1[3]; size_t count; unsigned int pad2[3]; int fp; } c99_fwrite_t; size_t fwrite(const void * __restrict buf, size_t size, size_t count, FILE *fp) { c99_fwrite_t args; CHECK_INIT(_REENT); args.buf = buf; args.size = size; args.count = count; args.fp = fp->_fp; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FWRITE, &args); } picolibc-1.8.11/libc/machine/spu/getc.c000066400000000000000000000034021513574234600176110ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" /* * A subroutine version of the macro getc. */ int getc(fp) FILE *fp; { int ret; CHECK_INIT(_REENT); ret = fp->_fp; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_GETC, &ret); } picolibc-1.8.11/libc/machine/spu/getchar.c000066400000000000000000000032471513574234600203130ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" #undef getchar int getchar() { int ret; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_GETCHAR, &ret); } picolibc-1.8.11/libc/machine/spu/gets.c000066400000000000000000000033301513574234600176310ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" char * gets(buf) char *buf; { /* The return value gets written over buf */ return (char *)__send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_GETS, &buf); } picolibc-1.8.11/libc/machine/spu/include/000077500000000000000000000000001513574234600201475ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/spu/include/ea.h000066400000000000000000000115351513574234600207120ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __EA_H #define __EA_H #include #include #include #include #include /* * take this out when compiler support is common */ #if (!defined(__EA32__) && !defined(__EA64__)) #warning "need __ea support in compiler to compile to take advantage of libea features" #define __ea #define __EA32__ #endif #ifdef __EA64__ typedef uint64_t size_ea_t; typedef int64_t ssize_ea_t; typedef uint64_t key_ea_t; #define MAP_FAILED_EA ((__ea void *)-1LL) #else typedef uint32_t size_ea_t; typedef int32_t ssize_ea_t; typedef uint32_t key_ea_t; #define MAP_FAILED_EA ((__ea void *)-1) #endif typedef __ea void *eaptr; struct iovec_ea { #ifdef __EA32__ unsigned int __pad1; /* 32 bit padding */ #endif /*__ea void *iov_base;*/ eaptr iov_base; /* Starting address */ #ifdef __EA32__ unsigned int __pad2; /* 32 bit padding */ #endif size_ea_t iov_len; /* Number of bytes */ }; /* Memory Mapping functions */ __ea void *mmap_ea(__ea void *start, size_ea_t length, int prot, int flags, int fd, off_t offset); int munmap_ea(__ea void *start, size_ea_t length); __ea void *mremap_ea(__ea void *old_address, size_ea_t old_size, size_ea_t new_size, unsigned long flags); int msync_ea(__ea void *start, size_ea_t length, int flags); /* EA memory mangement functions */ __ea void *calloc_ea(size_ea_t nmemb, size_ea_t length); void free_ea(__ea void *ptr); __ea void *malloc_ea(size_ea_t size); __ea void *realloc_ea(__ea void *ptr, size_ea_t size); int posix_memalign_ea(__ea void **memptr, size_ea_t alignment, size_ea_t size); /* String copying functions */ __ea void *memcpy_ea(__ea void *dest, __ea const void *src, size_ea_t n); __ea void *memmove_ea(__ea void *dest, __ea const void *src, size_ea_t n); __ea char *strcpy_ea(__ea char *dest, __ea const char *src); __ea char *strncpy_ea(__ea char *dest, __ea const char *src, size_ea_t n); /* Concatenation functions */ __ea char *strcat_ea(__ea char *dest, __ea const char *src); __ea char *strncat_ea(__ea char *dest, __ea const char *src, size_ea_t n); /* Comparison functions */ int memcmp_ea(__ea void *s1, __ea const void *s2, size_ea_t n); int strcmp_ea(__ea char *s1, __ea const char *s2); int strncmp_ea(__ea void *s1, __ea const void *s2, size_ea_t n3); /* Search functions*/ __ea void *memchr_ea(__ea const void *s, int c, size_ea_t n); __ea char *strchr_ea(__ea const char *s, int c); size_ea_t strcspn_ea(__ea const char *s, const char *reject); __ea char *strpbrk_ea(__ea const char *s, const char *accept); __ea char *strrchr_ea(__ea const char *s, int c); size_ea_t strspn_ea(__ea const char *s, const char *accept); __ea char *strstr_ea(__ea const char *s1, __ea const char *s2); /* Misc functions */ __ea void *memset_ea(__ea void *dest, int c, size_ea_t n); size_ea_t strlen_ea(__ea const char *s); /* Linux system call functions */ ssize_ea_t read_ea(int fd, __ea void *buf, size_ea_t count); ssize_ea_t pread_ea(int fd, __ea void *buf, size_ea_t count, off_t offset); ssize_ea_t readv_ea(int fd, struct iovec_ea *vector, int count); ssize_ea_t write_ea(int fd, __ea const void *buf, size_ea_t count); ssize_ea_t pwrite_ea(int fd, __ea const void *buf, size_ea_t count, off_t offset); ssize_ea_t writev_ea(int fd, struct iovec_ea *vector, int count); #if defined(__EA64__) && defined(__EA32__) #error __EA64__ and __EA32__ are both defined #endif #endif picolibc-1.8.11/libc/machine/spu/include/fenv.h000066400000000000000000000042341513574234600212610ustar00rootroot00000000000000/* (C) Copyright 2006, 2007 International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _FENV_H #define _FENV_H #include _BEGIN_STD_C /* Exception */ void feclearexcept(int excepts); void fegetexceptflag(fexcept_t *flagp, int excepts); void feraiseexcept(int excepts); void fesetexceptflag(const fexcept_t *flagp, int excepts); int fetestexcept(int excepts); /* Rounding mode */ int fegetround(void); int fesetround(int rounding_mode); /* Float environment */ void fegetenv(fenv_t *envp); int feholdexcept(fenv_t *envp); void fesetenv(const fenv_t *envp); void feupdateenv(const fenv_t *envp); _END_STD_C #endif picolibc-1.8.11/libc/machine/spu/include/spu_timer.h000066400000000000000000000055151513574234600223350ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SPU_TIMER_H_ #define _SPU_TIMER_H_ #include _BEGIN_STD_C /* Clock services. */ extern void spu_clock_start(void); extern int spu_clock_stop(void); extern uint64_t spu_clock_read(void); /* Timer services. */ extern int spu_timer_alloc(int interval, void (*func)(int)); extern int spu_timer_free(int id); extern int spu_timer_start(int id); extern int spu_timer_stop(int id); extern unsigned spu_timebase(void); /* Interrupt services. */ extern void spu_slih_register(unsigned event_mask, unsigned (*slih)(unsigned)); extern unsigned spu_clock_slih(unsigned event_mask); /* Number of supported timers. */ #define SPU_TIMER_NTIMERS 4 /* Recommended minimun spu timer interval time from (cat /proc/cpuinfo) * QS20 100/14318000 = 6.98 usec * QS21/QS22 100/26666666 = 3.75 usec * PS3 100/79800000 = 1.25 usec */ #define SPU_TIMER_MIN_INTERVAL 100 /* Clock error codes. */ #define SPU_CLOCK_ERR_NOT_RUNNING -2 #define SPU_CLOCK_ERR_STILL_RUNNING -3 #define SPU_CLOCK_ERR_TIMERS_ACTIVE -4 /* Timer error codes. */ #define SPU_TIMER_ERR_INVALID_PARM -10 #define SPU_TIMER_ERR_NONE_FREE -11 #define SPU_TIMER_ERR_INVALID_ID -12 #define SPU_TIMER_ERR_ACTIVE -13 #define SPU_TIMER_ERR_NOT_ACTIVE -14 #define SPU_TIMER_ERR_NOCLOCK -15 #define SPU_TIMER_ERR_FREE -16 #define SPU_TIMER_ERR_NOT_STOPPED -17 _END_STD_C #endif picolibc-1.8.11/libc/machine/spu/iprintf.S000066400000000000000000000031021513574234600203170ustar00rootroot00000000000000/* Copyright (c) 2007, Toshiba Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of Toshiba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #define printf iprintf #include "printf.S" picolibc-1.8.11/libc/machine/spu/iscanf.S000066400000000000000000000030771513574234600201220ustar00rootroot00000000000000/* Copyright (c) 2007, Toshiba Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of Toshiba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #define scanf iscanf #include "scanf.S" picolibc-1.8.11/libc/machine/spu/machine/000077500000000000000000000000001513574234600201305ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/spu/machine/_types.h000066400000000000000000000042111513574234600216020ustar00rootroot00000000000000/* Copyright 2007 International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MACHINE__TYPES_H #define _MACHINE__TYPES_H #include /* * fpos_t large enough for either 32 or 64 bit ppc glibc fpos_t. */ #define __machine_fpos_t_defined typedef struct { char __pos[16]; } _fpos_t; #ifdef __LARGE64_FILES #define __machine_fpos64_t_defined typedef _fpos_t _fpos64_t; #endif #define __machine_dev_t_defined typedef int __dev_t; #define __machine_uid_t_defined typedef unsigned int __uid_t; #define __machine_gid_t_defined typedef unsigned int __gid_t; #endif /* _MACHINE__TYPES_H */ picolibc-1.8.11/libc/machine/spu/machine/fenv.h000066400000000000000000000136701513574234600212460ustar00rootroot00000000000000/* (C) Copyright 2006, 2007 International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MACHINE_FENV_H #define _MACHINE_FENV_H #include _BEGIN_STD_C /* * The exception macros are such that the functions to pack/unpack them * will map a 32 bit fenv_t from/to the 128 bit fpscr. * * Suffixes: * _SNGL: single precision * _DBL: double precision * _N: element number, no suffix for element 0. */ #define FE_OVERFLOW_SNGL 0x08000000 #define FE_UNDERFLOW_SNGL 0x04000000 #define FE_DIFF_SNGL 0x02000000 #define FE_DIVBYZERO_SNGL 0x00000040 #define FE_OVERFLOW_SNGL_1 0x00040000 #define FE_UNDERFLOW_SNGL_1 0x00020000 #define FE_DIFF_SNGL_1 0x00010000 #define FE_DIVBYZERO_SNGL_1 0x00000020 #define FE_OVERFLOW_SNGL_2 0x00000200 #define FE_UNDERFLOW_SNGL_2 0x00000100 #define FE_DIFF_SNGL_2 0x00000080 #define FE_DIVBYZERO_SNGL_2 0x00000010 #define FE_OVERFLOW_SNGL_3 0x00000004 #define FE_UNDERFLOW_SNGL_3 0x00000002 #define FE_DIFF_SNGL_3 0x00000001 #define FE_DIVBYZERO_SNGL_3 0x00000008 #define FE_ALL_EXCEPT_SNGL (FE_OVERFLOW_SNGL | FE_UNDERFLOW_SNGL | FE_DIFF_SNGL | FE_DIVBYZERO_SNGL) #define FE_ALL_EXCEPT_SNGL_1 \ (FE_OVERFLOW_SNGL_1 | FE_UNDERFLOW_SNGL_1 | FE_DIFF_SNGL_1 | FE_DIVBYZERO_SNGL_1) #define FE_ALL_EXCEPT_SNGL_2 \ (FE_OVERFLOW_SNGL_2 | FE_UNDERFLOW_SNGL_2 | FE_DIFF_SNGL_2 | FE_DIVBYZERO_SNGL_2) #define FE_ALL_EXCEPT_SNGL_3 \ (FE_OVERFLOW_SNGL_3 | FE_UNDERFLOW_SNGL_3 | FE_DIFF_SNGL_3 | FE_DIVBYZERO_SNGL_3) #define FE_OVERFLOW_DBL 0x01000000 #define FE_UNDERFLOW_DBL 0x00800000 #define FE_INEXACT_DBL 0x00400000 #define FE_INVALID_DBL 0x00200000 #define FE_NC_NAN_DBL 0x00100000 #define FE_NC_DENORM_DBL 0x00080000 #define FE_OVERFLOW_DBL_1 0x00008000 #define FE_UNDERFLOW_DBL_1 0x00004000 #define FE_INEXACT_DBL_1 0x00002000 #define FE_INVALID_DBL_1 0x00001000 #define FE_NC_NAN_DBL_1 0x00000800 #define FE_NC_DENORM_DBL_1 0x00000400 #define FE_ALL_EXCEPT_DBL \ (FE_OVERFLOW_DBL | FE_UNDERFLOW_DBL | FE_INEXACT_DBL | FE_INVALID_DBL | FE_NC_NAN_DBL \ | FE_NC_DENORM_DBL) #define FE_ALL_EXCEPT_DBL_1 \ (FE_OVERFLOW_DBL_1 | FE_UNDERFLOW_DBL_1 | FE_INEXACT_DBL_1 | FE_INVALID_DBL_1 \ | FE_NC_NAN_DBL_1 | FE_NC_DENORM_DBL_1) #define FE_ALL_EXCEPT \ (FE_ALL_EXCEPT_SNGL | FE_ALL_EXCEPT_SNGL_1 | FE_ALL_EXCEPT_SNGL_2 | FE_ALL_EXCEPT_SNGL_3 \ | FE_ALL_EXCEPT_DBL | FE_ALL_EXCEPT_DBL_1) /* * Warning: some of these are single and some double precision only, * because of the hardware implementation. */ #define FE_DIVBYZERO \ (FE_DIVBYZERO_SNGL | FE_DIVBYZERO_SNGL_1 | FE_DIVBYZERO_SNGL_2 | FE_DIVBYZERO_SNGL_3) #define FE_INEXACT (FE_INEXACT_DBL | FE_INEXACT_DBL_1) #define FE_INVALID (FE_INVALID_DBL | FE_INVALID_DBL_1) #define FE_NC_NAN (FE_NC_NAN_DBL | FE_NC_NAN_DBL_1) #define FE_NC_DENORM (FE_NC_DENORM_DBL | FE_NC_DENORM_DBL_1) /* * __FE_ROUND_ELE_n values are set so that they can easily be used as a * mask when setting the fpscr. These tell us whether we are setting the * round mode for a specific element (double precision floating point * only, so there are only two elements). */ #define __FE_ROUND_ELE_0 0xc00 #define __FE_ROUND_ELE_1 0x300 /* * The following map directly to round values in the fpscr. */ #define __FE_SPU_TONEAREST 0 #define __FE_SPU_TOWARDZERO 1 #define __FE_SPU_UPWARD 2 #define __FE_SPU_DOWNWARD 3 #define FE_TONEAREST (__FE_ROUND_ELE_0 | (__FE_SPU_TONEAREST << 2)) #define FE_TOWARDZERO (__FE_ROUND_ELE_0 | (__FE_SPU_TOWARDZERO << 2)) #define FE_UPWARD (__FE_ROUND_ELE_0 | (__FE_SPU_UPWARD << 2)) #define FE_DOWNWARD (__FE_ROUND_ELE_0 | (__FE_SPU_DOWNWARD << 2)) #define FE_TONEAREST_1 (__FE_ROUND_ELE_1 | __FE_SPU_TONEAREST) #define FE_TOWARDZERO_1 (__FE_ROUND_ELE_1 | __FE_SPU_TOWARDZERO) #define FE_UPWARD_1 (__FE_ROUND_ELE_1 | __FE_SPU_UPWARD) #define FE_DOWNWARD_1 (__FE_ROUND_ELE_1 | __FE_SPU_DOWNWARD) typedef unsigned int fexcept_t; typedef unsigned int fenv_t; _END_STD_C #endif /* fenv.h */ picolibc-1.8.11/libc/machine/spu/malloc_ea.c000066400000000000000000000034221513574234600206050ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "ea_internal.h" #include COMPAT_EA_ALIAS(malloc_ea); __ea void * malloc_ea(size_ea_t size) { unsigned long long sz; sz = (unsigned long long)size; __send_to_ppe(JSRE_LIBEA_SIGNALCODE, SPE_LIBEA_MALLOC, &sz); return ull_to_eavoid(sz); } picolibc-1.8.11/libc/machine/spu/memchr_ea.c000066400000000000000000000046501513574234600206150ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "ea_internal.h" #include #include #include COMPAT_EA_ALIAS(memchr_ea); __ea void * memchr_ea(__ea const void *s, int c, size_ea_t n) { __ea void *curr_s = (__ea void *)s; void *local_s; size_ea_t left_in_cacheline; size_ea_t search_size; void *where; size_ea_t ret; while (n) { left_in_cacheline = ROUND_UP_NEXT_128((size_ea_t)curr_s) - (size_ea_t)curr_s; search_size = left_in_cacheline < n ? left_in_cacheline : n; local_s = __cache_fetch(curr_s); where = memchr(local_s, c, search_size); if (where) { ret = (size_ea_t)curr_s + ((size_ea_t)(int)where - (size_ea_t)(int)local_s); return (__ea void *)ret; } /* update values to take into account what we copied */ curr_s += search_size; n -= search_size; } /* if we got here n was initially 0 */ return NULL; } picolibc-1.8.11/libc/machine/spu/memcmp.c000066400000000000000000000037071513574234600201550ustar00rootroot00000000000000/* (C) Copyright 2008 International Business Machines Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "strncmp.h" /* * Compare the two strings s1 and s2 of length n. Returns an integer less * than, equal to, or greater than zero if s1 is found, respectively, * to be less than, to match, or be greater than s2. */ int memcmp(const void *s1, const void *s2, size_t n) { vec_uint4 end_v; return _strncmp_internal(s1, s2, n, &end_v, 0 /* no zero check */); } picolibc-1.8.11/libc/machine/spu/memcmp_ea.c000066400000000000000000000051071513574234600206160ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "ea_internal.h" #include #include COMPAT_EA_ALIAS(memcmp_ea); int memcmp_ea(__ea void *s1, __ea const void *s2, size_ea_t n) { __ea void *curr_s1 = s1; __ea void *curr_s2 = (__ea void *)s2; void *l_s1; void *l_s2; size_ea_t local_n; size_ea_t s2_n; size_ea_t s1_n; int ret; ret = 0; while (n) { l_s2 = __cache_fetch(curr_s2); l_s1 = __cache_fetch(curr_s1); /* * Use the smaller of the size left to compare (n), the space left in * s2 cacheline (s2_n), or the space left in the s1 cacheline (s1_n). */ s2_n = ROUND_UP_NEXT_128((size_ea_t)curr_s2) - (size_ea_t)curr_s2; s1_n = ROUND_UP_NEXT_128((size_ea_t)curr_s1) - (size_ea_t)curr_s1; local_n = three_way_min(s2_n, s1_n, n); ret = memcmp(l_s1, l_s2, local_n); if (ret) return ret; /* update values to take into account what we copied */ curr_s2 += local_n; curr_s1 += local_n; n -= local_n; } return ret; } picolibc-1.8.11/libc/machine/spu/memcpy.c000066400000000000000000000106271513574234600201700ustar00rootroot00000000000000/* (C) Copyright 2001,2006, International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include "../../string/local.h" /* Copy n bytes from memory area src to memory area dest. * The memory areas may not overlap. The memcpy subroutine * returns a pointer to dest. * * Faster implementation of this function can be implemented * either with prior knowledge of the alignment or special * casing specific optimal alignments. */ void * __no_builtin memcpy(void * __restrict__ dest, const void * __restrict__ src, size_t n) { int adjust, delta; unsigned int soffset1, doffset1, doffset2; vec_uchar16 *vSrc, *vDst; vec_uchar16 sdata1, sdata2, sdata, ddata, shuffle; vec_uchar16 mask, mask1, mask2, mask3; vSrc = (vec_uchar16 *)(src); vDst = (vec_uchar16 *)(dest); /* Handle any leading destination partial quadwords as * well a very short copy (ie, such that the n characters * all reside in a single (destination) quadword. */ soffset1 = (unsigned int)(src) & 15; doffset1 = (unsigned int)(dest) & 15; doffset2 = ((unsigned int)(dest) + n) & 15; /* Compute a shuffle pattern used to align the source string * with the alignment of the destination string. */ adjust = (int)spu_extract(spu_cmpgt(spu_promote(doffset1, 0), spu_promote(soffset1, 0)), 0); delta = (int)soffset1 - (int)doffset1; delta += adjust & 16; shuffle = (vec_uchar16)spu_add( (vec_uint4)spu_splats((unsigned char)delta), VEC_LITERAL(vec_uint4, 0x00010203, 0x04050607, 0x08090A0B, 0x0C0D0E0F)); vSrc += adjust; sdata1 = *vSrc++; sdata2 = *vSrc++; ddata = *vDst; sdata = spu_shuffle(sdata1, sdata2, shuffle); /* Construct a series of masks used to data insert. The masks * contain 0 when the destination word is unchanged, 1 when it * must be replaced by source bytes. * * mask1 = mask for leading unchanged bytes * mask2 = mask for trailing unchange bytes * mask3 = mask indicating the more than one qword is being changed. */ mask = spu_splats((unsigned char)-1); mask1 = spu_rlmaskqwbyte(mask, -doffset1); mask2 = spu_slqwbyte(mask, 16 - doffset2); mask3 = (vec_uchar16)spu_cmpgt(spu_splats((unsigned int)(doffset1 + n)), 15); *vDst++ = spu_sel(ddata, sdata, spu_and(mask1, spu_or(mask2, mask3))); n += doffset1; /* Handle complete destination quadwords */ while (n > 31) { sdata1 = sdata2; sdata2 = *vSrc++; *vDst++ = spu_shuffle(sdata1, sdata2, shuffle); n -= 16; } /* Handle any trailing partial (destination) quadwords */ mask = spu_and((vec_uchar16)spu_cmpgt(spu_splats((unsigned int)n), 16), mask2); *vDst = spu_sel(*vDst, spu_shuffle(sdata2, *vSrc, shuffle), mask); return (dest); } picolibc-1.8.11/libc/machine/spu/memcpy_ea.c000066400000000000000000000052421513574234600206320ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "ea_internal.h" #include #include #include "../../string/local.h" COMPAT_EA_ALIAS(memcpy_ea); __ea void * __no_builtin memcpy_ea(__ea void *dest, __ea const void *src, size_ea_t n) { __ea void *curr_dest = dest; __ea const void *curr_src = src; void *l_dest; void *l_src; size_ea_t local_n; size_ea_t src_n; size_ea_t dst_n; while (n) { l_src = __cache_fetch((__ea void *)curr_src); /* * use the smaller of the size left to copy (n), the space left in the * src cacheline (src_n), or the space left in the destination * cacheline (dst_n) */ src_n = ROUND_UP_NEXT_128((size_ea_t)curr_src) - (size_ea_t)curr_src; dst_n = ROUND_UP_NEXT_128((size_ea_t)curr_dest) - (size_ea_t)curr_dest; local_n = three_way_min(src_n, dst_n, n); l_dest = __cache_fetch_dirty(curr_dest, local_n); memcpy(l_dest, l_src, local_n); /* update values to take into account what we copied */ curr_src += local_n; curr_dest += local_n; n -= local_n; } return dest; } picolibc-1.8.11/libc/machine/spu/memmove.c000066400000000000000000000205471513574234600203450ustar00rootroot00000000000000/* (C) Copyright 2001,2006, International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "vec_literal.h" /* Copy n bytes from memory area src to memory area dest. * Copying is performed as if the n characters pointed to * by src are first copied into a temporary array that does * not overlap the src and dest arrays. Then the n characters * of the temporary array are copied into the destination * array. The memmove subroutine returns a pointer to dest. */ void * memmove(void * __restrict__ dest, const void * __restrict__ src, size_t n) { int adjust, delta; unsigned int soffset1, soffset2, doffset1, doffset2; vec_uchar16 *vSrc, *vDst; vec_uchar16 sdata1, sdata2, sdata, ddata, shuffle; vec_uchar16 mask, mask1, mask2, mask3, one = spu_splats((unsigned char)-1); soffset1 = (unsigned int)(src) & 15; doffset1 = (unsigned int)(dest) & 15; doffset2 = ((unsigned int)(dest) + n) & 15; /* Construct a series of masks used to data insert. The masks * contains 0 bit when the destination word is unchanged, 1 when it * must be replaced by source bits. * * mask1 = mask for leading unchanged bytes * mask2 = mask for trailing unchange bytes * mask3 = mask indicating the more than one qword is being changed. */ mask = one; mask1 = spu_rlmaskqwbyte(mask, -doffset1); mask2 = spu_slqwbyte(mask, 16 - doffset2); mask3 = (vec_uchar16)spu_cmpgt(spu_splats((unsigned int)(doffset1 + n)), 15); vDst = (vec_uchar16 *)(dest); delta = (int)soffset1 - (int)doffset1; /* The follow check only works if the SPU addresses are not * wrapped. No provisions have been made to correct for this * limitation. */ if (((unsigned int)dest - (unsigned int)src) >= (unsigned int)n) { /* Forward copy. Perform a memcpy. * * Handle any leading destination partial quadwords as * well a very short copy (ie, such that the n characters * all reside in a single (destination) quadword. */ vSrc = (vec_uchar16 *)(src); vDst = (vec_uchar16 *)(dest); /* Handle any leading destination partial quadwords as * well a very short copy (ie, such that the n characters * all reside in a single (destination) quadword. */ soffset1 = (unsigned int)(src) & 15; doffset1 = (unsigned int)(dest) & 15; doffset2 = ((unsigned int)(dest) + n) & 15; /* Compute a shuffle pattern used to align the source string * with the alignment of the destination string. */ adjust = (int)spu_extract(spu_cmpgt(spu_promote(doffset1, 0), spu_promote(soffset1, 0)), 0); delta = (int)soffset1 - (int)doffset1; delta += adjust & 16; shuffle = (vec_uchar16)spu_add( (vec_uint4)spu_splats((unsigned char)delta), VEC_LITERAL(vec_uint4, 0x00010203, 0x04050607, 0x08090A0B, 0x0C0D0E0F)); vSrc += adjust; sdata1 = *vSrc++; sdata2 = *vSrc++; ddata = *vDst; sdata = spu_shuffle(sdata1, sdata2, shuffle); /* Construct a series of masks used to data insert. The masks * contain 0 when the destination word is unchanged, 1 when it * must be replaced by source bytes. * * mask1 = mask for leading unchanged bytes * mask2 = mask for trailing unchange bytes * mask3 = mask indicating the more than one qword is being changed. */ mask = one; mask1 = spu_rlmaskqwbyte(mask, -doffset1); mask2 = spu_slqwbyte(mask, 16 - doffset2); mask3 = (vec_uchar16)spu_cmpgt(spu_splats((unsigned int)(doffset1 + n)), 15); *vDst++ = spu_sel(ddata, sdata, spu_and(mask1, spu_or(mask2, mask3))); n += doffset1; /* Handle complete destination quadwords */ while (n > 31) { sdata1 = sdata2; sdata2 = *vSrc++; *vDst++ = spu_shuffle(sdata1, sdata2, shuffle); n -= 16; } /* Handle any trailing partial (destination) quadwords */ mask = spu_and((vec_uchar16)spu_cmpgt(spu_splats((unsigned int)n), 16), mask2); *vDst = spu_sel(*vDst, spu_shuffle(sdata2, *vSrc, shuffle), mask); } else { /* Backward copy. * * Handle any leading destination partial quadwords as * well a very short copy (ie, such that the n characters * all reside in a single (destination) quadword. */ vSrc = (vec_uchar16 *)((unsigned int)src + n - 1); vDst = (vec_uchar16 *)((unsigned int)dest + n - 1); /* Handle any leading destination partial quadwords as * well a very short copy (ie, such that the n characters * all reside in a single (destination) quadword. */ soffset1 = (unsigned int)(src) & 15; soffset2 = (unsigned int)(vSrc) & 15; doffset1 = (unsigned int)(dest) & 15; doffset2 = (unsigned int)(vDst) & 15; /* Compute a shuffle pattern used to align the source string * with the alignment of the destination string. */ adjust = (int)spu_extract(spu_cmpgt(spu_promote(soffset2, 0), spu_promote(doffset2, 0)), 0); delta = (int)doffset2 - (int)soffset2; delta += adjust & 16; shuffle = (vec_uchar16)spu_sub( VEC_LITERAL(vec_uint4, 0x10111213, 0x14151617, 0x18191A1B, 0x1C1D1E1F), (vec_uint4)spu_splats((unsigned char)delta)); vSrc -= adjust; sdata2 = *vSrc--; sdata1 = *vSrc--; ddata = *vDst; sdata = spu_shuffle(sdata1, sdata2, shuffle); /* Construct a series of masks used to data insert. The masks * contain 0 when the destination word is unchanged, 1 when it * must be replaced by source bytes. * * mask1 = mask for leading unchanged bytes * mask2 = mask for trailing unchange bytes * mask3 = mask indicating the more than one qword is being changed. */ mask = one; mask1 = spu_rlmaskqwbyte(mask, -doffset1); mask2 = spu_slqwbyte(mask, 15 - doffset2); mask3 = (vec_uchar16)spu_cmpgt(spu_splats((int)(doffset2 - n)), -2); *vDst-- = spu_sel(ddata, sdata, spu_and(mask2, spu_orc(mask1, mask3))); n -= doffset2 + 1; /* Handle complete destination quadwords */ while ((int)n > 15) { sdata2 = sdata1; sdata1 = *vSrc--; *vDst-- = spu_shuffle(sdata1, sdata2, shuffle); n -= 16; } /* Handle any trailing partial (destination) quadwords */ mask = spu_and((vec_uchar16)spu_cmpgt(spu_splats((int)n), 0), mask1); *vDst = spu_sel(*vDst, spu_shuffle(*vSrc, sdata1, shuffle), mask); } return (dest); } picolibc-1.8.11/libc/machine/spu/memmove_ea.c000066400000000000000000000051351513574234600210060ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "ea_internal.h" #include #include COMPAT_EA_ALIAS(memmove_ea); __ea void * memmove_ea(__ea void *dest, __ea const void *src, size_ea_t n) { __ea void *curr_dest = dest; __ea void *curr_src; void *l_dest; void *l_src; size_ea_t local_n; size_ea_t src_n; size_ea_t dst_n; curr_src = (__ea void *)src; while (n) { l_src = __cache_fetch(curr_src); /* * use the smaller of the size left to copy (n), the space left in the * src cacheline (src_n), or the space left in the destination * cacheline (dst_n). */ src_n = ROUND_UP_NEXT_128((size_ea_t)curr_src) - (size_ea_t)curr_src; dst_n = ROUND_UP_NEXT_128((size_ea_t)curr_dest) - (size_ea_t)curr_dest; local_n = three_way_min(src_n, dst_n, n); l_dest = __cache_fetch_dirty(curr_dest, local_n); memmove(l_dest, l_src, local_n); /* update values to take into account what we copied */ curr_src += local_n; curr_dest += local_n; n -= local_n; } return dest; } picolibc-1.8.11/libc/machine/spu/memset.c000066400000000000000000000060631513574234600201670ustar00rootroot00000000000000/* (C) Copyright 2001,2006, International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include /* Fills the first n bytes of the memory area pointed to by s * with the constant byte c. Returns a pointer to the memory area s. */ void * memset(void *s, int c, size_t n) { int skip, cnt, i; vec_uchar16 *vs; vec_uchar16 vc, mask, one = spu_splats((unsigned char)-1); vs = (vec_uchar16 *)(s); vc = spu_splats((unsigned char)c); cnt = (int)(n); /* Handle any leading partial quadwords as well a * very short settings (ie, such that the n characters * all reside in a single quadword. */ skip = (int)(s) & 15; if (skip) { mask = spu_rlmaskqwbyte(one, -skip); cnt -= 16 - skip; if (cnt < 0) { mask = spu_and(mask, spu_slqwbyte(one, (unsigned int)(-cnt))); } *vs = spu_sel(*vs, vc, mask); vs++; } /* Handle 8 quadwords at a time */ for (i = 127; i < cnt; cnt -= 8 * 16) { vs[0] = vc; vs[1] = vc; vs[2] = vc; vs[3] = vc; vs[4] = vc; vs[5] = vc; vs[6] = vc; vs[7] = vc; vs += 8; } /* Finish all remaining complete quadwords */ for (i = 15; i < cnt; cnt -= 16) *vs++ = vc; /* Handle any trailing partial quadwords */ if (cnt > 0) { mask = spu_slqwbyte(one, (unsigned int)(16 - cnt)); *vs = spu_sel(*vs, vc, mask); } return (s); } picolibc-1.8.11/libc/machine/spu/memset_ea.c000066400000000000000000000042451513574234600206340ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include "ea_internal.h" #include #include "../../string/local.h" COMPAT_EA_ALIAS(memset_ea); __ea void * __no_builtin memset_ea(__ea void *dest, int c, size_ea_t n) { __ea void *curr_dest = dest; void *l_dest; size_ea_t local_n; size_ea_t dst_n; while (n) { dst_n = ROUND_UP_NEXT_128((size_ea_t)curr_dest) - (size_ea_t)curr_dest; local_n = dst_n < n ? dst_n : n; l_dest = __cache_fetch_dirty(curr_dest, local_n); memset(l_dest, c, local_n); /* update values to take into account what we copied */ curr_dest += local_n; n -= local_n; } return dest; } picolibc-1.8.11/libc/machine/spu/mk_syscalls000066400000000000000000000117451513574234600210030ustar00rootroot00000000000000#!/usr/bin/perl -w # # (C) Copyright 2007 TOSHIBA CORPORATION # All Rights Reserved # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the names of Toshiba nor the names of its # contributors may be used to endorse or promote products derived from this # software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. open(DEFS, "syscall.def"); while ($line = ) { next if ($line =~ /^#.*/); ($opcode, $name, $fp, $parms) = split(" ", $line); $filename = ">" . $name . ".S"; open(SOURCE, $filename); print SOURCE "\/\*\n"; print SOURCE " Copyright (c) 2007, Toshiba Corporation\n\n"; print SOURCE " All rights reserved.\n\n"; print SOURCE " Redistribution and use in source and binary forms, with or without\n"; print SOURCE " modification, are permitted provided that the following conditions are met:\n\n"; print SOURCE " \* Redistributions of source code must retain the above copyright notice,\n"; print SOURCE " this list of conditions and the following disclaimer.\n"; print SOURCE " \* Redistributions in binary form must reproduce the above copyright\n"; print SOURCE " notice, this list of conditions and the following disclaimer in the\n"; print SOURCE " documentation and/or other materials provided with the distribution.\n"; print SOURCE " \* Neither the names of Toshiba nor the names of its\n"; print SOURCE " contributors may be used to endorse or promote products derived from this\n"; print SOURCE " software without specific prior written permission.\n\n"; print SOURCE " THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n"; print SOURCE " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n"; print SOURCE " IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n"; print SOURCE " ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\n"; print SOURCE " LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n"; print SOURCE " CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n"; print SOURCE " SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n"; print SOURCE " INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n"; print SOURCE " CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n"; print SOURCE " ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n"; print SOURCE " POSSIBILITY OF SUCH DAMAGE.\n"; print SOURCE " \*\/\n\n"; print SOURCE "#include \"c99ppe.h\"\n\n"; print SOURCE " .text\n"; print SOURCE " .align 4\n"; print SOURCE " GLOBL ", $name, "\n"; print SOURCE " .type ", $name, ", \@function\n"; print SOURCE $name, ":\n"; print SOURCE " stqd \$0, 16(\$sp) \/\* save caller address \*\/\n"; print SOURCE " il \$2, ", $parms, " \/\* number of fixed arguments \*\/\n"; print SOURCE " brsl \$0, __stack_reg_va \/\* save register to the stack frame \*\/\n\n"; if ($fp > 0) { print SOURCE " brsl \$0, __check_init\n"; print SOURCE " lqd \$3, 16\*2(\$sp) \/\* \$3 <- saved FP on the stack frame \*\/\n"; print SOURCE " lqd \$2, 0(\$3) \/\* FP = fp->_fp \*\/\n"; print SOURCE " rotqby \$2, \$2, \$3\n"; print SOURCE " stqd \$2, 16\*2(\$sp) \/\* replace FP on the stack frame \*\/\n\n"; } print SOURCE " il \$3, SPE_C99_SIGNALCODE\n"; print SOURCE " il \$4, ", $opcode, "\n"; print SOURCE " ai \$5, \$sp, 16\*2 \/\* data (\$3 save address) \*\/\n"; print SOURCE " brsl \$0, __send_to_ppe\n\n"; print SOURCE " il \$2, 16\*(SPE_STACK_REGS+2+2)\n"; print SOURCE " a \$sp, \$sp, \$2\n"; print SOURCE " lqd \$0, 16(\$sp) \/\* load caller address \*\/\n"; print SOURCE " bi \$0 \/\* return to caller \*\/\n"; print SOURCE " .size ", $name, ", .-", $name, "\n"; close(SOURCE); } picolibc-1.8.11/libc/machine/spu/mmap_ea.c000066400000000000000000000046201513574234600202710ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include "ea_internal.h" #include COMPAT_EA_ALIAS(mmap_ea); __ea void * mmap_ea(__ea void *start, size_ea_t length, int prot, int flags, int fd, off_t offset) { #ifdef __EA64__ if (length > 0xffffffffULL) { errno = ENOMEM; return MAP_FAILED_EADDR; } else { return (__ea void *)mmap_eaddr((unsigned long long)start, (size_t)length, prot, flags, fd, offset); } #else /* __EA32__ */ unsigned long long res; /* * mmap_eaddr returns 64 bits. For ea32, only the lower 32 bits can be * returned. */ res = mmap_eaddr((unsigned long long)(unsigned int)start, length, prot, flags, fd, offset); if (res != MAP_FAILED_EADDR && res > 0xffffffffULL) { munmap_eaddr(res, length); errno = ENOMEM; res = MAP_FAILED_EADDR; } return (__ea void *)(int)res; #endif } picolibc-1.8.11/libc/machine/spu/mremap_ea.c000066400000000000000000000043721513574234600206240ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include "ea_internal.h" #include COMPAT_EA_ALIAS(mremap_ea); __ea void * mremap_ea(__ea void *old_address, size_ea_t old_size, size_ea_t new_size, unsigned long flags) { #ifdef __EA64__ return (__ea void *)mremap_eaddr((unsigned long long)old_address, old_size, new_size, flags); #else /* __EA32__ */ unsigned long long res; res = mremap_eaddr((unsigned long long)(unsigned int)old_address, old_size, new_size, flags); if (res != MAP_FAILED_EADDR && res > 0xffffffffULL) { /* * We cannot reliably undo the successful remap, so unmap the address. */ munmap_eaddr(res, new_size); errno = ENOMEM; res = MAP_FAILED_EADDR; } return (__ea void *)(int)res; #endif } picolibc-1.8.11/libc/machine/spu/msync_ea.c000066400000000000000000000033231513574234600204670ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "ea_internal.h" #include COMPAT_EA_ALIAS(msync_ea); int msync_ea(__ea void *start, size_ea_t length, int flags) { return msync_eaddr((unsigned long long)(size_ea_t)start, length, flags); } picolibc-1.8.11/libc/machine/spu/munmap_ea.c000066400000000000000000000033041513574234600206320ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "ea_internal.h" #include COMPAT_EA_ALIAS(munmap_ea); int munmap_ea(__ea void *start, size_ea_t length) { return munmap_eaddr((unsigned long long)(size_ea_t)start, length); } picolibc-1.8.11/libc/machine/spu/perror.c000066400000000000000000000034661513574234600202120ustar00rootroot00000000000000/* Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "c99ppe.h" typedef struct { const char *str; unsigned int pad0[3]; int arg_errno; unsigned int pad1[3]; } c99_perror_t; void perror(const char *s) { c99_perror_t arg; arg.str = s; arg.arg_errno = errno; __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_PERROR, &arg); return; } picolibc-1.8.11/libc/machine/spu/posix_memalign_ea.c000066400000000000000000000045101513574234600223500ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "ea_internal.h" #include typedef struct { unsigned int memptr; unsigned int pad0[3]; unsigned long long align; unsigned int pad1[2]; unsigned long long size; unsigned int pad2[2]; } memalign_ea_t; COMPAT_EA_ALIAS(posix_memalign_ea); int posix_memalign_ea(__ea void **memptr, size_ea_t align, size_ea_t size) { memalign_ea_t arg; /* * Note that memptr is an LS address that will store an EA address. So, * it fits in 32 bits. * * The assist call will store 32 or 64 bits, depending on whether it's * 32 or 64 bit ppu code. */ arg.memptr = (unsigned int)memptr; arg.align = (unsigned long long)align; arg.size = (unsigned long long)size; return __send_to_ppe(JSRE_LIBEA_SIGNALCODE, SPE_LIBEA_POSIX_MEMALIGN, &arg); } picolibc-1.8.11/libc/machine/spu/pread_ea.c000066400000000000000000000037731513574234600204420ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Ken Werner */ #include #include "ea_internal.h" #include #include #include "sys/linux_syscalls.h" extern void __cache_flush(void) __weak; COMPAT_EA_ALIAS(pread_ea); ssize_ea_t pread_ea(int fd, __ea void *buf, size_ea_t count, off_t offset) { struct spu_syscall_block s = { __NR_pread64, { fd, (size_ea_t)buf, count, offset, 0, 0 } }; /* Flush cache only if the application really uses the software cache. */ if (__cache_flush) __cache_flush(); return __linux_syscall(&s); } picolibc-1.8.11/libc/machine/spu/printf.S000066400000000000000000000040301513574234600201470ustar00rootroot00000000000000/* Copyright (c) 2007, Toshiba Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of Toshiba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "c99ppe.h" .text .align 4 GLOBL printf .type printf, @function printf: stqd $0, 16($sp) /* save caller address */ il $2, 1 /* number of fixed arguments */ brsl $0, __stack_reg_va /* save register to the stack frame */ il $3, SPE_C99_SIGNALCODE il $4, SPE_C99_VPRINTF ai $5, $sp, 16*2 /* data ($3 save address) */ brsl $0, __send_to_ppe il $2, 16*(SPE_STACK_REGS+2+2) a $sp, $sp, $2 lqd $0, 16($sp) /* load caller address */ bi $0 /* return to caller */ .size printf, .-printf picolibc-1.8.11/libc/machine/spu/putc.c000066400000000000000000000036231513574234600176470ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" typedef struct { int ch; unsigned int pad0[3]; int fp; unsigned int pad1[3]; } c99_putc_t; int putc(c, fp) int c; register FILE *fp; { c99_putc_t args; CHECK_INIT(_REENT); args.ch = c; args.fp = fp->_fp; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_PUTC, &args); } picolibc-1.8.11/libc/machine/spu/putchar.c000066400000000000000000000032131513574234600203350ustar00rootroot00000000000000/* Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "c99ppe.h" #undef putchar int putchar(c) int c; { /* c gets overwritten before return */ return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_PUTCHAR, &c); } picolibc-1.8.11/libc/machine/spu/puts.c000066400000000000000000000031761513574234600176720ustar00rootroot00000000000000/* Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "c99ppe.h" int puts(char const *s) { /* The return value gets written over s */ return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_PUTS, &s); } picolibc-1.8.11/libc/machine/spu/pwrite_ea.c000066400000000000000000000040041513574234600206450ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Ken Werner */ #include #include "ea_internal.h" #include #include #include "sys/linux_syscalls.h" extern void __cache_flush(void) __weak; COMPAT_EA_ALIAS(pwrite_ea); ssize_ea_t pwrite_ea(int fd, __ea const void *buf, size_ea_t count, off_t offset) { struct spu_syscall_block s = { __NR_pwrite64, { fd, (size_ea_t)buf, count, offset, 0, 0 } }; /* Flush cache only if the application really uses the software cache. */ if (__cache_flush) __cache_flush(); return __linux_syscall(&s); } picolibc-1.8.11/libc/machine/spu/read_ea.c000066400000000000000000000037431513574234600202570ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Ken Werner */ #include #include "ea_internal.h" #include #include #include "sys/linux_syscalls.h" extern void __cache_flush(void) __weak; COMPAT_EA_ALIAS(read_ea); ssize_ea_t read_ea(int fd, __ea void *buf, size_ea_t count) { struct spu_syscall_block s = { __NR_read, { fd, (size_ea_t)buf, count, 0, 0, 0 } }; /* Flush cache only if the application really uses the software cache. */ if (__cache_flush) __cache_flush(); return __linux_syscall(&s); } picolibc-1.8.11/libc/machine/spu/readv_ea.c000066400000000000000000000043041513574234600204370ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Ken Werner */ #include #include "ea_internal.h" #include #include #include "sys/linux_syscalls.h" extern void __cache_flush(void) __weak; COMPAT_EA_ALIAS(readv_ea); ssize_ea_t readv_ea(int fd, struct iovec_ea *vector, int count) { #ifdef __EA32__ int i; #endif struct spu_syscall_block s = { __NR_readv, { fd, (size_ea_t)(__ea void *)vector, count, 0, 0, 0 } }; #ifdef __EA32__ for (i = 0; i < count; ++i) { vector[i].__pad1 = 0x0; /* 32 bit padding */ vector[i].__pad2 = 0x0; /* 32 bit padding */ } #endif /* Flush cache only if the application really uses the software cache. */ if (__cache_flush) __cache_flush(); return __linux_syscall(&s); } picolibc-1.8.11/libc/machine/spu/realloc_ea.c000066400000000000000000000037751513574234600207720ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "ea_internal.h" #include typedef struct { unsigned long long ptr; unsigned int pad0[2]; unsigned long long size; unsigned int pad1[2]; } realloc_ea_t; COMPAT_EA_ALIAS(realloc_ea); __ea void * realloc_ea(__ea void *ptr, size_ea_t size) { realloc_ea_t args; args.ptr = (unsigned long long)(size_ea_t)ptr; args.size = (unsigned long long)size; __send_to_ppe(JSRE_LIBEA_SIGNALCODE, SPE_LIBEA_REALLOC, &args); return ull_to_eavoid(args.ptr); } picolibc-1.8.11/libc/machine/spu/remove.c000066400000000000000000000033411513574234600201660ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" int remove(filename) const char *filename; { /* The return value gets written over buf */ return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_REMOVE, &filename); } picolibc-1.8.11/libc/machine/spu/rename.c000066400000000000000000000035741513574234600201500ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" typedef struct { const char *old; unsigned int pad0[3]; const char *new; unsigned int pad1[3]; } c99_rename_t; int rename(old, new) const char *old; const char *new; { c99_rename_t args; args.old = old; args.new = new; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_RENAME, &args); } picolibc-1.8.11/libc/machine/spu/rewind.c000066400000000000000000000033211513574234600201570ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" void rewind(FILE *fp) { int ret; CHECK_INIT(_REENT); ret = fp->_fp; __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_REWIND, &ret); return; } picolibc-1.8.11/libc/machine/spu/scanf.S000066400000000000000000000040221513574234600177400ustar00rootroot00000000000000/* Copyright (c) 2007, Toshiba Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of Toshiba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "c99ppe.h" .text .align 4 GLOBL scanf .type scanf, @function scanf: stqd $0, 16($sp) /* save caller address */ il $2, 1 /* number of fixed arguments */ brsl $0, __stack_reg_va /* save register to the stack frame */ il $3, SPE_C99_SIGNALCODE il $4, SPE_C99_VSCANF ai $5, $sp, 16*2 /* data ($3 save address) */ brsl $0, __send_to_ppe il $2, 16*(SPE_STACK_REGS+2+2) a $sp, $sp, $2 lqd $0, 16($sp) /* load caller address */ bi $0 /* return to caller */ .size scanf, .-scanf picolibc-1.8.11/libc/machine/spu/setbuf.c000066400000000000000000000036301513574234600201620ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" typedef struct { int fp; unsigned int pad0[3]; char *buf; unsigned int pad1[3]; } c99_setbuf_t; void setbuf(FILE * __restrict fp, char * __restrict buf) { c99_setbuf_t args; CHECK_INIT(_REENT); args.fp = fp->_fp; args.buf = buf; __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_SETBUF, &args); return; } picolibc-1.8.11/libc/machine/spu/setjmp.S000066400000000000000000000102451513574234600201540ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2005, 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Andreas Neukoetter (ti95neuk@de.ibm.com) */ /* int setjmp( jmp_buf env ); */ #include .text .align 2 .global setjmp .type setjmp, @function setjmp: stqd $80, 2*16($3) stqd $81, 3*16($3) stqd $82, 4*16($3) stqd $83, 5*16($3) stqd $84, 6*16($3) stqd $85, 7*16($3) stqd $86, 8*16($3) stqd $87, 9*16($3) stqd $88, 10*16($3) stqd $89, 11*16($3) stqd $90, 12*16($3) stqd $91, 13*16($3) stqd $92, 14*16($3) stqd $93, 15*16($3) stqd $94, 16*16($3) stqd $95, 17*16($3) stqd $96, 18*16($3) stqd $97, 19*16($3) stqd $98, 20*16($3) stqd $99, 21*16($3) stqd $100, 22*16($3) stqd $101, 23*16($3) stqd $102, 24*16($3) stqd $103, 25*16($3) stqd $104, 26*16($3) stqd $105, 27*16($3) stqd $106, 28*16($3) stqd $107, 29*16($3) stqd $108, 30*16($3) stqd $109, 31*16($3) stqd $110, 32*16($3) stqd $111, 33*16($3) stqd $112, 34*16($3) stqd $113, 35*16($3) stqd $114, 36*16($3) stqd $115, 37*16($3) stqd $116, 38*16($3) stqd $117, 39*16($3) stqd $118, 40*16($3) stqd $119, 41*16($3) hbr setjmp_ret, $0 lnop # pipe1 bubble added for instruction fetch stqd $120, 42*16($3) stqd $121, 43*16($3) stqd $122, 44*16($3) stqd $123, 45*16($3) stqd $124, 46*16($3) stqd $125, 47*16($3) stqd $126, 48*16($3) stqd $127, 49*16($3) stqd $0, 0*16($3) stqd $1, 1*16($3) il $3, 0 setjmp_ret: bi $0 .size setjmp, .-setjmp /* int longjmp( jmp_buf env, int val ); */ .text .align 2 .global longjmp .type longjmp, @function longjmp: lr $127, $1 lqd $0, 0*16($3) lqd $1, 1*16($3) sf $126, $127, $1 rotqbyi $126, $126, 12 fsmbi $127, 0x0F00 and $126, $126, $127 a $1, $1, $126 # restore all the non-volatile registers lqd $80, 2*16($3) lqd $81, 3*16($3) lqd $82, 4*16($3) lqd $83, 5*16($3) lqd $84, 6*16($3) lqd $85, 7*16($3) lqd $86, 8*16($3) lqd $87, 9*16($3) lqd $88, 10*16($3) lqd $89, 11*16($3) lqd $90, 12*16($3) lqd $91, 13*16($3) lqd $92, 14*16($3) lqd $93, 15*16($3) lqd $94, 16*16($3) lqd $95, 17*16($3) lqd $96, 18*16($3) lqd $97, 19*16($3) lqd $98, 20*16($3) lqd $99, 21*16($3) lqd $100, 22*16($3) lqd $101, 23*16($3) lqd $102, 24*16($3) lqd $103, 25*16($3) lqd $104, 26*16($3) lqd $105, 27*16($3) lqd $106, 28*16($3) lqd $107, 29*16($3) lqd $108, 30*16($3) lqd $109, 31*16($3) hbr longjmp_ret, $0 lqd $110, 32*16($3) lqd $111, 33*16($3) lqd $112, 34*16($3) lqd $113, 35*16($3) lqd $114, 36*16($3) lqd $115, 37*16($3) lqd $116, 38*16($3) lqd $117, 39*16($3) lqd $118, 40*16($3) lqd $119, 41*16($3) lqd $120, 42*16($3) lqd $121, 43*16($3) lqd $122, 44*16($3) lqd $123, 45*16($3) lqd $124, 46*16($3) lqd $125, 47*16($3) ceqi $5, $4, 0 lqd $126, 48*16($3) lqd $127, 49*16($3) sf $3, $5, $4 longjmp_ret: bi $0 .size longjmp, .-longjmp picolibc-1.8.11/libc/machine/spu/setvbuf.c000066400000000000000000000040421513574234600203460ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" typedef struct { int fp; unsigned int pad0[3]; char *buf; unsigned int pad1[3]; int mode; unsigned int pad2[3]; size_t size; unsigned int pad3[3]; } c99_setvbuf_t; int setvbuf(FILE *fp, char *buf, int mode, size_t size) { c99_setvbuf_t args; CHECK_INIT(_REENT); args.fp = fp->_fp; args.buf = buf; args.mode = mode; args.size = size; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_SETVBUF, &args); } picolibc-1.8.11/libc/machine/spu/siprintf.S000066400000000000000000000031051513574234600205050ustar00rootroot00000000000000/* Copyright (c) 2007, Toshiba Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of Toshiba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #define sprintf siprintf #include "sprintf.S" picolibc-1.8.11/libc/machine/spu/siscanf.S000066400000000000000000000031021513574234600202720ustar00rootroot00000000000000/* Copyright (c) 2007, Toshiba Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of Toshiba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #define sscanf siscanf #include "sscanf.S" picolibc-1.8.11/libc/machine/spu/sleep.c000066400000000000000000000007431513574234600200040ustar00rootroot00000000000000/* Copyright (c) 2008 Patrick Mansfield */ /* Copied from libc/posix/sleep.c, removed the check for HAVE_NANOSLEEP */ /* Written 2000 by Werner Almesberger */ #include #include #include #include unsigned sleep(unsigned seconds) { struct timespec ts; ts.tv_sec = seconds; ts.tv_nsec = 0; if (!nanosleep(&ts, &ts)) return 0; if (errno == EINTR) return ts.tv_sec; return -1; } picolibc-1.8.11/libc/machine/spu/sniprintf.S000066400000000000000000000031101513574234600206570ustar00rootroot00000000000000/* Copyright (c) 2007, Toshiba Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of Toshiba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #define snprintf sniprintf #include "snprintf.S" picolibc-1.8.11/libc/machine/spu/snprintf.S000066400000000000000000000040441513574234600205150ustar00rootroot00000000000000/* Copyright (c) 2007, Toshiba Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of Toshiba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "c99ppe.h" .text .align 4 GLOBL snprintf .type snprintf, @function snprintf: stqd $0, 16($sp) /* save caller address */ il $2, 3 /* number of fixed arguments */ brsl $0, __stack_reg_va /* save register to the stack frame */ il $3, SPE_C99_SIGNALCODE il $4, SPE_C99_VSNPRINTF ai $5, $sp, 16*2 /* data ($3 save address) */ brsl $0, __send_to_ppe il $2, 16*(SPE_STACK_REGS+2+2) a $sp, $sp, $2 lqd $0, 16($sp) /* load caller address */ bi $0 /* return to caller */ .size snprintf, .-snprintf picolibc-1.8.11/libc/machine/spu/sprintf.S000066400000000000000000000040361513574234600203400ustar00rootroot00000000000000/* Copyright (c) 2007, Toshiba Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of Toshiba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "c99ppe.h" .text .align 4 GLOBL sprintf .type sprintf, @function sprintf: stqd $0, 16($sp) /* save caller address */ il $2, 2 /* number of fixed arguments */ brsl $0, __stack_reg_va /* save register to the stack frame */ il $3, SPE_C99_SIGNALCODE il $4, SPE_C99_VSPRINTF ai $5, $sp, 16*2 /* data ($3 save address) */ brsl $0, __send_to_ppe il $2, 16*(SPE_STACK_REGS+2+2) a $sp, $sp, $2 lqd $0, 16($sp) /* load caller address */ bi $0 /* return to caller */ .size sprintf, .-sprintf picolibc-1.8.11/libc/machine/spu/spu-gmon.c000066400000000000000000000315741513574234600204470ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Ken Werner */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* Magic cookie. */ #define GMON_MAGIC_COOKIE "gmon" /* Version number. */ #define GMON_VERSION 1 /* Fraction of text space to allocate for histogram counters. */ #define HISTFRACTION 4 /* Histogram counter type. */ #define HISTCOUNTER unsigned short /* Fraction of text space to allocate for "from" hash buckets. HASHFRACTION is based on the minimum number of bytes of separation between two subroutine call points in the object code. */ #define HASHFRACTION 4 /* Percent of text space to allocate for tostructs with a minimum. */ #define ARCDENSITY 3 /* Minimal amount of arcs. */ #define MINARCS 50 /* Rounding macros. */ #define ROUNDDOWN(x, y) (((x) / (y)) * (y)) #define ROUNDUP(x, y) ((((x) + (y) - 1) / (y)) * (y)) /* Sampling rate in Hertz. */ #define SAMPLE_INTERVAL 100 /* Tag definitions for the gmon.out sub headers. */ #define GMON_TAG_TIME_HIST 0 #define GMON_TAG_CG_ARC 1 struct tostruct { uintptr_t selfpc; long count; unsigned short link; }; struct gmon_hdr { char cookie[4]; int32_t version; char spare[3 * 4]; }; struct gmon_hist_hdr { uintptr_t low_pc; uintptr_t high_pc; int32_t hist_size; int32_t prof_rate; char dimen[15]; char dimen_abbrev; } __attribute__((packed)); struct rawarc { uintptr_t raw_frompc; uintptr_t raw_selfpc; long raw_count; } __attribute__((packed)); /* start and end of the text section */ extern char _start; extern char _etext; /* EAR entry for the starting address of SPE executable image. */ extern const unsigned long long _EAR_; __asm__(".section .toe,\"a\",@nobits\n\r" ".align 4\n\r" ".type _EAR_, @object\n\r" ".size _EAR_, 16\n" "_EAR_: .space 16\n" ".previous"); /* froms are indexing tos */ static __ea unsigned short *froms; static __ea struct tostruct *tos = 0; static long tolimit = 0; static uintptr_t s_lowpc = 0; static uintptr_t s_highpc = 0; static unsigned long s_textsize = 0; static int fd; static int hist_size; static int timer_id; void __sample(int id) { unsigned int pc; unsigned int pc_backup; off_t offset; unsigned short val; if (id != timer_id) return; /* Fetch program counter. */ pc = spu_read_srr0() & ~3; pc_backup = pc; if (pc < s_lowpc || pc > s_highpc) return; pc -= (uintptr_t)&_start; offset = pc / HISTFRACTION * sizeof(HISTCOUNTER) + sizeof(struct gmon_hdr) + 1 + sizeof(struct gmon_hist_hdr); /* Read, increment and write the counter. */ if (pread(fd, &val, 2, offset) != 2) { perror("can't read the histogram"); return; } if (val < USHRT_MAX) ++val; if (pwrite(fd, &val, 2, offset) != 2) { perror("can't write the histogram"); } } static void write_histogram(int fd) { struct gmon_hist_hdr hist_hdr; u_char tag = GMON_TAG_TIME_HIST; hist_hdr.low_pc = s_lowpc; hist_hdr.high_pc = s_highpc; hist_hdr.hist_size = hist_size / sizeof(HISTCOUNTER); /* Amount of bins. */ hist_hdr.prof_rate = 100; /* Hertz. */ strncpy(hist_hdr.dimen, "seconds", sizeof(hist_hdr.dimen)); hist_hdr.dimen_abbrev = 's'; struct iovec iov[2] = { { &tag, sizeof(tag) }, { &hist_hdr, sizeof(struct gmon_hist_hdr) } }; if (writev(fd, iov, 2) != sizeof(struct gmon_hist_hdr) + sizeof(tag)) perror("can't write the histogram header"); /* Skip the already written histogram data. */ lseek(fd, hist_size, SEEK_CUR); } static void write_callgraph(int fd) { int fromindex, endfrom; uintptr_t frompc; int toindex; struct rawarc rawarc; u_char tag = GMON_TAG_CG_ARC; endfrom = s_textsize / (HASHFRACTION * sizeof(*froms)); for (fromindex = 0; fromindex < endfrom; ++fromindex) { if (froms[fromindex]) { frompc = s_lowpc + (fromindex * HASHFRACTION * sizeof(*froms)); for (toindex = froms[fromindex]; toindex != 0; toindex = tos[toindex].link) { rawarc.raw_frompc = frompc; rawarc.raw_selfpc = tos[toindex].selfpc; rawarc.raw_count = tos[toindex].count; struct iovec iov[2] = { { &tag, sizeof(tag) }, { &rawarc, sizeof(struct rawarc) } }; if (writev(fd, iov, 2) != sizeof(tag) + sizeof(struct rawarc)) perror("can't write the callgraph"); } } } } void __mcleanup(void) { struct gmon_hdr ghdr; /* Disable sampling. */ spu_timer_stop(timer_id); spu_timer_free(timer_id); spu_clock_stop(); /* Jump to the beginning of the gmon.out file. */ if (lseek(fd, 0, SEEK_SET) == -1) { perror("Cannot seek to the beginning of the gmon.out file."); close(fd); return; } /* Write the gmon.out header. */ memset(&ghdr, '\0', sizeof(struct gmon_hdr)); memcpy(&ghdr.cookie[0], GMON_MAGIC_COOKIE, sizeof(ghdr.cookie)); ghdr.version = GMON_VERSION; if (write(fd, &ghdr, sizeof(struct gmon_hdr)) == -1) { perror("Cannot write the gmon header to the gmon.out file."); close(fd); return; } /* Write the sampling buffer (histogram). */ write_histogram(fd); /* Write the call graph. */ write_callgraph(fd); close(fd); } void __monstartup(unsigned long long spu_id) { char filename[64]; s_lowpc = ROUNDDOWN((uintptr_t)&_start, HISTFRACTION * sizeof(HISTCOUNTER)); s_highpc = ROUNDUP((uintptr_t)&_etext, HISTFRACTION * sizeof(HISTCOUNTER)); s_textsize = s_highpc - s_lowpc; hist_size = s_textsize / HISTFRACTION * sizeof(HISTCOUNTER); /* Allocate froms. */ froms = malloc_ea(s_textsize / HASHFRACTION); if (froms == NULL) { fprintf(stderr, "Cannot allocate ea memory for the froms array.\n"); return; } memset_ea(froms, 0, s_textsize / HASHFRACTION); /* Determine tolimit. */ tolimit = s_textsize * ARCDENSITY / 100; if (tolimit < MINARCS) tolimit = MINARCS; /* Allocate tos. */ tos = malloc_ea(tolimit * sizeof(struct tostruct)); if (tos == NULL) { fprintf(stderr, "Cannot allocate ea memory for the tos array.\n"); return; } memset_ea(tos, 0, tolimit * sizeof(struct tostruct)); /* Determine the gmon.out file name. */ if (spu_id) snprintf(filename, sizeof(filename), "gmon-%d-%llu-%llu.out", linux_getpid(), spu_id, _EAR_); else strncpy(filename, "gmon.out", sizeof(filename)); /* Open the gmon.out file. */ fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0644); if (fd == -1) { char errstr[128]; snprintf(errstr, sizeof(errstr), "Cannot open file: %s", filename); perror(errstr); return; } /* Truncate the file up to the size where the histogram fits in. */ if (ftruncate(fd, sizeof(struct gmon_hdr) + 1 + sizeof(struct gmon_hist_hdr) + hist_size) == -1) { char errstr[128]; snprintf(errstr, sizeof(errstr), "Cannot truncate file: %s", filename); perror(errstr); return; } /* Start the histogram sampler. */ spu_slih_register(MFC_DECREMENTER_EVENT, spu_clock_slih); timer_id = spu_timer_alloc(spu_timebase() / SAMPLE_INTERVAL, __sample); spu_clock_start(); spu_timer_start(timer_id); atexit(__mcleanup); } void __mcount_internal(uintptr_t frompc, uintptr_t selfpc) { /* sefpc: the address of the function just entered. */ /* frompc: the caller of the function just entered. */ unsigned int mach_stat; __ea unsigned short *frompcindex; unsigned short toindex; __ea struct tostruct *top; __ea struct tostruct *prevtop; /* Save current state and disable interrupts. */ mach_stat = spu_readch(SPU_RdMachStat); spu_idisable(); /* Sanity checks. */ if (frompc < s_lowpc || frompc > s_highpc) goto done; frompc -= s_lowpc; if (frompc > s_textsize) goto done; /* frompc indexes into the froms array the value at that position indexes into the tos array. */ frompcindex = &froms[(frompc) / (HASHFRACTION * sizeof(*froms))]; toindex = *frompcindex; if (toindex == 0) { /* First time traversing this arc link of tos[0] incremented. */ toindex = ++tos[0].link; /* Sanity check. */ if (toindex >= tolimit) { --tos[0].link; goto done; } /* Save the index into the froms array for the next time we traverse this arc. */ *frompcindex = toindex; top = &tos[toindex]; /* Sets the address of the function just entered. */ top->selfpc = selfpc; top->count = 1; top->link = 0; goto done; } /* toindex points to a tostruct */ top = &tos[toindex]; if (top->selfpc == selfpc) { /* The arc is at front of the chain. This is the most common case. */ top->count++; goto done; } /* top->selfpc != selfpc The pc we have got is not the pc we already stored (i.e. multiple function calls to the same fuction within a function. The arc is not at front of the chain. */ for (;;) { if (top->link == 0) { /* We are at the end of the chain and selfpc was not found. Thus we create a new tostruct and link it to the head of the chain. */ toindex = ++tos[0].link; /* Sanity check. */ if (toindex >= tolimit) { --tos[0].link; goto done; } top = &tos[toindex]; top->selfpc = selfpc; top->count = 1; /* Link back to the old tos entry. */ top->link = *frompcindex; /* Store a link to the new top in the froms array which makes the current tos head of the chain. */ *frompcindex = toindex; goto done; } else { /* Otherwise check the next arc on the chain. */ prevtop = top; top = &tos[top->link]; if (top->selfpc == selfpc) { /* selfpc matches; increment its count. */ top->count++; /* Move it to the head of the chain. */ /* Save previous tos index. */ toindex = prevtop->link; /* Link the former to to the current tos. */ prevtop->link = top->link; /* Link back to the old tos entry. */ top->link = *frompcindex; /* Store a link to the new top in the froms array which makes the current tos head of the chain. */ *frompcindex = toindex; goto done; } } } done: /* Enable interrupts if necessary. */ if (__builtin_expect(mach_stat & 1, 0)) spu_ienable(); } picolibc-1.8.11/libc/machine/spu/spu-mcount.S000066400000000000000000000072051513574234600207660ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Ken Werner */ /* _mcount extracts the address of the function just entered and the address of the caller of that function and then calls __mcount_internal. The prologue calls mcount without saving any registers. The return address is stored in $75. The _mcount function has to: - create a new stack frame - save registers $2 to $75 on the stack - copy the two addresses ($0 and $75) into the argument registers $3 and $4 - call __mcount_internal - restore registers - return to $75 */ /* The following two convenience macros assist in the coding of the saving and restoring the register. saveregs first, last Saves registers from first to the last. restoreregs first, last Restores registers from last down to first. Note: first must be less than or equal to last. */ #include .macro saveregs first, last stqd $\first, \first*16($SP) .if \last-\first saveregs "(\first+1)",\last .endif .endm .macro restoreregs first, last lqd $\last, \last*16($SP) .if \last-\first restoreregs \first,"(\last-1)" .endif .endm /* _mcount needs to be resident since the overlay manager uses the scratch registers too. */ .text .align 3 /* 8 byte alignment. */ .global _mcount .type _mcount, @function _mcount: stqd $lr, 16($sp) /* Save link register in the callers stack frame. */ stqd $lr, -1216($sp) /* Store back pointer. */ il $lr, -1216 /* Push a new stack frame. */ a $sp, $sp, $lr /* Frame size: 16 * (74 + 2) = 1216. */ /* Save registers $2 to $75 on the stack. */ saveregs 2, 75 /* Bring the __mcount_internal arguments in place. */ lqd $3, 1232($sp) /* frompc (the link register). */ ori $4, $75, 0 /* selfpc (the gcc prologue puts "brsl $75, _mcount" in front of every function). */ brsl $lr, __mcount_internal /* Restore register $2 to $75 from the stack. */ restoreregs 2, 75 il $lr, 1216 a $sp, $sp, $lr /* Pop the stack frame. */ lqd $lr, 16($sp) /* Restore link register. */ bi $75 /* Branch to the called function. */ picolibc-1.8.11/libc/machine/spu/spu_clock_stop.c000066400000000000000000000050731513574234600217240ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* SPU clock stop library service. */ #include #include #include "spu_timer_internal.h" /* Stops the SPU clock: * decrements clock start count * when count is zero, disables the decrementer event and stops the decrementer Returns 0 on success and <0 on failure: * SPU_CLOCK_ERR_NOT_RUNNING - clock was already off * SPU_CLOCK_ERR_TIMERS_ACTIVE - active timers exist * SPU_CLOCK_ERR_STILL_RUNNING - start count was decremented but clock was not stopped */ int spu_clock_stop(void) { if (__spu_clock_startcnt == 0) return SPU_CLOCK_ERR_NOT_RUNNING; if (__spu_clock_startcnt == 1 && (__spu_timers_active || __spu_timers_handled)) return SPU_CLOCK_ERR_TIMERS_ACTIVE; /* Don't stop clock if the clock is still in use. */ if (--__spu_clock_startcnt != 0) return SPU_CLOCK_ERR_STILL_RUNNING; /* Clock stopped, stop decrementer. */ __disable_spu_decr(); /* Clock is enabled on clock start - restore to original state (saved at start). */ if (__likely(!__spu_clock_state_was_enabled)) { spu_idisable(); } return 0; } picolibc-1.8.11/libc/machine/spu/spu_clock_svcs.c000066400000000000000000000063121513574234600217120ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* SPU clock start and read library services. */ #include #include #include "spu_timer_internal.h" /* The software managed timebase value. */ volatile uint64_t __spu_tb_val __aligned(16); /* Timeout value of the current interval. */ volatile int __spu_tb_timeout __aligned(16); /* Clock start count (clock is running if >0). */ volatile unsigned __spu_clock_startcnt __aligned(16); /* Saved interrupt state from clock_start. */ volatile unsigned __spu_clock_state_was_enabled; /* Initializes the software managed timebase, enables the decrementer event, starts the decrementer and enables interrupts. Must be called before clock or timer services can be used. Should only be called by base app/lib code (not from an interrupt/timer handler). Returns with interrupts ENABLED. */ void spu_clock_start(void) { /* Increment clock start and return if it was already running. */ if (++__spu_clock_startcnt > 1) return; __spu_clock_state_was_enabled = spu_readch(SPU_RdMachStat) & 0x1; spu_idisable(); __spu_tb_timeout = CLOCK_START_VALUE; __spu_tb_val = 0; /* Disable, write, enable the decrementer. */ __enable_spu_decr(__spu_tb_timeout, __disable_spu_decr()); spu_ienable(); return; } /* Returns a monotonically increasing, 64-bit counter, in timebase units, relative to the last call to spu_clock_start(). */ uint64_t spu_clock_read(void) { int64_t time; unsigned was_enabled; /* Return 0 if clock is off. */ if (__spu_clock_startcnt == 0) return 0LL; was_enabled = spu_readch(SPU_RdMachStat) & 0x1; spu_idisable(); time = __spu_tb_val + (__spu_tb_timeout - spu_readch(SPU_RdDec)); if (__likely(was_enabled)) spu_ienable(); return time; } picolibc-1.8.11/libc/machine/spu/spu_timebase.c000066400000000000000000000035771513574234600213640ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include /* This function queries /proc/cpuinfo and returns the SPU time base in Hertz. */ unsigned int spu_timebase(void) { FILE *f; unsigned tb = 0; char line[64]; if ((f = fopen("/proc/cpuinfo", "r"))) { while (fgets(line, sizeof(line), f)) if (sscanf(line, "timebase : %u", &tb)) break; fclose(f); } return (tb); } picolibc-1.8.11/libc/machine/spu/spu_timer_flih.S000066400000000000000000000142131513574234600216620ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* First-level interrupt handler. */ /* The following two convenience macros assist in the coding of the saving and restoring the volatile register starting from register 2 up to register 79. saveregs first, last Saves registers from first to the last. restoreregs first, last Restores registers from last down to first. Note: first must be less than or equal to last. */ #include .macro saveregs first, last stqd $\first, -(STACK_SKIP+\first)*16($SP) .if \last-\first saveregs "(\first+1)",\last .endif .endm .macro restoreregs first, last lqd $\last, (82-\last)*16($SP) .if \last-\first restoreregs \first,"(\last-1)" .endif .endm .section .interrupt,"ax" .align 3 .type spu_flih, @function spu_flih: /* Adjust the stack pointer to skip the maximum register save area (STACK_SKIP quadword registers) in case an interrupt occurred while executing a leaf function that used the stack area without actually allocating its own stack frame. */ .set STACK_SKIP, 125 /* Save the current link register on a new stack frame for the normal spu_flih() version of this file. */ stqd $0, -(STACK_SKIP+80)*16($SP) stqd $SP, -(STACK_SKIP+82)*16($SP) /* Save back chain pointer. */ saveregs 2, 39 il $2, -(STACK_SKIP+82)*16 /* Stack frame size. */ rdch $3, $SPU_RdEventStat /* Read event status. */ rdch $6, $SPU_RdEventMask /* Read event mask. */ hbrp /* Open a slot for instruction prefetch. */ saveregs 40,59 clz $4, $3 /* Get first slih index. */ stqd $6, -(STACK_SKIP+1)*16($SP) /* Save event mask on stack. */ saveregs 60, 67 /* Do not disable/ack the decrementer event here. The timer library manages this and expects it to be enabled upon entry to the SLIH. */ il $7, 0x20 andc $5, $3, $7 andc $7, $6, $5 /* Clear event bits. */ saveregs 68, 69 wrch $SPU_WrEventAck, $3 /* Ack events(s) - include decrementer event. */ wrch $SPU_WrEventMask, $7 /* Disable event(s) - exclude decrementer event. */ saveregs 70, 79 a $SP, $SP, $2 /* Instantiate flih stack frame. */ next_event: /* Fetch and dispatch the event handler for the first non-zero event. The dispatch handler is indexed into the __spu_slih_handlers array using the count of zero off the event status as an index. */ ila $5, __spu_slih_handlers /* Slih array offset. */ shli $4, $4, 2 /* Slih entry offset. */ lqx $5, $4, $5 /* Load slih address. */ rotqby $5, $5, $4 /* Rotate to word 0. */ bisl $0, $5 /* Branch to slih. */ clz $4, $3 /* Get next slih index. */ brnz $3, next_event lqd $2, 81*16($SP) /* Read event mask from stack. */ restoreregs 40, 79 wrch $SPU_WrEventMask, $2 /* Restore event mask. */ hbrp /* Open a slot for instruction pre-fetch. */ restoreregs 2, 39 /* Restore the link register from the new stack frame for the normal spu_flih() version of this file. */ lqd $0, 2*16($SP) lqd $SP, 0*16($SP) /* restore stack pointer from back chain ptr. */ irete /* Return from interrupt and re-enable interrupts. */ .size spu_flih, .-spu_flih /* spu_slih_handlers[] Here we initialize 33 default event handlers. The first entry in this array corresponds to the event handler for the event associated with bit 0 of Channel 0 (External Event Status). The 32nd entry in this array corresponds to bit 31 of Channel 0 (DMA Tag Status Update Event). The 33rd entry in this array is a special case entry to handle "phantom events" which occur when the channel count for Channel 0 is 1, causing an asynchronous SPU interrupt, but the value returned for a read of Channel 0 is 0. The index calculated into this array by spu_flih() for this case is 32, hence the 33rd entry. */ .data .align 4 .extern __spu_default_slih .global __spu_slih_handlers .type __spu_slih_handlers, @object __spu_slih_handlers: .rept 33 .long __spu_default_slih .endr .size __spu_slih_handlers, .-__spu_slih_handlers picolibc-1.8.11/libc/machine/spu/spu_timer_free.c000066400000000000000000000055751513574234600217140ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* SPU timer free library service. */ #include #include #include "spu_timer_internal.h" /* Frees an allocated timer. The timer must be in the stopped state for this to succeed. Maybe be called: * after allocated, before it's started * after it's been explicitly stopped Returns 0 on success, timer sucessfully deallocated. Returns <0 on failure * SPU_TIMER_INVALID_ID - id out of range * SPU_TIMER_ERR_FREE - id in free state * SPU_TIMER_ERR_ACTIVE - id in handled or active state */ int spu_timer_free(int id) { spu_timer_t *t, **pn; unsigned was_enabled; if (id < 0 || id >= SPU_TIMER_NTIMERS) return SPU_TIMER_ERR_INVALID_ID; if (__spu_timers[id].state == SPU_TIMER_STOPPED) { was_enabled = spu_readch(SPU_RdMachStat) & 0x1; spu_idisable(); t = __spu_timers_stopped; pn = &__spu_timers_stopped; while (t && (t->id != id)) { pn = &t->next; t = t->next; } #ifdef SPU_TIMER_DEBUG if (!t) ABORT(); #endif *pn = t->next; /* Add timer back to free list (mask). */ __spu_timers_avail |= (1 << (id)); __spu_timers[id].state = SPU_TIMER_FREE; if (__likely(was_enabled)) spu_ienable(); return 0; } /* Handle invalid states. */ return (__spu_timers[id].state == SPU_TIMER_FREE) ? SPU_TIMER_ERR_FREE : SPU_TIMER_ERR_ACTIVE; } picolibc-1.8.11/libc/machine/spu/spu_timer_internal.h000066400000000000000000000112731513574234600226040ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Internal definitions for SPU timer library. */ #ifndef _SPU_TIMER_INTERNAL_H_ #define _SPU_TIMER_INTERNAL_H_ #include #include #include #include #ifdef SPU_TIMER_DEBUG #include #include #endif /* The timer state tells which list its on. */ typedef enum spu_timer_state { SPU_TIMER_FREE = 0, SPU_TIMER_ACTIVE = 1, SPU_TIMER_HANDLED = 2, SPU_TIMER_STOPPED = 3 } spu_timer_state_t; typedef struct spu_timer { int tmout __aligned(16); /* Time until expiration (tb). */ int intvl __aligned(16); /* Interval. */ int id __aligned(16); spu_timer_state_t state __aligned(16); void (*func)(int) __aligned(16); /* Handler. */ struct spu_timer *next __aligned(16); } spu_timer_t; /* Max decrementer value. */ #define DECR_MAX 0xFFFFFFFFU /* Arbitrary non-triggering value. */ #define CLOCK_START_VALUE 0x7FFFFFFF #define MIN_INTVL 1 #define MAX_INTVL INT_MAX /* Timers within 15 tics will expire together. */ #define TIMER_INTERVAL_WINDOW 15 /* Disables the decrementer and returns the saved event mask for a subsequent call to __enable_spu_decr. The decrementer interrupt is acknowledged in the flih when the event is received, but is required also as part of the procedure to stop the decrementer. */ static inline unsigned __disable_spu_decr(void) { unsigned mask = spu_readch(SPU_RdEventMask); spu_writech(SPU_WrEventMask, mask & ~MFC_DECREMENTER_EVENT); spu_writech(SPU_WrEventAck, MFC_DECREMENTER_EVENT); spu_sync_c(); return mask; } /* Writes and enables the decrementer, along with the given event mask. */ static inline void __enable_spu_decr(int val, unsigned mask) { spu_writech(SPU_WrDec, (val)); spu_writech(SPU_WrEventMask, mask | MFC_DECREMENTER_EVENT); spu_sync_c(); } /* These are shared between modules but are not inlined, to save space. */ extern void __spu_timer_start(int id, int reset); extern void __reset_spu_decr(int val); /* The timers. */ extern spu_timer_t __spu_timers[]; /* Active timer list. */ extern spu_timer_t *__spu_timers_active; /* Stopped (allocated) timer list. */ extern spu_timer_t *__spu_timers_stopped; /* List of timers being handled. */ extern spu_timer_t *__spu_timers_handled; /* Bitmask of available timers. */ extern unsigned __spu_timers_avail; /* The software managed timebase value. */ extern volatile uint64_t __spu_tb_val; /* Timeout value of the current interval. */ extern volatile int __spu_tb_timeout; /* Clock start count (clock is running if >0). */ extern volatile unsigned __spu_clock_startcnt; /* Saved interrupt state from clock_start. */ extern volatile unsigned __spu_clock_state_was_enabled; #define __likely(_c) __builtin_expect((_c), 1) #define __unlikely(_c) __builtin_expect((_c), 0) #define ABORT() \ { \ fprintf(stderr, "Internal error, aborting: %s:%d\n", __FILE__, __LINE__); \ assert(0); \ } #endif picolibc-1.8.11/libc/machine/spu/spu_timer_slih.c000066400000000000000000000210671513574234600217240ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Second Level Interrupt handler and related services for SPU timers. */ #include #include "spu_timer_internal.h" /* Resets decrementer to the specified value. Also updates software timebase to account for the time between the last decrementer reset and now. There are two cases: * Called by application to start a new timer. * Called by spu_clock to active the next timer. In both cases, the amount of time is the current interval timeout minus the current decrementer value. */ void __reset_spu_decr(int val) { /* The interrupt occurs when the msb goes from 0 to 1 or when the decrementer goes from 0 to -1. To be precisely accurate we should set the timer to the intverval -1, unless the interval passed in is 0 in which case it should be left at 0. */ int enable_val = (__likely(val)) ? val - 1 : 0; /* Decrementer must be stopped before writing it - minimize the time stopped. */ unsigned mask = __disable_spu_decr(); /* Perform tb correction before resettting the decrementer. the corrected value is the current timeout value minus the current decrementer value. Occasionally the read returns 0 - a second read will clear this condition. */ spu_readch(SPU_RdDec); int decval = spu_readch(SPU_RdDec); /* Restart decrementer with next timeout val. */ __enable_spu_decr(enable_val, mask); /* Update the timebase values before enabling for interrupts. */ __spu_tb_val += __spu_tb_timeout - decval; __spu_tb_timeout = enable_val; } /* Update software timebase and timeout value for the 'next to expire' timer. Called when starting a new timer so the timer list will have timeouts relative to the current time. */ static inline void __update_spu_tb_val(void) { int elapsed = __spu_tb_timeout - spu_readch(SPU_RdDec); #ifdef SPU_TIMER_DEBUG if (elapsed < 0) ABORT(); #endif __spu_tb_val += elapsed; /* Adjust the timeout for the timer next to expire. Note this could cause the timeout to go negative, if it was just about to expire when we called spu_timer_start. This is OK, since this can happen any time interrupts are disabled. We just schedule an immediate timeout in this case. */ if (__spu_timers_active) { __spu_timers_active->tmout -= elapsed; if (__spu_timers_active->tmout < 0) __spu_timers_active->tmout = 0; } } /* Add an allocated timer to the active list. The active list is sorted by timeout value. The timer at the head of the list is the timer that will expire next. The rest of the timers have a timeout value that is relative to the timer ahead of it on the list. This relative value is determined here, when the timer is added to the active list. When its position in the list is found, the timer's timeout value is set to its interval minus the sum of all the timeout values ahead of it. The timeout value for the timer following the newly added timer is then adjusted to a new relative value. If the newly added timer is at the head of the list, the decrementer is reset. This function is called by SLIH to restart multiple timers (reset == 0) or by spu_timer_start() to start a single timer (reset == 1). */ void __spu_timer_start(int id, int reset) { spu_timer_t *t; spu_timer_t **pn; spu_timer_t *start = &__spu_timers[id]; unsigned tmout_time = 0; unsigned my_intvl = start->intvl; unsigned was_enabled = spu_readch(SPU_RdMachStat) & 0x1; spu_idisable(); t = __spu_timers_active; pn = &__spu_timers_active; /* If the active list is empty, just add the timer with the timeout set to the interval. Otherwise find the place in the list for the timer, setting its timeout to its interval minus the sum of timeouts ahead of it. */ start->state = SPU_TIMER_ACTIVE; if (__likely(!t)) { __spu_timers_active = start; start->next = NULL; start->tmout = my_intvl; } else { /* Update swtb and timeout val of the next timer, so all times are relative to now. */ if (reset) __update_spu_tb_val(); while (t && (my_intvl >= (tmout_time + t->tmout))) { tmout_time += t->tmout; pn = &t->next; ; t = t->next; } start->next = t; start->tmout = my_intvl - tmout_time; *pn = start; /* Adjust timeout for timer after us. */ if (t) t->tmout -= start->tmout; } if (reset && (__spu_timers_active == start)) __reset_spu_decr(__spu_timers_active->tmout); if (__unlikely(was_enabled)) spu_ienable(); } /* SLIH for decrementer. Manages software timebase and timers. Called by SPU FLIH. Assumes decrementer is still running (event not yet acknowledeged). */ unsigned int spu_clock_slih(unsigned status) { int decr_reset_val; spu_timer_t *active, *handled; unsigned was_enabled = spu_readch(SPU_RdMachStat) & 0x1; status &= ~MFC_DECREMENTER_EVENT; spu_idisable(); /* The decrementer has now expired. The decrementer event was acknowledged in the FLIH but not disabled. The decrementer will continue to run while we're running the clock/timer handler. The software clock keeps running, and accounts for all the time spent running handlers. Add the current timeout to the software timebase and set the timeout to DECR_MAX. This allows the "clock read" code to continue to work while we're in here, and gives us the most possible time to finish before another underflow. */ __spu_tb_val += __spu_tb_timeout; __spu_tb_timeout = DECR_MAX; /* For all timers that have the current timeout value, move them from the active list to the handled list and call their handlers. Note that the handled/stopped lists may be manipulated by the handlers if they wish to stop/free the timers. Note that only the first expired timer will reflect the real timeout value; the rest of the timers that had the same timeout value will have a relative value of zero. */ if (__spu_timers_active) { __spu_timers_active->tmout = 0; while ((active = __spu_timers_active) && (active->tmout <= TIMER_INTERVAL_WINDOW)) { __spu_timers_active = active->next; active->next = __spu_timers_handled; __spu_timers_handled = active; active->state = SPU_TIMER_HANDLED; (*active->func)(active->id); } } /* put the handled timers back on the list and restart decrementer. */ while ((handled = __spu_timers_handled) != NULL) { __spu_timers_handled = handled->next; __spu_timer_start(handled->id, 0); } /* Reset the decrementer before returning. If we have any active timers, we set it to the timeout value for the timer at the head of the list, else the default clock value. */ decr_reset_val = __spu_timers_active ? __spu_timers_active->tmout : CLOCK_START_VALUE; __reset_spu_decr(decr_reset_val); if (__likely(was_enabled)) spu_ienable(); return status; } picolibc-1.8.11/libc/machine/spu/spu_timer_slih_reg.c000066400000000000000000000052561513574234600225630ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Services for SLIH registration. */ #include #include #include #define SPU_EVENT_ID(_mask) (spu_extract(spu_cntlz(spu_promote(_mask, 0)), 0)) typedef unsigned (*spu_slih_t)(unsigned); extern spu_slih_t __spu_slih_handlers[]; /* This function is called whenever an event occurs for which no second level event handler was registered. The default event handler does nothing and zeros the most significant event bit indicating that the event was processed (when in reality, it was discarded). */ unsigned __spu_default_slih(unsigned events) { unsigned int mse; mse = 0x80000000 >> SPU_EVENT_ID(events); events &= ~mse; return (events); } /* Registers a SPU second level interrupt handler for the events specified by mask. The event mask consists of a set of bits corresponding to the event status bits (see channel 0 description). A mask containing multiple 1 bits will set the second level event handler for each of the events. */ void spu_slih_register(unsigned mask, spu_slih_t func) { unsigned int id; while (mask) { id = SPU_EVENT_ID(mask); __spu_slih_handlers[id] = (func) ? func : __spu_default_slih; mask &= ~(0x80000000 >> id); } } picolibc-1.8.11/libc/machine/spu/spu_timer_stop.c000066400000000000000000000070241513574234600217470ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* SPU timer stop library service. */ #include #include #include "spu_timer_internal.h" /* Stop a timer. Moves it from either the active or handled list to the stopped list. Returns 0 on sucess, timer was successfully stopped. Returns <0 - Failure: * SPU_TIMER_ERR_NOT_ACTIVE - timer was not active * SPU_TIMER_ERR_INVALID_ID - invalid timer id * SPU_TIMER_ERR_NOCLOCK - spu clock is not running */ int spu_timer_stop(int id) { spu_timer_t *t, **pn; unsigned was_enabled; if (id < 0 || id >= SPU_TIMER_NTIMERS) return SPU_TIMER_ERR_INVALID_ID; if (__spu_clock_startcnt == 0) return SPU_TIMER_ERR_NOCLOCK; /* Free or stopped states. */ if (__spu_timers[id].state == SPU_TIMER_ACTIVE || __spu_timers[id].state == SPU_TIMER_HANDLED) { was_enabled = spu_readch(SPU_RdMachStat) & 0x1; spu_idisable(); /* Timer is on either active list or handled list. */ t = (__spu_timers[id].state == SPU_TIMER_ACTIVE) ? __spu_timers_active : __spu_timers_handled; pn = (__spu_timers[id].state == SPU_TIMER_ACTIVE) ? &__spu_timers_active : &__spu_timers_handled; while (t && t->id != id) { pn = &t->next; t = t->next; } #ifdef SPU_TIMER_DEBUG if (!t) ABORT(); /* Internal error. */ #endif /* Fix timeout of next timer and decrementer if we were at the head of the active list. */ if (t->next) { t->next->tmout += t->tmout; if (__spu_timers_active == t) __reset_spu_decr(t->next->tmout); } else __reset_spu_decr(CLOCK_START_VALUE); *pn = t->next; /* Update this elements to pointer. */ t->next = __spu_timers_stopped; __spu_timers_stopped = t; __spu_timers[id].state = SPU_TIMER_STOPPED; if (__likely(was_enabled)) spu_ienable(); return 0; } return SPU_TIMER_ERR_NOT_ACTIVE; } picolibc-1.8.11/libc/machine/spu/spu_timer_svcs.c000066400000000000000000000077611513574234600217500ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* SPU timer start and alloc library services. */ #include #include #include "spu_timer_internal.h" /* The timers. */ spu_timer_t __spu_timers[SPU_TIMER_NTIMERS] __aligned(16); /* Active timer list. */ spu_timer_t *__spu_timers_active; /* Stopped (allocated) timer list. */ spu_timer_t *__spu_timers_stopped; /* List of timers being handled. */ spu_timer_t *__spu_timers_handled; /* Bitmask of available timers. */ unsigned __spu_timers_avail = ((1 << (SPU_TIMER_NTIMERS - 1)) + ((1 << (SPU_TIMER_NTIMERS - 1)) - 1)); /* Allocates an SPU interval timer and returns the timer ID. Must be called before starting a timer. interval specifies the expiration interval in timebase units. func specifies the function pointer to expiration handler. Returns the timer ID on success or <0 on Failure: * SPU_TIMER_ERR_NONE_FREE - no free timers to allocate * SPU_TIMER_ERR_INVALID_PARM - invalid parm */ int spu_timer_alloc(int interval, void (*func)(int)) { unsigned was_enabled; int id; if (interval < MIN_INTVL || interval > MAX_INTVL || func == NULL) return SPU_TIMER_ERR_INVALID_PARM; was_enabled = spu_readch(SPU_RdMachStat) & 0x1; /* Get id of next available timer. */ id = spu_extract((spu_sub((unsigned)31, spu_cntlz(spu_promote(__spu_timers_avail, 0)))), 0); /* No timers avail. */ if (id == -1) return SPU_TIMER_ERR_NONE_FREE; /* Higher order bits represent lower timer ids. */ __spu_timers_avail &= ~(1 << (id)); id = (SPU_TIMER_NTIMERS - 1) - id; /* Initialize timer and put it on stopped list. */ (__spu_timers + id)->func = func; (__spu_timers + id)->intvl = interval; (__spu_timers + id)->id = id; (__spu_timers + id)->state = SPU_TIMER_STOPPED; spu_idisable(); (__spu_timers + id)->next = __spu_timers_stopped; __spu_timers_stopped = &__spu_timers[id]; if (__likely(was_enabled)) spu_ienable(); return id; } /* External interface for starting a timer. See description of __spu_timer_start(). Returns 0 on success and <0 on failure: * SPU_TIMER_ERR_INVALID_ID - invalid id * SPU_TIMER_ERR_NOCLOCK - clock is off * SPU_TIMER_ERR_NOT_STOPPED - timer not in stopped state */ int spu_timer_start(int id) { if (id < 0 || id >= SPU_TIMER_NTIMERS) return SPU_TIMER_ERR_INVALID_ID; if (__spu_clock_startcnt == 0) return SPU_TIMER_ERR_NOCLOCK; if (__spu_timers[id].state != SPU_TIMER_STOPPED) return SPU_TIMER_ERR_NOT_STOPPED; __spu_timer_start(id, 1); return 0; } picolibc-1.8.11/libc/machine/spu/sscanf.S000066400000000000000000000040301513574234600201220ustar00rootroot00000000000000/* Copyright (c) 2007, Toshiba Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of Toshiba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "c99ppe.h" .text .align 4 GLOBL sscanf .type sscanf, @function sscanf: stqd $0, 16($sp) /* save caller address */ il $2, 2 /* number of fixed arguments */ brsl $0, __stack_reg_va /* save register to the stack frame */ il $3, SPE_C99_SIGNALCODE il $4, SPE_C99_VSSCANF ai $5, $sp, 16*2 /* data ($3 save address) */ brsl $0, __send_to_ppe il $2, 16*(SPE_STACK_REGS+2+2) a $sp, $sp, $2 lqd $0, 16($sp) /* load caller address */ bi $0 /* return to caller */ .size sscanf, .-sscanf picolibc-1.8.11/libc/machine/spu/stack_reg_va.S000066400000000000000000000133201513574234600212770ustar00rootroot00000000000000/* Copyright (c) 2007, Toshiba Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of Toshiba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * This file contains code use to construct a PIC, spu side, syscall * function with variable parameters in accordance with the CBE ABI. * * This function is equivalent to constructing a va_list structure and * calling the va_list form of the function. Therefore, for example, * a printf function stack frame will look like this: * * | Stack | high memory * | Parms | * | | * |------------| * | Link Reg | * |------------| * | Back Chain |<-----. <---- input SP * |------------| | * | Reg 74 | | * |------------| | * | Reg 73 | | * |------------| | * // ... // | * |------------| | * | Reg 5 | | * |------------| | * | Reg 4 |<--. | * |------------| | | * va_list.| call_stack |------' * |------------| | * va_list.| next_arg |---' * |------------| * | format (r3)| <---- start of parameters * |------------| |------------| * | stack | | | * | code | |(Back Chain)| <---- output SP * | 1-3 qwords | <---- code_ptr `------------' * `------------' * low memory * * This was written in assembly so that it is smaller than what would * be produced by using va_start. */ #include #include "c99ppe.h" #define parms $2 /* Number of fixed arguments */ #define offset $67 #define flag $68 #define regdec $69 #define link $70 #define code_ptr $71 #define ptr $72 #define inst $73 #define tmp $74 .text .global __stack_reg_va .type __stack_reg_va, @function __stack_reg_va: /* Save registers 69-74 explicitly so that we have some * working registers. */ stqd $74, 16*(-1)($sp) stqd $73, 16*(-2)($sp) stqd $72, 16*(-3)($sp) stqd $71, 16*(-4)($sp) stqd $70, 16*(-5)($sp) stqd $69, 16*(-6)($sp) /* Construct self-modifying stack code that saves the remaining * volatile registers onto the stack. */ il regdec, -1 /* for decrement register value in save instruction */ shlqbyi regdec, regdec, 12 il tmp, -(SPE_STACK_REGS+2+3)*16 a code_ptr, $sp, tmp lqr tmp, save_regs_1 /* store stack code */ stqd tmp, 0(code_ptr) lqr inst, save_regs_2 ai ptr, $sp, 16*(-6) sync bisl link, code_ptr /* branch to the constructed stack code */ /* Adjust pointer so that it points to the first variable * argument on the stack. */ ai offset, parms, -1 /* offset = parms - 1 */ mpyi offset, offset, 16 /* offset = offset * 16 */ a ptr, ptr, offset /* ptr = ptr + offset */ /* Store the va_list to the parameter list. */ stqd $sp, 16*(-1)(ptr) stqd ptr, 16*(-2)(ptr) /* Make $3 store address. */ ai offset, parms, 2 /* offset = parms + 2 */ mpyi offset, offset, -16 /* offset = offset * -16 */ a ptr, ptr, offset /* ptr = ptr + offset */ /* Save all the fixed (non-variable arguments on the stack) */ ceqi flag, parms, 0x01 /* if(parms==1) flag=0xFFFFFFFF */ brnz flag, reg_3 /* if(flag!=0) jump */ ceqi flag, parms, 0x02 /* if(parms==2) flag=0xFFFFFFFF */ brnz flag, reg_4 /* if(flag!=0) jump */ stqd $5, 16*2(ptr) reg_4: stqd $4, 16*1(ptr) reg_3: stqd $3, 0(ptr) il $3, -16*(SPE_STACK_REGS+2+2) stqx $sp, $3, $sp /* save back chain */ a $sp, $sp, $3 bi $0 /* return to caller */ /***************************** stack code *********************************************/ /* The following code is copied into the stack for re-entract, * self-modified, code execution. This code copies the volatile * registers into a va_list parameter array. */ .balignl 16, 0 save_regs_1: stqd inst, 16(code_ptr) /* store instruction */ sync a inst, inst, regdec /* decrement register number in the instruction */ ceqbi tmp, inst, 3 /* if (reg-num == 3) tmp = 0x000000FF 000..0 */ save_regs_2: stqd $68, -16(ptr) ai ptr, ptr, -16 brz tmp, save_regs_1 /* if (tmp == 0) jump */ bi link /* finish to make va_list */ .size __stack_reg_va, .-__stack_reg_va picolibc-1.8.11/libc/machine/spu/stdio.c000066400000000000000000000045751513574234600200250ustar00rootroot00000000000000/* Copyright (C) 2007 Sony Computer Entertainment Inc. Copyright 2007 Sony Corp. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Kazunori Asayama */ #include #include #include "c99ppe.h" static FILE __fp[SPE_FOPEN_MAX]; FILE * __sfp(struct _reent *d) { int i; for (i = 0; i < SPE_FOPEN_MAX; i++) { if (!__fp[i]._fp) { return &__fp[i]; } } errno = EMFILE; return NULL; } static void __cleanup(struct _reent *s) { int i; for (i = 0; i < SPE_FOPEN_MAX; i++) { if (__fp[i]._fp) { fclose(&__fp[i]); } } } void __sinit(struct _reent *s) { _REENT_CLEANUP(s) = __cleanup; _REENT_STDIN(s) = &s->__sf[0]; _REENT_STDIN(s)->_fp = SPE_STDIN; _REENT_STDOUT(s) = &s->__sf[1]; _REENT_STDOUT(s)->_fp = SPE_STDOUT; _REENT_STDERR(s) = &s->__sf[2]; _REENT_STDERR(s)->_fp = SPE_STDERR; } void __check_init(void) { CHECK_INIT(_REENT); } picolibc-1.8.11/libc/machine/spu/straddr.h000066400000000000000000000054121513574234600203420ustar00rootroot00000000000000/* (C) Copyright 2008 International Business Machines Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "vec_literal.h" /* * Supply the inline _straddr for use by strncpy and strncat. * * _straddr: search the string s, and return the address of the first byte * containing zero. */ static inline char * _straddr(const char *s) { unsigned int cnt, cmp, skip, mask; vec_uchar16 *ptr, data; /* * Compensate for unaligned strings. */ ptr = (vec_uchar16 *)s; /* implicit (s & ~0xf) */ skip = (unsigned int)(ptr) & 0xf; /* * skip the first skip bytes starting at (s & ~0xf). */ mask = 0xFFFF >> skip; data = *ptr; cmp = spu_extract(spu_gather(spu_cmpeq(data, 0)), 0); cmp &= mask; cnt = spu_extract(spu_cntlz(spu_promote(cmp, 0)), 0); while (cnt == 32) { data = *++ptr; cnt = spu_extract(spu_cntlz(spu_gather(spu_cmpeq(data, 0))), 0); /* * The first 16 bits for gather on a byte vector are zero, so if cnt * is 32, none of the 16 bytes in data was zero. And, there are (cnt - * 16) non-zero bytes in data. */ } /* * The first non-zero byte is at ptr aligned down plus the number of * non-zero bytes seen. */ return ((char *)(((int)ptr & ~0xf) + (cnt - 16))); } picolibc-1.8.11/libc/machine/spu/strcat.c000066400000000000000000000040351513574234600201720ustar00rootroot00000000000000/* (C) Copyright 2008 International Business Machines Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "straddr.h" #include "strcpy.h" /* * Appends the string pointed to by src (up to and including the /0 * character) to the array pointed to by dest overwriting the * /0 character at the end of dest. The strings may not overlap and * the dest string must have enough space for the result. */ char * strcat(char * __restrict__ dest, const char * __restrict__ src) { _strncpy(_straddr(dest), src, 0, 0, 0); return dest; } picolibc-1.8.11/libc/machine/spu/strcat_ea.c000066400000000000000000000040341513574234600206360ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "ea_internal.h" #include COMPAT_EA_ALIAS(strcat_ea); /* * Maybe not the fastest thing ever since it reads through the data once on * strlen and once on memcpy, but it should work. */ __ea char * strcat_ea(__ea char *dest, __ea const char *src) { size_ea_t length_src; size_ea_t length_dest; __ea char *new_dest; length_src = strlen_ea(src); length_dest = strlen_ea(dest); new_dest = dest + length_dest; memcpy_ea((__ea void *)new_dest, (__ea void *)src, length_src + 1); return dest; } picolibc-1.8.11/libc/machine/spu/strchr.c000066400000000000000000000057751513574234600202130ustar00rootroot00000000000000/* (C) Copyright 2001,2006, International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include /* Scans the string pointed to by s for the character c and * returns a pointer to the first occurance of c. If * c is not found, then NULL is returned. */ char * strchr(const char *s, int c) { unsigned int cmp, skip; vec_uchar16 *ptr, data, vc; vec_uint4 cmp_c, cmp_0; vec_uint4 result; vec_uint4 mask; vec_uint4 one = spu_splats(0xffffU); /* Scan memory array a quadword at a time. Skip leading * mis-aligned bytes. */ ptr = (vec_uchar16 *)s; skip = (unsigned int)(ptr) & 15; mask = spu_rlmask(one, -skip); vc = spu_splats((unsigned char)(c)); data = *ptr++; cmp_c = spu_and(spu_gather(spu_cmpeq(data, vc)), mask); cmp_0 = spu_and(spu_gather(spu_cmpeq(data, 0)), mask); cmp = spu_extract(spu_or(cmp_c, cmp_0), 0); while (cmp == 0) { data = *ptr++; cmp_c = spu_gather(spu_cmpeq(data, vc)); cmp_0 = spu_gather(spu_cmpeq(data, 0)); cmp = spu_extract(spu_or(cmp_c, cmp_0), 0); } /* Compute the location of the first character. If it is beyond * the end of the string, then return NULL. */ result = spu_add(spu_promote((unsigned int)ptr - (skip + 32), 0), spu_cntlz(spu_promote(cmp, 0))); result = spu_andc(result, spu_cmpgt(cmp_0, cmp_c)); return ((char *)spu_extract(result, 0)); } picolibc-1.8.11/libc/machine/spu/strchr_ea.c000066400000000000000000000033511513574234600206440ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "ea_internal.h" #include #include #include COMPAT_EA_ALIAS(strchr_ea); __ea char * strchr_ea(__ea const char *s, int c) { size_ea_t size; size = strlen_ea(s); return (char *)memchr_ea(s, c, size); } picolibc-1.8.11/libc/machine/spu/strcmp.c000066400000000000000000000071551513574234600202100ustar00rootroot00000000000000/* (C) Copyright 2001,2006, International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "vec_literal.h" /* Compare the two strings s1 and s2. Return an integer less than, equal * to, or greater than zero if s1 is found, respectively, to be less than, * to match, or be greater than s2. */ int strcmp(const char *s1, const char *s2) { unsigned int offset1, offset2; vec_uint4 gt_v, lt_v, mask_v; vec_uint4 cnt1_v, cnt2_v; vec_uint4 end1_v, end2_v, end_v, neq_v; vec_uchar16 shuffle1, shuffle2; vec_uchar16 data1A, data1B, data1, data2A, data2B, data2; vec_uchar16 *ptr1, *ptr2; ptr1 = (vec_uchar16 *)s1; ptr2 = (vec_uchar16 *)s2; offset1 = (unsigned int)(ptr1) & 15; offset2 = (unsigned int)(ptr2) & 15; shuffle1 = (vec_uchar16)spu_add( (vec_uint4)spu_splats((unsigned char)offset1), VEC_LITERAL(vec_uint4, 0x00010203, 0x04050607, 0x08090A0B, 0x0C0D0E0F)); shuffle2 = (vec_uchar16)spu_add( (vec_uint4)spu_splats((unsigned char)offset2), VEC_LITERAL(vec_uint4, 0x00010203, 0x04050607, 0x08090A0B, 0x0C0D0E0F)); data1A = *ptr1++; data2A = *ptr2++; do { data1B = *ptr1++; data2B = *ptr2++; data1 = spu_shuffle(data1A, data1B, shuffle1); data2 = spu_shuffle(data2A, data2B, shuffle2); data1A = data1B; data2A = data2B; neq_v = spu_gather(spu_xor(spu_cmpeq(data1, data2), -1)); end1_v = spu_gather(spu_cmpeq(data1, 0)); end2_v = spu_gather(spu_cmpeq(data2, 0)); end_v = spu_or(end1_v, end2_v), 0; } while (spu_extract(spu_or(end_v, neq_v), 0) == 0); cnt1_v = spu_cntlz(end1_v); cnt2_v = spu_cntlz(end2_v); gt_v = spu_gather(spu_cmpgt(data1, data2)); lt_v = spu_gather(spu_cmpgt(data2, data1)); mask_v = spu_and(spu_cmpeq(cnt1_v, cnt2_v), spu_cmpeq(spu_rlmask(neq_v, (vec_int4)spu_add((vec_uint4)cnt1_v, -32)), 0)); gt_v = spu_sub(-1, spu_sl(spu_cmpgt(gt_v, lt_v), 1)); return (spu_extract(spu_andc(gt_v, mask_v), 0)); } picolibc-1.8.11/libc/machine/spu/strcmp_ea.c000066400000000000000000000055771513574234600206630ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include "ea_internal.h" #include "strncmp.h" #include COMPAT_EA_ALIAS(strcmp_ea); /* * It's not clear what is returned if both strings are equal to * each other up to the length of the shorter string. */ int strcmp_ea(__ea char *s1, __ea const char *s2) { __ea char *curr_s1 = (__ea char *)s1; __ea char *curr_s2 = (__ea char *)s2; void *l_s1; void *l_s2; size_ea_t s2_n; size_ea_t s1_n; int min; int ret; vec_uint4 end_v; while (1) { l_s2 = __cache_fetch(curr_s2); l_s1 = __cache_fetch(curr_s1); /* * Use the smaller of the the space left in s2 cacheline or * the space left in the s1 cacheline. */ s2_n = ROUND_UP_NEXT_128((size_ea_t)curr_s2) - (size_ea_t)curr_s2; s1_n = ROUND_UP_NEXT_128((size_ea_t)curr_s1) - (size_ea_t)curr_s1; min = MIN(s2_n, s1_n); ret = _strncmp_internal(l_s1, l_s2, min, &end_v, 1); /* * Only the first slot of end_v is set. */ if (ret || spu_extract(end_v, 0)) /* * If any NUL values were seen (end_v values of zero) we still have * to return ret, as it might not be zero. */ return ret; curr_s1 += min; curr_s2 += min; } } picolibc-1.8.11/libc/machine/spu/strcpy.c000066400000000000000000000036311513574234600202170ustar00rootroot00000000000000/* (C) Copyright 2008 International Business Machines Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "strcpy.h" /* * Copy the string pointed to by src (up to and including the /0 * character) into the array pointed to by dest. If copy between * two arrays that overlap, then behavior is undefined. */ char * strcpy(char * __restrict__ dest, const char * __restrict__ src) { return _strncpy(dest, src, 0, 0, 0); } picolibc-1.8.11/libc/machine/spu/strcpy.h000066400000000000000000000155241513574234600202300ustar00rootroot00000000000000/* (C) Copyright 2008 International Business Machines Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "vec_literal.h" #include /* * Supply an inline _strncpy for strcpy/cat and strncpy/cat. Relies on * checklen and lastzero code being optimized out when they are constant * zero values. */ static inline void * _strncpy(char * __restrict__ dest, const char * __restrict__ src, size_t maxlen, int checklen, int lastzero) { int adjust, offset, soffset, doffset, shift; vec_uchar16 *vsrc, *vdest; vec_uchar16 sdata1, sdata2, sdata, shuffle; vec_uchar16 mask1, maskzero, cmp0; vec_uint4 nonzeroes, gathered_cmp, vtmp, vtmp2; vec_uint4 curlen; /* assumes size_t is 4 bytes */ const vec_uint4 val31 = { 31, 31, 31, 31 }; const vec_uint4 val_0123 = { 0x00010203, 0x04050607, 0x08090A0B, 0x0C0D0E0F }; const vec_uchar16 all_ones = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; vsrc = (vec_uchar16 *)src; vdest = (vec_uchar16 *)dest; soffset = (int)src & 15; doffset = (int)dest & 15; if (checklen) { /* * Set curlen so it is the number of bytes we would copy if starting * from vdest & ~0xf. * * curlen could probably be replaced by comparing vdest plus some * offset to dest + maxlen, that would help mainly in the while loop * but would lose only one instruction (the curlen -= 16). */ curlen = spu_splats((unsigned int)(maxlen + doffset)); } /* * Setup a shuffle pattern to align the source string with the * alignment of the destination string. */ vtmp = spu_cmpgt(spu_promote(doffset, 0), spu_promote(soffset, 0)); adjust = spu_extract(vtmp, 0); offset = soffset - doffset; offset += adjust & 16; shuffle = spu_splats((unsigned char)offset); shuffle = (vec_uchar16)spu_add((vec_uint4)shuffle, val_0123); vsrc += adjust; sdata1 = *vsrc++; sdata2 = *vsrc++; sdata = spu_shuffle(sdata1, sdata2, shuffle); /* * mask out leading bytes */ mask1 = spu_rlmaskqwbyte(all_ones, -doffset); cmp0 = spu_and(mask1, spu_cmpeq(sdata, 0)); nonzeroes = spu_cntlz(spu_gather(cmp0)); /* * First element of nonzeroes - 15 is the number of leading non-zero * bytes plus 1 for the zero byte. */ if (checklen) { vtmp = spu_add(curlen, 15); vtmp2 = spu_cmpgt(nonzeroes, vtmp); nonzeroes = spu_sel(nonzeroes, vtmp, vtmp2); } vtmp = spu_cmpgt(nonzeroes, val31); /* * Note: using immediate (constant 31) vs a vector value (val31) does * not give different results, and we have to have a vector val31 for * the spu_sel below, so use val31 everywhere. */ vtmp = spu_sel(nonzeroes, val31, vtmp); /* * So vtmp is now min(nonzeroes, 31), the number of bytes + 16 that we * want to copy from the first 16 bytes of the source. */ if (checklen) { curlen = spu_sub(vtmp, curlen); curlen = spu_sub(15, curlen); } /* * We want a right shift 0xff with fill by ones of (vtmp - 15) bytes, but * that doesn't exist so use spu_slqwbyte and vtmp all ones left by * (31 - vtmp). Note: this can also use spu_rlqwbytebc with spu_rlqw. */ shift = spu_extract(spu_sub(val31, vtmp), 0); maskzero = spu_slqwbyte(all_ones, shift); maskzero = spu_and(mask1, maskzero); *vdest = spu_sel(*vdest, sdata, maskzero); vtmp = spu_cmpgt(nonzeroes, val31); if (checklen) { vtmp2 = spu_cmpgt(curlen, 0); vtmp = spu_and(vtmp, vtmp2); } if (spu_extract(vtmp, 0)) { sdata1 = sdata2; sdata2 = *vsrc++; sdata = spu_shuffle(sdata1, sdata2, shuffle); cmp0 = spu_cmpeq(sdata, 0); gathered_cmp = spu_gather(cmp0); /* * Copy 16 bytes at a time. */ while ((spu_extract(gathered_cmp, 0) == 0) && (!checklen || (spu_extract(curlen, 0) > 15))) { if (checklen) curlen = spu_add(curlen, -16); *++vdest = sdata; sdata1 = sdata2; sdata2 = *vsrc++; sdata = spu_shuffle(sdata1, sdata2, shuffle); cmp0 = spu_cmpeq(sdata, 0); gathered_cmp = spu_gather(cmp0); } /* * Copy 0 to 15 trailing bytes, either up to the smaller of curlen or * the number of non-zero bytes. */ nonzeroes = spu_cntlz(gathered_cmp); if (checklen) { vtmp = spu_add(curlen, 15); vtmp2 = spu_cmpgt(nonzeroes, vtmp); nonzeroes = spu_sel(nonzeroes, vtmp, vtmp2); curlen = spu_sub(nonzeroes, curlen); curlen = spu_sub(15, curlen); } shift = spu_extract(spu_sub(val31, nonzeroes), 0); maskzero = spu_slqwbyte(all_ones, shift); ++vdest; *vdest = spu_sel(*vdest, sdata, maskzero); } if (checklen && lastzero) { /* * For strncat. */ dest[maxlen - spu_extract(curlen, 0)] = '\0'; } /* Pad null bytes if the length of the "src" is less than "n" (strncpy). */ if (checklen && !lastzero && spu_extract(curlen, 0)) memset(dest + maxlen - spu_extract(curlen, 0), 0, spu_extract(curlen, 0)); return (dest); } picolibc-1.8.11/libc/machine/spu/strcpy_ea.c000066400000000000000000000035531513574234600206670ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "ea_internal.h" #include COMPAT_EA_ALIAS(strcpy_ea); /* * Not the fastest since it reads through the data once on * strlen and once on memcpy. */ __ea char * strcpy_ea(__ea char *dest, __ea const char *src) { size_ea_t length; length = strlen_ea(src); memcpy_ea((__ea void *)dest, (__ea void *)src, length + 1); return dest; } picolibc-1.8.11/libc/machine/spu/strcspn.c000066400000000000000000000070011513574234600203620ustar00rootroot00000000000000/* (C) Copyright 2001,2006, International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "vec_literal.h" /* Computes the length of the maximum initial segement * of the string pointed to by s1 which consists entirely * of characters not contained in the string pointed to by s2. */ size_t strcspn(const char *s1, const char *s2) { size_t len, cnt; unsigned int offset; vec_uchar16 shuffle, match, initial_splat, splat; vec_uchar16 data1, data2, dataA, dataB, *ptr1, *ptr2; ptr1 = (vec_uchar16 *)s1; offset = (unsigned int)(s1) & 15; shuffle = (vec_uchar16)spu_add( (vec_uint4)spu_splats((unsigned char)offset), VEC_LITERAL(vec_uint4, 0x0010203, 0x04050607, 0x08090A0B, 0x0C0D0E0F)); len = 0; dataA = *ptr1++; dataB = *ptr1++; initial_splat = spu_splats((unsigned char)((unsigned int)(s2) & 0xF)); /* For each quadword of the string s1. */ do { data1 = spu_shuffle(dataA, dataB, shuffle); ptr2 = (vec_uchar16 *)s2; data2 = *ptr2; data2 = spu_shuffle(data2, data2, initial_splat); ptr2 = (vec_uchar16 *)((unsigned int)(ptr2) + 1); splat = initial_splat; match = spu_cmpeq(data1, 0); /* For each character of s2, compare agains a quadword of s1, * accumulating match success in the variable match. */ while (spu_extract((vec_uint4)data2, 0)) { match = spu_or(match, spu_cmpeq(data1, data2)); splat = spu_and((vec_uchar16)(spu_add((vec_uint4)splat, VEC_SPLAT_U32(0x01010101))), 0xF); data2 = *ptr2; data2 = spu_shuffle(data2, data2, splat); ptr2 = (vec_uchar16 *)((unsigned int)(ptr2) + 1); } cnt = spu_extract(spu_cntlz(spu_gather(match)), 0); len = (len - 16) + cnt; dataA = dataB; dataB = *ptr1++; } while (cnt == 32); return (len); } picolibc-1.8.11/libc/machine/spu/strcspn_ea.c000066400000000000000000000041611513574234600210330ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "ea_internal.h" #include #include #include COMPAT_EA_ALIAS(strcspn_ea); size_ea_t strcspn_ea(__ea const char *s, const char *reject) { size_ea_t s_length; size_ea_t found_length; __ea void *found_it; size_ea_t ret; size_t i; size_t rej_length; s_length = strlen_ea(s); rej_length = strlen(reject); ret = s_length; for (i = 0; i < rej_length; i++) { found_it = memchr_ea(s, reject[i], s_length); found_length = (size_ea_t)found_it - (size_ea_t)s; if (found_length < ret) ret = found_length; } return ret; } picolibc-1.8.11/libc/machine/spu/strlen.c000066400000000000000000000050571513574234600202060ustar00rootroot00000000000000/* (C) Copyright 2001,2006, International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include /* * Calculates the length of the string s, not including the terminating * \0 character. */ size_t strlen(const char *s) { unsigned int cnt, cmp, skip, mask; vec_uchar16 *ptr, data; /* * Compensate for initial mis-aligned string. */ ptr = (vec_uchar16 *)s; /* implicit 16 byte alignment when dereferenced */ skip = (unsigned int)(ptr) & 15; mask = 0xFFFF >> skip; data = *ptr; cmp = spu_extract(spu_gather(spu_cmpeq(data, 0)), 0); cmp &= mask; cnt = spu_extract(spu_cntlz(spu_promote(cmp, 0)), 0); while (cnt == 32) { data = *++ptr; cnt = spu_extract(spu_cntlz(spu_gather(spu_cmpeq(data, 0))), 0); } /* * The length is ptr aligned down to a 16 byte boundary, plus the offset * to the zero byte, minus the starting address s. */ return ((((int)ptr & ~0xf) + (cnt - 16)) - (int)s); } picolibc-1.8.11/libc/machine/spu/strlen_ea.c000066400000000000000000000044661513574234600206560ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "ea_internal.h" #include #include #include COMPAT_EA_ALIAS(strlen_ea); size_ea_t strlen_ea(__ea const char *s) { __ea void *curr_s = (__ea void *)s; void *local_s; size_ea_t left_in_cacheline; void *where_null; size_ea_t length_of_string = 0; while (1) { left_in_cacheline = ROUND_UP_NEXT_128((size_ea_t)curr_s) - (size_ea_t)curr_s; local_s = __cache_fetch(curr_s); where_null = memchr(local_s, '\0', left_in_cacheline); if (where_null) { length_of_string += ((size_ea_t)(int)where_null - (size_ea_t)(int)local_s); return length_of_string; } /* update values to take into account what we copied */ curr_s += left_in_cacheline; length_of_string += left_in_cacheline; } } picolibc-1.8.11/libc/machine/spu/strncat.c000066400000000000000000000040501513574234600203450ustar00rootroot00000000000000/* (C) Copyright 2008 International Business Machines Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "straddr.h" #include "strcpy.h" /* * Appends the string pointed to by src (up to and including the /0 * character) to the array pointed to by dest (overwriting the * /0 character at the end of dest. The strings may not overlap and * the dest string must have enough space for the result. */ char * strncat(char * __restrict__ dest, const char * __restrict__ src, size_t n) { _strncpy(_straddr(dest), src, n, 1, 1); return dest; } picolibc-1.8.11/libc/machine/spu/strncat_ea.c000066400000000000000000000043101513574234600210110ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "ea_internal.h" #include COMPAT_EA_ALIAS(strncat_ea); /* * Not the fastest thing ever since it reads through the data once on * strlen and once on memcpy. */ __ea char * strncat_ea(__ea char *dest, __ea const char *src, size_ea_t n) { size_ea_t length_src; size_ea_t length_dest; __ea char *new_dest; size_ea_t smaller_length; length_src = strlen_ea(src); length_dest = strlen_ea(dest); new_dest = dest + length_dest; smaller_length = length_src < n ? length_src : n; memcpy_ea((__ea void *)new_dest, (__ea void *)src, smaller_length); /* null out last character */ memset_ea((__ea void *)(new_dest + smaller_length), 0, 1); return dest; } picolibc-1.8.11/libc/machine/spu/strncmp.c000066400000000000000000000040331513574234600203560ustar00rootroot00000000000000/* (C) Copyright 2001,2006, International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "strncmp.h" /* * Compare the two strings s1 and s2 of length n. Returns an integer less * than, equal to, or greater than zero if s1 is found, respectively, * to be less than, to match, or be greater than s2. */ int strncmp(const char *s1, const char *s2, size_t n) { vec_uint4 end_v; return _strncmp_internal(s1, s2, n, &end_v, 1); } picolibc-1.8.11/libc/machine/spu/strncmp.h000066400000000000000000000134211513574234600203640ustar00rootroot00000000000000/* (C) Copyright 2001,2006,2008 International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include /* * Internal _strncmp_internal for strncmp and memcmp: * * Compare the two strings s1 and s2 of length n. Returns an integer less * than, equal to, or greater than zero if s1 is found, respectively, * to be less than, to match, or be greater than s2. Check for zero bytes * only if check_zeroes is set. In additin, the vector value *end_v will * contain all zeroes if we hit a NUL character that caused the comparison * to complete, *end_v is modified only if check_zeroes is set. */ static inline int _strncmp_internal(const char *s1, const char *s2, size_t n, vec_uint4 *end_v, int check_zeroes) { unsigned int offset1, offset2; vec_int4 n_v; vec_uint4 cnt1_v, cnt2_v, max_cnt_v; vec_uint4 gt_v, lt_v, mask_v, end1_v, end2_v, neq_v, tmp1_v; vec_uint4 shift_n_v, shift_eos_v, max_shift_v; vec_uchar16 shuffle1, shuffle2; vec_uchar16 data1A, data1B, data1, data2A, data2B, data2; vec_uchar16 *ptr1, *ptr2; data1 = data2 = spu_splats((unsigned char)0); ptr1 = (vec_uchar16 *)s1; ptr2 = (vec_uchar16 *)s2; offset1 = (unsigned int)(ptr1) & 15; offset2 = (unsigned int)(ptr2) & 15; shuffle1 = (vec_uchar16)spu_add((vec_uint4)spu_splats((unsigned char)offset1), ((vec_uint4) { 0x00010203, 0x04050607, 0x08090A0B, 0x0C0D0E0F })); shuffle2 = (vec_uchar16)spu_add((vec_uint4)spu_splats((unsigned char)offset2), ((vec_uint4) { 0x00010203, 0x04050607, 0x08090A0B, 0x0C0D0E0F })); data1A = *ptr1++; data2A = *ptr2++; n_v = spu_promote((int)n, 0); do { data1B = *ptr1++; data2B = *ptr2++; /* * Quadword align each of the input strings so that we operate on full * quadwords. */ data1 = spu_shuffle(data1A, data1B, shuffle1); data2 = spu_shuffle(data2A, data2B, shuffle2); data1A = data1B; data2A = data2B; neq_v = spu_gather(spu_xor(spu_cmpeq(data1, data2), -1)); if (check_zeroes) { end1_v = spu_gather(spu_cmpeq(data1, 0)); end2_v = spu_gather(spu_cmpeq(data2, 0)); *end_v = spu_or(end1_v, end2_v); } n_v = spu_add(n_v, -16); /* * Repeat until either * 1) the character count expired * 2) check_zeroes is set and a null character is discovered in one of * the input strings * 3) the strings do not compare equal */ if (check_zeroes) { tmp1_v = spu_or(*end_v, neq_v); tmp1_v = spu_cmpeq(tmp1_v, 0); } else { tmp1_v = spu_cmpeq(neq_v, 0); } tmp1_v = spu_and(tmp1_v, spu_cmpgt(n_v, 0)); } while (spu_extract(tmp1_v, 0)); /* * Construct a mask to eliminate characters that are not of interest * in the comparison. */ mask_v = spu_splats((unsigned int)0xFFFF); shift_n_v = spu_andc((__vector unsigned int)spu_sub(0, n_v), spu_cmpgt(n_v, -1)); if (check_zeroes) { cnt1_v = spu_cntlz(end1_v); cnt2_v = spu_cntlz(end2_v); max_cnt_v = spu_sel(cnt1_v, cnt2_v, spu_cmpgt(cnt2_v, cnt1_v)); shift_eos_v = spu_sub(32, max_cnt_v); max_shift_v = spu_sel(shift_n_v, shift_eos_v, spu_cmpgt(shift_eos_v, shift_n_v)); mask_v = spu_and(spu_sl(mask_v, spu_extract(max_shift_v, 0)), mask_v); } else { mask_v = spu_and(spu_sl(mask_v, spu_extract(shift_n_v, 0)), mask_v); } /* * Determine if greater then or less then in the case that they are * not equal. gt_v is either 1 (in the case s1 is greater then s2), or * -1 (in the case that s2 is greater then s1). * * There are no byte vector math instructions, so we can't subtract * data1 from data2. */ gt_v = spu_gather(spu_cmpgt(data1, data2)); lt_v = spu_gather(spu_cmpgt(data2, data1)); gt_v = spu_sub(-1, spu_sl(spu_cmpgt(gt_v, lt_v), 1)); /* * Construct a mask to be applied to gt_v if the strings are discovered * to be equal. */ mask_v = spu_cmpeq(spu_and(neq_v, mask_v), 0); return (spu_extract(spu_andc(gt_v, mask_v), 0)); } picolibc-1.8.11/libc/machine/spu/strncmp_ea.c000066400000000000000000000060061513574234600210250ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include "ea_internal.h" #include "strncmp.h" #include COMPAT_EA_ALIAS(strncmp_ea); int strncmp_ea(__ea void *s1, __ea const void *s2, size_ea_t n3) { __ea void *curr_s1 = (__ea void *)s1; __ea void *curr_s2 = (__ea void *)s2; void *l_s1; void *l_s2; int min; size_ea_t s2_n; size_ea_t s1_n; int ret; vec_uint4 end_v; ret = 0; /* in case n3 is 0 */ while (n3) { l_s2 = __cache_fetch(curr_s2); l_s1 = __cache_fetch(curr_s1); /* * Use the smaller of the size left to compare (n3), the space left in * s2 cacheline (s2_n), or the space left in the s1 cacheline (s1_n) */ s2_n = ROUND_UP_NEXT_128((size_ea_t)curr_s2) - (size_ea_t)curr_s2; s1_n = ROUND_UP_NEXT_128((size_ea_t)curr_s1) - (size_ea_t)curr_s1; min = three_way_min(s2_n, s1_n, n3); ret = _strncmp_internal(l_s1, l_s2, min, &end_v, 1); /* * Only the first slot of end_v is set. */ /* if (ret || spu_extract(spu_cmpeq(end_v, 0), 0)) { */ /* if (ret || spu_extract(spu_gather(spu_cmpeq(end_v, 0)), 0)) { */ if (ret || spu_extract(end_v, 0)) /* * If any NUL values were seen (end_v values of zero) we still have * to return ret, as it might not be zero. */ return ret; curr_s2 += min; curr_s1 += min; n3 -= min; } return ret; } picolibc-1.8.11/libc/machine/spu/strncpy.c000066400000000000000000000036471513574234600204040ustar00rootroot00000000000000/* (C) Copyright 2008 International Business Machines Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "strcpy.h" /* * Copy the string up to n character from memory area src to memory area * dest. The memory areas may not overlap. The strncpy subroutine returns * a pointer to dest. */ char * strncpy(char * __restrict__ dest, const char * __restrict__ src, size_t n) { return _strncpy(dest, src, n, 1, 0); } picolibc-1.8.11/libc/machine/spu/strncpy_ea.c000066400000000000000000000040211513574234600210340ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "ea_internal.h" #include COMPAT_EA_ALIAS(strncpy_ea); /* * Not the fastest since it reads through the data once on strlen and once * on memcpy. */ __ea char * strncpy_ea(__ea char *dest, __ea const char *src, size_ea_t n) { size_ea_t length = strlen_ea(src); if (length < n) { memcpy_ea((__ea void *)dest, (__ea void *)src, length); memset_ea((__ea void *)(dest + length), 0, n - length); } else { memcpy_ea((__ea void *)dest, (__ea void *)src, n); } return dest; } picolibc-1.8.11/libc/machine/spu/strpbrk.c000066400000000000000000000073521513574234600203660ustar00rootroot00000000000000/* (C) Copyright 2001,2006, International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "vec_literal.h" /* Locates the first occurance in string pointed to by s1 of * any character in the string pointed to by s2. A null pointer * is returned if no character in s2 occurs in s1. */ char * strpbrk(const char *s1, const char *s2) { unsigned int offset; vec_uint4 cnt; vec_uchar16 shuffle, match, initial_splat, splat, eos; vec_uchar16 data1, data2, dataA, dataB, *ptr1, *ptr2; ptr1 = (vec_uchar16 *)s1; offset = (unsigned int)(s1) & 15; shuffle = (vec_uchar16)spu_add( (vec_uint4)spu_splats((unsigned char)offset), VEC_LITERAL(vec_uint4, 0x0010203, 0x04050607, 0x08090A0B, 0x0C0D0E0F)); dataA = *ptr1++; dataB = *ptr1++; initial_splat = spu_splats((unsigned char)((unsigned int)(s2) & 0xF)); /* For each quadword of the string s1. */ do { data1 = spu_shuffle(dataA, dataB, shuffle); eos = match = spu_cmpeq(data1, 0); ptr2 = (vec_uchar16 *)s2; data2 = *ptr2; data2 = spu_shuffle(data2, data2, initial_splat); ptr2 = (vec_uchar16 *)((unsigned int)(ptr2) + 1); splat = initial_splat; /* For each character of s2, compare agains a quadword of s1, * accumulating match success in the variable match. */ while (spu_extract((vec_uint4)data2, 0)) { match = spu_or(match, spu_cmpeq(data1, data2)); splat = spu_and((vec_uchar16)(spu_add((vec_uint4)splat, VEC_SPLAT_U32(0x01010101))), 0xF); data2 = *ptr2; data2 = spu_shuffle(data2, data2, splat); ptr2 = (vec_uchar16 *)((unsigned int)(ptr2) + 1); } cnt = spu_cntlz(spu_gather(match)); dataA = dataB; dataB = *ptr1++; } while (spu_extract(cnt, 0) == 32); /* Compute the first match pointer, zeroing it (NIL) if it is the end of * string. */ return ((char *)spu_extract( spu_andc(spu_add(spu_add(spu_promote((unsigned int)(ptr1), 0), -64), cnt), spu_cmpeq(cnt, spu_cntlz(spu_gather(eos)))), 0)); } picolibc-1.8.11/libc/machine/spu/strpbrk_ea.c000066400000000000000000000034111513574234600210230ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "ea_internal.h" #include #include #include COMPAT_EA_ALIAS(strpbrk_ea); __ea char * strpbrk_ea(__ea const char *s, const char *accept) { size_ea_t where; where = strcspn_ea(s, accept); return (__ea char *)((size_ea_t)s + where); } picolibc-1.8.11/libc/machine/spu/strrchr.c000066400000000000000000000101251513574234600203560ustar00rootroot00000000000000/* (C) Copyright 2001,2006, International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "vec_literal.h" /* Scans the string pointed to by s for the character c and * returns a pointer to the last occurance of c. If * c is not found, then NULL is returned. */ char * strrchr(const char *s, int c) { int nskip; vec_uchar16 *ptr, data, vc; vec_uint4 cmp_c, cmp_0, cmp; vec_uint4 res_ptr, res_cmp; vec_uint4 mask, result; vec_uint4 one = spu_splats(0xffffU); /* Scan memory array a quadword at a time. Skip leading * mis-aligned bytes. */ ptr = (vec_uchar16 *)s; nskip = -((unsigned int)(ptr) & 15); mask = spu_rlmask(one, nskip); vc = spu_splats((unsigned char)(c)); data = *ptr++; ptr = (vec_uchar16 *)((unsigned int)ptr & ~15); cmp_c = spu_and(spu_gather(spu_cmpeq(data, vc)), mask); cmp_0 = spu_and(spu_gather(spu_cmpeq(data, 0)), mask); res_ptr = spu_splats(0U); res_cmp = spu_splats(0U); while (spu_extract(cmp_0, 0) == 0) { cmp = spu_cmpeq(cmp_c, 0); res_ptr = spu_sel(spu_promote((unsigned int)(ptr), 0), res_ptr, cmp); res_cmp = spu_sel(cmp_c, res_cmp, cmp); data = *ptr++; cmp_c = spu_gather(spu_cmpeq(data, vc)); cmp_0 = spu_gather(spu_cmpeq(data, 0)); cmp = spu_cmpeq(cmp_c, 0); } /* Compute the location of the last character before termination * character. * * First mask off compare results following the first termination character. */ mask = spu_sl(one, 31 - spu_extract(spu_cntlz(cmp_0), 0)); cmp_c = spu_and(cmp_c, mask); /* Conditionally update res_ptr and res_cmd if a match was found in the last * quadword. */ cmp = spu_cmpeq(cmp_c, 0); res_ptr = spu_sel(spu_promote((unsigned int)(ptr), 0), res_ptr, cmp); res_cmp = spu_sel(cmp_c, res_cmp, cmp); /* Bit reserve res_cmp for locating last occurance. */ mask = spu_cmpeq(res_cmp, 0); res_cmp = (vec_uint4)spu_maskb(spu_extract(res_cmp, 0)); res_cmp = spu_gather((vec_uchar16)spu_shuffle( res_cmp, res_cmp, VEC_LITERAL(vec_uchar16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0))); /* Compute the location (ptr) of the last occurance of c. If no * occurance was found (ie, element 0 of res_cmp == 0, then return * NULL. */ result = spu_sub(spu_add(res_ptr, 15), spu_cntlz(res_cmp)); result = spu_andc(result, mask); return ((char *)spu_extract(result, 0)); } picolibc-1.8.11/libc/machine/spu/strrchr_ea.c000066400000000000000000000057601513574234600210340ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "ea_internal.h" #include #include #include static __ea char * similie_ls_to_ea(char *l1, __ea char *ea1, char *l2) { return (__ea char *)((size_ea_t)ea1 + ((size_ea_t)(int)l2 - (size_ea_t)(int)l1)); } COMPAT_EA_ALIAS(strrchr_ea); __ea char * strrchr_ea(__ea const char *s, int c) { size_ea_t string_length; char *curr_ptr; __ea char *string_start_local; __ea char *end_of_string_ea; __ea char *start_of_cacheline_ea; char *start_of_cachline_local; string_start_local = __cache_fetch((__ea char *)s); string_length = strlen_ea(s); end_of_string_ea = (__ea char *)s + string_length; start_of_cacheline_ea = round_down_128_ea(end_of_string_ea - 1); start_of_cachline_local = __cache_fetch(start_of_cacheline_ea); /*this next line should be the same cacheline, just the end of the string */ curr_ptr = __cache_fetch(end_of_string_ea - 1); while (1) { /*search backwards through this cachline */ while (curr_ptr >= start_of_cachline_local) { if (*curr_ptr == (char)c) return similie_ls_to_ea(start_of_cachline_local, start_of_cacheline_ea, curr_ptr); curr_ptr--; if (curr_ptr < string_start_local) return NULL; } /* iterate cacheline backwards */ start_of_cacheline_ea -= 128; start_of_cachline_local = __cache_fetch(start_of_cacheline_ea); curr_ptr = __cache_fetch(start_of_cacheline_ea + 128); } } picolibc-1.8.11/libc/machine/spu/strspn.c000066400000000000000000000070121513574234600202210ustar00rootroot00000000000000/* (C) Copyright 2001,2006, International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "vec_literal.h" /* Computes the length of the maximum initial segement * of the string pointed to by s1 which consists entirely * of characters from the string pointed to by s2. */ size_t strspn(const char *s1, const char *s2) { size_t len, cnt; unsigned int offset; vec_uchar16 shuffle, match, initial_splat, splat; vec_uchar16 data1, data2, dataA, dataB, *ptr1, *ptr2; ptr1 = (vec_uchar16 *)s1; offset = (unsigned int)(s1) & 15; shuffle = (vec_uchar16)spu_add( (vec_uint4)spu_splats((unsigned char)offset), VEC_LITERAL(vec_uint4, 0x0010203, 0x04050607, 0x08090A0B, 0x0C0D0E0F)); len = 0; dataA = *ptr1++; dataB = *ptr1++; initial_splat = spu_splats((unsigned char)((unsigned int)(s2) & 0xF)); /* For each quadword of the string s1. */ do { data1 = spu_shuffle(dataA, dataB, shuffle); match = spu_splats((unsigned char)0); ptr2 = (vec_uchar16 *)s2; data2 = *ptr2; data2 = spu_shuffle(data2, data2, initial_splat); ptr2 = (vec_uchar16 *)((unsigned int)(ptr2) + 1); splat = initial_splat; /* For each character of s2, compare agains a quadword of s1, * accumulating match success in the variable match. */ while (spu_extract((vec_uint4)data2, 0)) { match = spu_or(match, spu_cmpeq(data1, data2)); splat = spu_and((vec_uchar16)(spu_add((vec_uint4)splat, VEC_SPLAT_U32(0x01010101))), 0xF); data2 = *ptr2; data2 = spu_shuffle(data2, data2, splat); ptr2 = (vec_uchar16 *)((unsigned int)(ptr2) + 1); } cnt = spu_extract(spu_cntlz(spu_gather(spu_xor(match, -1))), 0); len = (len - 16) + cnt; dataA = dataB; dataB = *ptr1++; } while (cnt == 32); return (len); } picolibc-1.8.11/libc/machine/spu/strspn_ea.c000066400000000000000000000041341513574234600206700ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "ea_internal.h" #include #include #include COMPAT_EA_ALIAS(strspn_ea); size_ea_t strspn_ea(__ea const char *s, const char *accept) { __ea void *curr_s = (__ea void *)s; char *local_s; size_ea_t length_of_string = 0; size_ea_t s_len; int i; s_len = strlen_ea(s); for (i = 0; i < s_len; i++) { local_s = (char *)__cache_fetch(curr_s); if (!strchr(accept, local_s[0])) { return length_of_string; } else { length_of_string++; curr_s++; } } return length_of_string; } picolibc-1.8.11/libc/machine/spu/strstr_ea.c000066400000000000000000000051771513574234600207100ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007, 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "ea_internal.h" #include #include #include COMPAT_EA_ALIAS(strstr_ea); __ea char * strstr_ea(__ea const char *s1, __ea const char *s2) { __ea char *ret; __ea char *curr; size_ea_t s2_length; size_ea_t s1_length; int i; int found; ret = (__ea char *)s1; s2_length = strlen_ea(s2); s1_length = strlen_ea(s1); while (ret < (s1 + s1_length)) { /* search for first letter */ // temporary hack for broken 64 bit compiler ret = strchr_ea(ret, s2[0]); /*if we find it search for the rest */ if (ret) { found = 1; for (i = 1; i < s2_length; i++) { // temporary hack for broken 64 bit compiler curr = strchr_ea(ret, s2[i]); /* if the letter doesn't exist or isn't in the right spot we unfind */ if (!curr || (curr != (ret + i))) found = 0; } } if (found) { return ret; } else { ret++; } /*go back and try again with the rest of it */ } return NULL; } picolibc-1.8.11/libc/machine/spu/strxfrm.c000066400000000000000000000051221513574234600203750ustar00rootroot00000000000000/* (C) Copyright 2001,2006, International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #define min(a, b) (a) < (b) ? (a) : (b) /* The strxfrm() function transforms the src string into a form such that * the result of strcmp() on two strings that have been transformed with * strxfrm() is the same as the result of strcoll() on the two strings * before their transformation. The first n characters of the transformed * string are placed in dest. * * The strxfrm() function returns the number of bytes required to store * the transformed string in dest excluding the terminating character * If the value returned is n or more, the contents of dest are indeterminate. * * Note: Since this library/function only supports a single locale, no * transformation is performed. */ size_t strxfrm(char * __restrict__ dest, const char * __restrict__ src, size_t n) { size_t len; len = strlen(src); (void)memcpy((void *)dest, (void *)src, min(n, len + 1)); return len; } picolibc-1.8.11/libc/machine/spu/sys/000077500000000000000000000000001513574234600173425ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/spu/sys/custom_file.h000066400000000000000000000032111513574234600220210ustar00rootroot00000000000000/* Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __CUSTOM_FILE_H__ #define __CUSTOM_FILE_H__ 1 /* * Cell SPE support */ struct __sFILE_spu { int _fp; /* pseudo FILE pointer on PPE */ }; typedef struct __sFILE_spu __FILE; #endif /* __CUSTOM_FILE_H__ */ picolibc-1.8.11/libc/machine/spu/sys/dirent.h000066400000000000000000000037231513574234600210050ustar00rootroot00000000000000/* Copyright 2007 International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SYS_DIRENT_H #define _SYS_DIRENT_H #include _BEGIN_STD_C #define MAXNAMLEN 255 struct dirent { ino_t d_ino; char d_name[MAXNAMLEN + 1]; }; typedef struct { unsigned long long ppc_dir; /* * Allow one readdir for each opendir, and store the data here. */ struct dirent dirent; } DIR; _END_STD_C #endif picolibc-1.8.11/libc/machine/spu/sys/errno.h000066400000000000000000000212111513574234600206350ustar00rootroot00000000000000/* Copyright (c) 2007 Patrick Mansfield */ /* * The SPU must have these values match those on the PPU linux side, so * the assisted calls (system or library ones) that set errno will use the * same values. * * This file is based on the CRIS file, with these modifications: * * EDEADLOCK - instead of EDEADLK (35) use 58 (for some reason ppc only does * this, it is not used by ppc kernel code nor glibc code). * * ECANCELED value of 125 added, in linux and posix value of 125, in generic * newlib errno.h, value of 140 * * ENOTSUP as EOPNOTSUPP (95) added, in linux and posix value 95, in * generic newlib errno.h, value of 134 */ /* This file is to be kept in sync with libc/include/sys/errno.h on which it is based, except values used or returned by syscalls must be those of the Linux ppc. */ #ifndef _SYS_ERRNO_H_ #define _SYS_ERRNO_H_ #include _BEGIN_STD_C #ifdef __GLOBAL_ERRNO #define __THREAD_LOCAL_ERRNO #else #define __THREAD_LOCAL_ERRNO __THREAD_LOCAL #endif #ifdef __PICOLIBC_ERRNO_FUNCTION int *__PICOLIBC_ERRNO_FUNCTION(void); #define errno (*__PICOLIBC_ERRNO_FUNCTION()) #else extern __THREAD_LOCAL_ERRNO int errno; #define errno errno #endif /* Adjusted to the linux asm/errno.h */ #define EPERM 1 /* Operation not permitted */ #define ENOENT 2 /* No such file or directory */ #define ESRCH 3 /* No such process */ #define EINTR 4 /* Interrupted system call */ #define EIO 5 /* I/O error */ #define ENXIO 6 /* No such device or address */ #define E2BIG 7 /* Arg list too long */ #define ENOEXEC 8 /* Exec format error */ #define EBADF 9 /* Bad file number */ #define ECHILD 10 /* No child processes */ #define EAGAIN 11 /* Try again */ #define ENOMEM 12 /* Out of memory */ #define EACCES 13 /* Permission denied */ #define EFAULT 14 /* Bad address */ #define ENOTBLK 15 /* Block device required */ #define EBUSY 16 /* Device or resource busy */ #define EEXIST 17 /* File exists */ #define EXDEV 18 /* Cross-device link */ #define ENODEV 19 /* No such device */ #define ENOTDIR 20 /* Not a directory */ #define EISDIR 21 /* Is a directory */ #define EINVAL 22 /* Invalid argument */ #define ENFILE 23 /* File table overflow */ #define EMFILE 24 /* Too many open files */ #define ENOTTY 25 /* Not a typewriter */ #define ETXTBSY 26 /* Text file busy */ #define EFBIG 27 /* File too large */ #define ENOSPC 28 /* No space left on device */ #define ESPIPE 29 /* Illegal seek */ #define EROFS 30 /* Read-only file system */ #define EMLINK 31 /* Too many links */ #define EPIPE 32 /* Broken pipe */ #define EDOM 33 /* Math argument out of domain of func */ #define ERANGE 34 /* Math result not representable */ #define EDEADLK 35 /* Resource deadlock would occur */ #define ENAMETOOLONG 36 /* File name too long */ #define ENOLCK 37 /* No record locks available */ #define ENOSYS 38 /* Function not implemented */ #define ENOTEMPTY 39 /* Directory not empty */ #define ELOOP 40 /* Too many symbolic links encountered */ #define EWOULDBLOCK EAGAIN /* Operation would block */ #define ENOMSG 42 /* No message of desired type */ #define EIDRM 43 /* Identifier removed */ #define ECHRNG 44 /* Channel number out of range */ #define EL2NSYNC 45 /* Level 2 not synchronized */ #define EL3HLT 46 /* Level 3 halted */ #define EL3RST 47 /* Level 3 reset */ #define ELNRNG 48 /* Link number out of range */ #define EUNATCH 49 /* Protocol driver not attached */ #define ENOCSI 50 /* No CSI structure available */ #define EL2HLT 51 /* Level 2 halted */ #define EBADE 52 /* Invalid exchange */ #define EBADR 53 /* Invalid request descriptor */ #define EXFULL 54 /* Exchange full */ #define ENOANO 55 /* No anode */ #define EBADRQC 56 /* Invalid request code */ #define EBADSLT 57 /* Invalid slot */ #define EDEADLOCK 58 #define EBFONT 59 /* Bad font file format */ /* This is only used internally in newlib; not returned by the kernel. EBFONT seems the closest match for a "bad file format" error. */ #define EFTYPE EBFONT /* Inappropriate file type or format */ #define ENOSTR 60 /* Device not a stream */ #define ENODATA 61 /* No data available */ #define ETIME 62 /* Timer expired */ #define ENOSR 63 /* Out of streams resources */ #define ENONET 64 /* Machine is not on the network */ #define ENOPKG 65 /* Package not installed */ #define EREMOTE 66 /* Object is remote */ #define ENOLINK 67 /* Link has been severed */ #define EADV 68 /* Advertise error */ #define ESRMNT 69 /* Srmount error */ #define ECOMM 70 /* Communication error on send */ #define EPROTO 71 /* Protocol error */ #define EMULTIHOP 72 /* Multihop attempted */ #define EDOTDOT 73 /* RFS specific error */ #define EBADMSG 74 /* Not a data message */ #define EOVERFLOW 75 /* Value too large for defined data type */ #define ENOTUNIQ 76 /* Name not unique on network */ #define EBADFD 77 /* File descriptor in bad state */ #define EREMCHG 78 /* Remote address changed */ #define ELIBACC 79 /* Can not access a needed shared library */ #define ELIBBAD 80 /* Accessing a corrupted shared library */ #define ELIBSCN 81 /* .lib section in a.out corrupted */ #define ELIBMAX 82 /* Attempting to link in too many shared libraries */ #define ELIBEXEC 83 /* Cannot exec a shared library directly */ #define EILSEQ 84 /* Illegal byte sequence */ #define ERESTART 85 /* Interrupted system call should be restarted */ #define ESTRPIPE 86 /* Streams pipe error */ #define EUSERS 87 /* Too many users */ #define ENOTSOCK 88 /* Socket operation on non-socket */ #define EDESTADDRREQ 89 /* Destination address required */ #define EMSGSIZE 90 /* Message too long */ #define EPROTOTYPE 91 /* Protocol wrong type for socket */ #define ENOPROTOOPT 92 /* Protocol not available */ #define EPROTONOSUPPORT 93 /* Protocol not supported */ #define ESOCKTNOSUPPORT 94 /* Socket type not supported */ #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ #define ENOTSUP EOPNOTSUPP #define EPFNOSUPPORT 96 /* Protocol family not supported */ #define EAFNOSUPPORT 97 /* Address family not supported by protocol */ #define EADDRINUSE 98 /* Address already in use */ #define EADDRNOTAVAIL 99 /* Cannot assign requested address */ #define ENETDOWN 100 /* Network is down */ #define ENETUNREACH 101 /* Network is unreachable */ #define ENETRESET 102 /* Network dropped connection because of reset */ #define ECONNABORTED 103 /* Software caused connection abort */ #define ECONNRESET 104 /* Connection reset by peer */ #define ENOBUFS 105 /* No buffer space available */ #define EISCONN 106 /* Transport endpoint is already connected */ #define ENOTCONN 107 /* Transport endpoint is not connected */ #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ #define ETOOMANYREFS 109 /* Too many references: cannot splice */ #define ETIMEDOUT 110 /* Connection timed out */ #define ECONNREFUSED 111 /* Connection refused */ #define EHOSTDOWN 112 /* Host is down */ #define EHOSTUNREACH 113 /* No route to host */ #define EALREADY 114 /* Operation already in progress */ #define EINPROGRESS 115 /* Operation now in progress */ #define ESTALE 116 /* Stale NFS file handle */ #define EUCLEAN 117 /* Structure needs cleaning */ #define ENOTNAM 118 /* Not a XENIX named type file */ #define ENAVAIL 119 /* No XENIX semaphores available */ #define EISNAM 120 /* Is a named type file */ #define EREMOTEIO 121 /* Remote I/O error */ #define EDQUOT 122 /* Quota exceeded */ #define ENOMEDIUM 123 /* No medium found */ #define EMEDIUMTYPE 124 /* Wrong medium type */ #define ECANCELED 125 /* Operation Canceled */ #define __ELASTERROR 2000 /* Users can add values starting here */ _END_STD_C #endif /* _SYS_ERRNO_H */ picolibc-1.8.11/libc/machine/spu/sys/linux_syscalls.h000066400000000000000000000240431513574234600225720ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Ken Werner */ #ifndef __LINUX_SYSCALLS_H #define __LINUX_SYSCALLS_H #include /* The system call numbers. See kernel source file arch/powerpc/include/asm/unistd.h. */ #define __NR_read 3 #define __NR_write 4 #define __NR_open 5 #define __NR_close 6 #define __NR_waitpid 7 #define __NR_creat 8 #define __NR_link 9 #define __NR_unlink 10 #define __NR_chdir 12 #define __NR_time 13 #define __NR_mkdod 14 #define __NR_chmod 15 #define __NR_lchown 16 #define __NR_lseek 19 #define __NR_getpid 20 #define __NR_setuid 23 #define __NR_getuid 24 #define __NR_stime 25 #define __NR_alarm 27 #define __NR_access 33 #define __NR_nice 34 #define __NR_sync 36 #define __NR_kill 37 #define __NR_rename 38 #define __NR_mkdir 39 #define __NR_rmdir 40 #define __NR_dup 41 #define __NR_pipe 42 #define __NR_times 43 #define __NR_brk 45 #define __NR_setgid 46 #define __NR_getgid 47 #define __NR_geteuid 49 #define __NR_getegid 50 #define __NR_ioctl 54 #define __NR_fcntl 55 #define __NR_setpgid 57 #define __NR_umask 60 #define __NR_chroot 61 #define __NR_dup2 63 #define __NR_getppid 64 #define __NR_getpgrp 65 #define __NR_setsid 66 #define __NR_sgetmask 68 #define __NR_ssetmask 69 #define __NR_setreuid 70 #define __NR_setregid 71 #define __NR_sethostname 74 #define __NR_setrlimit 75 #define __NR_getrusage 77 #define __NR_gettimeofday 78 #define __NR_settimeofday 79 #define __NR_getgroups 80 #define __NR_setgroups 81 #define __NR_symlink 83 #define __NR_readlink 85 #define __NR_mmap 90 #define __NR_munmap 91 #define __NR_truncate 92 #define __NR_ftruncate 93 #define __NR_fchmod 94 #define __NR_fchown 95 #define __NR_getpriority 96 #define __NR_setpriority 97 #define __NR_socketcall 102 #define __NR_syslog 103 #define __NR_setitimer 104 #define __NR_getitimer 105 #define __NR_newstat 106 #define __NR_newlstat 107 #define __NR_newfstat 108 #define __NR_vhangup 111 #define __NR_wait4 114 #define __NR_sysinfo 116 #define __NR_fsync 118 #define __NR_setdomainname 121 #define __NR_newuname 122 #define __NR_adjtimex 124 #define __NR_mprotect 125 #define __NR_getpgid 132 #define __NR_fchdir 133 #define __NR_bdflush 134 #define __NR_personality 136 #define __NR_setfsuid 138 #define __NR_setfsgid 139 #define __NR__llseek 140 #define __NR_getdents 141 #define __NR__newselect 142 #define __NR_flock 143 #define __NR_msync 144 #define __NR_readv 145 #define __NR_writev 146 #define __NR_getsid 147 #define __NR_fdatasync 148 #define __NR_mlock 150 #define __NR_munlock 151 #define __NR_mlockall 152 #define __NR_munlockall 153 #define __NR_sched_setparam 154 #define __NR_sched_getparam 155 #define __NR_sched_setscheduler 156 #define __NR_sched_getscheduler 157 #define __NR_sched_yield 158 #define __NR_sched_get_priority_max 159 #define __NR_sched_get_priority_min 160 #define __NR_sched_rr_get_interval 161 #define __NR_nanosleep 162 #define __NR_mremap 163 #define __NR_setresuid 164 #define __NR_getresuid 165 #define __NR_poll 167 #define __NR_setresgid 169 #define __NR_getresgid 170 #define __NR_prctl 171 #define __NR_pread64 179 #define __NR_pwrite64 180 #define __NR_chown 181 #define __NR_getcwd 182 #define __NR_capget 183 #define __NR_capset 184 #define __NR_sendfile 185 #define __NR_getrlimit 190 #define __NR_readahead 191 #define __NR_getdents64 202 #define __NR_pivot_root 203 #define __NR_madvise 205 #define __NR_mincore 206 #define __NR_gettid 207 #define __NR_tkill 208 #define __NR_setxattr 209 #define __NR_lsetxattr 210 #define __NR_fsetxattr 211 #define __NR_getxattr 212 #define __NR_lgetxattr 213 #define __NR_fgetxattr 214 #define __NR_listxattr 215 #define __NR_llistxattr 216 #define __NR_flistxattr 217 #define __NR_removexattr 218 #define __NR_lremovexattr 219 #define __NR_fremovexattr 220 #define __NR_futex 221 #define __NR_sched_setaffinity 222 #define __NR_sched_getaffinity 223 #define __NR_io_setup 227 #define __NR_io_destroy 228 #define __NR_io_getevents 229 #define __NR_io_submit 230 #define __NR_io_cancel 231 #define __NR_fadvise64 233 #define __NR_epoll_create 236 #define __NR_epoll_ctl 237 #define __NR_epoll_wait 238 #define __NR_remap_file_pages 239 #define __NR_timer_create 240 #define __NR_timer_settime 241 #define __NR_timer_gettime 242 #define __NR_timer_getoverrun 243 #define __NR_timer_delete 244 #define __NR_clock_settime 245 #define __NR_clock_gettime 246 #define __NR_clock_getres 247 #define __NR_clock_nanosleep 248 #define __NR_tgkill 250 #define __NR_utimes 251 #define __NR_statfs64 252 #define __NR_fstatfs64 253 #define __NR_rtas 255 #define __NR_unshare 282 #define __NR_splice 283 #define __NR_tee 284 #define __NR_vmsplice 285 #define __NR_openat 286 #define __NR_mkdirat 287 #define __NR_mknodat 288 #define __NR_fchownat 289 #define __NR_futimesat 290 #define __NR_fstatat64 291 #define __NR_unlinkat 292 #define __NR_renameat 293 #define __NR_linkat 294 #define __NR_symlinkat 295 #define __NR_readlinkat 296 #define __NR_fchmodat 297 #define __NR_faccessat 298 #define __NR_get_robust_list 299 #define __NR_set_robust_list 300 #define __NR_move_pages 301 #define __NR_getcpu 302 #define __NR_utimensat 304 #define __NR_signalfd 305 #define __NR_timerfd 306 #define __NR_eventfd 307 #define __NR_sync_file_range2 308 #define __NR_fallocate 309 #define __NR_subpage_prot 310 #define __NR_timerfd_settime 311 #define __NR_timerfd_gettime 312 #define __NR_signalfd4 313 #define __NR_eventfd2 314 #define __NR_epoll_create1 315 #define __NR_dup3 316 #define __NR_pipe2 317 #define __NR_inotify_init1 318 /* System callbacks from the SPU. See kernel source file arch/powerpc/include/asm/spu.h. */ struct spu_syscall_block { unsigned long long nr_ret; /* System call nr and return value. */ unsigned long long parm[6]; /* System call arguments. */ }; _BEGIN_STD_C /* Issues a Linux system call. */ int __linux_syscall(struct spu_syscall_block *s); /* Linux system calls. */ pid_t linux_getpid(void); pid_t linux_gettid(void); _END_STD_C #endif picolibc-1.8.11/libc/machine/spu/sys/mman.h000066400000000000000000000054201513574234600204440ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2007 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MMAN_H_ #define _MMAN_H_ #include /* * Prots to 'mmap'. */ #define PROT_READ 0x1 #define PROT_WRITE 0x2 #define PROT_EXEC 0x4 #define PROT_NONE 0x0 /* * Flags to 'mmap'. */ #define MAP_SHARED 0x001 #define MAP_PRIVATE 0x002 #define MAP_FIXED 0x010 #define MAP_FILE 0x000 #define MAP_ANONYMOUS 0x020 #define MAP_ANON MAP_ANONYMOUS #define MAP_GROWSDOWN 0x0100 #define MAP_DENYWRITE 0x0800 #define MAP_EXECUTABLE 0x1000 #define MAP_LOCKED 0x0080 #define MAP_NORESERVE 0x0040 /* * Failed flag from 'mmap'. */ #define MAP_FAILED_EADDR ((unsigned long long)(-1LL)) /* * Flags to 'mremap'. */ #define MREMAP_MAYMOVE 1 /* * Flags to 'msync'. */ #define MS_ASYNC 1 #define MS_SYNC 4 #define MS_INVALIDATE 2 extern int shm_open(const char *name, int oflag, mode_t mode); extern int shm_unlink(const char *name); unsigned long long mmap_eaddr(unsigned long long start, size_t length, int prot, int flags, int fd, off_t offset); unsigned long long mremap_eaddr(unsigned long long old_addr, size_t old_size, size_t new_size, int flags); unsigned long long msync_eaddr(unsigned long long start, size_t length, int flags); unsigned long long munmap_eaddr(unsigned long long start, size_t length); #endif /* _MMAN_H_ */ picolibc-1.8.11/libc/machine/spu/sys/sched.h000066400000000000000000000002741513574234600206040ustar00rootroot00000000000000/* Copyright (c) 2007 Patrick Mansfield */ #ifndef _SYS_SCHED_H #define _SYS_SCHED_H #include _BEGIN_STD_C int sched_yield(void); _END_STD_C #endif picolibc-1.8.11/libc/machine/spu/sys/syscall.h000066400000000000000000000003661513574234600211720ustar00rootroot00000000000000/* Copyright (c) 2007 Patrick Mansfield */ #ifndef _SYS_SYSCALL_H #define _SYS_SYSCALL_H #include _BEGIN_STD_C int __send_to_ppe(unsigned int signalcode, unsigned int opcode, void *data); _END_STD_C #endif picolibc-1.8.11/libc/machine/spu/sys/uio.h000066400000000000000000000005211513574234600203050ustar00rootroot00000000000000/* Copyright (c) 2007 Patrick Mansfield */ #ifndef _SYS_UIO_H #define _SYS_UIO_H #include _BEGIN_STD_C /* * Per POSIX */ struct iovec { void *iov_base; size_t iov_len; }; ssize_t readv(int, const struct iovec *, int); ssize_t writev(int, const struct iovec *, int); _END_STD_C #endif picolibc-1.8.11/libc/machine/spu/sys/utime.h000066400000000000000000000004461513574234600206420ustar00rootroot00000000000000/* Copyright (c) 2007 Patrick Mansfield */ #ifndef _SYS_UTIME_H #define _SYS_UTIME_H #include _BEGIN_STD_C /* * Per POSIX */ struct utimbuf { time_t actime; time_t modtime; }; int utime(const char *, const struct utimbuf *); _END_STD_C #endif picolibc-1.8.11/libc/machine/spu/syscall.def000066400000000000000000000036241513574234600206630ustar00rootroot00000000000000# # (C) Copyright 2007 TOSHIBA CORPORATION # All Rights Reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the names of Toshiba nor the names of its # contributors may be used to endorse or promote products derived from this # software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # # OPCODE NAME FP PARMS(Number of fixed arguments) # SPE_C99_VFPRINTF fprintf 1 2 SPE_C99_VFSCANF fscanf 1 2 SPE_C99_VPRINTF printf 0 1 SPE_C99_VSCANF scanf 0 1 SPE_C99_VSNPRINTF snprintf 0 3 SPE_C99_VSPRINTF sprintf 0 2 SPE_C99_VSSCANF sscanf 0 2 picolibc-1.8.11/libc/machine/spu/tmpfile.c000066400000000000000000000036601513574234600203350ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" FILE * tmpfile(void) { int ret; FILE *fp; struct _reent *ptr = _REENT; CHECK_INIT(ptr); fp = __sfp(ptr); if (!fp) { return NULL; } ret = __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_TMPFILE, &ret); if (ret) { fp->_fp = ret; return fp; } else { __sfp_free(fp); return NULL; } } picolibc-1.8.11/libc/machine/spu/tmpnam.c000066400000000000000000000033151513574234600201660ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" char * tmpnam(char *s) { /* The return value gets written over buf */ return (char *)__send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_TMPNAM, &s); } picolibc-1.8.11/libc/machine/spu/ungetc.c000066400000000000000000000036311513574234600201600ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" typedef struct { int c; unsigned int pad0[3]; int fp; unsigned int pad1[3]; } c99_ungetc_t; int ungetc(c, fp) int c; register FILE *fp; { c99_ungetc_t args; CHECK_INIT(_REENT); args.c = c; args.fp = fp->_fp; return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_UNGETC, &args); } picolibc-1.8.11/libc/machine/spu/usleep.c000066400000000000000000000007351513574234600201720ustar00rootroot00000000000000/* Copied from libc/posix/usleep.c, removed the check for HAVE_NANOSLEEP */ /* Copyright (c) 2002 by Jeff Johnston */ #include #include #include #include int usleep(useconds_t useconds) { struct timespec ts; ts.tv_sec = (long int)useconds / 1000000; ts.tv_nsec = ((long int)useconds % 1000000) * 1000; if (!nanosleep(&ts, &ts)) return 0; if (errno == EINTR) return ts.tv_sec; return -1; } picolibc-1.8.11/libc/machine/spu/vec_literal.h000066400000000000000000000073421513574234600211740ustar00rootroot00000000000000/* (C) Copyright 2001,2006, International Business Machines Corporation, Sony Computer Entertainment, Incorporated, Toshiba Corporation, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _VEC_LITERAL_H_ #define _VEC_LITERAL_H_ /* This header files provides an abstraction for the various implementations * of vector literal construction. The two formats are: * * 1) Altivec styled using parenthesis * 2) C grammer friendly styled using curly braces * * The macro, VEC_LITERAL has been developed to provide some portability * in these two styles. To achieve true portability, user must specify all * elements of the vector being initialized. A single element can be provided * but only the first element guarenteed across both construction styles. * * The VEC_SPLAT_* macros have been provided for portability of vector literal * construction when all the elements of the vector contain the same value. */ /* Use curly brace style. */ #define VEC_LITERAL(_type, ...) ((_type) { __VA_ARGS__ }) #define VEC_SPLAT_U8(_val) \ ((__vector unsigned char) { _val, _val, _val, _val, _val, _val, _val, _val, _val, _val, _val, \ _val, _val, _val, _val, _val }) #define VEC_SPLAT_S8(_val) \ ((__vector signed char) { _val, _val, _val, _val, _val, _val, _val, _val, _val, _val, _val, \ _val, _val, _val, _val, _val }) #define VEC_SPLAT_U16(_val) \ ((__vector unsigned short) { _val, _val, _val, _val, _val, _val, _val, _val }) #define VEC_SPLAT_S16(_val) \ ((__vector signed short) { _val, _val, _val, _val, _val, _val, _val, _val }) #define VEC_SPLAT_U32(_val) ((__vector unsigned int) { _val, _val, _val, _val }) #define VEC_SPLAT_S32(_val) ((__vector signed int) { _val, _val, _val, _val }) #define VEC_SPLAT_F32(_val) ((__vector float) { _val, _val, _val, _val }) #define VEC_SPLAT_U64(_val) ((__vector unsigned long long) { _val, _val }) #define VEC_SPLAT_S64(_val) ((__vector signed long long) { _val, _val }) #define VEC_SPLAT_F64(_val) ((__vector double) { _val, _val }) #endif /* _VEC_LITERAL_H_ */ picolibc-1.8.11/libc/machine/spu/vfiprintf.c000066400000000000000000000002051513574234600206740ustar00rootroot00000000000000/* Copyright (c) 2007 Kazunori Asayama */ #include #define INTEGER_ONLY #include "vfprintf.c" picolibc-1.8.11/libc/machine/spu/vfiscanf.c000066400000000000000000000002041513574234600204630ustar00rootroot00000000000000/* Copyright (c) 2007 Kazunori Asayama */ #include #define INTEGER_ONLY #include "vfscanf.c" picolibc-1.8.11/libc/machine/spu/vfprintf.c000066400000000000000000000040601513574234600205260ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" #include #ifdef INTEGER_ONLY #define vfprintf vfiprintf #endif typedef struct { int fp; unsigned int pad0[3]; char *fmt; unsigned int pad1[3]; va_list ap; } c99_vfprintf_t; int vfprintf(FILE * __restrict fp, const char * __restrict fmt0, va_list ap) { c99_vfprintf_t args; CHECK_INIT(_REENT); args.fp = fp->_fp; args.fmt = (char *)fmt0; va_copy(args.ap, ap); return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_VFPRINTF, &args); } picolibc-1.8.11/libc/machine/spu/vfscanf.c000066400000000000000000000040501513574234600203150ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" #include #ifdef INTEGER_ONLY #define vfscanf vfiscanf #endif typedef struct { int fp; unsigned int pad0[3]; char *fmt; unsigned int pad1[3]; va_list ap; } c99_vfscanf_t; int vfscanf(FILE * __restrict fp, const char * __restrict fmt, va_list ap) { c99_vfscanf_t args; CHECK_INIT(_REENT); args.fp = fp->_fp; args.fmt = (char *)fmt; va_copy(args.ap, ap); return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_VFSCANF, &args); } picolibc-1.8.11/libc/machine/spu/viprintf.c000066400000000000000000000002031513574234600205240ustar00rootroot00000000000000/* Copyright (c) 2007 Kazunori Asayama */ #include #define INTEGER_ONLY #include "vprintf.c" picolibc-1.8.11/libc/machine/spu/viscanf.c000066400000000000000000000002031513574234600203140ustar00rootroot00000000000000/* Copyright (c) 2007 Kazunori Asayama */ #include #define INTEGER_ONLY #include "vscanf.c" picolibc-1.8.11/libc/machine/spu/vprintf.c000066400000000000000000000035331513574234600203640ustar00rootroot00000000000000/* Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "c99ppe.h" #include #ifdef INTEGER_ONLY #define vprintf viprintf #endif typedef struct { const char *fmt; unsigned int pad0[3]; va_list ap; } c99_vprintf_t; int vprintf(const char *fmt, va_list ap) { c99_vprintf_t args; args.fmt = fmt; va_copy(args.ap, ap); return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_VPRINTF, &args); } picolibc-1.8.11/libc/machine/spu/vscanf.c000066400000000000000000000036411513574234600201540ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" #include #ifdef INTEGER_ONLY #define vscanf viscanf #endif typedef struct { char *fmt; unsigned int pad0[3]; va_list ap; } c99_vscanf_t; int vscanf(const char *fmt, va_list ap) { c99_vscanf_t args; args.fmt = (char *)fmt; va_copy(args.ap, ap); return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_VSCANF, &args); } picolibc-1.8.11/libc/machine/spu/vsiprintf.c000066400000000000000000000002051513574234600207110ustar00rootroot00000000000000/* Copyright (c) 2007 Kazunori Asayama */ #include #define INTEGER_ONLY #include "vsprintf.c" picolibc-1.8.11/libc/machine/spu/vsiscanf.c000066400000000000000000000002041513574234600205000ustar00rootroot00000000000000/* Copyright (c) 2007 Kazunori Asayama */ #include #define INTEGER_ONLY #include "vsscanf.c" picolibc-1.8.11/libc/machine/spu/vsniprintf.c000066400000000000000000000002061513574234600210700ustar00rootroot00000000000000/* Copyright (c) 2007 Kazunori Asayama */ #include #define INTEGER_ONLY #include "vsnprintf.c" picolibc-1.8.11/libc/machine/spu/vsnprintf.c000066400000000000000000000040771513574234600207310ustar00rootroot00000000000000/* Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "c99ppe.h" #include #ifdef INTEGER_ONLY #define vsnprintf vsniprintf #endif typedef struct { char *str; unsigned int pad0[3]; size_t size; unsigned int pad1[3]; const char *fmt; unsigned int pad2[3]; va_list ap; } c99_vsnprintf_t; int vsnprintf(char * __restrict str, size_t size, const char * __restrict fmt, va_list ap) { c99_vsnprintf_t args; CHECK_STR_INIT(_REENT); args.str = str; args.size = size; args.fmt = fmt; va_copy(args.ap, ap); return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_VSNPRINTF, &args); } picolibc-1.8.11/libc/machine/spu/vsprintf.c000066400000000000000000000037561513574234600205560ustar00rootroot00000000000000/* Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "c99ppe.h" #include #ifdef INTEGER_ONLY #define vsprintf vsiprintf #endif typedef struct { char *str; unsigned int pad0[3]; char *fmt; unsigned int pad1[3]; va_list ap; } c99_vsprintf_t; int vsprintf(char * __restrict str, const char * __restrict fmt, va_list ap) { c99_vsprintf_t args; CHECK_STR_INIT(_REENT); args.str = str; args.fmt = (char *)fmt; va_copy(args.ap, ap); return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_VSPRINTF, &args); } picolibc-1.8.11/libc/machine/spu/vsscanf.c000066400000000000000000000040611513574234600203340ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2006 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Joel Schopp */ #include #include #include "c99ppe.h" #include #ifdef INTEGER_ONLY #define vsscanf vsiscanf #endif typedef struct { const char *str; unsigned int pad0[3]; const char *fmt; unsigned int pad1[3]; va_list ap; } c99_vsscanf_t; int vsscanf(const char * __restrict str, const char * __restrict fmt, va_list ap) { c99_vsscanf_t args; CHECK_STR_INIT(_REENT); args.str = str; args.fmt = (char *)fmt; va_copy(args.ap, ap); return __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_VSSCANF, &args); } picolibc-1.8.11/libc/machine/spu/write_ea.c000066400000000000000000000037541513574234600205000ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Ken Werner */ #include #include "ea_internal.h" #include #include #include "sys/linux_syscalls.h" extern void __cache_flush(void) __weak; COMPAT_EA_ALIAS(write_ea); ssize_ea_t write_ea(int fd, __ea const void *buf, size_ea_t count) { struct spu_syscall_block s = { __NR_write, { fd, (size_ea_t)buf, count, 0, 0, 0 } }; /* Flush cache only if the application really uses the software cache. */ if (__cache_flush) __cache_flush(); return __linux_syscall(&s); } picolibc-1.8.11/libc/machine/spu/writev_ea.c000066400000000000000000000043071513574234600206610ustar00rootroot00000000000000/* (C) Copyright IBM Corp. 2008 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of IBM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Author: Ken Werner */ #include #include "ea_internal.h" #include #include #include "sys/linux_syscalls.h" extern void __cache_flush(void) __weak; COMPAT_EA_ALIAS(writev_ea); ssize_ea_t writev_ea(int fd, struct iovec_ea *vector, int count) { #ifdef __EA32__ int i; #endif struct spu_syscall_block s = { __NR_writev, { fd, (size_ea_t)(__ea void *)vector, count, 0, 0, 0 } }; #ifdef __EA32__ for (i = 0; i < count; ++i) { vector[i].__pad1 = 0x0; /* 32 bit padding */ vector[i].__pad2 = 0x0; /* 32 bit padding */ } #endif /* Flush cache only if the application really uses the software cache. */ if (__cache_flush) __cache_flush(); return __linux_syscall(&s); } picolibc-1.8.11/libc/machine/tic4x/000077500000000000000000000000001513574234600167505ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/tic4x/setjmp.S000066400000000000000000000027301513574234600204000ustar00rootroot00000000000000/* * Copyright (c) 2004 Michael Hayes . * * The author hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice is included verbatim in any distributions. No written agreement, * license, or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their authors * and need not follow the licensing terms described here, provided that * the new terms are clearly indicated on the first page of each file where * they apply. */ /* setjmp/longjmp routines. */ #include .sect .text .global setjmp .global longjmp setjmp: pop r1 ldi sp, ar0 #ifndef _REGPARM ldi *ar0, ar2 #endif sti r4, *ar2++ sti r5, *ar2++ stf r6, *ar2++ stf r7, *ar2++ #ifdef _TMS320C4x sti r8, *ar2++ #endif sti ar3, *ar2++ sti ar4, *ar2++ sti ar5, *ar2++ sti ar6, *ar2++ sti ar7, *ar2++ bd r1 sti r1, *ar2++ sti ar0, *ar2 ldi 0, r0 longjmp: #ifndef _REGPARM ldi sp, ar0 ldi *-ar0(1), ar2 ldi *-ar0(2), r0 ldiz 1, r0 #else ldi r2, r0 ldiz 1, r0 #endif ldi *ar2++, r4 ldi *ar2++, r5 ldf *ar2++, r6 ldf *ar2++, r7 #ifdef _TMS320C4x ldi *ar2++, r8 #endif ldi *ar2++, ar3 ldi *ar2++, ar4 ldi *ar2++, ar5 ldi *ar2++, ar6 ldi *ar2++, ar7 ldi *ar2++, r1 ldi *ar2, sp b r1 .end picolibc-1.8.11/libc/machine/tic6x/000077500000000000000000000000001513574234600167525ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/tic6x/setjmp.S000066400000000000000000000076141513574234600204100ustar00rootroot00000000000000#include ;****************************************************************************** ;* SETJMP v7.2.0I10181 * ;* * ;/* Copyright (c) 1996-2010 Texas Instruments Incorporated */ ;* http://www.ti.com/ * ;* * ;* Redistribution and use in source and binary forms, with or without * ;* modification, are permitted provided that the following conditions * ;* are met: * ;* * ;* Redistributions of source code must retain the above copyright * ;* notice, this list of conditions and the following disclaimer. * ;* * ;* Redistributions in binary form must reproduce the above copyright * ;* notice, this list of conditions and the following disclaimer in * ;* the documentation and/or other materials provided with the * ;* distribution. * ;* * ;* Neither the name of Texas Instruments Incorporated nor the names * ;* of its contributors may be used to endorse or promote products * ;* derived from this software without specific prior written * ;* permission. * ;* * ;* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ;* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ;* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * ;* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * ;* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * ;* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * ;* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * ;* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * ;* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ;* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * ;* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ;* * ;****************************************************************************** .text .globl setjmp .type setjmp,%function setjmp: MV .L2X A4, B4 || STW .D1T2 B3, *+A4(48) STW .D1T1 A10, *+A4(0) || STW .D2T2 B10, *+B4(4) || RET .S2 B3 STW .D1T1 A11, *+A4(8) || STW .D2T2 B11, *+B4(12) STW .D1T1 A12, *+A4(16) || STW .D2T2 B12, *+B4(20) STW .D1T1 A13, *+A4(24) || STW .D2T2 B13, *+B4(28) STW .D1T1 A14, *+A4(32) || STW .D2T2 B14, *+B4(36) STW .D1T1 A15, *+A4(40) || STW .D2T2 B15, *+B4(44) || ZERO .S1 A4 .size setjmp, . - setjmp .globl longjmp .type longjmp,%function longjmp: LDW .D1T1 *+A4(48), A3 MV .L2X A4, B6 || MV .S1 A4, A6 || MV .D2 B4, B2 LDW .D1T1 *+A6(0), A10 || LDW .D2T2 *+B6(4), B10 || [B2] MV .L1X B4, A4 || [!B2] MVK .S1 1, A4 LDW .D1T1 *+A6(8), A11 || LDW .D2T2 *+B6(12), B11 LDW .D1T1 *+A6(16), A12 || LDW .D2T2 *+B6(20), B12 LDW .D1T1 *+A6(24), A13 || LDW .D2T2 *+B6(28), B13 LDW .D1T1 *+A6(32), A14 || LDW .D2T2 *+B6(36), B14 LDW .D1T1 *+A6(40), A15 || LDW .D2T2 *+B6(44), B15 || RET .S2X A3 NOP 5 .size longjmp, . - longjmp picolibc-1.8.11/libc/machine/tic80/000077500000000000000000000000001513574234600166445ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/tic80/setjmp.S000066400000000000000000000031451513574234600202750ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* These are predefined by new versions of GNU cpp. */ #include #ifndef __USER_LABEL_PREFIX__ #define __USER_LABEL_PREFIX__ _ #endif /* ANSI concatenation macros. */ #define CONCAT1(a, b) CONCAT2(a, b) #define CONCAT2(a, b) a ## b /* Use the right prefix for global labels. */ #define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x) .global SYM (setjmp) .global SYM (_setjmp) .global SYM (longjmp) .section .text,"x" .align 4 SYM (_setjmp): SYM (setjmp): st.d 0(r2),r20 st.d 8(r2),r22 st.d 16(r2),r24 st.d 24(r2),r26 st.d 32(r2),r28 st.d 40(r2),r30 st 48(r2),r1 jsr r31(r0),r0 addu 0,r0,r2 .section .text,"x" .align 4 SYM (longjmp): ld.d 0(r2),r20 ld.d 8(r2),r22 ld.d 16(r2),r24 ld.d 24(r2),r26 ld.d 32(r2),r28 ld.d 40(r2),r30 bcnd L1,r4,ne0.w ld 48(r2),r1 jsr r31(r0),r0 addu 1,r0,r2 L1: jsr r31(r0),r0 addu r4,r0,r2 picolibc-1.8.11/libc/machine/v850/000077500000000000000000000000001513574234600164175ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/v850/setjmp.S000066400000000000000000000026721513574234600200540ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .file "setjmp.S" .section .text .align 1 .global _setjmp _setjmp: st.w r1,0[r6] st.w r3,4[r6] st.w r4,8[r6] st.w r20,12[r6] st.w r21,16[r6] st.w r22,20[r6] st.w r23,24[r6] st.w r24,28[r6] st.w r25,32[r6] st.w r26,36[r6] st.w r27,40[r6] st.w r28,44[r6] st.w r29,48[r6] st.w r30,52[r6] st.w r31,56[r6] mov r0, r10 jmp [r31] .global _longjmp _longjmp: ld.w 0[r6],r1 ld.w 4[r6],r3 ld.w 8[r6],r4 ld.w 12[r6],r20 ld.w 16[r6],r21 ld.w 20[r6],r22 ld.w 24[r6],r23 ld.w 28[r6],r24 ld.w 32[r6],r25 ld.w 36[r6],r26 ld.w 40[r6],r27 ld.w 44[r6],r28 ld.w 48[r6],r29 ld.w 52[r6],r30 ld.w 56[r6],r31 cmp r7, r0 jne 1f mov 1,r7 1: mov r7, r10 jmp [r31] picolibc-1.8.11/libc/machine/visium/000077500000000000000000000000001513574234600172315ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/visium/memcpy.c000066400000000000000000000612411513574234600206730ustar00rootroot00000000000000/* memcpy for the Visium processor. Copyright (c) 2015 Rolls-Royce Controls and Data Services Limited. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Rolls-Royce Controls and Data Services Limited nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This file must be kept in sync with libgcc/config/visium/memcpy.c */ #include #include #include "memcpy.h" #include "../../string/local.h" #define INST_BARRIER __asm__ __volatile__("" ::: "memory"); #define MOVE_32_OBJECTS(in, out) \ do { \ INST_BARRIER \ m0 = in[0]; \ m1 = in[1]; \ m2 = in[2]; \ m3 = in[3]; \ out[0] = m0; \ out[1] = m1; \ out[2] = m2; \ out[3] = m3; \ INST_BARRIER \ m0 = in[4]; \ m1 = in[5]; \ m2 = in[6]; \ m3 = in[7]; \ out[4] = m0; \ out[5] = m1; \ out[6] = m2; \ out[7] = m3; \ INST_BARRIER \ m0 = in[8]; \ m1 = in[9]; \ m2 = in[10]; \ m3 = in[11]; \ out[8] = m0; \ out[9] = m1; \ out[10] = m2; \ out[11] = m3; \ INST_BARRIER \ m0 = in[12]; \ m1 = in[13]; \ m2 = in[14]; \ m3 = in[15]; \ out[12] = m0; \ out[13] = m1; \ out[14] = m2; \ out[15] = m3; \ INST_BARRIER \ m0 = in[16]; \ m1 = in[17]; \ m2 = in[18]; \ m3 = in[19]; \ out[16] = m0; \ out[17] = m1; \ out[18] = m2; \ out[19] = m3; \ INST_BARRIER \ m0 = in[20]; \ m1 = in[21]; \ m2 = in[22]; \ m3 = in[23]; \ out[20] = m0; \ out[21] = m1; \ out[22] = m2; \ out[23] = m3; \ INST_BARRIER \ m0 = in[24]; \ m1 = in[25]; \ m2 = in[26]; \ m3 = in[27]; \ out[24] = m0; \ out[25] = m1; \ out[26] = m2; \ out[27] = m3; \ INST_BARRIER \ m0 = in[28]; \ m1 = in[29]; \ m2 = in[30]; \ m3 = in[31]; \ out[28] = m0; \ out[29] = m1; \ out[30] = m2; \ out[31] = m3; \ INST_BARRIER \ in += 32; \ out += 32; \ } while (0) #define MOVE_16_OBJECTS(in, out) \ do { \ INST_BARRIER \ m0 = in[0]; \ m1 = in[1]; \ m2 = in[2]; \ m3 = in[3]; \ out[0] = m0; \ out[1] = m1; \ out[2] = m2; \ out[3] = m3; \ INST_BARRIER \ m0 = in[4]; \ m1 = in[5]; \ m2 = in[6]; \ m3 = in[7]; \ out[4] = m0; \ out[5] = m1; \ out[6] = m2; \ out[7] = m3; \ INST_BARRIER \ m0 = in[8]; \ m1 = in[9]; \ m2 = in[10]; \ m3 = in[11]; \ out[8] = m0; \ out[9] = m1; \ out[10] = m2; \ out[11] = m3; \ INST_BARRIER \ m0 = in[12]; \ m1 = in[13]; \ m2 = in[14]; \ m3 = in[15]; \ out[12] = m0; \ out[13] = m1; \ out[14] = m2; \ out[15] = m3; \ INST_BARRIER \ in += 16; \ out += 16; \ } while (0) #define MOVE_12_OBJECTS(in, out) \ do { \ INST_BARRIER \ m0 = in[0]; \ m1 = in[1]; \ m2 = in[2]; \ m3 = in[3]; \ out[0] = m0; \ out[1] = m1; \ out[2] = m2; \ out[3] = m3; \ INST_BARRIER \ m0 = in[4]; \ m1 = in[5]; \ m2 = in[6]; \ m3 = in[7]; \ out[4] = m0; \ out[5] = m1; \ out[6] = m2; \ out[7] = m3; \ INST_BARRIER \ m0 = in[8]; \ m1 = in[9]; \ m2 = in[10]; \ m3 = in[11]; \ out[8] = m0; \ out[9] = m1; \ out[10] = m2; \ out[11] = m3; \ INST_BARRIER \ in += 12; \ out += 12; \ } while (0) #define MOVE_11_OBJECTS(in, out) \ do { \ INST_BARRIER \ m0 = in[0]; \ m1 = in[1]; \ m2 = in[2]; \ m3 = in[3]; \ out[0] = m0; \ out[1] = m1; \ out[2] = m2; \ out[3] = m3; \ INST_BARRIER \ m0 = in[4]; \ m1 = in[5]; \ m2 = in[6]; \ m3 = in[7]; \ out[4] = m0; \ out[5] = m1; \ out[6] = m2; \ out[7] = m3; \ INST_BARRIER \ m0 = in[8]; \ m1 = in[9]; \ m2 = in[10]; \ out[8] = m0; \ out[9] = m1; \ out[10] = m2; \ INST_BARRIER \ in += 11; \ out += 11; \ } while (0) #define MOVE_10_OBJECTS(in, out) \ do { \ INST_BARRIER \ m0 = in[0]; \ m1 = in[1]; \ m2 = in[2]; \ m3 = in[3]; \ out[0] = m0; \ out[1] = m1; \ out[2] = m2; \ out[3] = m3; \ INST_BARRIER \ m0 = in[4]; \ m1 = in[5]; \ m2 = in[6]; \ m3 = in[7]; \ out[4] = m0; \ m0 = in[8]; \ out[5] = m1; \ m1 = in[9]; \ out[6] = m2; \ out[7] = m3; \ out[8] = m0; \ out[9] = m1; \ INST_BARRIER \ in += 10; \ out += 10; \ } while (0) #define MOVE_9_OBJECTS(in, out) \ do { \ INST_BARRIER \ m0 = in[0]; \ m1 = in[1]; \ m2 = in[2]; \ m3 = in[3]; \ out[0] = m0; \ out[1] = m1; \ out[2] = m2; \ out[3] = m3; \ INST_BARRIER \ m0 = in[4]; \ m1 = in[5]; \ m2 = in[6]; \ m3 = in[7]; \ out[4] = m0; \ out[5] = m1; \ out[6] = m2; \ out[7] = m3; \ INST_BARRIER \ m0 = in[8]; \ out[8] = m0; \ in += 9; \ out += 9; \ } while (0) #define MOVE_8_OBJECTS(in, out) \ do { \ INST_BARRIER \ m0 = in[0]; \ m1 = in[1]; \ m2 = in[2]; \ m3 = in[3]; \ out[0] = m0; \ out[1] = m1; \ out[2] = m2; \ out[3] = m3; \ INST_BARRIER \ m0 = in[4]; \ m1 = in[5]; \ m2 = in[6]; \ m3 = in[7]; \ out[4] = m0; \ out[5] = m1; \ out[6] = m2; \ out[7] = m3; \ INST_BARRIER \ in += 8; \ out += 8; \ } while (0) #define MOVE_7_OBJECTS(in, out) \ do { \ INST_BARRIER \ m0 = in[0]; \ m1 = in[1]; \ m2 = in[2]; \ m3 = in[3]; \ out[0] = m0; \ out[1] = m1; \ out[2] = m2; \ out[3] = m3; \ INST_BARRIER \ m0 = in[4]; \ m1 = in[5]; \ m2 = in[6]; \ out[4] = m0; \ out[5] = m1; \ out[6] = m2; \ INST_BARRIER \ in += 7; \ out += 7; \ } while (0) #define MOVE_6_OBJECTS(in, out) \ do { \ INST_BARRIER \ m0 = in[0]; \ m1 = in[1]; \ m2 = in[2]; \ m3 = in[3]; \ out[0] = m0; \ INST_BARRIER \ m0 = in[4]; \ out[1] = m1; \ INST_BARRIER \ m1 = in[5]; \ out[2] = m2; \ out[3] = m3; \ out[4] = m0; \ out[5] = m1; \ INST_BARRIER \ in += 6; \ out += 6; \ } while (0) #define MOVE_5_OBJECTS(in, out) \ do { \ INST_BARRIER \ m0 = in[0]; \ m1 = in[1]; \ m2 = in[2]; \ m3 = in[3]; \ INST_BARRIER \ out[0] = m0; \ m0 = in[4]; \ INST_BARRIER \ out[1] = m1; \ out[2] = m2; \ out[3] = m3; \ out[4] = m0; \ INST_BARRIER \ in += 5; \ out += 5; \ } while (0) #define MOVE_4_OBJECTS(in, out) \ do { \ INST_BARRIER \ m0 = in[0]; \ m1 = in[1]; \ m2 = in[2]; \ m3 = in[3]; \ out[0] = m0; \ out[1] = m1; \ out[2] = m2; \ out[3] = m3; \ INST_BARRIER \ in += 4; \ out += 4; \ } while (0) #define MOVE_3_OBJECTS(in, out) \ do { \ INST_BARRIER \ m0 = in[0]; \ m1 = in[1]; \ m2 = in[2]; \ out[0] = m0; \ out[1] = m1; \ out[2] = m2; \ INST_BARRIER \ in += 3; \ out += 3; \ } while (0) #define MOVE_2_OBJECTS(in, out) \ do { \ INST_BARRIER \ m0 = in[0]; \ m1 = in[1]; \ out[0] = m0; \ out[1] = m1; \ INST_BARRIER \ in += 2; \ out += 2; \ } while (0) #define MOVE_1_OBJECT(in, out) \ do { \ INST_BARRIER \ m0 = in[0]; \ out[0] = m0; \ INST_BARRIER \ in += 1; \ out += 1; \ } while (0) static inline void __no_builtin __int_memcpy(void * __restrict s1, const void * __restrict s2, size_t n) { int value = n; int loop_var; const int *in = s2; int *out = s1; int count; int m0, m1, m2, m3; /* This code currently give a stall for any value with a 1->2 in the low 5 bits, i.e. 1,2, 33,34 ? not acceptable! */ switch (value & 0x1f) { case 0: break; case 1: MOVE_1_OBJECT(in, out); break; case 2: MOVE_2_OBJECTS(in, out); break; case 3: MOVE_3_OBJECTS(in, out); break; case 4: MOVE_4_OBJECTS(in, out); break; case 5: MOVE_5_OBJECTS(in, out); break; case 6: MOVE_6_OBJECTS(in, out); break; case 7: MOVE_7_OBJECTS(in, out); break; case 8: MOVE_8_OBJECTS(in, out); break; case 9: MOVE_9_OBJECTS(in, out); break; case 10: MOVE_10_OBJECTS(in, out); break; case 11: MOVE_11_OBJECTS(in, out); break; case 12: MOVE_12_OBJECTS(in, out); break; case 13: MOVE_9_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; case 14: MOVE_12_OBJECTS(in, out); MOVE_2_OBJECTS(in, out); break; case 15: MOVE_11_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; case 16: MOVE_16_OBJECTS(in, out); break; case 17: MOVE_11_OBJECTS(in, out); MOVE_6_OBJECTS(in, out); break; case 18: MOVE_9_OBJECTS(in, out); MOVE_9_OBJECTS(in, out); break; case 19: MOVE_16_OBJECTS(in, out); MOVE_3_OBJECTS(in, out); break; case 20: MOVE_16_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; case 21: MOVE_16_OBJECTS(in, out); MOVE_5_OBJECTS(in, out); break; case 22: MOVE_16_OBJECTS(in, out); MOVE_6_OBJECTS(in, out); break; case 23: MOVE_16_OBJECTS(in, out); MOVE_7_OBJECTS(in, out); break; case 24: MOVE_16_OBJECTS(in, out); MOVE_8_OBJECTS(in, out); break; case 25: MOVE_16_OBJECTS(in, out); MOVE_9_OBJECTS(in, out); break; case 26: MOVE_16_OBJECTS(in, out); MOVE_10_OBJECTS(in, out); break; case 27: MOVE_16_OBJECTS(in, out); MOVE_11_OBJECTS(in, out); break; case 28: MOVE_16_OBJECTS(in, out); MOVE_8_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; case 29: MOVE_16_OBJECTS(in, out); MOVE_9_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; case 30: MOVE_16_OBJECTS(in, out); MOVE_12_OBJECTS(in, out); MOVE_2_OBJECTS(in, out); break; case 31: MOVE_16_OBJECTS(in, out); MOVE_11_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; } /* This loop governs the asmptoptic behaviour of this algorithm, for long word copies. */ count = value >> 5; for (loop_var = 0; loop_var < count; loop_var++) MOVE_32_OBJECTS(in, out); } static inline void __no_builtin __shrt_int_memcpy(void * __restrict s1, const void * __restrict s2, size_t n) { int value = n; int loop_var; const short int *in = s2; int short *out = s1; int count; int m0, m1, m2, m3; /* This code currently give a stall for any value with a 1->2 in the low 5 bits, i.e. 1,2, 33,34 ? not acceptable! */ switch (value & 0x1f) { case 0: break; case 1: MOVE_1_OBJECT(in, out); break; case 2: MOVE_2_OBJECTS(in, out); break; case 3: MOVE_3_OBJECTS(in, out); break; case 4: MOVE_4_OBJECTS(in, out); break; case 5: MOVE_5_OBJECTS(in, out); break; case 6: MOVE_6_OBJECTS(in, out); break; case 7: MOVE_7_OBJECTS(in, out); break; case 8: MOVE_8_OBJECTS(in, out); break; case 9: MOVE_9_OBJECTS(in, out); break; case 10: MOVE_10_OBJECTS(in, out); break; case 11: MOVE_11_OBJECTS(in, out); break; case 12: MOVE_12_OBJECTS(in, out); break; case 13: MOVE_9_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; case 14: MOVE_12_OBJECTS(in, out); MOVE_2_OBJECTS(in, out); break; case 15: MOVE_11_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; case 16: MOVE_16_OBJECTS(in, out); break; case 17: MOVE_11_OBJECTS(in, out); MOVE_6_OBJECTS(in, out); break; case 18: MOVE_9_OBJECTS(in, out); MOVE_9_OBJECTS(in, out); break; case 19: MOVE_16_OBJECTS(in, out); MOVE_3_OBJECTS(in, out); break; case 20: MOVE_16_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; case 21: MOVE_16_OBJECTS(in, out); MOVE_5_OBJECTS(in, out); break; case 22: MOVE_16_OBJECTS(in, out); MOVE_6_OBJECTS(in, out); break; case 23: MOVE_16_OBJECTS(in, out); MOVE_7_OBJECTS(in, out); break; case 24: MOVE_16_OBJECTS(in, out); MOVE_8_OBJECTS(in, out); break; case 25: MOVE_16_OBJECTS(in, out); MOVE_9_OBJECTS(in, out); break; case 26: MOVE_16_OBJECTS(in, out); MOVE_10_OBJECTS(in, out); break; case 27: MOVE_16_OBJECTS(in, out); MOVE_11_OBJECTS(in, out); break; case 28: MOVE_16_OBJECTS(in, out); MOVE_8_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; case 29: MOVE_16_OBJECTS(in, out); MOVE_9_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; case 30: MOVE_16_OBJECTS(in, out); MOVE_12_OBJECTS(in, out); MOVE_2_OBJECTS(in, out); break; case 31: MOVE_16_OBJECTS(in, out); MOVE_11_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; } /* This loop governs the asmptoptic behaviour of this algorithm, for long word copies. */ count = value >> 5; for (loop_var = 0; loop_var < count; loop_var++) MOVE_32_OBJECTS(in, out); } static inline void __no_builtin __byte_memcpy(void * __restrict s1, const void * __restrict s2, size_t n) { int value = n; int loop_var; const char *in = s2; char *out = s1; int count; int m0, m1, m2, m3; /* This code currently give a stall for any value with a 1->2 in the low 5 bits, i.e. 1,2, 33,34 ? not acceptable! */ switch (value & 0x1f) { case 0: break; case 1: MOVE_1_OBJECT(in, out); break; case 2: MOVE_2_OBJECTS(in, out); break; case 3: MOVE_3_OBJECTS(in, out); break; case 4: MOVE_4_OBJECTS(in, out); break; case 5: MOVE_5_OBJECTS(in, out); break; case 6: MOVE_6_OBJECTS(in, out); break; case 7: MOVE_7_OBJECTS(in, out); break; case 8: MOVE_8_OBJECTS(in, out); break; case 9: MOVE_9_OBJECTS(in, out); break; case 10: MOVE_10_OBJECTS(in, out); break; case 11: MOVE_11_OBJECTS(in, out); break; case 12: MOVE_12_OBJECTS(in, out); break; case 13: MOVE_9_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; case 14: MOVE_12_OBJECTS(in, out); MOVE_2_OBJECTS(in, out); break; case 15: MOVE_11_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; case 16: MOVE_16_OBJECTS(in, out); break; case 17: MOVE_11_OBJECTS(in, out); MOVE_6_OBJECTS(in, out); break; case 18: MOVE_9_OBJECTS(in, out); MOVE_9_OBJECTS(in, out); break; case 19: MOVE_16_OBJECTS(in, out); MOVE_3_OBJECTS(in, out); break; case 20: MOVE_16_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; case 21: MOVE_16_OBJECTS(in, out); MOVE_5_OBJECTS(in, out); break; case 22: MOVE_16_OBJECTS(in, out); MOVE_6_OBJECTS(in, out); break; case 23: MOVE_16_OBJECTS(in, out); MOVE_7_OBJECTS(in, out); break; case 24: MOVE_16_OBJECTS(in, out); MOVE_8_OBJECTS(in, out); break; case 25: MOVE_16_OBJECTS(in, out); MOVE_9_OBJECTS(in, out); break; case 26: MOVE_16_OBJECTS(in, out); MOVE_10_OBJECTS(in, out); break; case 27: MOVE_16_OBJECTS(in, out); MOVE_11_OBJECTS(in, out); break; case 28: MOVE_16_OBJECTS(in, out); MOVE_8_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; case 29: MOVE_16_OBJECTS(in, out); MOVE_9_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; case 30: MOVE_16_OBJECTS(in, out); MOVE_12_OBJECTS(in, out); MOVE_2_OBJECTS(in, out); break; case 31: MOVE_16_OBJECTS(in, out); MOVE_11_OBJECTS(in, out); MOVE_4_OBJECTS(in, out); break; } /* This loop governs the asmptoptic behaviour of this algorithm, for long word copies. */ count = value >> 5; for (loop_var = 0; loop_var < count; loop_var++) MOVE_32_OBJECTS(in, out); } /* Exposed interface. */ void * __no_builtin memcpy(void * __restrict s1, const void * __restrict s2, size_t n) { void *result = s1; /* None of the following handles copying zero bytes. */ if (n != 0) { unsigned test = (unsigned)s2 | (unsigned)s1 | (unsigned)n; if (test & 1) __byte_memcpy(s1, s2, n); else if (test & 2) __shrt_int_memcpy(s1, s2, n >> 1); else #ifdef __VISIUM_ARCH_BMI__ __asm__ __volatile__("bmd %0,%1,%2" : "+t"(s1), "+u"(s2), "+v"(n) : : "r4", "r5", "r6", "memory"); #else __int_memcpy(s1, s2, n >> 2); #endif /* __VISIUM_ARCH_BMI__ */ } return result; } picolibc-1.8.11/libc/machine/visium/memcpy.h000066400000000000000000000033241513574234600206760ustar00rootroot00000000000000/* memcpy for the Visium processor. Copyright (c) 2015 Rolls-Royce Controls and Data Services Limited. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Rolls-Royce Controls and Data Services Limited nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ void *memcpy(void * __restrict s1, const void * __restrict s2, size_t n); picolibc-1.8.11/libc/machine/visium/memmove.c000066400000000000000000000041171513574234600210450ustar00rootroot00000000000000/* memmove for the Visium processor. Copyright (c) 2015 Rolls-Royce Controls and Data Services Limited. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Rolls-Royce Controls and Data Services Limited nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include void * memmove(void *dst, const void *src, size_t len) { char *d = dst; const char *s = src; /* The overlap case is allegedly rare - with this implementation it will have a high penalty on the GR6. */ if (s < d && d < s + len) { s += len; d += len; while (len--) *--d = *--s; return dst; } return memcpy(dst, src, len); } picolibc-1.8.11/libc/machine/visium/memset.c000066400000000000000000000402431513574234600206720ustar00rootroot00000000000000/* memset for the Visium processor. Copyright (c) 2015 Rolls-Royce Controls and Data Services Limited. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Rolls-Royce Controls and Data Services Limited nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This file must be kept in sync with libgcc/config/visium/memset.c */ #include #include #include "memset.h" #include "../../string/local.h" #define SET_32_OBJECTS(out) \ do { \ out[0] = m0; \ out[1] = m0; \ out[2] = m0; \ out[3] = m0; \ out[4] = m0; \ out[5] = m0; \ out[6] = m0; \ out[7] = m0; \ out[8] = m0; \ out[9] = m0; \ out[10] = m0; \ out[11] = m0; \ out[12] = m0; \ out[13] = m0; \ out[14] = m0; \ out[15] = m0; \ out[16] = m0; \ out[17] = m0; \ out[18] = m0; \ out[19] = m0; \ out[20] = m0; \ out[21] = m0; \ out[22] = m0; \ out[23] = m0; \ out[24] = m0; \ out[25] = m0; \ out[26] = m0; \ out[27] = m0; \ out[28] = m0; \ out[29] = m0; \ out[30] = m0; \ out[31] = m0; \ out += 32; \ } while (0) #define SET_16_OBJECTS(out) \ do { \ out[0] = m0; \ out[1] = m0; \ out[2] = m0; \ out[3] = m0; \ out[4] = m0; \ out[5] = m0; \ out[6] = m0; \ out[7] = m0; \ out[8] = m0; \ out[9] = m0; \ out[10] = m0; \ out[11] = m0; \ out[12] = m0; \ out[13] = m0; \ out[14] = m0; \ out[15] = m0; \ out += 16; \ } while (0) #define SET_12_OBJECTS(out) \ do { \ out[0] = m0; \ out[1] = m0; \ out[2] = m0; \ out[3] = m0; \ out[4] = m0; \ out[5] = m0; \ out[6] = m0; \ out[7] = m0; \ out[8] = m0; \ out[9] = m0; \ out[10] = m0; \ out[11] = m0; \ out += 12; \ } while (0) #define SET_11_OBJECTS(out) \ do { \ out[0] = m0; \ out[1] = m0; \ out[2] = m0; \ out[3] = m0; \ out[4] = m0; \ out[5] = m0; \ out[6] = m0; \ out[7] = m0; \ out[8] = m0; \ out[9] = m0; \ out[10] = m0; \ out += 11; \ } while (0) #define SET_10_OBJECTS(out) \ do { \ out[0] = m0; \ out[1] = m0; \ out[2] = m0; \ out[3] = m0; \ out[4] = m0; \ out[5] = m0; \ out[6] = m0; \ out[7] = m0; \ out[8] = m0; \ out[9] = m0; \ out += 10; \ } while (0) #define SET_9_OBJECTS(out) \ do { \ out[0] = m0; \ out[1] = m0; \ out[2] = m0; \ out[3] = m0; \ out[4] = m0; \ out[5] = m0; \ out[6] = m0; \ out[7] = m0; \ out[8] = m0; \ out += 9; \ } while (0) #define SET_8_OBJECTS(out) \ do { \ out[0] = m0; \ out[1] = m0; \ out[2] = m0; \ out[3] = m0; \ out[4] = m0; \ out[5] = m0; \ out[6] = m0; \ out[7] = m0; \ out += 8; \ } while (0) #define SET_7_OBJECTS(out) \ do { \ out[0] = m0; \ out[1] = m0; \ out[2] = m0; \ out[3] = m0; \ out[4] = m0; \ out[5] = m0; \ out[6] = m0; \ out += 7; \ } while (0) #define SET_6_OBJECTS(out) \ do { \ out[0] = m0; \ out[1] = m0; \ out[2] = m0; \ out[3] = m0; \ out[4] = m0; \ out[5] = m0; \ out += 6; \ } while (0) #define SET_5_OBJECTS(out) \ do { \ out[0] = m0; \ out[1] = m0; \ out[2] = m0; \ out[3] = m0; \ out[4] = m0; \ out += 5; \ } while (0) #define SET_4_OBJECTS(out) \ do { \ out[0] = m0; \ out[1] = m0; \ out[2] = m0; \ out[3] = m0; \ out += 4; \ } while (0) #define SET_3_OBJECTS(out) \ do { \ out[0] = m0; \ out[1] = m0; \ out[2] = m0; \ out += 3; \ } while (0) #define SET_2_OBJECTS(out) \ do { \ out[0] = m0; \ out[1] = m0; \ out += 2; \ } while (0) #define SET_1_OBJECT(out) \ do { \ out[0] = m0; \ out += 1; \ } while (0) static inline void __no_builtin __int_memset(void * __restrict s1, int val, size_t n) { int value = n; int loop_var; int *out = s1; int count; int m0 = val; /* This code currently give a stall for any value with a 1->2 in the low 5 bits, i.e. 1,2, 33,34 ? not acceptable! */ switch (value & 0x1f) { case 0: break; case 1: SET_1_OBJECT(out); break; case 2: SET_2_OBJECTS(out); break; case 3: SET_3_OBJECTS(out); break; case 4: SET_4_OBJECTS(out); break; case 5: SET_5_OBJECTS(out); break; case 6: SET_6_OBJECTS(out); break; case 7: SET_7_OBJECTS(out); break; case 8: SET_8_OBJECTS(out); break; case 9: SET_9_OBJECTS(out); break; case 10: SET_10_OBJECTS(out); break; case 11: SET_11_OBJECTS(out); break; case 12: SET_12_OBJECTS(out); break; case 13: SET_9_OBJECTS(out); SET_4_OBJECTS(out); break; case 14: SET_12_OBJECTS(out); SET_2_OBJECTS(out); break; case 15: SET_11_OBJECTS(out); SET_4_OBJECTS(out); break; case 16: SET_16_OBJECTS(out); break; case 17: SET_11_OBJECTS(out); SET_6_OBJECTS(out); break; case 18: SET_9_OBJECTS(out); SET_9_OBJECTS(out); break; case 19: SET_16_OBJECTS(out); SET_3_OBJECTS(out); break; case 20: SET_16_OBJECTS(out); SET_4_OBJECTS(out); break; case 21: SET_16_OBJECTS(out); SET_5_OBJECTS(out); break; case 22: SET_16_OBJECTS(out); SET_6_OBJECTS(out); break; case 23: SET_16_OBJECTS(out); SET_7_OBJECTS(out); break; case 24: SET_16_OBJECTS(out); SET_8_OBJECTS(out); break; case 25: SET_16_OBJECTS(out); SET_9_OBJECTS(out); break; case 26: SET_16_OBJECTS(out); SET_10_OBJECTS(out); break; case 27: SET_16_OBJECTS(out); SET_11_OBJECTS(out); break; case 28: SET_16_OBJECTS(out); SET_8_OBJECTS(out); SET_4_OBJECTS(out); break; case 29: SET_16_OBJECTS(out); SET_9_OBJECTS(out); SET_4_OBJECTS(out); break; case 30: SET_16_OBJECTS(out); SET_12_OBJECTS(out); SET_2_OBJECTS(out); break; case 31: SET_16_OBJECTS(out); SET_11_OBJECTS(out); SET_4_OBJECTS(out); break; } /* This loop governs the asmptoptic behaviour of this algorithm, for long word copies. */ count = value >> 5; for (loop_var = 0; loop_var < count; loop_var++) SET_32_OBJECTS(out); } static inline void __no_builtin __short_int_memset(void * __restrict s1, int val, size_t n) { int value = n; int loop_var; int short *out = s1; int count; int m0 = val; /* This code currently give a stall for any value with a 1->2 in the low 5 bits, i.e. 1,2, 33,34 ? not acceptable! */ switch (value & 0x1f) { case 0: break; case 1: SET_1_OBJECT(out); break; case 2: SET_2_OBJECTS(out); break; case 3: SET_3_OBJECTS(out); break; case 4: SET_4_OBJECTS(out); break; case 5: SET_5_OBJECTS(out); break; case 6: SET_6_OBJECTS(out); break; case 7: SET_7_OBJECTS(out); break; case 8: SET_8_OBJECTS(out); break; case 9: SET_9_OBJECTS(out); break; case 10: SET_10_OBJECTS(out); break; case 11: SET_11_OBJECTS(out); break; case 12: SET_12_OBJECTS(out); break; case 13: SET_9_OBJECTS(out); SET_4_OBJECTS(out); break; case 14: SET_12_OBJECTS(out); SET_2_OBJECTS(out); break; case 15: SET_11_OBJECTS(out); SET_4_OBJECTS(out); break; case 16: SET_16_OBJECTS(out); break; case 17: SET_11_OBJECTS(out); SET_6_OBJECTS(out); break; case 18: SET_9_OBJECTS(out); SET_9_OBJECTS(out); break; case 19: SET_16_OBJECTS(out); SET_3_OBJECTS(out); break; case 20: SET_16_OBJECTS(out); SET_4_OBJECTS(out); break; case 21: SET_16_OBJECTS(out); SET_5_OBJECTS(out); break; case 22: SET_16_OBJECTS(out); SET_6_OBJECTS(out); break; case 23: SET_16_OBJECTS(out); SET_7_OBJECTS(out); break; case 24: SET_16_OBJECTS(out); SET_8_OBJECTS(out); break; case 25: SET_16_OBJECTS(out); SET_9_OBJECTS(out); break; case 26: SET_16_OBJECTS(out); SET_10_OBJECTS(out); break; case 27: SET_16_OBJECTS(out); SET_11_OBJECTS(out); break; case 28: SET_16_OBJECTS(out); SET_8_OBJECTS(out); SET_4_OBJECTS(out); break; case 29: SET_16_OBJECTS(out); SET_9_OBJECTS(out); SET_4_OBJECTS(out); break; case 30: SET_16_OBJECTS(out); SET_12_OBJECTS(out); SET_2_OBJECTS(out); break; case 31: SET_16_OBJECTS(out); SET_11_OBJECTS(out); SET_4_OBJECTS(out); break; } /* This loop governs the asmptoptic behaviour of this algorithm, for long word copies. */ count = value >> 5; for (loop_var = 0; loop_var < count; loop_var++) SET_32_OBJECTS(out); } static inline void __no_builtin __byte_memset(void * __restrict s1, int val, size_t n) { int value = n; int loop_var; char *out = s1; int count; int m0 = val; /* This code currently give a stall for any value with a 1->2 in the low 5 bits, i.e. 1,2, 33,34 ? not acceptable! */ switch (value & 0x1f) { case 0: break; case 1: SET_1_OBJECT(out); break; case 2: SET_2_OBJECTS(out); break; case 3: SET_3_OBJECTS(out); break; case 4: SET_4_OBJECTS(out); break; case 5: SET_5_OBJECTS(out); break; case 6: SET_6_OBJECTS(out); break; case 7: SET_7_OBJECTS(out); break; case 8: SET_8_OBJECTS(out); break; case 9: SET_9_OBJECTS(out); break; case 10: SET_10_OBJECTS(out); break; case 11: SET_11_OBJECTS(out); break; case 12: SET_12_OBJECTS(out); break; case 13: SET_9_OBJECTS(out); SET_4_OBJECTS(out); break; case 14: SET_12_OBJECTS(out); SET_2_OBJECTS(out); break; case 15: SET_11_OBJECTS(out); SET_4_OBJECTS(out); break; case 16: SET_16_OBJECTS(out); break; case 17: SET_11_OBJECTS(out); SET_6_OBJECTS(out); break; case 18: SET_9_OBJECTS(out); SET_9_OBJECTS(out); break; case 19: SET_16_OBJECTS(out); SET_3_OBJECTS(out); break; case 20: SET_16_OBJECTS(out); SET_4_OBJECTS(out); break; case 21: SET_16_OBJECTS(out); SET_5_OBJECTS(out); break; case 22: SET_16_OBJECTS(out); SET_6_OBJECTS(out); break; case 23: SET_16_OBJECTS(out); SET_7_OBJECTS(out); break; case 24: SET_16_OBJECTS(out); SET_8_OBJECTS(out); break; case 25: SET_16_OBJECTS(out); SET_9_OBJECTS(out); break; case 26: SET_16_OBJECTS(out); SET_10_OBJECTS(out); break; case 27: SET_16_OBJECTS(out); SET_11_OBJECTS(out); break; case 28: SET_16_OBJECTS(out); SET_8_OBJECTS(out); SET_4_OBJECTS(out); break; case 29: SET_16_OBJECTS(out); SET_9_OBJECTS(out); SET_4_OBJECTS(out); break; case 30: SET_16_OBJECTS(out); SET_12_OBJECTS(out); SET_2_OBJECTS(out); break; case 31: SET_16_OBJECTS(out); SET_11_OBJECTS(out); SET_4_OBJECTS(out); break; } /* This loop governs the asmptoptic behaviour of this algorithm, for long word copies. */ count = value >> 5; for (loop_var = 0; loop_var < count; loop_var++) SET_32_OBJECTS(out); } /* Exposed interface. */ void * __no_builtin memset(void *s, int c, size_t n) { void *result = s; /* None of the following handles setting zero bytes. */ if (n != 0) { unsigned test = (unsigned)s | (unsigned)n; if (test & 1) __byte_memset(s, c, n); else if (test & 2) { short int sc = (short int)((c << 8) + (char)c); __short_int_memset(s, sc, n >> 1); } else { int ic = (c << 24) + ((char)c << 16) + ((char)c << 8) + (char)c; __int_memset(s, ic, n >> 2); } } return result; } picolibc-1.8.11/libc/machine/visium/memset.h000066400000000000000000000032621513574234600206770ustar00rootroot00000000000000/* memset for the Visium processor. Copyright (c) 2015 Rolls-Royce Controls and Data Services Limited. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Rolls-Royce Controls and Data Services Limited nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ void *memset(void *s, int c, size_t n); picolibc-1.8.11/libc/machine/visium/setjmp.S000066400000000000000000000045011513574234600206570ustar00rootroot00000000000000/* setjmp/longjmp for the Visium processor. Copyright (c) 2015 Rolls-Royce Controls and Data Services Limited. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Rolls-Royce Controls and Data Services Limited nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include .text .globl setjmp .type setjmp, @function setjmp: write.l 0(r1),r11 write.l 1(r1),r12 write.l 2(r1),r13 write.l 3(r1),r14 write.l 4(r1),r15 write.l 5(r1),r16 write.l 6(r1),r17 write.l 7(r1),r18 write.l 8(r1),r19 write.l 9(r1),r21 write.l 10(r1),r22 write.l 11(r1),r23 bra tr,r21,r0 moviq r1,0 .size setjmp, .-setjmp .globl longjmp .type longjmp, @function longjmp: read.l r11,0(r1) read.l r12,1(r1) read.l r13,2(r1) read.l r14,3(r1) read.l r15,4(r1) read.l r16,5(r1) read.l r17,6(r1) read.l r18,7(r1) read.l r19,8(r1) read.l r21,9(r1) read.l r22,10(r1) read.l r23,11(r1) bra tr,r21,r0 move.l r1,r2 .size longjmp, .-longjmp picolibc-1.8.11/libc/machine/w65/000077500000000000000000000000001513574234600163365ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/w65/cmpsi.c000066400000000000000000000022771513574234600176250ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include union u { struct { short int msw; unsigned short lsw; } w; long l; }; int __cmpsi2(long arga, short int msw_b, unsigned short int lsw_b) { union u u; u.l = arga; if (u.w.msw != msw_b) { if (u.w.msw < msw_b) return 0; return 2; } if (u.w.lsw != lsw_b) { if (u.w.lsw < lsw_b) return 0; return 2; } return 1; } picolibc-1.8.11/libc/machine/w65/divsi3.c000066400000000000000000000060471513574234600177120ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include #define divnorm(num, den, sign) \ { \ if (num < 0) { \ num = -num; \ sign = 1; \ } else { \ sign = 0; \ } \ \ if (den < 0) { \ den = -den; \ sign = 1 - sign; \ } \ } static unsigned long divmodsi4(int modwanted, unsigned long num, unsigned long den) { long int bit = 1; long int res = 0; long prevden; while (den < num && bit && !(den & (1L << 31))) { den <<= 1; bit <<= 1; } while (bit) { if (num >= den) { num -= den; res |= bit; } bit >>= 1; den >>= 1; } if (modwanted) return num; return res; } #define exitdiv(sign, res) \ if (sign) { \ res = -res; \ } \ return res; long __modsi3(long numerator, long denominator) { int sign = 0; long dividend; long modul; if (numerator < 0) { numerator = -numerator; sign = 1; } if (denominator < 0) { denominator = -denominator; } modul = divmodsi4(1, numerator, denominator); if (sign) return -modul; return modul; } long __divsi3(long numerator, long denominator) { int sign; long dividend; long modul; divnorm(numerator, denominator, sign); dividend = divmodsi4(0, numerator, denominator); exitdiv(sign, dividend); } long __umodsi3(unsigned long numerator, unsigned long denominator) { long dividend; long modul; modul = divmodsi4(1, numerator, denominator); return modul; } long __udivsi3(unsigned long numerator, unsigned long denominator) { int sign; long dividend; long modul; dividend = divmodsi4(0, numerator, denominator); return dividend; } #include #ifdef TEST main() { long int i, j, k, m; for (i = -10000; i < 10000; i += 8) { for (j = -10000; j < 10000; j += 11) { k = i / j; m = __divsi3(i, j); if (k != m) printf("fail %d %d %d %d\n", i, j, k, m); } } } #endif picolibc-1.8.11/libc/machine/w65/lshrhi.S000066400000000000000000000025501513574234600177550ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .global ___lshrhi15 ___lshrhi15: lsr a .global ___lshrhi14 ___lshrhi14: lsr a .global ___lshrhi13 ___lshrhi13: lsr a .global ___lshrhi12 ___lshrhi12: lsr a .global ___lshrhi11 ___lshrhi11: lsr a .global ___lshrhi10 ___lshrhi10: lsr a .global ___lshrhi9 ___lshrhi9: lsr a .global ___lshrhi8 ___lshrhi8: lsr a .global ___lshrhi7 ___lshrhi7: lsr a .global ___lshrhi6 ___lshrhi6: lsr a .global ___lshrhi5 ___lshrhi5: lsr a .global ___lshrhi4 ___lshrhi4: lsr a .global ___lshrhi3 ___lshrhi3: lsr a .global ___lshrhi2 ___lshrhi2: lsr a lsr a rtl picolibc-1.8.11/libc/machine/w65/mulsi3.c000066400000000000000000000017271513574234600177250ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include long __mulsi3(unsigned long a, unsigned long b) { long res = 0; while (a) { if (a & 1) { res += b; } b <<= 1; a >>= 1; } return res; } picolibc-1.8.11/libc/machine/w65/sdivhi3.S000066400000000000000000000021771513574234600200420ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .global ___sdivhi3 ___sdivhi3: lda udv ply beq Lend !if positive result eor #0xFFFF !negate result inc a Lend: sta .global ___smulhi3 ___smulhi3: lda #0 mult1: ldx .global ___udivhi3 ___udivhi3: stz .global ___umodhi3 ___umodhi3: jsr >___udivhi3 stx struct __attribute__((__packed__)) interrupt_gate { uint16_t offset_low; uint16_t segment; uint16_t flags; uint16_t offset_high; #ifdef __x86_64 uint32_t offset_top; uint32_t reserved; #endif }; struct __attribute__((__packed__)) idt { uint16_t limit; const struct interrupt_gate *base; #if defined(__x86_64) && defined(__ILP32__) uint32_t pad; #endif }; struct interrupt_frame; #define isr_decl(num, name) void x86_##name##_interrupt(struct interrupt_frame *frame); isr_decl(0, divide); isr_decl(2, nmi); isr_decl(3, breakpoint); isr_decl(6, invalid_opcode); isr_decl(11, segment_not_present); isr_decl(12, stack_segment_fault); isr_decl(13, general_protection_fault); isr_decl(14, page_fault); isr_decl(18, machine_check); #define GATE_TYPE_TASK 5 #define GATE_TYPE_ISR_286 6 #define GATE_TYPE_TRAP_286 7 #define GATE_TYPE_ISR_386 14 #define GATE_TYPE_TRAP_386 15 #define GATE_SEGMENT_PRESENT (1 << 15) #define GATE_DPL(l) ((l) << 13) #define GATE_TYPE(t) ((t) << 8) #define GATE_OFFSET_LOW(p) (( #define GATE_FLAGS(t) (GATE_SEGMENT_PRESENT | GATE_DPL(3) | GATE_TYPE(t)) #define GATE_ISR(n) ((uintptr_t)x86_##n##_interrupt) #define GATE_TRAP(n) ((uintptr_t)x86_##n##_interrupt) #define isr(number, name) [number] = GATE_ISR(name) #define esr(number, name) [number] = GATE_TRAP(name) /* * We can't construct the interrupt vector at compile time * because the linker can't perform the necessary relocations. * Kludge around this by building a constructor to initialize * them at runtime. */ static struct interrupt_gate interrupt_vector[256]; const uintptr_t __weak_interrupt_table[256] = { esr(0, divide), esr(2, nmi), esr(3, breakpoint), esr(6, invalid_opcode), esr(11, segment_not_present), esr(12, stack_segment_fault), esr(13, general_protection_fault), esr(14, page_fault), esr(18, machine_check), }; __weak_reference(__weak_interrupt_table, __interrupt_table); static void __attribute__((constructor)) init_interrupt_vector(void) { unsigned i; for (i = 0; i < 256; i++) { uintptr_t ptr = __interrupt_table[i]; interrupt_vector[i].offset_low = (uint16_t)ptr; interrupt_vector[i].segment = 0x10; if (i < 32) interrupt_vector[i].flags = GATE_FLAGS(GATE_TYPE_TRAP_386); else interrupt_vector[i].flags = GATE_FLAGS(GATE_TYPE_ISR_386); interrupt_vector[i].offset_high = (uint16_t)(ptr >> 16); #ifdef __x86_64 interrupt_vector[i].offset_top = (uint32_t)((uint64_t)ptr >> 32); #endif } } /* Interrupt descriptor table value for lidt */ struct idt __weak_idt = { .limit = sizeof(interrupt_vector) - 1, .base = interrupt_vector }; __weak_reference(__weak_idt, __idt); picolibc-1.8.11/libc/machine/x86/machine/000077500000000000000000000000001513574234600177465ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/x86/machine/CMakeLists.txt000066400000000000000000000031371513574234600225120ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_headers(machine fenv.h fastmath.h ) picolibc-1.8.11/libc/machine/x86/machine/_ssp_tls.h000066400000000000000000000035431513574234600217520ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 TK Chia * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MACHINE__SSP_TLS_H_ #define _MACHINE__SSP_TLS_H_ #include #ifndef __THREAD_LOCAL_STORAGE_STACK_GUARD #error #endif #include "machine/_tls.h" extern _Thread_local __tcb_head_t __x86_tls_tcb; #define __stack_chk_guard (__x86_tls_tcb.__stack_guard) #endif picolibc-1.8.11/libc/machine/x86/machine/_tls.h000066400000000000000000000046041513574234600210640ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 TK Chia * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MACHINE__TLS_H_ #define _MACHINE__TLS_H_ #include #include #if !defined(__i386__) && !defined(__x86_64) #error #endif typedef struct { /* Self-pointer per ABI (https://akkadia.org/drepper/tls.pdf). */ void *__tcb; #ifdef __THREAD_LOCAL_STORAGE_STACK_GUARD /* * If we are configured to use a TLS stack protection canary, then * GCC expects the canary to be located at the same offset into the * TCB as implemented in GNU libc's Native POSIX Thread Library * (NPTL) component. So declare some additional NPTL-compatible TCB * fields here. */ void *__dtv; void *__self; int32_t __multiple_threads; #ifdef __x86_64 int32_t __gscope_flag; #endif uintptr_t __sysinfo; uintptr_t __stack_guard; #endif } __tcb_head_t; #endif picolibc-1.8.11/libc/machine/x86/machine/fastmath.h000066400000000000000000000103371513574234600217320ustar00rootroot00000000000000/* Copyright (c) 2007 Jeff Johnston */ #ifndef _MACHFASTMATH_H #define _MACHFASTMATH_H #ifndef __x86_64 #if defined(__GNUC__) && __STDC__ - 0 > 0 #define __str1__(__x) #__x #define __str2__(__x) __str1__(__x) #define __U_L_PREFIX__ __str2__(__USER_LABEL_PREFIX__) __extension__ double atan2(double, double) __asm__(__U_L_PREFIX__ "_f_atan2"); __extension__ double exp(double) __asm__(__U_L_PREFIX__ "_f_exp"); __extension__ double frexp(double, int *) __asm__(__U_L_PREFIX__ "_f_frexp"); __extension__ double ldexp(double, int) __asm__(__U_L_PREFIX__ "_f_ldexp"); __extension__ double log(double) __asm__(__U_L_PREFIX__ "_f_log"); __extension__ double log10(double) __asm__(__U_L_PREFIX__ "_f_log10"); __extension__ double pow(double, double) __asm__(__U_L_PREFIX__ "_f_pow"); __extension__ double tan(double) __asm__(__U_L_PREFIX__ "_f_tan"); #if !defined(__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L __extension__ float atan2f(float, float) __asm__(__U_L_PREFIX__ "_f_atan2f"); __extension__ float expf(float) __asm__(__U_L_PREFIX__ "_f_expf"); __extension__ float frexpf(float, int *) __asm__(__U_L_PREFIX__ "_f_frexpf"); __extension__ float ldexpf(float, int) __asm__(__U_L_PREFIX__ "_f_ldexpf"); __extension__ long long llrint(double) __asm__(__U_L_PREFIX__ "_f_llrint"); __extension__ long long llrintf(float) __asm__(__U_L_PREFIX__ "_f_llrintf"); __extension__ long long llrintl(long double) __asm__(__U_L_PREFIX__ "_f_llrintl"); __extension__ float logf(float) __asm__(__U_L_PREFIX__ "_f_logf"); __extension__ float log10f(float) __asm__(__U_L_PREFIX__ "_f_log10f"); __extension__ long lrint(double) __asm__(__U_L_PREFIX__ "_f_lrint"); __extension__ long lrintf(float) __asm__(__U_L_PREFIX__ "_f_lrintf"); __extension__ long lrintl(long double) __asm__(__U_L_PREFIX__ "_f_lrintl"); __extension__ float powf(float, float) __asm__(__U_L_PREFIX__ "_f_powf"); __extension__ double rint(double) __asm__(__U_L_PREFIX__ "_f_rint"); __extension__ float rintf(float) __asm__(__U_L_PREFIX__ "_f_rintf"); __extension__ long double rintl(long double) __asm__(__U_L_PREFIX__ "_f_rintl"); __extension__ float tanf(float) __asm__(__U_L_PREFIX__ "_f_tanf"); #endif #else double EXFUN(_f_atan2, (double, double)); double EXFUN(_f_exp, (double)); double EXFUN(_f_frexp, (double, int *)); double EXFUN(_f_ldexp, (double, int)); double EXFUN(_f_log, (double)); double EXFUN(_f_log10, (double)); double EXFUN(_f_pow, (double, double)); #define atan2(__y, __x) _f_atan2((__y), (__x)) #define exp(__x) _f_exp(__x) #define frexp(__x, __p) _f_frexp((__x), (__p)) #define ldexp(__x, __e) _f_ldexp((__x), (__e)) #define log(__x) _f_log(__x) #define log10(__x) _f_log10(__x) #define pow(__x, __y) _f_pow((__x), (__y)) #ifndef __STRICT_ANSI__ float EXFUN(_f_atan2f, (float, float)); float EXFUN(_f_expf, (float)); float EXFUN(_f_frexpf, (float, int *)); float EXFUN(_f_ldexpf, (float, int)); long long EXFUN(_f_llrint, (double)); long long EXFUN(_f_llrintf, (float)); long long EXFUN(_f_llrintl, (long double)); float EXFUN(_f_logf, (float)); float EXFUN(_f_log10f, (float)); long EXFUN(_f_lrint, (double)); long EXFUN(_f_lrintf, (float)); long EXFUN(_f_lrintl, (long double)); float EXFUN(_f_powf, (float, float)); float EXFUN(_f_rint, (double)); double EXFUN(_f_rintf, (float)); long double EXFUN(_f_rintl, (long double)); #define atan2f(__y, __x) _f_atan2f((__y), (__x)) #define expf(__x) _f_expf(__x) #define frexpf(__x, __p) _f_frexpf((__x), (__p)) #define ldexpf(__x, __e) _f_ldexpf((__x), (__e)) #define llrint(__x) _f_llrint((__x)) #define llrintf(__x) _f_llrintf((__x)) #define llrintl(__x) _f_llrintl((__x)) #define logf(__x) _f_logf(__x) #define log10f(__x) _f_log10f(__x) #define lrint(__x) _f_lrint((__x)) #define lrintf(__x) _f_lrintf((__x)) #define lrintl(__x) _f_lrintl((__x)) #define powf(__x, y) _f_powf((__x), (__y)) #define rint(__x) _f_rint((__x)) #define rintf(__x) _f_rintf((__x)) #define rintl(__x) _f_rintl((__x)) #endif #endif /* GCC */ #endif /* !__x86_64 */ #endif /* _MACHFASTMATH_H */ picolibc-1.8.11/libc/machine/x86/machine/fenv.h000066400000000000000000000145371513574234600210670ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2010-2019 Red Hat, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * 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. */ #ifndef _MACHINE_FENV_H #define _MACHINE_FENV_H 1 #include _BEGIN_STD_C #ifdef _SOFT_FLOAT typedef int fenv_t; typedef int fexcept_t; #define FE_TONEAREST (0) #else /* Primary sources: The Open Group Base Specifications Issue 6: http://www.opengroup.org/onlinepubs/000095399/basedefs/fenv.h.html C99 Language spec (draft n1256): Intel(R) 64 and IA-32 Architectures Software Developer's Manuals: http://www.intel.com/products/processor/manuals/ GNU C library manual pages: http://www.gnu.org/software/libc/manual/html_node/Control-Functions.html http://www.gnu.org/software/libc/manual/html_node/Rounding.html http://www.gnu.org/software/libc/manual/html_node/FP-Exceptions.html http://www.gnu.org/software/libc/manual/html_node/Status-bit-operations.html Linux online man page(s): http://linux.die.net/man/3/fegetexcept The documentation quotes these sources for reference. All definitions and code have been developed solely based on the information from these specs. */ /* Represents the entire floating-point environment. The floating-point environment refers collectively to any floating-point status flags and control modes supported by the implementation. In this implementation, the struct contains the state information from the fstenv/fnstenv instructions and a copy of the SSE MXCSR, since GCC uses SSE for a lot of floating-point operations. (Cygwin assumes i686 or above these days, as does the compiler.) */ typedef struct _fenv_t { struct _fpu_env_info { unsigned int _fpu_cw; /* low 16 bits only. */ unsigned int _fpu_sw; /* low 16 bits only. */ unsigned int _fpu_tagw; /* low 16 bits only. */ unsigned int _fpu_ipoff; unsigned int _fpu_ipsel; unsigned int _fpu_opoff; unsigned int _fpu_opsel; /* low 16 bits only. */ } _fpu; unsigned int _sse_mxcsr; } fenv_t; /* Represents the floating-point status flags collectively, including any status the implementation associates with the flags. A floating-point status flag is a system variable whose value is set (but never cleared) when a floating-point exception is raised, which occurs as a side effect of exceptional floating-point arithmetic to provide auxiliary information. A floating-point control mode is a system variable whose value may be set by the user to affect the subsequent behavior of floating-point arithmetic. */ typedef __uint32_t fexcept_t; /* The header shall define the following constants if and only if the implementation supports the floating-point exception by means of the floating-point functions feclearexcept(), fegetexceptflag(), feraiseexcept(), fesetexceptflag(), and fetestexcept(). Each expands to an integer constant expression with values such that bitwise-inclusive ORs of all combinations of the constants result in distinct values. */ #define FE_DIVBYZERO (1 << 2) #define FE_INEXACT (1 << 5) #define FE_INVALID (1 << 0) #define FE_OVERFLOW (1 << 3) #define FE_UNDERFLOW (1 << 4) /* The header shall define the following constant, which is simply the bitwise-inclusive OR of all floating-point exception constants defined above: */ /* in agreement w/ Linux the subnormal exception will always be masked */ #define FE_ALL_EXCEPT (FE_INEXACT | FE_UNDERFLOW | FE_OVERFLOW | FE_DIVBYZERO | FE_INVALID) /* The header shall define the following constants if and only if the implementation supports getting and setting the represented rounding direction by means of the fegetround() and fesetround() functions. Each expands to an integer constant expression whose values are distinct non-negative vales. */ #define FE_DOWNWARD (1) #define FE_TONEAREST (0) #define FE_TOWARDZERO (3) #define FE_UPWARD (2) /* Only Solaris and QNX implement fegetprec/fesetprec. As Solaris, use the values defined by http://www.open-std.org/jtc1/sc22//WG14/www/docs/n752.htm QNX defines different values. */ #if __MISC_VISIBLE #define FE_FLTPREC (0) #define FE_DBLPREC (2) #define FE_LDBLPREC (3) #endif /* Additional implementation-defined environments, with macro definitions beginning with FE_ and an uppercase letter,and having type "pointer to const-qualified fenv_t",may also be specified by the implementation. */ #if __GNU_VISIBLE /* If possible, the GNU C Library defines a macro FE_NOMASK_ENV which represents an environment where every exception raised causes a trap to occur. You can test for this macro using #ifdef. It is only defined if _GNU_SOURCE is defined. */ extern const fenv_t * const _fe_nomask_env; #define FE_NOMASK_ENV (_fe_nomask_env) #endif #endif /* !_SOFT_FLOAT */ #ifdef _SOFT_FLOAT #if !defined(__declare_fenv_inline) && defined(__declare_extern_inline) #define __declare_fenv_inline(type) __declare_extern_inline(type) #endif #ifdef __declare_fenv_inline #include #endif #endif _END_STD_C #endif /* _FENV_H */ picolibc-1.8.11/libc/machine/x86/machine/meson.build000066400000000000000000000033531513574234600221140ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2020 Keith Packard, # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_machine_headers_machine = [ 'fenv.h', 'fastmath.h' ] if really_install install_headers(inc_machine_headers_machine, install_dir: include_dir / 'machine') endif picolibc-1.8.11/libc/machine/x86/memchr-32.S000066400000000000000000000034231513574234600201650ustar00rootroot00000000000000/* * ==================================================== * Copyright (C) 1998, 2002, 2008 by Red Hat Inc. All rights reserved. * * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== */ #include #include "i386mach.h" .global SYM (memchr) SOTYPE_FUNCTION(memchr) SYM (memchr): #ifdef __iamcu__ pushl edi movl eax,edi movl edx,eax xorl edx,edx testl ecx,ecx jz L20 repnz scasb setnz dl decl edi decl edx andl edi,edx L20: movl edx,eax popl edi #else pushl ebp movl esp,ebp pushl edi movzbl 12(ebp),eax movl 16(ebp),ecx movl 8(ebp),edi xorl edx,edx testl ecx,ecx jz L20 #ifdef __OPTIMIZE_SIZE__ cld repnz scasb setnz dl decl edi #else /* !__OPTIMIZE_SIZE__ */ /* Do byte-wise checks until string is aligned. */ testl $3,edi je L5 cmpb (edi),al je L15 incl edi decl ecx je L20 testl $3,edi je L5 cmpb (edi),al je L15 incl edi decl ecx je L20 testl $3,edi je L5 cmpb (edi),al je L15 incl edi decl ecx je L20 /* Create a mask, then check a word at a time. */ L5: movb al,ah movl eax,edx sall $16,edx orl edx,eax pushl ebx .p2align 4,,7 L8: subl $4,ecx jc L9 movl (edi),edx addl $4,edi xorl eax,edx leal -16843009(edx),ebx notl edx andl edx,ebx testl $-2139062144,ebx je L8 subl $4,edi L9: popl ebx xorl edx,edx addl $4,ecx je L20 /* Final byte-wise checks. */ .p2align 4,,7 L10: cmpb (edi),al je L15 incl edi decl ecx jne L10 xorl edi,edi #endif /* !__OPTIMIZE_SIZE__ */ L15: decl edx andl edi,edx L20: movl edx,eax leal -4(ebp),esp popl edi leave #endif ret #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/x86/memchr.S000066400000000000000000000001061513574234600177360ustar00rootroot00000000000000#include #ifndef __x86_64 #include "memchr-32.S" #endif picolibc-1.8.11/libc/machine/x86/memchr.c000066400000000000000000000001171513574234600177600ustar00rootroot00000000000000#include #ifdef __x86_64 #include "../../string/memchr.c" #endif picolibc-1.8.11/libc/machine/x86/memcmp-32.S000066400000000000000000000035171513574234600201740ustar00rootroot00000000000000/* * ==================================================== * Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved. * * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== */ #include #include "i386mach.h" .global SYM (memcmp) SOTYPE_FUNCTION(memcmp) SYM (memcmp): #ifdef __iamcu__ pushl edi pushl esi movl eax,edi movl edx,esi cld /* check if length is zero in which case just return 0 */ xorl eax,eax testl ecx,ecx jz L4 /* compare any unaligned bytes or remainder bytes */ repz cmpsb /* set output to be < 0 if less than, 0 if equal, or > 0 if greater than */ xorl edx,edx movb -1(esi),dl movb -1(edi),al subl edx,eax L4: popl esi popl edi #else pushl ebp movl esp,ebp subl $16,esp pushl ebx pushl edi pushl esi movl 8(ebp),edi movl 12(ebp),esi movl 16(ebp),ecx cld /* check if length is zero in which case just return 0 */ xorl eax,eax testl ecx,ecx jz L4 #ifndef __OPTIMIZE_SIZE__ /* if aligned on long boundary, compare doublewords at a time first */ movl edi,eax orl esi,eax testb $3,al jne BYTECMP movl ecx,ebx shrl $2,ecx /* calculate number of long words to compare */ repz cmpsl jz L5 subl $4,esi subl $4,edi movl $4,ecx jmp BYTECMP L5: andl $3,ebx /* calculate number of remaining bytes */ movl ebx,ecx #endif /* not __OPTIMIZE_SIZE__ */ BYTECMP: /* compare any unaligned bytes or remainder bytes */ repz cmpsb /* set output to be < 0 if less than, 0 if equal, or > 0 if greater than */ L3: xorl edx,edx movb -1(esi),dl xorl eax,eax movb -1(edi),al subl edx,eax L4: leal -28(ebp),esp popl esi popl edi popl ebx leave #endif ret #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/x86/memcmp.S000066400000000000000000000001061513574234600177410ustar00rootroot00000000000000#include #ifndef __x86_64 #include "memcmp-32.S" #endif picolibc-1.8.11/libc/machine/x86/memcmp.c000066400000000000000000000001171513574234600177630ustar00rootroot00000000000000#include #ifdef __x86_64 #include "../../string/memcmp.c" #endif picolibc-1.8.11/libc/machine/x86/memcpy-32.S000066400000000000000000000024401513574234600202020ustar00rootroot00000000000000/* * ==================================================== * Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved. * * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== */ #include #include "i386mach.h" .global SYM (memcpy) SOTYPE_FUNCTION(memcpy) SYM (memcpy): #ifdef __iamcu__ pushl esi pushl edi movl eax,edi movl edx,esi rep movsb popl edi popl esi #else pushl ebp movl esp,ebp pushl esi pushl edi pushl ebx movl 8(ebp),edi movl 16(ebp),ecx movl 12(ebp),esi cld #ifndef __OPTIMIZE_SIZE__ cmpl $8,ecx jbe .L3 /* move any preceding bytes until destination address is long word aligned */ movl edi,edx movl ecx,ebx andl $3,edx jz .L11 movl $4,ecx subl edx,ecx andl $3,ecx subl ecx,ebx rep movsb mov ebx,ecx /* move bytes a long word at a time */ .L11: shrl $2,ecx .p2align 2 rep movsl movl ebx,ecx andl $3,ecx #endif /* !__OPTIMIZE_SIZE__ */ /* handle any remaining bytes */ .L3: rep movsb .L5: movl 8(ebp),eax leal -12(ebp),esp popl ebx popl edi popl esi leave #endif ret #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/x86/memcpy-64.S000066400000000000000000000044771513574234600202230ustar00rootroot00000000000000/* * ==================================================== * Copyright (C) 2007 by Ellips BV. All rights reserved. * * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== */ #include #include "x86_64mach.h" .global SYM (memcpy) SOTYPE_FUNCTION(memcpy) SYM (memcpy): movq rdi, rax /* Store destination in return value */ cmpq $16, rdx jb byte_copy movq rdi, r8 /* Align destination on quad word boundary */ andq $7, r8 jz quadword_aligned movq $8, rcx subq r8, rcx subq rcx, rdx rep movsb quadword_aligned: cmpq $256, rdx jb quadword_copy pushq rax pushq r12 pushq r13 pushq r14 movq rdx, rcx /* Copy 128 bytes at a time with minimum cache polution */ shrq $7, rcx .p2align 4 loop: prefetchnta 768 (rsi) prefetchnta 832 (rsi) movq (rsi), rax movq 8 (rsi), r8 movq 16 (rsi), r9 movq 24 (rsi), r10 movq 32 (rsi), r11 movq 40 (rsi), r12 movq 48 (rsi), r13 movq 56 (rsi), r14 movntiq rax, (rdi) movntiq r8 , 8 (rdi) movntiq r9 , 16 (rdi) movntiq r10, 24 (rdi) movntiq r11, 32 (rdi) movntiq r12, 40 (rdi) movntiq r13, 48 (rdi) movntiq r14, 56 (rdi) movq 64 (rsi), rax movq 72 (rsi), r8 movq 80 (rsi), r9 movq 88 (rsi), r10 movq 96 (rsi), r11 movq 104 (rsi), r12 movq 112 (rsi), r13 movq 120 (rsi), r14 movntiq rax, 64 (rdi) movntiq r8 , 72 (rdi) movntiq r9 , 80 (rdi) movntiq r10, 88 (rdi) movntiq r11, 96 (rdi) movntiq r12, 104 (rdi) movntiq r13, 112 (rdi) movntiq r14, 120 (rdi) leaq 128 (rsi), rsi leaq 128 (rdi), rdi dec rcx jnz loop sfence movq rdx, rcx andq $127, rcx rep movsb popq r14 popq r13 popq r12 popq rax ret byte_copy: movq rdx, rcx rep movsb ret quadword_copy: movq rdx, rcx shrq $3, rcx .p2align 4 rep movsq movq rdx, rcx andq $7, rcx rep movsb /* Copy the remaining bytes */ ret #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/x86/memcpy.S000066400000000000000000000001421513574234600177550ustar00rootroot00000000000000#include #ifdef __x86_64 #include "memcpy-64.S" #else #include "memcpy-32.S" #endif picolibc-1.8.11/libc/machine/x86/memmove-32.S000066400000000000000000000045761513574234600203710ustar00rootroot00000000000000/* * ==================================================== * Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved. * * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== */ #include #include "i386mach.h" .global SYM (memmove) SOTYPE_FUNCTION(memmove) SYM (memmove): #ifdef __iamcu__ pushl esi pushl edi movl eax,edi movl edx,esi cmp esi,edi ja .Lcopy_backward je .Lbwd_write_0bytes rep movsb popl edi popl esi ret .Lcopy_backward: lea -1(edi,ecx),edi lea -1(esi,ecx),esi std rep movsb cld .Lbwd_write_0bytes: popl edi popl esi #else pushl ebp movl esp,ebp pushl esi pushl edi pushl ebx movl 8(ebp),edi movl 16(ebp),ecx movl 12(ebp),esi /* check for destructive overlap (src < dst && dst < src + length) */ cld cmpl edi,esi jae .L2 leal -1(ecx,esi),ebx cmpl ebx,edi ja .L2 /* IF: destructive overlap, must copy backwards */ addl ecx,esi addl ecx,edi std #ifndef __OPTIMIZE_SIZE__ cmpl $8,ecx jbe .L13 .L18: /* move trailing bytes in reverse until destination address is long word aligned */ movl edi,edx movl ecx,ebx andl $3,edx jz .L21 movl edx,ecx decl esi decl edi subl ecx,ebx rep movsb mov ebx,ecx incl esi incl edi .L21: /* move bytes in reverse, a long word at a time */ shrl $2,ecx subl $4,esi subl $4,edi rep movsl addl $4,esi addl $4,edi movl ebx,ecx andl $3,ecx #endif /* !__OPTIMIZE_SIZE__ */ /* handle any remaining bytes not on a long word boundary */ .L13: decl esi decl edi .L15: rep movsb jmp .L5 .p2align 4,,7 /* ELSE: no destructive overlap so we copy forwards */ .L2: #ifndef __OPTIMIZE_SIZE__ cmpl $8,ecx jbe .L3 /* move any preceding bytes until destination address is long word aligned */ movl edi,edx movl ecx,ebx andl $3,edx jz .L11 movl $4,ecx subl edx,ecx andl $3,ecx subl ecx,ebx rep movsb mov ebx,ecx /* move bytes a long word at a time */ .L11: shrl $2,ecx .p2align 2 rep movsl movl ebx,ecx andl $3,ecx #endif /* !__OPTIMIZE_SIZE__ */ /* handle any remaining bytes */ .L3: rep movsb .L5: movl 8(ebp),eax cld leal -12(ebp),esp popl ebx popl edi popl esi leave #endif ret #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/x86/memmove.S000066400000000000000000000001071513574234600201310ustar00rootroot00000000000000#include #ifndef __x86_64 #include "memmove-32.S" #endif picolibc-1.8.11/libc/machine/x86/memmove.c000066400000000000000000000001201513574234600201440ustar00rootroot00000000000000#include #ifdef __x86_64 #include "../../string/memmove.c" #endif picolibc-1.8.11/libc/machine/x86/memset-32.S000066400000000000000000000031741513574234600202070ustar00rootroot00000000000000/* * ==================================================== * Copyright (C) 1998, 2002, 2008 by Red Hat Inc. All rights reserved. * * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== */ #include #include "i386mach.h" .global SYM (memset) SOTYPE_FUNCTION(memset) SYM (memset): #ifdef __iamcu__ pushl edi movl eax,edi movzbl dl,eax mov edi,edx rep stosb mov edx,eax popl edi #else pushl ebp movl esp,ebp pushl edi movl 8(ebp),edi movzbl 12(ebp),eax movl 16(ebp),ecx cld #ifndef __OPTIMIZE_SIZE__ /* Less than 16 bytes won't benefit from the 'rep stosl' loop. */ cmpl $16,ecx jbe .L19 testl $7,edi je .L10 /* It turns out that 8-byte aligned 'rep stosl' outperforms 4-byte aligned on some x86 platforms. */ movb al,(edi) incl edi decl ecx testl $7,edi je .L10 movb al,(edi) incl edi decl ecx testl $7,edi je .L10 movb al,(edi) incl edi decl ecx testl $7,edi je .L10 movb al,(edi) incl edi decl ecx testl $7,edi je .L10 movb al,(edi) incl edi decl ecx testl $7,edi je .L10 movb al,(edi) incl edi decl ecx testl $7,edi je .L10 movb al,(edi) incl edi decl ecx /* At this point, ecx>8 and edi%8==0. */ .L10: movb al,ah movl eax,edx sall $16,edx orl edx,eax movl ecx,edx shrl $2,ecx andl $3,edx rep stosl movl edx,ecx #endif /* not __OPTIMIZE_SIZE__ */ .L19: rep stosb movl 8(ebp),eax leal -4(ebp),esp popl edi leave #endif ret #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/x86/memset-64.S000066400000000000000000000036271513574234600202170ustar00rootroot00000000000000/* * ==================================================== * Copyright (C) 2007 by Ellips BV. All rights reserved. * * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== */ #include #ifndef __x86_64 #include "../i386/memset.S" #else #include "x86_64mach.h" .global SYM (memset) SOTYPE_FUNCTION(memset) SYM (memset): movq rdi, r9 /* Save return value */ movq rsi, rax movq rdx, rcx cmpq $16, rdx jb byte_set movq rdi, r8 /* Align on quad word boundary */ andq $7, r8 jz quadword_aligned movq $8, rcx subq r8, rcx subq rcx, rdx rep stosb movq rdx, rcx quadword_aligned: movabs $0x0101010101010101, r8 movzbl sil, eax imul r8, rax cmpq $256, rdx jb quadword_set shrq $7, rcx /* Store 128 bytes at a time with minimum cache polution */ .p2align 4 loop: movntiq rax, (rdi) movntiq rax, 8 (rdi) movntiq rax, 16 (rdi) movntiq rax, 24 (rdi) movntiq rax, 32 (rdi) movntiq rax, 40 (rdi) movntiq rax, 48 (rdi) movntiq rax, 56 (rdi) movntiq rax, 64 (rdi) movntiq rax, 72 (rdi) movntiq rax, 80 (rdi) movntiq rax, 88 (rdi) movntiq rax, 96 (rdi) movntiq rax, 104 (rdi) movntiq rax, 112 (rdi) movntiq rax, 120 (rdi) leaq 128 (rdi), rdi dec rcx jnz loop sfence movq rdx, rcx andq $127, rcx rep stosb movq r9, rax ret byte_set: rep stosb movq r9, rax ret quadword_set: shrq $3, rcx .p2align 4 rep stosq movq rdx, rcx andq $7, rcx rep stosb /* Store the remaining bytes */ movq r9, rax ret #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif #endif picolibc-1.8.11/libc/machine/x86/memset.S000066400000000000000000000001421513574234600177550ustar00rootroot00000000000000#include #ifdef __x86_64 #include "memset-64.S" #else #include "memset-32.S" #endif picolibc-1.8.11/libc/machine/x86/meson.build000066400000000000000000000042711513574234600205100ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'interrupt.c', 'interrupt.S', 'memcpy.S', 'memset.S', 'setjmp.S', 'memchr.c', 'memcmp.c', 'memmove.c', 'strchr.c', 'strlen.c', 'memchr.S', 'memcmp.S', 'memmove.S', 'strchr.S', 'strlen.S', 'tcb.S', 'tls.c', ] subdir('machine') subdir('sys') foreach params : targets target = params['name'] target_dir = params['dir'] target_c_args = params['c_args'] set_variable('lib_machine' + target, static_library('machine' + target, srcs_machine, pic: false, include_directories: inc, c_args: target_c_args + c_args + arg_fnobuiltin + arg_fnolto)) endforeach picolibc-1.8.11/libc/machine/x86/setjmp-32.S000066400000000000000000000046371513574234600202240ustar00rootroot00000000000000/* This is file is a merger of SETJMP.S and LONGJMP.S */ /* * This file was modified to use the __USER_LABEL_PREFIX__ and * __REGISTER_PREFIX__ macros defined by later versions of GNU cpp by * Joel Sherrill (joel@OARcorp.com) * Slight change: now includes i386mach.h for this (Werner Almesberger) * * Copyright (C) 1991 DJ Delorie * All rights reserved. * * Redistribution, modification, and use in source and binary forms is permitted * provided that the above copyright notice and following paragraph are * duplicated in all such forms. * * This file is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /* ** jmp_buf: ** eax ebx ecx edx esi edi ebp esp eip ** 0 4 8 12 16 20 24 28 32 ** ** Intel MCU jmp_buf: ** ebx esi edi ebp esp eip ** 0 4 8 12 16 20 */ #include #include "i386mach.h" .global SYM (setjmp) .global SYM (longjmp) SOTYPE_FUNCTION(setjmp) SOTYPE_FUNCTION(longjmp) SYM (setjmp): #ifdef __iamcu__ /* Store EIP. */ movl 0(esp),ecx movl ecx,20(eax) movl ebx,0 (eax) movl esi,4 (eax) movl edi,8 (eax) movl ebp,12(eax) /* Skip return address, which will be pushed onto stack in longjmp, and store SP. */ leal 4(esp),ecx movl ecx,16(eax) xorl eax,eax #else pushl ebp movl esp,ebp pushl edi movl 8 (ebp),edi movl eax,0 (edi) movl ebx,4 (edi) movl ecx,8 (edi) movl edx,12 (edi) movl esi,16 (edi) movl -4 (ebp),eax movl eax,20 (edi) movl 0 (ebp),eax movl eax,24 (edi) movl esp,eax addl $12,eax movl eax,28 (edi) movl 4 (ebp),eax movl eax,32 (edi) popl edi movl $0,eax leave #endif ret SYM (longjmp): #ifdef __iamcu__ /* Check retval. */ testl edx,edx jne 0f incl edx 0: /* Restore stack first. */ movl 16(eax),esp /* Put return address on stack. */ pushl 20(eax) movl 0(eax),ebx movl 4(eax),esi movl 8(eax),edi movl 12(eax),ebp movl edx,eax #else pushl ebp movl esp,ebp movl 8(ebp),edi /* get jmp_buf */ movl 12(ebp),eax /* store retval in j->eax */ testl eax,eax jne 0f incl eax 0: movl eax,0(edi) movl 24(edi),ebp __CLI movl 28(edi),esp pushl 32(edi) movl 0(edi),eax movl 4(edi),ebx movl 8(edi),ecx movl 12(edi),edx movl 16(edi),esi movl 20(edi),edi __STI #endif ret #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/x86/setjmp-64.S000066400000000000000000000024641513574234600202250ustar00rootroot00000000000000/* * ==================================================== * Copyright (C) 2007 by Ellips BV. All rights reserved. * * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== */ #include #ifndef __x86_64 #include "../i386/setjmp.S" #else /* ** jmp_buf: ** rbx rbp r12 r13 r14 r15 rsp rip ** 0 8 16 24 32 40 48 56 */ #include "x86_64mach.h" .global SYM (setjmp) .global SYM (longjmp) SOTYPE_FUNCTION(setjmp) SOTYPE_FUNCTION(longjmp) SYM (setjmp): movq rbx, 0 (rdi) movq rbp, 8 (rdi) movq r12, 16 (rdi) movq r13, 24 (rdi) movq r14, 32 (rdi) movq r15, 40 (rdi) leaq 8 (rsp), rax movq rax, 48 (rdi) movq (rsp), rax movq rax, 56 (rdi) movq $0, rax ret SYM (longjmp): movq rsi, rax /* Return value */ /* turn 0 into 1 */ testq rsi, rsi movl $1, edx cmove rdx, rax movq 8 (rdi), rbp __CLI movq 48 (rdi), rsp pushq 56 (rdi) movq 0 (rdi), rbx movq 16 (rdi), r12 movq 24 (rdi), r13 movq 32 (rdi), r14 movq 40 (rdi), r15 __STI ret #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif #endif picolibc-1.8.11/libc/machine/x86/setjmp.S000066400000000000000000000001421513574234600177650ustar00rootroot00000000000000#include #ifdef __x86_64 #include "setjmp-64.S" #else #include "setjmp-32.S" #endif picolibc-1.8.11/libc/machine/x86/strchr-32.S000066400000000000000000000056011513574234600202170ustar00rootroot00000000000000/* * ==================================================== * Copyright (C) 1998, 2002, 2008 by Red Hat Inc. All rights reserved. * * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== */ #include #include "i386mach.h" .global SYM (strchr) SOTYPE_FUNCTION(strchr) SYM (strchr): #ifdef __iamcu__ xorl ecx,ecx movb dl,cl /* loop while (*s && *s++ != c) */ leal -1(eax),eax L15: incl eax movb (eax),dl testb dl,dl je L14 cmpb cl,dl jne L15 L14: /* if (*s == c) return address otherwise return NULL */ cmpb cl,(eax) je L19 xorl eax,eax L19: ret #else pushl ebp movl esp,ebp pushl edi pushl ebx xorl ebx,ebx movl 8(ebp),edi addb 12(ebp),bl #ifndef __OPTIMIZE_SIZE__ /* Special case strchr(p,0). */ je L25 /* Do byte-wise checks until string is aligned. */ test $3,edi je L5 movl edi,eax movb (eax),cl testb cl,cl je L14 cmpb bl,cl je L19 incl edi test $3,edi je L5 movl edi,eax movb (eax),cl testb cl,cl je L14 cmpb bl,cl je L19 incl edi test $3,edi je L5 movl edi,eax movb (eax),cl testb cl,cl je L14 cmpb bl,cl je L19 incl edi /* create 4 byte mask which is just the desired byte repeated 4 times */ L5: movl ebx,ecx sall $8,ebx subl $4,edi orl ecx,ebx movl ebx,edx sall $16,ebx orl edx,ebx /* loop performing 4 byte mask checking for 0 byte or desired byte */ .p2align 4,,7 L10: addl $4,edi movl (edi),ecx leal -16843009(ecx),edx movl ecx,eax notl eax andl eax,edx testl $-2139062144,edx jne L9 xorl ebx,ecx leal -16843009(ecx),edx notl ecx andl ecx,edx testl $-2139062144,edx je L10 #endif /* not __OPTIMIZE_SIZE__ */ /* loop while (*s && *s++ != c) */ L9: leal -1(edi),eax .p2align 4,,7 L15: incl eax movb (eax),dl testb dl,dl je L14 cmpb bl,dl jne L15 L14: /* if (*s == c) return address otherwise return NULL */ cmpb bl,(eax) je L19 xorl eax,eax L19: leal -8(ebp),esp popl ebx popl edi leave ret #ifndef __OPTIMIZE_SIZE__ /* Special case strchr(p,0). */ #if 0 /* Hideous performance on modern machines. */ L25: cld movl $-1,ecx xor eax,eax repnz scasb leal -1(edi),eax jmp L19 #endif L25: /* Do byte-wise checks until string is aligned. */ test $3,edi je L26 movl edi,eax movb (eax),cl testb cl,cl je L19 incl edi test $3,edi je L26 movl edi,eax movb (eax),cl testb cl,cl je L19 incl edi test $3,edi je L26 movl edi,eax movb (eax),cl testb cl,cl je L19 incl edi L26: subl $4,edi /* loop performing 4 byte mask checking for desired 0 byte */ .p2align 4,,7 L27: addl $4,edi movl (edi),ecx leal -16843009(ecx),edx movl ecx,eax notl eax andl eax,edx testl $-2139062144,edx je L27 jmp L9 #endif /* !__OPTIMIZE_SIZE__ */ #endif /* __iamcu__ */ #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/x86/strchr.S000066400000000000000000000001061513574234600177700ustar00rootroot00000000000000#include #ifndef __x86_64 #include "strchr-32.S" #endif picolibc-1.8.11/libc/machine/x86/strchr.c000066400000000000000000000001171513574234600200120ustar00rootroot00000000000000#include #ifdef __x86_64 #include "../../string/strchr.c" #endif picolibc-1.8.11/libc/machine/x86/strlen-32.S000066400000000000000000000031031513574234600202140ustar00rootroot00000000000000/* * ==================================================== * Copyright (C) 1998, 2002, 2008 by Red Hat Inc. All rights reserved. * * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== */ #include #include "i386mach.h" .global SYM (strlen) SOTYPE_FUNCTION(strlen) SYM (strlen): pushl ebp movl esp,ebp pushl edi #ifdef __iamcu__ movl eax,edx #else movl 8(ebp),edx #endif #if defined __OPTIMIZE_SIZE__ || defined __iamcu__ cld movl edx,edi movl $4294967295,ecx xor eax,eax repnz scasb #else /* Modern x86 hardware is much faster at double-word manipulation than with bytewise repnz scasb. */ /* Do byte-wise checks until string is aligned. */ movl edx,edi test $3,edi je L5 movb (edi),cl incl edi testb cl,cl je L15 test $3,edi je L5 movb (edi),cl incl edi testb cl,cl je L15 test $3,edi je L5 movb (edi),cl incl edi testb cl,cl je L15 L5: subl $4,edi /* loop performing 4 byte mask checking for desired 0 byte */ .p2align 4,,7 L10: addl $4,edi movl (edi),ecx leal -16843009(ecx),eax notl ecx andl ecx,eax testl $-2139062144,eax je L10 /* Find which of four bytes is 0. */ notl ecx incl edi testb cl,cl je L15 incl edi shrl $8,ecx testb cl,cl je L15 incl edi shrl $8,ecx testb cl,cl je L15 incl edi #endif L15: subl edx,edi leal -1(edi),eax leal -4(ebp),esp popl edi leave ret #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif picolibc-1.8.11/libc/machine/x86/strlen.S000066400000000000000000000001061513574234600177720ustar00rootroot00000000000000#include #ifndef __x86_64 #include "strlen-32.S" #endif picolibc-1.8.11/libc/machine/x86/strlen.c000066400000000000000000000001171513574234600200140ustar00rootroot00000000000000#include #ifdef __x86_64 #include "../../string/strlen.c" #endif picolibc-1.8.11/libc/machine/x86/sys/000077500000000000000000000000001513574234600171605ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/x86/sys/meson.build000066400000000000000000000033021513574234600213200ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_sys_headers_machine = [ ] if really_install install_headers(inc_sys_headers_machine, install_dir: include_dir / 'sys') endif picolibc-1.8.11/libc/machine/x86/tcb-32.S000066400000000000000000000052401513574234600174610ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 TK Chia * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include .text .weak __set_tcb .type __set_tcb, @function __set_tcb: /* * Assume that the %gs selector value refers to a slot in the GDT * dedicated to thread local storage; modify the GDT slot's base * * NOTE: this procedure only works if our program is running in * kernel mode (ring 0) and can directly write to the GDT * * If we are running unprivileged, then a syscall is likely needed * (e.g. set_thread_area on Linux/x86) */ push %edx push %edx sgdt 2(%esp) # read GDTR to get pointer to GDT pop %edx pop %edx xor %ecx, %ecx mov %gs, %cx # get index into GDT shr $3, %ecx jbe 9f lea (%edx, %ecx, 8), %ecx # compute pointer to GDT entry mov 4(%esp), %eax # get TCB base mov %eax, (%eax) # fill in self-pointer shld $8, %eax, %edx # split TCB address into two parts shl $8, %eax mov $0xff, %al # update GDT entry mov %eax, 1(%ecx) mov %dl, 7(%ecx) mov %gs, %ecx # reload %gs descriptor cache mov %ecx, %gs ret 9: ud2 .size __set_tcb, . - __set_tcb #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack, "", @progbits #endif picolibc-1.8.11/libc/machine/x86/tcb-64.S000066400000000000000000000040201513574234600174610ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 TK Chia * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #define MSR_FS_BASE 0xc0000100 .text .weak __set_tcb .type __set_tcb, @function __set_tcb: /* Assume that MSR_FS_BASE is present and that we can write to it */ xchg %rdi, %rax mov %rax, (%rax) # fill in self-pointer shld $32, %rax, %rdx # write %fs segment base mov $MSR_FS_BASE, %ecx wrmsr ret .size __set_tcb, . - __set_tcb #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack, "", @progbits #endif picolibc-1.8.11/libc/machine/x86/tcb.S000066400000000000000000000001341513574234600172340ustar00rootroot00000000000000#include #ifdef __x86_64 #include "tcb-64.S" #else #include "tcb-32.S" #endif picolibc-1.8.11/libc/machine/x86/tls.c000066400000000000000000000037611513574234600173170ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 TK Chia * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "machine/_tls.h" extern void __set_tcb(void *); extern char __x86_tls_tcb_offset[]; #define TP_OFFSET ((size_t)&__x86_tls_tcb_offset) void _set_tls(void *tls) { __set_tcb((char *)tls + TP_OFFSET); } /* Reserve space for a TCB. */ __attribute__((__section__(".tls_tail_extra"), __aligned__(1), __used__)) static char __tcb_space[sizeof(__tcb_head_t)]; picolibc-1.8.11/libc/machine/x86/x86_64mach.h000066400000000000000000000047631513574234600203140ustar00rootroot00000000000000/* Copyright (C) 2007 by Ellips BV. All rights reserved. Permission to use, copy, modify, and distribute this software is freely granted, provided that this notice is preserved. */ /* ** This file is distributed WITHOUT ANY WARRANTY; without even the implied ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef __USER_LABEL_PREFIX__ #define __USER_LABEL_PREFIX__ _ #endif #define __REG_PREFIX__ % /* ANSI concatenation macros. */ #define CONCAT1(a, b) CONCAT2(a, b) #define CONCAT2(a, b) a##b /* Use the right prefix for global labels. */ #define SYM(x) CONCAT1(__USER_LABEL_PREFIX__, x) /* Use the right prefix for registers. */ #define REG(x) CONCAT1(__REG_PREFIX__, x) #define rax REG(rax) #define rbx REG(rbx) #define rcx REG(rcx) #define rdx REG(rdx) #define rsi REG(rsi) #define rdi REG(rdi) #define rbp REG(rbp) #define rsp REG(rsp) #define r8 REG(r8) #define r9 REG(r9) #define r10 REG(r10) #define r11 REG(r11) #define r12 REG(r12) #define r13 REG(r13) #define r14 REG(r14) #define r15 REG(r15) #define eax REG(eax) #define ebx REG(ebx) #define ecx REG(ecx) #define edx REG(edx) #define esi REG(esi) #define edi REG(edi) #define ebp REG(ebp) #define esp REG(esp) #define st0 REG(st) #define st1 REG(st(1)) #define st2 REG(st(2)) #define st3 REG(st(3)) #define st4 REG(st(4)) #define st5 REG(st(5)) #define st6 REG(st(6)) #define st7 REG(st(7)) #define ax REG(ax) #define bx REG(bx) #define cx REG(cx) #define dx REG(dx) #define ah REG(ah) #define bh REG(bh) #define ch REG(ch) #define dh REG(dh) #define al REG(al) #define bl REG(bl) #define cl REG(cl) #define dl REG(dl) #define sil REG(sil) #define mm1 REG(mm1) #define mm2 REG(mm2) #define mm3 REG(mm3) #define mm4 REG(mm4) #define mm5 REG(mm5) #define mm6 REG(mm6) #define mm7 REG(mm7) #define xmm0 REG(xmm0) #define xmm1 REG(xmm1) #define xmm2 REG(xmm2) #define xmm3 REG(xmm3) #define xmm4 REG(xmm4) #define xmm5 REG(xmm5) #define xmm6 REG(xmm6) #define xmm7 REG(xmm7) #define cr0 REG(cr0) #define cr1 REG(cr1) #define cr2 REG(cr2) #define cr3 REG(cr3) #define cr4 REG(cr4) #ifdef _I386MACH_NEED_SOTYPE_FUNCTION #define SOTYPE_FUNCTION(sym) .type SYM(sym), @function #else #define SOTYPE_FUNCTION(sym) #endif #ifndef _I386MACH_DISABLE_HW_INTERRUPTS #define __CLI #define __STI #else #define __CLI cli #define __STI sti #endif picolibc-1.8.11/libc/machine/x86_64/000077500000000000000000000000001513574234600166535ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/x86_64/machine/000077500000000000000000000000001513574234600202575ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/x86_64/machine/_fpmath.h000066400000000000000000000042031513574234600220450ustar00rootroot00000000000000/*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2002, 2003 David Schultz * 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$ */ union IEEEl2bits { long double e; struct { unsigned int manl : 32; unsigned int manh : 32; unsigned int exp : 15; unsigned int sign : 1; unsigned int junkl : 16; unsigned int junkh : 32; } bits; struct { unsigned long man : 64; unsigned int expsign : 16; unsigned long junk : 48; } xbits; }; #define LDBL_NBIT 0x80000000 #define mask_nbit_l(u) ((u).bits.manh &= ~LDBL_NBIT) #define LDBL_MANH_SIZE 32 #define LDBL_MANL_SIZE 32 #define LDBL_TO_ARRAY32(u, a) \ do { \ (a)[0] = (uint32_t)(u).bits.manl; \ (a)[1] = (uint32_t)(u).bits.manh; \ } while (0) picolibc-1.8.11/libc/machine/xc16x/000077500000000000000000000000001513574234600166665ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/xc16x/putchar.c000066400000000000000000000007701513574234600205040ustar00rootroot00000000000000/* * Copyright (C) 2006 KPIT Cummins * Copyright (C) 2009 Conny Marco Menebröcker * All rights reserved. * * Redistribution and use in source and binary forms is permitted * provided that the above copyright notice and following paragraph are * duplicated in all such forms. * * This file is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include void putchar(int c) { __asm__("trap #1"); } picolibc-1.8.11/libc/machine/xc16x/puts.c000066400000000000000000000011241513574234600200230ustar00rootroot00000000000000/* * Copyright (C) 2006 KPIT Cummins * Copyright (C) 2009 Conny Marco Menebröcker * All rights reserved. * * Redistribution and use in source and binary forms is permitted * provided that the above copyright notice and following paragraph are * duplicated in all such forms. * * This file is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include int puts(const char *s) { /* Print string Function */ int a; while ((a = *s++)) putchar(a); return putchar('\n'); } picolibc-1.8.11/libc/machine/xc16x/setjmp.S000066400000000000000000000010321513574234600203100ustar00rootroot00000000000000/* * Copyright (C) 2006 KPIT Cummins * Copyright (C) 2009 Conny Marco Menebröcker * All rights reserved. * * Redistribution and use in source and binary forms is permitted * provided that the above copyright notice and following paragraph are * duplicated in all such forms. * * This file is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include .section .text .global setjmp _setjmp: #ifdef __xc16xL__ rets #else ret #endif picolibc-1.8.11/libc/machine/xstormy16/000077500000000000000000000000001513574234600176115ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/xstormy16/calloc.c000066400000000000000000000001061513574234600212070ustar00rootroot00000000000000#include #define DEFINE_CALLOC #include "tiny-malloc.c" picolibc-1.8.11/libc/machine/xstormy16/callocr.c000066400000000000000000000002001513574234600213640ustar00rootroot00000000000000#include #include void * _calloc_r(struct _reent *r, size_t a, size_t b) { return calloc(a, b); } picolibc-1.8.11/libc/machine/xstormy16/cfree.c000066400000000000000000000001051513574234600210350ustar00rootroot00000000000000#include #define DEFINE_CFREE #include "tiny-malloc.c" picolibc-1.8.11/libc/machine/xstormy16/freer.c000066400000000000000000000001451513574234600210600ustar00rootroot00000000000000#include #include void _free_r(struct _reent *r, void *x) { free(x); } picolibc-1.8.11/libc/machine/xstormy16/malign.c000066400000000000000000000001101513574234600212140ustar00rootroot00000000000000#include #define DEFINE_MEMALIGN #include "tiny-malloc.c" picolibc-1.8.11/libc/machine/xstormy16/malloc.c000066400000000000000000000002301513574234600212170ustar00rootroot00000000000000/* stdlib/malloc.c defines all these symbols in this file. */ #include #define DEFINE_FREE #define DEFINE_MALLOC #include "tiny-malloc.c" picolibc-1.8.11/libc/machine/xstormy16/mallocr.c000066400000000000000000000002631513574234600214070ustar00rootroot00000000000000/* Copyright (c) 2002 Geoffrey Keating */ #include #include void * _malloc_r(struct _reent *r, size_t sz) { return malloc(sz); } picolibc-1.8.11/libc/machine/xstormy16/msize.c000066400000000000000000000001221513574234600210770ustar00rootroot00000000000000#include #define DEFINE_MALLOC_USABLE_SIZE #include "tiny-malloc.c" picolibc-1.8.11/libc/machine/xstormy16/mstats.c000066400000000000000000000003341513574234600212700ustar00rootroot00000000000000/* stdlib/mstats.c defines all these symbols in this file. TODO: Missing mstats function. */ #include #define DEFINE_MALLINFO #define DEFINE_MALLOC_STATS #define DEFINE_MALLOPT #include "tiny-malloc.c" picolibc-1.8.11/libc/machine/xstormy16/realloc.c000066400000000000000000000001071513574234600213740ustar00rootroot00000000000000#include #define DEFINE_REALLOC #include "tiny-malloc.c" picolibc-1.8.11/libc/machine/xstormy16/reallocr.c000066400000000000000000000002031513574234600215530ustar00rootroot00000000000000#include #include void * _realloc_r(struct _reent *r, void *x, size_t sz) { return realloc(x, sz); } picolibc-1.8.11/libc/machine/xstormy16/setjmp.S000066400000000000000000000017671513574234600212520ustar00rootroot00000000000000#include ;; xstormy16 ;; Copyright (C) 2001 by Red Hat, Incorporated. All rights reserved. ;; ;; Permission to use, copy, modify, and distribute this software ;; is freely granted, provided that this notice is preserved. ;; .file "setjmp.S" .section .text .align 1 .global setjmp .type setjmp,@function setjmp: mov r0,r10 mov (r2++),r0 mov r0,r11 mov (r2++),r0 mov r0,r12 mov (r2++),r0 mov r0,r13 mov (r2++),r0 pop r0 ; PC high word pop r1 ; PC low word mov (r2++), r0 mov (r2++), r1 mov r3,sp mov (r2++),r3 mov.w r2,#0 mov r8, r0 mov r9, r1 jmp r8, r9 .size setjmp,.-setjmp .global longjmp .type longjmp,@function longjmp: mov r0,(r2++) mov r10,r0 mov r0,(r2++) mov r11,r0 mov r0,(r2++) mov r12,r0 mov r0,(r2++) mov r13,r0 mov r0,(r2++) mov r8, r0 mov r1,(r2++) mov r9, r1 mov r4,(r2++) mov sp,r4 ;; status arg (r3) to longjmp is return value ;; if it's zero, return 1 bnz r3, #0, 0f mov.w r3,#1 0: mov r2, r3 jmp r8,r9 .size longjmp,.-longjmp picolibc-1.8.11/libc/machine/xstormy16/tiny-malloc.c000066400000000000000000000420631513574234600222120ustar00rootroot00000000000000/* Copyright (c) 2002 Geoffrey Keating */ /* A replacement malloc with: - Much reduced code size; - Smaller RAM footprint; - The ability to handle downward-growing heaps; but - Slower; - Probably higher memory fragmentation; - Doesn't support threads (but, if it did support threads, it wouldn't need a global lock, only a compare-and-swap instruction); - Assumes the maximum alignment required is the alignment of a pointer; - Assumes that memory is already there and doesn't need to be allocated. * Synopsis of public routines malloc(size_t n); Return a pointer to a newly allocated chunk of at least n bytes, or null if no space is available. free(void* p); Release the chunk of memory pointed to by p, or no effect if p is null. realloc(void* p, size_t n); Return a pointer to a chunk of size n that contains the same data as does chunk p up to the minimum of (n, p's size) bytes, or null if no space is available. The returned pointer may or may not be the same as p. If p is null, equivalent to malloc. Unless the #define REALLOC_ZERO_BYTES_FREES below is set, realloc with a size argument of zero (re)allocates a minimum-sized chunk. memalign(size_t alignment, size_t n); Return a pointer to a newly allocated chunk of n bytes, aligned in accord with the alignment argument, which must be a power of two. Will fail if 'alignment' is too large. calloc(size_t unit, size_t quantity); Returns a pointer to quantity * unit bytes, with all locations set to zero. cfree(void* p); Equivalent to free(p). malloc_trim(size_t pad); Release all but pad bytes of freed top-most memory back to the system. Return 1 if successful, else 0. malloc_usable_size(void* p); Report the number usable allocated bytes associated with allocated chunk p. This may or may not report more bytes than were requested, due to alignment and minimum size constraints. malloc_stats(); Prints brief summary statistics on stderr. mallinfo() Returns (by copy) a struct containing various summary statistics. mallopt(int parameter_number, int parameter_value) Changes one of the tunable parameters described below. Returns 1 if successful in changing the parameter, else 0. Actually, returns 0 always, as no parameter can be changed. */ #include #ifdef __xstormy16__ #define MALLOC_DIRECTION -1 #endif #ifndef MALLOC_DIRECTION #define MALLOC_DIRECTION 1 #endif #include void *malloc(size_t); void free(void *); void *realloc(void *, size_t); void *memalign(size_t, size_t); void *valloc(size_t); void *pvalloc(size_t); void *calloc(size_t, size_t); void cfree(void *); int malloc_trim(size_t); size_t malloc_usable_size(void *); void malloc_stats(void); int mallopt(int, int); struct mallinfo mallinfo(void); typedef struct freelist_entry { size_t size; struct freelist_entry *next; } *fle; extern void *__malloc_end; extern fle __malloc_freelist; /* Return the number of bytes that need to be added to X to make it aligned to an ALIGN boundary. ALIGN must be a power of 2. */ #define M_ALIGN(x, align) (-(size_t)(x) & ((align) - 1)) /* Return the number of bytes that need to be subtracted from X to make it aligned to an ALIGN boundary. ALIGN must be a power of 2. */ #define M_ALIGN_SUB(x, align) ((size_t)(x) & ((align) - 1)) extern void __malloc_start; /* This is the minimum gap allowed between __malloc_end and the top of the stack. This is only checked for when __malloc_end is decreased; if instead the stack grows into the heap, silent data corruption will result. */ #define MALLOC_MINIMUM_GAP 32 #ifdef __xstormy16__ register void *stack_pointer __asm__("r15"); #define MALLOC_LIMIT stack_pointer #else #define MALLOC_LIMIT __builtin_frame_address(0) #endif #if MALLOC_DIRECTION < 0 #define CAN_ALLOC_P(required) \ (((size_t)__malloc_end - (size_t)MALLOC_LIMIT - MALLOC_MINIMUM_GAP) >= (required)) #else #define CAN_ALLOC_P(required) \ (((size_t)MALLOC_LIMIT - (size_t)__malloc_end - MALLOC_MINIMUM_GAP) >= (required)) #endif /* real_size is the size we actually have to allocate, allowing for overhead and alignment. */ #define REAL_SIZE(sz) \ ((sz) < sizeof(struct freelist_entry) - sizeof(size_t) \ ? sizeof(struct freelist_entry) \ : sz + sizeof(size_t) + M_ALIGN(sz, sizeof(size_t))) #ifdef DEFINE_MALLOC void *__malloc_end = &__malloc_start; fle __malloc_freelist; void * malloc(size_t sz) { fle *nextfree; fle block; /* real_size is the size we actually have to allocate, allowing for overhead and alignment. */ size_t real_size = REAL_SIZE(sz); /* Look for the first block on the freelist that is large enough. */ for (nextfree = &__malloc_freelist; *nextfree; nextfree = &(*nextfree)->next) { block = *nextfree; if (block->size >= real_size) { /* If the block found is just the right size, remove it from the free list. Otherwise, split it. */ if (block->size < real_size + sizeof(struct freelist_entry)) { *nextfree = block->next; return (void *)&block->next; } else { size_t newsize = block->size - real_size; fle newnext = block->next; *nextfree = (fle)((size_t)block + real_size); (*nextfree)->size = newsize; (*nextfree)->next = newnext; goto done; } } /* If this is the last block on the freelist, and it was too small, enlarge it. */ if (!block->next && __malloc_end == (void *)((size_t)block + block->size)) { size_t moresize = real_size - block->size; if (!CAN_ALLOC_P(moresize)) return NULL; *nextfree = NULL; if (MALLOC_DIRECTION < 0) { block = __malloc_end = (void *)((size_t)block - moresize); } else { __malloc_end = (void *)((size_t)block + real_size); } goto done; } } /* No free space at the end of the free list. Allocate new space and use that. */ if (!CAN_ALLOC_P(real_size)) return NULL; if (MALLOC_DIRECTION > 0) { block = __malloc_end; __malloc_end = (void *)((size_t)__malloc_end + real_size); } else { block = __malloc_end = (void *)((size_t)__malloc_end - real_size); } done: block->size = real_size; return (void *)&block->next; } #endif #ifdef DEFINE_FREE void free(void *block_p) { fle *nextfree; fle block = (fle)((size_t)block_p - offsetof(struct freelist_entry, next)); if (block_p == NULL) return; /* Look on the freelist to see if there's a free block just before or just after this block. */ for (nextfree = &__malloc_freelist; *nextfree; nextfree = &(*nextfree)->next) { fle thisblock = *nextfree; if ((size_t)thisblock + thisblock->size == (size_t)block) { thisblock->size += block->size; if (MALLOC_DIRECTION > 0 && thisblock->next && (size_t)block + block->size == (size_t)thisblock->next) { thisblock->size += thisblock->next->size; thisblock->next = thisblock->next->next; } return; } else if ((size_t)thisblock == (size_t)block + block->size) { if (MALLOC_DIRECTION < 0 && thisblock->next && (size_t)block == ((size_t)thisblock->next + thisblock->next->size)) { *nextfree = thisblock->next; thisblock->next->size += block->size + thisblock->size; } else { block->size += thisblock->size; block->next = thisblock->next; *nextfree = block; } return; } else if ((MALLOC_DIRECTION > 0 && (size_t)thisblock > (size_t)block) || (MALLOC_DIRECTION < 0 && (size_t)thisblock < (size_t)block)) break; } block->next = *nextfree; *nextfree = block; return; } #endif #ifdef DEFINE_REALLOC #include void * realloc(void *block_p, size_t sz) { fle block = (fle)((size_t)block_p - offsetof(struct freelist_entry, next)); size_t real_size = REAL_SIZE(sz); size_t old_real_size; if (block_p == NULL) return malloc(sz); old_real_size = block->size; /* Perhaps we need to allocate more space. */ if (old_real_size < real_size) { void *result; size_t old_size = old_real_size - sizeof(size_t); /* Need to allocate, copy, and free. */ result = malloc(sz); if (result == NULL) return NULL; memcpy(result, block_p, old_size < sz ? old_size : sz); free(block_p); return result; } /* Perhaps we can free some space. */ if (old_real_size - real_size >= sizeof(struct freelist_entry)) { fle newblock = (fle)((size_t)block + real_size); block->size = real_size; newblock->size = old_real_size - real_size; free(&newblock->next); } return block_p; } #endif #ifdef DEFINE_CALLOC #include void * calloc(size_t n, size_t elem_size) { void *result; size_t sz = n * elem_size; result = malloc(sz); if (result != NULL) memset(result, 0, sz); return result; } #endif #ifdef DEFINE_CFREE void cfree(void *p) { free(p); } #endif #ifdef DEFINE_MEMALIGN void * memalign(size_t align, size_t sz) { fle *nextfree; fle block; /* real_size is the size we actually have to allocate, allowing for overhead and alignment. */ size_t real_size = REAL_SIZE(sz); /* Some sanity checking on 'align'. */ if ((align & (align - 1)) != 0 || align <= 0) return NULL; /* Look for the first block on the freelist that is large enough. */ /* One tricky part is this: We want the result to be a valid pointer to free. That means that there has to be room for a size_t before the block. If there's additional space before the block, it should go on the freelist, or it'll be lost---we could add it to the size of the block before it in memory, but finding the previous block is expensive. */ for (nextfree = &__malloc_freelist;; nextfree = &(*nextfree)->next) { size_t before_size; size_t old_size; /* If we've run out of free blocks, allocate more space. */ if (!*nextfree) { old_size = real_size; if (MALLOC_DIRECTION < 0) { old_size += M_ALIGN_SUB(((size_t)__malloc_end - old_size + sizeof(size_t)), align); if (!CAN_ALLOC_P(old_size)) return NULL; block = __malloc_end = (void *)((size_t)__malloc_end - old_size); } else { block = __malloc_end; old_size += M_ALIGN((size_t)__malloc_end + sizeof(size_t), align); if (!CAN_ALLOC_P(old_size)) return NULL; __malloc_end = (void *)((size_t)__malloc_end + old_size); } *nextfree = block; block->size = old_size; block->next = NULL; } else { block = *nextfree; old_size = block->size; } before_size = M_ALIGN(&block->next, align); if (before_size != 0) before_size = sizeof(*block) + M_ALIGN(&(block + 1)->next, align); /* If this is the last block on the freelist, and it is too small, enlarge it. */ if (!block->next && old_size < real_size + before_size && __malloc_end == (void *)((size_t)block + block->size)) { if (MALLOC_DIRECTION < 0) { size_t moresize = real_size - block->size; moresize += M_ALIGN_SUB((size_t)&block->next - moresize, align); if (!CAN_ALLOC_P(moresize)) return NULL; block = __malloc_end = (void *)((size_t)block - moresize); block->next = NULL; block->size = old_size = old_size + moresize; before_size = 0; } else { if (!CAN_ALLOC_P(before_size + real_size - block->size)) return NULL; __malloc_end = (void *)((size_t)block + before_size + real_size); block->size = old_size = before_size + real_size; } /* Two out of the four cases below will now be possible; which two depends on MALLOC_DIRECTION. */ } if (old_size >= real_size + before_size) { /* This block will do. If there needs to be space before it, split the block. */ if (before_size != 0) { fle old_block = block; old_block->size = before_size; block = (fle)((size_t)block + before_size); /* If there's no space after the block, we're now nearly done; just make a note of the size required. Otherwise, we need to create a new free space block. */ if (old_size - before_size <= real_size + sizeof(struct freelist_entry)) { block->size = old_size - before_size; return (void *)&block->next; } else { fle new_block; new_block = (fle)((size_t)block + real_size); new_block->size = old_size - before_size - real_size; if (MALLOC_DIRECTION > 0) { new_block->next = old_block->next; old_block->next = new_block; } else { new_block->next = old_block; *nextfree = new_block; } goto done; } } else { /* If the block found is just the right size, remove it from the free list. Otherwise, split it. */ if (old_size <= real_size + sizeof(struct freelist_entry)) { *nextfree = block->next; return (void *)&block->next; } else { size_t newsize = old_size - real_size; fle newnext = block->next; *nextfree = (fle)((size_t)block + real_size); (*nextfree)->size = newsize; (*nextfree)->next = newnext; goto done; } } } } done: block->size = real_size; return (void *)&block->next; } #endif #ifdef DEFINE_VALLOC void * valloc(size_t sz) { return memalign(128, sz); } #endif #ifdef DEFINE_PVALLOC void * pvalloc(size_t sz) { return memalign(128, sz + M_ALIGN(sz, 128)); } #endif #ifdef DEFINE_MALLINFO #include "malloc.h" #include struct mallinfo mallinfo(void) { struct mallinfo r; fle fr; size_t free_size; size_t total_size; size_t free_blocks; memset(&r, 0, sizeof(r)); free_size = 0; free_blocks = 0; for (fr = __malloc_freelist; fr; fr = fr->next) { free_size += fr->size; free_blocks++; if (!fr->next) { int atend; if (MALLOC_DIRECTION > 0) atend = (void *)((size_t)fr + fr->size) == __malloc_end; else atend = (void *)fr == __malloc_end; if (atend) r.keepcost = fr->size; } } if (MALLOC_DIRECTION > 0) total_size = (char *)__malloc_end - (char *)&__malloc_start; else total_size = (char *)&__malloc_start - (char *)__malloc_end; #ifdef DEBUG /* Fixme: should walk through all the in-use blocks and see if they're valid. */ #endif r.arena = total_size; r.fordblks = free_size; r.uordblks = total_size - free_size; r.ordblks = free_blocks; return r; } #endif #ifdef DEFINE_MALLOC_STATS #include "malloc.h" #include void malloc_stats(void) { struct mallinfo i; FILE *fp; fp = stderr; i = mallinfo(); fprintf(fp, "malloc has reserved %u bytes between %p and %p\n", i.arena, &__malloc_start, __malloc_end); fprintf(fp, "there are %u bytes free in %u chunks\n", i.fordblks, i.ordblks); fprintf(fp, "of which %u bytes are at the end of the reserved space\n", i.keepcost); fprintf(fp, "and %u bytes are in use.\n", i.uordblks); } #endif #ifdef DEFINE_MALLOC_USABLE_SIZE size_t malloc_usable_size(void *block_p) { fle block = (fle)((size_t)block_p - offsetof(struct freelist_entry, next)); return block->size - sizeof(size_t); } #endif #ifdef DEFINE_MALLOPT int mallopt(int n, int v) { (void)n; (void)v; return 0; } #endif picolibc-1.8.11/libc/machine/xstormy16/valloc.c000066400000000000000000000002331513574234600212330ustar00rootroot00000000000000/* stdlib/valloc.c defines all these symbols in this file. */ #include #define DEFINE_PVALLOC #define DEFINE_VALLOC #include "tiny-malloc.c" picolibc-1.8.11/libc/machine/xtensa/000077500000000000000000000000001513574234600172175ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/xtensa/CMakeLists.txt000066400000000000000000000033111513574234600217550ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # add_subdirectory(machine) picolibc_sources_flags("-fno-builtin" memcpy.S memset.S setjmp.S strcmp.S strcpy.S strlen.S strncpy.S tls.c ) picolibc-1.8.11/libc/machine/xtensa/machine/000077500000000000000000000000001513574234600206235ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/xtensa/machine/CMakeLists.txt000066400000000000000000000031531513574234600233650ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_headers(machine core-isa.h fenv.h fenv-fp.h ) picolibc-1.8.11/libc/machine/xtensa/machine/core-isa.h000066400000000000000000000541371513574234600225100ustar00rootroot00000000000000#ifdef _XTENSA_HAVE_CONFIG_CORE_ISA_H #include #else /* * xtensa/config/core-isa.h -- HAL definitions that are dependent on Xtensa * processor CORE configuration * * See , which includes this file, for more details. */ /* Xtensa processor core configuration information. Copyright (c) 1999-2010 Tensilica Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef _XTENSA_CORE_CONFIGURATION_H #define _XTENSA_CORE_CONFIGURATION_H /**************************************************************************** Parameters Useful for Any Code, USER or PRIVILEGED ****************************************************************************/ /* * Note: Macros of the form XCHAL_HAVE_*** have a value of 1 if the option is * configured, and a value of 0 otherwise. These macros are always defined. */ /*---------------------------------------------------------------------- ISA ----------------------------------------------------------------------*/ #define XCHAL_HAVE_BE 0 /* big-endian byte ordering */ #define XCHAL_HAVE_WINDOWED 0 /* windowed registers option */ #define XCHAL_NUM_AREGS 16 /* num of physical addr regs */ #define XCHAL_NUM_AREGS_LOG2 4 /* log2(XCHAL_NUM_AREGS) */ #define XCHAL_MAX_INSTRUCTION_SIZE 3 /* max instr bytes (3..8) */ #define XCHAL_HAVE_DEBUG 1 /* debug option */ #define XCHAL_HAVE_DENSITY 1 /* 16-bit instructions */ #define XCHAL_HAVE_LOOPS 0 /* zero-overhead loops */ #define XCHAL_HAVE_NSA 1 /* NSA/NSAU instructions */ #define XCHAL_HAVE_MINMAX 0 /* MIN/MAX instructions */ #define XCHAL_HAVE_SEXT 0 /* SEXT instruction */ #define XCHAL_HAVE_CLAMPS 0 /* CLAMPS instruction */ #define XCHAL_HAVE_MUL16 1 /* MUL16S/MUL16U instructions */ #define XCHAL_HAVE_MUL32 1 /* MULL instruction */ #define XCHAL_HAVE_MUL32_HIGH 0 /* MULUH/MULSH instructions */ #define XCHAL_HAVE_DIV32 0 /* QUOS/QUOU/REMS/REMU instructions */ #define XCHAL_HAVE_L32R 1 /* L32R instruction */ #define XCHAL_HAVE_ABSOLUTE_LITERALS 1 /* non-PC-rel (extended) L32R */ #define XCHAL_HAVE_CONST16 0 /* CONST16 instruction */ #define XCHAL_HAVE_ADDX 1 /* ADDX#/SUBX# instructions */ #define XCHAL_HAVE_WIDE_BRANCHES 0 /* B*.W18 or B*.W15 instr's */ #define XCHAL_HAVE_PREDICTED_BRANCHES 0 /* B[EQ/EQZ/NE/NEZ]T instr's */ #define XCHAL_HAVE_CALL4AND12 0 /* (obsolete option) */ #define XCHAL_HAVE_ABS 1 /* ABS instruction */ /*#define XCHAL_HAVE_POPC 0*/ /* POPC instruction */ /*#define XCHAL_HAVE_CRC 0*/ /* CRC instruction */ #define XCHAL_HAVE_RELEASE_SYNC 0 /* L32AI/S32RI instructions */ #define XCHAL_HAVE_S32C1I 0 /* S32C1I instruction */ #define XCHAL_HAVE_SPECULATION 0 /* speculation */ #define XCHAL_HAVE_FULL_RESET 1 /* all regs/state reset */ #define XCHAL_NUM_CONTEXTS 1 /* */ #define XCHAL_NUM_MISC_REGS 0 /* num of scratch regs (0..4) */ #define XCHAL_HAVE_TAP_MASTER 0 /* JTAG TAP control instr's */ #define XCHAL_HAVE_PRID 1 /* processor ID register */ #define XCHAL_HAVE_EXTERN_REGS 1 /* WER/RER instructions */ #define XCHAL_HAVE_MP_INTERRUPTS 0 /* interrupt distributor port */ #define XCHAL_HAVE_MP_RUNSTALL 0 /* core RunStall control port */ #define XCHAL_HAVE_THREADPTR 0 /* THREADPTR register */ #define XCHAL_HAVE_BOOLEANS 0 /* boolean registers */ #define XCHAL_HAVE_CP 0 /* CPENABLE reg (coprocessor) */ #define XCHAL_CP_MAXCFG 0 /* max allowed cp id plus one */ #define XCHAL_HAVE_MAC16 0 /* MAC16 package */ #define XCHAL_HAVE_VECTORFPU2005 0 /* vector floating-point pkg */ #define XCHAL_HAVE_FP 0 /* floating point pkg */ #define XCHAL_HAVE_DFP 0 /* double precision FP pkg */ #define XCHAL_HAVE_DFP_accel 0 /* double precision FP acceleration pkg */ #define XCHAL_HAVE_VECTRA1 0 /* Vectra I pkg */ #define XCHAL_HAVE_VECTRALX 0 /* Vectra LX pkg */ #define XCHAL_HAVE_HIFIPRO 0 /* HiFiPro Audio Engine pkg */ #define XCHAL_HAVE_HIFI2 0 /* HiFi2 Audio Engine pkg */ #define XCHAL_HAVE_CONNXD2 0 /* ConnX D2 pkg */ /*---------------------------------------------------------------------- MISC ----------------------------------------------------------------------*/ #define XCHAL_NUM_WRITEBUFFER_ENTRIES 1 /* size of write buffer */ #define XCHAL_INST_FETCH_WIDTH 4 /* instr-fetch width in bytes */ #define XCHAL_DATA_WIDTH 4 /* data width in bytes */ /* In T1050, applies to selected core load and store instructions (see ISA): */ #define XCHAL_UNALIGNED_LOAD_EXCEPTION 1 /* unaligned loads cause exc. */ #define XCHAL_UNALIGNED_STORE_EXCEPTION 1 /* unaligned stores cause exc.*/ #define XCHAL_UNALIGNED_LOAD_HW 0 /* unaligned loads work in hw */ #define XCHAL_UNALIGNED_STORE_HW 0 /* unaligned stores work in hw*/ #define XCHAL_SW_VERSION 800001 /* sw version of this header */ #define XCHAL_CORE_ID \ "lx106" /* alphanum core name \ (CoreID) set in the Xtensa \ Processor Generator */ #define XCHAL_BUILD_UNIQUE_ID 0x0002B6F6 /* 22-bit sw build ID */ /* * These definitions describe the hardware targeted by this software. */ #define XCHAL_HW_CONFIGID0 0xC28CDAFA /* ConfigID hi 32 bits*/ #define XCHAL_HW_CONFIGID1 0x1082B6F6 /* ConfigID lo 32 bits*/ #define XCHAL_HW_VERSION_NAME "LX3.0.1" /* full version name */ #define XCHAL_HW_VERSION_MAJOR 2300 /* major ver# of targeted hw */ #define XCHAL_HW_VERSION_MINOR 1 /* minor ver# of targeted hw */ #define XCHAL_HW_VERSION 230001 /* major*100+minor */ #define XCHAL_HW_REL_LX3 1 #define XCHAL_HW_REL_LX3_0 1 #define XCHAL_HW_REL_LX3_0_1 1 #define XCHAL_HW_CONFIGID_RELIABLE 1 /* If software targets a *range* of hardware versions, these are the bounds: */ #define XCHAL_HW_MIN_VERSION_MAJOR 2300 /* major v of earliest tgt hw */ #define XCHAL_HW_MIN_VERSION_MINOR 1 /* minor v of earliest tgt hw */ #define XCHAL_HW_MIN_VERSION 230001 /* earliest targeted hw */ #define XCHAL_HW_MAX_VERSION_MAJOR 2300 /* major v of latest tgt hw */ #define XCHAL_HW_MAX_VERSION_MINOR 1 /* minor v of latest tgt hw */ #define XCHAL_HW_MAX_VERSION 230001 /* latest targeted hw */ /*---------------------------------------------------------------------- CACHE ----------------------------------------------------------------------*/ #define XCHAL_ICACHE_LINESIZE 4 /* I-cache line size in bytes */ #define XCHAL_DCACHE_LINESIZE 4 /* D-cache line size in bytes */ #define XCHAL_ICACHE_LINEWIDTH 2 /* log2(I line size in bytes) */ #define XCHAL_DCACHE_LINEWIDTH 2 /* log2(D line size in bytes) */ #define XCHAL_ICACHE_SIZE 0 /* I-cache size in bytes or 0 */ #define XCHAL_DCACHE_SIZE 0 /* D-cache size in bytes or 0 */ #define XCHAL_DCACHE_IS_WRITEBACK 0 /* writeback feature */ #define XCHAL_DCACHE_IS_COHERENT 0 /* MP coherence feature */ #define XCHAL_HAVE_PREFETCH 0 /* PREFCTL register */ /**************************************************************************** Parameters Useful for PRIVILEGED (Supervisory or Non-Virtualized) Code ****************************************************************************/ #ifndef XTENSA_HAL_NON_PRIVILEGED_ONLY /*---------------------------------------------------------------------- CACHE ----------------------------------------------------------------------*/ #define XCHAL_HAVE_PIF 1 /* any outbound PIF present */ /* If present, cache size in bytes == (ways * 2^(linewidth + setwidth)). */ /* Number of cache sets in log2(lines per way): */ #define XCHAL_ICACHE_SETWIDTH 0 #define XCHAL_DCACHE_SETWIDTH 0 /* Cache set associativity (number of ways): */ #define XCHAL_ICACHE_WAYS 1 #define XCHAL_DCACHE_WAYS 1 /* Cache features: */ #define XCHAL_ICACHE_LINE_LOCKABLE 0 #define XCHAL_DCACHE_LINE_LOCKABLE 0 #define XCHAL_ICACHE_ECC_PARITY 0 #define XCHAL_DCACHE_ECC_PARITY 0 /* Cache access size in bytes (affects operation of SICW instruction): */ #define XCHAL_ICACHE_ACCESS_SIZE 1 #define XCHAL_DCACHE_ACCESS_SIZE 1 /* Number of encoded cache attr bits (see for decoded bits): */ #define XCHAL_CA_BITS 4 /*---------------------------------------------------------------------- INTERNAL I/D RAM/ROMs and XLMI ----------------------------------------------------------------------*/ #define XCHAL_NUM_INSTROM 1 /* number of core instr. ROMs */ #define XCHAL_NUM_INSTRAM 2 /* number of core instr. RAMs */ #define XCHAL_NUM_DATAROM 1 /* number of core data ROMs */ #define XCHAL_NUM_DATARAM 2 /* number of core data RAMs */ #define XCHAL_NUM_URAM 0 /* number of core unified RAMs*/ #define XCHAL_NUM_XLMI 1 /* number of core XLMI ports */ /* Instruction ROM 0: */ #define XCHAL_INSTROM0_VADDR 0x40200000 #define XCHAL_INSTROM0_PADDR 0x40200000 #define XCHAL_INSTROM0_SIZE 1048576 #define XCHAL_INSTROM0_ECC_PARITY 0 /* Instruction RAM 0: */ #define XCHAL_INSTRAM0_VADDR 0x40000000 #define XCHAL_INSTRAM0_PADDR 0x40000000 #define XCHAL_INSTRAM0_SIZE 1048576 #define XCHAL_INSTRAM0_ECC_PARITY 0 /* Instruction RAM 1: */ #define XCHAL_INSTRAM1_VADDR 0x40100000 #define XCHAL_INSTRAM1_PADDR 0x40100000 #define XCHAL_INSTRAM1_SIZE 1048576 #define XCHAL_INSTRAM1_ECC_PARITY 0 /* Data ROM 0: */ #define XCHAL_DATAROM0_VADDR 0x3FF40000 #define XCHAL_DATAROM0_PADDR 0x3FF40000 #define XCHAL_DATAROM0_SIZE 262144 #define XCHAL_DATAROM0_ECC_PARITY 0 /* Data RAM 0: */ #define XCHAL_DATARAM0_VADDR 0x3FFC0000 #define XCHAL_DATARAM0_PADDR 0x3FFC0000 #define XCHAL_DATARAM0_SIZE 262144 #define XCHAL_DATARAM0_ECC_PARITY 0 /* Data RAM 1: */ #define XCHAL_DATARAM1_VADDR 0x3FF80000 #define XCHAL_DATARAM1_PADDR 0x3FF80000 #define XCHAL_DATARAM1_SIZE 262144 #define XCHAL_DATARAM1_ECC_PARITY 0 /* XLMI Port 0: */ #define XCHAL_XLMI0_VADDR 0x3FF00000 #define XCHAL_XLMI0_PADDR 0x3FF00000 #define XCHAL_XLMI0_SIZE 262144 #define XCHAL_XLMI0_ECC_PARITY 0 /*---------------------------------------------------------------------- INTERRUPTS and TIMERS ----------------------------------------------------------------------*/ #define XCHAL_HAVE_INTERRUPTS 1 /* interrupt option */ #define XCHAL_HAVE_HIGHPRI_INTERRUPTS 1 /* med/high-pri. interrupts */ #define XCHAL_HAVE_NMI 1 /* non-maskable interrupt */ #define XCHAL_HAVE_CCOUNT 1 /* CCOUNT reg. (timer option) */ #define XCHAL_NUM_TIMERS 1 /* number of CCOMPAREn regs */ #define XCHAL_NUM_INTERRUPTS 15 /* number of interrupts */ #define XCHAL_NUM_INTERRUPTS_LOG2 4 /* ceil(log2(NUM_INTERRUPTS)) */ #define XCHAL_NUM_EXTINTERRUPTS 13 /* num of external interrupts */ #define XCHAL_NUM_INTLEVELS \ 2 /* number of interrupt levels \ (not including level zero) */ #define XCHAL_EXCM_LEVEL 1 /* level masked by PS.EXCM */ /* (always 1 in XEA1; levels 2 .. EXCM_LEVEL are "medium priority") */ /* Masks of interrupts at each interrupt level: */ #define XCHAL_INTLEVEL1_MASK 0x00003FFF #define XCHAL_INTLEVEL2_MASK 0x00000000 #define XCHAL_INTLEVEL3_MASK 0x00004000 #define XCHAL_INTLEVEL4_MASK 0x00000000 #define XCHAL_INTLEVEL5_MASK 0x00000000 #define XCHAL_INTLEVEL6_MASK 0x00000000 #define XCHAL_INTLEVEL7_MASK 0x00000000 /* Masks of interrupts at each range 1..n of interrupt levels: */ #define XCHAL_INTLEVEL1_ANDBELOW_MASK 0x00003FFF #define XCHAL_INTLEVEL2_ANDBELOW_MASK 0x00003FFF #define XCHAL_INTLEVEL3_ANDBELOW_MASK 0x00007FFF #define XCHAL_INTLEVEL4_ANDBELOW_MASK 0x00007FFF #define XCHAL_INTLEVEL5_ANDBELOW_MASK 0x00007FFF #define XCHAL_INTLEVEL6_ANDBELOW_MASK 0x00007FFF #define XCHAL_INTLEVEL7_ANDBELOW_MASK 0x00007FFF /* Level of each interrupt: */ #define XCHAL_INT0_LEVEL 1 #define XCHAL_INT1_LEVEL 1 #define XCHAL_INT2_LEVEL 1 #define XCHAL_INT3_LEVEL 1 #define XCHAL_INT4_LEVEL 1 #define XCHAL_INT5_LEVEL 1 #define XCHAL_INT6_LEVEL 1 #define XCHAL_INT7_LEVEL 1 #define XCHAL_INT8_LEVEL 1 #define XCHAL_INT9_LEVEL 1 #define XCHAL_INT10_LEVEL 1 #define XCHAL_INT11_LEVEL 1 #define XCHAL_INT12_LEVEL 1 #define XCHAL_INT13_LEVEL 1 #define XCHAL_INT14_LEVEL 3 #define XCHAL_DEBUGLEVEL 2 /* debug interrupt level */ #define XCHAL_HAVE_DEBUG_EXTERN_INT 1 /* OCD external db interrupt */ #define XCHAL_NMILEVEL \ 3 /* NMI "level" (for use with \ EXCSAVE/EPS/EPC_n, RFI n) */ /* Type of each interrupt: */ #define XCHAL_INT0_TYPE XTHAL_INTTYPE_EXTERN_LEVEL #define XCHAL_INT1_TYPE XTHAL_INTTYPE_EXTERN_LEVEL #define XCHAL_INT2_TYPE XTHAL_INTTYPE_EXTERN_LEVEL #define XCHAL_INT3_TYPE XTHAL_INTTYPE_EXTERN_LEVEL #define XCHAL_INT4_TYPE XTHAL_INTTYPE_EXTERN_LEVEL #define XCHAL_INT5_TYPE XTHAL_INTTYPE_EXTERN_LEVEL #define XCHAL_INT6_TYPE XTHAL_INTTYPE_TIMER #define XCHAL_INT7_TYPE XTHAL_INTTYPE_SOFTWARE #define XCHAL_INT8_TYPE XTHAL_INTTYPE_EXTERN_EDGE #define XCHAL_INT9_TYPE XTHAL_INTTYPE_EXTERN_EDGE #define XCHAL_INT10_TYPE XTHAL_INTTYPE_EXTERN_EDGE #define XCHAL_INT11_TYPE XTHAL_INTTYPE_EXTERN_EDGE #define XCHAL_INT12_TYPE XTHAL_INTTYPE_EXTERN_EDGE #define XCHAL_INT13_TYPE XTHAL_INTTYPE_EXTERN_EDGE #define XCHAL_INT14_TYPE XTHAL_INTTYPE_NMI /* Masks of interrupts for each type of interrupt: */ #define XCHAL_INTTYPE_MASK_UNCONFIGURED 0xFFFF8000 #define XCHAL_INTTYPE_MASK_SOFTWARE 0x00000080 #define XCHAL_INTTYPE_MASK_EXTERN_EDGE 0x00003F00 #define XCHAL_INTTYPE_MASK_EXTERN_LEVEL 0x0000003F #define XCHAL_INTTYPE_MASK_TIMER 0x00000040 #define XCHAL_INTTYPE_MASK_NMI 0x00004000 #define XCHAL_INTTYPE_MASK_WRITE_ERROR 0x00000000 /* Interrupt numbers assigned to specific interrupt sources: */ #define XCHAL_TIMER0_INTERRUPT 6 /* CCOMPARE0 */ #define XCHAL_TIMER1_INTERRUPT XTHAL_TIMER_UNCONFIGURED #define XCHAL_TIMER2_INTERRUPT XTHAL_TIMER_UNCONFIGURED #define XCHAL_TIMER3_INTERRUPT XTHAL_TIMER_UNCONFIGURED #define XCHAL_NMI_INTERRUPT 14 /* non-maskable interrupt */ /* Interrupt numbers for levels at which only one interrupt is configured: */ #define XCHAL_INTLEVEL3_NUM 14 /* (There are many interrupts each at level(s) 1.) */ /* * External interrupt vectors/levels. * These macros describe how Xtensa processor interrupt numbers * (as numbered internally, eg. in INTERRUPT and INTENABLE registers) * map to external BInterrupt pins, for those interrupts * configured as external (level-triggered, edge-triggered, or NMI). * See the Xtensa processor databook for more details. */ /* Core interrupt numbers mapped to each EXTERNAL interrupt number: */ #define XCHAL_EXTINT0_NUM 0 /* (intlevel 1) */ #define XCHAL_EXTINT1_NUM 1 /* (intlevel 1) */ #define XCHAL_EXTINT2_NUM 2 /* (intlevel 1) */ #define XCHAL_EXTINT3_NUM 3 /* (intlevel 1) */ #define XCHAL_EXTINT4_NUM 4 /* (intlevel 1) */ #define XCHAL_EXTINT5_NUM 5 /* (intlevel 1) */ #define XCHAL_EXTINT6_NUM 8 /* (intlevel 1) */ #define XCHAL_EXTINT7_NUM 9 /* (intlevel 1) */ #define XCHAL_EXTINT8_NUM 10 /* (intlevel 1) */ #define XCHAL_EXTINT9_NUM 11 /* (intlevel 1) */ #define XCHAL_EXTINT10_NUM 12 /* (intlevel 1) */ #define XCHAL_EXTINT11_NUM 13 /* (intlevel 1) */ #define XCHAL_EXTINT12_NUM 14 /* (intlevel 3) */ /*---------------------------------------------------------------------- EXCEPTIONS and VECTORS ----------------------------------------------------------------------*/ #define XCHAL_XEA_VERSION \ 2 /* Xtensa Exception Architecture \ number: 1 == XEA1 (old) \ 2 == XEA2 (new) \ 0 == XEAX (extern) */ #define XCHAL_HAVE_XEA1 0 /* Exception Architecture 1 */ #define XCHAL_HAVE_XEA2 1 /* Exception Architecture 2 */ #define XCHAL_HAVE_XEAX 0 /* External Exception Arch. */ #define XCHAL_HAVE_EXCEPTIONS 1 /* exception option */ #define XCHAL_HAVE_MEM_ECC_PARITY 0 /* local memory ECC/parity */ #define XCHAL_HAVE_VECTOR_SELECT 1 /* relocatable vectors */ #define XCHAL_HAVE_VECBASE 1 /* relocatable vectors */ #define XCHAL_VECBASE_RESET_VADDR 0x40000000 /* VECBASE reset value */ #define XCHAL_VECBASE_RESET_PADDR 0x40000000 #define XCHAL_RESET_VECBASE_OVERLAP 0 #define XCHAL_RESET_VECTOR0_VADDR 0x50000000 #define XCHAL_RESET_VECTOR0_PADDR 0x50000000 #define XCHAL_RESET_VECTOR1_VADDR 0x40000080 #define XCHAL_RESET_VECTOR1_PADDR 0x40000080 #define XCHAL_RESET_VECTOR_VADDR 0x50000000 #define XCHAL_RESET_VECTOR_PADDR 0x50000000 #define XCHAL_USER_VECOFS 0x00000050 #define XCHAL_USER_VECTOR_VADDR 0x40000050 #define XCHAL_USER_VECTOR_PADDR 0x40000050 #define XCHAL_KERNEL_VECOFS 0x00000030 #define XCHAL_KERNEL_VECTOR_VADDR 0x40000030 #define XCHAL_KERNEL_VECTOR_PADDR 0x40000030 #define XCHAL_DOUBLEEXC_VECOFS 0x00000070 #define XCHAL_DOUBLEEXC_VECTOR_VADDR 0x40000070 #define XCHAL_DOUBLEEXC_VECTOR_PADDR 0x40000070 #define XCHAL_INTLEVEL2_VECOFS 0x00000010 #define XCHAL_INTLEVEL2_VECTOR_VADDR 0x40000010 #define XCHAL_INTLEVEL2_VECTOR_PADDR 0x40000010 #define XCHAL_DEBUG_VECOFS XCHAL_INTLEVEL2_VECOFS #define XCHAL_DEBUG_VECTOR_VADDR XCHAL_INTLEVEL2_VECTOR_VADDR #define XCHAL_DEBUG_VECTOR_PADDR XCHAL_INTLEVEL2_VECTOR_PADDR #define XCHAL_NMI_VECOFS 0x00000020 #define XCHAL_NMI_VECTOR_VADDR 0x40000020 #define XCHAL_NMI_VECTOR_PADDR 0x40000020 #define XCHAL_INTLEVEL3_VECOFS XCHAL_NMI_VECOFS #define XCHAL_INTLEVEL3_VECTOR_VADDR XCHAL_NMI_VECTOR_VADDR #define XCHAL_INTLEVEL3_VECTOR_PADDR XCHAL_NMI_VECTOR_PADDR /*---------------------------------------------------------------------- DEBUG ----------------------------------------------------------------------*/ #define XCHAL_HAVE_OCD 1 /* OnChipDebug option */ #define XCHAL_NUM_IBREAK 1 /* number of IBREAKn regs */ #define XCHAL_NUM_DBREAK 1 /* number of DBREAKn regs */ #define XCHAL_HAVE_OCD_DIR_ARRAY 0 /* faster OCD option */ /*---------------------------------------------------------------------- MMU ----------------------------------------------------------------------*/ /* See core-matmap.h header file for more details. */ #define XCHAL_HAVE_TLBS 1 /* inverse of HAVE_CACHEATTR */ #define XCHAL_HAVE_SPANNING_WAY 1 /* one way maps I+D 4GB vaddr */ #define XCHAL_SPANNING_WAY 0 /* TLB spanning way number */ #define XCHAL_HAVE_IDENTITY_MAP 1 /* vaddr == paddr always */ #define XCHAL_HAVE_CACHEATTR 0 /* CACHEATTR register present */ #define XCHAL_HAVE_MIMIC_CACHEATTR 1 /* region protection */ #define XCHAL_HAVE_XLT_CACHEATTR 0 /* region prot. w/translation */ #define XCHAL_HAVE_PTP_MMU \ 0 /* full MMU (with page table \ [autorefill] and protection) \ usable for an MMU-based OS */ /* If none of the above last 4 are set, it's a custom TLB configuration. */ #define XCHAL_MMU_ASID_BITS 0 /* number of bits in ASIDs */ #define XCHAL_MMU_RINGS 1 /* number of rings (1..4) */ #define XCHAL_MMU_RING_BITS 0 /* num of bits in RING field */ #endif /* !XTENSA_HAL_NON_PRIVILEGED_ONLY */ #endif /* _XTENSA_CORE_CONFIGURATION_H */ #endif picolibc-1.8.11/libc/machine/xtensa/machine/fenv-fp.h000066400000000000000000000114571513574234600223450ustar00rootroot00000000000000/* Copyright (c) 2011 Tensilica Inc. ALL RIGHTS RESERVED. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TENSILICA INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ __declare_fenv_inline(int) feclearexcept(int except) { unsigned int fsr; except <<= _FE_EXCEPTION_FLAGS_OFFSET; __asm__ volatile("rur.fsr %0" : "=a"(fsr)); fsr = fsr & ~except; __asm__ volatile("wur.fsr %0" : : "a"(fsr)); return 0; } __declare_fenv_inline(int) fedisableexcept(int excepts) { fexcept_t current; __asm__ volatile("rur.fcr %0" : "=a"(current)); current &= ~(excepts << _FE_EXCEPTION_ENABLE_OFFSET); __asm__ volatile("wur.fcr %0" : "=a"(current)); return 0; } __declare_fenv_inline(int) feenableexcept(int excepts) { fexcept_t current; __asm__ volatile("rur.fcr %0" : "=a"(current)); current |= excepts << _FE_EXCEPTION_ENABLE_OFFSET; __asm__ volatile("wur.fcr %0" : "=a"(current)); return 0; } __declare_fenv_inline(int) fegetenv(fenv_t *env_ptr) { unsigned int fsr; unsigned int fcr; __asm__ volatile("rur.fsr %0" : "=a"(fsr)); __asm__ volatile("rur.fcr %0" : "=a"(fcr)); *env_ptr = fsr | fcr; return 0; } __declare_fenv_inline(int) fegetexcept(void) { fexcept_t current; __asm__ volatile("rur.fsr %0" : "=a"(current)); return (current >> _FE_EXCEPTION_ENABLE_OFFSET) & FE_ALL_EXCEPT; } __declare_fenv_inline(int) fegetexceptflag(fexcept_t *flagp, int excepts) { unsigned int fsr; __asm__ volatile("rur.fsr %0" : "=a"(fsr)); fsr >>= _FE_EXCEPTION_FLAGS_OFFSET; excepts &= fsr; *flagp = excepts; return 0; } __declare_fenv_inline(int) fegetround(void) { fexcept_t current; __asm__ volatile("rur.fcr %0" : "=a"(current)); return (current & _FE_ROUND_MODE_MASK) >> _FE_ROUND_MODE_OFFSET; } __declare_fenv_inline(int) feholdexcept(fenv_t *envp) { fexcept_t fsr; fenv_t fcr; /* Get the environment. */ __asm__ volatile("rur.fcr %0" : "=a"(fcr)); __asm__ volatile("rur.fsr %0" : "=a"(fsr)); *envp = fsr | fcr; /* Clear the exception enable flags. */ fcr &= _FE_ROUND_MODE_MASK; __asm__ volatile("wur.fcr %0" : : "a"(fcr)); /* Clear the exception happened flags. */ fsr = 0; __asm__ volatile("wur.fsr %0" : : "a"(fsr)); return 0; } __declare_fenv_inline(int) feraiseexcept(int excepts) { fexcept_t current; __asm__ volatile("rur.fsr %0" : "=a"(current)); current |= excepts << _FE_EXCEPTION_FLAGS_OFFSET; __asm__ volatile("wur.fsr %0" : : "a"(current)); return 0; } __declare_fenv_inline(int) fesetexcept(int excepts) { return feraiseexcept(excepts); } __declare_fenv_inline(int) fesetenv(const fenv_t *env_ptr) { __asm__ volatile("wur.fsr %0" : : "a"(*env_ptr)); __asm__ volatile("wur.fcr %0" : : "a"(*env_ptr)); return 0; } __declare_fenv_inline(int) fesetexceptflag(const fexcept_t *flagp, int excepts) { unsigned int fsr; __asm__ volatile("rur.fsr %0" : "=a"(fsr)); fsr &= ~(excepts << _FE_EXCEPTION_FLAGS_OFFSET); fsr |= ((*flagp & excepts) << _FE_EXCEPTION_FLAGS_OFFSET); __asm__ volatile("wur.fsr %0" : : "a"(fsr)); return 0; } __declare_fenv_inline(int) fesetround(int round) { if (round & ~_FE_ROUND_MODE_MASK) return 1; __asm__ volatile("wur.fcr %0" : : "a"(round)); return 0; } __declare_fenv_inline(int) fetestexcept(int excepts) { fexcept_t current; __asm__ volatile("rur.fsr %0" : "=a"(current)); return (current >> _FE_EXCEPTION_FLAGS_OFFSET) & excepts; } __declare_fenv_inline(int) feupdateenv(const fenv_t *envp) { fenv_t current; fegetenv(¤t); fesetenv(envp); return feraiseexcept(current); } picolibc-1.8.11/libc/machine/xtensa/machine/fenv.h000066400000000000000000000055501513574234600217370ustar00rootroot00000000000000/* Copyright (c) 2011 Tensilica Inc. ALL RIGHTS RESERVED. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TENSILICA INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MACHINE_FENV_H #define _MACHINE_FENV_H #include _BEGIN_STD_C typedef unsigned long fenv_t; typedef unsigned long fexcept_t; #include #if XCHAL_HAVE_FP || XCHAL_HAVE_DFP #define FE_DIVBYZERO 0x08 #define FE_INEXACT 0x01 #define FE_INVALID 0x10 #define FE_OVERFLOW 0x04 #define FE_UNDERFLOW 0x02 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) #define FE_DOWNWARD 0x3 #define FE_TONEAREST 0x0 #define FE_TOWARDZERO 0x1 #define FE_UPWARD 0x2 #define _FE_EXCEPTION_FLAGS_OFFSET 7 #define _FE_EXCEPTION_FLAG_MASK (FE_ALL_EXCEPT << _FE_EXCEPTION_FLAGS_OFFSET) #define _FE_EXCEPTION_ENABLE_OFFSET 2 #define _FE_EXCEPTION_ENABLE_MASK (FE_ALL_EXCEPT << _FE_EXCEPTION_ENABLE_OFFSET) #define _FE_ROUND_MODE_OFFSET 0 #define _FE_ROUND_MODE_MASK (0x3 << _FE_ROUND_MODE_OFFSET) #define _FE_FLOATING_ENV_MASK \ (_FE_EXCEPTION_FLAG_MASK | _FE_EXCEPTION_ENABLE_MASK | _FE_ROUND_MODE_MASK) #else #define FE_TONEAREST 0x0 #endif #if !defined(__declare_fenv_inline) && defined(__declare_extern_inline) #define __declare_fenv_inline(type) __declare_extern_inline(type) #endif #ifdef __declare_fenv_inline #if XCHAL_HAVE_FP || XCHAL_HAVE_DFP #include #else #include #endif #endif _END_STD_C #endif picolibc-1.8.11/libc/machine/xtensa/machine/meson.build000066400000000000000000000033701513574234600227700ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2021 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # inc_machine_headers_machine = [ 'core-isa.h', 'fenv.h', 'fenv-fp.h' ] if really_install install_headers(inc_machine_headers_machine, install_dir: include_dir / 'machine') endif picolibc-1.8.11/libc/machine/xtensa/memcpy.S000066400000000000000000000156711513574234600206470ustar00rootroot00000000000000/* ANSI C standard library function memcpy. Copyright (c) 2002-2008 Tensilica Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include "xtensa-asm.h" /* If the Xtensa Unaligned Load Exception option is not used, this code can run a few cycles faster by relying on the low address bits being ignored. However, if the code is then run with an Xtensa ISS client that checks for unaligned accesses, it will produce a lot of warning messages. Set this flag to disable the use of unaligned accesses and keep the ISS happy. */ /* #define UNALIGNED_ADDRESSES_CHECKED XCHAL_UNALIGNED_LOAD_EXCEPTION */ #define UNALIGNED_ADDRESSES_CHECKED 1 /* void *memcpy (void *dst, const void *src, size_t len) The algorithm is as follows: If the destination is unaligned, align it by conditionally copying 1- and/or 2-byte pieces. If the source is aligned, copy 16 bytes with a loop, and then finish up with 8, 4, 2, and 1-byte copies conditional on the length. Else (if source is unaligned), do the same, but use SRC to align the source data. This code tries to use fall-through branches for the common case of aligned source and destination and multiple of 4 (or 8) length. */ /* Byte by byte copy. */ .text .begin schedule .align XCHAL_INST_FETCH_WIDTH .literal_position __memcpy_aux: /* Skip bytes to get proper alignment for three-byte loop */ .skip XCHAL_INST_FETCH_WIDTH - 3 .Lbytecopy: #if XCHAL_HAVE_LOOPS loopnez a4, 2f #else beqz a4, 2f add a7, a3, a4 // a7 = end address for source #endif 1: l8ui a6, a3, 0 addi a3, a3, 1 #if XTENSA_ESP32_PSRAM_CACHE_FIX nop nop nop #endif s8i a6, a5, 0 addi a5, a5, 1 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif #if !XCHAL_HAVE_LOOPS bltu a3, a7, 1b #endif 2: leaf_return /* Destination is unaligned. */ .align 4 .Ldst1mod2: // dst is only byte aligned /* Do short copies byte-by-byte. */ bltui a4, 7, .Lbytecopy /* Copy 1 byte. */ l8ui a6, a3, 0 addi a3, a3, 1 addi a4, a4, -1 s8i a6, a5, 0 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif addi a5, a5, 1 /* Return to main algorithm if dst is now aligned. */ bbci.l a5, 1, .Ldstaligned .Ldst2mod4: // dst has 16-bit alignment /* Do short copies byte-by-byte. */ bltui a4, 6, .Lbytecopy /* Copy 2 bytes. */ l8ui a6, a3, 0 l8ui a7, a3, 1 addi a3, a3, 2 addi a4, a4, -2 s8i a6, a5, 0 s8i a7, a5, 1 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif addi a5, a5, 2 /* dst is now aligned; return to main algorithm. */ j .Ldstaligned .align 4 .global memcpy .type memcpy, @function memcpy: leaf_entry sp, 16 /* a2 = dst, a3 = src, a4 = len */ mov a5, a2 // copy dst so that a2 is return value bbsi.l a2, 0, .Ldst1mod2 bbsi.l a2, 1, .Ldst2mod4 .Ldstaligned: /* Get number of loop iterations with 16B per iteration. */ srli a7, a4, 4 /* Check if source is aligned. */ slli a8, a3, 30 bnez a8, .Lsrcunaligned /* Destination and source are word-aligned, use word copy. */ #if XCHAL_HAVE_LOOPS loopnez a7, 2f #else beqz a7, 2f slli a8, a7, 4 add a8, a8, a3 // a8 = end of last 16B source chunk #endif #if XTENSA_ESP32_PSRAM_CACHE_FIX 1: l32i a6, a3, 0 l32i a7, a3, 4 s32i a6, a5, 0 s32i a7, a5, 4 memw l32i a6, a3, 8 l32i a7, a3, 12 s32i a6, a5, 8 s32i a7, a5, 12 memw addi a3, a3, 16 addi a5, a5, 16 #else 1: l32i a6, a3, 0 l32i a7, a3, 4 s32i a6, a5, 0 l32i a6, a3, 8 s32i a7, a5, 4 l32i a7, a3, 12 s32i a6, a5, 8 addi a3, a3, 16 s32i a7, a5, 12 addi a5, a5, 16 #endif #if !XCHAL_HAVE_LOOPS bltu a3, a8, 1b #endif /* Copy any leftover pieces smaller than 16B. */ 2: bbci.l a4, 3, 3f /* Copy 8 bytes. */ l32i a6, a3, 0 l32i a7, a3, 4 addi a3, a3, 8 s32i a6, a5, 0 s32i a7, a5, 4 addi a5, a5, 8 3: bbsi.l a4, 2, 4f bbsi.l a4, 1, 5f bbsi.l a4, 0, 6f #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif leaf_return .align 4 /* Copy 4 bytes. */ 4: l32i a6, a3, 0 addi a3, a3, 4 s32i a6, a5, 0 addi a5, a5, 4 bbsi.l a4, 1, 5f bbsi.l a4, 0, 6f #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif leaf_return /* Copy 2 bytes. */ 5: l16ui a6, a3, 0 addi a3, a3, 2 s16i a6, a5, 0 addi a5, a5, 2 bbsi.l a4, 0, 6f #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif leaf_return /* Copy 1 byte. */ 6: l8ui a6, a3, 0 s8i a6, a5, 0 .Ldone: #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif leaf_return /* Destination is aligned; source is unaligned. */ .align 4 .Lsrcunaligned: /* Avoid loading anything for zero-length copies. */ beqz a4, .Ldone /* Copy 16 bytes per iteration for word-aligned dst and unaligned src. */ ssa8 a3 // set shift amount from byte offset #if UNALIGNED_ADDRESSES_CHECKED srli a11, a8, 30 // save unalignment offset for below sub a3, a3, a11 // align a3 #endif l32i a6, a3, 0 // load first word #if XCHAL_HAVE_LOOPS loopnez a7, 2f #else beqz a7, 2f slli a10, a7, 4 add a10, a10, a3 // a10 = end of last 16B source chunk #endif 1: l32i a7, a3, 4 l32i a8, a3, 8 src_b a6, a6, a7 s32i a6, a5, 0 l32i a9, a3, 12 src_b a7, a7, a8 s32i a7, a5, 4 l32i a6, a3, 16 src_b a8, a8, a9 s32i a8, a5, 8 addi a3, a3, 16 src_b a9, a9, a6 s32i a9, a5, 12 addi a5, a5, 16 #if !XCHAL_HAVE_LOOPS bltu a3, a10, 1b #endif 2: bbci.l a4, 3, 3f /* Copy 8 bytes. */ l32i a7, a3, 4 l32i a8, a3, 8 src_b a6, a6, a7 s32i a6, a5, 0 addi a3, a3, 8 src_b a7, a7, a8 s32i a7, a5, 4 addi a5, a5, 8 mov a6, a8 3: bbci.l a4, 2, 4f /* Copy 4 bytes. */ l32i a7, a3, 4 addi a3, a3, 4 src_b a6, a6, a7 s32i a6, a5, 0 addi a5, a5, 4 mov a6, a7 4: #if UNALIGNED_ADDRESSES_CHECKED add a3, a3, a11 // readjust a3 with correct misalignment #endif bbsi.l a4, 1, 5f bbsi.l a4, 0, 6f leaf_return /* Copy 2 bytes. */ 5: l8ui a6, a3, 0 l8ui a7, a3, 1 addi a3, a3, 2 s8i a6, a5, 0 s8i a7, a5, 1 addi a5, a5, 2 bbsi.l a4, 0, 6f #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif leaf_return /* Copy 1 byte. */ 6: l8ui a6, a3, 0 s8i a6, a5, 0 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif leaf_return .end schedule .size memcpy, . - memcpy picolibc-1.8.11/libc/machine/xtensa/memset.S000066400000000000000000000103701513574234600206360ustar00rootroot00000000000000/* ANSI C standard library function memset. Copyright (c) 2001-2008 Tensilica Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include "xtensa-asm.h" /* void *memset (void *dst, int c, size_t length) The algorithm is as follows: Create a word with c in all byte positions. If the destination is aligned, set 16B chunks with a loop, and then finish up with 8B, 4B, 2B, and 1B stores conditional on the length. If the destination is unaligned, align it by conditionally setting 1B and/or 2B and then go to aligned case. This code tries to use fall-through branches for the common case of an aligned destination (except for the branches to the alignment labels). */ /* Byte-by-byte set. */ .text .begin schedule .align XCHAL_INST_FETCH_WIDTH .literal_position __memset_aux: /* Skip bytes to get proper alignment for three-byte loop */ .skip XCHAL_INST_FETCH_WIDTH - 3 .Lbyteset: #if XCHAL_HAVE_LOOPS loopnez a4, 2f #else beqz a4, 2f add a6, a5, a4 // a6 = ending address #endif 1: s8i a3, a5, 0 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif addi a5, a5, 1 #if !XCHAL_HAVE_LOOPS bltu a5, a6, 1b #endif 2: leaf_return /* Destination is unaligned. */ .align 4 .Ldst1mod2: // dst is only byte aligned /* Do short sizes byte-by-byte. */ bltui a4, 8, .Lbyteset /* Set 1 byte. */ s8i a3, a5, 0 addi a5, a5, 1 addi a4, a4, -1 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif /* Now retest if dst is aligned. */ _bbci.l a5, 1, .Ldstaligned .Ldst2mod4: // dst has 16-bit alignment /* Do short sizes byte-by-byte. */ bltui a4, 8, .Lbyteset /* Set 2 bytes. */ s16i a3, a5, 0 addi a5, a5, 2 addi a4, a4, -2 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif /* dst is now aligned; return to main algorithm */ j .Ldstaligned .align 4 .global memset .type memset, @function memset: leaf_entry sp, 16 /* a2 = dst, a3 = c, a4 = length */ /* Duplicate character into all bytes of word. */ extui a3, a3, 0, 8 slli a7, a3, 8 or a3, a3, a7 slli a7, a3, 16 or a3, a3, a7 mov a5, a2 // copy dst so that a2 is return value /* Check if dst is unaligned. */ _bbsi.l a2, 0, .Ldst1mod2 _bbsi.l a2, 1, .Ldst2mod4 .Ldstaligned: /* Get number of loop iterations with 16B per iteration. */ srli a7, a4, 4 #if XTENSA_ESP32_PSRAM_CACHE_FIX //do not do this if we have less than one iteration to do beqz a7, 2f //this seems to work to prefetch the cache line s32i a3, a5, 0 nop #endif /* Destination is word-aligned. */ #if XCHAL_HAVE_LOOPS loopnez a7, 2f #else beqz a7, 2f slli a6, a7, 4 add a6, a6, a5 // a6 = end of last 16B chunk #endif /* Set 16 bytes per iteration. */ 1: s32i a3, a5, 0 s32i a3, a5, 4 s32i a3, a5, 8 s32i a3, a5, 12 addi a5, a5, 16 #if !XCHAL_HAVE_LOOPS bltu a5, a6, 1b #endif /* Set any leftover pieces smaller than 16B. */ 2: bbci.l a4, 3, 3f /* Set 8 bytes. */ s32i a3, a5, 0 s32i a3, a5, 4 addi a5, a5, 8 3: bbci.l a4, 2, 4f /* Set 4 bytes. */ s32i a3, a5, 0 addi a5, a5, 4 4: bbci.l a4, 1, 5f /* Set 2 bytes. */ s16i a3, a5, 0 addi a5, a5, 2 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif 5: bbci.l a4, 0, 6f /* Set 1 byte. */ s8i a3, a5, 0 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif 6: leaf_return .end schedule .size memset, . - memset picolibc-1.8.11/libc/machine/xtensa/meson.build000066400000000000000000000045641513574234600213720ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Jonathan McDowell # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_machine = [ 'memcpy.S', 'memset.S', 'setjmp.S', 'strcmp.S', 'strcpy.S', 'strlen.S', 'strncpy.S', 'tls.c', ] conf_data.set('_XTENSA_HAVE_CONFIG_CORE_ISA_H', cc.check_header('xtensa/config/core-isa.h', args: '-D_LIBC'), description: 'Xtensa toolchain includes core-isa.h') subdir('machine') foreach params : targets target = params['name'] target_c_args = params['c_args'] _target_args_str = ' '.join(target_c_args) if _target_args_str.contains('mfix-esp32-psram-cache-issue') _esp32_psram_fix_arg = ['-DXTENSA_ESP32_PSRAM_CACHE_FIX=1'] else _esp32_psram_fix_arg = [] endif set_variable('lib_machine' + target, static_library('machine' + target, srcs_machine, include_directories: inc, c_args: target_c_args + c_args + _esp32_psram_fix_arg)) endforeach picolibc-1.8.11/libc/machine/xtensa/setjmp.S000066400000000000000000000154001513574234600206450ustar00rootroot00000000000000/* setjmp/longjmp functions for Xtensa. Copyright (c) 2001-2006 by Tensilica Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* Windowed ABI: This implementation relies heavily on the Xtensa register window mechanism. Setjmp flushes all the windows except its own to the stack and then copies registers from the save areas on the stack into the jmp_buf structure, along with the return address of the call to setjmp. Longjmp invalidates all the windows except its own, and then sets things up so that it will return to the right place, using a window underflow to automatically restore the registers. Note that it would probably be sufficient to only copy the registers from setjmp's caller into jmp_buf. However, we also copy the save area located at the stack pointer of setjmp's caller. This save area will typically remain intact until the longjmp call. The one exception is when there is an intervening alloca in setjmp's caller. This is certainly an unusual situation and is likely to cause problems in any case (the storage allocated on the stack cannot be safely accessed following the longjmp). As bad as it is, on most systems this situation would not necessarily lead to a catastrophic failure. If we did not preserve the extra save area on Xtensa, however, it would. When setjmp's caller returns after a longjmp, there will be a window underflow; an invalid return address or stack pointer in the save area will almost certainly lead to a crash. Keeping a copy of the extra save area in the jmp_buf avoids this with only a small additional cost. If setjmp and longjmp are ever time-critical, this could be removed. Call0 ABI: Much like other ABIs, this version just saves the necessary registers to the stack and restores them later. Much less needs to be done. */ #include #include "xtensa-asm.h" #define SYS_nop 0 #if XCHAL_HAVE_WINDOWED && !__XTENSA_CALL0_ABI__ /* int setjmp (jmp_buf env) */ .text .align 4 .literal_position .global setjmp .type setjmp, @function setjmp: entry sp, 16 call4 __xtensa_libgcc_window_spill /* Copy the register save area at (sp - 16). */ addi a5, a1, -16 l32i a3, a5, 0 l32i a4, a5, 4 s32i a3, a2, 0 s32i a4, a2, 4 l32i a3, a5, 8 l32i a4, a5, 12 s32i a3, a2, 8 s32i a4, a2, 12 /* Copy 0-8 words from the register overflow area. */ extui a3, a0, 30, 2 blti a3, 2, .Lendsj l32i a7, a1, 4 slli a4, a3, 4 sub a5, a7, a4 addi a6, a2, 16 addi a7, a7, -16 // a7 = end of register overflow area .Lsjloop: l32i a3, a5, 0 l32i a4, a5, 4 s32i a3, a6, 0 s32i a4, a6, 4 l32i a3, a5, 8 l32i a4, a5, 12 s32i a3, a6, 8 s32i a4, a6, 12 addi a5, a5, 16 addi a6, a6, 16 blt a5, a7, .Lsjloop .Lendsj: /* Copy the register save area at sp. */ l32i a3, a1, 0 l32i a4, a1, 4 s32i a3, a2, 48 s32i a4, a2, 52 l32i a3, a1, 8 l32i a4, a1, 12 s32i a3, a2, 56 s32i a4, a2, 60 /* Save the return address, including the window size bits. */ s32i a0, a2, 64 movi a2, 0 retw .size setjmp, . - setjmp /* void longjmp (jmp_buf env, int val) */ .align 4 .literal_position .global longjmp .type longjmp, @function longjmp: entry sp, 16 /* a2 == &env, a3 == val */ #if XCHAL_MAYHAVE_ERRATUM_XEA1KWIN /* Using this register triggers early any overflow that a kernel-mode level-one interrupt might otherwise cause. */ # define AR_WB a15 #else /* Using this register is more efficient; it triggers less overflows. */ # define AR_WB a5 #endif /* Invalidate all but the current window; set WindowStart to (1 << WindowBase). */ rsr AR_WB, WINDOWBASE movi a4, 1 ssl AR_WB sll a4, a4 wsr a4, WINDOWSTART rsync /* Return to the return address of the setjmp, using the window size bits from the setjmp call so that the caller will be able to find the return value that we put in a2. */ l32i a0, a2, 64 /* Copy the first 4 saved registers from jmp_buf into the save area at the current sp so that the values will be restored to registers when longjmp returns. */ addi a7, a1, -16 l32i a4, a2, 0 l32i a5, a2, 4 s32i a4, a7, 0 s32i a5, a7, 4 l32i a4, a2, 8 l32i a5, a2, 12 s32i a4, a7, 8 s32i a5, a7, 12 /* Copy the remaining 0-8 saved registers. */ extui a7, a0, 30, 2 blti a7, 2, .Lendlj l32i a8, a2, 52 slli a4, a7, 4 sub a6, a8, a4 addi a5, a2, 16 addi a8, a8, -16 // a8 = end of register overflow area .Lljloop: l32i a7, a5, 0 l32i a4, a5, 4 s32i a7, a6, 0 s32i a4, a6, 4 l32i a7, a5, 8 l32i a4, a5, 12 s32i a7, a6, 8 s32i a4, a6, 12 addi a5, a5, 16 addi a6, a6, 16 blt a6, a8, .Lljloop .Lendlj: /* The 4 words saved from the register save area at the target's sp are copied back to the target procedure's save area. The only point of this is to prevent a catastrophic failure in case the contents were moved by an alloca after calling setjmp. This is a bit paranoid but it doesn't cost much. */ l32i a7, a2, 4 // load the target stack pointer addi a7, a7, -16 // find the destination save area l32i a4, a2, 48 l32i a5, a2, 52 s32i a4, a7, 0 s32i a5, a7, 4 l32i a4, a2, 56 l32i a5, a2, 60 s32i a4, a7, 8 s32i a5, a7, 12 /* Return val ? val : 1. */ movi a2, 1 movnez a2, a3, a3 retw .size longjmp, . - longjmp #else /* CALL0 ABI */ .text .align 4 .literal_position .global setjmp .type setjmp, @function setjmp: s32i a0, a2, 0 s32i a1, a2, 4 s32i a12, a2, 8 s32i a13, a2, 12 s32i a14, a2, 16 s32i a15, a2, 20 movi a2, 0 ret .size setjmp, . - setjmp .align 4 .literal_position .global longjmp .type longjmp, @function longjmp: l32i a0, a2, 0 l32i a12, a2, 8 l32i a13, a2, 12 l32i a14, a2, 16 l32i a15, a2, 20 l32i a1, a2, 4 /* Return val ? val : 1. */ movi a2, 1 movnez a2, a3, a3 ret .size longjmp, .-longjmp #endif /* CALL0 ABI */ picolibc-1.8.11/libc/machine/xtensa/strcmp.S000066400000000000000000000232021513574234600206520ustar00rootroot00000000000000/* ANSI C standard library function strcmp. Copyright (c) 2001-20012 Tensilica Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include "xtensa-asm.h" #define MASK4 0x40404040 #if XCHAL_HAVE_L32R .literal .Lmask0, MASK0 .literal .Lmask1, MASK1 .literal .Lmask2, MASK2 .literal .Lmask3, MASK3 .literal .Lmask4, MASK4 #endif /* XCHAL_HAVE_L32R */ .text .align 4 .literal_position .global strcmp .type strcmp, @function strcmp: leaf_entry sp, 16 /* a2 = s1, a3 = s2 */ l8ui a8, a2, 0 // byte 0 from s1 l8ui a9, a3, 0 // byte 0 from s2 movi a10, 3 // mask bne a8, a9, .Lretdiff or a11, a2, a3 bnone a11, a10, .Laligned xor a11, a2, a3 // compare low two bits of s1 and s2 bany a11, a10, .Lunaligned // if they have different alignment /* s1/s2 are not word-aligned. */ addi a2, a2, 1 // advance s1 beqz a8, .Leq // bytes equal, if zero, strings are equal addi a3, a3, 1 // advance s2 bnone a2, a10, .Laligned // if s1/s2 now aligned l8ui a8, a2, 0 // byte 1 from s1 l8ui a9, a3, 0 // byte 1 from s2 addi a2, a2, 1 // advance s1 bne a8, a9, .Lretdiff // if different, return difference beqz a8, .Leq // bytes equal, if zero, strings are equal addi a3, a3, 1 // advance s2 bnone a2, a10, .Laligned // if s1/s2 now aligned l8ui a8, a2, 0 // byte 2 from s1 l8ui a9, a3, 0 // byte 2 from s2 addi a2, a2, 1 // advance s1 bne a8, a9, .Lretdiff // if different, return difference beqz a8, .Leq // bytes equal, if zero, strings are equal addi a3, a3, 1 // advance s2 j .Laligned /* s1 and s2 have different alignment. If the zero-overhead loop option is available, use an (almost) infinite zero-overhead loop with conditional exits so we only pay for taken branches when exiting the loop. Note: It is important for this unaligned case to come before the code for aligned strings, because otherwise some of the branches above cannot reach and have to be transformed to branches around jumps. The unaligned code is smaller and the branches can reach over it. */ .align 4 #if XCHAL_HAVE_LOOPS #if XCHAL_HAVE_DENSITY /* (2 mod 4) alignment for loop instruction */ #else /* (1 mod 4) alignment for loop instruction */ .byte 0 .byte 0 #endif #endif .Lunaligned: #if XCHAL_HAVE_LOOPS #if XCHAL_HAVE_DENSITY _movi.n a8, 0 // set up for the maximum loop count #else _movi a8, 0 // set up for the maximum loop count #endif loop a8, .Lretdiff // loop forever (almost anyway) #endif .Lnextbyte: l8ui a8, a2, 0 l8ui a9, a3, 0 addi a2, a2, 1 bne a8, a9, .Lretdiff addi a3, a3, 1 #if XCHAL_HAVE_LOOPS beqz a8, .Lretdiff #else bnez a8, .Lnextbyte #endif .Lretdiff: sub a2, a8, a9 leaf_return /* s1 is word-aligned; s2 is word-aligned. If the zero-overhead loop option is available, use an (almost) infinite zero-overhead loop with conditional exits so we only pay for taken branches when exiting the loop. */ /* New algorithm, relying on the fact that all normal ASCII is between 32 and 127. Rather than check all bytes for zero: Take one word (4 bytes). Call it w1. Shift w1 left by one into w1'. Or w1 and w1'. For all normal ASCII bit 6 will be 1; for zero it won't. Check that all 4 bit 6's (one for each byte) are one: If they are, we are definitely not done. If they are not, we are probably done, but need to check for zero. */ .align 4 #if XCHAL_HAVE_LOOPS #if !XCHAL_HAVE_L32R /* (2 mod 4) alignment for loop instruction */ .byte 0 .byte 0 #endif .Laligned: #if XCHAL_HAVE_L32R l32r a4, .Lmask0 // mask for byte 0 l32r a7, .Lmask4 #else const16 a4, MASK0@h const16 a4, MASK0@l const16 a7, MASK4@h const16 a7, MASK4@l #endif /* Loop forever */ 1: loop a0, .Laligned_done /* First unrolled loop body. */ l32i a8, a2, 0 // get word from s1 l32i a9, a3, 0 // get word from s2 slli a5, a8, 1 bne a8, a9, .Lwne2 or a9, a8, a5 bnall a9, a7, .Lprobeq /* Second unrolled loop body. */ l32i a8, a2, 4 // get word from s1+4 l32i a9, a3, 4 // get word from s2+4 slli a5, a8, 1 bne a8, a9, .Lwne2 or a9, a8, a5 bnall a9, a7, .Lprobeq2 addi a2, a2, 8 // advance s1 pointer addi a3, a3, 8 // advance s2 pointer .Laligned_done: j 1b .Lprobeq2: /* Adjust pointers to account for the loop unrolling. */ addi a2, a2, 4 addi a3, a3, 4 #else /* !XCHAL_HAVE_LOOPS */ .Laligned: movi a4, MASK0 // mask for byte 0 movi a7, MASK4 j .Lfirstword .Lnextword: addi a2, a2, 4 // advance s1 pointer addi a3, a3, 4 // advance s2 pointer .Lfirstword: l32i a8, a2, 0 // get word from s1 l32i a9, a3, 0 // get word from s2 slli a5, a8, 1 bne a8, a9, .Lwne2 or a9, a8, a5 ball a9, a7, .Lnextword #endif /* !XCHAL_HAVE_LOOPS */ /* align (0 mod 4) */ .Lprobeq: /* Words are probably equal, but check for sure. If not, loop over the rest of string using normal algorithm. */ bnone a8, a4, .Leq // if byte 0 is zero #if XCHAL_HAVE_L32R l32r a5, .Lmask1 // mask for byte 1 l32r a6, .Lmask2 // mask for byte 2 bnone a8, a5, .Leq // if byte 1 is zero l32r a7, .Lmask3 // mask for byte 3 bnone a8, a6, .Leq // if byte 2 is zero bnone a8, a7, .Leq // if byte 3 is zero /* align (1 mod 4) */ #else const16 a5, MASK1@h // mask for byte 1 const16 a5, MASK1@l bnone a8, a5, .Leq // if byte 1 is zero const16 a6, MASK2@h // mask for byte 2 const16 a6, MASK2@l bnone a8, a6, .Leq // if byte 2 is zero const16 a7, MASK3@h // mask for byte 3 const16 a7, MASK3@l bnone a8, a7, .Leq // if byte 3 is zero /* align (2 mod 4) */ #endif /* XCHAL_HAVE_L32R */ #if XCHAL_HAVE_DENSITY addi.n a2, a2, 4 // advance s1 pointer addi.n a3, a3, 4 // advance s2 pointer /* align (1 mod 4) or (2 mod 4) */ #else addi a2, a2, 4 // advance s1 pointer addi a3, a3, 4 // advance s2 pointer or a1, a1, a1 // nop #if !XCHAL_HAVE_L32R or a1, a1, a1 // nop #endif /* align (2 mod 4) */ #endif /* XCHAL_HAVE_DENSITY */ #if XCHAL_HAVE_LOOPS 1: loop a0, .Leq // loop forever (a4 is bigger than max iters) l32i a8, a2, 0 // get word from s1 l32i a9, a3, 0 // get word from s2 addi a2, a2, 4 // advance s1 pointer bne a8, a9, .Lwne bnone a8, a4, .Leq // if byte 0 is zero bnone a8, a5, .Leq // if byte 1 is zero bnone a8, a6, .Leq // if byte 2 is zero bnone a8, a7, .Leq // if byte 3 is zero addi a3, a3, 4 // advance s2 pointer j 1b #else /* !XCHAL_HAVE_LOOPS */ j .Lfirstword2 .Lnextword2: addi a3, a3, 4 // advance s2 pointer .Lfirstword2: l32i a8, a2, 0 // get word from s1 l32i a9, a3, 0 // get word from s2 addi a2, a2, 4 // advance s1 pointer bne a8, a9, .Lwne bnone a8, a4, .Leq // if byte 0 is zero bnone a8, a5, .Leq // if byte 1 is zero bnone a8, a6, .Leq // if byte 2 is zero bany a8, a7, .Lnextword2 // if byte 3 is zero #endif /* !XCHAL_HAVE_LOOPS */ /* Words are equal; some byte is zero. */ .Leq: movi a2, 0 // return equal leaf_return .Lwne2: /* Words are not equal. On big-endian processors, if none of the bytes are zero, the return value can be determined by a simple comparison. */ #ifdef __XTENSA_EB__ or a10, a8, a5 bnall a10, a7, .Lsomezero bgeu a8, a9, .Lposreturn movi a2, -1 leaf_return .Lposreturn: movi a2, 1 leaf_return .Lsomezero: // There is probably some zero byte. #endif /* __XTENSA_EB__ */ .Lwne: /* Words are not equal. */ xor a2, a8, a9 // get word with nonzero in byte that differs bany a2, a4, .Ldiff0 // if byte 0 differs movi a5, MASK1 // mask for byte 1 bnone a8, a4, .Leq // if byte 0 is zero bany a2, a5, .Ldiff1 // if byte 1 differs movi a6, MASK2 // mask for byte 2 bnone a8, a5, .Leq // if byte 1 is zero bany a2, a6, .Ldiff2 // if byte 2 differs bnone a8, a6, .Leq // if byte 2 is zero #ifdef __XTENSA_EB__ .Ldiff3: .Ldiff2: .Ldiff1: /* Byte 0 is equal (at least) and there is a difference before a zero byte. Just subtract words to get the return value. The high order equal bytes cancel, leaving room for the sign. */ sub a2, a8, a9 leaf_return .Ldiff0: /* Need to make room for the sign, so can't subtract whole words. */ extui a10, a8, 24, 8 extui a11, a9, 24, 8 sub a2, a10, a11 leaf_return #else /* !__XTENSA_EB__ */ /* Little-endian is a little more difficult because can't subtract whole words. */ .Ldiff3: /* Bytes 0-2 are equal; byte 3 is different. For little-endian need to have a sign bit for the difference. */ extui a10, a8, 24, 8 extui a11, a9, 24, 8 sub a2, a10, a11 leaf_return .Ldiff0: /* Byte 0 is different. */ extui a10, a8, 0, 8 extui a11, a9, 0, 8 sub a2, a10, a11 leaf_return .Ldiff1: /* Byte 0 is equal; byte 1 is different. */ extui a10, a8, 8, 8 extui a11, a9, 8, 8 sub a2, a10, a11 leaf_return .Ldiff2: /* Bytes 0-1 are equal; byte 2 is different. */ extui a10, a8, 16, 8 extui a11, a9, 16, 8 sub a2, a10, a11 leaf_return #endif /* !__XTENSA_EB */ .size strcmp, . - strcmp picolibc-1.8.11/libc/machine/xtensa/strcpy.S000066400000000000000000000150271513574234600206740ustar00rootroot00000000000000/* ANSI C standard library function strcpy. Copyright (c) 2001-2008 Tensilica Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include "xtensa-asm.h" .text .begin schedule .align 4 .literal_position .global strcpy .type strcpy, @function strcpy: leaf_entry sp, 16 /* a2 = dst, a3 = src */ mov a10, a2 // leave dst in return value register movi a4, MASK0 movi a5, MASK1 movi a6, MASK2 movi a7, MASK3 bbsi.l a3, 0, .Lsrc1mod2 bbsi.l a3, 1, .Lsrc2mod4 .Lsrcaligned: /* Check if the destination is aligned. */ movi a8, 3 bnone a10, a8, .Laligned j .Ldstunaligned .Lsrc1mod2: // src address is odd l8ui a8, a3, 0 // get byte 0 addi a3, a3, 1 // advance src pointer s8i a8, a10, 0 // store byte 0 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif beqz a8, 1f // if byte 0 is zero addi a10, a10, 1 // advance dst pointer bbci.l a3, 1, .Lsrcaligned // if src is now word-aligned .Lsrc2mod4: // src address is 2 mod 4 l8ui a8, a3, 0 // get byte 0 /* 1-cycle interlock */ s8i a8, a10, 0 // store byte 0 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif beqz a8, 1f // if byte 0 is zero l8ui a8, a3, 1 // get byte 0 addi a3, a3, 2 // advance src pointer s8i a8, a10, 1 // store byte 0 addi a10, a10, 2 // advance dst pointer #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif bnez a8, .Lsrcaligned 1: leaf_return /* dst is word-aligned; src is word-aligned. */ .align 4 #if XCHAL_HAVE_LOOPS #if XCHAL_HAVE_DENSITY /* (2 mod 4) alignment for loop instruction */ #else /* (1 mod 4) alignment for loop instruction */ .byte 0 .byte 0 #endif .Laligned: #if XCHAL_HAVE_DENSITY _movi.n a8, 0 // set up for the maximum loop count #else _movi a8, 0 // set up for the maximum loop count #endif loop a8, .Lz3 // loop forever (almost anyway) l32i a8, a3, 0 // get word from src addi a3, a3, 4 // advance src pointer bnone a8, a4, .Lz0 // if byte 0 is zero bnone a8, a5, .Lz1 // if byte 1 is zero bnone a8, a6, .Lz2 // if byte 2 is zero s32i a8, a10, 0 // store word to dst #if XTENSA_ESP32_PSRAM_CACHE_FIX l32i a8, a10, 0 s32i a8, a10, 0 #endif bnone a8, a7, .Lz3 // if byte 3 is zero addi a10, a10, 4 // advance dst pointer #else /* !XCHAL_HAVE_LOOPS */ 1: addi a10, a10, 4 // advance dst pointer .Laligned: l32i a8, a3, 0 // get word from src addi a3, a3, 4 // advance src pointer bnone a8, a4, .Lz0 // if byte 0 is zero bnone a8, a5, .Lz1 // if byte 1 is zero bnone a8, a6, .Lz2 // if byte 2 is zero s32i a8, a10, 0 // store word to dst #if XTENSA_ESP32_PSRAM_CACHE_FIX l32i a8, a10, 0 s32i a8, a10, 0 #endif bany a8, a7, 1b // if byte 3 is zero #endif /* !XCHAL_HAVE_LOOPS */ .Lz3: /* Byte 3 is zero. */ leaf_return .Lz0: /* Byte 0 is zero. */ #ifdef __XTENSA_EB__ movi a8, 0 #endif s8i a8, a10, 0 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif leaf_return .Lz1: /* Byte 1 is zero. */ #ifdef __XTENSA_EB__ extui a8, a8, 16, 16 #endif s16i a8, a10, 0 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif leaf_return .Lz2: /* Byte 2 is zero. */ #ifdef __XTENSA_EB__ extui a8, a8, 16, 16 #endif s16i a8, a10, 0 movi a8, 0 s8i a8, a10, 2 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif leaf_return #if 1 /* For now just use byte copy loop for the unaligned destination case. */ .align 4 #if XCHAL_HAVE_LOOPS #if XCHAL_HAVE_DENSITY /* (2 mod 4) alignment for loop instruction */ #else /* (1 mod 4) alignment for loop instruction */ .byte 0 .byte 0 #endif #endif .Ldstunaligned: #if XCHAL_HAVE_LOOPS #if XCHAL_HAVE_DENSITY _movi.n a8, 0 // set up for the maximum loop count #else _movi a8, 0 // set up for the maximum loop count #endif loop a8, 2f // loop forever (almost anyway) #endif 1: l8ui a8, a3, 0 addi a3, a3, 1 s8i a8, a10, 0 addi a10, a10, 1 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif #if XCHAL_HAVE_LOOPS beqz a8, 2f #else bnez a8, 1b #endif 2: leaf_return #else /* 0 */ /* This code is not functional yet. */ .Ldstunaligned: l32i a9, a2, 0 // load word from dst #ifdef __XTENSA_EB__ ssa8b a9 // rotate by dst alignment so that src a9, a9, a9 // shift in loop will put back in place ssa8l a9 // shift left by byte*8 #else ssa8l a9 // rotate by dst alignment so that src a9, a9, a9 // shift in loop will put back in place ssa8b a9 // shift left by 32-byte*8 #endif /* dst is word-aligned; src is unaligned. */ .Ldstunalignedloop: l32i a8, a3, 0 // get word from src /* 1-cycle interlock */ bnone a8, a4, .Lu0 // if byte 0 is zero bnone a8, a5, .Lu1 // if byte 1 is zero bnone a8, a6, .Lu2 // if byte 2 is zero src a9, a8, a9 // combine last word and this word s32i a9, a10, 0 // store word to dst bnone a8, a7, .Lu3 // if byte 3 is nonzero, iterate l32i a9, a3, 4 // get word from src addi a3, a3, 8 // advance src pointer bnone a9, a4, .Lu4 // if byte 0 is zero bnone a9, a5, .Lu5 // if byte 1 is zero bnone a9, a6, .Lu6 // if byte 2 is zero src a8, a9, a8 // combine last word and this word s32i a8, a10, 4 // store word to dst addi a10, a10, 8 // advance dst pointer bany a8, a7, .Ldstunalignedloop // if byte 3 is nonzero, iterate /* Byte 7 is zero. */ .Lu7: leaf_return .Lu0: /* Byte 0 is zero. */ #ifdef __XTENSA_EB__ movi a8, 0 #endif s8i a8, a10, 0 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif leaf_return .Lu1: /* Byte 1 is zero. */ #ifdef __XTENSA_EB__ extui a8, a8, 16, 16 #endif s16i a8, a10, 0 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif leaf_return .Lu2: /* Byte 2 is zero. */ s16i a8, a10, 0 movi a8, 0 s8i a8, a10, 2 #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif leaf_return #endif /* 0 */ .end schedule .size strcpy, . - strcpy picolibc-1.8.11/libc/machine/xtensa/strlen.S000066400000000000000000000064521513574234600206610ustar00rootroot00000000000000/* ANSI C standard library function strlen. Copyright (c) 2001-2008 Tensilica Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include "xtensa-asm.h" .text .begin schedule .align 4 .literal_position .global strlen .type strlen, @function strlen: leaf_entry sp, 16 /* a2 = s */ addi a3, a2, -4 // because we overincrement at the end movi a4, MASK0 movi a5, MASK1 movi a6, MASK2 movi a7, MASK3 bbsi.l a2, 0, .L1mod2 bbsi.l a2, 1, .L2mod4 j .Laligned .L1mod2: // address is odd l8ui a8, a3, 4 // get byte 0 addi a3, a3, 1 // advance string pointer beqz a8, .Lz3 // if byte 0 is zero bbci.l a3, 1, .Laligned // if string pointer is now word-aligned .L2mod4: // address is 2 mod 4 addi a3, a3, 2 // advance ptr for aligned access l32i a8, a3, 0 // get word with first two bytes of string bnone a8, a6, .Lz2 // if byte 2 (of word, not string) is zero bany a8, a7, .Laligned // if byte 3 (of word, not string) is nonzero /* Byte 3 is zero. */ addi a3, a3, 3 // point to zero byte sub a2, a3, a2 // subtract to get length leaf_return /* String is word-aligned. */ .align 4 #if XCHAL_HAVE_LOOPS #if XCHAL_HAVE_DENSITY /* (2 mod 4) alignment for loop instruction */ #else /* (1 mod 4) alignment for loop instruction */ .byte 0 .byte 0 #endif #endif .Laligned: #if XCHAL_HAVE_LOOPS #if XCHAL_HAVE_DENSITY _movi.n a8, 0 // set up for the maximum loop count #else _movi a8, 0 // set up for the maximum loop count #endif loop a8, .Lz3 // loop forever (almost anyway) #endif 1: l32i a8, a3, 4 // get next word of string addi a3, a3, 4 // advance string pointer bnone a8, a4, .Lz0 // if byte 0 is zero bnone a8, a5, .Lz1 // if byte 1 is zero bnone a8, a6, .Lz2 // if byte 2 is zero #if XCHAL_HAVE_LOOPS bnone a8, a7, .Lz3 // if byte 3 is zero #else bany a8, a7, 1b // repeat if byte 3 is non-zero #endif .Lz3: /* Byte 3 is zero. */ addi a3, a3, 3 // point to zero byte /* Fall through.... */ .Lz0: /* Byte 0 is zero. */ sub a2, a3, a2 // subtract to get length leaf_return .Lz1: /* Byte 1 is zero. */ addi a3, a3, 1 // point to zero byte sub a2, a3, a2 // subtract to get length leaf_return .Lz2: /* Byte 2 is zero. */ addi a3, a3, 2 // point to zero byte sub a2, a3, a2 // subtract to get length leaf_return .end schedule .size strlen, . - strlen picolibc-1.8.11/libc/machine/xtensa/strncpy.S000066400000000000000000000147051513574234600210540ustar00rootroot00000000000000/* ANSI C standard library function strncpy. Copyright (c) 2001-2008 Tensilica Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include "xtensa-asm.h" .text .begin schedule .align 4 .literal_position __strncpy_aux: .Lsrc1mod2: // src address is odd l8ui a8, a3, 0 // get byte 0 addi a3, a3, 1 // advance src pointer s8i a8, a10, 0 // store byte 0 addi a4, a4, -1 // decrement n beqz a4, .Lret // if n is zero addi a10, a10, 1 // advance dst pointer beqz a8, .Lfill // if byte 0 is zero bbci.l a3, 1, .Lsrcaligned // if src is now word-aligned .Lsrc2mod4: // src address is 2 mod 4 l8ui a8, a3, 0 // get byte 0 addi a4, a4, -1 // decrement n s8i a8, a10, 0 // store byte 0 beqz a4, .Lret // if n is zero addi a10, a10, 1 // advance dst pointer beqz a8, .Lfill // if byte 0 is zero l8ui a8, a3, 1 // get byte 0 addi a3, a3, 2 // advance src pointer s8i a8, a10, 0 // store byte 0 addi a4, a4, -1 // decrement n beqz a4, .Lret // if n is zero addi a10, a10, 1 // advance dst pointer bnez a8, .Lsrcaligned j .Lfill .Lret: #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif leaf_return .align 4 .global strncpy .type strncpy, @function strncpy: leaf_entry sp, 16 /* a2 = dst, a3 = src */ mov a10, a2 // leave dst in return value register beqz a4, .Lret // if n is zero movi a11, MASK0 movi a5, MASK1 movi a6, MASK2 movi a7, MASK3 bbsi.l a3, 0, .Lsrc1mod2 bbsi.l a3, 1, .Lsrc2mod4 .Lsrcaligned: /* Check if the destination is aligned. */ movi a8, 3 bnone a10, a8, .Laligned j .Ldstunaligned /* Fill the dst with zeros -- n is at least 1. */ .Lfill: movi a9, 0 bbsi.l a10, 0, .Lfill1mod2 bbsi.l a10, 1, .Lfill2mod4 .Lfillaligned: blti a4, 4, .Lfillcleanup /* Loop filling complete words with zero. */ #if XCHAL_HAVE_LOOPS srai a8, a4, 2 loop a8, 1f s32i a9, a10, 0 addi a10, a10, 4 1: slli a8, a8, 2 sub a4, a4, a8 #else /* !XCHAL_HAVE_LOOPS */ 1: s32i a9, a10, 0 addi a10, a10, 4 addi a4, a4, -4 bgei a4, 4, 1b #endif /* !XCHAL_HAVE_LOOPS */ beqz a4, 2f .Lfillcleanup: /* Fill leftover (1 to 3) bytes with zero. */ s8i a9, a10, 0 // store byte 0 addi a4, a4, -1 // decrement n addi a10, a10, 1 bnez a4, .Lfillcleanup 2: #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif leaf_return .Lfill1mod2: // dst address is odd s8i a9, a10, 0 // store byte 0 addi a4, a4, -1 // decrement n beqz a4, 2b // if n is zero addi a10, a10, 1 // advance dst pointer bbci.l a10, 1, .Lfillaligned // if dst is now word-aligned .Lfill2mod4: // dst address is 2 mod 4 s8i a9, a10, 0 // store byte 0 addi a4, a4, -1 // decrement n beqz a4, 2b // if n is zero s8i a9, a10, 1 // store byte 1 addi a4, a4, -1 // decrement n beqz a4, 2b // if n is zero addi a10, a10, 2 // advance dst pointer j .Lfillaligned /* dst is word-aligned; src is word-aligned; n is at least 1. */ .align 4 #if XCHAL_HAVE_LOOPS #if XCHAL_HAVE_DENSITY /* (2 mod 4) alignment for loop instruction */ #else /* (1 mod 4) alignment for loop instruction */ .byte 0 .byte 0 #endif #endif .Laligned: #if XCHAL_HAVE_LOOPS #if XCHAL_HAVE_DENSITY _movi.n a8, 0 // set up for the maximum loop count #else _movi a8, 0 // set up for the maximum loop count #endif loop a8, 1f // loop forever (almost anyway) blti a4, 5, .Ldstunaligned // n is near limit; do one at a time l32i a8, a3, 0 // get word from src addi a3, a3, 4 // advance src pointer bnone a8, a11, .Lz0 // if byte 0 is zero bnone a8, a5, .Lz1 // if byte 1 is zero bnone a8, a6, .Lz2 // if byte 2 is zero s32i a8, a10, 0 // store word to dst addi a4, a4, -4 // decrement n addi a10, a10, 4 // advance dst pointer bnone a8, a7, .Lfill // if byte 3 is zero 1: #else /* !XCHAL_HAVE_LOOPS */ 1: blti a4, 5, .Ldstunaligned // n is near limit; do one at a time l32i a8, a3, 0 // get word from src addi a3, a3, 4 // advance src pointer bnone a8, a11, .Lz0 // if byte 0 is zero bnone a8, a5, .Lz1 // if byte 1 is zero bnone a8, a6, .Lz2 // if byte 2 is zero s32i a8, a10, 0 // store word to dst addi a4, a4, -4 // decrement n addi a10, a10, 4 // advance dst pointer bany a8, a7, 1b // no zeroes #endif /* !XCHAL_HAVE_LOOPS */ j .Lfill .Lz0: /* Byte 0 is zero. */ #ifdef __XTENSA_EB__ movi a8, 0 #endif s8i a8, a10, 0 addi a4, a4, -1 // decrement n addi a10, a10, 1 // advance dst pointer j .Lfill .Lz1: /* Byte 1 is zero. */ #ifdef __XTENSA_EB__ extui a8, a8, 16, 16 #endif s16i a8, a10, 0 addi a4, a4, -2 // decrement n addi a10, a10, 2 // advance dst pointer j .Lfill .Lz2: /* Byte 2 is zero. */ #ifdef __XTENSA_EB__ extui a8, a8, 16, 16 #endif s16i a8, a10, 0 movi a8, 0 s8i a8, a10, 2 addi a4, a4, -3 // decrement n addi a10, a10, 3 // advance dst pointer j .Lfill .align 4 #if XCHAL_HAVE_LOOPS #if XCHAL_HAVE_DENSITY /* (2 mod 4) alignment for loop instruction */ #else /* (1 mod 4) alignment for loop instruction */ .byte 0 .byte 0 #endif #endif .Ldstunaligned: #if XCHAL_HAVE_LOOPS #if XCHAL_HAVE_DENSITY _movi.n a8, 0 // set up for the maximum loop count #else _movi a8, 0 // set up for the maximum loop count #endif loop a8, 2f // loop forever (almost anyway) #endif 1: l8ui a8, a3, 0 addi a3, a3, 1 #if XTENSA_ESP32_PSRAM_CACHE_FIX nop nop nop #endif s8i a8, a10, 0 addi a4, a4, -1 beqz a4, 3f addi a10, a10, 1 #if XCHAL_HAVE_LOOPS beqz a8, 2f #else bnez a8, 1b #endif 2: j .Lfill 3: #if XTENSA_ESP32_PSRAM_CACHE_FIX memw #endif leaf_return .end schedule .size strncpy, . - strncpy picolibc-1.8.11/libc/machine/xtensa/tls.c000066400000000000000000000036731513574234600201760ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #ifdef __THREAD_LOCAL_STORAGE_API #define _REG(n) #n #define REG(n) _REG(n) extern char __arm32_tls_tcb_offset; #define TP_OFFSET ((size_t)&__arm32_tls_tcb_offset) void _set_tls(void *tls) { uintptr_t u = (uintptr_t)tls - TP_OFFSET; __asm__("wur %0," REG(THREADPTR) : : "r"(u)); } #endif picolibc-1.8.11/libc/machine/xtensa/xtensa-asm.h000066400000000000000000000040431513574234600214510ustar00rootroot00000000000000/* Copyright (c) 2006 Tensilica Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* Define macros for leaf function entry and return, supporting either the * standard register windowed ABI or the non-windowed call0 ABI. These * macros do not allocate any extra stack space, so they only work for * leaf functions that do not need to spill anything to the stack. */ #include .macro leaf_entry reg, size #if XCHAL_HAVE_WINDOWED && !__XTENSA_CALL0_ABI__ entry \reg, \size #else /* do nothing */ #endif .endm .macro leaf_return #if XCHAL_HAVE_WINDOWED && !__XTENSA_CALL0_ABI__ retw #else ret #endif .endm .macro src_b r, w0, w1 #ifdef __XTENSA_EB__ src \r, \w0, \w1 #else src \r, \w1, \w0 #endif .endm .macro ssa8 r #ifdef __XTENSA_EB__ ssa8b \r #else ssa8l \r #endif .endm #if XCHAL_HAVE_BE #define MASK0 0xff000000 #define MASK1 0x00ff0000 #define MASK2 0x0000ff00 #define MASK3 0x000000ff #else #define MASK0 0x000000ff #define MASK1 0x0000ff00 #define MASK2 0x00ff0000 #define MASK3 0xff000000 #endif picolibc-1.8.11/libc/machine/xtensa/xtensa.tex000066400000000000000000000037021513574234600212450ustar00rootroot00000000000000@node Xtensa @chapter Functions for Xtensa Processors This chapter describes machine-dependent functions that are included in the C library when it is built for Xtensa processors. @menu * Function setjmp:: Save stack environment * Function longjmp:: Non-local goto @end menu @page @node Function setjmp @section @code{setjmp}---save stack environment @findex setjmp @strong{Synopsis} @example #include int setjmp(jmp_buf env); @end example @strong{Description}@* @code{setjmp} and @code{longjmp} are useful for dealing with errors and interrupts encountered in a low-level subroutine of a program. @code{setjmp} saves the stack context/environment in @code{env} for later use by @code{longjmp}. The stack context will be invalidated if the function which called @code{setjmp} returns. @* @strong{Returns}@* @code{setjmp} returns 0 if returning directly, and non-zero when returning from @code{longjmp} using the saved context. @* @strong{Portability}@* @code{setjmp} is ANSI C and POSIX.1. setjmp requires no supporting OS subroutines. @* @page @node Function longjmp @section @code{longjmp}---non-local goto @findex longjmp @strong{Synopsis} @example #include void longjmp(jmp_buf env, int val); @end example @strong{Description}@* @code{longjmp} and @code{setjmp} are useful for dealing with errors and interrupts encountered in a low-level subroutine of a program. @code{longjmp} restores the environment saved by the last call of @code{setjmp} with the corresponding @code{env} argument. After @code{longjmp} is completed, program execution continues as if the corresponding call of @code{setjmp} had just returned the value @code{val}. @code{longjmp} cannot cause 0 to be returned. If @code{longjmp} is invoked with a second argument of 0, 1 will be returned instead. @* @strong{Returns}@* This function never returns. @* @strong{Portability}@* @code{longjmp} is ANSI C and POSIX.1. longjmp requires no supporting OS subroutines. @* picolibc-1.8.11/libc/machine/z8k/000077500000000000000000000000001513574234600164315ustar00rootroot00000000000000picolibc-1.8.11/libc/machine/z8k/args.h000066400000000000000000000016061513574234600175410ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifdef __Z8001__ segm #define PARG_0 rr6 #else unsegm #define PARG_0 r7 #endif #define LARG_0 rr6 #define ARG_0 r7 #define LARG_1 rr4 picolibc-1.8.11/libc/machine/z8k/memcmp.S000066400000000000000000000055661513574234600200470ustar00rootroot00000000000000/* * memcmp routine for Z8000 * Copyright (C) 2004 Christian Groessler * * Permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies. * * This file is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /* int memcmp(const void *b1, const void *b2, size_t length); */ #include name "memcmp.S" .text even global _memcmp _memcmp: #ifdef __Z8001__ segm #ifdef __STD_CALL__ ldl rr6,rr14(#4) ldl rr4,rr14(#8) ldl rr2,rr14(#12) #endif /* rr2 - length (high word ignored) * rr4 - b2 * rr6 - b1 */ clr r1 /* initialize return value */ testl rr2 jr z,finish bitb rl7,#0 /* odd b1? */ jr nz,testb2 bitb rl5,#0 /* odd b2? */ jr nz,odd_cmp /* b1 even, b2 odd */ jr t,even_cmp testb2: bitb rl5,#0 jr z,odd_cmp /* b2 even, b1 odd */ cpsib @rr6,@rr4,r3,eq jr z,beq /* bytes are the same */ jr t,byte_diff beq: jr ov,finish /* jump if r3 is zero now */ /* compare words */ even_cmp: ld r2,r3 /* remember length */ srl r3,#1 jr z,no_words cpsir @rr6,@rr4,r3,ne jr nz,no_words dec r7,#2 dec r5,#2 /* point to different bytes */ ldk r3,#2 jr t,odd_cmp no_words: bitb rl2,#0 /* odd length? */ jr z,finish cpsib @rr6,@rr4,r3,eq jr z,finish /* last bytes are the same */ jr t,byte_diff /* compare bytes */ odd_cmp: cpsirb @rr6,@rr4,r3,ne jr nz,finish byte_diff: dec r7,#1 dec r5,#1 /* point to different bytes */ ldb rl1,@rr6 clr r0 ldb rl0,@rr4 sub r1,r0 finish: /* set return value */ #ifdef __STD_CALL__ ld r7,r1 #else ld r2,r1 #endif #else /* above Z8001, below Z8002 */ unsegm #ifdef __STD_CALL__ ld r7,r15(#2) ld r6,r15(#4) ld r5,r15(#6) #endif /* r5 - length * r6 - b2 * r7 - b1 */ clr r1 /* initialize return value */ test r5 jr z,finish bitb rl7,#0 /* odd destination address? */ jr nz,testb2 bitb rl6,#0 /* odd source address? */ jr nz,odd_cmp /* b1 even, b2 odd */ jr t,even_cmp testb2: bitb rl6,#0 jr z,odd_cmp /* b2 even, b1 odd */ cpsib @r7,@r6,r5,eq jr z,beq /* bytes are the same */ jr t,byte_diff beq: jr ov,finish /* jump if r3 is zero now */ /* compare words */ even_cmp: ld r4,r5 /* remember length */ srl r5,#1 jr z,no_words cpsir @r7,@r6,r5,ne jr nz,no_words dec r7,#2 dec r6,#2 /* point to different bytes */ ldk r5,#2 jr t,odd_cmp no_words: bitb rl4,#0 /* odd length? */ jr z,finish cpsib @r7,@r6,r4,eq jr z,finish /* last bytes are the same */ jr t,byte_diff /* compare bytes */ odd_cmp: cpsirb @r7,@r6,r5,ne jr nz,finish byte_diff: dec r7,#1 dec r6,#1 /* point to different bytes */ ldb rl1,@r7 clr r0 ldb rl0,@r6 sub r1,r0 finish: #ifdef __STD_CALL__ ld r7,r1 #else ld r2,r1 #endif #endif /* Z8002 */ ret .end picolibc-1.8.11/libc/machine/z8k/memcpy.S000066400000000000000000000046211513574234600200520ustar00rootroot00000000000000/* * memcpy routine for Z8000 * Copyright (C) 2004 Christian Groessler * * Permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies. * * This file is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /* void *memcpy(void *dest, const void *src, size_t length); */ #include name "memcpy.S" .text even global _memcpy global memmove_entry _memcpy: #ifdef __Z8001__ segm #ifdef __STD_CALL__ ldl rr6,rr14(#4) ldl rr4,rr14(#8) ldl rr2,rr14(#12) #else pushl @rr14,rr6 #endif /* rr2 - length (high word ignored) * rr4 - src * rr6 - dest */ testl rr2 jr z,finish memmove_entry: /* external entry point from memmove */ bitb rl7,#0 /* odd destination address? */ jr nz,testsrc bitb rl5,#0 /* odd source address? */ jr nz,odd_copy jr t,even_copy /* dest even, src odd */ testsrc: bitb rl5,#0 jr z,odd_copy /* src even, dest odd */ ldib @rr6,@rr4,r3 jr ov,finish /* jump if r3 is zero now */ /* copy words */ even_copy: ld r2,r3 /* remember length */ srl r3,#1 jr z,no_words ldir @rr6,@rr4,r3 no_words: bitb rl2,#0 /* odd length? */ jr z,finish ldib @rr6,@rr4,r2 /* yes, copy last byte */ jr finish /* copy bytes */ odd_copy: ldirb @rr6,@rr4,r3 finish: #ifdef __STD_CALL__ ldl rr6,rr14(#4) #else popl rr2,@rr14 #endif #else /* above Z8001, below Z8002 */ unsegm #ifdef __STD_CALL__ ld r7,r15(#2) ld r6,r15(#4) ld r5,r15(#6) #else ld r2,r7 /* buffer pointer return value */ #endif /* r5 - length * r6 - src * r7 - dest */ test r5 jr z,finish memmove_entry: /* external entry point from memmove */ bitb rl7,#0 /* odd destination address? */ jr nz,testsrc bitb rl6,#0 /* odd source address? */ jr nz,odd_copy jr t,even_copy /* dest even, src odd */ testsrc: bitb rl6,#0 jr z,odd_copy /* src even, dest odd */ ldib @r7,@r6,r5 jr ov,finish /* jump if r5 is zero now */ /* copy words */ even_copy: ld r4,r5 /* remember length */ srl r5,#1 jr z,no_words ldir @r7,@r6,r5 no_words: bitb rl4,#0 /* odd length? */ jr z,finish ldib @r7,@r6,r4 /* yes, copy last byte */ jr finish /* copy bytes */ odd_copy: ldirb @r7,@r6,r5 finish: #ifdef __STD_CALL__ ld r7,r15(#2) #endif #endif /* Z8002 */ ret .end picolibc-1.8.11/libc/machine/z8k/memmove.S000066400000000000000000000064011513574234600202230ustar00rootroot00000000000000/* * memmove routine for Z8000 * Copyright (C) 2004 Christian Groessler * * Permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies. * * This file is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /* void *memmove(void *dest, const void *src, size_t length); */ #include name "memmove.S" .text even global _memmove _memmove: #ifdef __Z8001__ segm #ifdef __STD_CALL__ ldl rr6,rr14(#4) ldl rr4,rr14(#8) ldl rr2,rr14(#12) #else pushl @rr14,rr6 #endif /* rr2 - length (high word ignored) * rr4 - src * rr6 - dest */ testl rr2 jr z,finish /* check for destructive overlap (src < dest && dest < src + length) */ cpl rr6,rr4 jp ule,memmove_entry /* non-destructive, let memcpy do the work */ ldl rr0,rr2 addl rr0,rr4 /* rr0 = src + length */ cpl rr0,rr6 jp ult,memmove_entry /* non-destructive, let memcpy do the work */ /* set-up pointers to copy backwards, add (length - 1) */ addl rr4,rr2 /* src + length */ addl rr6,rr2 /* dest + length */ subl rr4,#1 subl rr6,#1 /* check alignment */ bitb rl7,#0 /* odd destination address? */ jr z,testsrc bitb rl5,#0 /* odd source address? */ jr z,odd_copy jr even_copy testsrc: bitb rl5,#0 jr nz,odd_copy /* src even, dest odd */ lddb @rr6,@rr4,r3 jr ov,finish /* jump if r5 is zero now */ /* copy words */ even_copy: ld r2,r3 /* remember length */ srl r3,#1 /* jr z,no_words it cannot be zero here */ dec r5,#1 dec r7,#1 lddr @rr6,@rr4,r3 no_words: bitb rl2,#0 /* odd length? */ jr z,finish inc r5,#1 inc r7,#1 lddb @rr6,@rr4,r2 /* yes, copy last byte */ jr finish /* copy bytes */ odd_copy: lddrb @rr6,@rr4,r3 finish: #ifdef __STD_CALL__ ldl rr6,rr14(#4) #else popl rr2,@rr14 #endif #else /* above Z8001, below Z8002 */ unsegm #ifdef __STD_CALL__ ld r7,r15(#2) ld r6,r15(#4) ld r5,r15(#6) #else ld r2,r7 /* buffer pointer return value */ #endif /* r5 - length * r6 - src * r7 - dest */ test r5 jr z,finish /* check for destructive overlap (src < dest && dest < src + length) */ cp r7,r6 jp ule,memmove_entry /* non-destructive, let memcpy do the work */ ld r0,r5 add r0,r6 /* r0 = src + length */ cp r0,r7 jp ult,memmove_entry /* non-destructive, let memcpy do the work */ /* set-up pointers to copy backwards, add (length - 1) */ add r6,r5 /* src + length */ add r7,r5 /* dest + length */ dec r6,#1 dec r7,#1 /* check alignment */ bitb rl7,#0 /* odd destination address? */ jr z,testsrc bitb rl6,#0 /* odd source address? */ jr z,odd_copy jr even_copy testsrc: bitb rl6,#0 jr nz,odd_copy /* src even, dest odd */ lddb @r7,@r6,r5 jr ov,finish /* jump if r5 is zero now */ /* copy words */ even_copy: ld r4,r5 /* remember length */ srl r5,#1 /* jr z,no_words it cannot be zero here */ dec r6,#1 dec r7,#1 lddr @r7,@r6,r5 no_words: bitb rl4,#0 /* odd length? */ jr z,finish inc r6,#1 inc r7,#1 lddb @r7,@r6,r4 /* yes, copy last byte */ jr finish /* copy bytes */ odd_copy: lddrb @r7,@r6,r5 finish: #ifdef __STD_CALL__ ld r7,r15(#2) #endif #endif /* Z8002 */ ret .end picolibc-1.8.11/libc/machine/z8k/memset.S000066400000000000000000000036131513574234600200520ustar00rootroot00000000000000/* * memset routine for Z8000 * Copyright (C) 2004 Christian Groessler * * Permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies. * * This file is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /* void *memset(void *buffer, int value, size_t length); */ #include name "memset.S" .text even global _memset _memset: #ifdef __Z8001__ segm #ifdef __STD_CALL__ ldl rr6,rr14(#4) ld r5,rr14(#8) ldl rr2,rr14(#10) #else pushl @rr14,rr6 #endif /* rr2 - length * rl5 - value * rr6 - buffer */ testl rr2 jr z,finish ldb rh5,rl5 ld r1,r5 /* r1 contains value */ bit r7,#0 jr z,not_odd ldb @rr6,rl1 inc r7,#1 subl rr2,#1 jr z,finish not_odd:ld r0,r3 /* remember length */ srl r3,#1 jr z,no_words ldl rr4,rr6 ld @rr6,r1 inc r7,#2 dec r3,#1 jr z,no_words ldir @rr6,@rr4,r3 /* fill words */ no_words: bit r0,#0 /* one byte remaining? */ jr z,finish ldb @rr6,rl1 finish: #ifdef __STD_CALL__ ldl rr6,rr14(#4) #else popl rr2,@rr14 #endif #else /* above Z8001, below Z8002 */ unsegm #ifdef __STD_CALL__ ld r7,r15(#2) ld r6,r15(#4) ld r5,r15(#6) #else ld r2,r7 /* buffer pointer return value */ #endif /* r5 - length * r6 - value * r7 - buffer */ test r5 jr z,finish ldb rh6,rl6 ld r1,r6 /* r1 contains value */ bit r7,#0 jr z,not_odd ldb @r7,rl1 inc r7,#1 dec r5,#1 jr z,finish not_odd:ld r0,r5 /* remember length */ srl r5,#1 jr z,no_words ld r4,r7 ld @r7,r1 inc r7,#2 dec r5,#1 jr z,no_words ldir @r7,@r4,r5 /* fill words */ no_words: bit r0,#0 /* one byte remaining? */ jr z,finish ldb @r7,rl1 finish: #ifdef __STD_CALL__ ld r7,r15(#2) #endif #endif /* Z8002 */ ret .end picolibc-1.8.11/libc/machine/z8k/setjmp.S000066400000000000000000000052041513574234600200600ustar00rootroot00000000000000/* Copyright (c) 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include .global _setjmp .global _longjmp #ifdef __Z8001__ segm #ifdef __STD_CALL__ _setjmp: ldl rr6,rr14(#4) ! get argument ldl rr2,@rr14 ! fetch pc ldl @rr6,rr2 ! save it ldl rr6(#16),rr8 ldl rr6(#4),rr10 ldl rr6(#8),rr12 ! remember frame pointer ldl rr6(#12),rr14 ! remember stack pointer ldk r7,#0 ret t _longjmp: ldl rr4,rr14(#4) ! get first argument ld r7,rr14(#8) ! get return value ldl rr8,rr4(#16) ldl rr10,rr4(#4) ldl rr12,rr4(#8) ! restore old frame pointer ldl rr14,rr4(#12) ! restore old stack pointer ldl rr4,@rr4 ! return address inc r15,#4 jp @rr4 #else /* above __STD_CALL_, below not */ _setjmp: ldl rr2,@rr14 ! fetch pc ldl @rr6,rr2 ! save it ldl rr6(16),rr8 ldl rr6(4),rr10 ldl rr6(8),rr12 ! and the other special regs ldl rr6(12),rr14 ldk r2,#0 ret t _longjmp: ld r2,r5 ! get return value ldl rr4,rr6(0) ldl rr8,rr6(16) ldl rr10,rr6(4) ldl rr12,rr6(8) ldl rr14,rr6(12) inc r15,#4 jp @rr4 #endif /* not __STD_CALL__ */ #else /* above Z8001, below Z8002 */ unseg #ifdef __STD_CALL__ _setjmp: ld r7,r15(#2) ! get argument ld r2,@r15 ! fetch pc ld @r7,r2 ! save it ldl r7(#14),rr8 ldl r7(#2),rr10 ldl r7(#6),rr12 ! remember frame pointer ldl r7(#10),rr14 ! remember stack pointer ldk r7,#0 ret t _longjmp: ld r4,r15(#2) ! get first argument (jmp_buf) ld r7,r15(#4) ! get return value ldl rr8,r4(#14) ldl rr10,r4(#2) ldl rr12,r4(#6) ! restore old frame pointer ldl rr14,r4(#10) ! restore old stack pointer ld r4,@r4 ! return address inc r15,#2 jp @r4 #else /* above __STD_CALL_, below not */ _setjmp: ld r2,@r15 ! fetch pc ld @r7,r2 ! save it ldl r7(4),rr10 ldl r7(8),rr12 ! and the other special regs ldl r7(12),rr14 ldk r2,#0 ret t _longjmp: ld r2,r6 ! get return value ld r4,@r7 ldl rr10,r7(4) ldl rr12,r7(8) ldl rr14,r7(12) inc r15,#2 jp @r4 #endif /* not __STD_CALL__ */ #endif /* Z8002 version */ picolibc-1.8.11/libc/meson.build000066400000000000000000000056361513574234600164650ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # libdirs = ['argz', 'ctype', 'errno', 'iconv', 'locale', 'misc', 'posix', 'search', 'signal', 'ssp', 'stdio', 'stdlib', 'string', 'time', 'xdr', 'uchar', 'ubsan'] libnames = libdirs inc_sys_headers_machine = [] inc_machine_headers_machine = [] srcs_machine = [] machine_dir = 'machine' / host_cpu_family if fs.is_dir(machine_dir) libdirs = [machine_dir] + libdirs libnames = ['machine'] + libnames endif foreach libdir : libdirs subdir(libdir) endforeach src_cpart = [] foreach libname : libnames src_cpart += get_variable('src_' + libname, []) endforeach subdir('include') foreach params : targets target = params['name'] target_dir = params['dir'] target_c_args = params['c_args'] libobjs = [] libsrcs_target = [] foreach libname : libnames if is_variable('lib_' + libname + target) libobjs += get_variable('lib_' + libname + target).extract_all_objects(recursive:true) endif libsrcs_target += get_variable('src_' + libname + target, []) endforeach set_variable('src_cpart_' + target, libsrcs_target) if libobjs != [] local_lib_cpart_target = static_library('cpart' + target, pic: false, objects : libobjs, include_directories: inc, c_args: target_c_args + c_args) set_variable('lib_cpart' + target, local_lib_cpart_target) endif endforeach picolibc-1.8.11/libc/misc/000077500000000000000000000000001513574234600152445ustar00rootroot00000000000000picolibc-1.8.11/libc/misc/CMakeLists.txt000066400000000000000000000032461513574234600200110ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources( dso_handle.c getauxval.c ffs.c fini.c init.c inittls.c lock.c picosbrk.c unctrl.c ) picolibc-1.8.11/libc/misc/dso_handle.c000066400000000000000000000034371513574234600175170ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Part of the C++ ABI for handling dynamic shared objects during global * destruction. We don't have shared objects, so this is just a stub * to let C++ programs link */ const void * const __dso_handle; picolibc-1.8.11/libc/misc/ffs.c000066400000000000000000000050321513574234600161660ustar00rootroot00000000000000/* Copyright (c) 1981, 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>---find first bit set in a word INDEX ffs SYNOPSIS #include int ffs(int <[word]>); DESCRIPTION <> returns the first bit set in a word. RETURNS <> returns 0 if <[c]> is 0, 1 if <[c]> is odd, 2 if <[c]> is a multiple of 2, etc. PORTABILITY <> is not ANSI C. No supporting OS subroutines are required. */ #include /* * GCC calls "ffs" for __builtin_ffs when the target doesn't have * custom code and INT_TYPE_SIZE < BITS_PER_WORD so we can't use that * builtin to implement ffs here. Instead, fall back to the ctz code * instead. */ #if __HAVE_BUILTIN_FFS && defined(__GNUC__) && __INT_WIDTH__ != __LONG_WIDTH__ #undef __HAVE_BUILTIN_FFS #endif int ffs(int i) { #if __HAVE_BUILTIN_FFS return (__builtin_ffs(i)); #elif __HAVE_BUILTIN_CTZ if (i == 0) return 0; return __builtin_ctz((unsigned int)i) + 1; #else int r; if (!i) return 0; r = 0; for (;;) { if (((1 << r++) & i) != 0) break; } return r; #endif } picolibc-1.8.11/libc/misc/fini.c000066400000000000000000000020121513574234600163300ustar00rootroot00000000000000/* * Copyright (C) 2010 CodeSourcery, Inc. * * Permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies. * * This file is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /* Handle ELF .{pre_init,init,fini}_array sections. */ #include #include #ifdef __INIT_FINI_ARRAY #ifdef __GNUCLIKE_PRAGMA_DIAGNOSTIC #pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wunknown-warning-option" #pragma GCC diagnostic ignored "-Wanalyzer-out-of-bounds" #endif /* Run all the cleanup routines. */ void __libc_fini_array(void) { void (**fn)(void); void (**fn_start)(void); fn = __fini_array_end; fn_start = __fini_array_start; while (fn != fn_start) (*--fn)(); #ifdef __INIT_FINI_FUNCS if (_fini) _fini(); #endif } #endif picolibc-1.8.11/libc/misc/getauxval.c000066400000000000000000000034061513574234600174130ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include unsigned long getauxval(unsigned long type) { (void)type; errno = EINVAL; return 0; } __weak_reference(getauxval, __getauxval); picolibc-1.8.11/libc/misc/init.c000066400000000000000000000022321513574234600163520ustar00rootroot00000000000000/* * Copyright (C) 2004 CodeSourcery, LLC * * Permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies. * * This file is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /* Handle ELF .{pre_init,init,fini}_array sections. */ #include #include #ifdef __INIT_FINI_ARRAY /* Iterate over all the init routines. */ void __libc_init_array(void) { void (**fn)(void); void (**fn_end)(void); #ifdef __INIT_FINI_FUNCS fn = __preinit_array_start; fn_end = __preinit_array_end; while (fn != fn_end) (*fn++)(); if (_init) _init(); fn = __init_array_start; fn_end = __init_array_end; while (fn != fn_end) (*fn++)(); #else /* * The init array immediately follows the preinit array, * so we can just run both in one loop */ fn = __bothinit_array_start; fn_end = __bothinit_array_end; while (fn != fn_end) (*fn++)(); #endif } #endif picolibc-1.8.11/libc/misc/inittls.c000066400000000000000000000055041513574234600171020ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #ifdef __THREAD_LOCAL_STORAGE_API /* * The TLS block consists of initialized data immediately followed by * zero filled data * * These addresses must be defined by the loader configuration file */ extern char __tdata_source[]; /* Source of TLS initialization data (in ROM) */ #ifdef __PICOCRT_RUNTIME_SIZE extern char __tdata_start[]; /* Start of static tdata area */ extern char __tdata_end[]; /* End of static tdata area */ extern char __tbss_start[]; /* Start of static zero-initialized TLS data */ extern char __tbss_end[]; /* End of static zero-initialized TLS data */ #define __tdata_size (__tdata_end - __tdata_start) #define __tbss_size (__tbss_end - __tbss_start) #define __tbss_offset (__tbss_start - __tdata_start) #else extern char __tdata_size[]; /* Size of TLS initized data */ extern char __tbss_size[]; /* Size of TLS zero-filled data */ extern char __tbss_offset[]; /* Offset from tdata to tbss */ #endif void _init_tls(void *__tls) { char *tls = __tls; /* Copy tls initialized data */ memcpy(tls, __tdata_source, (uintptr_t)__tdata_size); /* Clear tls zero data */ memset(tls + (uintptr_t)__tbss_offset, '\0', (uintptr_t)__tbss_size); } #endif picolibc-1.8.11/libc/misc/lock.c000066400000000000000000000064401513574234600163440ustar00rootroot00000000000000/* Copyright (c) 2016 Thomas Preud'homme */ /* FUNCTION <<__retarget_lock_init>>, <<__retarget_lock_init_recursive>>, <<__retarget_lock_close>>, <<__retarget_lock_close_recursive>>, <<__retarget_lock_acquire>>, <<__retarget_lock_acquire_recursive>>, <<__retarget_lock_release>>, <<__retarget_lock_release_recursive>>---locking routines INDEX __lock___sfp_recursive_mutex INDEX __lock___atexit_recursive_mutex INDEX __lock___at_quick_exit_mutex INDEX __lock___malloc_recursive_mutex INDEX __lock___env_recursive_mutex INDEX __lock___tz_mutex INDEX __lock___arc4random_mutex INDEX __retarget_lock_init INDEX __retarget_lock_init_recursive INDEX __retarget_lock_close INDEX __retarget_lock_close_recursive INDEX __retarget_lock_acquire INDEX __retarget_lock_acquire_recursive INDEX __retarget_lock_release INDEX __retarget_lock_release_recursive SYNOPSIS #include struct __lock __lock___sfp_recursive_mutex; struct __lock __lock___atexit_recursive_mutex; struct __lock __lock___at_quick_exit_mutex; struct __lock __lock___malloc_recursive_mutex; struct __lock __lock___env_recursive_mutex; struct __lock __lock___tz_mutex; struct __lock __lock___arc4random_mutex; void __retarget_lock_init (_LOCK_T * <[lock_ptr]>); void __retarget_lock_init_recursive (_LOCK_T * <[lock_ptr]>); void __retarget_lock_close (_LOCK_T <[lock]>); void __retarget_lock_close_recursive (_LOCK_T <[lock]>); void __retarget_lock_acquire (_LOCK_T <[lock]>); void __retarget_lock_acquire_recursive (_LOCK_T <[lock]>); void __retarget_lock_release (_LOCK_T <[lock]>); void __retarget_lock_release_recursive (_LOCK_T <[lock]>); DESCRIPTION Newlib was configured to allow the target platform to provide the locking routines and static locks at link time. As such, a dummy default implementation of these routines and static locks is provided for single-threaded application to link successfully out of the box on bare-metal systems. For multi-threaded applications the target platform is required to provide an implementation for @strong{all} these routines and static locks. If some routines or static locks are missing, the link will fail with doubly defined symbols. PORTABILITY These locking routines and static lock are newlib-specific. Supporting OS subroutines are required for linking multi-threaded applications. */ /* dummy lock routines and static locks for single-threaded apps */ #include #ifndef __SINGLE_THREAD struct __lock { char unused; }; struct __lock __lock___libc_recursive_mutex; void __retarget_lock_init(_LOCK_T *lock) { (void)lock; } void __retarget_lock_init_recursive(_LOCK_T *lock) { (void)lock; } void __retarget_lock_close(_LOCK_T lock) { (void)lock; } void __retarget_lock_close_recursive(_LOCK_T lock) { (void)lock; } void __retarget_lock_acquire(_LOCK_T lock) { (void)lock; } void __retarget_lock_acquire_recursive(_LOCK_T lock) { (void)lock; } void __retarget_lock_release(_LOCK_T lock) { (void)lock; } void __retarget_lock_release_recursive(_LOCK_T lock) { (void)lock; } #endif /* __SINGLE_THREAD */ picolibc-1.8.11/libc/misc/meson.build000066400000000000000000000040421513574234600174060ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_misc = [ 'dso_handle.c', 'getauxval.c', 'ffs.c', 'fini.c', 'init.c', 'inittls.c', 'lock.c', 'picosbrk.c', 'unctrl.c', ] srcs_misc_use = [] foreach file : srcs_misc s_file = fs.replace_suffix(file, '.S') if file in srcs_machine message('libc/misc/' + file + ': machine overrides generic') elif s_file in srcs_machine message('libc/misc/' + s_file + ': machine overrides generic') else srcs_misc_use += file endif endforeach src_misc = files(srcs_misc_use) picolibc-1.8.11/libc/misc/misc.tex000066400000000000000000000036351513574234600167300ustar00rootroot00000000000000# #Copyright (c) 1981, 1993 #The Regents of the University of California. All rights reserved. # #Redistribution and use in source and binary forms, with or without #modification, are permitted provided that the following conditions #are met: #1. Redistributions of source code must retain the above copyright #notice, this list of conditions and the following disclaimer. #2. Redistributions in binary form must reproduce the above copyright #notice, this list of conditions and the following disclaimer in the #documentation and/or other materials provided with the distribution. #3. Neither the name of the University nor the names of its contributors #may be used to endorse or promote products derived from this software #without specific prior written permission. # #THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND #ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE #IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE #ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE #FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL #DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS #OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) #HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT #LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY #OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF #SUCH DAMAGE. # @node Misc @chapter Miscellaneous Macros and Functions This chapter describes miscellaneous routines not covered elsewhere. @menu * Function ffs:: Return first bit set in a word * Function __retarget_lock_init:: Retargetable locking routines * Function unctrl:: Return printable representation of a character @end menu @page @include misc/ffs.def @page @include misc/lock.def @page @include misc/unctrl.def picolibc-1.8.11/libc/misc/picosbrk.c000066400000000000000000000045141513574234600172300ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #if __INTERNAL_HEAP > 0 char __heap_start[__INTERNAL_HEAP] __aligned(sizeof(double)); #define __heap_end (&__heap_start[__INTERNAL_HEAP]) #else extern char __heap_start[]; extern char __heap_end[]; #endif static char *__brk = __heap_start; void * sbrk(ptrdiff_t incr) { if (incr < 0) { if ((size_t)((uintptr_t)__brk - (uintptr_t)__heap_start) < (size_t)(-incr)) { errno = ENOMEM; return (void *)-1; } } else { if ((size_t)((uintptr_t)__heap_end - (uintptr_t)__brk) < (size_t)incr) { errno = ENOMEM; return (void *)-1; } } void *ret = __brk; __brk = (char *)((uintptr_t)__brk + incr); return ret; } picolibc-1.8.11/libc/misc/unctrl.c000066400000000000000000000124521513574234600167230ustar00rootroot00000000000000/* FUNCTION <>---get printable representation of a character INDEX unctrl INDEX unctrllen SYNOPSIS #include char *unctrl(int <[c]>); int unctrllen(int <[c]>); DESCRIPTION <> is a macro which returns the printable representation of <[c]> as a string. <> is a macro which returns the length of the printable representation of <[c]>. RETURNS <> returns a string of the printable representation of <[c]>. <> returns the length of the string which is the printable representation of <[c]>. PORTABILITY <> and <> are not ANSI C. No supporting OS subroutines are required. */ /* * Copyright (c) 1981, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)unctrl.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ const char * const __unctrl[256] = { "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "^I", "^J", "^K", "^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U", "^V", "^W", "^X", "^Y", "^Z", "^[", "^\\", "^]", "^~", "^_", " ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?", "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "\\", "]", "^", "_", "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~", "^?", "0x80", "0x81", "0x82", "0x83", "0x84", "0x85", "0x86", "0x87", "0x88", "0x89", "0x8a", "0x8b", "0x8c", "0x8d", "0x8e", "0x8f", "0x90", "0x91", "0x92", "0x93", "0x94", "0x95", "0x96", "0x97", "0x98", "0x99", "0x9a", "0x9b", "0x9c", "0x9d", "0x9e", "0x9f", "0xa0", "0xa1", "0xa2", "0xa3", "0xa4", "0xa5", "0xa6", "0xa7", "0xa8", "0xa9", "0xaa", "0xab", "0xac", "0xad", "0xae", "0xaf", "0xb0", "0xb1", "0xb2", "0xb3", "0xb4", "0xb5", "0xb6", "0xb7", "0xb8", "0xb9", "0xba", "0xbb", "0xbc", "0xbd", "0xbe", "0xbf", "0xc0", "0xc1", "0xc2", "0xc3", "0xc4", "0xc5", "0xc6", "0xc7", "0xc8", "0xc9", "0xca", "0xcb", "0xcc", "0xcd", "0xce", "0xcf", "0xd0", "0xd1", "0xd2", "0xd3", "0xd4", "0xd5", "0xd6", "0xd7", "0xd8", "0xd9", "0xda", "0xdb", "0xdc", "0xdd", "0xde", "0xdf", "0xe0", "0xe1", "0xe2", "0xe3", "0xe4", "0xe5", "0xe6", "0xe7", "0xe8", "0xe9", "0xea", "0xeb", "0xec", "0xed", "0xee", "0xef", "0xf0", "0xf1", "0xf2", "0xf3", "0xf4", "0xf5", "0xf6", "0xf7", "0xf8", "0xf9", "0xfa", "0xfb", "0xfc", "0xfd", "0xfe", "0xff", }; const char __unctrllen[256] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, }; picolibc-1.8.11/libc/posix/000077500000000000000000000000001513574234600154535ustar00rootroot00000000000000picolibc-1.8.11/libc/posix/CMakeLists.txt000066400000000000000000000033461513574234600202210ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources( basename.c collcmp.c dirname.c fnmatch.c fpathconf.c pathconf.c regcomp.c regerror.c regexec.c regfree.c strfmon.c strfmon_l.c vstrfmon.c ) picolibc-1.8.11/libc/posix/basename.c000066400000000000000000000010551513574234600173730ustar00rootroot00000000000000#ifndef _NO_BASENAME /* Copyright 2005 Shaun Jackman * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include char * basename(char *path) { char *p; if (path == NULL || *path == '\0') return "."; p = path + strlen(path) - 1; while (*p == '/') { if (p == path) return path; *p-- = '\0'; } while (p >= path && *p != '/') p--; return p + 1; } #endif /* !_NO_BASENAME */ picolibc-1.8.11/libc/posix/cclass.h000066400000000000000000000046361513574234600171050ustar00rootroot00000000000000/*- * Copyright (c) 1992, 1993, 1994 Henry Spencer. * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Henry Spencer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)cclass.h 8.3 (Berkeley) 3/20/94 * $FreeBSD: src/lib/libc/regex/cclass.h,v 1.4 2002/03/22 23:41:56 obrien Exp $ */ typedef enum { CALNUM, CALPHA, CBLANK, CCNTRL, CDIGIT, CGRAPH, CLOWER, CPRINT, CPUNCT, CSPACE, CUPPER, CXDIGIT } citype; /* character-class table */ static const struct cclass { const char *name; citype fidx; } cclasses[] = { { "alnum", CALNUM }, { "alpha", CALPHA }, { "blank", CBLANK }, { "cntrl", CCNTRL }, { "digit", CDIGIT }, { "graph", CGRAPH }, { "lower", CLOWER }, { "print", CPRINT }, { "punct", CPUNCT }, { "space", CSPACE }, { "upper", CUPPER }, { "xdigit", CXDIGIT }, { 0 } }; picolibc-1.8.11/libc/posix/cname.h000066400000000000000000000132651513574234600167160ustar00rootroot00000000000000/*- * Copyright (c) 1992, 1993, 1994 Henry Spencer. * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Henry Spencer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)cname.h 8.3 (Berkeley) 3/20/94 * $FreeBSD: src/lib/libc/regex/cname.h,v 1.3 2002/03/22 23:41:56 obrien Exp $ */ /* character-name table */ static const struct cname { const char *name; char code; } cnames[] = { { "NUL", '\0' }, { "SOH", '\001' }, { "STX", '\002' }, { "ETX", '\003' }, { "EOT", '\004' }, { "ENQ", '\005' }, { "ACK", '\006' }, { "BEL", '\007' }, { "alert", '\007' }, { "BS", '\010' }, { "backspace", '\b' }, { "HT", '\011' }, { "tab", '\t' }, { "LF", '\012' }, { "newline", '\n' }, { "VT", '\013' }, { "vertical-tab", '\v' }, { "FF", '\014' }, { "form-feed", '\f' }, { "CR", '\015' }, { "carriage-return", '\r' }, { "SO", '\016' }, { "SI", '\017' }, { "DLE", '\020' }, { "DC1", '\021' }, { "DC2", '\022' }, { "DC3", '\023' }, { "DC4", '\024' }, { "NAK", '\025' }, { "SYN", '\026' }, { "ETB", '\027' }, { "CAN", '\030' }, { "EM", '\031' }, { "SUB", '\032' }, { "ESC", '\033' }, { "IS4", '\034' }, { "FS", '\034' }, { "IS3", '\035' }, { "GS", '\035' }, { "IS2", '\036' }, { "RS", '\036' }, { "IS1", '\037' }, { "US", '\037' }, { "space", ' ' }, { "exclamation-mark", '!' }, { "quotation-mark", '"' }, { "number-sign", '#' }, { "dollar-sign", '$' }, { "percent-sign", '%' }, { "ampersand", '&' }, { "apostrophe", '\'' }, { "left-parenthesis", '(' }, { "right-parenthesis", ')' }, { "asterisk", '*' }, { "plus-sign", '+' }, { "comma", ',' }, { "hyphen", '-' }, { "hyphen-minus", '-' }, { "period", '.' }, { "full-stop", '.' }, { "slash", '/' }, { "solidus", '/' }, { "zero", '0' }, { "one", '1' }, { "two", '2' }, { "three", '3' }, { "four", '4' }, { "five", '5' }, { "six", '6' }, { "seven", '7' }, { "eight", '8' }, { "nine", '9' }, { "colon", ':' }, { "semicolon", ';' }, { "less-than-sign", '<' }, { "equals-sign", '=' }, { "greater-than-sign", '>' }, { "question-mark", '?' }, { "commercial-at", '@' }, { "left-square-bracket", '[' }, { "backslash", '\\' }, { "reverse-solidus", '\\' }, { "right-square-bracket", ']' }, { "circumflex", '^' }, { "circumflex-accent", '^' }, { "underscore", '_' }, { "low-line", '_' }, { "grave-accent", '`' }, { "left-brace", '{' }, { "left-curly-bracket", '{' }, { "vertical-line", '|' }, { "right-brace", '}' }, { "right-curly-bracket", '}' }, { "tilde", '~' }, { "DEL", '\177' }, { NULL, 0 } }; picolibc-1.8.11/libc/posix/collate.h000066400000000000000000000032661513574234600172560ustar00rootroot00000000000000/*- * Copyright (c) 1995 Alex Tatmanjants * at Electronni Visti IA, Kiev, Ukraine. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/locale/collate.h,v 1.11 2002/03/21 22:46:54 obrien Exp $ */ #ifndef _COLLATE_H_ #define _COLLATE_H_ _BEGIN_STD_C /* Picolibc doesn't have any LC_COLLATE support, so this is never defined */ #ifdef __HAVE_REAL_STRCOLL int __collate_range_cmp(int, int); #endif _END_STD_C #endif /* !_COLLATE_H_ */ picolibc-1.8.11/libc/posix/collcmp.c000066400000000000000000000036131513574234600172530ustar00rootroot00000000000000/* * Copyright (C) 1996 by Andrey A. Chernov, Moscow, Russia. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include "collate.h" #ifdef __HAVE_REAL_STRCOLL /* * Compare two characters converting collate information * into ASCII-compatible range, it allows to handle * "[a-z]"-type ranges with national characters. */ int __collate_range_cmp(int c1, int c2) { char s1[2], s2[2]; int ret; c1 &= UCHAR_MAX; c2 &= UCHAR_MAX; if (c1 == c2) return (0); s1[0] = c1; s1[1] = 0; s2[0] = c2; s2[1] = 0; if ((ret = strcoll(s1, s2)) != 0) return (ret); return (c1 - c2); } #endif picolibc-1.8.11/libc/posix/dirname.c000066400000000000000000000016541513574234600172440ustar00rootroot00000000000000/* Copyright 2005 Shaun Jackman * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ #include #include #if defined(__GNUC__) && !defined(clang) && __OPTIMIZE_SIZE__ /* * GCC 12.x has a bug in -Os mode on (at least) arm v8.1-m which * mis-compiles this function. Work around that by switching * optimization mode */ #ifdef __GNUCLIKE_PRAGMA_DIAGNOSTIC #pragma GCC diagnostic ignored "-Wpragmas" #endif #pragma GCC optimize("O2") #endif char * dirname(char *path) { char *p; if (path == NULL || *path == '\0') return "."; p = path + strlen(path) - 1; while (*p == '/') { if (p == path) return path; *p-- = '\0'; } while (p >= path && *p != '/') p--; while (p > path && p[-1] == '/') p--; return p < path ? "." : p == path ? "/" : (*p = '\0', path); } picolibc-1.8.11/libc/posix/engine.c000066400000000000000000001044451513574234600170740ustar00rootroot00000000000000/*- * Copyright (c) 1992, 1993, 1994 Henry Spencer. * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Henry Spencer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)engine.c 8.5 (Berkeley) 3/20/94 */ /* * The matching engine and friends. This file is #included by regexec.c * after suitable #defines of a variety of macros used herein, so that * different state representations can be used without duplicating masses * of code. */ #ifdef SNAMES #define matcher smatcher #define fast sfast #define slow sslow #define dissect sdissect #define backref sbackref #define step sstep #define print sprint #define at sat #define match smat #endif #ifdef LNAMES #define matcher lmatcher #define fast lfast #define slow lslow #define dissect ldissect #define backref lbackref #define step lstep #define print lprint #define at lat #define match lmat #endif /* another structure passed up and down to avoid zillions of parameters */ struct match { struct re_guts *g; int eflags; regmatch_t *pmatch; /* [nsub+1] (0 element unused) */ char *offp; /* offsets work from here */ char *beginp; /* start of string -- virtual NUL precedes */ char *endp; /* end of string -- virtual NUL here */ char *coldp; /* can be no match starting before here */ char **lastpos; /* [nplus+1] */ STATEVARS; states st; /* current states */ states fresh; /* states for a fresh start */ states tmp; /* temporary */ states empty; /* empty set of states */ }; /* ========= begin header generated by ./mkh ========= */ /* === engine.c === */ static int matcher(struct re_guts *g, char *string, size_t nmatch, regmatch_t pmatch[], int eflags); static char *dissect(struct match *m, char *start, char *stop, sopno startst, sopno stopst); static char *backref(struct match *m, char *start, char *stop, sopno startst, sopno stopst, sopno lev); static char *fast(struct match *m, char *start, char *stop, sopno startst, sopno stopst); static char *slow(struct match *m, char *start, char *stop, sopno startst, sopno stopst); static states step(struct re_guts *g, sopno start, sopno stop, states bef, int ch, states aft); #define BOL (OUT + 1) #define EOL (BOL + 1) #define BOLEOL (BOL + 2) #define NOTHING (BOL + 3) #define BOW (BOL + 4) #define EOW (BOL + 5) #define CODEMAX (BOL + 5) /* highest code used */ #define NONCHAR(c) ((c) > CHAR_MAX) #define NNONCHAR (CODEMAX - CHAR_MAX) #ifdef REDEBUG static void print(struct match *m, char *caption, states st, int ch, FILE *d); #endif #ifdef REDEBUG static void at(struct match *m, char *title, char *start, char *stop, sopno startst, sopno stopst); #endif #ifdef REDEBUG static char *pchar(int ch); #endif /* ========= end header generated by ./mkh ========= */ #ifdef REDEBUG #define SP(t, s, c) print(m, t, s, c, stdout) #define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2) #define NOTE(str) \ { \ if (m->eflags & REG_TRACE) \ printf("=%s\n", (str)); \ } #else #define SP(t, s, c) /* nothing */ #define AT(t, p1, p2, s1, s2) /* nothing */ #define NOTE(s) /* nothing */ #endif /* - matcher - the actual matching engine == static int matcher(struct re_guts *g, char *string, \ == size_t nmatch, regmatch_t pmatch[], int eflags); */ static int /* 0 success, REG_NOMATCH failure */ matcher(struct re_guts *g, char *string, size_t nmatch, regmatch_t pmatch[], int eflags) { char *endp; size_t i; struct match mv; struct match *m = &mv; char *dp = NULL; const sopno gf = g->firststate + 1; /* +1 for OEND */ const sopno gl = g->laststate; char *start; char *stop; /* Boyer-Moore algorithms variables */ char *pp; int cj, mj; char *mustfirst; char *mustlast; int *matchjump; int *charjump; /* simplify the situation where possible */ if (g->cflags & REG_NOSUB) nmatch = 0; if (eflags & REG_STARTEND) { start = string + pmatch[0].rm_so; stop = string + pmatch[0].rm_eo; } else { start = string; stop = start + strlen(start); } if (stop < start) return (REG_INVARG); /* prescreening; this does wonders for this rather slow code */ if (g->must != NULL) { if (g->charjump != NULL && g->matchjump != NULL) { mustfirst = g->must; mustlast = g->must + g->mlen - 1; charjump = g->charjump; matchjump = g->matchjump; pp = mustlast; for (dp = start + g->mlen - 1; dp < stop;) { /* Fast skip non-matches */ while (dp < stop && charjump[(unsigned char)*dp]) dp += charjump[(unsigned char)*dp]; if (dp >= stop) break; /* Greedy matcher */ /* We depend on not being used for * for strings of length 1 */ while (*--dp == *--pp && pp != mustfirst) ; if (*dp == *pp) break; /* Jump to next possible match */ mj = matchjump[pp - mustfirst]; cj = charjump[(unsigned char)*dp]; dp += (cj < mj ? mj : cj); pp = mustlast; } if (pp != mustfirst) return (REG_NOMATCH); } else { for (dp = start; dp < stop; dp++) if (*dp == g->must[0] && stop - dp >= g->mlen && memcmp(dp, g->must, (size_t)g->mlen) == 0) break; if (dp == stop) /* we didn't find g->must */ return (REG_NOMATCH); } } /* match struct setup */ m->g = g; m->eflags = eflags; m->pmatch = NULL; m->lastpos = NULL; m->offp = string; m->beginp = start; m->endp = stop; STATESETUP(m, 4); SETUP(m->st); SETUP(m->fresh); SETUP(m->tmp); SETUP(m->empty); CLEAR(m->empty); /* Adjust start according to moffset, to speed things up */ if (g->moffset > -1) start = ((dp - g->moffset) < start) ? start : dp - g->moffset; /* this loop does only one repetition except for backrefs */ for (;;) { endp = fast(m, start, stop, gf, gl); if (endp == NULL) { /* a miss */ STATETEARDOWN(m); return (REG_NOMATCH); } if (nmatch == 0 && !g->backrefs) break; /* no further info needed */ /* where? */ assert(m->coldp != NULL); for (;;) { NOTE("finding start"); endp = slow(m, m->coldp, stop, gf, gl); if (endp != NULL) break; assert(m->coldp < m->endp); m->coldp++; } if (nmatch == 1 && !g->backrefs) break; /* no further info needed */ /* oh my, he wants the subexpressions... */ if (m->pmatch == NULL) m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) * sizeof(regmatch_t)); if (m->pmatch == NULL) { STATETEARDOWN(m); return (REG_ESPACE); } for (i = 1; i <= m->g->nsub; i++) m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1; if (!g->backrefs && !(m->eflags & REG_BACKR)) { NOTE("dissecting"); dp = dissect(m, m->coldp, endp, gf, gl); } else { if (g->nplus > 0 && m->lastpos == NULL) m->lastpos = (char **)malloc((g->nplus + 1) * sizeof(char *)); if (g->nplus > 0 && m->lastpos == NULL) { free(m->pmatch); STATETEARDOWN(m); return (REG_ESPACE); } NOTE("backref dissect"); dp = backref(m, m->coldp, endp, gf, gl, (sopno)0); } if (dp != NULL) break; /* uh-oh... we couldn't find a subexpression-level match */ assert(g->backrefs); /* must be back references doing it */ assert(g->nplus == 0 || m->lastpos != NULL); for (;;) { if (dp != NULL || endp <= m->coldp) break; /* defeat */ NOTE("backoff"); endp = slow(m, m->coldp, endp - 1, gf, gl); if (endp == NULL) break; /* defeat */ /* try it on a shorter possibility */ #ifndef NDEBUG for (i = 1; i <= m->g->nsub; i++) { assert(m->pmatch[i].rm_so == -1); assert(m->pmatch[i].rm_eo == -1); } #endif NOTE("backoff dissect"); dp = backref(m, m->coldp, endp, gf, gl, (sopno)0); } assert(dp == NULL || dp == endp); if (dp != NULL) /* found a shorter one */ break; /* despite initial appearances, there is no match here */ NOTE("false alarm"); start = m->coldp + 1; /* recycle starting later */ assert(start <= stop); } /* fill in the details if requested */ if (nmatch > 0) { pmatch[0].rm_so = m->coldp - m->offp; pmatch[0].rm_eo = endp - m->offp; } if (nmatch > 1) { assert(m->pmatch != NULL); for (i = 1; i < nmatch; i++) if (i <= m->g->nsub) pmatch[i] = m->pmatch[i]; else { pmatch[i].rm_so = -1; pmatch[i].rm_eo = -1; } } if (m->pmatch != NULL) free((char *)m->pmatch); if (m->lastpos != NULL) free((char *)m->lastpos); STATETEARDOWN(m); return (0); } /* - dissect - figure out what matched what, no back references == static char *dissect(struct match *m, char *start, \ == char *stop, sopno startst, sopno stopst); */ static char * /* == stop (success) always */ dissect(struct match *m, char *start, char *stop, sopno startst, sopno stopst) { int i; sopno ss; /* start sop of current subRE */ sopno es; /* end sop of current subRE */ char *sp; /* start of string matched by it */ char *stp; /* string matched by it cannot pass here */ char *rest; /* start of rest of string */ char *tail; /* string unmatched by rest of RE */ sopno ssub; /* start sop of subsubRE */ sopno esub; /* end sop of subsubRE */ char *ssp; /* start of string matched by subsubRE */ char *sep; /* end of string matched by subsubRE */ char *oldssp; /* previous ssp */ char *dp; AT("diss", start, stop, startst, stopst); sp = start; for (ss = startst; ss < stopst; ss = es) { /* identify end of subRE */ es = ss; switch (OP(m->g->strip[es])) { case OPLUS_: case OQUEST_: es += OPND(m->g->strip[es]); break; case OCH_: while (OP(m->g->strip[es]) != O_CH) es += OPND(m->g->strip[es]); break; } es++; /* figure out what it matched */ switch (OP(m->g->strip[ss])) { case OEND: assert(nope); break; case OCHAR: sp++; break; case OBOL: case OEOL: case OBOW: case OEOW: break; case OANY: case OANYOF: sp++; break; case OBACK_: case O_BACK: assert(nope); break; /* cases where length of match is hard to find */ case OQUEST_: stp = stop; for (;;) { /* how long could this one be? */ rest = slow(m, sp, stp, ss, es); assert(rest != NULL); /* it did match */ /* could the rest match the rest? */ tail = slow(m, rest, stop, es, stopst); if (tail == stop) break; /* yes! */ /* no -- try a shorter match for this one */ stp = rest - 1; assert(stp >= sp); /* it did work */ } ssub = ss + 1; esub = es - 1; /* did innards match? */ if (slow(m, sp, rest, ssub, esub) != NULL) { dp = dissect(m, sp, rest, ssub, esub); (void)dp; assert(dp == rest); } else /* no */ assert(sp == rest); sp = rest; break; case OPLUS_: stp = stop; for (;;) { /* how long could this one be? */ rest = slow(m, sp, stp, ss, es); assert(rest != NULL); /* it did match */ /* could the rest match the rest? */ tail = slow(m, rest, stop, es, stopst); if (tail == stop) break; /* yes! */ /* no -- try a shorter match for this one */ stp = rest - 1; assert(stp >= sp); /* it did work */ } ssub = ss + 1; esub = es - 1; ssp = sp; oldssp = ssp; for (;;) { /* find last match of innards */ sep = slow(m, ssp, rest, ssub, esub); if (sep == NULL || sep == ssp) break; /* failed or matched null */ oldssp = ssp; /* on to next try */ ssp = sep; } if (sep == NULL) { /* last successful match */ sep = ssp; ssp = oldssp; } assert(sep == rest); /* must exhaust substring */ assert(slow(m, ssp, sep, ssub, esub) == rest); dp = dissect(m, ssp, sep, ssub, esub); (void)dp; assert(dp == sep); sp = rest; break; case OCH_: stp = stop; for (;;) { /* how long could this one be? */ rest = slow(m, sp, stp, ss, es); assert(rest != NULL); /* it did match */ /* could the rest match the rest? */ tail = slow(m, rest, stop, es, stopst); if (tail == stop) break; /* yes! */ /* no -- try a shorter match for this one */ stp = rest - 1; assert(stp >= sp); /* it did work */ } ssub = ss + 1; esub = ss + OPND(m->g->strip[ss]) - 1; assert(OP(m->g->strip[esub]) == OOR1); for (;;) { /* find first matching branch */ if (slow(m, sp, rest, ssub, esub) == rest) break; /* it matched all of it */ /* that one missed, try next one */ assert(OP(m->g->strip[esub]) == OOR1); esub++; assert(OP(m->g->strip[esub]) == OOR2); ssub = esub + 1; esub += OPND(m->g->strip[esub]); if (OP(m->g->strip[esub]) == OOR2) esub--; else assert(OP(m->g->strip[esub]) == O_CH); } dp = dissect(m, sp, rest, ssub, esub); (void)dp; assert(dp == rest); sp = rest; break; case O_PLUS: case O_QUEST: case OOR1: case OOR2: case O_CH: assert(nope); break; case OLPAREN: i = OPND(m->g->strip[ss]); assert(0 < i && i <= m->g->nsub); m->pmatch[i].rm_so = sp - m->offp; break; case ORPAREN: i = OPND(m->g->strip[ss]); assert(0 < i && i <= m->g->nsub); m->pmatch[i].rm_eo = sp - m->offp; break; default: /* uh oh */ assert(nope); break; } } assert(sp == stop); return (sp); } /* - backref - figure out what matched what, figuring in back references == static char *backref(struct match *m, char *start, \ == char *stop, sopno startst, sopno stopst, sopno lev); */ static char * /* == stop (success) or NULL (failure) */ backref(struct match *m, char *start, char *stop, sopno startst, sopno stopst, sopno lev /* PLUS nesting level */ ) { int i; sopno ss; /* start sop of current subRE */ char *sp; /* start of string matched by it */ sopno ssub; /* start sop of subsubRE */ sopno esub; /* end sop of subsubRE */ char *ssp; /* start of string matched by subsubRE */ char *dp; size_t len; int hard; sop s; regoff_t offsave; cset *cs; AT("back", start, stop, startst, stopst); sp = start; /* get as far as we can with easy stuff */ hard = 0; for (ss = startst; !hard && ss < stopst; ss++) switch (OP(s = m->g->strip[ss])) { case OCHAR: if (sp == stop || *sp++ != (char)OPND(s)) return (NULL); break; case OANY: if (sp == stop) return (NULL); sp++; break; case OANYOF: cs = &m->g->sets[OPND(s)]; if (sp == stop || !CHIN(cs, *sp++)) return (NULL); break; case OBOL: if ((sp == m->beginp && !(m->eflags & REG_NOTBOL)) || (sp < m->endp && *(sp - 1) == '\n' && (m->g->cflags & REG_NEWLINE))) { /* yes */ } else return (NULL); break; case OEOL: if ((sp == m->endp && !(m->eflags & REG_NOTEOL)) || (sp < m->endp && *sp == '\n' && (m->g->cflags & REG_NEWLINE))) { /* yes */ } else return (NULL); break; case OBOW: if (((sp == m->beginp && !(m->eflags & REG_NOTBOL)) || (sp < m->endp && *(sp - 1) == '\n' && (m->g->cflags & REG_NEWLINE)) || (sp > m->beginp && !ISWORD(*(sp - 1)))) && (sp < m->endp && ISWORD(*sp))) { /* yes */ } else return (NULL); break; case OEOW: if (((sp == m->endp && !(m->eflags & REG_NOTEOL)) || (sp < m->endp && *sp == '\n' && (m->g->cflags & REG_NEWLINE)) || (sp < m->endp && !ISWORD(*sp))) && (sp > m->beginp && ISWORD(*(sp - 1)))) { /* yes */ } else return (NULL); break; case O_QUEST: break; case OOR1: /* matches null but needs to skip */ ss++; s = m->g->strip[ss]; do { assert(OP(s) == OOR2); ss += OPND(s); } while (OP(s = m->g->strip[ss]) != O_CH); /* note that the ss++ gets us past the O_CH */ break; default: /* have to make a choice */ hard = 1; break; } if (!hard) { /* that was it! */ if (sp != stop) return (NULL); return (sp); } ss--; /* adjust for the for's final increment */ /* the hard stuff */ AT("hard", sp, stop, ss, stopst); s = m->g->strip[ss]; switch (OP(s)) { case OBACK_: /* the vilest depths */ i = OPND(s); assert(0 < i && i <= m->g->nsub); if (m->pmatch[i].rm_eo == -1) return (NULL); assert(m->pmatch[i].rm_so != -1); len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so; assert(stop - m->beginp >= len); if (sp > stop - len) return (NULL); /* not enough left to match */ ssp = m->offp + m->pmatch[i].rm_so; if (memcmp(sp, ssp, len) != 0) return (NULL); while (m->g->strip[ss] != (sop)SOP(O_BACK, i)) ss++; return (backref(m, sp + len, stop, ss + 1, stopst, lev)); break; case OQUEST_: /* to null or not */ dp = backref(m, sp, stop, ss + 1, stopst, lev); if (dp != NULL) return (dp); /* not */ return (backref(m, sp, stop, ss + OPND(s) + 1, stopst, lev)); break; case OPLUS_: assert(m->lastpos != NULL); assert(lev + 1 <= m->g->nplus); m->lastpos[lev + 1] = sp; return (backref(m, sp, stop, ss + 1, stopst, lev + 1)); break; case O_PLUS: if (sp == m->lastpos[lev]) /* last pass matched null */ return (backref(m, sp, stop, ss + 1, stopst, lev - 1)); /* try another pass */ m->lastpos[lev] = sp; dp = backref(m, sp, stop, ss - OPND(s) + 1, stopst, lev); if (dp == NULL) return (backref(m, sp, stop, ss + 1, stopst, lev - 1)); else return (dp); break; case OCH_: /* find the right one, if any */ ssub = ss + 1; esub = ss + OPND(s) - 1; assert(OP(m->g->strip[esub]) == OOR1); for (;;) { /* find first matching branch */ dp = backref(m, sp, stop, ssub, esub, lev); if (dp != NULL) return (dp); /* that one missed, try next one */ if (OP(m->g->strip[esub]) == O_CH) return (NULL); /* there is none */ esub++; assert(OP(m->g->strip[esub]) == OOR2); ssub = esub + 1; esub += OPND(m->g->strip[esub]); if (OP(m->g->strip[esub]) == OOR2) esub--; else assert(OP(m->g->strip[esub]) == O_CH); } break; case OLPAREN: /* must undo assignment if rest fails */ i = OPND(s); assert(0 < i && i <= m->g->nsub); offsave = m->pmatch[i].rm_so; m->pmatch[i].rm_so = sp - m->offp; dp = backref(m, sp, stop, ss + 1, stopst, lev); if (dp != NULL) return (dp); m->pmatch[i].rm_so = offsave; return (NULL); break; case ORPAREN: /* must undo assignment if rest fails */ i = OPND(s); assert(0 < i && i <= m->g->nsub); offsave = m->pmatch[i].rm_eo; m->pmatch[i].rm_eo = sp - m->offp; dp = backref(m, sp, stop, ss + 1, stopst, lev); if (dp != NULL) return (dp); m->pmatch[i].rm_eo = offsave; return (NULL); break; default: /* uh oh */ assert(nope); break; } /* "can't happen" */ assert(nope); /* NOTREACHED */ return "shut up gcc"; } /* - fast - step through the string at top speed == static char *fast(struct match *m, char *start, \ == char *stop, sopno startst, sopno stopst); */ static char * /* where tentative match ended, or NULL */ fast(struct match *m, char *start, char *stop, sopno startst, sopno stopst) { states st = m->st; states fresh = m->fresh; states tmp = m->tmp; char *p = start; int c = (start == m->beginp) ? OUT : *(start - 1); int lastc; /* previous c */ int flagch; int i; char *coldp; /* last p after which no match was underway */ CLEAR(st); SET1(st, startst); st = step(m->g, startst, stopst, st, NOTHING, st); ASSIGN(fresh, st); SP("start", st, *p); coldp = NULL; for (;;) { /* next character */ lastc = c; c = (p == m->endp) ? OUT : *p; if (EQ(st, fresh)) coldp = p; /* is there an EOL and/or BOL between lastc and c? */ flagch = '\0'; i = 0; if ((lastc == '\n' && m->g->cflags & REG_NEWLINE) || (lastc == OUT && !(m->eflags & REG_NOTBOL))) { flagch = BOL; i = m->g->nbol; } if ((c == '\n' && m->g->cflags & REG_NEWLINE) || (c == OUT && !(m->eflags & REG_NOTEOL))) { flagch = (flagch == BOL) ? BOLEOL : EOL; i += m->g->neol; } if (i != 0) { for (; i > 0; i--) st = step(m->g, startst, stopst, st, flagch, st); SP("boleol", st, c); } /* how about a word boundary? */ if ((flagch == BOL || (lastc != OUT && !ISWORD(lastc))) && (c != OUT && ISWORD(c))) { flagch = BOW; } if ((lastc != OUT && ISWORD(lastc)) && (flagch == EOL || (c != OUT && !ISWORD(c)))) { flagch = EOW; } if (flagch == BOW || flagch == EOW) { st = step(m->g, startst, stopst, st, flagch, st); SP("boweow", st, c); } /* are we done? */ if (ISSET(st, stopst) || p == stop) break; /* NOTE BREAK OUT */ /* no, we must deal with this character */ ASSIGN(tmp, st); ASSIGN(st, fresh); assert(c != OUT); st = step(m->g, startst, stopst, tmp, c, st); SP("aft", st, c); assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st)); p++; } assert(coldp != NULL); m->coldp = coldp; if (ISSET(st, stopst)) return (p + 1); else return (NULL); } /* - slow - step through the string more deliberately == static char *slow(struct match *m, char *start, \ == char *stop, sopno startst, sopno stopst); */ static char * /* where it ended */ slow(struct match *m, char *start, char *stop, sopno startst, sopno stopst) { states st = m->st; states empty = m->empty; states tmp = m->tmp; char *p = start; int c = (start == m->beginp) ? OUT : *(start - 1); int lastc; /* previous c */ int flagch; int i; char *matchp; /* last p at which a match ended */ AT("slow", start, stop, startst, stopst); CLEAR(st); SET1(st, startst); SP("sstart", st, *p); st = step(m->g, startst, stopst, st, NOTHING, st); matchp = NULL; for (;;) { /* next character */ lastc = c; c = (p == m->endp) ? OUT : *p; /* is there an EOL and/or BOL between lastc and c? */ flagch = '\0'; i = 0; if ((lastc == '\n' && m->g->cflags & REG_NEWLINE) || (lastc == OUT && !(m->eflags & REG_NOTBOL))) { flagch = BOL; i = m->g->nbol; } if ((c == '\n' && m->g->cflags & REG_NEWLINE) || (c == OUT && !(m->eflags & REG_NOTEOL))) { flagch = (flagch == BOL) ? BOLEOL : EOL; i += m->g->neol; } if (i != 0) { for (; i > 0; i--) st = step(m->g, startst, stopst, st, flagch, st); SP("sboleol", st, c); } /* how about a word boundary? */ if ((flagch == BOL || (lastc != OUT && !ISWORD(lastc))) && (c != OUT && ISWORD(c))) { flagch = BOW; } if ((lastc != OUT && ISWORD(lastc)) && (flagch == EOL || (c != OUT && !ISWORD(c)))) { flagch = EOW; } if (flagch == BOW || flagch == EOW) { st = step(m->g, startst, stopst, st, flagch, st); SP("sboweow", st, c); } /* are we done? */ if (ISSET(st, stopst)) matchp = p; if (EQ(st, empty) || p == stop) break; /* NOTE BREAK OUT */ /* no, we must deal with this character */ ASSIGN(tmp, st); ASSIGN(st, empty); assert(c != OUT); st = step(m->g, startst, stopst, tmp, c, st); SP("saft", st, c); assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st)); p++; } return (matchp); } /* - step - map set of states reachable before char to set reachable after == static states step(struct re_guts *g, sopno start, sopno stop, \ == states bef, int ch, states aft); == #define BOL (OUT+1) == #define EOL (BOL+1) == #define BOLEOL (BOL+2) == #define NOTHING (BOL+3) == #define BOW (BOL+4) == #define EOW (BOL+5) == #define CODEMAX (BOL+5) // highest code used == #define NONCHAR(c) ((c) > CHAR_MAX) == #define NNONCHAR (CODEMAX-CHAR_MAX) */ static states step(struct re_guts *g, sopno start, /* start state within strip */ sopno stop, /* state after stop state within strip */ states bef, /* states reachable before */ int ch, /* character or NONCHAR code */ states aft /* states already known reachable after */ ) { cset *cs; sop s; sopno pc; onestate here; /* note, macros know this name */ sopno look; int i; for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) { s = g->strip[pc]; switch (OP(s)) { case OEND: assert(pc == stop - 1); break; case OCHAR: /* only characters can match */ assert(!NONCHAR(ch) || ch != (char)OPND(s)); if (ch == (char)OPND(s)) FWD(aft, bef, 1); break; case OBOL: if (ch == BOL || ch == BOLEOL) FWD(aft, bef, 1); break; case OEOL: if (ch == EOL || ch == BOLEOL) FWD(aft, bef, 1); break; case OBOW: if (ch == BOW) FWD(aft, bef, 1); break; case OEOW: if (ch == EOW) FWD(aft, bef, 1); break; case OANY: if (!NONCHAR(ch)) FWD(aft, bef, 1); break; case OANYOF: cs = &g->sets[OPND(s)]; if (!NONCHAR(ch) && CHIN(cs, ch)) FWD(aft, bef, 1); break; case OBACK_: /* ignored here */ case O_BACK: FWD(aft, aft, 1); break; case OPLUS_: /* forward, this is just an empty */ FWD(aft, aft, 1); break; case O_PLUS: /* both forward and back */ FWD(aft, aft, 1); i = ISSETBACK(aft, OPND(s)); BACK(aft, aft, OPND(s)); if (!i && ISSETBACK(aft, OPND(s))) { /* oho, must reconsider loop body */ pc -= OPND(s) + 1; INIT(here, pc); } break; case OQUEST_: /* two branches, both forward */ FWD(aft, aft, 1); FWD(aft, aft, OPND(s)); break; case O_QUEST: /* just an empty */ FWD(aft, aft, 1); break; case OLPAREN: /* not significant here */ case ORPAREN: FWD(aft, aft, 1); break; case OCH_: /* mark the first two branches */ FWD(aft, aft, 1); assert(OP(g->strip[pc + OPND(s)]) == OOR2); FWD(aft, aft, OPND(s)); break; case OOR1: /* done a branch, find the O_CH */ if (ISSTATEIN(aft, here)) { for (look = 1; OP(s = g->strip[pc + look]) != O_CH; look += OPND(s)) assert(OP(s) == OOR2); FWD(aft, aft, look); } break; case OOR2: /* propagate OCH_'s marking */ FWD(aft, aft, 1); if (OP(g->strip[pc + OPND(s)]) != O_CH) { assert(OP(g->strip[pc + OPND(s)]) == OOR2); FWD(aft, aft, OPND(s)); } break; case O_CH: /* just empty */ FWD(aft, aft, 1); break; default: /* ooooops... */ assert(nope); break; } } return (aft); } #ifdef REDEBUG /* - print - print a set of states == #ifdef REDEBUG == static void print(struct match *m, char *caption, states st, \ == int ch, FILE *d); == #endif */ static void print(struct match *m, char *caption, states st, int ch, FILE *d) { struct re_guts *g = m->g; int i; int first = 1; if (!(m->eflags & REG_TRACE)) return; fprintf(d, "%s", caption); if (ch != '\0') fprintf(d, " %s", pchar(ch)); for (i = 0; i < g->nstates; i++) if (ISSET(st, i)) { fprintf(d, "%s%d", (first) ? "\t" : ", ", i); first = 0; } fprintf(d, "\n"); } /* - at - print current situation == #ifdef REDEBUG == static void at(struct match *m, char *title, char *start, char *stop, \ == sopno startst, sopno stopst); == #endif */ static void at(struct match *m, char *title, char *start, char *stop, sopno startst, sopno stopst) { if (!(m->eflags & REG_TRACE)) return; printf("%s %s-", title, pchar(*start)); printf("%s ", pchar(*stop)); printf("%ld-%ld\n", (long)startst, (long)stopst); } #ifndef PCHARDONE #define PCHARDONE /* never again */ /* - pchar - make a character printable == #ifdef REDEBUG == static char *pchar(int ch); == #endif * * Is this identical to regchar() over in debug.c? Well, yes. But a * duplicate here avoids having a debugging-capable regexec.o tied to * a matching debug.o, and this is convenient. It all disappears in * the non-debug compilation anyway, so it doesn't matter much. */ static char * /* -> representation */ pchar(int ch) { static char pbuf[10]; if (isprint((uch)ch) || ch == ' ') sprintf(pbuf, "%c", ch); else sprintf(pbuf, "\\%o", ch); return (pbuf); } #endif #endif #undef matcher #undef fast #undef slow #undef dissect #undef backref #undef step #undef print #undef at #undef match picolibc-1.8.11/libc/posix/fnmatch.c000066400000000000000000000243401513574234600172420ustar00rootroot00000000000000/* * Copyright (c) 1989, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Guido van Rossum. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * Function fnmatch() as specified in POSIX 1003.2-1992, section B.6. * Compares a filename or pathname to a pattern. */ #define _GNU_SOURCE #include #include #include #include #include "collate.h" #define EOS '\0' #define RANGE_MATCH 1 #define RANGE_NOMATCH 0 #define RANGE_ERROR (-1) static int rangematch(const char *, char, int, char **); static int _fnmatch(const char *pattern, const char *string, int flags, int level) { const char *stringstart; char *newp; char c, test; for (stringstart = string;;) switch (c = *pattern++) { case EOS: if ((flags & FNM_LEADING_DIR) && *string == '/') return (0); return (*string == EOS ? 0 : FNM_NOMATCH); case '?': if (*string == EOS) return (FNM_NOMATCH); if (*string == '/' && (flags & FNM_PATHNAME)) return (FNM_NOMATCH); if (*string == '.' && (flags & FNM_PERIOD) && (string == stringstart || ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) return (FNM_NOMATCH); ++string; break; case '*': c = *pattern; /* Collapse multiple stars. */ while (c == '*') c = *++pattern; if (*string == '.' && (flags & FNM_PERIOD) && (string == stringstart || ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) return (FNM_NOMATCH); /* Optimize for pattern with * at end or before /. */ if (c == EOS) if (flags & FNM_PATHNAME) return ((flags & FNM_LEADING_DIR) || strchr(string, '/') == NULL ? 0 : FNM_NOMATCH); else return (0); else if (c == '/' && flags & FNM_PATHNAME) { if ((string = strchr(string, '/')) == NULL) return (FNM_NOMATCH); break; } if (level == 0) return (-FNM_NOMATCH); /* General case, use recursion. */ while ((test = *string) != EOS) { switch (_fnmatch(pattern, string, flags & ~FNM_PERIOD, level - 1)) { case 0: return (0); case -FNM_NOMATCH: return -FNM_NOMATCH; default: break; } if (test == '/' && flags & FNM_PATHNAME) break; ++string; } return (FNM_NOMATCH); case '[': if (*string == EOS) return (FNM_NOMATCH); if (*string == '/' && (flags & FNM_PATHNAME)) return (FNM_NOMATCH); if (*string == '.' && (flags & FNM_PERIOD) && (string == stringstart || ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) return (FNM_NOMATCH); switch (rangematch(pattern, *string, flags, &newp)) { case RANGE_ERROR: goto norm; case RANGE_MATCH: pattern = newp; break; case RANGE_NOMATCH: return (FNM_NOMATCH); } ++string; break; case '\\': if (!(flags & FNM_NOESCAPE)) { if ((c = *pattern++) == EOS) { c = '\\'; --pattern; } } __fallthrough; default: norm: if (c == *string) ; else if ((flags & FNM_CASEFOLD) && (tolower((unsigned char)c) == tolower((unsigned char)*string))) ; else return (FNM_NOMATCH); string++; break; } /* NOTREACHED */ } /* Limit recursion to 16 levels to avoid stack overflow */ int fnmatch(const char *pattern, const char *string, int flags) { return _fnmatch(pattern, string, flags, 16); } static const struct { const char *name; int (*func)(int); } classes[] = { { .name = "alnum", .func = isalnum }, { .name = "alpha", .func = isalpha }, { .name = "blank", .func = isblank }, { .name = "cntrl", .func = iscntrl }, { .name = "digit", .func = isdigit }, { .name = "graph", .func = isgraph }, { .name = "lower", .func = islower }, { .name = "print", .func = isprint }, { .name = "punct", .func = ispunct }, { .name = "space", .func = isspace }, { .name = "upper", .func = isupper }, { .name = "xdigit", .func = isxdigit }, }; #define NUM_CLASSES (sizeof(classes) / sizeof(classes[0])) static int rangematch(const char *pattern, char test, int flags, char **newp) { int negate, ok; char c, c2; /* * A bracket expression starting with an unquoted circumflex * character produces unspecified results (IEEE 1003.2-1992, * 3.13.2). This implementation treats it like '!', for * consistency with the regular expression syntax. * J.T. Conklin (conklin@ngai.kaleida.com) */ if ((negate = (*pattern == '!' || *pattern == '^'))) ++pattern; if (flags & FNM_CASEFOLD) test = tolower((unsigned char)test); /* * A right bracket shall lose its special meaning and represent * itself in a bracket expression if it occurs first in the list. * -- POSIX.2 2.8.3.2 */ ok = 0; c = *pattern++; do { if (c == '\\' && !(flags & FNM_NOESCAPE)) c = *pattern++; if (c == EOS) return (RANGE_ERROR); if (c == '/' && (flags & FNM_PATHNAME)) return (RANGE_NOMATCH); /* Equivalence classes -- [=class=] */ if (c == '[' && pattern[0] == '=' && pattern[1] != EOS && pattern[2] == '=' && pattern[3] == ']') { c = pattern[1]; pattern += 4; } /* Collating sequences -- [.symbol.] */ if (c == '[' && pattern[0] == '.' && pattern[1] != EOS) { size_t col_len = 1; /* Find the end of any potential collating symbol */ while (pattern[1 + col_len] != EOS) { if (pattern[1 + col_len] == '.' && pattern[1 + col_len + 1] == ']') { /* Found a collating symbol. */ if (col_len > 1) { /* We have no collating symbols longer than 1 char */ return (RANGE_ERROR); } /* Extract collating symbol */ c = pattern[1]; /* Skip [. and .] */ pattern += 2 + 2; break; } col_len++; } } /* Character class -- [:class:] */ if (c == '[' && pattern[0] == ':') { size_t name_len = 0; while (islower(pattern[1 + name_len])) name_len++; if (pattern[1 + name_len] == ':' && pattern[1 + name_len + 1] == ']') { size_t class; /* Found a valid class pattern, now see if it's one we know */ for (class = 0; class < NUM_CLASSES; class++) { if (name_len == strlen(classes[class].name) && strncmp(&pattern[1], classes[class].name, name_len) == 0) { if (classes[class].func(test)) ok = 1; break; } } /* Skip over the pattern and continue evaluating the expression */ pattern = pattern + 1 + name_len + 2; continue; } } if (flags & FNM_CASEFOLD) c = tolower((unsigned char)c); if (*pattern == '-' && (c2 = *(pattern + 1)) != EOS && c2 != ']') { pattern += 2; if (c2 == '\\' && !(flags & FNM_NOESCAPE)) c2 = *pattern++; if (c2 == EOS) return (RANGE_ERROR); if (flags & FNM_CASEFOLD) c2 = tolower((unsigned char)c2); if ( #ifdef __HAVE_REAL_STRCOLL __collate_range_cmp(c, test) <= 0 && __collate_range_cmp(test, c2) <= 0 #else c <= test && test <= c2 #endif ) ok = 1; } else if (c == test) ok = 1; } while ((c = *pattern++) != ']'); *newp = (char *)pattern; return (ok == negate ? RANGE_NOMATCH : RANGE_MATCH); } picolibc-1.8.11/libc/posix/fpathconf.c000066400000000000000000000033671513574234600176000ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include #include #include long fpathconf(int fd, int name) { (void)fd; return pathconf(".", name); } picolibc-1.8.11/libc/posix/meson.build000066400000000000000000000041711513574234600176200ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2020 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_posix = [ 'basename.c', 'collcmp.c', 'dirname.c', 'fnmatch.c', 'fpathconf.c', 'pathconf.c', 'regcomp.c', 'regerror.c', 'regexec.c', 'regfree.c', 'strfmon.c', 'strfmon_l.c', 'vstrfmon.c', ] srcs_posix_use = [] foreach file : srcs_posix s_file = fs.replace_suffix(file, '.S') if file in srcs_machine message('libc/posix/' + file + ': machine overrides generic') elif s_file in srcs_machine message('libc/posix/' + s_file + ': machine overrides generic') else srcs_posix_use += file endif endforeach src_posix = files(srcs_posix_use) picolibc-1.8.11/libc/posix/pathconf.c000066400000000000000000000046461513574234600174330ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include #include #include long pathconf(const char *path, int name) { (void)path; switch (name) { case _PC_LINK_MAX: return _POSIX_LINK_MAX; case _PC_MAX_CANON: return _POSIX_MAX_CANON; case _PC_MAX_INPUT: return _POSIX_MAX_INPUT; case _PC_NAME_MAX: return _POSIX_NAME_MAX; case _PC_PATH_MAX: return _POSIX_PATH_MAX; case _PC_PIPE_BUF: return _POSIX_PIPE_BUF; case _PC_CHOWN_RESTRICTED: #ifdef _POSIX_CHOWN_RESTRICTED return _POSIX_CHOWN_RESTRICTED; #else return 0; #endif case _PC_NO_TRUNC: #ifdef _POSIX_NO_TRUNC return _POSIX_NO_TRUNC; #else return 0; #endif case _PC_VDISABLE: return 0; default: errno = EINVAL; return -1; } } picolibc-1.8.11/libc/posix/posix-local.h000066400000000000000000000033371513574234600200640ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include ssize_t __vstrfmon(char * __restrict buf, size_t size, const char * __restrict format, va_list ap); picolibc-1.8.11/libc/posix/regcomp.c000066400000000000000000001547371513574234600172740ustar00rootroot00000000000000/*- * Copyright (c) 1992, 1993, 1994 Henry Spencer. * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Henry Spencer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)regcomp.c 8.5 (Berkeley) 3/20/94 */ #define _GNU_SOURCE #include #include #include #include #include #include #include "collate.h" #include "utils.h" #include "regex2.h" #include "cclass.h" #include "cname.h" #ifdef __GNUCLIKE_PRAGMA_DIAGNOSTIC #pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wunknown-warning-option" #pragma GCC diagnostic ignored "-Wanalyzer-out-of-bounds" #pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak" #pragma GCC diagnostic ignored "-Wanalyzer-null-dereference" #endif /* * parse structure, passed up and down to avoid global variables and * other clumsinesses */ struct parse { char *next; /* next character in RE */ char *end; /* end of string (-> NUL normally) */ int error; /* has an error been seen? */ sop *strip; /* malloced strip */ sopno ssize; /* malloced strip size (allocated) */ sopno slen; /* malloced strip length (used) */ int ncsalloc; /* number of csets allocated */ struct re_guts *g; #define NPAREN 10 /* we need to remember () 1-9 for back refs */ sopno pbegin[NPAREN]; /* -> ( ([0] unused) */ sopno pend[NPAREN]; /* -> ) ([0] unused) */ }; /* ========= begin header generated by ./mkh ========= */ /* === regcomp.c === */ static void p_ere(struct parse *p, int stop); static void p_ere_exp(struct parse *p); static void p_str(struct parse *p); static void p_bre(struct parse *p, int end1, int end2); static int p_simp_re(struct parse *p, int starordinary); static int p_count(struct parse *p); static void p_bracket(struct parse *p); static void p_b_term(struct parse *p, cset *cs); static void p_b_cclass(struct parse *p, cset *cs); static void p_b_eclass(struct parse *p, cset *cs); static char p_b_symbol(struct parse *p); static char p_b_coll_elem(struct parse *p, int endc); static char othercase(int ch); static void bothcases(struct parse *p, int ch); static void ordinary(struct parse *p, int ch); static void nonnewline(struct parse *p); static void repeat(struct parse *p, sopno start, int from, int to); static int seterr(struct parse *p, int e); static cset *allocset(struct parse *p); static void freeset(struct parse *p, cset *cs); static int freezeset(struct parse *p, cset *cs); static int firstch(struct parse *p, cset *cs); static int nch(struct parse *p, cset *cs); #if used static void mcadd(struct parse *p, cset *cs, char *cp); static void mcsub(cset *cs, char *cp); static int mcin(cset *cs, char *cp); static char *mcfind(cset *cs, char *cp); #endif static void mcinvert(struct parse *p, cset *cs); static void mccase(struct parse *p, cset *cs); static int isinsets(struct re_guts *g, int c); static int samesets(struct re_guts *g, int c1, int c2); static void categorize(struct parse *p, struct re_guts *g); static sopno dupl(struct parse *p, sopno start, sopno finish); static void doemit(struct parse *p, sop op, size_t opnd); static void doinsert(struct parse *p, sop op, size_t opnd, sopno pos); static void dofwd(struct parse *p, sopno pos, sop value); static void enlarge(struct parse *p, sopno size); static void stripsnug(struct parse *p, struct re_guts *g); static void findmust(struct parse *p, struct re_guts *g); static int altoffset(sop *scan, int offset, int mccs); static void computejumps(struct parse *p, struct re_guts *g); static void computematchjumps(struct parse *p, struct re_guts *g); static sopno pluscount(struct parse *p, struct re_guts *g); /* ========= end header generated by ./mkh ========= */ static char nuls[10]; /* place to point scanner in event of error */ /* * macros for use with parse structure * BEWARE: these know that the parse structure is named `p' !!! */ #define PEEK() (*p->next) #define PEEK2() (*(p->next + 1)) #define MORE() (p->next < p->end) #define MORE2() (p->next + 1 < p->end) #define SEE(c) (MORE() && PEEK() == (c)) #define SEETWO(a, b) (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b)) #define EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0) #define EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0) #define NEXT() (p->next++) #define NEXT2() (p->next += 2) #define NEXTn(n) (p->next += (n)) #define GETNEXT() (*p->next++) #define SETERROR(e) seterr(p, (e)) #define REQUIRE(co, e) ((co) || SETERROR(e)) #define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e)) #define MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e)) #define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e)) #define EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd)) #define INSERT(op, pos) doinsert(p, (sop)(op), HERE() - (pos) + 1, pos) #define AHEAD(pos) dofwd(p, pos, HERE() - (pos)) #define ASTERN(sop, pos) EMIT(sop, HERE() - pos) #define HERE() (p->slen) #define THERE() (p->slen - 1) #define THERETHERE() (p->slen - 2) #define DROP(n) (p->slen -= (n)) #ifndef NDEBUG static int never = 0; /* for use in asserts; shuts lint up */ #else #define never 0 /* some s have bugs too */ #endif /* Macro used by computejump()/computematchjump() */ #define MIN(a, b) ((a) < (b) ? (a) : (b)) /* - regcomp - interface for parser and compilation = extern int regcomp(regex_t *__restrict, const char *__restrict, int); = #define REG_BASIC 0000 = #define REG_EXTENDED 0001 = #define REG_ICASE 0002 = #define REG_NOSUB 0004 = #define REG_NEWLINE 0010 = #define REG_NOSPEC 0020 = #define REG_PEND 0040 = #define REG_DUMP 0200 */ int /* 0 success, otherwise REG_something */ regcomp(regex_t * __restrict preg, const char * __restrict pattern, int cflags) { struct parse pa; struct re_guts *g; struct parse *p = &pa; int i; size_t len; #ifdef REDEBUG #define GOODFLAGS(f) (f) #else #define GOODFLAGS(f) ((f) & ~REG_DUMP) #endif cflags = GOODFLAGS(cflags); if ((cflags & REG_EXTENDED) && (cflags & REG_NOSPEC)) return (REG_INVARG); if (cflags & REG_PEND) { if (preg->re_endp < pattern) return (REG_INVARG); len = preg->re_endp - pattern; } else len = strlen((char *)pattern); /* do the mallocs early so failure handling is easy */ g = (struct re_guts *)malloc(sizeof(struct re_guts)); if (g == NULL) return (REG_ESPACE); p->ssize = len / (size_t)2 * (size_t)3 + (size_t)1; /* ugh */ p->strip = (sop *)malloc(p->ssize * sizeof(sop)); p->slen = 0; if (p->strip == NULL) { free((char *)g); return (REG_ESPACE); } /* set things up */ p->g = g; p->next = (char *)pattern; /* convenience; we do not modify it */ p->end = p->next + len; p->error = 0; p->ncsalloc = 0; for (i = 0; i < NPAREN; i++) { p->pbegin[i] = 0; p->pend[i] = 0; } g->csetsize = NC; g->sets = NULL; g->setbits = NULL; g->ncsets = 0; g->cflags = cflags; g->iflags = 0; g->nbol = 0; g->neol = 0; g->must = NULL; g->moffset = -1; g->charjump = NULL; g->matchjump = NULL; g->mlen = 0; g->nsub = 0; g->ncategories = 1; /* category 0 is "everything else" */ g->categories = &g->catspace[-(CHAR_MIN)]; (void)memset((char *)g->catspace, 0, NC * sizeof(cat_t)); g->backrefs = 0; /* do it */ EMIT(OEND, 0); g->firststate = THERE(); if (cflags & REG_EXTENDED) p_ere(p, OUT); else if (cflags & REG_NOSPEC) p_str(p); else p_bre(p, OUT, OUT); EMIT(OEND, 0); g->laststate = THERE(); /* tidy up loose ends and fill things in */ categorize(p, g); stripsnug(p, g); findmust(p, g); /* only use Boyer-Moore algorithm if the pattern is bigger * than three characters */ if (g->mlen > 3) { computejumps(p, g); computematchjumps(p, g); if (g->matchjump == NULL && g->charjump != NULL) { free(g->charjump); g->charjump = NULL; } } g->nplus = pluscount(p, g); g->magic = MAGIC2; preg->re_nsub = g->nsub; preg->re_g = g; preg->re_magic = MAGIC1; #ifndef REDEBUG /* not debugging, so can't rely on the assert() in regexec() */ if (g->iflags & BAD) SETERROR(REG_ASSERT); #endif /* win or lose, we're done */ if (p->error != 0) /* lose */ regfree(preg); return (p->error); } /* - p_ere - ERE parser top level, concatenation and alternation == static void p_ere(struct parse *p, int stop); */ static void p_ere(struct parse *p, int stop /* character this ERE should end at */ ) { char c; sopno prevback = 0; sopno prevfwd = 0; sopno conc; int first = 1; /* is this the first alternative? */ for (;;) { /* do a bunch of concatenated expressions */ conc = HERE(); while (MORE() && (c = PEEK()) != '|' && c != stop) p_ere_exp(p); (void)REQUIRE(HERE() != conc, REG_EMPTY); /* require nonempty */ if (!EAT('|')) break; /* NOTE BREAK OUT */ if (first) { INSERT(OCH_, conc); /* offset is wrong */ prevfwd = conc; prevback = conc; first = 0; } ASTERN(OOR1, prevback); prevback = THERE(); AHEAD(prevfwd); /* fix previous offset */ prevfwd = HERE(); EMIT(OOR2, 0); /* offset is very wrong */ } if (!first) { /* tail-end fixups */ AHEAD(prevfwd); ASTERN(O_CH, prevback); } assert(!MORE() || SEE(stop)); } /* - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op == static void p_ere_exp(struct parse *p); */ static void p_ere_exp(struct parse *p) { char c; sopno pos; int count; int count2; sopno subno; int wascaret = 0; assert(MORE()); /* caller should have ensured this */ c = GETNEXT(); pos = HERE(); switch (c) { case '(': (void)REQUIRE(MORE(), REG_EPAREN); p->g->nsub++; subno = p->g->nsub; if (subno < NPAREN) p->pbegin[subno] = HERE(); EMIT(OLPAREN, subno); if (!SEE(')')) p_ere(p, ')'); if (subno < NPAREN) { p->pend[subno] = HERE(); assert(p->pend[subno] != 0); } EMIT(ORPAREN, subno); (void)MUSTEAT(')', REG_EPAREN); break; #ifndef POSIX_MISTAKE case ')': /* happens only if no current unmatched ( */ /* * You may ask, why the ifndef? Because I didn't notice * this until slightly too late for 1003.2, and none of the * other 1003.2 regular-expression reviewers noticed it at * all. So an unmatched ) is legal POSIX, at least until * we can get it fixed. */ SETERROR(REG_EPAREN); break; #endif case '^': EMIT(OBOL, 0); p->g->iflags |= USEBOL; p->g->nbol++; wascaret = 1; break; case '$': EMIT(OEOL, 0); p->g->iflags |= USEEOL; p->g->neol++; break; case '|': SETERROR(REG_EMPTY); break; case '*': case '+': case '?': SETERROR(REG_BADRPT); break; case '.': if (p->g->cflags & REG_NEWLINE) nonnewline(p); else EMIT(OANY, 0); break; case '[': p_bracket(p); break; case '\\': (void)REQUIRE(MORE(), REG_EESCAPE); c = GETNEXT(); ordinary(p, c); break; case '{': /* okay as ordinary except if digit follows */ (void)REQUIRE(!MORE() || !isdigit((uch)PEEK()), REG_BADRPT); __fallthrough; default: ordinary(p, c); break; } if (!MORE()) return; c = PEEK(); /* we call { a repetition if followed by a digit */ if (!(c == '*' || c == '+' || c == '?' || (c == '{' && MORE2() && isdigit((uch)PEEK2())))) return; /* no repetition, we're done */ NEXT(); (void)REQUIRE(!wascaret, REG_BADRPT); switch (c) { case '*': /* implemented as +? */ /* this case does not require the (y|) trick, noKLUDGE */ INSERT(OPLUS_, pos); ASTERN(O_PLUS, pos); INSERT(OQUEST_, pos); ASTERN(O_QUEST, pos); break; case '+': INSERT(OPLUS_, pos); ASTERN(O_PLUS, pos); break; case '?': /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ INSERT(OCH_, pos); /* offset slightly wrong */ ASTERN(OOR1, pos); /* this one's right */ AHEAD(pos); /* fix the OCH_ */ EMIT(OOR2, 0); /* offset very wrong... */ AHEAD(THERE()); /* ...so fix it */ ASTERN(O_CH, THERETHERE()); break; case '{': count = p_count(p); if (EAT(',')) { if (isdigit((uch)PEEK())) { count2 = p_count(p); (void)REQUIRE(count <= count2, REG_BADBR); } else /* single number with comma */ count2 = REGEX_INFINITY; } else /* just a single number */ count2 = count; repeat(p, pos, count, count2); if (!EAT('}')) { /* error heuristics */ while (MORE() && PEEK() != '}') NEXT(); (void)REQUIRE(MORE(), REG_EBRACE); SETERROR(REG_BADBR); } break; } if (!MORE()) return; c = PEEK(); if (!(c == '*' || c == '+' || c == '?' || (c == '{' && MORE2() && isdigit((uch)PEEK2())))) return; SETERROR(REG_BADRPT); } /* - p_str - string (no metacharacters) "parser" == static void p_str(struct parse *p); */ static void p_str(struct parse *p) { (void)REQUIRE(MORE(), REG_EMPTY); while (MORE()) ordinary(p, GETNEXT()); } /* - p_bre - BRE parser top level, anchoring and concatenation == static void p_bre(struct parse *p, int end1, \ == int end2); * Giving end1 as OUT essentially eliminates the end1/end2 check. * * This implementation is a bit of a kludge, in that a trailing $ is first * taken as an ordinary character and then revised to be an anchor. The * only undesirable side effect is that '$' gets included as a character * category in such cases. This is fairly harmless; not worth fixing. * The amount of lookahead needed to avoid this kludge is excessive. */ static void p_bre(struct parse *p, int end1, /* first terminating character */ int end2 /* second terminating character */ ) { sopno start = HERE(); int first = 1; /* first subexpression? */ int wasdollar = 0; if (EAT('^')) { EMIT(OBOL, 0); p->g->iflags |= USEBOL; p->g->nbol++; } while (MORE() && !SEETWO(end1, end2)) { wasdollar = p_simp_re(p, first); first = 0; } if (wasdollar) { /* oops, that was a trailing anchor */ DROP(1); EMIT(OEOL, 0); p->g->iflags |= USEEOL; p->g->neol++; } (void)REQUIRE(HERE() != start, REG_EMPTY); /* require nonempty */ } /* - p_simp_re - parse a simple RE, an atom possibly followed by a repetition == static int p_simp_re(struct parse *p, int starordinary); */ static int /* was the simple RE an unbackslashed $? */ p_simp_re(struct parse *p, int starordinary /* is a leading * an ordinary character? */ ) { int c; int count; int count2; sopno pos; int i; sopno subno; #define BACKSL (1 << CHAR_BIT) pos = HERE(); /* repetion op, if any, covers from here */ assert(MORE()); /* caller should have ensured this */ c = GETNEXT(); if (c == '\\') { (void)REQUIRE(MORE(), REG_EESCAPE); c = BACKSL | GETNEXT(); } switch (c) { case '.': if (p->g->cflags & REG_NEWLINE) nonnewline(p); else EMIT(OANY, 0); break; case '[': p_bracket(p); break; case BACKSL | '{': SETERROR(REG_BADRPT); break; case BACKSL | '(': p->g->nsub++; subno = p->g->nsub; if (subno < NPAREN) p->pbegin[subno] = HERE(); EMIT(OLPAREN, subno); /* the MORE here is an error heuristic */ if (MORE() && !SEETWO('\\', ')')) p_bre(p, '\\', ')'); if (subno < NPAREN) { p->pend[subno] = HERE(); assert(p->pend[subno] != 0); } EMIT(ORPAREN, subno); (void)REQUIRE(EATTWO('\\', ')'), REG_EPAREN); break; case BACKSL | ')': /* should not get here -- must be user */ case BACKSL | '}': SETERROR(REG_EPAREN); break; case BACKSL | '1': case BACKSL | '2': case BACKSL | '3': case BACKSL | '4': case BACKSL | '5': case BACKSL | '6': case BACKSL | '7': case BACKSL | '8': case BACKSL | '9': i = (c & ~BACKSL) - '0'; assert(i < NPAREN); if (p->pend[i] != 0) { assert(i <= p->g->nsub); EMIT(OBACK_, i); assert(p->pbegin[i] != 0); assert(OP(p->strip[p->pbegin[i]]) == OLPAREN); assert(OP(p->strip[p->pend[i]]) == ORPAREN); (void)dupl(p, p->pbegin[i] + 1, p->pend[i]); EMIT(O_BACK, i); } else SETERROR(REG_ESUBREG); p->g->backrefs = 1; break; case '*': (void)REQUIRE(starordinary, REG_BADRPT); __fallthrough; default: ordinary(p, (char)c); break; } if (EAT('*')) { /* implemented as +? */ /* this case does not require the (y|) trick, noKLUDGE */ INSERT(OPLUS_, pos); ASTERN(O_PLUS, pos); INSERT(OQUEST_, pos); ASTERN(O_QUEST, pos); } else if (EATTWO('\\', '{')) { count = p_count(p); if (EAT(',')) { if (MORE() && isdigit((uch)PEEK())) { count2 = p_count(p); (void)REQUIRE(count <= count2, REG_BADBR); } else /* single number with comma */ count2 = REGEX_INFINITY; } else /* just a single number */ count2 = count; repeat(p, pos, count, count2); if (!EATTWO('\\', '}')) { /* error heuristics */ while (MORE() && !SEETWO('\\', '}')) NEXT(); (void)REQUIRE(MORE(), REG_EBRACE); SETERROR(REG_BADBR); } } else if (c == '$') /* $ (but not \$) ends it */ return (1); return (0); } /* - p_count - parse a repetition count == static int p_count(struct parse *p); */ static int /* the value */ p_count(struct parse *p) { int count = 0; int ndigits = 0; while (MORE() && isdigit((uch)PEEK()) && count <= DUPMAX) { count = count * 10 + (GETNEXT() - '0'); ndigits++; } (void)REQUIRE(ndigits > 0 && count <= DUPMAX, REG_BADBR); return (count); } /* - p_bracket - parse a bracketed character list == static void p_bracket(struct parse *p); * * Note a significant property of this code: if the allocset() did SETERROR, * no set operations are done. */ static void p_bracket(struct parse *p) { cset *cs = allocset(p); int invert = 0; /* Dept of Truly Sickening Special-Case Kludges */ if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", 6) == 0) { EMIT(OBOW, 0); NEXTn(6); return; } if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", 6) == 0) { EMIT(OEOW, 0); NEXTn(6); return; } if (p->error != 0) /* don't mess things up further */ return; if (EAT('^')) invert++; /* make note to invert set at end */ if (EAT(']')) CHadd(cs, ']'); else if (EAT('-')) CHadd(cs, '-'); while (MORE() && PEEK() != ']' && !SEETWO('-', ']')) p_b_term(p, cs); if (EAT('-')) CHadd(cs, '-'); (void)MUSTEAT(']', REG_EBRACK); if (p->g->cflags & REG_ICASE) { int i; int ci; for (i = p->g->csetsize - 1; i >= 0; i--) if (CHIN(cs, i) && isalpha(i)) { ci = othercase(i); if (ci != i) CHadd(cs, ci); } if (cs->multis != NULL) mccase(p, cs); } if (invert) { int i; for (i = p->g->csetsize - 1; i >= 0; i--) if (CHIN(cs, i)) CHsub(cs, i); else CHadd(cs, i); if (p->g->cflags & REG_NEWLINE) CHsub(cs, '\n'); if (cs->multis != NULL) mcinvert(p, cs); } assert(cs->multis == NULL); /* xxx */ if (nch(p, cs) == 1) { /* optimize singleton sets */ ordinary(p, firstch(p, cs)); freeset(p, cs); } else EMIT(OANYOF, freezeset(p, cs)); } /* - p_b_term - parse one term of a bracketed character list == static void p_b_term(struct parse *p, cset *cs); */ static void p_b_term(struct parse *p, cset *cs) { char c; char start, finish; int i; /* classify what we've got */ switch ((MORE()) ? PEEK() : '\0') { case '[': c = (MORE2()) ? PEEK2() : '\0'; break; case '-': SETERROR(REG_ERANGE); return; /* NOTE RETURN */ break; default: c = '\0'; break; } switch (c) { case ':': /* character class */ NEXT2(); (void)REQUIRE(MORE(), REG_EBRACK); c = PEEK(); (void)REQUIRE(c != '-' && c != ']', REG_ECTYPE); p_b_cclass(p, cs); (void)REQUIRE(MORE(), REG_EBRACK); (void)REQUIRE(EATTWO(':', ']'), REG_ECTYPE); break; case '=': /* equivalence class */ NEXT2(); (void)REQUIRE(MORE(), REG_EBRACK); c = PEEK(); (void)REQUIRE(c != '-' && c != ']', REG_ECOLLATE); p_b_eclass(p, cs); (void)REQUIRE(MORE(), REG_EBRACK); (void)REQUIRE(EATTWO('=', ']'), REG_ECOLLATE); break; default: /* symbol, ordinary character, or range */ /* xxx revision needed for multichar stuff */ start = p_b_symbol(p); if (SEE('-') && MORE2() && PEEK2() != ']') { /* range */ NEXT(); if (EAT('-')) finish = '-'; else finish = p_b_symbol(p); } else finish = start; if (start == finish) CHadd(cs, start); else { #ifdef __HAVE_REAL_STRCOLL (void)REQUIRE(__collate_range_cmp(start, finish) <= 0, REG_ERANGE); for (i = CHAR_MIN; i <= CHAR_MAX; i++) { if (__collate_range_cmp(start, i) <= 0 && __collate_range_cmp(i, finish) <= 0) CHadd(cs, i); } #else (void)REQUIRE((uch)start <= (uch)finish, REG_ERANGE); for (i = (uch)start; i <= (uch)finish; i++) CHadd(cs, i); #endif } break; } } /* - p_b_cclass - parse a character-class name and deal with it == static void p_b_cclass(struct parse *p, cset *cs); */ static void p_b_cclass(struct parse *p, cset *cs) { int c; char *sp = p->next; const struct cclass *cp; size_t len; while (MORE() && isalpha((uch)PEEK())) NEXT(); len = p->next - sp; for (cp = cclasses; cp->name != NULL; cp++) if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0') break; if (cp->name == NULL) { /* oops, didn't find it */ SETERROR(REG_ECTYPE); return; } switch (cp->fidx) { case CALNUM: for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (isalnum((uch)c)) CHadd(cs, c); break; case CALPHA: for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (isalpha((uch)c)) CHadd(cs, c); break; case CBLANK: for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (isblank((uch)c)) CHadd(cs, c); break; case CCNTRL: for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (iscntrl((uch)c)) CHadd(cs, c); break; case CDIGIT: for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (isdigit((uch)c)) CHadd(cs, c); break; case CGRAPH: for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (isgraph((uch)c)) CHadd(cs, c); break; case CLOWER: for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (islower((uch)c)) CHadd(cs, c); break; case CPRINT: for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (isprint((uch)c)) CHadd(cs, c); break; case CPUNCT: for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (ispunct((uch)c)) CHadd(cs, c); break; case CSPACE: for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (isspace((uch)c)) CHadd(cs, c); break; case CUPPER: for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (isupper((uch)c)) CHadd(cs, c); break; case CXDIGIT: for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (isxdigit((uch)c)) CHadd(cs, c); break; } #if 0 for (u = cp->multis; *u != '\0'; u += strlen(u) + 1) MCadd(p, cs, u); #endif } /* - p_b_eclass - parse an equivalence-class name and deal with it == static void p_b_eclass(struct parse *p, cset *cs); * * This implementation is incomplete. xxx */ static void p_b_eclass(struct parse *p, cset *cs) { char c; c = p_b_coll_elem(p, '='); CHadd(cs, c); } /* - p_b_symbol - parse a character or [..]ed multicharacter collating symbol == static char p_b_symbol(struct parse *p); */ static char /* value of symbol */ p_b_symbol(struct parse *p) { char value; (void)REQUIRE(MORE(), REG_EBRACK); if (!EATTWO('[', '.')) return (GETNEXT()); /* collating symbol */ value = p_b_coll_elem(p, '.'); (void)REQUIRE(EATTWO('.', ']'), REG_ECOLLATE); return (value); } /* - p_b_coll_elem - parse a collating-element name and look it up == static char p_b_coll_elem(struct parse *p, int endc); */ static char /* value of collating element */ p_b_coll_elem(struct parse *p, int endc /* name ended by endc,']' */ ) { char *sp = p->next; const struct cname *cp; int len; while (MORE() && !SEETWO(endc, ']')) NEXT(); if (!MORE()) { SETERROR(REG_EBRACK); return (0); } len = p->next - sp; for (cp = cnames; cp->name != NULL; cp++) if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0') return (cp->code); /* known name */ if (len == 1) return (*sp); /* single character */ SETERROR(REG_ECOLLATE); /* neither */ return (0); } /* - othercase - return the case counterpart of an alphabetic == static char othercase(int ch); */ static char /* if no counterpart, return ch */ othercase(int ch) { ch = (uch)ch; assert(isalpha(ch)); if (isupper(ch)) return (tolower(ch)); else if (islower(ch)) return (toupper(ch)); else /* peculiar, but could happen */ return (ch); } /* - bothcases - emit a dualcase version of a two-case character == static void bothcases(struct parse *p, int ch); * * Boy, is this implementation ever a kludge... */ static void bothcases(struct parse *p, int ch) { char *oldnext = p->next; char *oldend = p->end; char bracket[3]; ch = (uch)ch; assert(othercase(ch) != ch); /* p_bracket() would recurse */ p->next = bracket; p->end = bracket + 2; bracket[0] = ch; bracket[1] = ']'; bracket[2] = '\0'; p_bracket(p); assert(p->next == bracket + 2); p->next = oldnext; p->end = oldend; } /* - ordinary - emit an ordinary character == static void ordinary(struct parse *p, int ch); */ static void ordinary(struct parse *p, int ch) { cat_t *cap = p->g->categories; if ((p->g->cflags & REG_ICASE) && isalpha((uch)ch) && othercase(ch) != ch) bothcases(p, ch); else { EMIT(OCHAR, (uch)ch); if (cap[ch] == 0) cap[ch] = p->g->ncategories++; } } /* - nonnewline - emit REG_NEWLINE version of OANY == static void nonnewline(struct parse *p); * * Boy, is this implementation ever a kludge... */ static void nonnewline(struct parse *p) { char *oldnext = p->next; char *oldend = p->end; char bracket[4]; p->next = bracket; p->end = bracket + 3; bracket[0] = '^'; bracket[1] = '\n'; bracket[2] = ']'; bracket[3] = '\0'; p_bracket(p); assert(p->next == bracket + 3); p->next = oldnext; p->end = oldend; } /* - repeat - generate code for a bounded repetition, recursively if needed == static void repeat(struct parse *p, sopno start, int from, int to); */ static void repeat(struct parse *p, sopno start, /* operand from here to end of strip */ int from, /* repeated from this number */ int to /* to this number of times (maybe INFINITY) */ ) { sopno finish = HERE(); #define N 2 #define INF 3 #define REP(f, t) ((f) * 8 + (t)) #define MAP(n) (((n) <= 1) ? (n) : ((n) == REGEX_INFINITY) ? INF : N) sopno copy; if (p->error != 0) /* head off possible runaway recursion */ return; assert(from <= to); switch (REP(MAP(from), MAP(to))) { case REP(0, 0): /* must be user doing this */ DROP(finish - start); /* drop the operand */ break; case REP(0, 1): /* as x{1,1}? */ case REP(0, N): /* as x{1,n}? */ case REP(0, INF): /* as x{1,}? */ /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ INSERT(OCH_, start); /* offset is wrong... */ repeat(p, start + 1, 1, to); ASTERN(OOR1, start); AHEAD(start); /* ... fix it */ EMIT(OOR2, 0); AHEAD(THERE()); ASTERN(O_CH, THERETHERE()); break; case REP(1, 1): /* trivial case */ /* done */ break; case REP(1, N): /* as x?x{1,n-1} */ /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ INSERT(OCH_, start); ASTERN(OOR1, start); AHEAD(start); EMIT(OOR2, 0); /* offset very wrong... */ AHEAD(THERE()); /* ...so fix it */ ASTERN(O_CH, THERETHERE()); copy = dupl(p, start + 1, finish + 1); assert(copy == finish + 4); repeat(p, copy, 1, to - 1); break; case REP(1, INF): /* as x+ */ INSERT(OPLUS_, start); ASTERN(O_PLUS, start); break; case REP(N, N): /* as xx{m-1,n-1} */ copy = dupl(p, start, finish); repeat(p, copy, from - 1, to - 1); break; case REP(N, INF): /* as xx{n-1,INF} */ copy = dupl(p, start, finish); repeat(p, copy, from - 1, to); break; default: /* "can't happen" */ SETERROR(REG_ASSERT); /* just in case */ break; } } /* - seterr - set an error condition == static int seterr(struct parse *p, int e); */ static int /* useless but makes type checking happy */ seterr(struct parse *p, int e) { if (p->error == 0) /* keep earliest error condition */ p->error = e; free(p->g->sets); free(p->g->setbits); p->g->sets = NULL; p->g->setbits = NULL; p->next = nuls; /* try to bring things to a halt */ p->end = nuls; return (0); /* make the return value well-defined */ } /* - allocset - allocate a set of characters for [] == static cset *allocset(struct parse *p); */ static cset * allocset(struct parse *p) { int no = p->g->ncsets++; size_t nc; size_t nbytes; cset *cs; size_t css = (size_t)p->g->csetsize; int i; uch *setbits; if (no >= p->ncsalloc) { /* need another column of space */ p->ncsalloc += CHAR_BIT; nc = p->ncsalloc; assert(nc % CHAR_BIT == 0); nbytes = nc / CHAR_BIT * css; cs = realloc(p->g->sets, nc * sizeof(cset)); if (!cs) { SETERROR(REG_ESPACE); return NULL; } p->g->sets = cs; setbits = realloc(p->g->setbits, nbytes); if (!setbits) { SETERROR(REG_ESPACE); return NULL; } p->g->setbits = setbits; for (i = 0; i < no; i++) cs[i].ptr = setbits + css * (i / CHAR_BIT); (void)memset(setbits + (nbytes - css), 0, css); } cs = &p->g->sets[no]; cs->ptr = p->g->setbits + css * ((no) / CHAR_BIT); cs->mask = 1 << ((no) % CHAR_BIT); cs->hash = 0; cs->smultis = 0; cs->multis = NULL; return (cs); } /* - freeset - free a now-unused set == static void freeset(struct parse *p, cset *cs); */ static void freeset(struct parse *p, cset *cs) { size_t i; cset *top = &p->g->sets[p->g->ncsets]; size_t css = (size_t)p->g->csetsize; for (i = 0; i < css; i++) CHsub(cs, i); if (cs == top - 1) /* recover only the easy case */ p->g->ncsets--; } /* - freezeset - final processing on a set of characters == static int freezeset(struct parse *p, cset *cs); * * The main task here is merging identical sets. This is usually a waste * of time (although the hash code minimizes the overhead), but can win * big if REG_ICASE is being used. REG_ICASE, by the way, is why the hash * is done using addition rather than xor -- all ASCII [aA] sets xor to * the same value! */ static int /* set number */ freezeset(struct parse *p, cset *cs) { short h = cs->hash; size_t i; cset *top = &p->g->sets[p->g->ncsets]; cset *cs2; size_t css = (size_t)p->g->csetsize; /* look for an earlier one which is the same */ for (cs2 = &p->g->sets[0]; cs2 < top; cs2++) if (cs2->hash == h && cs2 != cs) { /* maybe */ for (i = 0; i < css; i++) if (!!CHIN(cs2, i) != !!CHIN(cs, i)) break; /* no */ if (i == css) break; /* yes */ } if (cs2 < top) { /* found one */ freeset(p, cs); cs = cs2; } return ((int)(cs - p->g->sets)); } /* - firstch - return first character in a set (which must have at least one) == static int firstch(struct parse *p, cset *cs); */ static int /* character; there is no "none" value */ firstch(struct parse *p, cset *cs) { size_t i; size_t css = (size_t)p->g->csetsize; for (i = 0; i < css; i++) if (CHIN(cs, i)) return ((char)i); assert(never); return (0); /* arbitrary */ } /* - nch - number of characters in a set == static int nch(struct parse *p, cset *cs); */ static int nch(struct parse *p, cset *cs) { size_t i; size_t css = (size_t)p->g->csetsize; int n = 0; for (i = 0; i < css; i++) if (CHIN(cs, i)) n++; return (n); } #if used /* - mcadd - add a collating element to a cset == static void mcadd(struct parse *p, cset *cs, \ == char *cp); */ static void mcadd(struct parse *p, cset *cs, char *cp) { size_t oldend = cs->smultis; cs->smultis += strlen(cp) + 1; if (cs->multis == NULL) cs->multis = malloc(cs->smultis); else cs->multis = reallocf(cs->multis, cs->smultis); if (cs->multis == NULL) { SETERROR(REG_ESPACE); return; } (void)strcpy(cs->multis + oldend - 1, cp); cs->multis[cs->smultis - 1] = '\0'; } /* - mcsub - subtract a collating element from a cset == static void mcsub(cset *cs, char *cp); */ static void mcsub(cset *cs, char *cp) { char *fp = mcfind(cs, cp); size_t len = strlen(fp); assert(fp != NULL); (void)memmove(fp, fp + len + 1, cs->smultis - (fp + len + 1 - cs->multis)); cs->smultis -= len; if (cs->smultis == 0) { free(cs->multis); cs->multis = NULL; return; } cs->multis = reallocf(cs->multis, cs->smultis); assert(cs->multis != NULL); } /* - mcin - is a collating element in a cset? == static int mcin(cset *cs, char *cp); */ static int mcin(cset *cs, char *cp) { return (mcfind(cs, cp) != NULL); } /* - mcfind - find a collating element in a cset == static char *mcfind(cset *cs, char *cp); */ static char * mcfind(cset *cs, char *cp) { char *p; if (cs->multis == NULL) return (NULL); for (p = cs->multis; *p != '\0'; p += strlen(p) + 1) if (strcmp(cp, p) == 0) return (p); return (NULL); } #endif /* - mcinvert - invert the list of collating elements in a cset == static void mcinvert(struct parse *p, cset *cs); * * This would have to know the set of possibilities. Implementation * is deferred. */ static void mcinvert(struct parse *p, cset *cs) { (void)p; (void)cs; assert(cs->multis == NULL); /* xxx */ } /* - mccase - add case counterparts of the list of collating elements in a cset == static void mccase(struct parse *p, cset *cs); * * This would have to know the set of possibilities. Implementation * is deferred. */ static void mccase(struct parse *p, cset *cs) { (void)p; (void)cs; assert(cs->multis == NULL); /* xxx */ } /* - isinsets - is this character in any sets? == static int isinsets(struct re_guts *g, int c); */ static int /* predicate */ isinsets(struct re_guts *g, int c) { uch *col; int i; int ncols = (g->ncsets + (CHAR_BIT - 1)) / CHAR_BIT; unsigned uc = (uch)c; for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize) if (col[uc] != 0) return (1); return (0); } /* - samesets - are these two characters in exactly the same sets? == static int samesets(struct re_guts *g, int c1, int c2); */ static int /* predicate */ samesets(struct re_guts *g, int c1, int c2) { uch *col; int i; int ncols = (g->ncsets + (CHAR_BIT - 1)) / CHAR_BIT; unsigned uc1 = (uch)c1; unsigned uc2 = (uch)c2; for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize) if (col[uc1] != col[uc2]) return (0); return (1); } /* - categorize - sort out character categories == static void categorize(struct parse *p, struct re_guts *g); */ static void categorize(struct parse *p, struct re_guts *g) { cat_t *cats = g->categories; int c; int c2; cat_t cat; /* avoid making error situations worse */ if (p->error != 0) return; for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (cats[c] == 0 && isinsets(g, c)) { cat = g->ncategories++; cats[c] = cat; for (c2 = c + 1; c2 <= CHAR_MAX; c2++) if (cats[c2] == 0 && samesets(g, c, c2)) cats[c2] = cat; } } /* - dupl - emit a duplicate of a bunch of sops == static sopno dupl(struct parse *p, sopno start, sopno finish); */ static sopno /* start of duplicate */ dupl(struct parse *p, sopno start, /* from here */ sopno finish /* to this less one */ ) { sopno ret = HERE(); sopno len = finish - start; assert(finish >= start); if (len == 0) return (ret); enlarge(p, p->ssize + len); /* this many unexpected additions */ assert(p->ssize >= p->slen + len); (void)memcpy((char *)(p->strip + p->slen), (char *)(p->strip + start), (size_t)len * sizeof(sop)); p->slen += len; return (ret); } /* - doemit - emit a strip operator == static void doemit(struct parse *p, sop op, size_t opnd); * * It might seem better to implement this as a macro with a function as * hard-case backup, but it's just too big and messy unless there are * some changes to the data structures. Maybe later. */ static void doemit(struct parse *p, sop op, size_t opnd) { /* avoid making error situations worse */ if (p->error != 0) return; /* deal with oversize operands ("can't happen", more or less) */ assert(opnd < 1 << OPSHIFT); /* deal with undersized strip */ if (p->slen >= p->ssize) enlarge(p, (p->ssize + 1) / 2 * 3); /* +50% */ assert(p->slen < p->ssize); /* finally, it's all reduced to the easy case */ p->strip[p->slen++] = SOP(op, opnd); } /* - doinsert - insert a sop into the strip == static void doinsert(struct parse *p, sop op, size_t opnd, sopno pos); */ static void doinsert(struct parse *p, sop op, size_t opnd, sopno pos) { sopno sn; sop s; int i; /* avoid making error situations worse */ if (p->error != 0) return; sn = HERE(); EMIT(op, opnd); /* do checks, ensure space */ assert(HERE() == sn + 1); s = p->strip[sn]; /* adjust paren pointers */ assert(pos > 0); for (i = 1; i < NPAREN; i++) { if (p->pbegin[i] >= pos) { p->pbegin[i]++; } if (p->pend[i] >= pos) { p->pend[i]++; } } memmove((char *)&p->strip[pos + 1], (char *)&p->strip[pos], (HERE() - pos - 1) * sizeof(sop)); p->strip[pos] = s; } /* - dofwd - complete a forward reference == static void dofwd(struct parse *p, sopno pos, sop value); */ static void dofwd(struct parse *p, sopno pos, sop value) { /* avoid making error situations worse */ if (p->error != 0) return; assert(value < 1 << OPSHIFT); p->strip[pos] = OP(p->strip[pos]) | value; } /* - enlarge - enlarge the strip == static void enlarge(struct parse *p, sopno size); */ static void enlarge(struct parse *p, sopno size) { sop *sp; if (p->ssize >= size) return; sp = (sop *)realloc(p->strip, size * sizeof(sop)); if (sp == NULL) { SETERROR(REG_ESPACE); return; } p->strip = sp; p->ssize = size; } /* - stripsnug - compact the strip == static void stripsnug(struct parse *p, struct re_guts *g); */ static void stripsnug(struct parse *p, struct re_guts *g) { g->nstates = p->slen; g->strip = (sop *)realloc((char *)p->strip, p->slen * sizeof(sop)); if (g->strip == NULL) { SETERROR(REG_ESPACE); g->strip = p->strip; } } /* - findmust - fill in must and mlen with longest mandatory literal string == static void findmust(struct parse *p, struct re_guts *g); * * This algorithm could do fancy things like analyzing the operands of | * for common subsequences. Someday. This code is simple and finds most * of the interesting cases. * * Note that must and mlen got initialized during setup. */ static void findmust(struct parse *p, struct re_guts *g) { sop *scan; sop *start = NULL; sop *newstart = NULL; sopno newlen; sop s; char *cp; sopno i; int offset; int cs, mccs; /* avoid making error situations worse */ if (p->error != 0) return; /* Find out if we can handle OANYOF or not */ mccs = 0; for (cs = 0; cs < g->ncsets; cs++) if (g->sets[cs].multis != NULL) mccs = 1; /* find the longest OCHAR sequence in strip */ newlen = 0; offset = 0; g->moffset = 0; scan = g->strip + 1; do { s = *scan++; switch (OP(s)) { case OCHAR: /* sequence member */ if (newlen == 0) /* new sequence */ newstart = scan - 1; newlen++; break; case OPLUS_: /* things that don't break one */ case OLPAREN: case ORPAREN: break; case OQUEST_: /* things that must be skipped */ case OCH_: offset = altoffset(scan, offset, mccs); scan--; do { scan += OPND(s); s = *scan; /* assert() interferes w debug printouts */ if (OP(s) != O_QUEST && OP(s) != O_CH && OP(s) != OOR2) { g->iflags |= BAD; return; } } while (OP(s) != O_QUEST && OP(s) != O_CH); __fallthrough; case OBOW: /* things that break a sequence */ case OEOW: case OBOL: case OEOL: case O_QUEST: case O_CH: case OEND: if (newlen > g->mlen) { /* ends one */ start = newstart; g->mlen = newlen; if (offset > -1) { g->moffset += offset; offset = newlen; } else g->moffset = offset; } else { if (offset > -1) offset += newlen; } newlen = 0; break; case OANY: if (newlen > g->mlen) { /* ends one */ start = newstart; g->mlen = newlen; if (offset > -1) { g->moffset += offset; offset = newlen; } else g->moffset = offset; } else { if (offset > -1) offset += newlen; } if (offset > -1) offset++; newlen = 0; break; case OANYOF: /* may or may not invalidate offset */ /* First, everything as OANY */ if (newlen > g->mlen) { /* ends one */ start = newstart; g->mlen = newlen; if (offset > -1) { g->moffset += offset; offset = newlen; } else g->moffset = offset; } else { if (offset > -1) offset += newlen; } if (offset > -1) offset++; newlen = 0; /* And, now, if we found out we can't deal with * it, make offset = -1. */ if (mccs) offset = -1; break; default: /* Anything here makes it impossible or too hard * to calculate the offset -- so we give up; * save the last known good offset, in case the * must sequence doesn't occur later. */ if (newlen > g->mlen) { /* ends one */ start = newstart; g->mlen = newlen; if (offset > -1) g->moffset += offset; else g->moffset = offset; } offset = -1; newlen = 0; break; } } while (OP(s) != OEND); if (g->mlen == 0 || !start) { /* there isn't one */ g->moffset = -1; return; } /* turn it into a character string */ g->must = malloc((size_t)g->mlen + 1); if (g->must == NULL) { /* argh; just forget it */ g->mlen = 0; g->moffset = -1; return; } cp = g->must; scan = start; for (i = g->mlen; i > 0; i--) { while (OP(s = *scan++) != OCHAR) continue; assert(cp < g->must + g->mlen); *cp++ = (char)OPND(s); } assert(cp == g->must + g->mlen); *cp++ = '\0'; /* just on general principles */ } /* - altoffset - choose biggest offset among multiple choices == static int altoffset(sop *scan, int offset, int mccs); * * Compute, recursively if necessary, the largest offset among multiple * re paths. */ static int altoffset(sop *scan, int offset, int mccs) { int largest; int try; sop s; /* If we gave up already on offsets, return */ if (offset == -1) return -1; largest = 0; try = 0; s = *scan++; while (OP(s) != O_QUEST && OP(s) != O_CH) { switch (OP(s)) { case OOR1: if (try > largest) largest = try; try = 0; break; case OQUEST_: case OCH_: try = altoffset(scan, try, mccs); if (try == -1) return -1; scan--; do { scan += OPND(s); s = *scan; if (OP(s) != O_QUEST && OP(s) != O_CH && OP(s) != OOR2) return -1; } while (OP(s) != O_QUEST && OP(s) != O_CH); /* We must skip to the next position, or we'll * leave altoffset() too early. */ scan++; break; case OANYOF: if (mccs) return -1; __fallthrough; case OCHAR: case OANY: try++; case OBOW: case OEOW: case OLPAREN: case ORPAREN: case OOR2: break; default: try = -1; break; } if (try == -1) return -1; s = *scan++; } if (try > largest) largest = try; return largest + offset; } /* - computejumps - compute char jumps for BM scan == static void computejumps(struct parse *p, struct re_guts *g); * * This algorithm assumes g->must exists and is has size greater than * zero. It's based on the algorithm found on Computer Algorithms by * Sara Baase. * * A char jump is the number of characters one needs to jump based on * the value of the character from the text that was mismatched. */ static void computejumps(struct parse *p, struct re_guts *g) { int ch; int mindex; /* Avoid making errors worse */ if (p->error != 0) return; g->charjump = (int *)malloc(NC * sizeof(int)); if (g->charjump == NULL) /* Not a fatal error */ return; /* If the character does not exist in the pattern, the jump * is equal to the number of characters in the pattern. */ for (ch = 0; ch < NC; ch++) g->charjump[ch] = g->mlen; /* If the character does exist, compute the jump that would * take us to the last character in the pattern equal to it * (notice that we match right to left, so that last character * is the first one that would be matched). */ for (mindex = 0; mindex < g->mlen; mindex++) g->charjump[(unsigned char)g->must[mindex]] = g->mlen - mindex - 1; } /* - computematchjumps - compute match jumps for BM scan == static void computematchjumps(struct parse *p, struct re_guts *g); * * This algorithm assumes g->must exists and is has size greater than * zero. It's based on the algorithm found on Computer Algorithms by * Sara Baase. * * A match jump is the number of characters one needs to advance based * on the already-matched suffix. * Notice that all values here are minus (g->mlen-1), because of the way * the search algorithm works. */ static void computematchjumps(struct parse *p, struct re_guts *g) { int mindex; /* General "must" iterator */ int suffix; /* Keeps track of matching suffix */ int ssuffix; /* Keeps track of suffixes' suffix */ int *pmatches; /* pmatches[k] points to the next i * such that i+1...mlen is a substring * of k+1...k+mlen-i-1 */ /* Avoid making errors worse */ if (p->error != 0) return; pmatches = (int *)calloc(g->mlen + 1, sizeof(unsigned int)); if (pmatches == NULL) { g->matchjump = NULL; return; } g->matchjump = (int *)calloc(g->mlen, sizeof(unsigned int)); if (g->matchjump == NULL) { /* Not a fatal error */ free(pmatches); return; } /* Set maximum possible jump for each character in the pattern */ for (mindex = 0; mindex < g->mlen; mindex++) g->matchjump[mindex] = 2 * g->mlen - mindex - 1; /* Compute pmatches[] */ for (mindex = g->mlen - 1, suffix = g->mlen; mindex >= 0; mindex--, suffix--) { pmatches[mindex] = suffix; /* If a mismatch is found, interrupting the substring, * compute the matchjump for that position. If no * mismatch is found, then a text substring mismatched * against the suffix will also mismatch against the * substring. */ while (suffix < g->mlen && g->must[mindex] != g->must[suffix]) { g->matchjump[suffix] = MIN(g->matchjump[suffix], g->mlen - mindex - 1); suffix = pmatches[suffix]; } } /* Compute the matchjump up to the last substring found to jump * to the beginning of the largest must pattern prefix matching * it's own suffix. */ for (mindex = 0; mindex <= suffix; mindex++) g->matchjump[mindex] = MIN(g->matchjump[mindex], g->mlen + suffix - mindex); ssuffix = pmatches[suffix]; while (suffix < g->mlen) { while (suffix <= ssuffix && suffix < g->mlen) { g->matchjump[suffix] = MIN(g->matchjump[suffix], g->mlen + ssuffix - suffix); suffix++; } if (suffix < g->mlen) ssuffix = pmatches[ssuffix]; } free(pmatches); } /* - pluscount - count + nesting == static sopno pluscount(struct parse *p, struct re_guts *g); */ static sopno /* nesting depth */ pluscount(struct parse *p, struct re_guts *g) { sop *scan; sop s; sopno plusnest = 0; sopno maxnest = 0; if (p->error != 0) return (0); /* there may not be an OEND */ scan = g->strip + 1; do { s = *scan++; switch (OP(s)) { case OPLUS_: plusnest++; break; case O_PLUS: if (plusnest > maxnest) maxnest = plusnest; plusnest--; break; } } while (OP(s) != OEND); if (plusnest != 0) g->iflags |= BAD; return (maxnest); } picolibc-1.8.11/libc/posix/regerror.c000066400000000000000000000133231513574234600174500ustar00rootroot00000000000000/*- * Copyright (c) 1992, 1993, 1994 Henry Spencer. * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Henry Spencer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)regerror.c 8.4 (Berkeley) 3/20/94 */ #ifndef _NO_REGEX #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94"; #endif /* LIBC_SCCS and not lint */ #include #include #include #include #include #include #include "utils.h" /* ========= begin header generated by ./mkh ========= */ /* === regerror.c === */ static const char *regatoi(const regex_t *preg, char *localbuf); /* ========= end header generated by ./mkh ========= */ /* = #define REG_NOMATCH 1 = #define REG_BADPAT 2 = #define REG_ECOLLATE 3 = #define REG_ECTYPE 4 = #define REG_EESCAPE 5 = #define REG_ESUBREG 6 = #define REG_EBRACK 7 = #define REG_EPAREN 8 = #define REG_EBRACE 9 = #define REG_BADBR 10 = #define REG_ERANGE 11 = #define REG_ESPACE 12 = #define REG_BADRPT 13 = #define REG_EMPTY 14 = #define REG_ASSERT 15 = #define REG_INVARG 16 = #define REG_ATOI 255 // convert name to number (!) = #define REG_ITOA 0400 // convert number to name (!) */ static const struct rerr { int code; const char *name; const char *explain; } rerrs[] = { { REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match" }, { REG_BADPAT, "REG_BADPAT", "invalid regular expression" }, { REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element" }, { REG_ECTYPE, "REG_ECTYPE", "invalid character class" }, { REG_EESCAPE, "REG_EESCAPE", "trailing backslash (\\)" }, { REG_ESUBREG, "REG_ESUBREG", "invalid backreference number" }, { REG_EBRACK, "REG_EBRACK", "brackets ([ ]) not balanced" }, { REG_EPAREN, "REG_EPAREN", "parentheses not balanced" }, { REG_EBRACE, "REG_EBRACE", "braces not balanced" }, { REG_BADBR, "REG_BADBR", "invalid repetition count(s)" }, { REG_ERANGE, "REG_ERANGE", "invalid character range" }, { REG_ESPACE, "REG_ESPACE", "out of memory" }, { REG_BADRPT, "REG_BADRPT", "repetition-operator operand invalid" }, { REG_EMPTY, "REG_EMPTY", "empty (sub)expression" }, { REG_ASSERT, "REG_ASSERT", "\"can't happen\" -- you found a bug" }, { REG_INVARG, "REG_INVARG", "invalid argument to regex routine" }, { 0, "", "*** unknown regexp error code ***" } }; /* - regerror - the interface to error numbers = extern size_t regerror(int, const regex_t *__restrict, = char *__restrict, size_t); */ /* ARGSUSED */ size_t regerror(int errcode, const regex_t * __restrict preg, char * __restrict errbuf, size_t errbuf_size) { const struct rerr *r; size_t len; int target = errcode & ~REG_ITOA; const char *s; char convbuf[50]; if (errcode == REG_ATOI) s = regatoi(preg, convbuf); else { for (r = rerrs; r->code != 0; r++) if (r->code == target) break; if (errcode & REG_ITOA) { if (r->code != 0) (void)strcpy(convbuf, r->name); else sprintf(convbuf, "REG_0x%x", target); assert(strlen(convbuf) < sizeof(convbuf)); s = convbuf; } else s = r->explain; } len = strlen(s) + 1; if (errbuf_size > 0) { if (errbuf_size > len) (void)strcpy(errbuf, s); else { (void)strncpy(errbuf, s, errbuf_size - 1); errbuf[errbuf_size - 1] = '\0'; } } return (len); } /* - regatoi - internal routine to implement REG_ATOI == static char *regatoi(const regex_t *preg, char *localbuf); */ static const char * regatoi(const regex_t *preg, char *localbuf) { const struct rerr *r; for (r = rerrs; r->code != 0; r++) if (strcmp(r->name, preg->re_endp) == 0) break; sprintf(localbuf, "%d", r->code); return (localbuf); } #endif /* !_NO_REGEX */ picolibc-1.8.11/libc/posix/regex2.h000066400000000000000000000173711513574234600170310ustar00rootroot00000000000000/*- * Copyright (c) 1992, 1993, 1994 Henry Spencer. * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Henry Spencer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)regex2.h 8.4 (Berkeley) 3/20/94 * $FreeBSD: src/lib/libc/regex/regex2.h,v 1.6 2002/03/22 23:41:56 obrien Exp $ */ /* * First, the stuff that ends up in the outside-world include file = typedef off_t regoff_t; = typedef struct { = unsigned int re_magic; = size_t re_nsub; // number of parenthesized subexpressions = const char *re_endp; // end pointer for REG_PEND = struct re_guts *re_g; // none of your business :-) = } regex_t; = typedef struct { = regoff_t rm_so; // start of match = regoff_t rm_eo; // end of match = } regmatch_t; */ /* * internals of regex_t */ #define MAGIC1 ((((unsigned int)'r' ^ 0200) << 8) | 'e') /* * The internal representation is a *strip*, a sequence of * operators ending with an endmarker. (Some terminology etc. is a * historical relic of earlier versions which used multiple strips.) * Certain oddities in the representation are there to permit running * the machinery backwards; in particular, any deviation from sequential * flow must be marked at both its source and its destination. Some * fine points: * * - OPLUS_ and O_PLUS are *inside* the loop they create. * - OQUEST_ and O_QUEST are *outside* the bypass they create. * - OCH_ and O_CH are *outside* the multi-way branch they create, while * OOR1 and OOR2 are respectively the end and the beginning of one of * the branches. Note that there is an implicit OOR2 following OCH_ * and an implicit OOR1 preceding O_CH. * * In state representations, an operator's bit is on to signify a state * immediately *preceding* "execution" of that operator. */ typedef unsigned long sop; /* strip operator */ typedef long sopno; #define OPRMASK 0xf8000000L #define OPDMASK 0x07ffffffL #define OPSHIFT ((unsigned)27) #define OP(n) ((sop)(n) & OPRMASK) #define OPND(n) ((sop)(n) & OPDMASK) #define SOP(op, opnd) ((sop)(op) | (sop)(opnd)) /* operators meaning operand */ /* (back, fwd are offsets) */ #define OEND (1UL << OPSHIFT) /* endmarker - */ #define OCHAR (2UL << OPSHIFT) /* character unsigned char */ #define OBOL (3UL << OPSHIFT) /* left anchor - */ #define OEOL (4UL << OPSHIFT) /* right anchor - */ #define OANY (5UL << OPSHIFT) /* . - */ #define OANYOF (6UL << OPSHIFT) /* [...] set number */ #define OBACK_ (7UL << OPSHIFT) /* begin \d paren number */ #define O_BACK (8UL << OPSHIFT) /* end \d paren number */ #define OPLUS_ (9UL << OPSHIFT) /* + prefix fwd to suffix */ #define O_PLUS (10UL << OPSHIFT) /* + suffix back to prefix */ #define OQUEST_ (11UL << OPSHIFT) /* ? prefix fwd to suffix */ #define O_QUEST (12UL << OPSHIFT) /* ? suffix back to prefix */ #define OLPAREN (13UL << OPSHIFT) /* ( fwd to ) */ #define ORPAREN (14UL << OPSHIFT) /* ) back to ( */ #define OCH_ (15UL << OPSHIFT) /* begin choice fwd to OOR2 */ #define OOR1 (16UL << OPSHIFT) /* | pt. 1 back to OOR1 or OCH_ */ #define OOR2 (17UL << OPSHIFT) /* | pt. 2 fwd to OOR2 or O_CH */ #define O_CH (18UL << OPSHIFT) /* end choice back to OOR1 */ #define OBOW (19UL << OPSHIFT) /* begin word - */ #define OEOW (20UL << OPSHIFT) /* end word - */ /* * Structure for [] character-set representation. Character sets are * done as bit vectors, grouped 8 to a byte vector for compactness. * The individual set therefore has both a pointer to the byte vector * and a mask to pick out the relevant bit of each byte. A hash code * simplifies testing whether two sets could be identical. * * This will get trickier for multicharacter collating elements. As * preliminary hooks for dealing with such things, we also carry along * a string of multi-character elements, and decide the size of the * vectors at run time. */ typedef struct { uch *ptr; /* -> uch [csetsize] */ uch mask; /* bit within array */ short hash; /* hash code */ size_t smultis; char *multis; /* -> char[smulti] ab\0cd\0ef\0\0 */ } cset; /* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */ #define CHadd(cs, c) ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (uch)(c)) #define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (uch)(c)) #define CHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask) #define MCadd(p, cs, cp) mcadd(p, cs, cp) /* regcomp() internal fns */ #define MCsub(p, cs, cp) mcsub(p, cs, cp) #define MCin(p, cs, cp) mcin(p, cs, cp) /* stuff for character categories */ typedef unsigned char cat_t; /* * main compiled-expression structure */ struct re_guts { unsigned int magic; #define MAGIC2 ((((unsigned int)'R' ^ 0200) << 8) | 'E') sop *strip; /* malloced area for strip */ int csetsize; /* number of bits in a cset vector */ int ncsets; /* number of csets in use */ cset *sets; /* -> cset [ncsets] */ uch *setbits; /* -> uch[csetsize][ncsets/CHAR_BIT] */ int cflags; /* copy of regcomp() cflags argument */ sopno nstates; /* = number of sops */ sopno firststate; /* the initial OEND (normally 0) */ sopno laststate; /* the final OEND */ int iflags; /* internal flags */ #define USEBOL 01 /* used ^ */ #define USEEOL 02 /* used $ */ #define BAD 04 /* something wrong */ int nbol; /* number of ^ used */ int neol; /* number of $ used */ int ncategories; /* how many character categories */ cat_t *categories; /* ->catspace[-CHAR_MIN] */ char *must; /* match must contain this string */ int moffset; /* latest point at which must may be located */ int *charjump; /* Boyer-Moore char jump table */ int *matchjump; /* Boyer-Moore match jump table */ int mlen; /* length of must */ size_t nsub; /* copy of re_nsub */ int backrefs; /* does it use back references? */ sopno nplus; /* how deep does it nest +s? */ /* catspace must be last */ cat_t catspace[NC]; /* categories */ }; /* misc utilities */ #define OUT (CHAR_MAX + 1) /* a non-character value */ #define ISWORD(c) (isalnum((uch)(c)) || (c) == '_') picolibc-1.8.11/libc/posix/regexec.c000066400000000000000000000152101513574234600172400ustar00rootroot00000000000000/*- * Copyright (c) 1992, 1993, 1994 Henry Spencer. * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Henry Spencer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)regexec.c 8.3 (Berkeley) 3/20/94 */ #ifndef _NO_REGEX #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94"; #endif /* LIBC_SCCS and not lint */ /* * the outer shell of regexec() * * This file includes engine.c *twice*, after muchos fiddling with the * macros that code uses. This lets the same code operate on two different * representations for state sets. */ #include #include #include #include #include #include #include #include "utils.h" #include "regex2.h" #ifndef NDEBUG static int nope = 0; /* for use in asserts; shuts lint up */ #endif /* macros for manipulating states, small version */ #define states long #define states1 states /* for later use in regexec() decision */ #define CLEAR(v) ((v) = 0) #define SET0(v, n) ((v) &= ~((unsigned long)1 << (n))) #define SET1(v, n) ((v) |= (unsigned long)1 << (n)) #define ISSET(v, n) (((v) & ((unsigned long)1 << (n))) != 0) #define ASSIGN(d, s) ((d) = (s)) #define EQ(a, b) ((a) == (b)) #define STATEVARS long dummy /* dummy version */ #define STATESETUP(m, n) /* nothing */ #define STATETEARDOWN(m) /* nothing */ #define SETUP(v) ((v) = 0) #define onestate long #define INIT(o, n) ((o) = (unsigned long)1 << (n)) #define INC(o) ((o) <<= 1) #define ISSTATEIN(v, o) (((v) & (o)) != 0) /* some abbreviations; note that some of these know variable names! */ /* do "if I'm here, I can also be there" etc without branches */ #define FWD(dst, src, n) ((dst) |= ((unsigned long)(src) & (here)) << (n)) #define BACK(dst, src, n) ((dst) |= ((unsigned long)(src) & (here)) >> (n)) #define ISSETBACK(v, n) (((v) & ((unsigned long)here >> (n))) != 0) /* function names */ #define SNAMES /* engine.c looks after details */ #include "engine.c" /* now undo things */ #undef states #undef CLEAR #undef SET0 #undef SET1 #undef ISSET #undef ASSIGN #undef EQ #undef STATEVARS #undef STATESETUP #undef STATETEARDOWN #undef SETUP #undef onestate #undef INIT #undef INC #undef ISSTATEIN #undef FWD #undef BACK #undef ISSETBACK #undef SNAMES /* macros for manipulating states, large version */ #define states char * #define CLEAR(v) memset(v, 0, m->g->nstates) #define SET0(v, n) ((v)[n] = 0) #define SET1(v, n) ((v)[n] = 1) #define ISSET(v, n) ((v)[n]) #define ASSIGN(d, s) memcpy(d, s, m->g->nstates) #define EQ(a, b) (memcmp(a, b, m->g->nstates) == 0) #define STATEVARS \ long vn; \ char *space #define STATESETUP(m, nv) \ { \ (m)->space = malloc((nv) * (m)->g->nstates); \ if ((m)->space == NULL) \ return (REG_ESPACE); \ (m)->vn = 0; \ } #define STATETEARDOWN(m) \ { \ free((m)->space); \ } #define SETUP(v) ((v) = &m->space[m->vn++ * m->g->nstates]) #define onestate long #define INIT(o, n) ((o) = (n)) #define INC(o) ((o)++) #define ISSTATEIN(v, o) ((v)[o]) /* some abbreviations; note that some of these know variable names! */ /* do "if I'm here, I can also be there" etc without branches */ #define FWD(dst, src, n) ((dst)[here + (n)] |= (src)[here]) #define BACK(dst, src, n) ((dst)[here - (n)] |= (src)[here]) #define ISSETBACK(v, n) ((v)[here - (n)]) /* function names */ #define LNAMES /* flag */ #include "engine.c" /* - regexec - interface for matching = extern int regexec(const regex_t *__restrict, const char *__restrict, = size_t, regmatch_t [__restrict], int); = #define REG_NOTBOL 00001 = #define REG_NOTEOL 00002 = #define REG_STARTEND 00004 = #define REG_TRACE 00400 // tracing of execution = #define REG_LARGE 01000 // force large representation = #define REG_BACKR 02000 // force use of backref code * * We put this here so we can exploit knowledge of the state representation * when choosing which matcher to call. Also, by this point the matchers * have been prototyped. */ int /* 0 success, REG_NOMATCH failure */ regexec(const regex_t * __restrict preg, const char * __restrict string, size_t nmatch, regmatch_t pmatch[__restrict], int eflags) { struct re_guts *g = preg->re_g; #ifdef REDEBUG #define GOODFLAGS(f) (f) #else #define GOODFLAGS(f) ((f) & (REG_NOTBOL | REG_NOTEOL | REG_STARTEND)) #endif if (preg->re_magic != MAGIC1 || g->magic != MAGIC2) return (REG_BADPAT); assert(!(g->iflags & BAD)); if (g->iflags & BAD) /* backstop for no-debug case */ return (REG_BADPAT); eflags = GOODFLAGS(eflags); if (g->nstates <= (sopno)(CHAR_BIT * sizeof(states1)) && !(eflags & REG_LARGE)) return (smatcher(g, (char *)string, nmatch, pmatch, eflags)); else return (lmatcher(g, (char *)string, nmatch, pmatch, eflags)); } #endif /* !_NO_REGEX */ picolibc-1.8.11/libc/posix/regfree.c000066400000000000000000000055161513574234600172450ustar00rootroot00000000000000/*- * Copyright (c) 1992, 1993, 1994 Henry Spencer. * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Henry Spencer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)regfree.c 8.3 (Berkeley) 3/20/94 */ #ifndef _NO_REGEX #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)regfree.c 8.3 (Berkeley) 3/20/94"; #endif /* LIBC_SCCS and not lint */ #include #include #include #include #include #include "utils.h" #include "regex2.h" /* - regfree - free everything = extern void regfree(regex_t *); */ void regfree(regex_t *preg) { struct re_guts *g; if (preg->re_magic != MAGIC1) /* oops */ return; /* nice to complain, but hard */ g = preg->re_g; if (g == NULL || g->magic != MAGIC2) /* oops again */ return; preg->re_magic = 0; /* mark it invalid */ g->magic = 0; /* mark it invalid */ if (g->strip != NULL) free((char *)g->strip); if (g->sets != NULL) free((char *)g->sets); if (g->setbits != NULL) free((char *)g->setbits); if (g->must != NULL) free(g->must); if (g->charjump != NULL) free(g->charjump); if (g->matchjump != NULL) free(g->matchjump); free((char *)g); } #endif /* !_NO_REGEX */ picolibc-1.8.11/libc/posix/rune.h000066400000000000000000000047531513574234600166060ustar00rootroot00000000000000/*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Paul Borman at Krystal Technologies. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)rune.h 8.1 (Berkeley) 6/27/93 * $FreeBSD: src/include/rune.h,v 1.2 2002/03/23 17:24:53 imp Exp $ */ #ifndef _RUNE_H_ #define _RUNE_H_ #include "runetype.h" #include #define _PATH_LOCALE "/usr/share/locale" #define _INVALID_RUNE _CurrentRuneLocale->invalid_rune #define __sgetrune _CurrentRuneLocale->sgetrune #define __sputrune _CurrentRuneLocale->sputrune #define sgetrune(s, n, r) (*__sgetrune)((s), (n), (r)) #define sputrune(c, s, n, r) (*__sputrune)((c), (s), (n), (r)) _BEGIN_STD_C char *mbrune(const char *, rune_t); char *mbrrune(const char *, rune_t); char *mbmb(const char *, char *); long fgetrune(FILE *); int fputrune(rune_t, FILE *); int fungetrune(rune_t, FILE *); int setrunelocale(char *); void setinvalidrune(rune_t); _END_STD_C #endif /*! _RUNE_H_ */ picolibc-1.8.11/libc/posix/runetype.h000066400000000000000000000071461513574234600175070ustar00rootroot00000000000000/*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Paul Borman at Krystal Technologies. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)runetype.h 8.1 (Berkeley) 6/2/93 * $FreeBSD: src/include/runetype.h,v 1.5 2002/03/26 01:35:05 bde Exp $ */ #ifndef _RUNETYPE_H_ #define _RUNETYPE_H_ #include #include #ifdef _BSD_RUNE_T_ typedef _BSD_RUNE_T_ rune_t; #undef _BSD_RUNE_T_ #else typedef int rune_t; #endif #define _CACHED_RUNES (1 << 8) /* Must be a power of 2 */ #define _CRMASK (~(_CACHED_RUNES - 1)) /* * The lower 8 bits of runetype[] contain the digit value of the rune. */ typedef struct { rune_t min; /* First rune of the range */ rune_t max; /* Last rune (inclusive) of the range */ rune_t map; /* What first maps to in maps */ unsigned long *types; /* Array of types in range */ } _RuneEntry; typedef struct { int nranges; /* Number of ranges stored */ _RuneEntry *ranges; /* Pointer to the ranges */ } _RuneRange; typedef struct { char magic[8]; /* Magic saying what version we are */ char encoding[32]; /* ASCII name of this encoding */ rune_t (*sgetrune)(const char *, size_t, char const **); int (*sputrune)(rune_t, char *, size_t, char **); rune_t invalid_rune; unsigned long runetype[_CACHED_RUNES]; rune_t maplower[_CACHED_RUNES]; rune_t mapupper[_CACHED_RUNES]; /* * The following are to deal with Runes larger than _CACHED_RUNES - 1. * Their data is actually contiguous with this structure so as to make * it easier to read/write from/to disk. */ _RuneRange runetype_ext; _RuneRange maplower_ext; _RuneRange mapupper_ext; void *variable; /* Data which depends on the encoding */ int variable_len; /* how long that data is */ } _RuneLocale; #define _RUNE_MAGIC_1 "RuneMagi" /* Indicates version 0 of RuneLocale */ extern _RuneLocale _DefaultRuneLocale; extern _RuneLocale *_CurrentRuneLocale; #endif /* !_RUNETYPE_H_ */ picolibc-1.8.11/libc/posix/strfmon.c000066400000000000000000000035501513574234600173120ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include "posix-local.h" ssize_t strfmon(char * __restrict buf, size_t size, const char * __restrict format, ...) { va_list ap; ssize_t ret; va_start(ap, format); ret = __vstrfmon(buf, size, format, ap); va_end(ap); return ret; } picolibc-1.8.11/libc/posix/strfmon_l.c000066400000000000000000000036151513574234600176270ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include "posix-local.h" ssize_t strfmon_l(char * __restrict buf, size_t size, locale_t locale, const char * __restrict format, ...) { va_list ap; ssize_t ret; (void)locale; va_start(ap, format); ret = __vstrfmon(buf, size, format, ap); va_end(ap); return ret; } picolibc-1.8.11/libc/posix/sysexits.h000066400000000000000000000123031513574234600175160ustar00rootroot00000000000000/* * Copyright (c) 1987, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)sysexits.h 8.1 (Berkeley) 6/2/93 */ #ifndef _SYSEXITS_H #define _SYSEXITS_H 1 /* * SYSEXITS.H -- Exit status codes for system programs. * * This include file attempts to categorize possible error * exit statuses for system programs, notably delivermail * and the Berkeley network. * * Error numbers begin at EX__BASE to reduce the possibility of * clashing with other exit statuses that random programs may * already return. The meaning of the codes is approximately * as follows: * * EX_USAGE -- The command was used incorrectly, e.g., with * the wrong number of arguments, a bad flag, a bad * syntax in a parameter, or whatever. * EX_DATAERR -- The input data was incorrect in some way. * This should only be used for user's data & not * system files. * EX_NOINPUT -- An input file (not a system file) did not * exist or was not readable. This could also include * errors like "No message" to a mailer (if it cared * to catch it). * EX_NOUSER -- The user specified did not exist. This might * be used for mail addresses or remote logins. * EX_NOHOST -- The host specified did not exist. This is used * in mail addresses or network requests. * EX_UNAVAILABLE -- A service is unavailable. This can occur * if a support program or file does not exist. This * can also be used as a catchall message when something * you wanted to do doesn't work, but you don't know * why. * EX_SOFTWARE -- An internal software error has been detected. * This should be limited to non-operating system related * errors as possible. * EX_OSERR -- An operating system error has been detected. * This is intended to be used for such things as "cannot * fork", "cannot create pipe", or the like. It includes * things like getuid returning a user that does not * exist in the passwd file. * EX_OSFILE -- Some system file (e.g., /etc/passwd, /etc/utmp, * etc.) does not exist, cannot be opened, or has some * sort of error (e.g., syntax error). * EX_CANTCREAT -- A (user specified) output file cannot be * created. * EX_IOERR -- An error occurred while doing I/O on some file. * EX_TEMPFAIL -- temporary failure, indicating something that * is not really an error. In sendmail, this means * that a mailer (e.g.) could not create a connection, * and the request should be reattempted later. * EX_PROTOCOL -- the remote system returned something that * was "not possible" during a protocol exchange. * EX_NOPERM -- You did not have sufficient permission to * perform the operation. This is not intended for * file system problems, which should use NOINPUT or * CANTCREAT, but rather for higher level permissions. */ #define EX_OK 0 /* successful termination */ #define EX__BASE 64 /* base value for error messages */ #define EX_USAGE 64 /* command line usage error */ #define EX_DATAERR 65 /* data format error */ #define EX_NOINPUT 66 /* cannot open input */ #define EX_NOUSER 67 /* addressee unknown */ #define EX_NOHOST 68 /* host name unknown */ #define EX_UNAVAILABLE 69 /* service unavailable */ #define EX_SOFTWARE 70 /* internal software error */ #define EX_OSERR 71 /* system error (e.g., can't fork) */ #define EX_OSFILE 72 /* critical OS file missing */ #define EX_CANTCREAT 73 /* can't create (user) output file */ #define EX_IOERR 74 /* input/output error */ #define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */ #define EX_PROTOCOL 76 /* remote error in protocol */ #define EX_NOPERM 77 /* permission denied */ #define EX_CONFIG 78 /* configuration error */ #define EX__MAX 78 /* maximum listed value */ #endif /* sysexits.h */ picolibc-1.8.11/libc/posix/utils.h000066400000000000000000000045171513574234600167730ustar00rootroot00000000000000/*- * Copyright (c) 1992, 1993, 1994 Henry Spencer. * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Henry Spencer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)utils.h 8.3 (Berkeley) 3/20/94 * $FreeBSD: src/lib/libc/regex/utils.h,v 1.2 2002/03/22 23:41:56 obrien Exp $ */ #include /* for RE_DUP_MAX */ /* utility definitions */ #define DUPMAX RE_DUP_MAX /* xxx is this right? */ #define REGEX_INFINITY (DUPMAX + 1) #define NC (CHAR_MAX - CHAR_MIN + 1) typedef unsigned char uch; /* switch off assertions (if not already off) if no REDEBUG */ #ifndef REDEBUG #ifndef NDEBUG #define NDEBUG /* no assertions please */ #endif #endif #include /* for old systems with bcopy() but no memmove() */ #ifdef USEBCOPY #define memmove(d, s, c) bcopy(s, d, c) #endif picolibc-1.8.11/libc/posix/vstrfmon.c000066400000000000000000000206721513574234600175040ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include "posix-local.h" #include "stdio_private.h" /* * Shared function for strfmon and strfmon_l * * Handles C/POSIX locale, which means: * * int_curr_symbol "" * currency_symbol "" * mon_decimal_point "" * mon_thousands_sep "" * mon_grouping -1 * positive_sign "" * negative_sign "" * int_frac_digits -1 * frac_digits -1 * p_cs_precedes -1 * p_sep_by_space -1 * n_cs_precedes -1 * n_sep_by_space -1 * p_sign_posn -1 * n_sign_posn -1 * int_p_cs_precedes -1 * int_p_sep_by_space -1 * int_n_cs_precedes -1 * int_n_sep_by_space -1 * int_p_sign_posn -1 * int_n_sign_posn -1 */ ssize_t __vstrfmon(char * __restrict buf, size_t size, const char * __restrict format, va_list ap) { size_t pos = 0; #define output(c) \ do { \ if (pos == size) { \ errno = E2BIG; \ return -1; \ } \ buf[pos++] = (c); \ } while (0) #define decimal(v) \ do { \ (v) = c - '0'; \ for (;;) { \ c = *format++; \ if (!isdigit(c)) \ break; \ (v) = (v) * 10 + c - '0'; \ } \ } while (0) for (;;) { double val; char *val_pos; char c; char left_fill = ' '; bool sign_paren = false; bool left_justify = false; int field_width = -1; int left_precision = -1; int right_precision = -1; int val_width; int left_width; int total_width; size_t val_size; bool negative; /* Find the % */ for (;;) { c = *format++; if (c == '%') break; if (c == '\0') { output('\0'); return pos - 1; } output(c); } /* Parse flags */ for (;;) { c = *format++; switch (c) { case '=': left_fill = *format++; if (!left_fill) { errno = EINVAL; return -1; } continue; case '^': continue; case '(': sign_paren = true; continue; case '+': /* Should this return -1/EINVAL? Glibc doesn't */ sign_paren = false; continue; case '!': continue; case '-': left_justify = true; continue; } break; } /* parse field width */ if (isdigit(c)) decimal(field_width); /* parse left precision */ if (c == '#') { c = *format++; if (!isdigit(c)) { errno = EINVAL; return -1; } decimal(left_precision); } /* parse right precision */ if (c == '.') { c = *format++; if (!isdigit(c)) { errno = EINVAL; return -1; } decimal(right_precision); } /* parse conversion specifier char */ switch (c) { case 'i': case 'n': val = va_arg(ap, double); negative = signbit(val) != 0; if (negative) val = -val; /* Write the value into the provided buffer */ val_pos = buf + pos; val_size = size - pos; val_width = __d_snprintf(val_pos, val_size, "%.*f", right_precision, val); /* Check to see if it fit */ if (val_width < 0 || (size_t)val_width > val_size) { errno = E2BIG; return -1; } /* Trim trailing zeros */ while (val_pos[val_width - 1] == '0') val_width--; if (val_pos[val_width - 1] == '.') val_width--; /* Compute width of integer portion (left) */ left_width = strchrnul(val_pos, '.') - val_pos; /* Move it to the end of the buffer */ memmove(buf + size - val_width, val_pos, val_width); val_pos = buf + size - val_width; /* * * * * * * */ /* Compute total width of value */ total_width = val_width; /* Add sign character */ if (negative) { if (sign_paren) total_width += 2; else total_width += 1; } else if (left_precision >= 0) total_width += 1; /* Add left precision pad */ if (left_precision > left_width) total_width += (left_precision - left_width); /* Generate the result */ /* Pad field on left */ if (!left_justify) { while (total_width < field_width) { output(' '); total_width++; } } /* Output sign character */ if (negative) { if (sign_paren) output('('); else output('-'); } else if (left_precision >= 0) { output(' '); } /* Pad value with left_fill */ while (left_width < left_precision) { output(left_fill); left_width++; } /* Move val back into position */ if (pos + val_width > size) { errno = E2BIG; return -1; } memmove(buf + pos, val_pos, val_width); pos += val_width; /* Output close paren for negative values */ if (sign_paren) { if (negative) output(')'); } /* Pad field on right */ if (left_justify) { while (total_width < field_width) { output(' '); total_width++; } } break; case '%': output(c); break; default: errno = EINVAL; return -1; } } } picolibc-1.8.11/libc/search/000077500000000000000000000000001513574234600155565ustar00rootroot00000000000000picolibc-1.8.11/libc/search/CMakeLists.txt000066400000000000000000000034401513574234600203170ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources( bsd_qsort_r.c bsearch.c hash_bigkey.c hash_buf.c hash.c hash_func.c hash_log2.c hash_page.c hcreate.c hcreate_r.c ndbm.c qsort.c qsort_r.c tdelete.c tdestroy.c tfind.c tsearch.c twalk.c ) picolibc-1.8.11/libc/search/bsd_qsort_r.c000066400000000000000000000001501513574234600202370ustar00rootroot00000000000000/* Copyright (c) 2014 Yaakov Selkowitz */ #define I_AM_QSORT_R #include "qsort.c" picolibc-1.8.11/libc/search/bsearch.c000066400000000000000000000076771513574234600173520ustar00rootroot00000000000000/* Copyright (c) 1991, 1993, 1994 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * bsearch.c * Original Author: G. Haley * Rewritten by: G. Noer * * Searches an array of nmemb members, the initial member of which is pointed * to by base, for a member that matches the object pointed to by key. The * contents of the array shall be in ascending order according to a comparison * function pointed to by compar. The function shall return an integer less * than, equal to or greater than zero if the first argument is considered to be * respectively less than, equal to or greater than the second. Returns a * pointer to the matching member of the array, or a null pointer if no match * is found. */ /* FUNCTION <>---binary search INDEX bsearch SYNOPSIS #include void *bsearch(const void *<[key]>, const void *<[base]>, size_t <[nmemb]>, size_t <[size]>, int (*<[compar]>)(const void *, const void *)); DESCRIPTION <> searches an array beginning at <[base]> for any element that matches <[key]>, using binary search. <[nmemb]> is the element count of the array; <[size]> is the size of each element. The array must be sorted in ascending order with respect to the comparison function <[compar]> (which you supply as the last argument of <>). You must define the comparison function <<(*<[compar]>)>> to have two arguments; its result must be negative if the first argument is less than the second, zero if the two arguments match, and positive if the first argument is greater than the second (where ``less than'' and ``greater than'' refer to whatever arbitrary ordering is appropriate). RETURNS Returns a pointer to an element of <[array]> that matches <[key]>. If more than one matching element is available, the result may point to any of them. PORTABILITY <> is ANSI. No supporting OS subroutines are required. */ #include void * bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) { void *current; size_t lower = 0; size_t upper = nmemb; size_t index; int result; if (nmemb == 0 || size == 0) return NULL; while (lower < upper) { index = (lower + upper) / 2; current = (void *)(((char *)base) + (index * size)); result = compar(key, current); if (result < 0) upper = index; else if (result > 0) lower = index + 1; else return current; } return NULL; } picolibc-1.8.11/libc/search/db_local.h000066400000000000000000000200551513574234600174700ustar00rootroot00000000000000/*- * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)db.h 8.7 (Berkeley) 6/16/94 * $FreeBSD: src/include/db.h,v 1.5 2002/03/26 01:35:05 bde Exp $ */ #ifndef _DB_H_ #define _DB_H_ #include #include #define RET_ERROR -1 /* Return values. */ #define RET_SUCCESS 0 #define RET_SPECIAL 1 #define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */ typedef __uint32_t pgno_t; #define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */ typedef __uint16_t indx_t; #define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */ typedef __uint32_t recno_t; /* Key/data structure -- a Data-Base Thang. */ typedef struct { void *data; /* data */ size_t size; /* data length */ } DBT; /* Routine flags. */ #define R_CURSOR 1 /* del, put, seq */ #define __R_UNUSED 2 /* UNUSED */ #define R_FIRST 3 /* seq */ #define R_IAFTER 4 /* put (RECNO) */ #define R_IBEFORE 5 /* put (RECNO) */ #define R_LAST 6 /* seq (BTREE, RECNO) */ #define R_NEXT 7 /* seq */ #define R_NOOVERWRITE 8 /* put */ #define R_PREV 9 /* seq (BTREE, RECNO) */ #define R_SETCURSOR 10 /* put (RECNO) */ #define R_RECNOSYNC 11 /* sync (RECNO) */ typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE; /* * !!! * The following flags are included in the dbopen(3) call as part of the * open(2) flags. In order to avoid conflicts with the open flags, start * at the top of the 16 or 32-bit number space and work our way down. If * the open flags were significantly expanded in the future, it could be * a problem. Wish I'd left another flags word in the dbopen call. * * !!! * None of this stuff is implemented yet. The only reason that it's here * is so that the access methods can skip copying the key/data pair when * the DB_LOCK flag isn't set. */ #if UINT_MAX > 65535 #define DB_LOCK 0x20000000 /* Do locking. */ #define DB_SHMEM 0x40000000 /* Use shared memory. */ #define DB_TXN 0x80000000 /* Do transactions. */ #else #define DB_LOCK 0x2000 /* Do locking. */ #define DB_SHMEM 0x4000 /* Use shared memory. */ #define DB_TXN 0x8000 /* Do transactions. */ #endif /* Access method description structure. */ typedef struct __db { DBTYPE type; /* Underlying db type. */ int (*close)(struct __db *); int (*del)(const struct __db *, const DBT *, u_int); int (*get)(const struct __db *, const DBT *, DBT *, u_int); int (*put)(const struct __db *, DBT *, const DBT *, u_int); int (*seq)(const struct __db *, DBT *, DBT *, u_int); int (*sync)(const struct __db *, u_int); void *internal; /* Access method private. */ int (*fd)(const struct __db *); } DB; #define BTREEMAGIC 0x053162 #define BTREEVERSION 3 /* Structure used to pass parameters to the btree routines. */ typedef struct { #define R_DUP 0x01 /* duplicate keys */ u_long flags; u_int cachesize; /* bytes to cache */ int maxkeypage; /* maximum keys per page */ int minkeypage; /* minimum keys per page */ u_int psize; /* page size */ int(*compare) /* comparison function */ (const DBT *, const DBT *); size_t(*prefix) /* prefix function */ (const DBT *, const DBT *); int lorder; /* byte order */ } BTREEINFO; #define HASHMAGIC 0x061561L #define HASHVERSION 2 /* Structure used to pass parameters to the hashing routines. */ typedef struct { u_int bsize; /* bucket size */ u_int ffactor; /* fill factor */ u_int nelem; /* number of elements */ u_int cachesize; /* bytes to cache */ __uint32_t /* hash function */ (*hash)(const void *, size_t); int lorder; /* byte order */ } HASHINFO; /* Structure used to pass parameters to the record routines. */ typedef struct { #define R_FIXEDLEN 0x01 /* fixed-length records */ #define R_NOKEY 0x02 /* key not required */ #define R_SNAPSHOT 0x04 /* snapshot the input */ u_long flags; u_int cachesize; /* bytes to cache */ u_int psize; /* page size */ int lorder; /* byte order */ size_t reclen; /* record length (fixed-length records) */ u_char bval; /* delimiting byte (variable-length records */ char *bfname; /* btree file name */ } RECNOINFO; /* * Little endian <==> big endian 32-bit swap macros. * M_32_SWAP swap a memory location * P_32_SWAP swap a referenced memory location * P_32_COPY swap from one location to another */ #define M_32_SWAP(a) \ { \ __uint32_t _tmp = a; \ ((char *)&a)[0] = ((char *)&_tmp)[3]; \ ((char *)&a)[1] = ((char *)&_tmp)[2]; \ ((char *)&a)[2] = ((char *)&_tmp)[1]; \ ((char *)&a)[3] = ((char *)&_tmp)[0]; \ } #define P_32_SWAP(a) \ { \ __uint32_t _tmp = *(__uint32_t *)a; \ ((char *)a)[0] = ((char *)&_tmp)[3]; \ ((char *)a)[1] = ((char *)&_tmp)[2]; \ ((char *)a)[2] = ((char *)&_tmp)[1]; \ ((char *)a)[3] = ((char *)&_tmp)[0]; \ } #define P_32_COPY(a, b) \ { \ ((char *)&(b))[0] = ((char *)&(a))[3]; \ ((char *)&(b))[1] = ((char *)&(a))[2]; \ ((char *)&(b))[2] = ((char *)&(a))[1]; \ ((char *)&(b))[3] = ((char *)&(a))[0]; \ } /* * Little endian <==> big endian 16-bit swap macros. * M_16_SWAP swap a memory location * P_16_SWAP swap a referenced memory location * P_16_COPY swap from one location to another */ #define M_16_SWAP(a) \ { \ __uint16_t _tmp = a; \ ((char *)&a)[0] = ((char *)&_tmp)[1]; \ ((char *)&a)[1] = ((char *)&_tmp)[0]; \ } #define P_16_SWAP(a) \ { \ __uint16_t _tmp = *(__uint16_t *)a; \ ((char *)a)[0] = ((char *)&_tmp)[1]; \ ((char *)a)[1] = ((char *)&_tmp)[0]; \ } #define P_16_COPY(a, b) \ { \ ((char *)&(b))[0] = ((char *)&(a))[1]; \ ((char *)&(b))[1] = ((char *)&(a))[0]; \ } _BEGIN_STD_C DB *dbopen(const char *, int, int, DBTYPE, const void *); #ifdef __DBINTERFACE_PRIVATE DB *__bt_open(const char *, int, int, const BTREEINFO *, int); DB *__hash_open(const char *, int, int, int, const HASHINFO *); DB *__rec_open(const char *, int, int, const RECNOINFO *, int); void __dbpanic(DB *dbp); #endif _END_STD_C #endif /* !_DB_H_ */ picolibc-1.8.11/libc/search/extern.h000066400000000000000000000060241513574234600172360ustar00rootroot00000000000000/*- * Copyright (c) 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)extern.h 8.4 (Berkeley) 6/16/94 * $FreeBSD: src/lib/libc/db/hash/extern.h,v 1.3 2002/03/22 09:18:22 obrien Exp $ */ BUFHEAD *__add_ovflpage(HTAB *, BUFHEAD *); int __addel(HTAB *, BUFHEAD *, const DBT *, const DBT *); int __big_delete(HTAB *, BUFHEAD *); int __big_insert(HTAB *, BUFHEAD *, const DBT *, const DBT *); int __big_keydata(HTAB *, BUFHEAD *, DBT *, DBT *, int); int __big_return(HTAB *, BUFHEAD *, int, DBT *, int); int __big_split(HTAB *, BUFHEAD *, BUFHEAD *, BUFHEAD *, int, __uint32_t, SPLIT_RETURN *); int __buf_free(HTAB *, int, int); void __buf_init(HTAB *, int); __uint32_t __call_hash(HTAB *, char *, int); int __delpair(HTAB *, BUFHEAD *, int); int __expand_table(HTAB *); int __find_bigpair(HTAB *, BUFHEAD *, int, char *, int); __uint16_t __find_last_page(HTAB *, BUFHEAD **); void __free_ovflpage(HTAB *, BUFHEAD *); BUFHEAD *__get_buf(HTAB *, __uint32_t, BUFHEAD *, int); int __get_page(HTAB *, char *, __uint32_t, int, int, int); int __ibitmap(HTAB *, int, int, int); __uint32_t __log2(__uint32_t); int __put_page(HTAB *, char *, __uint32_t, int, int); void __reclaim_buf(HTAB *, BUFHEAD *); int __split_page(HTAB *, __uint32_t, __uint32_t); /* Default hash routine. */ extern __uint32_t __default_hash(const void *, size_t); #ifdef HASH_STATISTICS extern int hash_accesses, hash_collisions, hash_expansions, hash_overflows; #endif picolibc-1.8.11/libc/search/hash.c000066400000000000000000000660431513574234600166560ustar00rootroot00000000000000/*- * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Margo Seltzer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include #include #include #include #include #include #include #include #if !defined(DEBUG) && !defined(NDEBUG) #define NDEBUG #endif #include #define __DBINTERFACE_PRIVATE /* activate prototypes from db_local.h */ #include "db_local.h" #include "hash.h" #include "page.h" #include "extern.h" static int alloc_segs(HTAB *, int); static int flush_meta(HTAB *); static int hash_access(HTAB *, HASH_ACTION, DBT *, DBT *); static int hash_close(DB *); static int hash_delete(const DB *, const DBT *, u_int); static int hash_fd(const DB *); static int hash_get(const DB *, const DBT *, DBT *, u_int); static int hash_put(const DB *, DBT *, const DBT *, u_int); static void *hash_realloc(SEGMENT **, int, int); static int hash_seq(const DB *, DBT *, DBT *, u_int); static int hash_sync(const DB *, u_int); static int hdestroy(HTAB *); static HTAB *init_hash(HTAB *, const char *, const HASHINFO *); static int init_htab(HTAB *, int); #if (_BYTE_ORDER == _LITTLE_ENDIAN) static void swap_header(HTAB *); static void swap_header_copy(HASHHDR *, HASHHDR *); #endif /* Macros for min/max. */ #ifndef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX #define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif /* Fast arithmetic, relying on powers of 2, */ #define MOD(x, y) ((x) & ((y) - 1)) #define RETURN_ERROR(ERR, LOC) \ { \ save_errno = ERR; \ goto LOC; \ } /* Return values */ #define SUCCESS (0) #define ERROR (-1) #define ABNORMAL (1) #ifdef HASH_STATISTICS int hash_accesses, hash_collisions, hash_expansions, hash_overflows; #endif /************************** INTERFACE ROUTINES ***************************/ /* OPEN/CLOSE */ extern DB * __hash_open(const char *file, int flags, int mode, int dflags, const HASHINFO *info) /* Special directives for create */ { HTAB *hashp; (void)dflags; #ifdef __USE_INTERNAL_STAT64 struct stat64 statbuf; #else struct stat statbuf; #endif DB *dbp; int bpages, hdrsize, new_table, nsegs, save_errno; if ((flags & O_ACCMODE) == O_WRONLY) { errno = EINVAL; return (NULL); } if (!(hashp = (HTAB *)calloc(1, sizeof(HTAB)))) return (NULL); hashp->fp = -1; /* * Even if user wants write only, we need to be able to read * the actual file, so we need to open it read/write. But, the * field in the hashp structure needs to be accurate so that * we can check accesses. */ hashp->flags = flags; new_table = 0; if (!file || (flags & O_TRUNC) || #ifdef __USE_INTERNAL_STAT64 (stat64(file, &statbuf) && (errno == ENOENT))) { #else (stat(file, &statbuf) && (errno == ENOENT))) { #endif if (errno == ENOENT) errno = 0; /* Just in case someone looks at errno */ new_table = 1; } if (file) { if ((hashp->fp = open(file, flags, mode)) == -1) RETURN_ERROR(errno, error0); /* if the .db file is empty, and we had permission to create a new .db file, then reinitialize the database */ if ((flags & O_CREAT) && #ifdef __USE_INTERNAL_STAT64 fstat64(hashp->fp, &statbuf) == 0 && statbuf.st_size == 0) #else fstat(hashp->fp, &statbuf) == 0 && statbuf.st_size == 0) #endif new_table = 1; #ifdef __HAVE_FCNTL (void)fcntl(hashp->fp, F_SETFD, 1); #endif } if (new_table) { if (!(hashp = init_hash(hashp, file, (HASHINFO *)info))) RETURN_ERROR(errno, error1); } else { /* Table already exists */ if (info && info->hash) hashp->hash = info->hash; else hashp->hash = __default_hash; hdrsize = read(hashp->fp, &hashp->hdr, sizeof(HASHHDR)); #if (_BYTE_ORDER == _LITTLE_ENDIAN) swap_header(hashp); #endif if (hdrsize == -1) RETURN_ERROR(errno, error1); if (hdrsize != sizeof(HASHHDR)) RETURN_ERROR(EFTYPE, error1); /* Verify file type, versions and hash function */ if (hashp->MAGIC != HASHMAGIC) RETURN_ERROR(EFTYPE, error1); #define OLDHASHVERSION 1 if (hashp->HASH_VERSION != HASHVERSION && hashp->HASH_VERSION != OLDHASHVERSION) RETURN_ERROR(EFTYPE, error1); if (hashp->hash(CHARKEY, sizeof(CHARKEY)) != hashp->H_CHARKEY) RETURN_ERROR(EFTYPE, error1); /* Check bucket size isn't too big for target int. */ if (hashp->BSIZE > INT_MAX) RETURN_ERROR(EFTYPE, error1); /* * Figure out how many segments we need. Max_Bucket is the * maximum bucket number, so the number of buckets is * max_bucket + 1. */ nsegs = (hashp->MAX_BUCKET + 1 + hashp->SGSIZE - 1) / hashp->SGSIZE; hashp->nsegs = 0; if (alloc_segs(hashp, nsegs)) /* * If alloc_segs fails, table will have been destroyed * and errno will have been set. */ return (NULL); /* Read in bitmaps */ bpages = (hashp->SPARES[hashp->OVFL_POINT] + (hashp->BSIZE << BYTE_SHIFT) - 1) >> (hashp->BSHIFT + BYTE_SHIFT); hashp->nmaps = bpages; (void)memset(&hashp->mapp[0], 0, bpages * sizeof(__uint32_t *)); } /* Initialize Buffer Manager */ if (info && info->cachesize) __buf_init(hashp, info->cachesize); else __buf_init(hashp, DEF_BUFSIZE); hashp->new_file = new_table; hashp->save_file = file && (hashp->flags & O_RDWR); hashp->cbucket = -1; if (!(dbp = (DB *)malloc(sizeof(DB)))) { save_errno = errno; hdestroy(hashp); errno = save_errno; return (NULL); } dbp->internal = hashp; dbp->close = hash_close; dbp->del = hash_delete; dbp->fd = hash_fd; dbp->get = hash_get; dbp->put = hash_put; dbp->seq = hash_seq; dbp->sync = hash_sync; dbp->type = DB_HASH; #ifdef DEBUG (void)fprintf( stderr, "%s\n%s%x\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%x\n%s%x\n%s%d\n%s%d\n", "init_htab:", "TABLE POINTER ", hashp, "BUCKET SIZE ", hashp->BSIZE, "BUCKET SHIFT ", hashp->BSHIFT, "DIRECTORY SIZE ", hashp->DSIZE, "SEGMENT SIZE ", hashp->SGSIZE, "SEGMENT SHIFT ", hashp->SSHIFT, "FILL FACTOR ", hashp->FFACTOR, "MAX BUCKET ", hashp->MAX_BUCKET, "OVFL POINT ", hashp->OVFL_POINT, "LAST FREED ", hashp->LAST_FREED, "HIGH MASK ", hashp->HIGH_MASK, "LOW MASK ", hashp->LOW_MASK, "NSEGS ", hashp->nsegs, "NKEYS ", hashp->NKEYS); #endif #ifdef HASH_STATISTICS hash_overflows = hash_accesses = hash_collisions = hash_expansions = 0; #endif return (dbp); error1: if (hashp != NULL) (void)close(hashp->fp); error0: free(hashp); errno = save_errno; return (NULL); } static int hash_close(DB *dbp) { HTAB *hashp; int retval; if (!dbp) return (ERROR); hashp = (HTAB *)dbp->internal; retval = hdestroy(hashp); free(dbp); return (retval); } static int hash_fd(const DB *dbp) { HTAB *hashp; if (!dbp) return (ERROR); hashp = (HTAB *)dbp->internal; if (hashp->fp == -1) { errno = ENOENT; return (-1); } return (hashp->fp); } /************************** LOCAL CREATION ROUTINES **********************/ static HTAB * init_hash(HTAB *hashp, const char *file, const HASHINFO *info) { #ifdef __USE_INTERNAL_STAT64 struct stat64 statbuf; #else struct stat statbuf; #endif int nelem; nelem = 1; hashp->NKEYS = 0; hashp->LORDER = DB_BYTE_ORDER; hashp->BSIZE = DEF_BUCKET_SIZE; hashp->BSHIFT = DEF_BUCKET_SHIFT; hashp->SGSIZE = DEF_SEGSIZE; hashp->SSHIFT = DEF_SEGSIZE_SHIFT; hashp->DSIZE = DEF_DIRSIZE; hashp->FFACTOR = DEF_FFACTOR; hashp->hash = __default_hash; memset(hashp->SPARES, 0, sizeof(hashp->SPARES)); memset(hashp->BITMAPS, 0, sizeof(hashp->BITMAPS)); /* Fix bucket size to be optimal for file system */ if (file != NULL) { #ifdef __USE_INTERNAL_STAT64 if (stat64(file, &statbuf)) #else if (stat(file, &statbuf)) #endif return (NULL); hashp->BSIZE = MIN(statbuf.st_blksize, MAX_BSIZE); hashp->BSHIFT = __log2(hashp->BSIZE); } if (info) { if (info->bsize) { /* Round pagesize up to power of 2 */ hashp->BSHIFT = __log2(info->bsize); hashp->BSIZE = 1 << hashp->BSHIFT; if (hashp->BSIZE > MAX_BSIZE) { errno = EINVAL; return (NULL); } } if (info->ffactor) hashp->FFACTOR = info->ffactor; if (info->hash) hashp->hash = info->hash; if (info->nelem) nelem = info->nelem; if (info->lorder) { if (info->lorder != DB_BIG_ENDIAN && info->lorder != DB_LITTLE_ENDIAN) { errno = EINVAL; return (NULL); } hashp->LORDER = info->lorder; } } /* init_htab should destroy the table and set errno if it fails */ if (init_htab(hashp, nelem)) return (NULL); else return (hashp); } /* * This calls alloc_segs which may run out of memory. Alloc_segs will destroy * the table and set errno, so we just pass the error information along. * * Returns 0 on No Error */ static int init_htab(HTAB *hashp, int nelem) { int nbuckets, nsegs; int l2; /* * Divide number of elements by the fill factor and determine a * desired number of buckets. Allocate space for the next greater * power of two number of buckets. */ nelem = (nelem - 1) / hashp->FFACTOR + 1; l2 = __log2(MAX(nelem, 2)); nbuckets = 1 << l2; hashp->SPARES[l2] = l2 + 1; hashp->SPARES[l2 + 1] = l2 + 1; hashp->OVFL_POINT = l2; hashp->LAST_FREED = 2; /* First bitmap page is at: splitpoint l2 page offset 1 */ if (__ibitmap(hashp, OADDR_OF(l2, 1), l2 + 1, 0)) return (-1); hashp->MAX_BUCKET = hashp->LOW_MASK = nbuckets - 1; hashp->HIGH_MASK = (nbuckets << 1) - 1; hashp->HDRPAGES = ((MAX(sizeof(HASHHDR), MINHDRSIZE) - 1) >> hashp->BSHIFT) + 1; nsegs = (nbuckets - 1) / hashp->SGSIZE + 1; nsegs = 1 << __log2(nsegs); if (nsegs > hashp->DSIZE) hashp->DSIZE = nsegs; return (alloc_segs(hashp, nsegs)); } /********************** DESTROY/CLOSE ROUTINES ************************/ /* * Flushes any changes to the file if necessary and destroys the hashp * structure, freeing all allocated space. */ static int hdestroy(HTAB *hashp) { int i, save_errno; save_errno = 0; #ifdef HASH_STATISTICS (void)fprintf(stderr, "hdestroy: accesses %ld collisions %ld\n", hash_accesses, hash_collisions); (void)fprintf(stderr, "hdestroy: expansions %ld\n", hash_expansions); (void)fprintf(stderr, "hdestroy: overflows %ld\n", hash_overflows); (void)fprintf(stderr, "keys %ld maxp %d segmentcount %d\n", hashp->NKEYS, hashp->MAX_BUCKET, hashp->nsegs); for (i = 0; i < NCACHED; i++) (void)fprintf(stderr, "spares[%d] = %d\n", i, hashp->SPARES[i]); #endif /* * Call on buffer manager to free buffers, and if required, * write them to disk. */ if (__buf_free(hashp, 1, hashp->save_file)) save_errno = errno; if (hashp->dir) { free(*hashp->dir); /* Free initial segments */ /* Free extra segments */ while (hashp->exsegs--) free(hashp->dir[--hashp->nsegs]); free(hashp->dir); } if (flush_meta(hashp) && !save_errno) save_errno = errno; /* Free Bigmaps */ for (i = 0; i < hashp->nmaps; i++) if (hashp->mapp[i]) free(hashp->mapp[i]); if (hashp->fp != -1) (void)close(hashp->fp); free(hashp); if (save_errno) { errno = save_errno; return (ERROR); } return (SUCCESS); } /* * Write modified pages to disk * * Returns: * 0 == OK * -1 ERROR */ static int hash_sync(const DB *dbp, u_int flags) { HTAB *hashp; if (flags != 0) { errno = EINVAL; return (ERROR); } if (!dbp) return (ERROR); hashp = (HTAB *)dbp->internal; if (!hashp->save_file) return (0); if (__buf_free(hashp, 0, 1) || flush_meta(hashp)) return (ERROR); hashp->new_file = 0; return (0); } /* * Returns: * 0 == OK * -1 indicates that errno should be set */ static int flush_meta(HTAB *hashp) { HASHHDR *whdrp; #if (_BYTE_ORDER == _LITTLE_ENDIAN) HASHHDR whdr; #endif int fp, i, wsize; if (!hashp->save_file) return (0); hashp->MAGIC = HASHMAGIC; hashp->HASH_VERSION = HASHVERSION; hashp->H_CHARKEY = hashp->hash(CHARKEY, sizeof(CHARKEY)); fp = hashp->fp; whdrp = &hashp->hdr; #if (_BYTE_ORDER == _LITTLE_ENDIAN) whdrp = &whdr; swap_header_copy(&hashp->hdr, whdrp); #endif if ((lseek(fp, (off_t)0, SEEK_SET) == -1) || ((wsize = write(fp, whdrp, sizeof(HASHHDR))) == -1)) return (-1); else if (wsize != sizeof(HASHHDR)) { errno = EFTYPE; hashp->error = errno; return (-1); } for (i = 0; i < NCACHED; i++) if (hashp->mapp[i]) if (__put_page(hashp, (char *)hashp->mapp[i], hashp->BITMAPS[i], 0, 1)) return (-1); return (0); } /*******************************SEARCH ROUTINES *****************************/ /* * All the access routines return * * Returns: * 0 on SUCCESS * 1 to indicate an external ERROR (i.e. key not found, etc) * -1 to indicate an internal ERROR (i.e. out of memory, etc) */ static int hash_get(const DB *dbp, const DBT *key, DBT *data, u_int flag) { HTAB *hashp; hashp = (HTAB *)dbp->internal; if (flag) { hashp->error = errno = EINVAL; return (ERROR); } return (hash_access(hashp, HASH_GET, (DBT *)key, data)); } static int hash_put(const DB *dbp, DBT *key, const DBT *data, u_int flag) { HTAB *hashp; hashp = (HTAB *)dbp->internal; if (flag && flag != R_NOOVERWRITE) { hashp->error = EINVAL; errno = EINVAL; return (ERROR); } if ((hashp->flags & O_ACCMODE) == O_RDONLY) { hashp->error = errno = EPERM; return (ERROR); } return (hash_access(hashp, flag == R_NOOVERWRITE ? HASH_PUTNEW : HASH_PUT, (DBT *)key, (DBT *)data)); } static int hash_delete(const DB *dbp, const DBT *key, u_int flag /* Ignored */ ) { HTAB *hashp; hashp = (HTAB *)dbp->internal; if (flag && flag != R_CURSOR) { hashp->error = errno = EINVAL; return (ERROR); } if ((hashp->flags & O_ACCMODE) == O_RDONLY) { hashp->error = errno = EPERM; return (ERROR); } return (hash_access(hashp, HASH_DELETE, (DBT *)key, NULL)); } /* * Assume that hashp has been set in wrapper routine. */ static int hash_access(HTAB *hashp, HASH_ACTION action, DBT *key, DBT *val) { BUFHEAD *rbufp; BUFHEAD *bufp, *save_bufp; __uint16_t *bp; int n, ndx, off, size; char *kp; __uint16_t pageno; #ifdef HASH_STATISTICS hash_accesses++; #endif off = hashp->BSIZE; size = key->size; kp = (char *)key->data; rbufp = __get_buf(hashp, __call_hash(hashp, kp, size), NULL, 0); if (!rbufp) return (ERROR); save_bufp = rbufp; /* Pin the bucket chain */ rbufp->flags |= BUF_PIN; for (bp = (__uint16_t *)rbufp->page, n = *bp++, ndx = 1; ndx < n;) if (bp[1] >= REAL_KEY) { /* Real key/data pair */ if (size == off - (int)*bp && memcmp(kp, rbufp->page + *bp, size) == 0) goto found; off = bp[1]; #ifdef HASH_STATISTICS hash_collisions++; #endif bp += 2; ndx += 2; } else if (bp[1] == OVFLPAGE) { rbufp = __get_buf(hashp, *bp, rbufp, 0); if (!rbufp) { save_bufp->flags &= ~BUF_PIN; return (ERROR); } /* FOR LOOP INIT */ bp = (__uint16_t *)rbufp->page; n = *bp++; ndx = 1; off = hashp->BSIZE; } else if (bp[1] < REAL_KEY) { if ((ndx = __find_bigpair(hashp, rbufp, ndx, kp, size)) > 0) goto found; if (ndx == -2) { bufp = rbufp; if (!(pageno = __find_last_page(hashp, &bufp))) { ndx = 0; rbufp = bufp; break; /* FOR */ } rbufp = __get_buf(hashp, pageno, bufp, 0); if (!rbufp) { save_bufp->flags &= ~BUF_PIN; return (ERROR); } /* FOR LOOP INIT */ bp = (__uint16_t *)rbufp->page; n = *bp++; ndx = 1; off = hashp->BSIZE; } else { save_bufp->flags &= ~BUF_PIN; return (ERROR); } } /* Not found */ switch (action) { case HASH_PUT: case HASH_PUTNEW: if (__addel(hashp, rbufp, key, val)) { save_bufp->flags &= ~BUF_PIN; return (ERROR); } else { save_bufp->flags &= ~BUF_PIN; return (SUCCESS); } case HASH_GET: case HASH_DELETE: default: save_bufp->flags &= ~BUF_PIN; return (ABNORMAL); } found: switch (action) { case HASH_PUTNEW: save_bufp->flags &= ~BUF_PIN; return (ABNORMAL); case HASH_GET: bp = (__uint16_t *)rbufp->page; if (bp[ndx + 1] < REAL_KEY) { if (__big_return(hashp, rbufp, ndx, val, 0)) return (ERROR); } else { val->data = (u_char *)rbufp->page + (int)bp[ndx + 1]; val->size = bp[ndx] - bp[ndx + 1]; } break; case HASH_PUT: if ((__delpair(hashp, rbufp, ndx)) || (__addel(hashp, rbufp, key, val))) { save_bufp->flags &= ~BUF_PIN; return (ERROR); } break; case HASH_DELETE: if (__delpair(hashp, rbufp, ndx)) return (ERROR); break; default: abort(); } save_bufp->flags &= ~BUF_PIN; return (SUCCESS); } static int hash_seq(const DB *dbp, DBT *key, DBT *data, u_int flag) { int32_t bucket; BUFHEAD *bufp; HTAB *hashp; __uint16_t *bp, ndx; hashp = (HTAB *)dbp->internal; if (flag && flag != R_FIRST && flag != R_NEXT) { hashp->error = errno = EINVAL; return (ERROR); } #ifdef HASH_STATISTICS hash_accesses++; #endif if ((hashp->cbucket < 0) || (flag == R_FIRST)) { hashp->cbucket = 0; hashp->cndx = 1; hashp->cpage = NULL; } for (bp = NULL; !bp || !bp[0];) { if (!(bufp = hashp->cpage)) { for (bucket = hashp->cbucket; bucket <= hashp->MAX_BUCKET; bucket++, hashp->cndx = 1) { bufp = __get_buf(hashp, bucket, NULL, 0); if (!bufp) return (ERROR); hashp->cpage = bufp; bp = (__uint16_t *)bufp->page; if (bp[0]) break; } hashp->cbucket = bucket; if (hashp->cbucket > hashp->MAX_BUCKET) { hashp->cbucket = -1; return (ABNORMAL); } } else bp = (__uint16_t *)hashp->cpage->page; assert(bp); assert(bufp); while (bp[hashp->cndx + 1] == OVFLPAGE) { bufp = hashp->cpage = __get_buf(hashp, bp[hashp->cndx], bufp, 0); if (!bufp) return (ERROR); bp = (__uint16_t *)(bufp->page); hashp->cndx = 1; } if (!bp[0]) { hashp->cpage = NULL; ++hashp->cbucket; } } ndx = hashp->cndx; if (bp[ndx + 1] < REAL_KEY) { if (__big_keydata(hashp, bufp, key, data, 1)) return (ERROR); } else { key->data = (u_char *)hashp->cpage->page + bp[ndx]; key->size = (ndx > 1 ? bp[ndx - 1] : hashp->BSIZE) - bp[ndx]; data->data = (u_char *)hashp->cpage->page + bp[ndx + 1]; data->size = bp[ndx] - bp[ndx + 1]; ndx += 2; if (ndx > bp[0]) { hashp->cpage = NULL; hashp->cbucket++; hashp->cndx = 1; } else hashp->cndx = ndx; } return (SUCCESS); } /********************************* UTILITIES ************************/ /* * Returns: * 0 ==> OK * -1 ==> Error */ extern int __expand_table(HTAB *hashp) { int32_t old_bucket, new_bucket; int dirsize, new_segnum, spare_ndx; #ifdef HASH_STATISTICS hash_expansions++; #endif new_bucket = ++hashp->MAX_BUCKET; old_bucket = (hashp->MAX_BUCKET & hashp->LOW_MASK); new_segnum = new_bucket >> hashp->SSHIFT; /* Check if we need a new segment */ if (new_segnum >= hashp->nsegs) { /* Check if we need to expand directory */ if (new_segnum >= hashp->DSIZE) { /* Reallocate directory */ dirsize = hashp->DSIZE * sizeof(SEGMENT *); if (!hash_realloc(&hashp->dir, dirsize, dirsize << 1)) return (-1); hashp->DSIZE = dirsize << 1; } SEGMENT seg = calloc(hashp->SGSIZE, sizeof(SEGMENT)); if (seg == NULL) return (-1); hashp->dir[new_segnum] = seg; hashp->exsegs++; hashp->nsegs++; } /* * If the split point is increasing (MAX_BUCKET's log base 2 * * increases), we need to copy the current contents of the spare * split bucket to the next bucket. */ spare_ndx = __log2(hashp->MAX_BUCKET + 1); if (spare_ndx > hashp->OVFL_POINT) { hashp->SPARES[spare_ndx] = hashp->SPARES[hashp->OVFL_POINT]; hashp->OVFL_POINT = spare_ndx; } if (new_bucket > hashp->HIGH_MASK) { /* Starting a new doubling */ hashp->LOW_MASK = hashp->HIGH_MASK; hashp->HIGH_MASK = new_bucket | hashp->LOW_MASK; } /* Relocate records to the new bucket */ return (__split_page(hashp, old_bucket, new_bucket)); } /* * If realloc guarantees that the pointer is not destroyed if the realloc * fails, then this routine can go away. */ static void * hash_realloc(SEGMENT **p_ptr, int oldsize, int newsize) { void *p; if ((p = malloc(newsize))) { memmove(p, *p_ptr, oldsize); memset((char *)p + oldsize, 0, newsize - oldsize); free(*p_ptr); *p_ptr = p; } return (p); } extern __uint32_t __call_hash(HTAB *hashp, char *k, int len) { int32_t n, bucket; n = hashp->hash(k, len); bucket = n & hashp->HIGH_MASK; if (bucket > hashp->MAX_BUCKET) bucket = bucket & hashp->LOW_MASK; return (bucket); } /* * Allocate segment table. On error, destroy the table and set errno. * * Returns 0 on success */ static int alloc_segs(HTAB *hashp, int nsegs) { int i; SEGMENT store; int save_errno; if ((hashp->dir = (SEGMENT *)calloc(hashp->DSIZE, sizeof(SEGMENT *))) == NULL) { save_errno = errno; (void)hdestroy(hashp); errno = save_errno; return (-1); } /* Allocate segments */ if ((store = (SEGMENT)calloc(nsegs << hashp->SSHIFT, sizeof(SEGMENT))) == NULL) { save_errno = errno; (void)hdestroy(hashp); errno = save_errno; return (-1); } hashp->dir[0] = store; for (i = 1; i < nsegs; i++, hashp->nsegs++) hashp->dir[i] = &store[i << hashp->SSHIFT]; return (0); } #if (_BYTE_ORDER == _LITTLE_ENDIAN) /* * Hashp->hdr needs to be byteswapped. */ static void swap_header_copy(HASHHDR *srcp, HASHHDR *destp) { int i; P_32_COPY(srcp->magic, destp->magic); P_32_COPY(srcp->version, destp->version); P_32_COPY(srcp->lorder, destp->lorder); P_32_COPY(srcp->bsize, destp->bsize); P_32_COPY(srcp->bshift, destp->bshift); P_32_COPY(srcp->dsize, destp->dsize); P_32_COPY(srcp->ssize, destp->ssize); P_32_COPY(srcp->sshift, destp->sshift); P_32_COPY(srcp->ovfl_point, destp->ovfl_point); P_32_COPY(srcp->last_freed, destp->last_freed); P_32_COPY(srcp->max_bucket, destp->max_bucket); P_32_COPY(srcp->high_mask, destp->high_mask); P_32_COPY(srcp->low_mask, destp->low_mask); P_32_COPY(srcp->ffactor, destp->ffactor); P_32_COPY(srcp->nkeys, destp->nkeys); P_32_COPY(srcp->hdrpages, destp->hdrpages); P_32_COPY(srcp->h_charkey, destp->h_charkey); for (i = 0; i < NCACHED; i++) { P_32_COPY(srcp->spares[i], destp->spares[i]); P_16_COPY(srcp->bitmaps[i], destp->bitmaps[i]); } } static void swap_header(HTAB *hashp) { HASHHDR *hdrp; int i; hdrp = &hashp->hdr; M_32_SWAP(hdrp->magic); M_32_SWAP(hdrp->version); M_32_SWAP(hdrp->lorder); M_32_SWAP(hdrp->bsize); M_32_SWAP(hdrp->bshift); M_32_SWAP(hdrp->dsize); M_32_SWAP(hdrp->ssize); M_32_SWAP(hdrp->sshift); M_32_SWAP(hdrp->ovfl_point); M_32_SWAP(hdrp->last_freed); M_32_SWAP(hdrp->max_bucket); M_32_SWAP(hdrp->high_mask); M_32_SWAP(hdrp->low_mask); M_32_SWAP(hdrp->ffactor); M_32_SWAP(hdrp->nkeys); M_32_SWAP(hdrp->hdrpages); M_32_SWAP(hdrp->h_charkey); for (i = 0; i < NCACHED; i++) { M_32_SWAP(hdrp->spares[i]); M_16_SWAP(hdrp->bitmaps[i]); } } #endif picolibc-1.8.11/libc/search/hash.h000066400000000000000000000274011513574234600166560ustar00rootroot00000000000000/*- * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Margo Seltzer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)hash.h 8.3 (Berkeley) 5/31/94 * $FreeBSD: src/lib/libc/db/hash/hash.h,v 1.6 2002/03/21 22:46:26 obrien Exp $ */ #include #define __need_size_t #include #include /* Check that newlib understands the byte order of its target system. */ #ifndef _BYTE_ORDER #error _BYTE_ORDER not defined by sys/param.h #endif /* Define DB endianness constants based on target endianness. */ #define DB_LITTLE_ENDIAN 1234 #define DB_BIG_ENDIAN 4321 #if (_BYTE_ORDER == _LITTLE_ENDIAN) #define DB_BYTE_ORDER DB_LITTLE_ENDIAN #else #define DB_BYTE_ORDER DB_BIG_ENDIAN #endif /* Operations */ typedef enum { HASH_GET, HASH_PUT, HASH_PUTNEW, HASH_DELETE, HASH_FIRST, HASH_NEXT } HASH_ACTION; /* Buffer Management structures */ typedef struct _bufhead BUFHEAD; struct _bufhead { BUFHEAD *prev; /* LRU links */ BUFHEAD *next; /* LRU links */ BUFHEAD *ovfl; /* Overflow page buffer header */ __uint32_t addr; /* Address of this page */ char *page; /* Actual page data */ char flags; #define BUF_MOD 0x0001 #define BUF_DISK 0x0002 #define BUF_BUCKET 0x0004 #define BUF_PIN 0x0008 }; #define IS_BUCKET(X) ((X) & BUF_BUCKET) typedef BUFHEAD **SEGMENT; #ifdef __GNUCLIKE_PRAGMA_DIAGNOSTIC #pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wunknown-warning-option" /* 'bsize' is used directly with malloc/realloc which confuses -fanalyzer */ #pragma GCC diagnostic ignored "-Wanalyzer-allocation-size" #endif /* Hash Table Information */ typedef struct hashhdr { /* Disk resident portion */ int32_t magic; /* Magic NO for hash tables */ int32_t version; /* Version ID */ __uint32_t lorder; /* Byte Order */ int32_t bsize; /* Bucket/Page Size */ int32_t bshift; /* Bucket shift */ int32_t dsize; /* Directory Size */ int32_t ssize; /* Segment Size */ int32_t sshift; /* Segment shift */ int32_t ovfl_point; /* Where overflow pages are being * allocated */ int32_t last_freed; /* Last overflow page freed */ int32_t max_bucket; /* ID of Maximum bucket in use */ int32_t high_mask; /* Mask to modulo into entire table */ int32_t low_mask; /* Mask to modulo into lower half of * table */ int32_t ffactor; /* Fill factor */ int32_t nkeys; /* Number of keys in hash table */ int32_t hdrpages; /* Size of table header */ uint32_t h_charkey; /* value of hash(CHARKEY) */ #define NCACHED \ 32 /* number of bit maps and spare \ * points */ int32_t spares[NCACHED]; /* spare pages for overflow */ __uint16_t bitmaps[NCACHED]; /* address of overflow page * bitmaps */ } HASHHDR; typedef struct htab { /* Memory resident data structure */ HASHHDR hdr; /* Header */ int nsegs; /* Number of allocated segments */ int exsegs; /* Number of extra allocated * segments */ __uint32_t /* Hash function */ (*hash)(const void *, size_t); int flags; /* Flag values */ int fp; /* File pointer */ char *tmp_buf; /* Temporary Buffer for BIG data */ char *tmp_key; /* Temporary Buffer for BIG keys */ BUFHEAD *cpage; /* Current page */ int32_t cbucket; /* Current bucket */ int cndx; /* Index of next item on cpage */ int error; /* Error Number -- for DBM * compatibility */ int new_file; /* Indicates if fd is backing store * or no */ int save_file; /* Indicates whether we need to flush * file at * exit */ __uint32_t *mapp[NCACHED]; /* Pointers to page maps */ int nmaps; /* Initial number of bitmaps */ int nbufs; /* Number of buffers left to * allocate */ BUFHEAD bufhead; /* Header of buffer lru list */ SEGMENT *dir; /* Hash Bucket directory */ } HTAB; /* * Constants */ #if INT_MAX == 32767 #define MAX_BSIZE 4096 #else #define MAX_BSIZE 65536 /* 2^16 */ #endif #define MIN_BUFFERS 6 #define MINHDRSIZE 512 #if INT_MAX == 32767 #define DEF_BUFSIZE 4096 #else #define DEF_BUFSIZE 65536 /* 64 K */ #endif #define DEF_BUCKET_SIZE 4096 #define DEF_BUCKET_SHIFT 12 /* log2(BUCKET) */ #define DEF_SEGSIZE 256 #define DEF_SEGSIZE_SHIFT 8 /* log2(SEGSIZE) */ #define DEF_DIRSIZE 256 #define DEF_FFACTOR 65536 #define MIN_FFACTOR 4 #define SPLTMAX 8 #define CHARKEY "%$sniglet^&" #define NUMKEY 1038583 #define BYTE_SHIFT 3 #define INT_TO_BYTE 2 #define INT_BYTE_SHIFT 5 #define ALL_SET ((__uint32_t)0xFFFFFFFF) #define ALL_CLEAR 0 #define PTROF(X) ((BUFHEAD *)((ptrdiff_t)(X) & ~0x3)) #define ISMOD(X) ((__uint32_t)(ptrdiff_t)(X) & 0x1) #define DOMOD(X) ((X) = (char *)((ptrdiff_t)(X) | 0x1)) #define ISDISK(X) ((__uint32_t)(ptrdiff_t)(X) & 0x2) #define DODISK(X) ((X) = (char *)((ptrdiff_t)(X) | 0x2)) #define BITS_PER_MAP 32 /* Given the address of the beginning of a big map, clear/set the nth bit */ #define CLRBIT(A, N) ((A)[(N) / BITS_PER_MAP] &= ~(1 << ((N) % BITS_PER_MAP))) #define SETBIT(A, N) ((A)[(N) / BITS_PER_MAP] |= (1 << ((N) % BITS_PER_MAP))) #define ISSET(A, N) ((A)[(N) / BITS_PER_MAP] & (1 << ((N) % BITS_PER_MAP))) /* Overflow management */ /* * Overflow page numbers are allocated per split point. At each doubling of * the table, we can allocate extra pages. So, an overflow page number has * the top 5 bits indicate which split point and the lower 11 bits indicate * which page at that split point is indicated (pages within split points are * numberered starting with 1). */ #define SPLITSHIFT 11 #define SPLITMASK 0x7FF #define SPLITNUM(N) (((__uint32_t)(N)) >> SPLITSHIFT) #define OPAGENUM(N) ((N) & SPLITMASK) #define OADDR_OF(S, O) ((__uint32_t)((__uint32_t)(S) << SPLITSHIFT) + (O)) #define BUCKET_TO_PAGE(B) (B) + hashp->HDRPAGES + ((B) ? hashp->SPARES[__log2((B) + 1) - 1] : 0) #define OADDR_TO_PAGE(B) BUCKET_TO_PAGE((1 << SPLITNUM((B))) - 1) + OPAGENUM((B)); /* * page.h contains a detailed description of the page format. * * Normally, keys and data are accessed from offset tables in the top of * each page which point to the beginning of the key and data. There are * four flag values which may be stored in these offset tables which indicate * the following: * * * OVFLPAGE Rather than a key data pair, this pair contains * the address of an overflow page. The format of * the pair is: * OVERFLOW_PAGE_NUMBER OVFLPAGE * * PARTIAL_KEY This must be the first key/data pair on a page * and implies that page contains only a partial key. * That is, the key is too big to fit on a single page * so it starts on this page and continues on the next. * The format of the page is: * KEY_OFF PARTIAL_KEY OVFL_PAGENO OVFLPAGE * * KEY_OFF -- offset of the beginning of the key * PARTIAL_KEY -- 1 * OVFL_PAGENO - page number of the next overflow page * OVFLPAGE -- 0 * * FULL_KEY This must be the first key/data pair on the page. It * is used in two cases. * * Case 1: * There is a complete key on the page but no data * (because it wouldn't fit). The next page contains * the data. * * Page format it: * KEY_OFF FULL_KEY OVFL_PAGENO OVFL_PAGE * * KEY_OFF -- offset of the beginning of the key * FULL_KEY -- 2 * OVFL_PAGENO - page number of the next overflow page * OVFLPAGE -- 0 * * Case 2: * This page contains no key, but part of a large * data field, which is continued on the next page. * * Page format it: * DATA_OFF FULL_KEY OVFL_PAGENO OVFL_PAGE * * KEY_OFF -- offset of the beginning of the data on * this page * FULL_KEY -- 2 * OVFL_PAGENO - page number of the next overflow page * OVFLPAGE -- 0 * * FULL_KEY_DATA * This must be the first key/data pair on the page. * There are two cases: * * Case 1: * This page contains a key and the beginning of the * data field, but the data field is continued on the * next page. * * Page format is: * KEY_OFF FULL_KEY_DATA OVFL_PAGENO DATA_OFF * * KEY_OFF -- offset of the beginning of the key * FULL_KEY_DATA -- 3 * OVFL_PAGENO - page number of the next overflow page * DATA_OFF -- offset of the beginning of the data * * Case 2: * This page contains the last page of a big data pair. * There is no key, only the tail end of the data * on this page. * * Page format is: * DATA_OFF FULL_KEY_DATA * * DATA_OFF -- offset of the beginning of the data on * this page * FULL_KEY_DATA -- 3 * OVFL_PAGENO - page number of the next overflow page * OVFLPAGE -- 0 * * OVFL_PAGENO and OVFLPAGE are optional (they are * not present if there is no next page). */ #define OVFLPAGE 0 #define PARTIAL_KEY 1 #define FULL_KEY 2 #define FULL_KEY_DATA 3 #define REAL_KEY 4 /* Short hands for accessing structure */ #define BSIZE hdr.bsize #define BSHIFT hdr.bshift #define DSIZE hdr.dsize #define SGSIZE hdr.ssize #define SSHIFT hdr.sshift #define LORDER hdr.lorder #define OVFL_POINT hdr.ovfl_point #define LAST_FREED hdr.last_freed #define MAX_BUCKET hdr.max_bucket #define FFACTOR hdr.ffactor #define HIGH_MASK hdr.high_mask #define LOW_MASK hdr.low_mask #define NKEYS hdr.nkeys #define HDRPAGES hdr.hdrpages #define SPARES hdr.spares #define BITMAPS hdr.bitmaps #define HASH_VERSION hdr.version #define MAGIC hdr.magic #define NEXT_FREE hdr.next_free #define H_CHARKEY hdr.h_charkey picolibc-1.8.11/libc/search/hash_bigkey.c000066400000000000000000000436501513574234600202070ustar00rootroot00000000000000/*- * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Margo Seltzer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)hash_bigkey.c 8.3 (Berkeley) 5/31/94"; #endif /* LIBC_SCCS and not lint */ /* * PACKAGE: hash * DESCRIPTION: * Big key/data handling for the hashing package. * * ROUTINES: * External * __big_keydata * __big_split * __big_insert * __big_return * __big_delete * __find_last_page * Internal * collect_key * collect_data */ #include #include #include #include #include #ifdef DEBUG #include #endif #include "db_local.h" #include "hash.h" #include "page.h" #include "extern.h" static size_t collect_key(HTAB *, BUFHEAD *, size_t, DBT *, int); static size_t collect_data(HTAB *, BUFHEAD *, size_t, int); /* * Big_insert * * You need to do an insert and the key/data pair is too big * * Returns: * 0 ==> OK *-1 ==> ERROR */ extern int __big_insert(HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val) { __uint16_t *p; size_t key_size, n; size_t val_size; __uint16_t space, move_bytes, off; char *cp, *key_data, *val_data; cp = bufp->page; /* Character pointer of p. */ p = (__uint16_t *)cp; key_data = (char *)key->data; key_size = key->size; val_data = (char *)val->data; val_size = val->size; /* First move the Key */ for (space = FREESPACE(p) - BIGOVERHEAD; key_size; space = FREESPACE(p) - BIGOVERHEAD) { move_bytes = MIN(space, key_size); off = OFFSET(p) - move_bytes; memmove(cp + off, key_data, move_bytes); key_size -= move_bytes; key_data += move_bytes; n = p[0]; p[++n] = off; p[0] = ++n; FREESPACE(p) = off - PAGE_META(n); OFFSET(p) = off; p[n] = PARTIAL_KEY; bufp = __add_ovflpage(hashp, bufp); if (!bufp) return (-1); n = p[0]; if (!key_size) { if (FREESPACE(p)) { move_bytes = MIN(FREESPACE(p), val_size); off = OFFSET(p) - move_bytes; p[n] = off; memmove(cp + off, val_data, move_bytes); val_data += move_bytes; val_size -= move_bytes; p[n - 2] = FULL_KEY_DATA; FREESPACE(p) = FREESPACE(p) - move_bytes; OFFSET(p) = off; } else p[n - 2] = FULL_KEY; } p = (__uint16_t *)bufp->page; cp = bufp->page; bufp->flags |= BUF_MOD; } /* Now move the data */ for (space = FREESPACE(p) - BIGOVERHEAD; val_size; space = FREESPACE(p) - BIGOVERHEAD) { move_bytes = MIN(space, val_size); /* * Here's the hack to make sure that if the data ends on the * same page as the key ends, FREESPACE is at least one. */ if (space == val_size && val_size == val->size) move_bytes--; off = OFFSET(p) - move_bytes; memmove(cp + off, val_data, move_bytes); val_size -= move_bytes; val_data += move_bytes; n = p[0]; p[++n] = off; p[0] = ++n; FREESPACE(p) = off - PAGE_META(n); OFFSET(p) = off; if (val_size) { p[n] = FULL_KEY; bufp = __add_ovflpage(hashp, bufp); if (!bufp) return (-1); cp = bufp->page; p = (__uint16_t *)cp; } else p[n] = FULL_KEY_DATA; bufp->flags |= BUF_MOD; } return (0); } /* * Called when bufp's page contains a partial key (index should be 1) * * All pages in the big key/data pair except bufp are freed. We cannot * free bufp because the page pointing to it is lost and we can't get rid * of its pointer. * * Returns: * 0 => OK *-1 => ERROR */ extern int __big_delete(HTAB *hashp, BUFHEAD *bufp) { BUFHEAD *last_bfp, *rbufp; __uint16_t *bp, pageno; int key_done, n; rbufp = bufp; last_bfp = NULL; bp = (__uint16_t *)bufp->page; pageno = 0; key_done = 0; while (!key_done || (bp[2] != FULL_KEY_DATA)) { if (bp[2] == FULL_KEY || bp[2] == FULL_KEY_DATA) key_done = 1; /* * If there is freespace left on a FULL_KEY_DATA page, then * the data is short and fits entirely on this page, and this * is the last page. */ if (bp[2] == FULL_KEY_DATA && FREESPACE(bp)) break; pageno = bp[bp[0] - 1]; rbufp->flags |= BUF_MOD; rbufp = __get_buf(hashp, pageno, rbufp, 0); if (last_bfp) __free_ovflpage(hashp, last_bfp); last_bfp = rbufp; if (!rbufp) return (-1); /* Error. */ bp = (__uint16_t *)rbufp->page; } /* * If we get here then rbufp points to the last page of the big * key/data pair. Bufp points to the first one -- it should now be * empty pointing to the next page after this pair. Can't free it * because we don't have the page pointing to it. */ /* This is information from the last page of the pair. */ n = bp[0]; pageno = bp[n - 1]; /* Now, bp is the first page of the pair. */ bp = (__uint16_t *)bufp->page; if (n > 2) { /* There is an overflow page. */ bp[1] = pageno; bp[2] = OVFLPAGE; bufp->ovfl = rbufp->ovfl; } else /* This is the last page. */ bufp->ovfl = NULL; n -= 2; bp[0] = n; FREESPACE(bp) = hashp->BSIZE - PAGE_META(n); OFFSET(bp) = hashp->BSIZE - 1; bufp->flags |= BUF_MOD; if (rbufp) __free_ovflpage(hashp, rbufp); if (last_bfp != rbufp) __free_ovflpage(hashp, last_bfp); hashp->NKEYS--; return (0); } /* * Returns: * 0 = key not found * -1 = get next overflow page * -2 means key not found and this is big key/data * -3 error */ extern int __find_bigpair(HTAB *hashp, BUFHEAD *bufp, int ndx, char *key, int size) { __uint16_t *bp; char *p; int ksize; __uint16_t bytes; char *kkey; bp = (__uint16_t *)bufp->page; p = bufp->page; ksize = size; kkey = key; for (bytes = hashp->BSIZE - bp[ndx]; (int)bytes <= size && bp[ndx + 1] == PARTIAL_KEY; bytes = hashp->BSIZE - bp[ndx]) { if (memcmp(p + bp[ndx], kkey, bytes)) return (-2); kkey += bytes; ksize -= bytes; bufp = __get_buf(hashp, bp[ndx + 2], bufp, 0); if (!bufp) return (-3); p = bufp->page; bp = (__uint16_t *)p; ndx = 1; } if ((int)bytes != ksize || memcmp(p + bp[ndx], kkey, bytes)) { #ifdef HASH_STATISTICS ++hash_collisions; #endif return (-2); } else return (ndx); } /* * Given the buffer pointer of the first overflow page of a big pair, * find the end of the big pair * * This will set bpp to the buffer header of the last page of the big pair. * It will return the pageno of the overflow page following the last page * of the pair; 0 if there isn't any (i.e. big pair is the last key in the * bucket) */ extern __uint16_t __find_last_page(HTAB *hashp, BUFHEAD **bpp) { BUFHEAD *bufp; __uint16_t *bp, pageno; int n; bufp = *bpp; bp = (__uint16_t *)bufp->page; for (;;) { n = bp[0]; /* * This is the last page if: the tag is FULL_KEY_DATA and * either only 2 entries OVFLPAGE marker is explicit there * is freespace on the page. */ if (bp[2] == FULL_KEY_DATA && ((n == 2) || (bp[n] == OVFLPAGE) || (FREESPACE(bp)))) break; pageno = bp[n - 1]; bufp = __get_buf(hashp, pageno, bufp, 0); if (!bufp) return (0); /* Need to indicate an error! */ bp = (__uint16_t *)bufp->page; } *bpp = bufp; if (bp[0] > 2) return (bp[3]); else return (0); } /* * Return the data for the key/data pair that begins on this page at this * index (index should always be 1). */ extern int __big_return(HTAB *hashp, BUFHEAD *bufp, int ndx, DBT *val, int set_current) { BUFHEAD *save_p; __uint16_t *bp, len, off, save_addr; char *tp; bp = (__uint16_t *)bufp->page; while (bp[ndx + 1] == PARTIAL_KEY) { bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); bp = (__uint16_t *)bufp->page; ndx = 1; } if (bp[ndx + 1] == FULL_KEY) { bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); bp = (__uint16_t *)bufp->page; save_p = bufp; save_addr = save_p->addr; off = bp[1]; len = 0; } else if (!FREESPACE(bp)) { /* * This is a hack. We can't distinguish between * FULL_KEY_DATA that contains complete data or * incomplete data, so we require that if the data * is complete, there is at least 1 byte of free * space left. */ off = bp[bp[0]]; len = bp[1] - off; save_p = bufp; save_addr = bufp->addr; bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); bp = (__uint16_t *)bufp->page; } else { /* The data is all on one page. */ tp = (char *)bp; off = bp[bp[0]]; val->data = (u_char *)tp + off; val->size = bp[1] - off; if (set_current) { if (bp[0] == 2) { /* No more buckets in * chain */ hashp->cpage = NULL; hashp->cbucket++; hashp->cndx = 1; } else { hashp->cpage = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!hashp->cpage) return (-1); hashp->cndx = 1; if (!((__uint16_t *)hashp->cpage->page)[0]) { hashp->cbucket++; hashp->cpage = NULL; } } } return (0); } val->size = collect_data(hashp, bufp, len, set_current); if (val->size == (size_t)-1) return (-1); if (save_p->addr != save_addr) { /* We are pretty short on buffers. */ errno = EINVAL; /* OUT OF BUFFERS */ return (-1); } memmove(hashp->tmp_buf, (save_p->page) + off, len); val->data = (u_char *)hashp->tmp_buf; return (0); } /* * Count how big the total datasize is by recursing through the pages. Then * allocate a buffer and copy the data as you recurse up. */ static size_t collect_data(HTAB *hashp, BUFHEAD *bufp, size_t len, int set) { __uint16_t *bp; char *p; BUFHEAD *xbp; __uint16_t save_addr; size_t mylen, totlen; p = bufp->page; bp = (__uint16_t *)p; mylen = hashp->BSIZE - bp[1]; save_addr = bufp->addr; if (bp[2] == FULL_KEY_DATA) { /* End of Data */ totlen = len + mylen; if (hashp->tmp_buf) free(hashp->tmp_buf); if ((hashp->tmp_buf = (char *)malloc(totlen)) == NULL) return (-1); if (set) { hashp->cndx = 1; if (bp[0] == 2) { /* No more buckets in chain */ hashp->cpage = NULL; hashp->cbucket++; } else { hashp->cpage = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!hashp->cpage) return (-1); else if (!((__uint16_t *)hashp->cpage->page)[0]) { hashp->cbucket++; hashp->cpage = NULL; } } } } else { xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!xbp) return (-1); totlen = collect_data(hashp, xbp, len + mylen, set); if (totlen < 1 || totlen == (size_t)-1) return (-1); } if (bufp->addr != save_addr) { errno = EINVAL; /* Out of buffers. */ return (-1); } memmove(&hashp->tmp_buf[len], (bufp->page) + bp[1], mylen); return (totlen); } /* * Fill in the key and data for this big pair. */ extern int __big_keydata(HTAB *hashp, BUFHEAD *bufp, DBT *key, DBT *val, int set) { key->size = collect_key(hashp, bufp, 0, val, set); if (key->size == (size_t)-1) return (-1); key->data = (u_char *)hashp->tmp_key; return (0); } /* * Count how big the total key size is by recursing through the pages. Then * collect the data, allocate a buffer and copy the key as you recurse up. */ static size_t collect_key(HTAB *hashp, BUFHEAD *bufp, size_t len, DBT *val, int set) { BUFHEAD *xbp; char *p; size_t mylen, totlen; __uint16_t *bp, save_addr; p = bufp->page; bp = (__uint16_t *)p; mylen = hashp->BSIZE - bp[1]; save_addr = bufp->addr; totlen = len + mylen; if (bp[2] == FULL_KEY || bp[2] == FULL_KEY_DATA) { /* End of Key. */ if (hashp->tmp_key != NULL) free(hashp->tmp_key); if ((hashp->tmp_key = (char *)malloc(totlen)) == NULL) return (-1); if (__big_return(hashp, bufp, 1, val, set)) return (-1); } else { xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!xbp || ((totlen = collect_key(hashp, xbp, totlen, val, set)) < 1)) return (-1); } if (bufp->addr != save_addr) { errno = EINVAL; /* MIS -- OUT OF BUFFERS */ return (-1); } memmove(&hashp->tmp_key[len], (bufp->page) + bp[1], mylen); return (totlen); } /* * Returns: * 0 => OK * -1 => error */ extern int __big_split(HTAB *hashp, BUFHEAD *op, /* Pointer to where to put keys that go in old bucket */ BUFHEAD *np, /* Pointer to new bucket page */ /* Pointer to first page containing the big key/data */ BUFHEAD *big_keyp, int addr, /* Address of big_keyp */ __uint32_t obucket, /* Old Bucket */ SPLIT_RETURN *ret) { BUFHEAD *tmpp; __uint16_t *tp; BUFHEAD *bp; DBT key, val; __uint32_t change; __uint16_t free_space, n, off; bp = big_keyp; /* Now figure out where the big key/data goes */ if (__big_keydata(hashp, big_keyp, &key, &val, 0)) return (-1); change = (__call_hash(hashp, key.data, key.size) != obucket); if ((ret->next_addr = __find_last_page(hashp, &big_keyp))) { if (!(ret->nextp = __get_buf(hashp, ret->next_addr, big_keyp, 0))) return (-1); ; } else ret->nextp = NULL; /* Now make one of np/op point to the big key/data pair */ #ifdef DEBUG assert(np->ovfl == NULL); #endif if (change) tmpp = np; else tmpp = op; tmpp->flags |= BUF_MOD; #ifdef DEBUG1 (void)fprintf(stderr, "BIG_SPLIT: %d->ovfl was %d is now %d\n", tmpp->addr, (tmpp->ovfl ? tmpp->ovfl->addr : 0), (bp ? bp->addr : 0)); #endif tmpp->ovfl = bp; /* one of op/np point to big_keyp */ tp = (__uint16_t *)tmpp->page; #ifdef DEBUG assert(FREESPACE(tp) >= OVFLSIZE); #endif n = tp[0]; off = OFFSET(tp); free_space = FREESPACE(tp); tp[++n] = (__uint16_t)addr; tp[++n] = OVFLPAGE; tp[0] = n; OFFSET(tp) = off; FREESPACE(tp) = free_space - OVFLSIZE; /* * Finally, set the new and old return values. BIG_KEYP contains a * pointer to the last page of the big key_data pair. Make sure that * big_keyp has no following page (2 elements) or create an empty * following page. */ ret->newp = np; ret->oldp = op; tp = (__uint16_t *)big_keyp->page; big_keyp->flags |= BUF_MOD; if (tp[0] > 2) { /* * There may be either one or two offsets on this page. If * there is one, then the overflow page is linked on normally * and tp[4] is OVFLPAGE. If there are two, tp[4] contains * the second offset and needs to get stuffed in after the * next overflow page is added. */ n = tp[4]; free_space = FREESPACE(tp); off = OFFSET(tp); tp[0] -= 2; FREESPACE(tp) = free_space + OVFLSIZE; OFFSET(tp) = off; tmpp = __add_ovflpage(hashp, big_keyp); if (!tmpp) return (-1); tp[4] = n; } else tmpp = big_keyp; if (change) ret->newp = tmpp; else ret->oldp = tmpp; return (0); } picolibc-1.8.11/libc/search/hash_buf.c000066400000000000000000000242501513574234600175040ustar00rootroot00000000000000/*- * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Margo Seltzer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)hash_buf.c 8.5 (Berkeley) 7/15/94"; #endif /* LIBC_SCCS and not lint */ /* * PACKAGE: hash * * DESCRIPTION: * Contains buffer management * * ROUTINES: * External * __buf_init * __get_buf * __buf_free * __reclaim_buf * Internal * newbuf */ #include #include #include #include #ifdef DEBUG #include #endif #include "db_local.h" #include "hash.h" #include "page.h" #include "extern.h" static BUFHEAD *newbuf(HTAB *, __uint32_t, BUFHEAD *); /* Unlink B from its place in the lru */ #define BUF_REMOVE(B) \ { \ (B)->prev->next = (B)->next; \ (B)->next->prev = (B)->prev; \ } /* Insert B after P */ #define BUF_INSERT(B, P) \ { \ (B)->next = (P)->next; \ (B)->prev = (P); \ (P)->next = (B); \ (B)->next->prev = (B); \ } #define MRU hashp->bufhead.next #define LRU hashp->bufhead.prev #define MRU_INSERT(B) BUF_INSERT((B), &hashp->bufhead) #define LRU_INSERT(B) BUF_INSERT((B), LRU) /* Macros for min/max. */ #ifndef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX #define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif /* * We are looking for a buffer with address "addr". If prev_bp is NULL, then * address is a bucket index. If prev_bp is not NULL, then it points to the * page previous to an overflow page that we are trying to find. * * CAVEAT: The buffer header accessed via prev_bp's ovfl field may no longer * be valid. Therefore, you must always verify that its address matches the * address you are seeking. */ extern BUFHEAD * __get_buf(HTAB *hashp, __uint32_t addr, BUFHEAD *prev_bp, int newpage /* If prev_bp set, indicates a new overflow page. */ ) { BUFHEAD *bp; __uint32_t is_disk_mask; int is_disk, segment_ndx = 0; SEGMENT segp = NULL; is_disk = 0; is_disk_mask = 0; if (prev_bp) { bp = prev_bp->ovfl; if (!bp || (bp->addr != addr)) bp = NULL; if (!newpage) is_disk = BUF_DISK; } else { /* Grab buffer out of directory */ segment_ndx = addr & (hashp->SGSIZE - 1); /* valid segment ensured by __call_hash() */ segp = hashp->dir[addr >> hashp->SSHIFT]; #ifdef DEBUG assert(segp != NULL); #endif bp = PTROF(segp[segment_ndx]); is_disk_mask = ISDISK(segp[segment_ndx]); is_disk = is_disk_mask || !hashp->new_file; } if (!bp) { bp = newbuf(hashp, addr, prev_bp); if (!bp || __get_page(hashp, bp->page, addr, !prev_bp, is_disk, 0)) return (NULL); if (!prev_bp) segp[segment_ndx] = (BUFHEAD *)((ptrdiff_t)bp | (intptr_t)is_disk_mask); } else { BUF_REMOVE(bp); MRU_INSERT(bp); } return (bp); } /* * We need a buffer for this page. Either allocate one, or evict a resident * one (if we have as many buffers as we're allowed) and put this one in. * * If newbuf finds an error (returning NULL), it also sets errno. */ static BUFHEAD * newbuf(HTAB *hashp, __uint32_t addr, BUFHEAD *prev_bp) { BUFHEAD *bp; /* The buffer we're going to use */ BUFHEAD *xbp; /* Temp pointer */ BUFHEAD *next_xbp; SEGMENT segp; int segment_ndx; __uint16_t oaddr, *shortp; oaddr = 0; bp = LRU; /* * If LRU buffer is pinned, the buffer pool is too small. We need to * allocate more buffers. */ if (hashp->nbufs || (bp->flags & BUF_PIN)) { /* Allocate a new one */ if ((bp = (BUFHEAD *)malloc(sizeof(BUFHEAD))) == NULL) return (NULL); #ifdef PURIFY memset(bp, 0xff, sizeof(BUFHEAD)); #endif if ((bp->page = (char *)malloc(hashp->BSIZE)) == NULL) { free(bp); return (NULL); } #ifdef PURIFY memset(bp->page, 0xff, hashp->BSIZE); #endif if (hashp->nbufs) hashp->nbufs--; } else { /* Kick someone out */ BUF_REMOVE(bp); /* * If this is an overflow page with addr 0, it's already been * flushed back in an overflow chain and initialized. */ if ((bp->addr != 0) || (bp->flags & BUF_BUCKET)) { /* * Set oaddr before __put_page so that you get it * before bytes are swapped. */ shortp = (__uint16_t *)bp->page; if (shortp[0]) oaddr = shortp[shortp[0] - 1]; if ((bp->flags & BUF_MOD) && __put_page(hashp, bp->page, bp->addr, (int)IS_BUCKET(bp->flags), 0)) return (NULL); /* * Update the pointer to this page (i.e. invalidate it). * * If this is a new file (i.e. we created it at open * time), make sure that we mark pages which have been * written to disk so we retrieve them from disk later, * rather than allocating new pages. */ if (IS_BUCKET(bp->flags)) { segment_ndx = bp->addr & (hashp->SGSIZE - 1); segp = hashp->dir[bp->addr >> hashp->SSHIFT]; #ifdef DEBUG assert(segp != NULL); #endif if (hashp->new_file && ((bp->flags & BUF_MOD) || ISDISK(segp[segment_ndx]))) segp[segment_ndx] = (BUFHEAD *)BUF_DISK; else segp[segment_ndx] = NULL; } /* * Since overflow pages can only be access by means of * their bucket, free overflow pages associated with * this bucket. */ for (xbp = bp; xbp->ovfl;) { next_xbp = xbp->ovfl; xbp->ovfl = 0; xbp = next_xbp; /* Check that ovfl pointer is up date. */ if (IS_BUCKET(xbp->flags) || (oaddr != xbp->addr)) break; shortp = (__uint16_t *)xbp->page; if (shortp[0]) /* set before __put_page */ oaddr = shortp[shortp[0] - 1]; if ((xbp->flags & BUF_MOD) && __put_page(hashp, xbp->page, xbp->addr, 0, 0)) return (NULL); xbp->addr = 0; xbp->flags = 0; BUF_REMOVE(xbp); LRU_INSERT(xbp); } } } /* Now assign this buffer */ bp->addr = addr; #ifdef DEBUG1 (void)fprintf(stderr, "NEWBUF1: %d->ovfl was %d is now %d\n", bp->addr, (bp->ovfl ? bp->ovfl->addr : 0), 0); #endif bp->ovfl = NULL; if (prev_bp) { /* * If prev_bp is set, this is an overflow page, hook it in to * the buffer overflow links. */ #ifdef DEBUG1 (void)fprintf(stderr, "NEWBUF2: %d->ovfl was %d is now %d\n", prev_bp->addr, (prev_bp->ovfl ? bp->ovfl->addr : 0), (bp ? bp->addr : 0)); #endif prev_bp->ovfl = bp; bp->flags = 0; } else bp->flags = BUF_BUCKET; MRU_INSERT(bp); return (bp); } extern void __buf_init(HTAB *hashp, int nbytes) { BUFHEAD *bfp; int npages; bfp = &(hashp->bufhead); npages = (nbytes + hashp->BSIZE - 1) >> hashp->BSHIFT; npages = MAX(npages, MIN_BUFFERS); hashp->nbufs = npages; bfp->next = bfp; bfp->prev = bfp; /* * This space is calloc'd so these are already null. * * bfp->ovfl = NULL; * bfp->flags = 0; * bfp->page = NULL; * bfp->addr = 0; */ } extern int __buf_free(HTAB *hashp, int do_free, int to_disk) { BUFHEAD *bp; /* Need to make sure that buffer manager has been initialized */ if (!LRU) return (0); for (bp = LRU; bp != &hashp->bufhead;) { /* Check that the buffer is valid */ if (bp->addr || IS_BUCKET(bp->flags)) { if (to_disk && (bp->flags & BUF_MOD) && __put_page(hashp, bp->page, bp->addr, IS_BUCKET(bp->flags), 0)) return (-1); } /* Check if we are freeing stuff */ if (do_free) { if (bp->page) free(bp->page); BUF_REMOVE(bp); free(bp); bp = LRU; } else bp = bp->prev; } return (0); } extern void __reclaim_buf(HTAB *hashp, BUFHEAD *bp) { bp->ovfl = 0; bp->addr = 0; bp->flags = 0; BUF_REMOVE(bp); LRU_INSERT(bp); } picolibc-1.8.11/libc/search/hash_func.c000066400000000000000000000104241513574234600176610ustar00rootroot00000000000000/*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Margo Seltzer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #define _DEFAULT_SOURCE #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)hash_func.c 8.2 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include #include "db_local.h" #include "hash.h" #include "page.h" #include "extern.h" #if 0 static __uint32_t hash1(const void *, size_t); static __uint32_t hash2(const void *, size_t); static __uint32_t hash3(const void *, size_t); #endif /* * HASH FUNCTIONS * * Assume that we've already split the bucket to which this key hashes, * calculate that bucket, and check that in fact we did already split it. * * This came from ejb's hsearch. */ #define PRIME1 37 #define PRIME2 1048583 #if 0 static __uint32_t hash1(keyarg, len) const void *keyarg; size_t len; { const u_char *key; __uint32_t h; /* Convert string to integer */ for (key = keyarg, h = 0; len--;) h = h * PRIME1 ^ (*key++ - ' '); h %= PRIME2; return (h); } #endif /* * Phong's linear congruential hash */ #define dcharhash(h, c) ((h) = 0x63c63cd9 * (h) + 0x9c39c33d + (c)) #if 0 static __uint32_t hash2(keyarg, len) const void *keyarg; size_t len; { const u_char *e, *key; __uint32_t h; u_char c; key = keyarg; e = key + len; for (h = 0; key != e;) { c = *key++; if (!c && key > e) break; dcharhash(h, c); } return (h); } #endif /* * This is INCREDIBLY ugly, but fast. We break the string up into 8 byte * units. On the first time through the loop we get the "leftover bytes" * (strlen % 8). On every other iteration, we perform 8 HASHC's so we handle * all 8 bytes. Essentially, this saves us 7 cmp & branch instructions. If * this routine is heavily used enough, it's worth the ugly coding. * * OZ's original sdbm hash */ #if 0 static __uint32_t hash3(keyarg, len) const void *keyarg; size_t len; { const u_char *key; size_t loop; __uint32_t h; #define HASHC h = *key++ + 65599 * h h = 0; key = keyarg; if (len > 0) { loop = (len + 8 - 1) >> 3; switch (len & (8 - 1)) { case 0: do { HASHC; __fallthrough; case 7: HASHC; __fallthrough; case 6: HASHC; __fallthrough; case 5: HASHC; __fallthrough; case 4: HASHC; __fallthrough; case 3: HASHC; __fallthrough; case 2: HASHC; __fallthrough; case 1: HASHC; } while (--loop); } } return (h); } #endif /* Hash function from Chris Torek. */ __uint32_t __default_hash(const void *keyarg, size_t len) { const u_char *key; __uint32_t h; #define HASH4a h = (h << 5) - h + *key++; #define HASH4b h = (h << 5) + h + *key++; #define HASH4 HASH4b h = 0; key = keyarg; while (len--) { HASH4; } return (h); } picolibc-1.8.11/libc/search/hash_log2.c000066400000000000000000000041051513574234600175700ustar00rootroot00000000000000/*- * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Margo Seltzer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #define _DEFAULT_SOURCE #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)hash_log2.c 8.2 (Berkeley) 5/31/94"; #endif /* LIBC_SCCS and not lint */ #include #include "db_local.h" #include "hash.h" #include "page.h" #include "extern.h" __uint32_t __log2(__uint32_t num) { __uint32_t i, limit; limit = 1; for (i = 0; limit < num; limit = limit << 1, i++) ; return (i); } picolibc-1.8.11/libc/search/hash_page.c000066400000000000000000000630411513574234600176450ustar00rootroot00000000000000/*- * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Margo Seltzer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * PACKAGE: hashing * * DESCRIPTION: * Page manipulation for hashing package. * * ROUTINES: * * External * __get_page * __add_ovflpage * Internal * overflow_page * open_temp */ #define _DEFAULT_SOURCE #include #include #include #include #include #include #include #include #if !defined(DEBUG) && !defined(NDEBUG) #define NDEBUG #endif #include #include "db_local.h" #include "hash.h" #include "page.h" #include "extern.h" static __uint32_t *fetch_bitmap(HTAB *, int); static __uint32_t first_free(__uint32_t); static int open_temp(HTAB *); static __uint16_t overflow_page(HTAB *); static void putpair(char *, const DBT *, const DBT *); static void squeeze_key(__uint16_t *, const DBT *, const DBT *); static int ugly_split(HTAB *, __uint32_t, BUFHEAD *, BUFHEAD *, int, int); #define PAGE_INIT(P) \ { \ ((__uint16_t *)(P))[0] = 0; \ ((__uint16_t *)(P))[1] = hashp->BSIZE - 3 * sizeof(__uint16_t); \ ((__uint16_t *)(P))[2] = hashp->BSIZE; \ } /* * This is called AFTER we have verified that there is room on the page for * the pair (PAIRFITS has returned true) so we go right ahead and start moving * stuff on. */ static void putpair(char *p, const DBT *key, const DBT *val) { __uint16_t *bp, n, off; bp = (__uint16_t *)p; /* Enter the key first. */ n = bp[0]; off = OFFSET(bp) - key->size; memmove(p + off, key->data, key->size); bp[++n] = off; /* Now the data. */ off -= val->size; memmove(p + off, val->data, val->size); bp[++n] = off; /* Adjust page info. */ bp[0] = n; bp[n + 1] = off - ((n + 3) * sizeof(__uint16_t)); bp[n + 2] = off; } /* * Returns: * 0 OK * -1 error */ extern int __delpair(HTAB *hashp, BUFHEAD *bufp, int ndx) { __uint16_t *bp, newoff; int n; __uint16_t pairlen; bp = (__uint16_t *)bufp->page; n = bp[0]; if (bp[ndx + 1] < REAL_KEY) return (__big_delete(hashp, bufp)); if (ndx != 1) newoff = bp[ndx - 1]; else newoff = hashp->BSIZE; pairlen = newoff - bp[ndx + 1]; if (ndx != (n - 1)) { /* Hard Case -- need to shuffle keys */ int i; char *src = bufp->page + (int)OFFSET(bp); char *dst = src + (int)pairlen; memmove(dst, src, bp[ndx + 1] - OFFSET(bp)); /* Now adjust the pointers */ for (i = ndx + 2; i <= n; i += 2) { if (bp[i + 1] == OVFLPAGE) { bp[i - 2] = bp[i]; bp[i - 1] = bp[i + 1]; } else { bp[i - 2] = bp[i] + pairlen; bp[i - 1] = bp[i + 1] + pairlen; } } } /* Finally adjust the page data */ bp[n] = OFFSET(bp) + pairlen; bp[n - 1] = bp[n + 1] + pairlen + 2 * sizeof(__uint16_t); bp[0] = n - 2; hashp->NKEYS--; bufp->flags |= BUF_MOD; return (0); } /* * Returns: * 0 ==> OK * -1 ==> Error */ extern int __split_page(HTAB *hashp, __uint32_t obucket, __uint32_t nbucket) { BUFHEAD *new_bufp, *old_bufp; __uint16_t *ino; char *np; DBT key, val; int ndx, retval; __uint16_t n, copyto, diff, off, moved; char *op; copyto = (__uint16_t)hashp->BSIZE; off = (__uint16_t)hashp->BSIZE; old_bufp = __get_buf(hashp, obucket, NULL, 0); if (old_bufp == NULL) return (-1); new_bufp = __get_buf(hashp, nbucket, NULL, 0); if (new_bufp == NULL) return (-1); old_bufp->flags |= (BUF_MOD | BUF_PIN); new_bufp->flags |= (BUF_MOD | BUF_PIN); ino = (__uint16_t *)(op = old_bufp->page); np = new_bufp->page; moved = 0; for (n = 1, ndx = 1; n < ino[0]; n += 2) { if (ino[n + 1] < REAL_KEY) { retval = ugly_split(hashp, obucket, old_bufp, new_bufp, (int)copyto, (int)moved); old_bufp->flags &= ~BUF_PIN; new_bufp->flags &= ~BUF_PIN; return (retval); } key.data = (u_char *)op + ino[n]; key.size = off - ino[n]; if (__call_hash(hashp, key.data, key.size) == obucket) { /* Don't switch page */ diff = copyto - off; if (diff) { copyto = ino[n + 1] + diff; memmove(op + copyto, op + ino[n + 1], off - ino[n + 1]); ino[ndx] = copyto + ino[n] - ino[n + 1]; ino[ndx + 1] = copyto; } else copyto = ino[n + 1]; ndx += 2; } else { /* Switch page */ val.data = (u_char *)op + ino[n + 1]; val.size = ino[n] - ino[n + 1]; putpair(np, &key, &val); moved += 2; } off = ino[n + 1]; } /* Now clean up the page */ ino[0] -= moved; FREESPACE(ino) = copyto - sizeof(__uint16_t) * (ino[0] + 3); OFFSET(ino) = copyto; #ifdef DEBUG3 (void)fprintf(stderr, "split %d/%d\n", ((__uint16_t *)np)[0] / 2, ((__uint16_t *)op)[0] / 2); #endif /* unpin both pages */ old_bufp->flags &= ~BUF_PIN; new_bufp->flags &= ~BUF_PIN; return (0); } /* * Called when we encounter an overflow or big key/data page during split * handling. This is special cased since we have to begin checking whether * the key/data pairs fit on their respective pages and because we may need * overflow pages for both the old and new pages. * * The first page might be a page with regular key/data pairs in which case * we have a regular overflow condition and just need to go on to the next * page or it might be a big key/data pair in which case we need to fix the * big key/data pair. * * Returns: * 0 ==> success * -1 ==> failure */ static int ugly_split(HTAB *hashp, __uint32_t obucket, /* Same as __split_page. */ BUFHEAD *old_bufp, BUFHEAD *new_bufp, int copyto, /* First byte on page which contains key/data values. */ int moved /* Number of pairs moved to new page. */ ) { BUFHEAD *bufp; /* Buffer header for ino */ __uint16_t *ino; /* Page keys come off of */ __uint16_t *np; /* New page */ __uint16_t *op; /* Page keys go on to if they aren't moving */ BUFHEAD *last_bfp; /* Last buf header OVFL needing to be freed */ DBT key, val; SPLIT_RETURN ret; __uint16_t n, off, ov_addr, scopyto; char *cino; /* Character value of ino */ bufp = old_bufp; ino = (__uint16_t *)old_bufp->page; np = (__uint16_t *)new_bufp->page; op = (__uint16_t *)old_bufp->page; last_bfp = NULL; scopyto = (__uint16_t)copyto; /* ANSI */ n = ino[0] - 1; while (n < ino[0]) { if (ino[2] < REAL_KEY && ino[2] != OVFLPAGE) { if (__big_split(hashp, old_bufp, new_bufp, bufp, bufp->addr, obucket, &ret)) return (-1); old_bufp = ret.oldp; if (!old_bufp) return (-1); op = (__uint16_t *)old_bufp->page; new_bufp = ret.newp; if (!new_bufp) return (-1); np = (__uint16_t *)new_bufp->page; bufp = ret.nextp; if (!bufp) return (0); cino = (char *)bufp->page; ino = (__uint16_t *)cino; last_bfp = ret.nextp; } else if (ino[n + 1] == OVFLPAGE) { ov_addr = ino[n]; /* * Fix up the old page -- the extra 2 are the fields * which contained the overflow information. */ ino[0] -= (moved + 2); FREESPACE(ino) = scopyto - sizeof(__uint16_t) * (ino[0] + 3); OFFSET(ino) = scopyto; bufp = __get_buf(hashp, ov_addr, bufp, 0); if (!bufp) return (-1); ino = (__uint16_t *)bufp->page; n = 1; scopyto = hashp->BSIZE; moved = 0; if (last_bfp) __free_ovflpage(hashp, last_bfp); last_bfp = bufp; } /* Move regular sized pairs of there are any */ off = hashp->BSIZE; for (n = 1; (n < ino[0]) && (ino[n + 1] >= REAL_KEY); n += 2) { cino = (char *)ino; key.data = (u_char *)cino + ino[n]; key.size = off - ino[n]; val.data = (u_char *)cino + ino[n + 1]; val.size = ino[n] - ino[n + 1]; off = ino[n + 1]; if (__call_hash(hashp, key.data, key.size) == obucket) { /* Keep on old page */ if (PAIRFITS(op, (&key), (&val))) putpair((char *)op, &key, &val); else { old_bufp = __add_ovflpage(hashp, old_bufp); if (!old_bufp) return (-1); op = (__uint16_t *)old_bufp->page; putpair((char *)op, &key, &val); } old_bufp->flags |= BUF_MOD; } else { /* Move to new page */ if (PAIRFITS(np, (&key), (&val))) putpair((char *)np, &key, &val); else { new_bufp = __add_ovflpage(hashp, new_bufp); if (!new_bufp) return (-1); np = (__uint16_t *)new_bufp->page; putpair((char *)np, &key, &val); } new_bufp->flags |= BUF_MOD; } } } if (last_bfp) __free_ovflpage(hashp, last_bfp); return (0); } /* * Add the given pair to the page * * Returns: * 0 ==> OK * 1 ==> failure */ extern int __addel(HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val) { __uint16_t *bp, *sop; int do_expand; bp = (__uint16_t *)bufp->page; do_expand = 0; while (bp[0] && (bp[2] < REAL_KEY || bp[bp[0]] < REAL_KEY)) /* Exception case */ if (bp[2] == FULL_KEY_DATA && bp[0] == 2) /* This is the last page of a big key/data pair and we need to add another page */ break; else if (bp[2] < REAL_KEY && bp[bp[0]] != OVFLPAGE) { bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); bp = (__uint16_t *)bufp->page; } else /* Try to squeeze key on this page */ if (FREESPACE(bp) > PAIRSIZE(key, val)) { squeeze_key(bp, key, val); return (0); } else { bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); bp = (__uint16_t *)bufp->page; } if (PAIRFITS(bp, key, val)) putpair(bufp->page, key, val); else { do_expand = 1; bufp = __add_ovflpage(hashp, bufp); if (!bufp) return (-1); sop = (__uint16_t *)bufp->page; if (PAIRFITS(sop, key, val)) putpair((char *)sop, key, val); else if (__big_insert(hashp, bufp, key, val)) return (-1); } bufp->flags |= BUF_MOD; /* * If the average number of keys per bucket exceeds the fill factor, * expand the table. */ hashp->NKEYS++; if (do_expand || (hashp->NKEYS / (hashp->MAX_BUCKET + 1) > hashp->FFACTOR)) return (__expand_table(hashp)); return (0); } /* * * Returns: * pointer on success * NULL on error */ extern BUFHEAD * __add_ovflpage(HTAB *hashp, BUFHEAD *bufp) { __uint16_t *sp; __uint16_t ndx, ovfl_num; #ifdef DEBUG1 int tmp1, tmp2; #endif sp = (__uint16_t *)bufp->page; /* Check if we are dynamically determining the fill factor */ if (hashp->FFACTOR == DEF_FFACTOR) { hashp->FFACTOR = sp[0] >> 1; if (hashp->FFACTOR < MIN_FFACTOR) hashp->FFACTOR = MIN_FFACTOR; } bufp->flags |= BUF_MOD; ovfl_num = overflow_page(hashp); #ifdef DEBUG1 tmp1 = bufp->addr; tmp2 = bufp->ovfl ? bufp->ovfl->addr : 0; #endif if (!ovfl_num || !(bufp->ovfl = __get_buf(hashp, ovfl_num, bufp, 1))) return (NULL); bufp->ovfl->flags |= BUF_MOD; #ifdef DEBUG1 (void)fprintf(stderr, "ADDOVFLPAGE: %d->ovfl was %d is now %d\n", tmp1, tmp2, bufp->ovfl->addr); #endif ndx = sp[0]; /* * Since a pair is allocated on a page only if there's room to add * an overflow page, we know that the OVFL information will fit on * the page. */ sp[ndx + 4] = OFFSET(sp); sp[ndx + 3] = FREESPACE(sp) - OVFLSIZE; sp[ndx + 1] = ovfl_num; sp[ndx + 2] = OVFLPAGE; sp[0] = ndx + 2; #ifdef HASH_STATISTICS hash_overflows++; #endif return (bufp->ovfl); } /* * Returns: * 0 indicates SUCCESS * -1 indicates FAILURE */ extern int __get_page(HTAB *hashp, char *p, __uint32_t bucket, int is_bucket, int is_disk, int is_bitmap) { int fd, page, size; int rsize; __uint16_t *bp; fd = hashp->fp; size = hashp->BSIZE; if ((fd == -1) || !is_disk) { PAGE_INIT(p); return (0); } if (is_bucket) page = BUCKET_TO_PAGE(bucket); else page = OADDR_TO_PAGE(bucket); if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) || ((rsize = read(fd, p, size)) == -1)) return (-1); bp = (__uint16_t *)p; if (!rsize) bp[0] = 0; /* We hit the EOF, so initialize a new page */ else if (rsize != size) { errno = EFTYPE; return (-1); } if (!is_bitmap && !bp[0]) { PAGE_INIT(p); } else if (hashp->LORDER != DB_BYTE_ORDER) { int i, max; if (is_bitmap) { max = hashp->BSIZE >> 2; /* divide by 4 */ for (i = 0; i < max; i++) M_32_SWAP(((int *)p)[i]); } else { M_16_SWAP(bp[0]); max = bp[0] + 2; for (i = 1; i <= max; i++) M_16_SWAP(bp[i]); } } return (0); } /* * Write page p to disk * * Returns: * 0 ==> OK * -1 ==>failure */ extern int __put_page(HTAB *hashp, char *p, __uint32_t bucket, int is_bucket, int is_bitmap) { int fd, page, size; int wsize; size = hashp->BSIZE; if ((hashp->fp == -1) && open_temp(hashp)) return (-1); fd = hashp->fp; if (hashp->LORDER != DB_BYTE_ORDER) { int i; int max; if (is_bitmap) { max = hashp->BSIZE >> 2; /* divide by 4 */ for (i = 0; i < max; i++) M_32_SWAP(((int *)p)[i]); } else { max = ((__uint16_t *)p)[0] + 2; for (i = 0; i <= max; i++) M_16_SWAP(((__uint16_t *)p)[i]); } } if (is_bucket) page = BUCKET_TO_PAGE(bucket); else page = OADDR_TO_PAGE(bucket); if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) || ((wsize = write(fd, p, size)) == -1)) /* Errno is set */ return (-1); if (wsize != size) { errno = EFTYPE; return (-1); } return (0); } #define BYTE_MASK ((1 << INT_BYTE_SHIFT) - 1) /* * Initialize a new bitmap page. Bitmap pages are left in memory * once they are read in. */ extern int __ibitmap(HTAB *hashp, int pnum, int nbits, int ndx) { __uint32_t *ip; int clearbytes, clearints; clearints = ((nbits - 1) >> INT_BYTE_SHIFT) + 1; clearbytes = clearints << INT_TO_BYTE; if (clearbytes > hashp->BSIZE || (ip = (__uint32_t *)malloc(hashp->BSIZE)) == NULL) return (1); hashp->nmaps++; (void)memset((char *)ip, 0, clearbytes); (void)memset(((char *)ip) + clearbytes, 0xFF, hashp->BSIZE - clearbytes); ip[clearints - 1] = ALL_SET << (nbits & BYTE_MASK); SETBIT(ip, 0); hashp->BITMAPS[ndx] = (__uint16_t)pnum; hashp->mapp[ndx] = ip; return (0); } static __uint32_t first_free(__uint32_t map) { __uint32_t i, mask; mask = 0x1; for (i = 0; i < BITS_PER_MAP; i++) { if (!(mask & map)) return (i); mask = mask << 1; } return (i); } static __uint16_t overflow_page(HTAB *hashp) { __uint32_t *freep = NULL; int max_free, offset, splitnum; __uint16_t addr; int bit, first_page, free_bit, free_page, i, in_use_bits, j; #ifdef DEBUG2 int tmp1, tmp2; #endif splitnum = hashp->OVFL_POINT; max_free = hashp->SPARES[splitnum]; free_page = (max_free - 1) >> (hashp->BSHIFT + BYTE_SHIFT); free_bit = (max_free - 1) & ((hashp->BSIZE << BYTE_SHIFT) - 1); /* Look through all the free maps to find the first free block */ first_page = hashp->LAST_FREED >> (hashp->BSHIFT + BYTE_SHIFT); for (i = first_page; i <= free_page; i++) { if (!(freep = (__uint32_t *)hashp->mapp[i]) && !(freep = fetch_bitmap(hashp, i))) return (0); if (i == free_page) in_use_bits = free_bit; else in_use_bits = (hashp->BSIZE << BYTE_SHIFT) - 1; if (i == first_page) { bit = hashp->LAST_FREED & ((hashp->BSIZE << BYTE_SHIFT) - 1); j = bit / BITS_PER_MAP; bit = bit & ~(BITS_PER_MAP - 1); } else { bit = 0; j = 0; } for (; bit <= in_use_bits; j++, bit += BITS_PER_MAP) if (freep[j] != ALL_SET) goto found; } /* No Free Page Found */ hashp->LAST_FREED = hashp->SPARES[splitnum]; hashp->SPARES[splitnum]++; offset = hashp->SPARES[splitnum] - (splitnum ? hashp->SPARES[splitnum - 1] : 0); #define OVMSG "HASH: Out of overflow pages. Increase page size\n" if (offset > SPLITMASK) { if (++splitnum >= NCACHED) { (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); return (0); } hashp->OVFL_POINT = splitnum; hashp->SPARES[splitnum] = hashp->SPARES[splitnum - 1]; hashp->SPARES[splitnum - 1]--; offset = 1; } /* Check if we need to allocate a new bitmap page */ if (free_bit == (hashp->BSIZE << BYTE_SHIFT) - 1) { free_page++; if (free_page >= NCACHED) { (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); return (0); } /* * This is tricky. The 1 indicates that you want the new page * allocated with 1 clear bit. Actually, you are going to * allocate 2 pages from this map. The first is going to be * the map page, the second is the overflow page we were * looking for. The init_bitmap routine automatically, sets * the first bit of itself to indicate that the bitmap itself * is in use. We would explicitly set the second bit, but * don't have to if we tell init_bitmap not to leave it clear * in the first place. */ if (__ibitmap(hashp, (int)OADDR_OF(splitnum, offset), 1, free_page)) return (0); hashp->SPARES[splitnum]++; #ifdef DEBUG2 free_bit = 2; #endif offset++; if (offset > SPLITMASK) { if (++splitnum >= NCACHED) { (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); return (0); } hashp->OVFL_POINT = splitnum; hashp->SPARES[splitnum] = hashp->SPARES[splitnum - 1]; hashp->SPARES[splitnum - 1]--; offset = 0; } } else { /* * Free_bit addresses the last used bit. Bump it to address * the first available bit. */ free_bit++; SETBIT(freep, free_bit); } /* Calculate address of the new overflow page */ addr = OADDR_OF(splitnum, offset); #ifdef DEBUG2 (void)fprintf(stderr, "OVERFLOW_PAGE: ADDR: %d BIT: %d PAGE %d\n", addr, free_bit, free_page); #endif return (addr); found: bit = bit + first_free(freep[j]); SETBIT(freep, bit); #ifdef DEBUG2 tmp1 = bit; tmp2 = i; #endif /* * Bits are addressed starting with 0, but overflow pages are addressed * beginning at 1. Bit is a bit addressnumber, so we need to increment * it to convert it to a page number. */ bit = 1 + bit + (i * (hashp->BSIZE << BYTE_SHIFT)); if (bit >= hashp->LAST_FREED) hashp->LAST_FREED = bit - 1; /* Calculate the split number for this page */ for (i = 0; (i < splitnum) && (bit > hashp->SPARES[i]); i++) ; offset = (i ? bit - hashp->SPARES[i - 1] : bit); if (offset >= SPLITMASK) return (0); /* Out of overflow pages */ addr = OADDR_OF(i, offset); #ifdef DEBUG2 (void)fprintf(stderr, "OVERFLOW_PAGE: ADDR: %d BIT: %d PAGE %d\n", addr, tmp1, tmp2); #endif /* Allocate and return the overflow page */ return (addr); } /* * Mark this overflow page as free. */ extern void __free_ovflpage(HTAB *hashp, BUFHEAD *obufp) { __uint16_t addr; __uint32_t *freep; int bit_address, free_page, free_bit; __uint16_t ndx; addr = obufp->addr; #ifdef DEBUG1 (void)fprintf(stderr, "Freeing %d\n", addr); #endif ndx = (((__uint16_t)addr) >> SPLITSHIFT); bit_address = (ndx ? hashp->SPARES[ndx - 1] : 0) + (addr & SPLITMASK) - 1; if (bit_address < hashp->LAST_FREED) hashp->LAST_FREED = bit_address; free_page = (bit_address >> (hashp->BSHIFT + BYTE_SHIFT)); free_bit = bit_address & ((hashp->BSIZE << BYTE_SHIFT) - 1); if (!(freep = hashp->mapp[free_page])) freep = fetch_bitmap(hashp, free_page); /* * This had better never happen. It means we tried to read a bitmap * that has already had overflow pages allocated off it, and we * failed to read it from the file. */ assert(freep); CLRBIT(freep, free_bit); #ifdef DEBUG2 (void)fprintf(stderr, "FREE_OVFLPAGE: ADDR: %d BIT: %d PAGE %d\n", obufp->addr, free_bit, free_page); #endif __reclaim_buf(hashp, obufp); } /* * Returns: * 0 success * -1 failure */ static int open_temp(HTAB *hashp) { sigset_t set, oset; char namestr[sizeof("_hashXXXXXX")]; /* Block signals; make sure file goes away at process exit. */ (void)sigfillset(&set); (void)sigprocmask(SIG_BLOCK, &set, &oset); strcpy(namestr, "_hashXXXXXX"); if ((hashp->fp = mkstemp(namestr)) != -1) { (void)unlink(namestr); #ifdef __HAVE_FCNTL (void)fcntl(hashp->fp, F_SETFD, 1); #endif } (void)sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL); return (hashp->fp != -1 ? 0 : -1); } /* * We have to know that the key will fit, but the last entry on the page is * an overflow pair, so we need to shift things. */ static void squeeze_key(__uint16_t *sp, const DBT *key, const DBT *val) { char *p; __uint16_t free_space, n, off, pageno; p = (char *)sp; n = sp[0]; free_space = FREESPACE(sp); off = OFFSET(sp); pageno = sp[n - 1]; off -= key->size; sp[n - 1] = off; memmove(p + off, key->data, key->size); off -= val->size; sp[n] = off; memmove(p + off, val->data, val->size); sp[0] = n + 2; sp[n + 1] = pageno; sp[n + 2] = OVFLPAGE; FREESPACE(sp) = free_space - PAIRSIZE(key, val); OFFSET(sp) = off; } static __uint32_t * fetch_bitmap(HTAB *hashp, int ndx) { if (ndx >= hashp->nmaps) return (NULL); if ((hashp->mapp[ndx] = (__uint32_t *)malloc(hashp->BSIZE)) == NULL) return (NULL); if (__get_page(hashp, (char *)hashp->mapp[ndx], hashp->BITMAPS[ndx], 0, 1, 1)) { free(hashp->mapp[ndx]); return (NULL); } return (hashp->mapp[ndx]); } #ifdef DEBUG4 int print_chain(addr) int addr; { BUFHEAD *bufp; short *bp, oaddr; (void)fprintf(stderr, "%d ", addr); bufp = __get_buf(hashp, addr, NULL, 0); bp = (short *)bufp->page; while (bp[0] && ((bp[bp[0]] == OVFLPAGE) || ((bp[0] > 2) && bp[2] < REAL_KEY))) { oaddr = bp[bp[0] - 1]; (void)fprintf(stderr, "%d ", (int)oaddr); bufp = __get_buf(hashp, (int)oaddr, bufp, 0); bp = (short *)bufp->page; } (void)fprintf(stderr, "\n"); } #endif picolibc-1.8.11/libc/search/hcreate.3000066400000000000000000000136341513574234600172640ustar00rootroot00000000000000.\" .\" Copyright (c) 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD: src/lib/libc/stdlib/hcreate.3,v 1.2 2001/07/09 15:54:36 ru Exp $ .\" .Dd May 8, 2001 .Os .Dt HCREATE 3 .Sh NAME .Nm hcreate , hdestroy , hsearch .Nd manage hash search table .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In search.h .Ft int .Fn hcreate "size_t nel" .Ft void .Fn hdestroy void .Ft ENTRY * .Fn hsearch "ENTRY item" "ACTION action" .Sh DESCRIPTION The .Fn hcreate , .Fn hdestroy , and .Fn hsearch functions manage hash search tables. .Pp The .Fn hcreate function allocates sufficient space for the table, and the application should ensure it is called before .Fn hsearch is used. The .Fa nel argument is an estimate of the maximum number of entries that the table should contain. This number may be adjusted upward by the algorithm in order to obtain certain mathematically favorable circumstances. .Pp The .Fn hdestroy function disposes of the search table, and may be followed by another call to .Fn hcreate . After the call to .Fn hdestroy , the data can no longer be considered accessible. .Pp The .Fn hsearch function is a hash-table search routine. It returns a pointer into a hash table indicating the location at which an entry can be found. The .Fa item argument is a structure of type .Vt ENTRY (defined in the .Aq Pa search.h header) containing two pointers: .Fa item.key points to the comparison key (a .Vt "char *" ) , and .Fa item.data (a .Vt "void *" ) points to any other data to be associated with that key. The comparison function used by .Fn hsearch is .Xr strcmp 3 . The .Fa action argument is a member of an enumeration type .Vt ACTION indicating the disposition of the entry if it cannot be found in the table. .Dv ENTER indicates that the .Fa item should be inserted in the table at an appropriate point. .Dv FIND indicates that no entry should be made. Unsuccessful resolution is indicated by the return of a .Dv NULL pointer. .Sh RETURN VALUES The .Fn hcreate function returns 0 if it cannot allocate sufficient space for the table; otherwise, it returns non-zero. .Pp The .Fn hdestroy function does not return a value. .Pp The .Fn hsearch function returns a .Dv NULL pointer if either the .Fa action is .Dv FIND and the .Fa item could not be found or the .Fa action is .Dv ENTER and the table is full. .Sh ERRORS The .Fn hcreate and .Fn hsearch functions may fail if: .Bl -tag -width Er .It Bq Er ENOMEM Insufficient storage space is available. .El .Sh EXAMPLES The following example reads in strings followed by two numbers and stores them in a hash table, discarding duplicates. It then reads in strings and finds the matching entry in the hash table and prints it out. .Bd -literal #include #include #include struct info { /* This is the info stored in the table */ int age, room; /* other than the key. */ }; #define NUM_EMPL 5000 /* # of elements in search table. */ int main(void) { char string_space[NUM_EMPL*20]; /* Space to store strings. */ struct info info_space[NUM_EMPL]; /* Space to store employee info. */ char *str_ptr = string_space; /* Next space in string_space. */ struct info *info_ptr = info_space; /* Next space in info_space. */ ENTRY item; ENTRY *found_item; /* Name to look for in table. */ char name_to_find[30]; int i = 0; /* Create table; no error checking is performed. */ (void) hcreate(NUM_EMPL); while (scanf("%s%d%d", str_ptr, &info_ptr->age, &info_ptr->room) != EOF && i++ < NUM_EMPL) { /* Put information in structure, and structure in item. */ item.key = str_ptr; item.data = info_ptr; str_ptr += strlen(str_ptr) + 1; info_ptr++; /* Put item into table. */ (void) hsearch(item, ENTER); } /* Access table. */ item.key = name_to_find; while (scanf("%s", item.key) != EOF) { if ((found_item = hsearch(item, FIND)) != NULL) { /* If item is in the table. */ (void)printf("found %s, age = %d, room = %d\en", found_item->key, ((struct info *)found_item->data)->age, ((struct info *)found_item->data)->room); } else (void)printf("no such employee %s\en", name_to_find); } return 0; } .Ed .Sh SEE ALSO .Xr bsearch 3 , .Xr lsearch 3 , .Xr malloc 3 , .Xr strcmp 3 , .Xr tsearch 3 .Sh STANDARDS The .Fn hcreate , .Fn hdestroy , and .Fn hsearch functions conform to .St -xpg4.2 . .Sh HISTORY The .Fn hcreate , .Fn hdestroy , and .Fn hsearch functions first appeared in .At V . .Sh BUGS The interface permits the use of only one hash table at a time. picolibc-1.8.11/libc/search/hcreate.c000066400000000000000000000045701513574234600173430ustar00rootroot00000000000000/* $NetBSD: hcreate.c,v 1.2 2001/02/19 21:26:04 ross Exp $ */ /* * Copyright (c) 2001 Christopher G. Demetriou * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * <> */ /* * hcreate() / hsearch() / hdestroy() * * SysV/XPG4 hash table functions. * * Implementation done based on NetBSD manual page and Solaris manual page, * plus my own personal experience about how they're supposed to work. * * I tried to look at Knuth (as cited by the Solaris manual page), but * nobody had a copy in the office, so... */ #if 0 #if defined(LIBC_SCCS) && !defined(lint) #endif /* LIBC_SCCS and not lint */ #endif #include #include #include #include #include static struct hsearch_data htab; int hcreate(size_t nel) { return hcreate_r(nel, &htab); } void hdestroy(void) { hdestroy_r(&htab); } ENTRY * hsearch(ENTRY item, ACTION action) { ENTRY *retval; hsearch_r(item, action, &retval, &htab); return retval; } picolibc-1.8.11/libc/search/hcreate_r.c000066400000000000000000000122061513574234600176570ustar00rootroot00000000000000/* $NetBSD: hcreate.c,v 1.2 2001/02/19 21:26:04 ross Exp $ */ /* * Copyright (c) 2001 Christopher G. Demetriou * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * <> */ /* * hcreate() / hsearch() / hdestroy() * * SysV/XPG4 hash table functions. * * Implementation done based on NetBSD manual page and Solaris manual page, * plus my own personal experience about how they're supposed to work. * * I tried to look at Knuth (as cited by the Solaris manual page), but * nobody had a copy in the office, so... */ #define _DEFAULT_SOURCE #if 0 #if defined(LIBC_SCCS) && !defined(lint) #endif /* LIBC_SCCS and not lint */ #endif #include #include #include #include #include #include #include "db_local.h" #include "hash.h" #include "page.h" #include "extern.h" /* * DO NOT MAKE THIS STRUCTURE LARGER THAN 32 BYTES (4 ptrs on 64-bit * ptr machine) without adjusting MAX_BUCKETS_LG2 below. */ struct internal_entry { SLIST_ENTRY(internal_entry) link; ENTRY ent; }; SLIST_HEAD(internal_head, internal_entry); #define MIN_BUCKETS_LG2 4 #define MIN_BUCKETS (1 << MIN_BUCKETS_LG2) /* * max * sizeof internal_entry must fit into size_t. * assumes internal_entry is <= 32 (2^5) bytes. */ #ifdef __MSP430X_LARGE__ /* 20-bit size_t. */ #define MAX_BUCKETS_LG2 (20 - 1 - 5) #else #define MAX_BUCKETS_LG2 (sizeof(size_t) * 8 - 1 - 5) #endif #define MAX_BUCKETS ((size_t)1 << MAX_BUCKETS_LG2) int hcreate_r(size_t nel, struct hsearch_data *htab) { size_t idx; unsigned int p2; /* Make sure this this isn't called when a table already exists. */ if (htab->htable != NULL) { errno = EINVAL; return 0; } /* If nel is too small, make it min sized. */ if (nel < MIN_BUCKETS) nel = MIN_BUCKETS; /* If it's too large, cap it. */ if (nel > MAX_BUCKETS) nel = MAX_BUCKETS; /* If it's is not a power of two in size, round up. */ if ((nel & (nel - 1)) != 0) { for (p2 = 0; nel != 0; p2++) nel >>= 1; nel = 1 << p2; } /* Allocate the table. */ htab->htablesize = nel; htab->htable = malloc(htab->htablesize * sizeof htab->htable[0]); if (htab->htable == NULL) { errno = ENOMEM; return 0; } /* Initialize it. */ for (idx = 0; idx < htab->htablesize; idx++) SLIST_INIT(&(htab->htable[idx])); return 1; } void hdestroy_r(struct hsearch_data *htab) { #if 0 struct internal_entry *ie; size_t idx; #endif if (htab->htable == NULL) return; #if 0 for (idx = 0; idx < htab->htablesize; idx++) { while (!SLIST_EMPTY(&(htab->htable[idx]))) { ie = SLIST_FIRST(&(htab->htable[idx])); SLIST_REMOVE_HEAD(&(htab->htable[idx]), link); free(ie->ent.key); free(ie); } } #endif free(htab->htable); htab->htable = NULL; } int hsearch_r(ENTRY item, ACTION action, ENTRY **retval, struct hsearch_data *htab) { struct internal_head *head; struct internal_entry *ie; __uint32_t hashval; size_t len; len = strlen(item.key); hashval = __default_hash(item.key, len); head = &(htab->htable[hashval & (htab->htablesize - 1)]); ie = SLIST_FIRST(head); while (ie != NULL) { if (strcmp(ie->ent.key, item.key) == 0) break; ie = SLIST_NEXT(ie, link); } if (ie != NULL) { *retval = &ie->ent; return 1; } else if (action == FIND) { *retval = NULL; return 0; } ie = malloc(sizeof *ie); if (ie == NULL) { *retval = NULL; return 0; } ie->ent.key = item.key; ie->ent.data = item.data; SLIST_INSERT_HEAD(head, ie, link); *retval = &ie->ent; return 1; } picolibc-1.8.11/libc/search/meson.build000066400000000000000000000037471513574234600177330ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_search = [ 'bsd_qsort_r.c', 'bsearch.c', 'hash_bigkey.c', 'hash_buf.c', 'hash.c', 'hash_func.c', 'hash_log2.c', 'hash_page.c', 'hcreate.c', 'hcreate_r.c', 'ndbm.c', 'qsort.c', 'qsort_r.c', 'tdelete.c', 'tdestroy.c', 'tfind.c', 'tsearch.c', 'twalk.c', ] hdrs_search = [ 'db_local.h', 'extern.h', 'hash.h', 'page.h', ] src_search = files(srcs_search) picolibc-1.8.11/libc/search/ndbm.c000066400000000000000000000114161513574234600166450ustar00rootroot00000000000000/*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Margo Seltzer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * This package provides a dbm compatible interface to the new hashing * package described in db(3). */ #define _DEFAULT_SOURCE #include #include #include #include #include #include "hash.h" #define __DBINTERFACE_PRIVATE /* activate prototypes from db_local.h */ #include "db_local.h" /* * Returns: * *DBM on success * NULL on failure */ extern DBM * dbm_open(const char *file, int flags, mode_t mode) { HASHINFO info; char path[MAXPATHLEN]; info.bsize = 4096; info.ffactor = 40; info.nelem = 1; info.cachesize = 0; info.hash = NULL; info.lorder = 0; if (strlen(file) >= sizeof(path) - strlen(DBM_SUFFIX)) { errno = ENAMETOOLONG; return (NULL); } (void)strcpy(path, file); (void)strcat(path, DBM_SUFFIX); return ((DBM *)__hash_open(path, flags, mode, 0, &info)); } extern void dbm_close(DBM *db) { (void)(db->close)(db); } /* * Returns: * DATUM on success * NULL on failure */ extern datum dbm_fetch(DBM *db, datum key) { datum retdata; int status; DBT dbtkey, dbtretdata; dbtkey.data = key.dptr; dbtkey.size = key.dsize; status = (db->get)(db, &dbtkey, &dbtretdata, 0); if (status) { dbtretdata.data = NULL; dbtretdata.size = 0; } retdata.dptr = dbtretdata.data; retdata.dsize = dbtretdata.size; return (retdata); } /* * Returns: * DATUM on success * NULL on failure */ extern datum dbm_firstkey(DBM *db) { int status; datum retkey; DBT dbtretkey, dbtretdata; status = (db->seq)(db, &dbtretkey, &dbtretdata, R_FIRST); if (status) dbtretkey.data = NULL; retkey.dptr = dbtretkey.data; retkey.dsize = dbtretkey.size; return (retkey); } /* * Returns: * DATUM on success * NULL on failure */ extern datum dbm_nextkey(DBM *db) { int status; datum retkey; DBT dbtretkey, dbtretdata; status = (db->seq)(db, &dbtretkey, &dbtretdata, R_NEXT); if (status) dbtretkey.data = NULL; retkey.dptr = dbtretkey.data; retkey.dsize = dbtretkey.size; return (retkey); } /* * Returns: * 0 on success * <0 failure */ extern int dbm_delete(DBM *db, datum key) { int status; DBT dbtkey; dbtkey.data = key.dptr; dbtkey.size = key.dsize; status = (db->del)(db, &dbtkey, 0); if (status) return (-1); else return (0); } /* * Returns: * 0 on success * <0 failure * 1 if DBM_INSERT and entry exists */ extern int dbm_store(DBM *db, datum key, datum data, int flags) { DBT dbtkey, dbtdata; dbtkey.data = key.dptr; dbtkey.size = key.dsize; dbtdata.data = data.dptr; dbtdata.size = data.dsize; return ((db->put)(db, &dbtkey, &dbtdata, (flags == DBM_INSERT) ? R_NOOVERWRITE : 0)); } extern int dbm_error(DBM *db) { HTAB *hp; hp = (HTAB *)db->internal; return (hp->error); } extern int dbm_clearerr(DBM *db) { HTAB *hp; hp = (HTAB *)db->internal; hp->error = 0; return (0); } extern int dbm_dirfno(DBM *db) { return (((HTAB *)db->internal)->fp); } picolibc-1.8.11/libc/search/page.h000066400000000000000000000067721513574234600166570ustar00rootroot00000000000000/*- * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Margo Seltzer. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)page.h 8.2 (Berkeley) 5/31/94 * $FreeBSD: src/lib/libc/db/hash/page.h,v 1.2 2002/03/22 23:41:40 obrien Exp $ */ /* * Definitions for hashing page file format. */ /* * routines dealing with a data page * * page format: * +------------------------------+ * p | n | keyoff | datoff | keyoff | * +------------+--------+--------+ * | datoff | free | ptr | --> | * +--------+---------------------+ * | F R E E A R E A | * +--------------+---------------+ * | <---- - - - | data | * +--------+-----+----+----------+ * | key | data | key | * +--------+----------+----------+ * * Pointer to the free space is always: p[p[0] + 2] * Amount of free space on the page is: p[p[0] + 1] */ /* * How many bytes required for this pair? * 2 shorts in the table at the top of the page + room for the * key and room for the data * * We prohibit entering a pair on a page unless there is also room to append * an overflow page. The reason for this it that you can get in a situation * where a single key/data pair fits on a page, but you can't append an * overflow page and later you'd have to split the key/data and handle like * a big pair. * You might as well do this up front. */ #define PAIRSIZE(K, D) (2 * sizeof(__uint16_t) + (K)->size + (D)->size) #define BIGOVERHEAD (4 * sizeof(__uint16_t)) #define KEYSIZE(K) (4 * sizeof(__uint16_t) + (K)->size); #define OVFLSIZE (2 * sizeof(__uint16_t)) #define FREESPACE(P) ((P)[(P)[0] + 1]) #define OFFSET(P) ((P)[(P)[0] + 2]) #define PAIRFITS(P, K, D) \ (((P)[2] >= REAL_KEY) && (PAIRSIZE((K), (D)) + OVFLSIZE) <= FREESPACE((P))) #define PAGE_META(N) (((N) + 3) * sizeof(__uint16_t)) typedef struct { BUFHEAD *newp; BUFHEAD *oldp; BUFHEAD *nextp; __uint16_t next_addr; } SPLIT_RETURN; picolibc-1.8.11/libc/search/qsort.c000066400000000000000000000310551513574234600170760ustar00rootroot00000000000000/* FUNCTION <>---sort an array INDEX qsort SYNOPSIS #include void qsort(void *<[base]>, size_t <[nmemb]>, size_t <[size]>, int (*<[compar]>)(const void *, const void *) ); DESCRIPTION <> sorts an array (beginning at <[base]>) of <[nmemb]> objects. <[size]> describes the size of each element of the array. You must supply a pointer to a comparison function, using the argument shown as <[compar]>. (This permits sorting objects of unknown properties.) Define the comparison function to accept two arguments, each a pointer to an element of the array starting at <[base]>. The result of <<(*<[compar]>)>> must be negative if the first argument is less than the second, zero if the two arguments match, and positive if the first argument is greater than the second (where ``less than'' and ``greater than'' refer to whatever arbitrary ordering is appropriate). The array is sorted in place; that is, when <> returns, the array elements beginning at <[base]> have been reordered. RETURNS <> does not return a result. PORTABILITY <> is required by ANSI (without specifying the sorting algorithm). */ /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if defined(I_AM_QSORT_R) #define _BSD_SOURCE #else #define _DEFAULT_SOURCE #endif #include #include #if defined(I_AM_QSORT_R) typedef int cmp_t(void *, const void *, const void *); #elif defined(I_AM_GNU_QSORT_R) typedef int cmp_t(const void *, const void *, void *); #else typedef int cmp_t(const void *, const void *); #endif static inline char *med3(char *, char *, char *, cmp_t *, void *); static inline void swapfunc(char *, char *, size_t, int, int); #define min(a, b) (a) < (b) ? a : b typedef unsigned int swap_uint_t; typedef unsigned long swap_ulong_t; #define need_both_sizes() (sizeof(swap_uint_t) != sizeof(swap_ulong_t)) /* * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". */ #define swapcode(TYPE, parmi, parmj, n) \ do { \ size_t i = (n) / sizeof(TYPE); \ TYPE *pi = (TYPE *)(parmi); \ TYPE *pj = (TYPE *)(parmj); \ do { \ TYPE t = *pi; \ *pi++ = *pj; \ *pj++ = t; \ } while (--i > 0); \ } while (0) #define SWAPINIT(TYPE, a, es) \ swaptype_##TYPE = ((uintptr_t)(a) % sizeof(TYPE)) || ((es) % sizeof(TYPE)) ? 2 \ : ((es) == sizeof(TYPE)) ? 0 \ : 1; static inline void swapfunc(char *a, char *b, size_t n, int swaptype_swap_ulong_t, int swaptype_swap_uint_t) { if (swaptype_swap_ulong_t <= 1) swapcode(swap_ulong_t, a, b, n); else if (need_both_sizes() && swaptype_swap_uint_t <= 1) swapcode(swap_uint_t, a, b, n); else swapcode(unsigned char, a, b, n); } #define swap(a, b) \ if (swaptype_swap_ulong_t == 0) { \ swap_ulong_t t = *(swap_ulong_t *)(a); \ *(swap_ulong_t *)(a) = *(swap_ulong_t *)(b); \ *(swap_ulong_t *)(b) = t; \ } else if (need_both_sizes() && swaptype_swap_uint_t == 0) { \ swap_uint_t t = *(swap_uint_t *)(a); \ *(swap_uint_t *)(a) = *(swap_uint_t *)(b); \ *(swap_uint_t *)(b) = t; \ } else \ swapfunc(a, b, es, swaptype_swap_ulong_t, swaptype_swap_uint_t) #define vecswap(a, b, n) \ if ((n) > 0) \ swapfunc(a, b, n, swaptype_swap_ulong_t, swaptype_swap_uint_t) #if defined(I_AM_QSORT_R) #define CMP(t, x, y) (cmp((t), (x), (y))) #elif defined(I_AM_GNU_QSORT_R) #define CMP(t, x, y) (cmp((x), (y), (t))) #else #define CMP(t, x, y) (cmp((x), (y))) #endif static __inline char * med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk #if !defined(I_AM_QSORT_R) && !defined(I_AM_GNU_QSORT_R) __unused #endif ) { return CMP(thunk, a, b) < 0 ? (CMP(thunk, b, c) < 0 ? b : (CMP(thunk, a, c) < 0 ? c : a)) : (CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c)); } /* * Classical function call recursion wastes a lot of stack space. Each * recursion level requires a full stack frame comprising all local variables * and additional space as dictated by the processor calling convention. * * This implementation instead stores the variables that are unique for each * recursion level in a parameter stack array, and uses iteration to emulate * recursion. Function call recursion is not used until the array is full. * * To ensure the stack consumption isn't worsened by this design, the size of * the parameter stack array is chosen to be similar to the stack frame * excluding the array. Each function call recursion level can handle this * number of iterative recursion levels. */ #define PARAMETER_STACK_LEVELS 8u #if defined(I_AM_QSORT_R) void __bsd_qsort_r(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp); void __bsd_qsort_r(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp) #elif defined(I_AM_GNU_QSORT_R) void qsort_r(void *a, size_t n, size_t es, cmp_t *cmp, void *thunk) #else #define thunk NULL void qsort(void *a, size_t n, size_t es, cmp_t *cmp) #endif { char *pa, *pb, *pc, *pd, *pl, *pm, *pn; size_t d, r; int cmp_result; int swaptype_swap_ulong_t, swaptype_swap_uint_t, swap_cnt; size_t recursion_level = 0; struct { void *a; size_t n; } parameter_stack[PARAMETER_STACK_LEVELS]; SWAPINIT(swap_ulong_t, a, es); SWAPINIT(swap_uint_t, a, es); loop: swap_cnt = 0; if (n < 7) { /* Short arrays are insertion sorted. */ for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es) for (pl = pm; pl > (char *)a && CMP(thunk, pl - es, pl) > 0; pl -= es) swap(pl, pl - es); goto pop; } /* Select a pivot element, move it to the left. */ pm = (char *)a + (n / 2) * es; if (n > 7) { pl = a; pn = (char *)a + (n - 1) * es; if (n > 40) { d = (n / 8) * es; pl = med3(pl, pl + d, pl + 2 * d, cmp, thunk); pm = med3(pm - d, pm, pm + d, cmp, thunk); pn = med3(pn - 2 * d, pn - d, pn, cmp, thunk); } pm = med3(pl, pm, pn, cmp, thunk); } swap(a, pm); /* * Sort the array relative the pivot in four ranges as follows: * { elems == pivot, elems < pivot, elems > pivot, elems == pivot } */ pa = pb = (char *)a + es; pc = pd = (char *)a + (n - 1) * es; for (;;) { /* Scan left to right stopping at first element > pivot. */ while (pb <= pc && (cmp_result = CMP(thunk, pb, a)) <= 0) { /* Move elements == pivot to the left (to pa) */ if (cmp_result == 0) { swap_cnt = 1; swap(pa, pb); pa += es; } pb += es; } /* Scan right to left stopping at first element < pivot. */ while (pb <= pc && (cmp_result = CMP(thunk, pc, a)) >= 0) { /* Move elements == pivot to the right (to pd) */ if (cmp_result == 0) { swap_cnt = 1; swap(pc, pd); pd -= es; } pc -= es; } if (pb > pc) break; /* The scan has found two elements to swap with each other. */ swap(pb, pc); swap_cnt = 1; pb += es; pc -= es; } if (swap_cnt == 0) { /* Switch to insertion sort */ for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es) for (pl = pm; pl > (char *)a && CMP(thunk, pl - es, pl) > 0; pl -= es) swap(pl, pl - es); goto pop; } /* * Rearrange the array in three parts sorted like this: * { elements < pivot, elements == pivot, elements > pivot } */ pn = (char *)a + n * es; r = min(pa - (char *)a, pb - pa); vecswap(a, pb - r, r); r = min((size_t)(pd - pc), (size_t)(pn - pd) - es); vecswap(pb, pn - r, r); d = pb - pa; /* d = Size of left part. */ r = pd - pc; /* r = Size of right part. */ pn -= r; /* pn = Base of right part. */ /* * Check which of the left and right parts are larger. * Set (a, n) to (base, size) of the larger part. * Set (pa, r) to (base, size) of the smaller part. */ if (r > d) { /* Right part is the larger part */ pa = a; a = pn; n = r; r = d; } else { /* Left part is the larger part, or both are equal. */ pa = pn; n = d; } /* * The left and right parts each need further sorting if they * contain two elements or more. If both need sorting we use * recursion to sort the smaller part and save the larger part * to be sorted by iteration after the recursion. * Using recursion only for the smaller part guarantees a * recursion depth that is bounded to be less than (log2(n)). */ if (r > es) { /* Smaller part > 1 element. Both parts need sorting. */ if (recursion_level < PARAMETER_STACK_LEVELS) { /* * The smaller part needs to be recursively sorted * before the larger part is sorted. To avoid function * call recursion the parameters for the larger part * are pushed on the parameter_stack array. The smaller * part is sorted using iteration and the larger part * will be sorted when the parameter_stack is popped * after the smaller part has been sorted. */ parameter_stack[recursion_level].a = a; parameter_stack[recursion_level].n = n / es; recursion_level++; a = pa; n = r / es; goto loop; } else { /* * The parameter_stack array is full. The smaller part * is sorted using function call recursion. The larger * part will be sorted after the function call returns. */ #if defined(I_AM_QSORT_R) __bsd_qsort_r(pa, r / es, es, thunk, cmp); #elif defined(I_AM_GNU_QSORT_R) qsort_r(pa, r / es, es, cmp, thunk); #else qsort(pa, r / es, es, cmp); #endif } } if (n > es) { /* The larger part needs sorting. Iterate to sort. */ n = n / es; goto loop; } /* Both left and right parts are one element or less - level done. */ pop: if (recursion_level != 0) { recursion_level--; a = parameter_stack[recursion_level].a; n = parameter_stack[recursion_level].n; goto loop; } } picolibc-1.8.11/libc/search/qsort_r.c000066400000000000000000000033551513574234600174210ustar00rootroot00000000000000/* Copyright (c) 2014 Yaakov Selkowitz */ /* FUNCTION <>---sort an array INDEX qsort_r SYNOPSIS #define _BSD_SOURCE #include void qsort_r(void *<[base]>, size_t <[nmemb]>, size_t <[size]>, void *<[thunk]>, int (*<[compar]>)(void*, const void *, const void *)); #define _GNU_SOURCE #include void qsort_r(void *<[base]>, size_t <[nmemb]>, size_t <[size]>, int (*<[compar]>)(const void *, const void *, void *), void *<[thunk]>); DESCRIPTION <> sorts an array (beginning at <[base]>) of <[nmemb]> objects. <[size]> describes the size of each element of the array. You must supply a pointer to a comparison function, using the argument shown as <[compar]>. (This permits sorting objects of unknown properties.) There are two forms of this function, in each the comparison function is defined to accept three arguments, but in a different order. Two are pointers to an element of the array starting at <[base]>, and another being an arbitrary pointer <[thunk]>. The result of <<(*<[compar]>)>> must be negative if the first argument is less than the second, zero if the two arguments match, and positive if the first argument is greater than the second (where ``less than'' and ``greater than'' refer to whatever arbitrary ordering is appropriate). The array is sorted in place; that is, when <> returns, the array elements beginning at <[base]> have been reordered. RETURNS <> does not return a result. PORTABILITY <>, in various forms, appears in both BSD and glibc. */ #define _GNU_SOURCE #define I_AM_GNU_QSORT_R #include "qsort.c" picolibc-1.8.11/libc/search/tdelete.c000066400000000000000000000064271513574234600173610ustar00rootroot00000000000000/* Copyright (c) 1991, 1993, 1994 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */ /* * Tree search generalized from Knuth (6.2.2) Algorithm T just like * the AT&T man page says. * * The node_t structure is for internal use only, lint doesn't grok it. * * Written by reading the System V Interface Definition, not the code. * * Totally public domain. */ #if 0 #if defined(LIBC_SCCS) && !defined(lint) #endif /* LIBC_SCCS and not lint */ #endif #include #define _SEARCH_PRIVATE #include #include /* delete node with given key */ void * tdelete(const void * __restrict vkey, /* key to be deleted */ void ** __restrict vrootp, /* address of the root of tree */ int (*compar)(const void *, const void *)) { node_t **rootp = (node_t **)vrootp; node_t *p, *q, *r; int cmp; if (rootp == NULL || (p = *rootp) == NULL) return NULL; while ((cmp = (*compar)(vkey, (*rootp)->key)) != 0) { p = *rootp; rootp = (cmp < 0) ? &(*rootp)->llink : /* follow llink branch */ &(*rootp)->rlink; /* follow rlink branch */ if (*rootp == NULL) return NULL; /* key not found */ } r = (*rootp)->rlink; /* D1: */ if ((q = (*rootp)->llink) == NULL) /* Left NULL? */ q = r; else if (r != NULL) { /* Right link is NULL? */ if (r->llink == NULL) { /* D2: Find successor */ r->llink = q; q = r; } else { /* D3: Find NULL link */ for (q = r->llink; q->llink != NULL; q = r->llink) r = q; r->llink = q->rlink; q->llink = (*rootp)->llink; q->rlink = (*rootp)->rlink; } } free(*rootp); /* D4: Free node */ *rootp = q; /* link parent to new node */ return p; } picolibc-1.8.11/libc/search/tdestroy.c000066400000000000000000000047421513574234600176060ustar00rootroot00000000000000/* Copyright (c) 1991, 1993, 1994 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */ /* * Tree search generalized from Knuth (6.2.2) Algorithm T just like * the AT&T man page says. * * The node_t structure is for internal use only, lint doesn't grok it. * * Written by reading the System V Interface Definition, not the code. * * Totally public domain. */ #if 0 #if defined(LIBC_SCCS) && !defined(lint) #endif /* LIBC_SCCS and not lint */ #endif #include #define _SEARCH_PRIVATE #include #include /* Walk the nodes of a tree */ static void trecurse(node_t *root, /* Root of the tree to be walked */ void (*free_action)(void *)) { if (root->llink != NULL) trecurse(root->llink, free_action); if (root->rlink != NULL) trecurse(root->rlink, free_action); (*free_action)((void *)root->key); free(root); } void tdestroy(void *vrootp, void (*freefct)(void *)) { node_t *root = (node_t *)vrootp; if (root != NULL) trecurse(root, freefct); } picolibc-1.8.11/libc/search/tfind.c000066400000000000000000000052151513574234600170310ustar00rootroot00000000000000/* Copyright (c) 1991, 1993, 1994 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $NetBSD: tfind.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */ /* * Tree search generalized from Knuth (6.2.2) Algorithm T just like * the AT&T man page says. * * The node_t structure is for internal use only, lint doesn't grok it. * * Written by reading the System V Interface Definition, not the code. * * Totally public domain. */ #if 0 #if defined(LIBC_SCCS) && !defined(lint) #endif /* LIBC_SCCS and not lint */ #endif #include #define _SEARCH_PRIVATE #include #include /* find a node, or return 0 */ void * tfind(const void *vkey, /* key to be found */ void **vrootp, /* address of the tree root */ int (*compar)(const void *, const void *)) { node_t **rootp = (node_t **)vrootp; if (rootp == NULL) return NULL; while (*rootp != NULL) { /* T1: */ int r; if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */ return *rootp; /* key found */ rootp = (r < 0) ? &(*rootp)->llink : /* T3: follow left branch */ &(*rootp)->rlink; /* T4: follow right branch */ } return NULL; } picolibc-1.8.11/libc/search/tsearch.3000066400000000000000000000074041513574234600173000ustar00rootroot00000000000000.\" $NetBSD$ .\" Copyright (c) 1997 Todd C. Miller .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. The name of the author may not be used to endorse or promote products .\" derived from this software without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY .\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL .\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, .\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, .\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; .\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" OpenBSD: tsearch.3,v 1.2 1998/06/21 22:13:49 millert Exp .\" $FreeBSD: src/lib/libc/stdlib/tsearch.3,v 1.7 2001/09/07 14:46:36 asmodai Exp $ .\" .Dd June 15, 1997 .Dt TSEARCH 3 .Os .Sh NAME .Nm tsearch , tfind , tdelete , twalk .Nd manipulate binary search trees .Sh SYNOPSIS .In search.h .Ft void * .Fn tdelete "const void *key" "void **rootp" "int (*compar) (const void *, const void *)" .Ft void * .Fn tfind "const void *key" "void **rootp" "int (*compar) (const void *, const void *)" .Ft void * .Fn tsearch "const void *key" "void **rootp" "int (*compar) (const void *, const void *)" .Ft void .Fn twalk "const void *root" "void (*compar) (const void *, VISIT, int)" .Sh DESCRIPTION The .Fn tdelete , .Fn tfind , .Fn tsearch , and .Fn twalk functions manage binary search trees based on algorithms T and D from Knuth (6.2.2). The comparison function passed in by the user has the same style of return values as .Xr strcmp 3 . .Pp .Fn Tfind searches for the datum matched by the argument .Fa key in the binary tree rooted at .Fa rootp , returning a pointer to the datum if it is found and NULL if it is not. .Pp .Fn Tsearch is identical to .Fn tfind except that if no match is found, .Fa key is inserted into the tree and a pointer to it is returned. If .Fa rootp points to a NULL value a new binary search tree is created. .Pp .Fn Tdelete deletes a node from the specified binary search tree and returns a pointer to the parent of the node to be deleted. It takes the same arguments as .Fn tfind and .Fn tsearch . If the node to be deleted is the root of the binary search tree, .Fa rootp will be adjusted. .Pp .Fn Twalk walks the binary search tree rooted in .Fa root and calls the function .Fa action on each node. .Fa Action is called with three arguments: a pointer to the current node, a value from the enum .Sy "typedef enum { preorder, postorder, endorder, leaf } VISIT;" specifying the traversal type, and a node level (where level zero is the root of the tree). .Sh SEE ALSO .Xr bsearch 3 , .Xr hsearch 3 , .Xr lsearch 3 .Sh RETURN VALUES The .Fn tsearch function returns NULL if allocation of a new node fails (usually due to a lack of free memory). .Pp .Fn Tfind , .Fn tsearch , and .Fn tdelete return NULL if .Fa rootp is NULL or the datum cannot be found. .Pp The .Fn twalk function returns no value. picolibc-1.8.11/libc/search/tsearch.c000066400000000000000000000057271513574234600173660ustar00rootroot00000000000000/* Copyright (c) 1991, 1993, 1994 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $NetBSD: tsearch.c,v 1.3 1999/09/16 11:45:37 lukem Exp $ */ /* * Tree search generalized from Knuth (6.2.2) Algorithm T just like * the AT&T man page says. * * The node_t structure is for internal use only, lint doesn't grok it. * * Written by reading the System V Interface Definition, not the code. * * Totally public domain. */ #if 0 #if defined(LIBC_SCCS) && !defined(lint) #endif /* LIBC_SCCS and not lint */ #endif #include #define _SEARCH_PRIVATE #include #include /* find or insert datum into search tree */ void * tsearch(const void *vkey, /* key to be located */ void **vrootp, /* address of tree root */ int (*compar)(const void *, const void *)) { node_t *q; node_t **rootp = (node_t **)vrootp; if (rootp == NULL) return NULL; while (*rootp != NULL) { /* Knuth's T1: */ int r; if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */ return *rootp; /* we found it! */ rootp = (r < 0) ? &(*rootp)->llink : /* T3: follow left branch */ &(*rootp)->rlink; /* T4: follow right branch */ } q = malloc(sizeof(node_t)); /* T5: key not found */ if (q != 0) { /* make new node */ *rootp = q; /* link new node to old */ /* LINTED const castaway ok */ q->key = (void *)vkey; /* initialize new node */ q->llink = q->rlink = NULL; } return q; } picolibc-1.8.11/libc/search/twalk.c000066400000000000000000000055741513574234600170570ustar00rootroot00000000000000/* Copyright (c) 1991, 1993, 1994 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $NetBSD: twalk.c,v 1.1 1999/02/22 10:33:16 christos Exp $ */ /* * Tree search generalized from Knuth (6.2.2) Algorithm T just like * the AT&T man page says. * * The node_t structure is for internal use only, lint doesn't grok it. * * Written by reading the System V Interface Definition, not the code. * * Totally public domain. */ #if 0 #if defined(LIBC_SCCS) && !defined(lint) #endif /* LIBC_SCCS and not lint */ #endif #include #define _SEARCH_PRIVATE #include #include static void trecurse(const node_t *, void (*action)(const void *, VISIT, int), int level); /* Walk the nodes of a tree */ static void trecurse(const node_t *root, /* Root of the tree to be walked */ void (*action)(const void *, VISIT, int), int level) { if (root->llink == NULL && root->rlink == NULL) (*action)(root, leaf, level); else { (*action)(root, preorder, level); if (root->llink != NULL) trecurse(root->llink, action, level + 1); (*action)(root, postorder, level); if (root->rlink != NULL) trecurse(root->rlink, action, level + 1); (*action)(root, endorder, level); } } /* Walk the nodes of a tree */ void twalk(const void *vroot, /* Root of the tree to be walked */ void (*action)(const void *, VISIT, int)) { if (vroot != NULL && action != NULL) trecurse(vroot, action, 0); } picolibc-1.8.11/libc/signal/000077500000000000000000000000001513574234600155665ustar00rootroot00000000000000picolibc-1.8.11/libc/signal/CMakeLists.txt000066400000000000000000000031471513574234600203330ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources( psignal.c sig2str.c signal.c ) picolibc-1.8.11/libc/signal/meson.build000066400000000000000000000037451513574234600177410ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_signal = [ 'psignal.c', 'sig2str.c', 'signal.c', ] srcs_signal_use = [] foreach file : srcs_signal s_file = fs.replace_suffix(file, '.S') if file in srcs_machine message('libc/signal/' + file + ': machine overrides generic') elif s_file in srcs_machine message('libc/signal/' + s_file + ': machine overrides generic') else srcs_signal_use += file endif endforeach src_signal = files(srcs_signal_use) picolibc-1.8.11/libc/signal/psignal.c000066400000000000000000000022171513574234600173710ustar00rootroot00000000000000/* Copyright 2002, 2011 Red Hat Inc. */ /* FUNCTION <>---print a signal message on standard error INDEX psignal SYNOPSIS #include void psignal(int <[signal]>, const char *<[prefix]>); DESCRIPTION Use <> to print (on standard error) a signal message corresponding to the value of the signal number <[signal]>. Unless you use <> as the value of the argument <[prefix]>, the signal message will begin with the string at <[prefix]>, followed by a colon and a space (<<: >>). The remainder of the signal message is one of the strings described for <>. RETURNS <> returns no result. PORTABILITY POSIX.1-2008 requires <>, but the strings issued vary from one implementation to another. Supporting OS subroutines required: <>, <>, <>, <>, <>, <>, <>. */ #define _DEFAULT_SOURCE #include #include #include #include void psignal(int sig, const char *s) { fflush(stderr); if (s != NULL && *s != '\0') fprintf(stderr, "%s: ", s); fprintf(stderr, "%s\n", strsignal(sig)); } picolibc-1.8.11/libc/signal/sig2str.c000066400000000000000000000202041513574234600173250ustar00rootroot00000000000000/* SPDX-License-Identifier: BSD-2-Clause */ /* * Copyright (C) 2021 Matthew Joyce * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>, <>---Translate between signal number and name INDEX sig2str INDEX str2sig SYNOPSIS #include int sig2str(int <[signum]>, char *<[str]>); int str2sig(const char *restrict <[str]>, int *restrict <[pnum]>); DESCRIPTION The <> function translates the signal number specified by <[signum]> to a signal name and stores this string in the location specified by <[str]>. The application must ensure that <[str]> points to a location that can store the string including the terminating null byte. The symbolic constant <[SIG2STR_MAX]> defined in `<>' gives the maximum number of bytes required. The <> function translates the signal name in the string pointed to by <[str]> to a signal number and stores this value in the location specified by <[pnum]>. RETURNS <> returns <<0>> if <[signum]>> is a valid, supported signal number. Otherwise, it returns <<-1>>. <> returns <<0>> if it stores a value in the location pointed to by <[pnum]>. Otherwise it returns <<-1>>. */ #define _DEFAULT_SOURCE #include #include #include #include #define SPACES_TO_N 6 /* Allows indexing to RT Signal number in str2sig */ #define NUM_OF_SIGS (sizeof(sig_array) / sizeof(sig_name_and_num)) typedef struct sig_name_and_num { const char sig_name[8]; const int sig_num; } sig_name_and_num; static const sig_name_and_num sig_array[] = { { "EXIT", 0 }, #ifdef SIGHUP { "HUP", SIGHUP }, #endif #ifdef SIGINT { "INT", SIGINT }, #endif #ifdef SIGQUIT { "QUIT", SIGQUIT }, #endif #ifdef SIGILL { "ILL", SIGILL }, #endif #ifdef SIGTRAP { "TRAP", SIGTRAP }, #endif #ifdef SIGABRT { "ABRT", SIGABRT }, #endif #ifdef SIGIOT { "IOT", SIGIOT }, #endif #ifdef SIGEMT { "EMT", SIGEMT }, #endif #ifdef SIGFPE { "FPE", SIGFPE }, #endif #ifdef SIGKILL { "KILL", SIGKILL }, #endif #ifdef SIGBUS { "BUS", SIGBUS }, #endif #ifdef SIGSEGV { "SEGV", SIGSEGV }, #endif #ifdef SIGSYS { "SYS", SIGSYS }, #endif #ifdef SIGPIPE { "PIPE", SIGPIPE }, #endif #ifdef SIGALRM { "ALRM", SIGALRM }, #endif #ifdef SIGTERM { "TERM", SIGTERM }, #endif #ifdef SIGURG { "URG", SIGURG }, #endif #ifdef SIGSTOP { "STOP", SIGSTOP }, #endif #ifdef SIGTSTP { "TSTP", SIGTSTP }, #endif #ifdef SIGCONT { "CONT", SIGCONT }, #endif #ifdef SIGCHLD { "CHLD", SIGCHLD }, #endif #ifdef SIGCLD { "CLD", SIGCLD }, #endif #ifdef SIGTTIN { "TTIN", SIGTTIN }, #endif #ifdef SIGTTOU { "TTOU", SIGTTOU }, #endif #ifdef SIGIO { "IO", SIGIO }, #endif #ifdef SIGPOLL { "POLL", SIGPOLL }, #endif #ifdef SIGWINCH { "WINCH", SIGWINCH }, #endif #ifdef SIGUSR1 { "USR1", SIGUSR1 }, #endif #ifdef SIGUSR2 { "USR2", SIGUSR2 }, #endif #ifdef SIGPWR { "PWR", SIGPWR }, #endif #ifdef SIGXCPU { "XCPU", SIGXCPU }, #endif #ifdef SIGXFSZ { "XFSZ", SIGXFSZ }, #endif #ifdef SIGVTALRM { "VTALRM", SIGVTALRM }, #endif #ifdef SIGPROF { "PROF", SIGPROF }, #endif #ifdef SIGLOST { "LOST", SIGLOST }, #endif /* The Issue 8 standard requires that SIGRTMIN and SIGRTMAX be included * as valid results to be saved from calls to sig2str/str2sig. */ #ifdef SIGRTMIN { "RTMIN", SIGRTMIN }, #endif #ifdef SIGRTMAX { "RTMAX", SIGRTMAX } #endif }; int sig2str(int signum, char *str) { const sig_name_and_num *sptr; #if defined(SIGRTMIN) && defined(SIGRTMAX) /* If signum falls in lower half of the real time signals range, define * the saved str value as "RTMIN+n" according to the Issue 8 standard */ if ((SIGRTMIN + 1) <= signum && signum <= (SIGRTMIN + SIGRTMAX) / 2) { sprintf(str, "RTMIN+%d", (signum - SIGRTMIN)); return 0; } /* If signum falls in upper half of the real time signals range, define * the saved str value as "RTMAX-m" according to the Issue 8 standard */ if ((((SIGRTMIN + SIGRTMAX) / 2) + 1) <= signum && signum <= (SIGRTMAX - 1)) { sprintf(str, "RTMAX-%d", (SIGRTMAX - signum)); return 0; } #endif /* Otherwise, search for signal matching signum in sig_array. If found, * save its string value in str. */ for (sptr = sig_array; sptr < &sig_array[NUM_OF_SIGS]; sptr++) { if (sptr->sig_num == signum) { strcpy(str, sptr->sig_name); return 0; } } /* If signum is not a recognized signal number, return -1 */ return -1; } int str2sig(const char * __restrict str, int * __restrict pnum) { char *endp; const sig_name_and_num *sptr; unsigned long is_valid_decimal; #if defined(SIGRTMIN) && defined(SIGRTMAX) /* i686 Cygwin only supports one RT signal. For this case, skip checks * for "RTMIN+n" and "RTMAX-m". */ if (SIGRTMIN != SIGRTMAX) { /* If str is in RT signal range, get number of of RT signal, save it as an * integer. */ if (strncmp(str, "RTMIN+", SPACES_TO_N) == 0) { unsigned long j = strtoul(&str[SPACES_TO_N], &endp, 10); /* If number is valid, save it in pnum. */ if (*endp == '\0') { if (1 <= j && j <= ((SIGRTMAX - SIGRTMIN) - 1)) { *pnum = (SIGRTMIN + j); return 0; } return -1; } return -1; } /* If str is in RT signal range, get number of of RT signal, save it as an * integer. */ if (strncmp(str, "RTMAX-", SPACES_TO_N) == 0) { unsigned long j = strtoul(&str[SPACES_TO_N], &endp, 10); // and endptr null check /* If number is valid, save it in pnum. */ if (*endp == '\0') { if (1 <= j && j <= ((SIGRTMAX - SIGRTMIN) - 1)) { *pnum = (SIGRTMAX - j); return 0; } return -1; } return -1; } } #endif /*If str is a valid signal name, save its corresponding number in pnum. */ for (sptr = sig_array; sptr < &sig_array[NUM_OF_SIGS]; sptr++) { if (strcmp(sptr->sig_name, str) == 0) { *pnum = sptr->sig_num; return 0; } } /* str was not found in sig_array. Check whether str is a string * representation of a valid integer. */ is_valid_decimal = strtoul(str, &endp, 10); if (*endp != '\0') { return -1; } /* If str is a representation of a decimal value, save its integer value * in pnum. */ if (1 <= is_valid_decimal && is_valid_decimal <= (_NSIG - 1)) { *pnum = is_valid_decimal; return 0; } return -1; } picolibc-1.8.11/libc/signal/signal.c000066400000000000000000000113561513574234600172150ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---specify handler subroutine for a signal INDEX signal SYNOPSIS #include void (*signal(int <[sig]>, void(*<[func]>)(int))) (int); DESCRIPTION <> provides a simple signal-handling implementation for embedded targets. <> allows you to request changed treatment for a particular signal <[sig]>. You can use one of the predefined macros <> (select system default handling) or <> (ignore this signal) as the value of <[func]>; otherwise, <[func]> is a function pointer that identifies a subroutine in your program as the handler for this signal. Some of the execution environment for signal handlers is unpredictable; notably, the only library function required to work correctly from within a signal handler is <> itself, and only when used to redefine the handler for the current signal value. Static storage is likewise unreliable for signal handlers, with one exception: if you declare a static storage location as `<>', then you may use that location in a signal handler to store signal values. If your signal handler terminates using <> (or implicit return), your program's execution continues at the point where it was when the signal was raised (whether by your program itself, or by an external event). Signal handlers can also use functions such as <> and <> to avoid returning. @c FIXME: do we have setjmp.h and assoc fns? RETURNS If your request for a signal handler cannot be honored, the result is <>; a specific error number is also recorded in <>. Otherwise, the result is the previous handler (a function pointer or one of the predefined macros). PORTABILITY ANSI C requires <>. No supporting OS subroutines are required to link with <>, but it will not have any useful effects, except for software generated signals, without an operating system that can actually raise exceptions. */ /* * signal.c * Original Author: G. Haley * * signal associates the function pointed to by func with the signal sig. When * a signal occurs, the value of func determines the action taken as follows: * if func is SIG_DFL, the default handling for that signal will occur; if func * is SIG_IGN, the signal will be ignored; otherwise, the default handling for * the signal is restored (SIG_DFL), and the function func is called with sig * as its argument. Returns the value of func for the previous call to signal * for the signal sig, or SIG_ERR if the request fails. */ #define _DEFAULT_SOURCE #include #include #include #if __SIZEOF_POINTER__ == 2 && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) #define _USE_ATOMIC_SIGNAL #endif #if __SIZEOF_POINTER__ == 4 && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) #define _USE_ATOMIC_SIGNAL #endif #if __SIZEOF_POINTER__ == 8 && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) #define _USE_ATOMIC_SIGNAL #endif #ifdef _USE_ATOMIC_SIGNAL #include static _Atomic _sig_func_ptr _sig_func[_NSIG]; #else static _sig_func_ptr _sig_func[_NSIG]; #endif _sig_func_ptr signal(int sig, _sig_func_ptr func) { if (sig < 0 || sig >= _NSIG) { errno = EINVAL; return SIG_ERR; } #ifdef _USE_ATOMIC_SIGNAL return (_sig_func_ptr)atomic_exchange(&_sig_func[sig], func); #else _sig_func_ptr old = _sig_func[sig]; _sig_func[sig] = func; return old; #endif } int raise(int sig) { if (sig < 0 || sig >= _NSIG) { errno = EINVAL; return -1; } for (;;) { _sig_func_ptr func; #ifdef _USE_ATOMIC_SIGNAL func = (_sig_func_ptr)atomic_load(&_sig_func[sig]); #else func = _sig_func[sig]; #endif if (func == SIG_IGN) return 0; else if (func == SIG_DFL) _exit(128 + sig); #ifdef _USE_ATOMIC_SIGNAL /* make sure it hasn't changed in the meantime */ if (!atomic_compare_exchange_strong(&_sig_func[sig], &func, SIG_DFL)) continue; #else _sig_func[sig] = SIG_DFL; #endif (*func)(sig); return 0; } } picolibc-1.8.11/libc/signal/signal.tex000066400000000000000000000062121513574234600175660ustar00rootroot00000000000000# #Copyright (c) 1994 Cygnus Support. #All rights reserved. # #Redistribution and use in source and binary forms are permitted #provided that the above copyright notice and this paragraph are #duplicated in all such forms and that any documentation, #and/or other materials related to such #distribution and use acknowledge that the software was developed #at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to #endorse or promote products derived from this software without #specific prior written permission. #THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR #IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED #WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. @node Signals @chapter Signal Handling (@file{signal.h}) A @dfn{signal} is an event that interrupts the normal flow of control in your program. Your operating environment normally defines the full set of signals available (see @file{sys/signal.h}), as well as the default means of dealing with them---typically, either printing an error message and aborting your program, or ignoring the signal. All systems support at least the following signals: @table @code @item SIGABRT Abnormal termination of a program; raised by the @code{abort} function. @item SIGFPE A domain error in arithmetic, such as overflow, or division by zero. @item SIGILL Attempt to execute as a function data that is not executable. @item SIGINT Interrupt; an interactive attention signal. @item SIGSEGV An attempt to access a memory location that is not available. @item SIGTERM A request that your program end execution. @end table Two functions are available for dealing with asynchronous signals---one to allow your program to send signals to itself (this is called @dfn{raising} a signal), and one to specify subroutines (called @dfn{handlers} to handle particular signals that you anticipate may occur---whether raised by your own program or the operating environment. To support these functions, @file{signal.h} defines three macros: @table @code @item SIG_DFL Used with the @code{signal} function in place of a pointer to a handler subroutine, to select the operating environment's default handling of a signal. @item SIG_IGN Used with the @code{signal} function in place of a pointer to a handler, to ignore a particular signal. @item SIG_ERR Returned by the @code{signal} function in place of a pointer to a handler, to indicate that your request to set up a handler could not be honored for some reason. @end table @file{signal.h} also defines an integral type, @code{sig_atomic_t}. This type is not used in any function declarations; it exists only to allow your signal handlers to declare a static storage location where they may store a signal value. (Static storage is not otherwise reliable from signal handlers.) @menu * Function psignal:: Print a signal message to standard error * Function raise:: Send a signal * Function sig2str:: Translate between signal number and name * Function signal:: Specify handler subroutine for a signal @end menu @page @include signal/psignal.def @page @include signal/raise.def @page @include signal/sig2str.def @page @include signal/signal.def picolibc-1.8.11/libc/ssp/000077500000000000000000000000001513574234600151165ustar00rootroot00000000000000picolibc-1.8.11/libc/ssp/CMakeLists.txt000066400000000000000000000035221513574234600176600ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources( chk_fail.c gets_chk.c memcpy_chk.c memmove_chk.c mempcpy_chk.c memset_chk.c snprintf_chk.c sprintf_chk.c stack_protector.c stpcpy_chk.c stpncpy_chk.c strcat_chk.c strcpy_chk.c strncat_chk.c strncpy_chk.c vsnprintf_chk.c vsprintf_chk.c ) picolibc-1.8.11/libc/ssp/chk_fail.c000066400000000000000000000010101513574234600170120ustar00rootroot00000000000000/* Copyright 2017 Yaakov Selkowitz */ #include #include #include #include #include #include #undef puts static void (*fortify_handler)(int sig); #define CHK_FAIL_MSG "*** overflow detected ***: terminated" __noreturn void __chk_fail(void) { puts(CHK_FAIL_MSG); if (fortify_handler) (*fortify_handler)(SIGABRT); abort(); } void set_fortify_handler(void (*handler)(int sig)) { fortify_handler = handler; } picolibc-1.8.11/libc/ssp/gets_chk.c000066400000000000000000000042601513574234600170530ustar00rootroot00000000000000/* $NetBSD: gets_chk.c,v 1.7 2013/10/04 20:49:16 christos Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*LINTLIBRARY*/ #include #include #include #include #include #include char * __gets_chk(char * __restrict str, size_t slen) { char *cp = str; for (;;) { int c = getchar(); switch (c) { case EOF: if (ferror(stdin) || cp == str) return NULL; __fallthrough; case '\n': if (slen == 0) __chk_fail(); *cp = '\0'; return str; default: if (slen == 0) __chk_fail(); slen--; *cp++ = (char)c; } } } picolibc-1.8.11/libc/ssp/memcpy_chk.c000066400000000000000000000036751513574234600174140ustar00rootroot00000000000000/* $NetBSD: memcpy_chk.c,v 1.7 2015/05/13 19:57:16 joerg Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*LINTLIBRARY*/ #include #include #undef memcpy void *__memcpy_chk(void * __restrict, const void * __restrict, size_t, size_t); void * __memcpy_chk(void * __restrict dst, const void * __restrict src, size_t len, size_t slen) { if (len > slen) __chk_fail(); if (__ssp_overlap((const char *)src, (const char *)dst, len)) __chk_fail(); return memcpy(dst, src, len); } picolibc-1.8.11/libc/ssp/memmove_chk.c000066400000000000000000000035231513574234600175570ustar00rootroot00000000000000/* $NetBSD: memmove_chk.c,v 1.5 2014/09/17 00:39:28 joerg Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*LINTLIBRARY*/ #include #include #undef memmove #undef __memmove_chk void *__memmove_chk(void *, const void *src, size_t, size_t); void * __memmove_chk(void *dst, const void *src, size_t len, size_t slen) { if (len > slen) __chk_fail(); return memmove(dst, src, len); } picolibc-1.8.11/libc/ssp/mempcpy_chk.c000066400000000000000000000033141513574234600175620ustar00rootroot00000000000000/* Copyright (c) 2006 The NetBSD Foundation, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _GNU_SOURCE #include #include #undef mempcpy void *__mempcpy_chk(void * __restrict, const void * __restrict, size_t, size_t); void * __mempcpy_chk(void * __restrict dst, const void * __restrict src, size_t len, size_t slen) { if (len > slen) __chk_fail(); if (__ssp_overlap((const char *)src, (const char *)dst, len)) __chk_fail(); return mempcpy(dst, src, len); } picolibc-1.8.11/libc/ssp/memset_chk.c000066400000000000000000000034731513574234600174100ustar00rootroot00000000000000/* $NetBSD: memset_chk.c,v 1.5 2014/09/17 00:39:28 joerg Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*LINTLIBRARY*/ #include #include #undef memset void *__memset_chk(void * __restrict, int, size_t, size_t); void * __memset_chk(void * __restrict dst, int val, size_t len, size_t slen) { if (len > slen) __chk_fail(); return memset(dst, val, len); } picolibc-1.8.11/libc/ssp/meson.build000066400000000000000000000043751513574234600172710ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_ssp = [ 'chk_fail.c', 'gets_chk.c', 'memcpy_chk.c', 'memmove_chk.c', 'mempcpy_chk.c', 'memset_chk.c', 'snprintf_chk.c', 'sprintf_chk.c', 'stack_protector.c', 'stpcpy_chk.c', 'stpncpy_chk.c', 'strcat_chk.c', 'strcpy_chk.c', 'strncat_chk.c', 'strncpy_chk.c', 'vsnprintf_chk.c', 'vsprintf_chk.c', ] srcs_ssp_use = [] foreach file : srcs_ssp s_file = fs.replace_suffix(file, '.S') if file in srcs_machine message('libc/ssp/' + file + ': machine overrides generic') elif s_file in srcs_machine message('libc/ssp/' + s_file + ': machine overrides generic') else srcs_ssp_use += file endif endforeach src_ssp = files(srcs_ssp_use) picolibc-1.8.11/libc/ssp/snprintf_chk.c000066400000000000000000000043341513574234600177560ustar00rootroot00000000000000/* $NetBSD: snprintf_chk.c,v 1.5 2008/04/28 20:23:00 martin Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*LINTLIBRARY*/ #include #include #include #include #undef vsnprintf /*ARGSUSED*/ int __snprintf_chk(char * __restrict buf, size_t len, int flags, size_t slen, const char * __restrict fmt, ...) { va_list ap; int rv; (void)flags; if (len > slen) __chk_fail(); va_start(ap, fmt); rv = vsnprintf(buf, len, fmt, ap); va_end(ap); return rv; } #ifdef _LONG_DOUBLE_IEEE128__ #ifdef __strong_reference #if defined(__GNUCLIKE_PRAGMA_DIAGNOSTIC) && !defined(__clang__) #pragma GCC diagnostic ignored "-Wmissing-attributes" #endif __strong_reference(__snprintf_chk, __snprintf_chkieee128); #endif #endif picolibc-1.8.11/libc/ssp/sprintf_chk.c000066400000000000000000000043121513574234600175740ustar00rootroot00000000000000/* $NetBSD: sprintf_chk.c,v 1.6 2009/02/05 05:40:36 lukem Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*LINTLIBRARY*/ #include #include #include #include #include #undef vsnprintf #undef vsprintf int /*ARGSUSED*/ __sprintf_chk(char * __restrict buf, int flags, size_t slen, const char * __restrict fmt, ...) { va_list ap; int rv; (void)flags; va_start(ap, fmt); if (slen > (size_t)INT_MAX) rv = vsprintf(buf, fmt, ap); else { if ((rv = vsnprintf(buf, slen, fmt, ap)) >= 0 && (size_t)rv >= slen) __chk_fail(); } va_end(ap); return rv; } #ifdef __LONG_DOUBLE_128__ #ifdef __strong_reference __strong_reference(__sprintf_chk, __sprintf_chkieee128); #endif #endif picolibc-1.8.11/libc/ssp/ssp.tex000066400000000000000000000040001513574234600164370ustar00rootroot00000000000000@node Overflow Protection @chapter Overflow Protection @menu * Stack Smashing Protection:: Checks enabled with -fstack-protector* * Object Size Checking:: Checks enabled with _FORTIFY_SOURCE @end menu @node Stack Smashing Protection @section Stack Smashing Protection Stack Smashing Protection is a compiler feature which emits extra code to check for stack smashing attacks. It depends on a canary, which is initialized with the process, and functions for process termination when an overflow is detected. These are private entry points intended solely for use by the compiler, and are used when any of the @code{-fstack-protector}, @code{-fstack-protector-all}, @code{-fstack-protector-explicit}, or @code{-fstack-protector-strong} compiler flags are enabled. @node Object Size Checking @section Object Size Checking Object Size Checking is a feature which wraps certain functions with checks to prevent buffer overflows. These are enabled when compiling with optimization (@code{-O1} and higher) and @code{_FORTIFY_SOURCE} defined to 1, or for stricter checks, to 2. @cindex list of overflow protected functions The following functions use object size checking to detect buffer overflows when enabled: @example @exdent @emph{String functions:} bcopy memmove strcpy bzero mempcpy strcat explicit_bzero memset strncat memcpy stpcpy strncpy @exdent @emph{Wide Character String functions:} fgetws wcrtomb wcsrtombs fgetws_unlocked wcscat wmemcpy mbsnrtowcs wcscpy wmemmove mbsrtowcs wcsncat wmempcpy wcpcpy wcsncpy wmemset wcpncpy wcsnrtombs @exdent @emph{Stdio functions:} fgets fread_unlocked sprintf fgets_unlocked gets vsnprintf fread snprintf vsprintf @exdent @emph{Stdlib functions:} mbstowcs wcstombs wctomb @exdent @emph{System functions:} getcwd read ttyname_r pread readlink @end example picolibc-1.8.11/libc/ssp/stack_protector.c000066400000000000000000000032371513574234600204750ustar00rootroot00000000000000/* Copyright (c) 2017 Yaakov Selkowitz */ #include #include #include #include #include #include #include #if defined(__AMDGCN__) || defined(__nvptx__) /* Global constructors not supported on this target, yet. */ uintptr_t __stack_chk_guard = 0x00000aff; /* 0, 0, '\n', 255 */ #else #ifdef __THREAD_LOCAL_STORAGE_STACK_GUARD #include "machine/_ssp_tls.h" #else uintptr_t __stack_chk_guard = 0; #endif int getentropy(void *, size_t) __weak; void __stack_chk_init(void) __attribute__((__constructor__)); void __attribute__((__constructor__)) __stack_chk_init(void) { if (__stack_chk_guard != 0) return; if (getentropy) { /* Use getentropy if available */ getentropy(&__stack_chk_guard, sizeof(__stack_chk_guard)); } else { /* If getentropy is not available, use the "terminator canary". */ ((unsigned char *)&__stack_chk_guard)[0] = 0; ((unsigned char *)&__stack_chk_guard)[1] = 0; #if __SIZEOF_POINTER__ > 2 ((unsigned char *)&__stack_chk_guard)[2] = '\n'; ((unsigned char *)&__stack_chk_guard)[3] = 255; #endif } } #endif __noreturn void __stack_chk_fail(void); #define STACK_CHK_MSG "*** stack smashing detected ***: terminated" __typeof(__stack_chk_fail) __stack_chk_fail_weak; __noreturn void __stack_chk_fail_weak(void) { puts(STACK_CHK_MSG); abort(); } __weak_reference(__stack_chk_fail_weak, __stack_chk_fail); #ifdef __ELF__ __typeof(__stack_chk_fail) __stack_chk_fail_local; void __attribute__((visibility("hidden"))) __stack_chk_fail_local(void) { __stack_chk_fail(); } #endif picolibc-1.8.11/libc/ssp/stpcpy_chk.c000066400000000000000000000037111513574234600174330ustar00rootroot00000000000000/* $NetBSD: stpcpy_chk.c,v 1.6 2015/05/09 15:42:21 christos Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*LINTLIBRARY*/ #include #include #undef memcpy char *__stpcpy_chk(char * __restrict, const char * __restrict, size_t); char * __stpcpy_chk(char * __restrict dst, const char * __restrict src, size_t slen) { size_t len = strlen(src); if (len >= slen) __chk_fail(); if (__ssp_overlap(src, dst, len)) __chk_fail(); (void)memcpy(dst, src, len + 1); return dst + len; } picolibc-1.8.11/libc/ssp/stpncpy_chk.c000066400000000000000000000037011513574234600176100ustar00rootroot00000000000000/* $NetBSD: stpncpy_chk.c,v 1.3 2015/05/09 15:42:21 christos Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE /*LINTLIBRARY*/ #include #include #undef stpncpy char *__stpncpy_chk(char * __restrict, const char * __restrict, size_t, size_t); char * __stpncpy_chk(char * __restrict dst, const char * __restrict src, size_t len, size_t slen) { if (len > slen) __chk_fail(); if (__ssp_overlap(src, dst, len)) __chk_fail(); return stpncpy(dst, src, len); } picolibc-1.8.11/libc/ssp/strcat_chk.c000066400000000000000000000040101513574234600174020ustar00rootroot00000000000000/* $NetBSD: strcat_chk.c,v 1.5 2014/09/17 00:39:28 joerg Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*LINTLIBRARY*/ #include #include char *__strcat_chk(char * __restrict, const char * __restrict, size_t); char * __strcat_chk(char * __restrict dst, const char * __restrict src, size_t slen) { char *d; for (d = dst; *d; d++) { if (slen-- == 0) __chk_fail(); } while (*src) { if (slen-- == 0) __chk_fail(); *d++ = *src++; } if (slen-- == 0) __chk_fail(); *d = '\0'; return dst; } picolibc-1.8.11/libc/ssp/strcpy_chk.c000066400000000000000000000036631513574234600174430ustar00rootroot00000000000000/* $NetBSD: strcpy_chk.c,v 1.8 2015/05/09 15:42:21 christos Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*LINTLIBRARY*/ #include #include #undef memcpy char *__strcpy_chk(char * __restrict, const char * __restrict, size_t); char * __strcpy_chk(char * __restrict dst, const char * __restrict src, size_t slen) { size_t len = strlen(src) + 1; if (len > slen) __chk_fail(); if (__ssp_overlap(src, dst, len)) __chk_fail(); return memcpy(dst, src, len); } picolibc-1.8.11/libc/ssp/strncat_chk.c000066400000000000000000000042721513574234600175720ustar00rootroot00000000000000/* $NetBSD: strncat_chk.c,v 1.5 2014/09/17 00:39:28 joerg Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*LINTLIBRARY*/ #include #include #include char *__strncat_chk(char * __restrict, const char * __restrict, size_t, size_t); char * __strncat_chk(char * __restrict dst, const char * __restrict src, size_t len, size_t slen) { char *d; if (len == 0) return dst; if (len > slen) __chk_fail(); for (d = dst; *d; d++) { if (slen-- == 0) __chk_fail(); } do { if ((*d = *src++) == '\0') break; if (slen-- == 0) __chk_fail(); d++; } while (--len != 0); if (slen-- == 0) __chk_fail(); *d = '\0'; return dst; } picolibc-1.8.11/libc/ssp/strncpy_chk.c000066400000000000000000000036511513574234600176160ustar00rootroot00000000000000/* $NetBSD: strncpy_chk.c,v 1.6 2015/05/09 15:42:21 christos Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*LINTLIBRARY*/ #include #include #undef strncpy char *__strncpy_chk(char * __restrict, const char * __restrict, size_t, size_t); char * __strncpy_chk(char * __restrict dst, const char * __restrict src, size_t len, size_t slen) { if (len > slen) __chk_fail(); if (__ssp_overlap(src, dst, len)) __chk_fail(); return strncpy(dst, src, len); } picolibc-1.8.11/libc/ssp/vsnprintf_chk.c000066400000000000000000000036031513574234600201420ustar00rootroot00000000000000/* $NetBSD: vsnprintf_chk.c,v 1.5 2008/04/28 20:23:00 martin Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*LINTLIBRARY*/ #include #include #include #include #undef vsnprintf int __vsnprintf_chk(char * __restrict buf, size_t len, int flags, size_t slen, const char * __restrict fmt, va_list ap) { if (len > slen) __chk_fail(); (void)flags; return vsnprintf(buf, len, fmt, ap); } picolibc-1.8.11/libc/ssp/vsprintf_chk.c000066400000000000000000000040521513574234600177630ustar00rootroot00000000000000/* $NetBSD: vsprintf_chk.c,v 1.6 2009/02/05 05:39:38 lukem Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*LINTLIBRARY*/ #include #include #include #include #include #undef vsprintf #undef vsnprintf /*ARGSUSED*/ int __vsprintf_chk(char * __restrict buf, int flags, size_t slen, const char * __restrict fmt, va_list ap) { int rv; (void)flags; if (slen > (size_t)INT_MAX) rv = vsprintf(buf, fmt, ap); else { if ((rv = vsnprintf(buf, slen, fmt, ap)) >= 0 && (size_t)rv >= slen) __chk_fail(); } return rv; } picolibc-1.8.11/libc/stdio/000077500000000000000000000000001513574234600154335ustar00rootroot00000000000000picolibc-1.8.11/libc/stdio/CMakeLists.txt000066400000000000000000000103071513574234600201740ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources( asnprintf.c asprintf.c atold_engine.c atomic_load.c atomic_store.c bufio.c bufio_close.c bufio_close_nf.c bufio_setvbuf.c clearerr.c compare_exchange.c dprintf.c dtox_engine.c ecvt.c ecvtf.c ecvtf_r.c ecvtl.c ecvtl_r.c ecvt_r.c exchange.c fclose.c fcvt.c fcvtf.c fcvtf_r.c fcvtl.c fcvtl_r.c fcvt_r.c fdevopen.c fdopen.c feof.c ferror.c fflush.c fgetc.c fgets.c fgetwc.c fgetws.c fileno.c filestrget.c filestrputalloc.c filestrput.c filewstrget.c flockfile.c fmemopen.c fopen.c fprintf.c fputc.c fputs.c fputwc.c fputws.c fread.c freopen.c fscanf.c fseek.c fseeko.c ftell.c ftello.c ftox_engine.c ftrylockfile.c funlockfile.c funopen.c fwide.c fwprintf.c fwrite.c fwscanf.c gcvt.c gcvtf.c gcvtl.c getchar.c getdelim.c getline.c gets.c getwchar.c ldtoa_engine.c ldtox_engine.c matchcaseprefix.c mktemp.c perror.c printf.c putchar.c puts.c putwchar.c remove.c rewind.c scanf.c setbuf.c setbuffer.c setlinebuf.c setvbuf.c sflags.c snprintf.c snprintfd.c snprintff.c sprintf.c sprintfd.c sprintff.c sscanf.c strfromd.c strfromf.c strfroml.c strtod.c strtod_l.c strtof.c strtof_l.c strtoimax.c strtoimax_l.c strtol.c strtold.c strtold_l.c strtol_l.c strtoll.c strtoll_l.c strtoul.c strtoul_l.c strtoull.c strtoull_l.c strtoumax.c strtoumax_l.c swprintf.c swprintfd.c swscanf.c tmpfile.c tmpnam.c ungetc.c ungetwc.c vasnprintf.c vasprintf.c vdprintf.c vffprintf.c vffscanf.c vfiprintf.c vfiscanf.c vflprintf.c vflscanf.c vfmprintf.c vfmscanf.c vfprintf.c vfscanf.c vfwprintf.c vfwscanf.c vprintf.c vscanf.c vsnprintf.c vsprintf.c vsscanf.c vswprintf.c vswscanf.c vwprintf.c vwscanf.c wcstod.c wcstod_l.c wcstof.c wcstof_l.c wcstoimax.c wcstoimax_l.c wcstol.c wcstold.c wcstold_l.c wcstol_l.c wcstoll.c wcstoll_l.c wcstoul.c wcstoul_l.c wcstoull.c wcstoull_l.c wcstoumax.c wcstoumax_l.c wprintf.c wscanf.c sprintf_s.c vfprintf_s.c vsnprintf_s.c ) if(__IO_FLOAT_EXACT) picolibc_sources( atod_ryu.c atof_ryu.c dtoa_ryu.c ftoa_ryu.c ryu_divpow2.c ryu_log10.c ryu_log2pow5.c ryu_pow5bits.c ryu_table.c ryu_umul128.c ) else() picolibc_sources( atod_engine.c atof_engine.c dtoa_engine.c ftoa_engine.c ) endif() if(POSIX_CONSOLE) picolibc_sources( posixiob_stdin.c posixiob_stdout.c posixiob_stderr.c ) endif() target_include_directories(c PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") picolibc-1.8.11/libc/stdio/asnprintf.c000066400000000000000000000034631513574234600176110ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" char * asnprintf(char *str, size_t *lenp, const char *fmt, ...) { va_list ap; char *ret; va_start(ap, fmt); ret = vasnprintf(str, lenp, fmt, ap); va_end(ap); return ret; } picolibc-1.8.11/libc/stdio/asprintf.c000066400000000000000000000041631513574234600174310ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int __disable_sanitizer asprintf(char **strp, const char *fmt, ...) { va_list ap; struct __file_str f = FDEV_SETUP_STRING_ALLOC(); int i; va_start(ap, fmt); i = vfprintf(&f.file, fmt, ap); va_end(ap); char *buf = POINTER_MINUS(f.end, f.size); if (i >= 0) { char *s = realloc(buf, i + 1); if (s) { s[i] = 0; *strp = s; } else { i = EOF; } } if (i < 0) free(buf); return i; } picolibc-1.8.11/libc/stdio/atod_engine.c000066400000000000000000000042601513574234600200550ustar00rootroot00000000000000/* Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2008 Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #ifdef FLOAT64 #define _NEED_IO_DOUBLE #include "dtoa.h" #if __GNUC__ == 12 && __GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ == 1 && __OPTIMIZE_SIZE__ /* * GCC 12.2.1 has a bug in -Os mode on (at least) arm v8.1-m which * mis-compiles this function resulting in an infinite loop. Work * around that by switching optimization mode */ #pragma GCC optimize("O2") #endif FLOAT64 __atod_engine(uint64_t u64, int exp) { FLOAT64 flt = u64; while (exp < 0) { flt *= 1e-1; exp++; } while (exp > 0) { flt *= 1e1; exp--; } return flt; } #endif picolibc-1.8.11/libc/stdio/atod_ryu.c000066400000000000000000000143261513574234600174330ustar00rootroot00000000000000// Copyright 2019 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. #include "stdio_private.h" #ifdef RYU_DEBUG #include #endif #include "ryu/common.h" #include "ryu/d2s_intrinsics.h" #if __SIZEOF_DOUBLE__ == 8 #define FLOAT64 double #elif __SIZEOF_LONG_DOUBLE__ == 8 #define FLOAT64 long double #endif #ifdef FLOAT64 #define DOUBLE_MANTISSA_BITS 52 #define DOUBLE_EXPONENT_BITS 11 #define DOUBLE_EXPONENT_BIAS 1023 #if defined(_MSC_VER) #include static inline uint32_t floor_log2(const uint64_t value) { long index; return _BitScanReverse64(&index, value) ? index : 64; } #else static inline uint32_t floor_log2(const uint64_t value) { return 63 - __builtin_clzll(value); } #endif // The max function is already defined on Windows. static inline int32_t max32(int32_t a, int32_t b) { return a < b ? b : a; } static inline FLOAT64 int64Bits2Double(uint64_t bits) { FLOAT64 f; memcpy(&f, &bits, sizeof(FLOAT64)); return f; } FLOAT64 __atod_engine(uint64_t m10, int e10) { #ifdef RYU_DEBUG printf("m10 = %lu\n", m10); printf("e10 = %d\n", e10); printf("m10 * 10^e10 = %" PRIu64 " * 10^%d\n", m10, e10); #endif #define signedM 0 #define RYU_OPTIMIZE_SIZE // Convert to binary float m2 * 2^e2, while retaining information about whether the conversion // was exact (trailingZeros). int32_t e2; uint64_t m2; bool trailingZeros; if (e10 >= 0) { // The length of m * 10^e in bits is: // log2(m10 * 10^e10) = log2(m10) + e10 log2(10) = log2(m10) + e10 + e10 * log2(5) // // We want to compute the DOUBLE_MANTISSA_BITS + 1 top-most bits (+1 for the implicit // leading one in IEEE format). We therefore choose a binary output exponent of // log2(m10 * 10^e10) - (DOUBLE_MANTISSA_BITS + 1). // // We use floor(log2(5^e10)) so that we get at least this many bits; better to // have an additional bit than to not have enough bits. e2 = floor_log2(m10) + e10 + log2pow5(e10) - (DOUBLE_MANTISSA_BITS + 1); // We now compute [m10 * 10^e10 / 2^e2] = [m10 * 5^e10 / 2^(e2-e10)]. // To that end, we use the DOUBLE_POW5_SPLIT table. int j = e2 - e10 - ceil_log2pow5(e10) + DOUBLE_POW5_BITCOUNT; assert(j >= 0); #if defined(RYU_OPTIMIZE_SIZE) uint64_t pow5[2]; __double_computePow5(e10, pow5); m2 = mulShift64(m10, pow5, j); #else assert(e10 < DOUBLE_POW5_TABLE_SIZE); m2 = mulShift64(m10, DOUBLE_POW5_SPLIT[e10], j); #endif // We also compute if the result is exact, i.e., // [m10 * 10^e10 / 2^e2] == m10 * 10^e10 / 2^e2. // This can only be the case if 2^e2 divides m10 * 10^e10, which in turn requires that the // largest power of 2 that divides m10 + e10 is greater than e2. If e2 is less than e10, // then the result must be exact. Otherwise we use the existing multipleOfPowerOf2 function. trailingZeros = e2 < e10 || (e2 - e10 < 64 && multipleOfPowerOf2(m10, e2 - e10)); } else { e2 = floor_log2(m10) + e10 - ceil_log2pow5(-e10) - (DOUBLE_MANTISSA_BITS + 1); int j = e2 - e10 + ceil_log2pow5(-e10) - 1 + DOUBLE_POW5_INV_BITCOUNT; #if defined(RYU_OPTIMIZE_SIZE) uint64_t pow5[2]; __double_computeInvPow5(-e10, pow5); m2 = mulShift64(m10, pow5, j); #else assert(-e10 < DOUBLE_POW5_INV_TABLE_SIZE); m2 = mulShift64(m10, DOUBLE_POW5_INV_SPLIT[-e10], j); #endif trailingZeros = multipleOfPowerOf5(m10, -e10); } #ifdef RYU_DEBUG printf("m2 * 2^e2 = 0x%" PRIx64 " * 2^%d\n", m2, e2); #endif // Compute the final IEEE exponent. uint32_t ieee_e2 = (uint32_t)max32(0, e2 + DOUBLE_EXPONENT_BIAS + floor_log2(m2)); if (ieee_e2 > 0x7fe) { // Final IEEE exponent is larger than the maximum representable; return +/-Infinity. uint64_t ieee = (((uint64_t)signedM) << (DOUBLE_EXPONENT_BITS + DOUBLE_MANTISSA_BITS)) | (0x7ffull << DOUBLE_MANTISSA_BITS); return int64Bits2Double(ieee); } // We need to figure out how much we need to shift m2. The tricky part is that we need to take // the final IEEE exponent into account, so we need to reverse the bias and also special-case // the value 0. int32_t shift = (ieee_e2 == 0 ? 1 : ieee_e2) - e2 - DOUBLE_EXPONENT_BIAS - DOUBLE_MANTISSA_BITS; assert(shift >= 0); #ifdef RYU_DEBUG printf("ieee_e2 = %d\n", ieee_e2); printf("shift = %d\n", shift); #endif // We need to round up if the exact value is more than 0.5 above the value we computed. That's // equivalent to checking if the last removed bit was 1 and either the value was not just // trailing zeros or the result would otherwise be odd. // // We need to update trailingZeros given that we have the exact output exponent ieee_e2 now. trailingZeros &= (m2 & ((1ull << (shift - 1)) - 1)) == 0; uint64_t lastRemovedBit = (m2 >> (shift - 1)) & 1; bool roundUp = (lastRemovedBit != 0) && (!trailingZeros || (((m2 >> shift) & 1) != 0)); #ifdef RYU_DEBUG printf("roundUp = %d\n", roundUp); printf("ieee_m2 = 0x%" PRIx64 "\n", (m2 >> shift) + roundUp); #endif uint64_t ieee_m2 = (m2 >> shift) + roundUp; assert(ieee_m2 <= (1ull << (DOUBLE_MANTISSA_BITS + 1))); ieee_m2 &= (1ull << DOUBLE_MANTISSA_BITS) - 1; if (ieee_m2 == 0 && roundUp) { // Due to how the IEEE represents +/-Infinity, we don't need to check for overflow here. ieee_e2++; } uint64_t ieee = (((((uint64_t)signedM) << DOUBLE_EXPONENT_BITS) | (uint64_t)ieee_e2) << DOUBLE_MANTISSA_BITS) | ieee_m2; return int64Bits2Double(ieee); } #endif /* FLOAT64 */ picolibc-1.8.11/libc/stdio/atof_engine.c000066400000000000000000000042071513574234600200600ustar00rootroot00000000000000/* Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2008 Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _NEED_IO_FLOAT #include "dtoa.h" #if __GNUC__ == 12 && __GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ == 1 && __OPTIMIZE_SIZE__ /* * GCC 12.2.1 has a bug in -Os mode on (at least) arm v8.1-m which * mis-compiles this function resulting in an infinite loop. Work * around that by switching optimization mode */ #pragma GCC optimize("O2") #endif float __atof_engine(uint32_t u32, int exp) { float flt = u32; while (exp < 0) { flt *= (float)1e-1f; exp++; } while (exp > 0) { flt *= (float)1e1f; exp--; } return flt; } picolibc-1.8.11/libc/stdio/atof_ryu.c000066400000000000000000000151211513574234600174270ustar00rootroot00000000000000// Copyright 2019 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. #include "stdio_private.h" #ifdef RYU_DEBUG #include #endif #include "ryu/common.h" #include "ryu/f2s_intrinsics.h" #define FLOAT_MANTISSA_BITS 23 #define FLOAT_EXPONENT_BITS 8 #define FLOAT_EXPONENT_BIAS 127 #if defined(_MSC_VER) #include static inline uint32_t floor_log2(const uint32_t value) { uint32_t index; return _BitScanReverse(&index, value) ? index : 32; } #else static inline uint32_t floor_log2(const uint32_t value) { #if __SIZEOF_INT__ >= 4 return 31 - __builtin_clz(value); #elif __SIZEOF_INT__ < 4 && __SIZEOF_LONG__ >= 4 return 31 - __builtin_clzl(value); #else #error no usable clz #endif } #endif // The max function is already defined on Windows. static inline int32_t max32(int32_t a, int32_t b) { return a < b ? b : a; } static inline float int32Bits2Float(uint32_t bits) { float f; memcpy(&f, &bits, sizeof(float)); return f; } float __atof_engine(uint32_t m10, int e10) { #ifdef RYU_DEBUG printf("m10digits = %ld\n", m10); printf("e10digits = %d\n", e10); printf("m10 * 10^e10 = %lu * 10^%d\n", m10, e10); #endif #define signedM 0 // Convert to binary float m2 * 2^e2, while retaining information about whether the conversion // was exact (trailingZeros). int32_t e2; uint32_t m2; bool trailingZeros; if (e10 >= 0) { // The length of m * 10^e in bits is: // log2(m10 * 10^e10) = log2(m10) + e10 log2(10) = log2(m10) + e10 + e10 * log2(5) // // We want to compute the FLOAT_MANTISSA_BITS + 1 top-most bits (+1 for the implicit leading // one in IEEE format). We therefore choose a binary output exponent of // log2(m10 * 10^e10) - (FLOAT_MANTISSA_BITS + 1). // // We use floor(log2(5^e10)) so that we get at least this many bits; better to // have an additional bit than to not have enough bits. e2 = floor_log2(m10) + e10 + log2pow5(e10) - (FLOAT_MANTISSA_BITS + 1); // We now compute [m10 * 10^e10 / 2^e2] = [m10 * 5^e10 / 2^(e2-e10)]. // To that end, we use the FLOAT_POW5_SPLIT table. int j = e2 - e10 - ceil_log2pow5(e10) + FLOAT_POW5_BITCOUNT; assert(j >= 0); m2 = mulPow5divPow2(m10, e10, j); // We also compute if the result is exact, i.e., // [m10 * 10^e10 / 2^e2] == m10 * 10^e10 / 2^e2. // This can only be the case if 2^e2 divides m10 * 10^e10, which in turn requires that the // largest power of 2 that divides m10 + e10 is greater than e2. If e2 is less than e10, // then the result must be exact. Otherwise we use the existing multipleOfPowerOf2 function. trailingZeros = e2 < e10 || (e2 - e10 < 32 && multipleOfPowerOf2_32(m10, e2 - e10)); } else { e2 = floor_log2(m10) + e10 - ceil_log2pow5(-e10) - (FLOAT_MANTISSA_BITS + 1); // We now compute [m10 * 10^e10 / 2^e2] = [m10 / (5^(-e10) 2^(e2-e10))]. int j = e2 - e10 + ceil_log2pow5(-e10) - 1 + FLOAT_POW5_INV_BITCOUNT; m2 = mulPow5InvDivPow2(m10, -e10, j); // We also compute if the result is exact, i.e., // [m10 / (5^(-e10) 2^(e2-e10))] == m10 / (5^(-e10) 2^(e2-e10)) // // If e2-e10 >= 0, we need to check whether (5^(-e10) 2^(e2-e10)) divides m10, which is the // case iff pow5(m10) >= -e10 AND pow2(m10) >= e2-e10. // // If e2-e10 < 0, we have actually computed [m10 * 2^(e10 e2) / 5^(-e10)] above, // and we need to check whether 5^(-e10) divides (m10 * 2^(e10-e2)), which is the case iff // pow5(m10 * 2^(e10-e2)) = pow5(m10) >= -e10. trailingZeros = (e2 < e10 || (e2 - e10 < 32 && multipleOfPowerOf2_32(m10, e2 - e10))) && multipleOfPowerOf5_32(m10, -e10); } #ifdef RYU_DEBUG printf("m2 * 2^e2 = %lu * 2^%d\n", m2, e2); #endif // Compute the final IEEE exponent. uint32_t ieee_e2 = (uint32_t)max32(0, e2 + FLOAT_EXPONENT_BIAS + floor_log2(m2)); if (ieee_e2 > 0xfe) { // Final IEEE exponent is larger than the maximum representable; return +/-Infinity. uint32_t ieee = (((uint32_t)signedM) << (FLOAT_EXPONENT_BITS + FLOAT_MANTISSA_BITS)) | ((uint32_t)0xffu << FLOAT_MANTISSA_BITS); return int32Bits2Float(ieee); } // We need to figure out how much we need to shift m2. The tricky part is that we need to take // the final IEEE exponent into account, so we need to reverse the bias and also special-case // the value 0. int32_t shift = (ieee_e2 == 0 ? 1 : ieee_e2) - e2 - FLOAT_EXPONENT_BIAS - FLOAT_MANTISSA_BITS; assert(shift >= 0); #ifdef RYU_DEBUG printf("ieee_e2 = %ld\n", ieee_e2); printf("shift = %ld\n", shift); #endif // We need to round up if the exact value is more than 0.5 above the value we computed. That's // equivalent to checking if the last removed bit was 1 and either the value was not just // trailing zeros or the result would otherwise be odd. // // We need to update trailingZeros given that we have the exact output exponent ieee_e2 now. trailingZeros &= (m2 & (((uint32_t)1u << (shift - 1)) - 1)) == 0; uint32_t lastRemovedBit = (m2 >> (shift - 1)) & 1; bool roundUp = (lastRemovedBit != 0) && (!trailingZeros || (((m2 >> shift) & 1) != 0)); #ifdef RYU_DEBUG printf("roundUp = %d\n", roundUp); printf("ieee_m2 = %lu\n", (m2 >> shift) + roundUp); #endif uint32_t ieee_m2 = (m2 >> shift) + roundUp; assert(ieee_m2 <= ((uint32_t)1u << (FLOAT_MANTISSA_BITS + 1))); ieee_m2 &= ((uint32_t)1u << FLOAT_MANTISSA_BITS) - 1; if (ieee_m2 == 0 && roundUp) { // Rounding up may overflow the mantissa. // In this case we move a trailing zero of the mantissa into the exponent. // Due to how the IEEE represents +/-Infinity, we don't need to check for overflow here. ieee_e2++; } uint32_t ieee = (((((uint32_t)signedM) << FLOAT_EXPONENT_BITS) | (uint32_t)ieee_e2) << FLOAT_MANTISSA_BITS) | ieee_m2; return int32Bits2Float(ieee); } picolibc-1.8.11/libc/stdio/atold_engine.c000066400000000000000000000074711513574234600202400ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2021 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #include #if __LDBL_MAX_10_EXP__ >= 4096 #define NPOW_10 13 #elif __LDBL_MAX_10_EXP__ >= 2048 #define NPOW_10 12 #elif __LDBL_MAX_10_EXP__ >= 1024 #define NPOW_10 11 #elif __LDBL_MAX_10_EXP__ >= 512 #define NPOW_10 10 #elif __LDBL_MAX_10_EXP__ >= 256 #define NPOW_10 9 #elif __LDBL_MAX_10_EXP__ >= 128 #define NPOW_10 8 #elif __LDBL_MAX_10_EXP__ >= 64 #define NPOW_10 7 #elif __LDBL_MAX_10_EXP__ >= 32 #define NPOW_10 6 #else #error __LDBL_MAX_10_EXP__ too small #endif static const long double pwr_p10[NPOW_10] = { 1e+1L, 1e+2L, 1e+4L, 1e+8L, 1e+16L, 1e+32L, #if NPOW_10 >= 7 1e+64L, #endif #if NPOW_10 >= 8 1e+128L, #endif #if NPOW_10 >= 9 1e+256L, #endif #if NPOW_10 >= 10 1e+512L, #endif #if NPOW_10 >= 11 1e+1024L, #endif #if NPOW_10 >= 12 1e+2048L, #endif #if NPOW_10 >= 13 1e+4096L #endif }; static const long double pwr_m10[NPOW_10] = { 1e-1L, 1e-2L, 1e-4L, 1e-8L, 1e-16L, 1e-32L, #if NPOW_10 >= 7 1e-64L, #endif #if NPOW_10 >= 8 1e-128L, #endif #if NPOW_10 >= 9 1e-256L, #endif #if NPOW_10 >= 10 1e-512L, #endif #if NPOW_10 >= 11 1e-1024L, #endif #if NPOW_10 >= 12 1e-2048L, #endif #if NPOW_10 >= 13 1e-4096L #endif }; long double __atold_engine(_u128 m10, int e10) { long double flt = _u128_to_ld(m10); int pwr; const long double *pptr; if (e10 < 0) { pptr = (pwr_m10 + NPOW_10 - 1); e10 = -e10; } else { pptr = (pwr_p10 + NPOW_10 - 1); } for (pwr = 1 << (NPOW_10 - 1); pwr; pwr >>= 1) { for (; e10 >= pwr; e10 -= pwr) { flt *= *pptr; } pptr--; } return flt; } picolibc-1.8.11/libc/stdio/atomic_load.c000066400000000000000000000036061513574234600200570ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #if defined(__ATOMIC_UNGETC) && !defined(PICOLIBC_HAVE_SYNC_COMPARE_AND_SWAP) __ungetc_t __picolibc_non_atomic_load_ungetc(const volatile __ungetc_t *p) { return __non_atomic_load_ungetc(p); } __weak_reference(__picolibc_non_atomic_load_ungetc, __atomic_load_ungetc); #endif picolibc-1.8.11/libc/stdio/atomic_store.c000066400000000000000000000035771513574234600203030ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2026 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #if defined(__ATOMIC_UNGETC) && !defined(PICOLIBC_HAVE_SYNC_COMPARE_AND_SWAP) void __picolibc_non_atomic_store_ungetc(__ungetc_t *p, __ungetc_t v) { __non_atomic_store_ungetc(p, v); } __weak_reference(__picolibc_non_atomic_store_ungetc, __atomic_store_ungetc); #endif picolibc-1.8.11/libc/stdio/bufio.c000066400000000000000000000147171513574234600167150ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #ifdef __STDIO_BUFIO_LOCKING void __bufio_lock_init(FILE *f) { struct __file_bufio *bf = (struct __file_bufio *)f; __LIBC_LOCK(); if (!bf->lock) __lock_init(bf->lock); __LIBC_UNLOCK(); } #endif int __bufio_flush_locked(FILE *f) { struct __file_bufio *bf = (struct __file_bufio *)f; char *buf; off_t backup; switch (bf->dir) { case __SWR: /* Flush everything, drop contents if that doesn't work */ buf = bf->buf; while (bf->len) { ssize_t this = bufio_write(bf, buf, bf->len); if (this <= 0) { bf->len = 0; return _FDEV_ERR; break; } buf += this; bf->pos += this; bf->len -= this; } break; case __SRD: /* Move the FD back to the current read position */ backup = bf->len - bf->off; if (backup) { bf->pos -= backup; (void)bufio_lseek(bf, bf->pos, SEEK_SET); } bf->len = 0; bf->off = 0; break; default: break; } return 0; } int __bufio_fill_locked(FILE *f) { struct __file_bufio *bf = (struct __file_bufio *)f; ssize_t len; /* Reset read pointer, read some data */ bf->off = 0; len = bufio_read(bf, bf->buf, bf->size); if (len <= 0) { bf->len = 0; if (len < 0) return _FDEV_ERR; else return _FDEV_EOF; } /* Update FD pos */ bf->len = len; bf->pos += len; return 0; } int __bufio_flush(FILE *f) { int ret; __bufio_lock(f); ret = __bufio_flush_locked(f); __bufio_unlock(f); return ret; } /* Set I/O direction, flushing when it changes */ int __bufio_setdir_locked(FILE *f, uint8_t dir) { struct __file_bufio *bf = (struct __file_bufio *)f; int ret = 0; if (bf->dir != dir) { ret = __bufio_flush_locked(f); bf->dir = dir; } return ret; } int __bufio_put(char c, FILE *f) { struct __file_bufio *bf = (struct __file_bufio *)f; int ret = (unsigned char)c; __bufio_lock(f); if (__bufio_setdir_locked(f, __SWR) < 0) { ret = _FDEV_ERR; goto bail; } bf->buf[bf->len++] = c; /* flush if full, or if sending newline when linebuffered */ if (bf->len >= bf->size || (c == '\n' && (bf->bflags & __BLBF))) if (__bufio_flush_locked(f) < 0) ret = _FDEV_ERR; bail: __bufio_unlock(f); return ret; } extern FILE * const stdin __weak; extern FILE * const stdout __weak; int __bufio_get(FILE *f) { struct __file_bufio *bf = (struct __file_bufio *)f; int ret; bool flushed = false; again: __bufio_lock(f); if (__bufio_setdir_locked(f, __SRD) < 0) { ret = _FDEV_ERR; goto bail; } if (bf->off >= bf->len) { /* * Flush stdout if reading from stdin. * * The odd-looking NULL address checks along with the * weak attributes for stdin and stdout above avoids * pulling in stdin/stdout definitions just for this * check. */ if (!flushed) { flushed = true; if (&stdin != NULL && &stdout != NULL && f == stdin) { __bufio_unlock(f); fflush(stdout); goto again; } } ret = __bufio_fill_locked(f); if (ret) goto bail; } /* * Cast to unsigned avoids sign-extending chars with high-bit * set */ ret = (unsigned char)bf->buf[bf->off++]; bail: __bufio_unlock(f); return ret; } off_t __bufio_seek(FILE *f, off_t offset, int whence) { struct __file_bufio *bf = (struct __file_bufio *)f; off_t ret; __bufio_lock(f); if (__bufio_setdir_locked(f, __SRD) < 0) { ret = _FDEV_ERR; } else { /* compute offset of the first char in the buffer */ __off_t buf_pos = bf->pos - bf->len; switch (whence) { case SEEK_CUR: /* Map CUR -> SET, accounting for position within buffer */ whence = SEEK_SET; offset += buf_pos + bf->off; __fallthrough; case SEEK_SET: /* Optimize for seeks within buffer or just past buffer */ if (buf_pos <= offset && offset <= buf_pos + bf->len) { bf->off = offset - buf_pos; ret = offset; break; } __fallthrough; default: ret = bufio_lseek(bf, offset, whence); if (ret >= 0) bf->pos = ret; /* Flush any buffered data after a real seek */ bf->len = 0; bf->off = 0; break; } } __bufio_unlock(f); return ret; } picolibc-1.8.11/libc/stdio/bufio_close.c000066400000000000000000000042261513574234600200740ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2026 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int __bufio_close(FILE *f) { struct __file_bufio *bf = (struct __file_bufio *)f; int ret = 0; __bufio_lock(f); ret = __bufio_flush_locked(f); if (bf->bflags & __BALL) free(bf->buf); __bufio_lock_close(f); /* * Don't close the fd or free the FILE for things not * generated by fopen or fdopen. These will usually be static * FILE structs defined for stdin/stdout/stderr. */ if (bf->bflags & __BFALL) { ret = bufio_close(bf); free(f); } return ret; } picolibc-1.8.11/libc/stdio/bufio_close_nf.c000066400000000000000000000035221513574234600205550ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2026 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" /* This function is used when the file has neither __BALL nor __BFALL set */ int __bufio_close_nf(FILE *f) { int ret = 0; __bufio_lock(f); ret = __bufio_flush_locked(f); __bufio_lock_close(f); return ret; } picolibc-1.8.11/libc/stdio/bufio_setvbuf.c000066400000000000000000000055211513574234600204440ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2026 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int __bufio_setvbuf(FILE *f, char *buf, int mode, size_t size) { struct __file_bufio *bf = (struct __file_bufio *)f; int ret = -1; __bufio_lock(f); if (__bufio_flush_locked(f) < 0) { ret = _FDEV_ERR; goto bail; } bf->bflags &= ~__BLBF; switch (mode) { case _IONBF: buf = NULL; size = 1; break; case _IOLBF: bf->bflags |= __BLBF; break; case _IOFBF: break; default: goto bail; } if (bf->bflags & __BALL) { if (buf) { free(bf->buf); bf->bflags &= ~__BALL; } else { /* * Handling allocation failures here is a bit tricky; * we don't want to lose the existing buffer. Instead, * we try to reallocate it */ buf = realloc(bf->buf, size); if (!buf) goto bail; } } else if (!buf) { buf = malloc(size); if (!buf) goto bail; bf->bflags |= __BALL; } if (bf->bflags & __BALL) bf->xfile.cfile.close = __bufio_close; bf->buf = buf; bf->size = size; ret = 0; bail: __bufio_unlock(f); return ret; } picolibc-1.8.11/libc/stdio/clearerr.c000066400000000000000000000040531513574234600174000ustar00rootroot00000000000000/* Copyright (c) 2002,2005 Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: clearerr.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" #undef clearerr #undef clearerr_unlocked void __STDIO_UNLOCKED(clearerr)(FILE *stream) { stream->flags &= ~(__SERR | __SEOF); } #if defined(__STDIO_LOCKING) void clearerr(FILE *stream) { __flockfile(stream); clearerr_unlocked(stream); __funlockfile(stream); } #else #ifdef __strong_reference __strong_reference(clearerr, clearerr_unlocked); #else void clearerr_unlocked(FILE *stream) { return clearerr(stream); } #endif #endif picolibc-1.8.11/libc/stdio/compare_exchange.c000066400000000000000000000040431513574234600210700ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #if defined(__ATOMIC_UNGETC) && !defined(PICOLIBC_HAVE_SYNC_COMPARE_AND_SWAP) /* Provide a non-atomic emulation and let the application replace it * with a real version */ bool __picolibc_non_atomic_compare_exchange_ungetc(__ungetc_t *p, __ungetc_t d, __ungetc_t v) { return __non_atomic_compare_exchange_ungetc(p, d, v); } __weak_reference(__picolibc_non_atomic_compare_exchange_ungetc, __atomic_compare_exchange_ungetc); #endif picolibc-1.8.11/libc/stdio/conv_flt.c000066400000000000000000000476671513574234600174350ustar00rootroot00000000000000/* Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2008 Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef CHAR #ifdef WIDE_CHARS #define CHAR wchar_t #define INT wint_t #if __SIZEOF_WCHAR_T__ == 2 #define UCHAR uint16_t #elif __SIZEOF_WCHAR_T__ == 4 #define UCHAR uint32_t #endif #define CQ(a) L##a #define MY_EOF WEOF #define IS_EOF(c) ((c) == WEOF) #define ISSPACE(c) iswspace(c) #define ISALNUM(c) iswalnum(c) #else #define CHAR char #define UCHAR unsigned char #define INT int #define CQ(a) a #define MY_EOF EOF #define IS_EOF(c) ((c) < 0) #define ISSPACE(c) isspace(c) #define ISALNUM(c) isalnum(c) #endif #endif static const CHAR pstr_nfinity[] = CQ("nfinity"); static const CHAR pstr_an[] = CQ("an"); #if defined(STRTOD) || defined(STRTOF) || defined(STRTOLD) #define CHECK_WIDTH() 1 #define CHECK_RANGE(flt) \ do { \ int __class = fpclassify(flt); \ if (__class == FP_INFINITE || __class == FP_SUBNORMAL || __class == FP_ZERO) \ errno = ERANGE; \ } while (0); #ifdef __IO_C99_FORMATS #define _NEED_IO_C99_FORMATS #endif #if defined(STRTOD) #define _NEED_IO_DOUBLE #define SCANF_VARIANT __IO_VARIANT_DOUBLE #define CHECK_LONG() 1 #define CHECK_LONG_LONG() 0 #elif defined(STRTOLD) #define _NEED_IO_LONG_DOUBLE #define SCANF_VARIANT __IO_VARIANT_DOUBLE #define CHECK_LONG() 0 #define CHECK_LONG_LONG() 1 #elif defined(STRTOF) #define _NEED_IO_FLOAT #define SCANF_VARIANT __IO_VARIANT_FLOAT #define CHECK_LONG() 0 #define CHECK_LONG_LONG() 0 #endif #define FLT_STREAM const CHAR #define FLT_CONTEXT int static inline INT scanf_getc(const CHAR *s, int *lenp) { int l = *lenp; INT c = s[l]; *lenp = l + 1; return c; } static inline void scanf_ungetc(INT c, FLT_STREAM *s, int *lenp) { (void)c; (void)s; --(*lenp); } #undef EOF #define EOF -1 #else #define CHECK_WIDTH() (--width != 0) #define CHECK_RANGE(flt) #ifdef _NEED_IO_FLOAT #define CHECK_LONG() 0 #define CHECK_LONG_LONG() 0 #elif defined(_NEED_IO_DOUBLE) #ifdef _NEED_IO_LONG_DOUBLE #define CHECK_LONG() (flags & FL_LONG) #define CHECK_LONG_LONG() (flags & FL_LONGLONG) #else #define CHECK_LONG() (flags & (FL_LONG | FL_LONGLONG)) #define CHECK_LONG_LONG() 0 #endif #else #define CHECK_LONG() 0 #define CHECK_LONG_LONG() 0 #endif #define FLT_STREAM FILE #define FLT_CONTEXT scanf_context_t #endif #include "scanf_private.h" #include "dtoa.h" #ifdef _NEED_IO_LONG_DOUBLE #define FLOAT long double #define FLOAT_MIN __LDBL_MIN__ #define FLOAT_MANT_DIG __LDBL_MANT_DIG__ #define FLOAT_MAX_EXP __LDBL_MAX_EXP__ #define FLOAT_MIN_EXP __LDBL_MIN_EXP__ #define ASFLOAT(x) aslongdouble(x) #if __SIZEOF_LONG_DOUBLE__ > 8 #define TOFLOAT(x) _u128_to_ld(x) #define UINTFLOAT _u128 #elif __SIZEOF_LONG_DOUBLE__ == 8 #define TOFLOAT(x) ((long double)(x)) #define UINTFLOAT uint64_t #elif __SIZEOF_LONG_DOUBLE__ == 4 #define TOFLOAT(x) ((long double)(x)) #define UINTFLOAT uint32_t #endif #elif defined(_NEED_IO_DOUBLE) #define FLOAT double #define FLOAT_MIN __DBL_MIN__ #define FLOAT_MANT_DIG __DBL_MANT_DIG__ #define FLOAT_MAX_EXP __DBL_MAX_EXP__ #define FLOAT_MIN_EXP __DBL_MIN_EXP__ #define ASFLOAT(x) _asdouble(x) #define TOFLOAT(x) ((double)(x)) #if __SIZEOF_DOUBLE__ == 4 #define UINTFLOAT uint32_t #elif __SIZEOF_DOUBLE__ == 8 #define UINTFLOAT uint64_t #endif #elif defined(_NEED_IO_FLOAT) #define FLOAT float #define FLOAT_MIN __FLT_MIN__ #define FLOAT_MANT_DIG __FLT_MANT_DIG__ #define FLOAT_MAX_EXP __FLT_MAX_EXP__ #define FLOAT_MIN_EXP __FLT_MIN_EXP__ #define ASFLOAT(x) _asfloat(x) #define TOFLOAT(x) ((float)(x)) #define UINTFLOAT uint32_t #endif #if FLOAT_MANT_DIG > 53 #define U32_TO_UF(x) to_u128(x) #define U64_TO_UF(x) to_u128(x) #define U128_TO_UF(x) (x) #define UF_TO_U32(x) from_u128(x) #define UF_TO_U64(x) from_u128(x) #define UF_TO_U128(x) (x) #define UF_IS_ZERO(x) _u128_is_zero(x) #define UF_TIMES_BASE(a, b) _u128_times_base(a, b) #define UF_PLUS_DIGIT(a, b) _u128_plus_64(a, b) #define UF_RSHIFT(a, b) _u128_rshift(a, b) #define UF_LSHIFT(a, b) _u128_lshift(a, b) #define UF_LSHIFT_64(a, b) _u128_lshift_64(a, b) #define UF_LT(a, b) _u128_lt(a, b) #define UF_GE(a, b) _u128_ge(a, b) #define UF_OR_64(a, b) _u128_or_64(a, b) #define UF_AND_64(a, b) _u128_and_64(a, b) #define UF_AND(a, b) _u128_and(a, b) #define UF_NOT(a) _u128_not(a) #define UF_OR(a, b) _u128_or(a, b) #else #define U32_TO_UF(x) (x) #define U64_TO_UF(x) (x) #define U128_TO_UF(x) from_u128(x) #define UF_TO_U32(x) (x) #define UF_TO_U64(x) (x) #define UF_TO_U128(x) to_u128(x) #define UF_IS_ZERO(x) ((x) == 0) #define UF_TIMES_BASE(a, b) ((a) * (b)) #define UF_PLUS_DIGIT(a, b) ((a) + (b)) #define UF_RSHIFT(a, b) ((a) >> (b)) #define UF_LSHIFT(a, b) ((a) << (b)) #define UF_LSHIFT_64(a, b) ((UINTFLOAT)(a) << (b)) #define UF_LT(a, b) ((a) < (b)) #define UF_GE(a, b) ((a) >= (b)) #define UF_OR_64(a, b) ((a) | (b)) #define UF_AND_64(a, b) ((a) & (b)) #define UF_AND(a, b) ((a) & (b)) #define UF_NOT(a) (~(a)) #define UF_OR(a, b) ((a) | (b)) #endif static UCHAR conv_flt(FLT_STREAM *stream, FLT_CONTEXT *context, width_t width, void *addr, uint16_t flags) { UINTFLOAT uint; unsigned int overflow = 0; int uintdigits = 0; FLOAT flt; INT i; const CHAR *p; int exp; i = scanf_getc(stream, context); /* after scanf_ungetc() */ switch (i) { case CQ('-'): flags |= FL_MINUS; __fallthrough; case CQ('+'): if (!CHECK_WIDTH() || IS_EOF(i = (INT)scanf_getc(stream, context))) return 0; } switch (TOLOWER(i)) { case CQ('n'): p = pstr_an; flt = (FLOAT)NAN; goto operate_pstr; case CQ('i'): p = pstr_nfinity; flt = (FLOAT)INFINITY; operate_pstr: { UCHAR c; while ((c = *p++) != 0) { if (CHECK_WIDTH()) { if (!IS_EOF(i = scanf_getc(stream, context))) { if (TOLOWER(i) == (INT)c) continue; scanf_ungetc(i, stream, context); } } if (p == pstr_nfinity + 3) break; return 0; } if (isnan(flt)) { if (CHECK_WIDTH()) { if ((i = scanf_getc(stream, context)) == CQ('(')) { while (CHECK_WIDTH() && (i = scanf_getc(stream, context)) != CQ(')')) { if (ISALNUM(i) || i == CQ('_')) continue; else break; } if (i != CQ(')')) return 0; } else { scanf_ungetc(i, stream, context); } } } } break; default: exp = 0; uint = U32_TO_UF(0); #define uintdigitsmax_10_float 8 #define uintdigitsmax_16_float 7 #if __SIZEOF_DOUBLE__ == 8 #define uintdigitsmax_10_double 16 #define uintdigitsmax_16_double 15 #elif __SIZEOF_DOUBLE__ == 4 #define uintdigitsmax_10_double 8 #define uintdigitsmax_16_double 7 #endif #if __SIZEOF_LONG_DOUBLE__ > 8 #define uintdigitsmax_10_long_double 32 #define uintdigitsmax_16_long_double 30 #elif __SIZEOF_LONG_DOUBLE__ == 8 #define uintdigitsmax_10_long_double 16 #define uintdigitsmax_16_long_double 15 #elif __SIZEOF_LONG_DOUBLE__ == 4 #define uintdigitsmax_10_long_double 8 #define uintdigitsmax_16_long_double 7 #endif #ifdef _NEED_IO_C99_FORMATS UCHAR base = 10; #else #define base 10 #endif #define uintdigitsmax \ ((base) == 10 \ ? (CHECK_LONG_LONG() ? uintdigitsmax_10_long_double \ : (CHECK_LONG() ? uintdigitsmax_10_double : uintdigitsmax_10_float)) \ : (CHECK_LONG_LONG() \ ? uintdigitsmax_16_long_double \ : (CHECK_LONG() ? uintdigitsmax_16_double : uintdigitsmax_16_float))) do { UCHAR c; #ifdef _NEED_IO_C99_FORMATS if ((flags & FL_FHEX) && (c = TOLOWER(i) - CQ('a')) <= 5) c += 10; else #endif c = i - CQ('0'); if (c < base) { flags |= FL_ANY; if (!(flags & FL_OVFL) && uintdigits > uintdigitsmax) { flags |= FL_OVFL; if (base == 10) { /* Check if overflow is >= 0.5 */ if (c >= 5) { overflow = 2; /* Check if overflow might be == 0.5 */ if (c == 5) c = 0; } } } if (flags & FL_OVFL) { overflow |= (c != 0); if (!(flags & FL_DOT)) exp += 1; } else { if (flags & FL_DOT) exp -= 1; uint = UF_PLUS_DIGIT(UF_TIMES_BASE(uint, base), c); if (!UF_IS_ZERO(uint)) uintdigits++; } } else if (c == (UCHAR)((CQ('.') - CQ('0'))) && !(flags & FL_DOT)) { flags |= FL_DOT; #ifdef _NEED_IO_C99_FORMATS } else if (TOLOWER(i) == CQ('x') && (flags & FL_ANY) && UF_IS_ZERO(uint)) { flags |= FL_FHEX; base = 16; #endif } else { break; } } while (CHECK_WIDTH() && !IS_EOF(i = scanf_getc(stream, context))); if (!(flags & FL_ANY)) return 0; #ifdef _NEED_IO_C99_FORMATS INT exp_match = CQ('e'); if (flags & FL_FHEX) { exp_match = CQ('p'); exp *= 4; } #else #define exp_match CQ('e') #endif if (TOLOWER(i) == (INT)exp_match) { int esign, edig; int expacc; if (!CHECK_WIDTH()) goto no_exp; esign = scanf_getc(stream, context); switch (esign) { case CQ('-'): flags |= FL_MEXP; __fallthrough; case CQ('+'): if (!CHECK_WIDTH()) { scanf_ungetc(esign, stream, context); goto no_exp; } edig = scanf_getc(stream, context); /* test EOF will below */ break; default: edig = esign; esign = EOF; break; } if (!isdigit(edig)) { scanf_ungetc(edig, stream, context); if (esign != EOF) scanf_ungetc(esign, stream, context); goto no_exp; } i = edig; expacc = 0; #define MAX_POSSIBLE_EXP (FLOAT_MAX_EXP + FLOAT_MANT_DIG * 4) do { if (expacc < MAX_POSSIBLE_EXP) expacc = expacc * 10 + (i - CQ('0')); } while (CHECK_WIDTH() && isdigit(i = scanf_getc(stream, context))); if (flags & FL_MEXP) expacc = -expacc; exp += expacc; } no_exp: if (width) scanf_ungetc(i, stream, context); if (UF_IS_ZERO(uint)) { flt = (FLOAT)0; break; } #ifdef _NEED_IO_C99_FORMATS if (flags & FL_FHEX) { int sig_bits; int min_exp; if (CHECK_LONG_LONG()) { sig_bits = __LDBL_MANT_DIG__; min_exp = __LDBL_MIN_EXP__ - 1; } else if (CHECK_LONG()) { sig_bits = __DBL_MANT_DIG__; min_exp = __DBL_MIN_EXP__ - 1; } else { sig_bits = __FLT_MANT_DIG__; min_exp = __FLT_MIN_EXP__ - 1; } /* We're using two guard bits, one for the * 'half' value and the second to indicate whether * there is any non-zero value beyond that */ exp += (sig_bits + 2 - 1); /* Make significand larger than 1.0 */ while (UF_LT(uint, UF_LSHIFT_64(1, (sig_bits + 2 - 1)))) { uint = UF_LSHIFT(uint, 1); exp--; } /* Now shift right until the exponent is in range and the * value is less than 2.0. Capture any value > 0.5 in the * LSB of uint. This may generate a denorm. */ while (UF_GE(uint, UF_LSHIFT_64(1, (sig_bits + 2))) || exp < min_exp) { /* squash extra bits into the second guard bit */ uint = UF_OR_64(UF_RSHIFT(uint, 1), UF_AND_64(uint, 1)); exp++; } /* Mix in the overflow bit computed while scanning the * string */ uint = UF_OR_64(uint, overflow); /* Round even */ if (UF_AND_64(uint, 3) == 3 || UF_AND_64(uint, 6) == 6) { uint = UF_PLUS_DIGIT(uint, 4); if (UF_GE(uint, UF_LSHIFT_64(1, FLOAT_MANT_DIG + 2))) { uint = UF_RSHIFT(uint, 1); exp++; } } /* remove guard bits */ uint = UF_RSHIFT(uint, 2); /* align from target to FLOAT */ uint = UF_LSHIFT(uint, FLOAT_MANT_DIG - sig_bits); if (min_exp != (FLOAT_MIN_EXP - 1)) { /* Convert from target denorm to FLOAT value */ while (UF_LT(uint, UF_LSHIFT_64(1, (FLOAT_MANT_DIG - 1))) && exp > FLOAT_MIN_EXP) { uint = UF_LSHIFT(uint, 1); exp--; } } if (exp >= FLOAT_MAX_EXP) { flt = (FLOAT)INFINITY; } else { #if FLOAT_MANT_DIG <= 53 || __LDBL_IS_IEC_60559__ != 0 || defined(__m68k__) if (UF_LT(uint, UF_LSHIFT_64(1, (FLOAT_MANT_DIG - 1)))) { exp = 0; } else { exp += (FLOAT_MAX_EXP - 1); #if FLOAT_MANT_DIG > 53 && (defined(__x86_64__) || defined(__i386__)) /* * Intel 80-bit format is weird -- there's an * integer bit so denorms can have the 'real' * exponent value. That means we don't mask off * the integer bit */ #define EXP_SHIFT FLOAT_MANT_DIG #elif FLOAT_MANT_DIG > 53 && defined(__m68k__) #define EXP_SHIFT FLOAT_MANT_DIG + 16 #else uint = UF_AND(uint, UF_NOT(UF_LSHIFT_64(1, (FLOAT_MANT_DIG - 1)))); #define EXP_SHIFT (FLOAT_MANT_DIG - 1) #endif } uint = UF_OR(uint, UF_LSHIFT_64(exp, EXP_SHIFT)); flt = ASFLOAT(uint); #else /* FLOAT_MANT_DIG <= 53 || __LDBL_IS_IEC_60559__ != 0 */ flt = scalbnl(TOFLOAT(uint), exp - (FLOAT_MANT_DIG - 1)); #endif CHECK_RANGE(flt); } } else #endif { /* * Mix in overflow. Overflow has four possible values: * * 0: overflow == 0 * 1: overflow < 0.5 * 2: overflow == 0.5 * 3: overflow > 0.5 * * We want to increment in case 2 if uint is odd * and always in case 3. */ overflow |= UF_AND_64(uint, 1); uint = UF_PLUS_DIGIT(uint, (overflow + 1) >> 2); #ifdef _NEED_IO_FLOAT_LARGE if (CHECK_LONG_LONG() && __SIZEOF_LONG_DOUBLE__ > 8) { flt = (FLOAT)__atold_engine(UF_TO_U128(uint), exp); } else #endif #ifdef _NEED_IO_FLOAT64 if ((CHECK_LONG() && __SIZEOF_DOUBLE__ == 8) || (CHECK_LONG_LONG() && __SIZEOF_LONG_DOUBLE__ == 8)) { if (uintdigits + exp <= -324) { // Number is less than 1e-324, which should be rounded down to 0; return +/-0.0. flt = (FLOAT)0.0; } else if (uintdigits + exp >= 310) { // Number is larger than 1e+309, which should be rounded to +/-Infinity. flt = (FLOAT)INFINITY; } else { flt = (FLOAT)__atod_engine(UF_TO_U64(uint), exp); } } else #endif { if (uintdigits + exp <= -46) { // Number is less than 1e-46, which should be rounded down to 0; return 0.0. flt = (FLOAT)0.0f; } else if (uintdigits + exp >= 40) { // Number is larger than 1e+39, which should be rounded to +/-Infinity. flt = (FLOAT)INFINITY; } else { flt = (FLOAT)__atof_engine(UF_TO_U32(uint), exp); } } } CHECK_RANGE(flt) break; } /* switch */ #if defined(__riscv) || defined(__ARC64__) || defined(__mips) /* * Some processors don't preserve the sign of NAN across * conversions, so we have to negate after the cast */ if (addr) { if (CHECK_LONG_LONG()) { long double ld = (long double)flt; if (flags & FL_MINUS) ld = -ld; *((long double *)addr) = ld; } else if (CHECK_LONG()) { double d = (double)flt; if (flags & FL_MINUS) d = -d; *((double *)addr) = d; } else { float f = (float)flt; if (flags & FL_MINUS) f = -f; *((float *)addr) = f; } } #else if (flags & FL_MINUS) flt = -flt; if (addr) { if (CHECK_LONG_LONG()) *((long double *)addr) = (long double)flt; else if (CHECK_LONG()) *((double *)addr) = (double)flt; else *((float *)addr) = (float)flt; } #endif return 1; } #undef base picolibc-1.8.11/libc/stdio/dprintf.c000066400000000000000000000034171513574234600172520ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int dprintf(int fd, const char *fmt, ...) { va_list ap; int i; va_start(ap, fmt); i = vdprintf(fd, fmt, ap); va_end(ap); return i; } picolibc-1.8.11/libc/stdio/dtoa.h000066400000000000000000000120761513574234600165410ustar00rootroot00000000000000/* Copyright © 2018, Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _DTOA_H_ #define _DTOA_H_ #include "stdio_private.h" #include "../../libm/common/math_config.h" #define DTOA_MINUS 1 #define DTOA_ZERO 2 #define DTOA_INF 4 #define DTOA_NAN 8 #if __LDBL_MANT_DIG__ == 113 #define LDTOA_MAX_DIG 34 #elif __LDBL_MANT_DIG__ == 106 #define LDTOA_MAX_DIG 32 #elif __LDBL_MANT_DIG__ == 64 #define LDTOA_MAX_DIG 20 #endif #define DTOA_MAX_DIG 17 #define DTOA_MAX_10_EXP 308 #define DTOA_MIN_10_EXP (-307) #define DTOA_SCALE_UP_NUM 9 #define DTOA_ROUND_NUM (DTOA_MAX_DIG + 1) #define DTOA_MAX_EXP 1024 #define FTOA_MAX_10_EXP 38 #define FTOA_MIN_10_EXP (-37) #define FTOA_MAX_DIG 9 #define FTOA_SCALE_UP_NUM 6 #define FTOA_ROUND_NUM (FTOA_MAX_DIG + 1) #ifdef _NEED_IO_LONG_DOUBLE #if __SIZEOF_LONG_DOUBLE__ == 4 #define _NEED_IO_FLOAT32 #define LONG_FLOAT_MAX_DIG FTOA_MAX_DIG #define __lfloat_d_engine __ftoa_engine #define __lfloat_x_engine __ftox_engine #define PRINTF_LONG_DOUBLE_ARG(ap) (asuint(va_arg(ap, long double))) #define PRINTF_LONG_DOUBLE_TYPE uint32_t #elif __SIZEOF_LONG_DOUBLE__ == 8 #define _NEED_IO_FLOAT64 #define LONG_FLOAT_MAX_DIG DTOA_MAX_DIG #define __lfloat_d_engine __dtoa_engine #define __lfloat_x_engine __dtox_engine #define PRINTF_LONG_DOUBLE_ARG(ap) (asuint64(va_arg(ap, long double))) #define PRINTF_LONG_DOUBLE_TYPE uint64_t #elif __SIZEOF_LONG_DOUBLE__ > 8 #define _NEED_IO_FLOAT_LARGE #define LONG_FLOAT_MAX_DIG LDTOA_MAX_DIG #define __lfloat_d_engine __ldtoa_engine #define __lfloat_x_engine __ldtox_engine #define PRINTF_LONG_DOUBLE_ARG(ap) va_arg(ap, long double) #define PRINTF_LONG_DOUBLE_TYPE long double #endif #endif #ifdef _NEED_IO_DOUBLE #if __SIZEOF_DOUBLE__ == 4 #define _NEED_IO_FLOAT32 #define FLOAT_MAX_DIG FTOA_MAX_DIG #define __float_d_engine __ftoa_engine #define __float_x_engine __ftox_engine #define PRINTF_FLOAT_ARG(ap) (asuint(va_arg(ap, double))) #elif __SIZEOF_DOUBLE__ == 8 #define _NEED_IO_FLOAT64 #define FLOAT_MAX_DIG DTOA_MAX_DIG #define __float_d_engine __dtoa_engine #define __float_x_engine __dtox_engine #define PRINTF_FLOAT_ARG(ap) (asuint64(va_arg(ap, double))) #endif #endif #ifdef _NEED_IO_FLOAT #define _NEED_IO_FLOAT32 #define PRINTF_FLOAT_ARG(ap) (va_arg(ap, uint32_t)) #define FLOAT_MAX_DIG FTOA_MAX_DIG #define __float_d_engine __ftoa_engine #define __float_x_engine __ftox_engine #endif #ifdef _NEED_IO_FLOAT_LARGE #define DTOA_DIGITS LDTOA_MAX_DIG #elif defined(_NEED_IO_FLOAT64) #define DTOA_DIGITS DTOA_MAX_DIG #elif defined(_NEED_IO_FLOAT32) #define DTOA_DIGITS FTOA_MAX_DIG #else #error No float requirement set #endif struct dtoa { int32_t exp; uint8_t flags; char digits[DTOA_DIGITS]; }; #ifdef _NEED_IO_FLOAT_LARGE int __ldtoa_engine(long double x, struct dtoa *dtoa, int max_digits, bool fmode, int max_decimals); int __ldtox_engine(long double x, struct dtoa *dtoa, int prec, unsigned char case_convert); long double __atold_engine(_u128 m10, int e10); #endif #ifdef _NEED_IO_FLOAT64 int __dtoa_engine(uint64_t x, struct dtoa *dtoa, int max_digits, bool fmode, int max_decimals); int __dtox_engine(uint64_t x, struct dtoa *dtoa, int prec, unsigned char case_convert); FLOAT64 __atod_engine(uint64_t m10, int e10); #endif #ifdef _NEED_IO_FLOAT32 int __ftoa_engine(uint32_t val, struct dtoa *ftoa, int max_digits, bool fmode, int max_decimals); int __ftox_engine(uint32_t x, struct dtoa *dtoa, int prec, unsigned char case_convert); float __atof_engine(uint32_t m10, int e10); #endif #endif /* !_DTOA_H_ */ picolibc-1.8.11/libc/stdio/dtoa_engine.c000066400000000000000000000166731513574234600200700ustar00rootroot00000000000000/* Copyright © 2018, Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #ifdef FLOAT64 #define _NEED_IO_FLOAT64 #include "dtoa.h" #define max(a, b) \ ({ \ __typeof(a) _a = a; \ __typeof(b) _b = b; \ _a > _b ? _a : _b; \ }) #define min(a, b) \ ({ \ __typeof(a) _a = a; \ __typeof(b) _b = b; \ _a < _b ? _a : _b; \ }) #define FRACTION_BITS (53 - 1) #define FRACTION_MASK (((uint64_t)1 << FRACTION_BITS) - 1) #define EXPONENT_BITS (64 - FRACTION_BITS - 1) #define EXPONENT_MASK (((uint64_t)1 << EXPONENT_BITS) - 1) #define SIGN_BIT ((uint64_t)1 << (64 - 1)) #define BIT64(x) ((uint64_t)1 << (x)) /* * Check to see if the high bit is set by casting * to signed and checking for negative */ static inline bool high_bit_set(uint64_t fract) { return ((int64_t)fract < 0); } int __dtoa_engine(uint64_t v, struct dtoa *dtoa, int max_digits, bool fmode, int max_decimals) { uint64_t fract = (v << (EXPONENT_BITS + 1)) >> 1; int expo = (v << 1) >> (FRACTION_BITS + 1); int decexp = 0; int i; uint8_t flags = 0; if ((int64_t)v < 0) flags |= DTOA_MINUS; if (expo == EXPONENT_MASK) { if (fract) flags |= DTOA_NAN; else flags |= DTOA_INF; } else { if (expo == 0) { if (fract == 0) { flags |= DTOA_ZERO; dtoa->digits[0] = '0'; max_digits = 1; goto done; } /* normalize */ while ((int64_t)(fract <<= 1) >= 0) expo--; } /* add implicit bit */ fract |= SIGN_BIT; /* adjust exponent */ expo -= (DTOA_MAX_EXP - 2); decexp = -1; /* * Let's consider: * * value = fract * 2^expo * 10^decexp * * Initially decexp = 0. The goal is to bring exp between * 0 and -2 as the magnitude of a fractional decimal digit is 3 bits. */ while (expo < -2) { /* * Make room to allow a multiplication by 5 without overflow. * We test only the top part for faster code. */ do { /* Round this division to avoid accumulating errors */ fract = (fract >> 1) + (fract & 1); expo++; } while ((uint32_t)(fract >> 32) >= (UINT32_MAX / 5U)); /* Perform fract * 5 * 2 / 10 */ fract *= 5U; expo++; decexp--; } while (expo > 0) { /* * Perform fract / 5 / 2 * 10. * The +2 is there to do round the result of the division * by 5 not to lose too much precision in extreme cases. */ fract += 2; fract /= 5U; expo--; decexp++; /* Bring back our fractional number to full scale */ do { fract <<= 1; expo--; } while (!high_bit_set(fract)); } /* * The binary fractional point is located somewhere above bit 63. * Move it between bits 59 and 60 to give 4 bits of room to the * integer part. */ fract >>= (4 - expo); /* If limiting decimals, then limit the max digits * to no more than the number of digits left of the decimal * plus the number of digits right of the decimal * * exp: exponent value. If negative, there are * -exp - 1 zeros left of the first non-zero * digit in 'f' format. If non-negative, * there are exp digits to the left of * the decimal point * * max_decimals: Only used in 'f' format. Round to no * more than this many digits to the * right of the decimal point (left if * negative) * * max_digits: We can't convert more than this number * of digits given the limits of the * buffer */ int save_max_digits = max_digits; if (fmode) { /* * This covers two cases: * * When exp is < 0, there are -exp-1 zeros taking up * space before we can display any of the real digits, * so we have to subtract those off max_decimals before * we round that (max_decimals - (-exp - 1)). This * may end up less than zero, in which case we have * no digits to display. * * When exp >= 0, there are exp + 1 digits left of the * decimal point *plus* max_decimals right of the * decimal point that need to be generated * * A single expression gives the right answer in both * cases, which is kinda cool */ /* max_decimals comes in biased by 1 to flag the 'f' case */ max_digits = min(max_digits, max(max_decimals < 0, max_decimals + decexp + 1)); } int decimals = max_digits; /* Round the value to the last digit being printed. */ uint64_t round = BIT64(59); /* 0.5 */ while (decimals--) { round /= 10U; } fract += round; /* Make sure rounding didn't make fract >= 1.0 */ if (fract >= BIT64(60)) { fract /= 10U; decexp++; max_digits = min(save_max_digits, max(1, max_decimals + decexp + 1)); } /* Now convert mantissa to decimal. */ /* Compute digits */ for (i = 0; i < max_digits; i++) { fract *= 10U; dtoa->digits[i] = (fract >> 60) + '0'; fract &= BIT64(60) - 1; } } done: dtoa->flags = flags; dtoa->exp = decexp; return max_digits; } #endif picolibc-1.8.11/libc/stdio/dtoa_ryu.c000066400000000000000000000363001513574234600174270ustar00rootroot00000000000000// Copyright 2018 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. // Runtime compiler options: // -DRYU_DEBUG Generate verbose debugging output to stdout. // // -DRYU_ONLY_64_BIT_OPS Avoid using uint128_t or 64-bit intrinsics. Slower, // depending on your compiler. // #include "stdio_private.h" #ifdef FLOAT64 #define _NEED_IO_FLOAT64 #include "dtoa.h" #include "ryu/ryu.h" #include #include #include #include #ifdef RYU_DEBUG #include #include #endif #include "ryu/common.h" #include "ryu/d2s_intrinsics.h" #define DOUBLE_MANTISSA_BITS 52 #define DOUBLE_EXPONENT_BITS 11 #define DOUBLE_BIAS 1023 static int decimalLength17(const uint64_t v) { int len = 1; uint64_t c = 10; while (c <= v) { len++; c = (c << 3) + (c << 1); } return len; } // A floating decimal representing m * 10^e. typedef struct floating_decimal_64 { uint64_t mantissa; // Decimal exponent's range is -324 to 308 // inclusive, and can fit in a short if needed. int16_t exponent; int16_t olength; } floating_decimal_64; static inline floating_decimal_64 d2d(const uint64_t ieeeMantissa, const uint32_t ieeeExponent, int max_digits, bool fmode, int max_decimals) { int32_t e2; uint64_t m2; if (ieeeExponent == 0) { // We subtract 2 so that the bounds computation has 2 additional bits. e2 = 1 - DOUBLE_BIAS - DOUBLE_MANTISSA_BITS - 2; m2 = ieeeMantissa; } else { e2 = (int32_t)ieeeExponent - DOUBLE_BIAS - DOUBLE_MANTISSA_BITS - 2; m2 = (1ull << DOUBLE_MANTISSA_BITS) | ieeeMantissa; } const bool even = (m2 & 1) == 0; const bool acceptBounds = even; /* Set if we're truncating more digits to meet format request */ bool truncate_max = false; #ifdef RYU_DEBUG printf("-> %" PRIu64 " * 2^%d\n", m2, e2 + 2); #endif // Step 2: Determine the interval of valid decimal representations. const uint64_t mv = 4 * m2; // Implicit bool -> int conversion. True is 1, false is 0. const uint32_t mmShift = ieeeMantissa != 0 || ieeeExponent <= 1; // We would compute mp and mm like this: // uint64_t mp = 4 * m2 + 2; // uint64_t mm = mv - 1 - mmShift; // Step 3: Convert to a decimal power base using 128-bit arithmetic. uint64_t vr, vp, vm; int32_t e10; bool vmIsTrailingZeros = false; bool vrIsTrailingZeros = false; if (e2 >= 0) { // I tried special-casing q == 0, but there was no effect on performance. // This expression is slightly faster than max_int(0, log10Pow2(e2) - 1). const uint32_t q = log10Pow2(e2) - (e2 > 3); e10 = (int32_t)q; const int32_t k = DOUBLE_POW5_INV_BITCOUNT + pow5bits((int32_t)q) - 1; const int32_t i = -e2 + (int32_t)q + k; uint64_t pow5[2]; __double_computeInvPow5(q, pow5); vr = mulShiftAll64(m2, pow5, i, &vp, &vm, mmShift); #ifdef RYU_DEBUG printf("%" PRIu64 " * 2^%d / 10^%u\n", mv, e2, q); printf("V+=%" PRIu64 "\nV =%" PRIu64 "\nV-=%" PRIu64 "\n", vp, vr, vm); #endif if (q <= 21) { // This should use q <= 22, but I think 21 is also safe. Smaller values // may still be safe, but it's more difficult to reason about them. // Only one of mp, mv, and mm can be a multiple of 5, if any. const uint32_t mvMod5 = ((uint32_t)mv) - 5 * ((uint32_t)div5(mv)); if (mvMod5 == 0) { vrIsTrailingZeros = multipleOfPowerOf5(mv, q); } else if (acceptBounds) { // Same as min_int(e2 + (~mm & 1), pow5Factor(mm)) >= q // <=> e2 + (~mm & 1) >= q && pow5Factor(mm) >= q // <=> true && pow5Factor(mm) >= q, since e2 >= q. vmIsTrailingZeros = multipleOfPowerOf5(mv - 1 - mmShift, q); } else { // Same as min_int(e2 + 1, pow5Factor(mp)) >= q. vp -= multipleOfPowerOf5(mv + 2, q); } } } else { // This expression is slightly faster than max_int(0, log10Pow5(-e2) - 1). const uint32_t q = log10Pow5(-e2) - (-e2 > 1); e10 = (int32_t)q + e2; const int32_t i = -e2 - (int32_t)q; const int32_t k = pow5bits(i) - DOUBLE_POW5_BITCOUNT; const int32_t j = (int32_t)q - k; uint64_t pow5[2]; __double_computePow5(i, pow5); vr = mulShiftAll64(m2, pow5, j, &vp, &vm, mmShift); #ifdef RYU_DEBUG printf("%" PRIu64 " * 5^%d / 10^%u\n", mv, -e2, q); printf("%u %d %d %d\n", q, i, k, j); printf("V+=%" PRIu64 "\nV =%" PRIu64 "\nV-=%" PRIu64 "\n", vp, vr, vm); #endif if (q <= 1) { // {vr,vp,vm} is trailing zeros if {mv,mp,mm} has at least q trailing 0 bits. // mv = 4 * m2, so it always has at least two trailing 0 bits. vrIsTrailingZeros = true; if (acceptBounds) { // mm = mv - 1 - mmShift, so it has 1 trailing 0 bit iff mmShift == 1. vmIsTrailingZeros = mmShift == 1; } else { // mp = mv + 2, so it always has at least one trailing 0 bit. --vp; } } else if (q < 63) { // TODO(ulfjack): Use a tighter bound here. // We want to know if the full product has at least q trailing zeros. // We need to compute min_int(p2(mv), p5(mv) - e2) >= q // <=> p2(mv) >= q && p5(mv) - e2 >= q // <=> p2(mv) >= q (because -e2 >= q) vrIsTrailingZeros = multipleOfPowerOf2(mv, q); #ifdef RYU_DEBUG printf("vr is trailing zeros=%s\n", vrIsTrailingZeros ? "true" : "false"); #endif } } #ifdef RYU_DEBUG printf("e10=%d\n", e10); printf("V+=%" PRIu64 "\nV =%" PRIu64 "\nV-=%" PRIu64 "\n", vp, vr, vm); printf("vm is trailing zeros=%s\n", vmIsTrailingZeros ? "true" : "false"); printf("vr is trailing zeros=%s\n", vrIsTrailingZeros ? "true" : "false"); #endif // Step 4: Find the shortest decimal representation in the interval of valid representations. int32_t removed = 0; uint8_t lastRemovedDigit = 0; uint64_t output; // On average, we remove ~2 digits. // General case, which happens rarely (~0.7%). /* If limiting decimals, then limit the max digits * to no more than the number of digits left of the decimal * plus the number of digits right of the decimal * * exp: exponent value. If negative, there are * -exp - 1 zeros left of the first non-zero * digit in 'f' format. If non-negative, * there are exp digits to the left of * the decimal point * * max_decimals: Only used in 'f' format. Round to this many * digits to the right of the decimal point * (left if negative) * * max_digits: We can't convert more than this number of digits given * the limits of the buffer */ int save_max_digits = max_digits; if (fmode) { int exp = e10 + decimalLength17(vr) - 1; /* * This covers two cases: * * When exp is < 0, there are -exp-1 zeros taking up * space before we can display any of the real digits, * so we have to subtract those off max_decimals before * we round that (max_decimals - (-exp - 1)). This * may end up less than zero, in which case we have * no digits to display. * * When exp >= 0, there are exp + 1 digits left of the * decimal point *plus* max_decimals right of the * decimal point that need to be generated * * A single expression gives the right answer in both * cases, which is kinda cool * * When called from fcvt, max_decimals may be less * than zero, indicating that we want to round left of * the decimal point. In that case, make sure we generate * at least one digit */ max_digits = min_int(max_digits, max_int(max_decimals < 0, max_decimals + exp + 1)); } for (;;) { const uint64_t vpDiv10 = div10(vp); const uint64_t vmDiv10 = div10(vm); if (vpDiv10 <= vmDiv10) { if (decimalLength17(vr) <= max_digits || (max_digits == 0 && vr == 0)) break; else truncate_max = true; } const uint32_t vmMod10 = ((uint32_t)vm) - 10 * ((uint32_t)vmDiv10); const uint64_t vrDiv10 = div10(vr); const uint32_t vrMod10 = ((uint32_t)vr) - 10 * ((uint32_t)vrDiv10); vmIsTrailingZeros &= vmMod10 == 0; vrIsTrailingZeros &= lastRemovedDigit == 0; lastRemovedDigit = (uint8_t)vrMod10; vr = vrDiv10; vp = vpDiv10; vm = vmDiv10; ++removed; } #ifdef RYU_DEBUG printf("V+=%" PRIu64 "\nV =%" PRIu64 "\nV-=%" PRIu64 "\n", vp, vr, vm); printf("d-10=%s\n", vmIsTrailingZeros ? "true" : "false"); #endif if (vmIsTrailingZeros) { for (;;) { const uint64_t vmDiv10 = div10(vm); const uint32_t vmMod10 = ((uint32_t)vm) - 10 * ((uint32_t)vmDiv10); if (vmMod10 != 0) { break; } const uint64_t vpDiv10 = div10(vp); const uint64_t vrDiv10 = div10(vr); const uint32_t vrMod10 = ((uint32_t)vr) - 10 * ((uint32_t)vrDiv10); vrIsTrailingZeros &= lastRemovedDigit == 0; lastRemovedDigit = (uint8_t)vrMod10; vr = vrDiv10; vp = vpDiv10; vm = vmDiv10; ++removed; } } #ifdef RYU_DEBUG printf("%" PRIu64 " %d\n", vr, lastRemovedDigit); printf("vr is trailing zeros=%s\n", vrIsTrailingZeros ? "true" : "false"); #endif if (vrIsTrailingZeros && lastRemovedDigit == 5 && vr % 2 == 0) { // Round even if the exact number is .....50..0. lastRemovedDigit = 4; } output = vr; e10 += removed; // We need to take vr + 1 if vr is outside bounds or we need to round up. // I don't know if the 'truncate_max' case is entirely correct; need some tests uint8_t carry = ((!truncate_max && vr == vm && (!acceptBounds || !vmIsTrailingZeros)) || lastRemovedDigit >= 5); output += carry; int len = decimalLength17(output); if (carry) { /* This can only happen if output has carried out of the top digit */ if (len > max_digits) { /* Recompute max digits in this case */ if (fmode) { int exp = e10 + len - 1; /* max_decimals comes in biased by 1 to flag the 'f' case */ max_digits = min_int(save_max_digits, max_int(1, max_decimals + exp + 1)); } if (len > max_digits) { output += 5; output /= 10; e10++; len--; } } } if (len > max_digits) len = max_digits; #ifdef RYU_DEBUG printf("V+=%" PRIu64 "\nV =%" PRIu64 "\nV-=%" PRIu64 "\n", vp, vr, vm); printf("O=%" PRIu64 "\n", output); printf("EXP=%d\n", exp); #endif floating_decimal_64 fd; fd.exponent = e10; fd.olength = len; fd.mantissa = output; return fd; } static inline bool d2d_small_int(const uint64_t ieeeMantissa, const uint32_t ieeeExponent, floating_decimal_64 * const v) { const uint64_t m2 = (1ull << DOUBLE_MANTISSA_BITS) | ieeeMantissa; const int32_t e2 = (int32_t)ieeeExponent - DOUBLE_BIAS - DOUBLE_MANTISSA_BITS; if (e2 > 0) { // f = m2 * 2^e2 >= 2^53 is an integer. // Ignore this case for now. return false; } if (e2 < -52) { // f < 1. return false; } // Since 2^52 <= m2 < 2^53 and 0 <= -e2 <= 52: 1 <= f = m2 / 2^-e2 < 2^53. // Test if the lower -e2 bits of the significand are 0, i.e. whether the fraction is 0. const uint64_t mask = (1ull << -e2) - 1; const uint64_t fraction = m2 & mask; if (fraction != 0) { return false; } // f is an integer in the range [1, 2^53). // Note: mantissa might contain trailing (decimal) 0's. // Note: since 2^53 < 10^16, there is no need to adjust decimalLength17(). v->mantissa = m2 >> -e2; v->exponent = 0; return true; } int __dtoa_engine(uint64_t bits, struct dtoa *dtoa, int max_digits, bool fmode, int max_decimals) { // Step 1: Decode the floating-point number, and unify normalized and subnormal cases. #ifdef RYU_DEBUG printf("IN="); for (int32_t bit = 63; bit >= 0; --bit) { printf("%d", (int)((bits >> bit) & 1)); } printf("\n"); #endif // Decode bits into sign, mantissa, and exponent. const bool ieeeSign = ((bits >> (DOUBLE_MANTISSA_BITS + DOUBLE_EXPONENT_BITS)) & 1) != 0; const uint64_t ieeeMantissa = bits & ((1ull << DOUBLE_MANTISSA_BITS) - 1); const uint32_t ieeeExponent = (uint32_t)((bits >> DOUBLE_MANTISSA_BITS) & ((1u << DOUBLE_EXPONENT_BITS) - 1)); uint8_t flags = 0; if (ieeeSign) flags |= DTOA_MINUS; if (ieeeExponent == 0 && ieeeMantissa == 0) { flags |= DTOA_ZERO; dtoa->digits[0] = '0'; dtoa->flags = flags; dtoa->exp = 0; return 1; } if (ieeeExponent == ((1u << DOUBLE_EXPONENT_BITS) - 1u)) { if (ieeeMantissa) { flags |= DTOA_NAN; } else { flags |= DTOA_INF; } dtoa->flags = flags; return 0; } floating_decimal_64 v; const bool isSmallInt = d2d_small_int(ieeeMantissa, ieeeExponent, &v); if (isSmallInt && 0) { // For small integers in the range [1, 2^53), v.mantissa might contain trailing (decimal) // zeros. For scientific notation we need to move these zeros into the exponent. (This is // not needed for fixed-point notation, so it might be beneficial to trim trailing zeros in // to_chars only if needed - once fixed-point notation output is implemented.) for (;;) { const uint64_t q = div10(v.mantissa); const uint32_t r = ((uint32_t)v.mantissa) - 10 * ((uint32_t)q); if (r != 0) { break; } v.mantissa = q; ++v.exponent; } } else { v = d2d(ieeeMantissa, ieeeExponent, max_digits, fmode, max_decimals); } uint64_t mant = v.mantissa; int32_t olength = v.olength; int32_t exp = v.exponent + olength - 1; int i; for (i = 0; i < olength; i++) { dtoa->digits[olength - i - 1] = (mant % 10) + '0'; mant /= 10; } dtoa->exp = exp; dtoa->flags = flags; return olength; } #endif /* FLOAT64 */ picolibc-1.8.11/libc/stdio/dtox_engine.c000066400000000000000000000110561513574234600201050ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2023 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef DTOX_SIZE #define DTOX_SIZE 8 #endif #include "stdio_private.h" #if DTOX_SIZE == 4 || defined(FLOAT64) #if DTOX_SIZE == 8 #define DTOA_MAX_DIG 17 #define DTOA_MAX_10_EXP 308 #define DTOA_MIN_10_EXP (-307) #define DTOA_SCALE_UP_NUM 9 #define DTOA_ROUND_NUM (DTOA_MAX_DIG + 1) #define DTOX_UINT uint64_t #define DTOX_INT int64_t #define DTOX_ASUINT(x) asuint64(x) #define EXP_SHIFT 52 #define EXP_MASK 0x7ff #define SIG_SHIFT 0 #define SIG_MASK 0xfffffffffffffLL #define SIG_MSB 0x10000000000000LL #define EXP_BIAS 1023 #define ASUINT(x) asuint64(x) #define DTOX_NDIGS 14 #define _NEED_IO_FLOAT64 #elif DTOX_SIZE == 4 #define _NEED_IO_FLOAT32 #define __dtox_engine __ftox_engine #define DTOX_UINT uint32_t #define DTOX_INT int32_t #define DTOX_ASUINT(x) asuint(x) #define EXP_SHIFT 23 #define EXP_MASK 0xff #define SIG_SHIFT 1 #define SIG_MASK 0x7fffff #define SIG_MSB 0x800000 #define EXP_BIAS 127 #define ASUINT(x) asuint(x) #define DTOX_NDIGS 7 #endif #include "dtoa.h" /* * Convert a 32-bit or 64-bit float to a string in hex ('a') format * * This chunk of code gets inserted into the vfprintf function in the * double/float handling code as well as the long double case when * long double is 32- or 64- bits. * * This code assumes that there is an integer type suitable for holding * the entire floating point value. * * Define DTOX_UINT, DTOX_INT and DTOX_SIZE before including * this file. */ #define TOCASE(c) ((c) - case_convert) int __dtox_engine(DTOX_UINT ufi, struct dtoa *dtoa, int prec, unsigned char case_convert) { DTOX_INT fi = (DTOX_INT)ufi; DTOX_INT s; int exp, d; dtoa->flags = 0; if (fi < 0) dtoa->flags = DTOA_MINUS; exp = ((fi >> EXP_SHIFT) & EXP_MASK); s = (fi & SIG_MASK) << SIG_SHIFT; if (s || exp) { if (exp == EXP_BIAS * 2 + 1) { if (s) dtoa->flags |= DTOA_NAN; else dtoa->flags |= DTOA_INF; return 0; } if (!exp) exp = 1; else s |= (SIG_MSB << SIG_SHIFT); exp -= EXP_BIAS; } dtoa->exp = exp; if (prec < 0) prec = 0; else if (prec >= (DTOX_NDIGS - 1)) prec = DTOX_NDIGS - 1; else { int bits = ((DTOX_NDIGS - 1) - prec) << 2; DTOX_INT half = ((DTOX_INT)1) << (bits - 1); DTOX_INT mask = ~((half << 1) - 1); /* round even */ if ((s & ~mask) > half || ((s >> bits) & 1) != 0) s += half; s &= mask; } for (d = DTOX_NDIGS - 1; d >= 0; d--) { int dig = s & 0xf; s >>= 4; if (dig == 0 && d > prec) continue; if (dig > 9) dig += TOCASE('a') - 10 - '0'; dig += '0'; dtoa->digits[d] = dig; if (prec < d) prec = d; } return prec; } #endif picolibc-1.8.11/libc/stdio/ecvt.c000066400000000000000000000041071513574234600165420ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #if __SIZEOF_DOUBLE__ == 8 #define _NEED_IO_DOUBLE #include "dtoa.h" static __THREAD_LOCAL char ecvt_buf[DTOA_MAX_DIG + 1]; char * ecvt(double invalue, int ndigit, int *decpt, int *sign) { if (ecvt_r(invalue, ndigit, decpt, sign, ecvt_buf, sizeof(ecvt_buf)) < 0) return NULL; return ecvt_buf; } #elif __SIZEOF_DOUBLE__ == 4 char * ecvt(double invalue, int ndigit, int *decpt, int *sign) { return ecvtf((float)invalue, ndigit, decpt, sign); } #endif picolibc-1.8.11/libc/stdio/ecvt_r.c000066400000000000000000000052261513574234600170660ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #if __SIZEOF_DOUBLE__ == 8 #define _NEED_IO_FLOAT64 #include "dtoa.h" int ecvt_r(double invalue, int ndigit, int *decpt, int *sign, char *buf, size_t len) { struct dtoa dtoa; char *digits = dtoa.digits; int ngot; if (ndigit < 0) ndigit = 0; if ((size_t)ndigit > len - 1) return -1; if (!isfinite(invalue)) { *sign = invalue < 0; *decpt = 0; if (isnan(invalue)) digits = "nan"; else digits = "inf"; ngot = 3; if (ndigit < ngot) ngot = ndigit; ndigit = ngot; } else { ngot = __dtoa_engine(asuint64(invalue), &dtoa, ndigit, false, 0); *sign = !!(dtoa.flags & DTOA_MINUS); *decpt = dtoa.exp + 1; } memset(buf, '0', ndigit); memcpy(buf, digits, ngot); buf[ndigit] = '\0'; return 0; } #elif __SIZEOF_DOUBLE__ == 4 #include "stdio_private.h" int ecvt_r(double invalue, int ndigit, int *decpt, int *sign, char *buf, size_t len) { return ecvtf_r(invalue, ndigit, decpt, sign, buf, len); } #endif picolibc-1.8.11/libc/stdio/ecvtf.c000066400000000000000000000036171513574234600167150ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #define _NEED_IO_FLOAT #include "dtoa.h" static __THREAD_LOCAL char ecvtf_buf[FTOA_MAX_DIG + 1]; char * ecvtf(float invalue, int ndigit, int *decpt, int *sign) { if (ecvtf_r(invalue, ndigit, decpt, sign, ecvtf_buf, sizeof(ecvtf_buf)) < 0) return NULL; return ecvtf_buf; } picolibc-1.8.11/libc/stdio/ecvtf_r.c000066400000000000000000000041531513574234600172320ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _NEED_IO_FLOAT #include "stdio_private.h" #include "dtoa.h" int ecvtf_r(float invalue, int ndigit, int *decpt, int *sign, char *buf, size_t len) { struct dtoa dtoa; int ngot; if (ndigit < 0) ndigit = 0; if ((size_t)ndigit > len - 1) return -1; ngot = __ftoa_engine(asuint(invalue), &dtoa, ndigit, false, 0); *sign = !!(dtoa.flags & DTOA_MINUS); *decpt = dtoa.exp + 1; memset(buf, '0', ndigit); memcpy(buf, dtoa.digits, ngot); buf[ndigit] = '\0'; return 0; } picolibc-1.8.11/libc/stdio/ecvtl.c000066400000000000000000000044641513574234600167240ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #if __SIZEOF_LONG_DOUBLE__ > 8 #define _NEED_IO_LONG_DOUBLE #include "dtoa.h" static __THREAD_LOCAL char ecvt_buf[LDTOA_MAX_DIG + 1]; char * ecvtl(long double invalue, int ndigit, int *decpt, int *sign) { if (ecvtl_r(invalue, ndigit, decpt, sign, ecvt_buf, sizeof(ecvt_buf)) < 0) return NULL; return ecvt_buf; } #elif __SIZEOF_LONG_DOUBLE__ == 4 #include "stdio_private.h" char * ecvtl(long double invalue, int ndigit, int *decpt, int *sign) { return ecvtf((float)invalue, ndigit, decpt, sign); } #elif __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__ #include "stdio_private.h" char * ecvtl(long double invalue, int ndigit, int *decpt, int *sign) { return ecvt((double)invalue, ndigit, decpt, sign); } #endif picolibc-1.8.11/libc/stdio/ecvtl_r.c000066400000000000000000000062471513574234600172460ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #if __SIZEOF_LONG_DOUBLE__ > __SIZEOF_DOUBLE__ #define _NEED_IO_LONG_DOUBLE #include "dtoa.h" int ecvtl_r(long double invalue, int ndigit, int *decpt, int *sign, char *buf, size_t len) { struct dtoa dtoa; char *digits = dtoa.digits; int ngot; if (ndigit < 0) ndigit = 0; if ((size_t)ndigit > len - 1) return -1; if (!isfinite(invalue)) { *sign = invalue < 0; *decpt = 0; if (isnan(invalue)) digits = "nan"; else digits = "inf"; ngot = 3; if (ndigit < ngot) ngot = ndigit; ndigit = ngot; } else { #ifdef _NEED_IO_FLOAT_LARGE ngot = __ldtoa_engine(invalue, &dtoa, ndigit, false, 0); #elif __SIZEOF_LONG_DOUBLE__ == 8 ngot = __dtoa_engine((FLOAT64)invalue, &dtoa, ndigit, false, 0); #elif __SIZEOF_LONG_DOUBLE__ == 4 ngot = __ftoa_engine((float)invalue, &dtoa, ndigit, false, 0); #endif *sign = !!(dtoa.flags & DTOA_MINUS); *decpt = dtoa.exp + 1; } memset(buf, '0', ndigit); memcpy(buf, digits, ngot); buf[ndigit] = '\0'; return 0; } #elif __SIZEOF_LONG_DOUBLE__ == 4 #include "stdio_private.h" int ecvtl_r(long double invalue, int ndigit, int *decpt, int *sign, char *buf, size_t len) { return ecvtf_r((float)invalue, ndigit, decpt, sign, buf, len); } #elif __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__ #include "stdio_private.h" int ecvtl_r(long double invalue, int ndigit, int *decpt, int *sign, char *buf, size_t len) { return ecvt_r((double)invalue, ndigit, decpt, sign, buf, len); } #endif picolibc-1.8.11/libc/stdio/exchange.c000066400000000000000000000036301513574234600173630ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #if defined(__ATOMIC_UNGETC) && !defined(PICOLIBC_HAVE_SYNC_COMPARE_AND_SWAP) __ungetc_t __picolibc_non_atomic_exchange_ungetc(__ungetc_t *p, __ungetc_t v) { return __non_atomic_exchange_ungetc(p, v); } __weak_reference(__picolibc_non_atomic_exchange_ungetc, __atomic_exchange_ungetc); #endif picolibc-1.8.11/libc/stdio/fclose.c000066400000000000000000000036471513574234600170640ustar00rootroot00000000000000/* Copyright (c) 2002,2005 Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: fclose.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int fclose(FILE *f) { struct __file_close *cf = (struct __file_close *)f; #ifdef __STDIO_LOCKING fflush(f); __flockfile_close(f); #endif if ((f->flags & __SCLOSE) && cf->close) { /* * File has 'close' function, call it */ return (*cf->close)(f); } return 0; } picolibc-1.8.11/libc/stdio/fcvt.c000066400000000000000000000042001513574234600165350ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #if __SIZEOF_DOUBLE__ == 8 #define _NEED_IO_DOUBLE #include "dtoa.h" #define FCVT_MAXDIG (__DBL_MAX_10_EXP__ + DTOA_MAX_DIG + 1) static __THREAD_LOCAL char fcvt_buf[FCVT_MAXDIG]; char * fcvt(double invalue, int ndigit, int *decpt, int *sign) { if (fcvt_r(invalue, ndigit, decpt, sign, fcvt_buf, sizeof(fcvt_buf)) < 0) return NULL; return fcvt_buf; } #elif __SIZEOF_DOUBLE__ == 4 char * fcvt(double invalue, int ndigit, int *decpt, int *sign) { return fcvtf((float)invalue, ndigit, decpt, sign); } #endif picolibc-1.8.11/libc/stdio/fcvt_r.c000066400000000000000000000113511513574234600170630ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #if __SIZEOF_DOUBLE__ == 8 #define _NEED_IO_FLOAT64 #include "dtoa.h" int fcvt_r(double invalue, int ndecimal, int *decpt, int *sign, char *buf, size_t len) { struct dtoa dtoa; int ntrailing; /* number of zeros to add after the value */ int ndigit; /* numer of generated digits */ int dtoa_decimal = ndecimal; char *digits = dtoa.digits; if (!isfinite(invalue)) { ndigit = 3; ntrailing = 0; *sign = invalue < 0; *decpt = 0; if (isnan(invalue)) digits = "nan"; else digits = "inf"; } else { /* ndecimal = digits after decimal point desired * ndigit = digits actually generated * dtoa.exp = exponent (position of decimal relative to first digit generated) */ if (ndecimal < 0) dtoa_decimal = 0; ndigit = __dtoa_engine(asuint64(invalue), &dtoa, DTOA_MAX_DIG, true, ndecimal); *sign = !!(dtoa.flags & DTOA_MINUS); /* * To compute the number of zeros added after the value, there are * three cases: * * 1. all of the generated digits are left of the decimal * point (dtoa.exp >= ndigit). We need (dtoa.exp - ndigit) * digits left of the decimal and ndecimal right of the * decimal: (dtoa.exp - ndigit) + ndecimal * * 2. some of the generated digits are right * of the decimal point (dtoa.exp < ndigit). We need * ndecimal digits total, but we have (ndigit - dtoa.exp) * already, so: ndecimal - (ndigit - dtoa.exp). * * 3. all of the generated digits are right of the decimal point * We need fewer than ndecimal digits by the magnitude of * the exponent (which is negative in this case, so: * ndecimal - (-dtoa.exp - 1) - ndigit * * These all turn out to be the same computation. Kinda cool. */ ntrailing = (dtoa.exp + 1 - ndigit) + dtoa_decimal; /* * If this value is negative, then we actually have *no* digits to * generate. In this case, we return the empty string and set the * exponent to the number of digits requested (as they're all * zero) */ if (ntrailing < 0) { ntrailing = 0; ndigit = 0; /* * Adjust exponent to reflect the desired output of ndecimal * zeros */ dtoa.exp = -(dtoa_decimal + 1); } *decpt = dtoa.exp + 1; } /* If we can't fit the whole value in the provided space, * return an error */ if ((size_t)(ndigit + ntrailing) >= len) return -1; /* Value */ memcpy(buf, digits, ndigit); buf += ndigit; /* Trailing zeros */ memset(buf, '0', ntrailing); buf += ntrailing; /* Null terminate */ buf[0] = '\0'; return 0; } #elif __SIZEOF_DOUBLE__ == 4 #include "stdio_private.h" int fcvt_r(double invalue, int ndecimal, int *decpt, int *sign, char *buf, size_t len) { return fcvtf_r((float)invalue, ndecimal, decpt, sign, buf, len); } #endif picolibc-1.8.11/libc/stdio/fcvtf.c000066400000000000000000000036611513574234600167150ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _NEED_IO_FLOAT #include "dtoa.h" #define FCVTF_MAXDIG (__FLT_MAX_10_EXP__ + FTOA_MAX_DIG + 1) static __THREAD_LOCAL char fcvtf_buf[FCVTF_MAXDIG]; char * fcvtf(float invalue, int ndecimal, int *decpt, int *sign) { if (fcvtf_r(invalue, ndecimal, decpt, sign, fcvtf_buf, sizeof(fcvtf_buf)) < 0) return NULL; return fcvtf_buf; } picolibc-1.8.11/libc/stdio/fcvtf_r.c000066400000000000000000000107701513574234600172350ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _NEED_IO_FLOAT #include "dtoa.h" int fcvtf_r(float invalue, int ndecimal, int *decpt, int *sign, char *buf, size_t len) { struct dtoa dtoa; int ntrailing; /* number of zeros to add after the value */ int ndigit; /* numer of generated digits */ int dtoa_decimal = ndecimal; char *digits = dtoa.digits; if (!finitef(invalue)) { ndigit = 3; ntrailing = 0; *sign = invalue < 0; *decpt = 0; if (isnan(invalue)) digits = "nan"; else digits = "inf"; } else { /* ndecimal = digits after decimal point desired * ndigit = digits actually generated * dtoa.exp = exponent (position of decimal relative to first digit generated) */ if (ndecimal < 0) dtoa_decimal = 0; ndigit = __ftoa_engine(asuint(invalue), &dtoa, FTOA_MAX_DIG, true, ndecimal); *sign = !!(dtoa.flags & DTOA_MINUS); /* * To compute the number of zeros added after the value, there are * three cases: * * 1. all of the generated digits are left of the decimal * point (dtoa.exp >= ndigit). We need (dtoa.exp - ndigit) * digits left of the decimal and ndecimal right of the * decimal: (dtoa.exp - ndigit) + ndecimal * * 2. some of the generated digits are right * of the decimal point (dtoa.exp < ndigit). We need * ndecimal digits total, but we have (ndigit - dtoa.exp) * already, so: ndecimal - (ndigit - dtoa.exp). * * 3. all of the generated digits are right of the decimal point * We need fewer than ndecimal digits by the magnitude of * the exponent (which is negative in this case, so: * ndecimal - (-dtoa.exp - 1) - ndigit * * These all turn out to be the same computation. Kinda cool. */ ntrailing = (dtoa.exp + 1 - ndigit) + dtoa_decimal; /* * If this value is negative, then we actually have *no* digits to * generate. In this case, we return the empty string and set the * exponent to the number of digits requested (as they're all * zero) */ if (ntrailing < 0) { ntrailing = 0; ndigit = 0; /* * Adjust exponent to reflect the desired output of ndecimal * zeros */ dtoa.exp = -(dtoa_decimal + 1); } *decpt = dtoa.exp + 1; } /* If we can't fit the whole value in the provided space, * return an error */ if ((size_t)(ndigit + ntrailing) >= len) return -1; /* Value */ memcpy(buf, digits, ndigit); len -= ndigit; buf += ndigit; /* Trailing zeros */ memset(buf, '0', ntrailing); buf += ntrailing; /* Null terminate */ buf[0] = '\0'; return 0; } picolibc-1.8.11/libc/stdio/fcvtl.c000066400000000000000000000046141513574234600167220ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #if __SIZEOF_LONG_DOUBLE__ > __SIZEOF_DOUBLE__ #define _NEED_IO_LONG_DOUBLE #include "dtoa.h" #define FCVTL_MAXDIG (__LDBL_MAX_10_EXP__ + LONG_FLOAT_MAX_DIG + 1) static __THREAD_LOCAL char fcvt_buf[FCVTL_MAXDIG]; char * fcvtl(long double invalue, int ndigit, int *decpt, int *sign) { if (fcvtl_r(invalue, ndigit, decpt, sign, fcvt_buf, sizeof(fcvt_buf)) < 0) return NULL; return fcvt_buf; } #elif __SIZEOF_LONG_DOUBLE__ == 4 #include "stdio_private.h" char * fcvtl(long double invalue, int ndecimal, int *decpt, int *sign) { return fcvtf((float)invalue, ndecimal, decpt, sign); } #elif __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__ #include "stdio_private.h" char * fcvtl(long double invalue, int ndecimal, int *decpt, int *sign) { return fcvt((double)invalue, ndecimal, decpt, sign); } #endif picolibc-1.8.11/libc/stdio/fcvtl_r.c000066400000000000000000000124231513574234600172400ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #if __SIZEOF_LONG_DOUBLE__ > __SIZEOF_DOUBLE__ #define _NEED_IO_LONG_DOUBLE #include "dtoa.h" int fcvtl_r(long double invalue, int ndecimal, int *decpt, int *sign, char *buf, size_t len) { struct dtoa dtoa; int ntrailing; /* number of zeros to add after the value */ int ndigit; /* numer of generated digits */ int dtoa_decimal = ndecimal; char *digits = dtoa.digits; if (!isfinite(invalue)) { ndigit = 3; ntrailing = 0; *sign = invalue < 0; *decpt = 0; if (isnan(invalue)) digits = "nan"; else digits = "inf"; } else { /* ndecimal = digits after decimal point desired * ndigit = digits actually generated * dtoa.exp = exponent (position of decimal relative to first digit generated) */ if (ndecimal < 0) dtoa_decimal = 0; #ifdef _NEED_IO_FLOAT_LARGE ndigit = __ldtoa_engine(invalue, &dtoa, LDTOA_MAX_DIG, true, ndecimal); #elif __SIZEOF_LONG_DOUBLE__ == 8 ndigit = __dtoa_engine((FLOAT64)invalue, &dtoa, DTOA_MAX_DIG, true, ndecimal); #elif __SIZEOF_LONG_DOUBLE__ == 4 ndigit = __ftoa_engine((float)invalue, &dtoa, FTOA_MAX_DIG, true, ndecimal); #endif *sign = !!(dtoa.flags & DTOA_MINUS); /* * To compute the number of zeros added after the value, there are * three cases: * * 1. all of the generated digits are left of the decimal * point (dtoa.exp >= ndigit). We need (dtoa.exp - ndigit) * digits left of the decimal and ndecimal right of the * decimal: (dtoa.exp - ndigit) + ndecimal * * 2. some of the generated digits are right * of the decimal point (dtoa.exp < ndigit). We need * ndecimal digits total, but we have (ndigit - dtoa.exp) * already, so: ndecimal - (ndigit - dtoa.exp). * * 3. all of the generated digits are right of the decimal point * We need fewer than ndecimal digits by the magnitude of * the exponent (which is negative in this case, so: * ndecimal - (-dtoa.exp - 1) - ndigit * * These all turn out to be the same computation. Kinda cool. */ ntrailing = (dtoa.exp + 1 - ndigit) + dtoa_decimal; /* * If this value is negative, then we actually have *no* digits to * generate. In this case, we return the empty string and set the * exponent to the number of digits requested (as they're all * zero) */ if (ntrailing < 0) { ntrailing = 0; ndigit = 0; /* * Adjust exponent to reflect the desired output of ndecimal * zeros */ dtoa.exp = -(dtoa_decimal + 1); } *decpt = dtoa.exp + 1; } /* If we can't fit the whole value in the provided space, * return an error */ if ((size_t)(ndigit + ntrailing) >= len) return -1; /* Value */ memcpy(buf, digits, ndigit); buf += ndigit; /* Trailing zeros */ memset(buf, '0', ntrailing); buf += ntrailing; /* Null terminate */ buf[0] = '\0'; return 0; } #elif __SIZEOF_LONG_DOUBLE__ == 4 #include "stdio_private.h" int fcvtl_r(long double invalue, int ndecimal, int *decpt, int *sign, char *buf, size_t len) { return fcvtf_r((float)invalue, ndecimal, decpt, sign, buf, len); } #elif __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__ #include "stdio_private.h" int fcvtl_r(long double invalue, int ndecimal, int *decpt, int *sign, char *buf, size_t len) { return fcvt_r((double)invalue, ndecimal, decpt, sign, buf, len); } #endif picolibc-1.8.11/libc/stdio/fdevopen.c000066400000000000000000000104761513574234600174150ustar00rootroot00000000000000/* Copyright (c) 2002,2005, 2007 Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: fdevopen.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" /** \file */ /** \ingroup avr_stdio This function is a replacement for \c fopen(). It opens a stream for a device where the actual device implementation needs to be provided by the application. If successful, a pointer to the structure for the opened stream is returned. Reasons for a possible failure currently include that neither the \c put nor the \c get argument have been provided, thus attempting to open a stream with no IO intent at all, or that insufficient dynamic memory is available to establish a new stream. If the \c put function pointer is provided, the stream is opened with write intent. The function passed as \c put shall take two arguments, the first a character to write to the device, and the second a pointer to FILE, and shall return 0 if the output was successful, and a nonzero value if the character could not be sent to the device. If the \c get function pointer is provided, the stream is opened with read intent. The function passed as \c get shall take a pointer to FILE as its single argument, and return one character from the device, passed as an \c int type. If an error occurs when trying to read from the device, it shall return \c _FDEV_ERR. If an end-of-file condition was reached while reading from the device, \c _FDEV_EOF shall be returned. If both functions are provided, the stream is opened with read and write intent. If the \c flush function pointer is provided, then it will be called whenever the application calls the fflush function on the file. This allows the underlying I/O implementation to perform buffering as needed. fdevopen() uses calloc() (und thus malloc()) in order to allocate the storage for the new stream. \note If the macro __STDIO_FDEVOPEN_COMPAT_12 is declared before including , a function prototype for fdevopen() will be chosen that is backwards compatible with avr-libc version 1.2 and before. This is solely intented for providing a simple migration path without the need to immediately change all source code. Do not use for new code. */ static int fdevclose(FILE *f) { int ret = 0; fflush(f); free(f); return ret; } FILE * fdevopen(int (*put)(char, FILE *), int (*get)(FILE *), int (*flush)(FILE *)) { struct __file_close *cf; if (put == 0 && get == 0) return 0; if ((cf = calloc(1, sizeof(*cf))) == 0) return 0; cf->file.flags = __SCLOSE; cf->close = fdevclose; if (get != 0) { cf->file.get = get; cf->file.flags |= __SRD; } if (put != 0) { cf->file.put = put; cf->file.flush = flush; cf->file.flags |= __SWR; } return (FILE *)cf; } picolibc-1.8.11/libc/stdio/fdopen.c000066400000000000000000000045451513574234600170620ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" FILE * fdopen(int fd, const char *mode) { int stdio_flags; int open_flags; struct __file_bufio *bf; char *buf; size_t buf_size; stdio_flags = __stdio_flags(mode, &open_flags); if (stdio_flags == 0) return NULL; buf_size = bufio_get_buf_size(fd); /* Allocate file structure and necessary buffers */ bf = calloc(1, sizeof(struct __file_bufio) + buf_size); if (bf == NULL) return NULL; buf = (char *)(bf + 1); *bf = (struct __file_bufio)FDEV_SETUP_POSIX(fd, buf, buf_size, stdio_flags, __BFALL); if (open_flags & O_APPEND) (void)fseeko(&(bf->xfile.cfile.file), 0, SEEK_END); return &(bf->xfile.cfile.file); } picolibc-1.8.11/libc/stdio/feof.c000066400000000000000000000040401513574234600165140ustar00rootroot00000000000000/* Copyright (c) 2002,2005 Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: feof.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" #undef feof #undef feof_unlocked int __STDIO_UNLOCKED(feof)(FILE *stream) { return stream->flags & __SEOF; } #ifdef __STDIO_LOCKING int feof(FILE *stream) { int ret; __flockfile(stream); ret = __STDIO_UNLOCKED(feof)(stream); __funlockfile(stream); return ret; } #else #ifdef __strong_reference __strong_reference(feof, feof_unlocked); #else int feof_unlocked(FILE *stream) { return feof(stream); } #endif #endif picolibc-1.8.11/libc/stdio/ferror.c000066400000000000000000000036201513574234600170770ustar00rootroot00000000000000/* Copyright (c) 2002,2005 Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: ferror.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" #undef ferror #undef ferror_unlocked int __STDIO_UNLOCKED(ferror)(FILE *stream) { return stream->flags & __SERR; } #ifdef __STDIO_LOCKING int ferror(FILE *stream) { int ret; __flockfile(stream); ret = ferror_unlocked(stream); __funlockfile(stream); return ret; } #endif picolibc-1.8.11/libc/stdio/fflush.c000066400000000000000000000035021513574234600170660ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int fflush(FILE *stream) { int ret = 0; __flockfile(stream); if (stream->flush) ret = (stream->flush)(stream); __atomic_store_ungetc(&stream->unget, 0); __funlock_return(stream, ret); } picolibc-1.8.11/libc/stdio/fgetc.c000066400000000000000000000051171513574234600166730ustar00rootroot00000000000000/* Copyright (c) 2002, 2005, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: fgetc.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" #undef getc #undef getc_unlocked int __STDIO_UNLOCKED(getc)(FILE *stream) { int rv; __ungetc_t unget; if ((stream->flags & __SRD) == 0) { stream->flags |= __SERR; return EOF; } if ((unget = __atomic_exchange_ungetc(&stream->unget, 0)) != 0) return (unsigned char)(unget - 1); rv = stream->get(stream); if (rv < 0) { /* if != _FDEV_ERR, assume it's _FDEV_EOF */ stream->flags |= (rv == _FDEV_ERR) ? __SERR : __SEOF; return EOF; } return (unsigned char)rv; } #ifdef __STDIO_LOCKING int getc(FILE *stream) { int ret; __flockfile(stream); ret = getc_unlocked(stream); __funlockfile(stream); return ret; } #else #ifdef __strong_reference __strong_reference(getc, getc_unlocked); #else int getc_unlocked(FILE *stream) { return getc(stream); } #endif #endif #ifdef __strong_reference __strong_reference(getc, fgetc); #else int fgetc(FILE *stream) { return getc(stream); } #endif picolibc-1.8.11/libc/stdio/fgetpos.c000066400000000000000000000047251513574234600172560ustar00rootroot00000000000000/* * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * and/or other materials related to such * distribution and use acknowledge that the software was developed * by the University of California, Berkeley. The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---record position in a stream or file INDEX fgetpos INDEX _fgetpos_r SYNOPSIS #include int fgetpos(FILE *restrict <[fp]>, fpos_t *restrict <[pos]>); int fgetpos( FILE *restrict <[fp]>, fpos_t *restrict <[pos]>); DESCRIPTION Objects of type <> can have a ``position'' that records how much of the file your program has already read. Many of the <> functions depend on this position, and many change it as a side effect. You can use <> to report on the current position for a file identified by <[fp]>; <> will write a value representing that position at <<*<[pos]>>>. Later, you can use this value with <> to return the file to this position. In the current implementation, <> simply uses a character count to represent the file position; this is the same number that would be returned by <>. RETURNS <> returns <<0>> when successful. If <> fails, the result is <<1>>. Failure occurs on streams that do not support positioning; the global <> indicates this condition with the value <>. PORTABILITY <> is required by the ANSI C standard, but the meaning of the value it records is not specified beyond requiring that it be acceptable as an argument to <>. In particular, other conforming C implementations may return a different result from <> than what <> writes at <<*<[pos]>>>. No supporting OS subroutines are required. */ #include int fgetpos(FILE * __restrict fp, _fpos_t * __restrict pos) { *pos = ftell(fp); if (*pos != -1) { return 0; } return 1; } picolibc-1.8.11/libc/stdio/fgets.c000066400000000000000000000041651513574234600167150ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: fgets.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" char * fgets(char *str, int size, FILE *stream) { char *cp; int c; __flockfile(stream); if ((stream->flags & __SRD) == 0 || size <= 0) __funlock_return(stream, NULL); size--; for (c = 0, cp = str; c != '\n' && size > 0; size--, cp++) { if ((c = getc_unlocked(stream)) == EOF) { if (cp == str) __funlock_return(stream, NULL); else break; } *cp = (char)c; } *cp = '\0'; __funlock_return(stream, str); } picolibc-1.8.11/libc/stdio/fgetwc.c000066400000000000000000000051231513574234600170570ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #undef getwc #undef getwc_unlocked wint_t __STDIO_UNLOCKED(getwc)(FILE *stream) { union { wchar_t wc; char c[sizeof(wchar_t)]; } u; unsigned i; int sc; __ungetc_t unget; stream->flags |= __SWIDE; if ((stream->flags & __SRD) == 0) return WEOF; if ((unget = __atomic_exchange_ungetc(&stream->unget, 0)) != 0) return (wint_t)(unget - 1); for (i = 0; i < sizeof(wchar_t); i++) { sc = stream->get(stream); if (sc < 0) return WEOF; u.c[i] = (char)sc; } return (wint_t)u.wc; } #ifdef __STDIO_LOCKING wint_t getwc(FILE *stream) { int ret; __flockfile(stream); ret = getwc_unlocked(stream); __funlockfile(stream); return ret; } #else #ifdef __strong_reference __strong_reference(getwc, getwc_unlocked); #else wint_t getwc_unlocked(FILE *stream) { return getwc(stream); } #endif #endif #ifdef __strong_reference __strong_reference(getwc, fgetwc); #else wint_t fgetwc(FILE *stream) { return getwc(stream); } #endif picolibc-1.8.11/libc/stdio/fgetws.c000066400000000000000000000043201513574234600170750ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" wchar_t * __STDIO_UNLOCKED(fgetws)(wchar_t *str, int size, FILE *stream) { wchar_t *cp; wint_t c; if ((stream->flags & __SRD) == 0 || size <= 0) return NULL; size--; for (c = 0, cp = str; c != L'\n' && size > 0; size--, cp++) { if ((c = __STDIO_UNLOCKED(getwc)(stream)) == WEOF) return NULL; *cp = (wchar_t)c; } *cp = L'\0'; return str; } #if defined(__STDIO_LOCKING) && !defined(_FILE_INCLUDED) wchar_t * fgetws(wchar_t *str, int size, FILE *stream) { wchar_t *ret; __flockfile(stream); ret = __STDIO_UNLOCKED(fgetws)(str, size, stream); __funlockfile(stream); return ret; } #endif picolibc-1.8.11/libc/stdio/fileno.c000066400000000000000000000035511513574234600170570ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int fileno(FILE *stream) { __flockfile(stream); if (stream->flags & __SBUF) { struct __file_bufio *pf = (struct __file_bufio *)stream; __funlock_return(stream, (int)(intptr_t)(pf->ptr)); } __funlock_return(stream, -1); } picolibc-1.8.11/libc/stdio/filestrget.c000066400000000000000000000035431513574234600177540ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int __file_str_get(FILE *stream) { struct __file_str *sstream = (struct __file_str *)stream; int rv; rv = (unsigned char)*sstream->pos; if (rv == '\0') return _FDEV_EOF; sstream->pos++; return rv; } picolibc-1.8.11/libc/stdio/filestrput.c000066400000000000000000000041561513574234600200060ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int __file_str_put(char c, FILE *stream) { struct __file_str *sstream = (struct __file_str *)stream; /* The sprintf family doesn't return an error on buffer * overflow, instead it returns the total number of characters * processed but truncates the result to fit within the target * buffer. As a result, this function simply stops writing * when it reaches the end of the buffer */ if (sstream->pos != sstream->end) *sstream->pos++ = c; return (unsigned char)c; } picolibc-1.8.11/libc/stdio/filestrputalloc.c000066400000000000000000000046001513574234600210130ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int __disable_sanitizer __file_str_put_alloc(char c, FILE *stream) { struct __file_str *sstream = (struct __file_str *)stream; if (sstream->pos == sstream->end) { size_t old_size = sstream->size; char *old = POINTER_MINUS(sstream->end, old_size); size_t new_size = old_size + 32; char *new; if (sstream->alloc) new = realloc(old, new_size); else { new = malloc(new_size); if (new && old_size) memcpy(new, old, old_size); } if (!new) return EOF; sstream->size = new_size; sstream->pos = new + old_size; sstream->end = new + new_size; sstream->alloc = true; } *sstream->pos++ = c; return (unsigned char)c; } picolibc-1.8.11/libc/stdio/filewstrget.c000066400000000000000000000040001513574234600201300ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int __file_wstr_get(FILE *stream) { struct __file_str *sstream = (struct __file_str *)stream; int rv; if (((sstream->pos - sstream->end) & (sizeof(wchar_t) - 1)) == 0) { wchar_t c; memcpy(&c, sstream->pos, sizeof(wchar_t)); if (c == L'\0') return _FDEV_EOF; } rv = (unsigned char)*sstream->pos; sstream->pos++; return rv; } picolibc-1.8.11/libc/stdio/flockfile.c000066400000000000000000000033401513574234600175350ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" void flockfile(FILE *f) { #ifdef __STDIO_LOCKING __flockfile(f); #else (void)f; __LIBC_LOCK(); #endif } picolibc-1.8.11/libc/stdio/flockfile_init.c000066400000000000000000000035701513574234600205650ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #ifdef __STDIO_LOCKING void __flockfile_init(FILE *f) { /* * Use the global C library lock to ensure this * only initializes the lock once */ __LIBC_LOCK(); if (!f->lock) __lock_init_recursive(f->lock); __LIBC_UNLOCK(); } #endif picolibc-1.8.11/libc/stdio/fmemopen.c000066400000000000000000000135461513574234600174160ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #define __MALL 0x01 #define __MAPP 0x02 struct __file_mem { struct __file_ext xfile; char *buf; size_t size; /* Current size. */ size_t bufsize; /* Upper limit on size. */ size_t pos; uint8_t mflags; }; static int __fmem_put(char c, FILE *f) { struct __file_mem *mf = (struct __file_mem *)f; size_t pos = mf->mflags & __MAPP ? mf->size : mf->pos; if ((f->flags & __SWR) == 0) { return _FDEV_ERR; } else if (pos < mf->bufsize) { mf->buf[pos++] = c; if (pos > mf->size) { mf->size = pos; /* When a stream open for update (the mode argument includes '+') or * for writing only is successfully written and the write advances * the current buffer end position, a null byte shall be written at * the new buffer end position if it fits. */ if (mf->size < mf->bufsize) { mf->buf[mf->size] = '\0'; } } mf->pos = pos; return (unsigned char)c; } else { return _FDEV_EOF; } } static int __fmem_get(FILE *f) { struct __file_mem *mf = (struct __file_mem *)f; if ((f->flags & __SRD) == 0) { return _FDEV_ERR; } else if (mf->pos < mf->size) { return (unsigned char)mf->buf[mf->pos++]; } else { return _FDEV_EOF; } } static int __fmem_flush(FILE *f) { struct __file_mem *mf = (struct __file_mem *)f; if ((f->flags & __SWR) && mf->pos < mf->bufsize) { mf->buf[mf->pos] = '\0'; if (mf->pos > mf->size) { mf->size = mf->pos; } } return 0; } static off_t __fmem_seek(FILE *f, off_t pos, int whence) { struct __file_mem *mf = (struct __file_mem *)f; switch (whence) { case SEEK_SET: break; case SEEK_CUR: pos += mf->pos; break; case SEEK_END: pos += mf->size; break; } _Static_assert(sizeof(off_t) >= sizeof(size_t), "must avoid truncation"); if (pos < 0 || (off_t)mf->bufsize < pos) return EOF; mf->pos = pos; return pos; } static int __fmem_close(FILE *f) { struct __file_mem *mf = (struct __file_mem *)f; if (mf->mflags & __MALL) free(mf->buf); else __fmem_flush(f); free(f); return 0; } FILE * fmemopen(void *buf, size_t size, const char *mode) { int stdio_flags; int open_flags; uint8_t mflags = 0; size_t initial_pos = 0; size_t initial_size; struct __file_mem *mf; stdio_flags = __stdio_flags(mode, &open_flags); if (stdio_flags == 0 || size == 0) { errno = EINVAL; return NULL; } /* Allocate file structure and necessary buffers */ mf = calloc(1, sizeof(struct __file_mem)); if (mf == NULL) return NULL; if (buf == NULL) { /* POSIX says return EINVAL if: The buf argument is a null pointer and * the mode argument does not include a '+' character. */ if ((stdio_flags & (__SRD | __SWR)) != (__SRD | __SWR)) { free(mf); errno = EINVAL; return NULL; } buf = malloc(size); if (!buf) { free(mf); errno = ENOMEM; return NULL; } *((char *)buf) = '\0'; mflags |= __MALL; } if (open_flags & O_CREAT) { if (open_flags & O_APPEND) { /* For append the position is set to the first NUL byte or the end. */ initial_pos = (mflags & __MALL) ? 0 : strnlen(buf, size); initial_size = initial_pos; mflags |= __MAPP; } else { initial_size = 0; /* w+ mode truncates the buffer, writing NUL */ if ((open_flags & O_ACCMODE) == O_RDWR) *((char *)buf) = '\0'; } } else { initial_size = size; } *mf = (struct __file_mem) { .xfile = FDEV_SETUP_EXT(__fmem_put, __fmem_get, __fmem_flush, __fmem_close, __fmem_seek, NULL, stdio_flags), .buf = buf, .size = initial_size, .bufsize = size, .pos = initial_pos, .mflags = mflags, }; return (FILE *)mf; } picolibc-1.8.11/libc/stdio/fopen.c000066400000000000000000000037721513574234600167170ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" FILE * fopen(const char *pathname, const char *mode) { FILE *ret; int fd; int stdio_flags; int open_flags; stdio_flags = __stdio_flags(mode, &open_flags); if (stdio_flags == 0) return NULL; fd = open(pathname, open_flags, 0666); if (fd < 0) return NULL; ret = fdopen(fd, mode); if (ret == NULL) close(fd); return ret; } picolibc-1.8.11/libc/stdio/fprintf.c000066400000000000000000000034221513574234600172500ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: fprintf.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int fprintf(FILE *stream, const char *fmt, ...) { va_list ap; int i; va_start(ap, fmt); i = vfprintf(stream, fmt, ap); va_end(ap); return i; } picolibc-1.8.11/libc/stdio/fputc.c000066400000000000000000000045161513574234600167260ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: fputc.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" #undef putc #undef putc_unlocked int __STDIO_UNLOCKED(putc)(int c, FILE *stream) { if ((stream->flags & __SWR) == 0) return EOF; if (stream->put(c, stream) < 0) { stream->flags |= __SERR; return EOF; } return (unsigned char)c; } #ifdef __STDIO_LOCKING int putc(int c, FILE *stream) { int ret; __flockfile(stream); ret = putc_unlocked(c, stream); __funlockfile(stream); return ret; } #else #ifdef __strong_reference __strong_reference(putc, putc_unlocked); #else int putc_unlocked(int c, FILE *stream) { return putc(c, stream); } #endif #endif #ifdef __strong_reference __strong_reference(putc, fputc); #else int fputc(int c, FILE *stream) { return putc(c, stream); } #endif picolibc-1.8.11/libc/stdio/fputs.c000066400000000000000000000040041513574234600167360ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: fputs.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int fputs(const char *str, FILE *stream) { int (*put)(char, struct __file *); char c; int ret = EOF; __flockfile(stream); if ((stream->flags & __SWR) == 0) goto fail; put = stream->put; while ((c = *str++) != '\0') if (put(c, stream) < 0) { stream->flags |= __SERR; goto fail; } ret = 0; fail: __funlock_return(stream, ret); } picolibc-1.8.11/libc/stdio/fputwc.c000066400000000000000000000050501513574234600171070ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #undef putwc #undef putwc_unlocked wint_t __STDIO_UNLOCKED(putwc)(wchar_t c, FILE *stream) { union { wchar_t wc; char c[sizeof(wchar_t)]; } u; unsigned i; __flockfile(stream); stream->flags |= __SWIDE; if ((stream->flags & __SWR) == 0) __funlock_return(stream, WEOF); u.wc = c; for (i = 0; i < sizeof(wchar_t); i++) if (stream->put(u.c[i], stream) < 0) __funlock_return(stream, WEOF); __funlock_return(stream, (wint_t)c); } #ifdef __STDIO_LOCKING wint_t putwc(wchar_t c, FILE *stream) { wint_t ret; __flockfile(stream); ret = putwc_unlocked(c, stream); __funlockfile(stream); return ret; } #else #ifdef __strong_reference __strong_reference(putwc, putwc_unlocked); #else wint_t putwc_unlocked(wchar_t c, FILE *stream) { return putwc(c, stream); } #endif #endif #ifdef __strong_reference __strong_reference(putwc, fputwc); #else wint_t fputwc(wchar_t c, FILE *stream) { return putwc(c, stream); } #endif picolibc-1.8.11/libc/stdio/fputws.c000066400000000000000000000036511513574234600171340ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: fputs.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int fputws(const wchar_t *str, FILE *stream) { wchar_t c; int rv = 0; __flockfile(stream); if ((stream->flags & __SWR) == 0) __funlock_return(stream, EOF); while ((c = *str++) != L'\0') if (putwc_unlocked(c, stream) == WEOF) rv = EOF; __funlock_return(stream, rv); } picolibc-1.8.11/libc/stdio/fread.c000066400000000000000000000110211513574234600166530ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: fread.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" #ifdef __FAST_BUFIO #include "../stdlib/mul_overflow.h" #endif extern FILE * const stdin __weak; extern FILE * const stdout __weak; size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) { size_t i, j; uint8_t *cp = (uint8_t *)ptr; int c; __flockfile(stream); if ((stream->flags & __SRD) == 0 || size == 0) __funlock_return(stream, 0); #ifdef __FAST_BUFIO size_t bytes; if ((stream->flags & __SBUF) != 0 && !mul_overflow(size, nmemb, &bytes) && bytes > 0) { struct __file_bufio *bf = (struct __file_bufio *)stream; __ungetc_t unget; bool flushed = false; again: __bufio_lock(stream); __bufio_setdir_locked(stream, __SRD); /* Deal with any pending unget */ if ((unget = __atomic_exchange_ungetc(&stream->unget, 0)) != 0) { *cp++ = (unget - 1); bytes--; } while (bytes) { int this_time = bf->len - bf->off; if (this_time) { /* Drain any buffered data */ if (bytes < (size_t)this_time) this_time = bytes; memcpy(cp, bf->buf + bf->off, this_time); bf->off += this_time; cp += this_time; bytes -= this_time; } else { /* Flush stdout if reading from stdin */ if (!flushed) { flushed = true; if (&stdin != NULL && &stdout != NULL && stream == stdin) { __bufio_unlock(stream); fflush(stdout); goto again; } } if (bytes < (size_t)bf->size) { /* Small reads go through the buffer */ int ret = __bufio_fill_locked(stream); if (ret) { stream->flags |= (ret == _FDEV_ERR) ? __SERR : __SEOF; break; } } else { /* Flush any buffered data */ bf->len = 0; bf->off = 0; /* Large reads go directly to the destination */ ssize_t len = bufio_read(bf, cp, bytes); if (len <= 0) { stream->flags |= (len < 0) ? __SERR : __SEOF; break; } cp += len; bytes -= len; bf->pos += len; } } } __bufio_unlock(stream); __funlock_return(stream, (cp - (uint8_t *)ptr) / size); } #endif for (i = 0; i < nmemb; i++) for (j = 0; j < size; j++) { c = getc_unlocked(stream); if (c == EOF) __funlock_return(stream, i); *cp++ = (uint8_t)c; } __funlock_return(stream, i); } picolibc-1.8.11/libc/stdio/freopen.c000066400000000000000000000060001513574234600172310ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" FILE * freopen(const char *pathname, const char *mode, FILE *stream) { FILE *ret = NULL; struct __file_bufio *pf = (struct __file_bufio *)stream; int fd; int stdio_flags; int open_flags; int buf_size; __flockfile(stream); /* Can't reopen FILEs which aren't buffered */ if (!(stream->flags & __SBUF)) goto exit; stdio_flags = __stdio_flags(mode, &open_flags); if (stdio_flags == 0) goto exit; if (pathname != NULL) { fd = open(pathname, open_flags, 0666); if (fd < 0) goto exit; } else fd = (int)(intptr_t)(pf->ptr); fflush(stream); __bufio_lock(stream); if (pathname != NULL) close((int)(intptr_t)(pf->ptr)); stream->flags = (stream->flags & ~(__SRD | __SWR | __SERR | __SEOF)) | stdio_flags; pf->pos = 0; pf->ptr = (void *)(intptr_t)(fd); /* Switch to POSIX backend */ pf->read_int = read; pf->write_int = write; pf->lseek_int = lseek; pf->close_int = close; /* Reset buffer mode and size */ buf_size = bufio_get_buf_size(fd); if (buf_size != pf->size || (pf->bflags & __BLBF)) (pf->xfile.setvbuf ? pf->xfile.setvbuf : __bufio_setvbuf)(stream, NULL, _IOFBF, buf_size); ret = stream; __bufio_unlock(stream); exit: __funlock_return(stream, ret); } picolibc-1.8.11/libc/stdio/fscanf.c000066400000000000000000000034171513574234600170440ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: fscanf.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int fscanf(FILE *stream, const char *fmt, ...) { va_list ap; int i; va_start(ap, fmt); i = vfscanf(stream, fmt, ap); va_end(ap); return i; } picolibc-1.8.11/libc/stdio/fseek.c000066400000000000000000000042531513574234600167000ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #ifndef FSEEK #define FSEEK fseek #define FSEEK_TYPE long #endif int FSEEK(FILE *stream, FSEEK_TYPE offset, int whence) { struct __file_ext *xf = (struct __file_ext *)stream; __flockfile(stream); if ((stream->flags & __SEXT) && xf->seek) { if ((xf->seek)(stream, (__off_t)offset, whence) >= 0) { stream->flags &= ~__SEOF; (void)__atomic_exchange_ungetc(&stream->unget, 0); __funlock_return(stream, 0); } __funlock_return(stream, -1); } errno = ESPIPE; __funlock_return(stream, -1); } picolibc-1.8.11/libc/stdio/fseeko.c000066400000000000000000000032311513574234600170520ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define FSEEK fseeko #define FSEEK_TYPE __off_t #include "fseek.c" picolibc-1.8.11/libc/stdio/fsetpos.c000066400000000000000000000042151513574234600172640ustar00rootroot00000000000000/* * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * and/or other materials related to such * distribution and use acknowledge that the software was developed * by the University of California, Berkeley. The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---restore position of a stream or file INDEX fsetpos INDEX _fsetpos_r SYNOPSIS #include int fsetpos(FILE *<[fp]>, const fpos_t *<[pos]>); int fsetpos( FILE *<[fp]>, const fpos_t *<[pos]>); DESCRIPTION Objects of type <> can have a ``position'' that records how much of the file your program has already read. Many of the <> functions depend on this position, and many change it as a side effect. You can use <> to return the file identified by <[fp]> to a previous position <<*<[pos]>>> (after first recording it with <>). See <> for a similar facility. RETURNS <> returns <<0>> when successful. If <> fails, the result is <<1>>. The reason for failure is indicated in <>: either <> (the stream identified by <[fp]> doesn't support repositioning) or <> (invalid file position). PORTABILITY ANSI C requires <>, but does not specify the nature of <<*<[pos]>>> beyond identifying it as written by <>. Supporting OS subroutines required: <>, <>, <>, <>, <>, <>, <>. */ #include int fsetpos(FILE *iop, const _fpos_t *pos) { int x = fseek(iop, *pos, SEEK_SET); if (x != 0) return 1; return 0; } picolibc-1.8.11/libc/stdio/ftell.c000066400000000000000000000041131513574234600167040ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #ifndef FTELL #define FTELL ftell #define FTELL_TYPE long #endif FTELL_TYPE FTELL(FILE *stream) { struct __file_ext *xf = (struct __file_ext *)stream; __flockfile(stream); if ((stream->flags & __SEXT) && xf->seek) { FTELL_TYPE ret = (FTELL_TYPE)(xf->seek)(stream, 0, SEEK_CUR); if (__atomic_load_ungetc(&stream->unget) != 0) ret--; __funlock_return(stream, ret); } errno = ESPIPE; __funlock_return(stream, -1); } picolibc-1.8.11/libc/stdio/ftello.c000066400000000000000000000032311513574234600170630ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define FTELL_TYPE __off_t #define FTELL ftello #include "ftell.c" picolibc-1.8.11/libc/stdio/ftoa_engine.c000066400000000000000000000167131513574234600200650ustar00rootroot00000000000000/* Copyright (c) 2005, Dmitry Xmelkov All rights reserved. Rewritten in C by Soren Kuula Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _NEED_IO_FLOAT32 #include "dtoa.h" /* * 2^b ~= f * r * 10^e * where * i = b div 8 * r = 2^(b mod 8) * f = factorTable[i] * e = exponentTable[i] */ static const int8_t exponentTable[32] = { -36, -33, -31, -29, -26, -24, -21, -19, -17, -14, -12, -9, -7, -4, -2, 0, 3, 5, 8, 10, 12, 15, 17, 20, 22, 24, 27, 29, 32, 34, 36, 39 }; static const uint32_t factorTable[32] = { 2295887404UL, 587747175UL, 1504632769UL, 3851859889UL, 986076132UL, 2524354897UL, 646234854UL, 1654361225UL, 4235164736UL, 1084202172UL, 2775557562UL, 710542736UL, 1818989404UL, 465661287UL, 1192092896UL, 3051757813UL, 781250000UL, 2000000000UL, 512000000UL, 1310720000UL, 3355443200UL, 858993459UL, 2199023256UL, 562949953UL, 1441151881UL, 3689348815UL, 944473297UL, 2417851639UL, 618970020UL, 1584563250UL, 4056481921UL, 1038459372UL }; #define max(a, b) \ ({ \ __typeof(a) _a = a; \ __typeof(b) _b = b; \ _a > _b ? _a : _b; \ }) #define min(a, b) \ ({ \ __typeof(a) _a = a; \ __typeof(b) _b = b; \ _a < _b ? _a : _b; \ }) int __ftoa_engine(uint32_t val, struct dtoa *ftoa, int maxDigits, bool fmode, int maxDecimals) { uint8_t flags = 0; uint32_t frac = val & 0x007fffffUL; if (maxDigits > FTOA_MAX_DIG) maxDigits = FTOA_MAX_DIG; /* Read the sign, shift the exponent in place and delete it from frac. */ if (val & ((uint32_t)1 << 31)) flags = DTOA_MINUS; uint8_t exp = val >> 23; ftoa->exp = 0; /* * Test for easy cases, zero and NaN */ if (exp == 0 && frac == 0) { flags |= DTOA_ZERO; ftoa->digits[0] = '0'; maxDigits = 1; } else if (exp == 0xff) { if (frac == 0) flags |= DTOA_INF; else flags |= DTOA_NAN; } else { /* The implicit leading 1 is made explicit, except if value * subnormal, in which case exp needs to be adjusted by one */ if (exp == 0) exp = 1; else frac |= (1UL << 23); uint8_t idx = exp >> 3; int8_t exp10 = exponentTable[idx]; /* * We COULD try making the multiplication in situ, where we make * frac and a 64 bit int overlap in memory and select/weigh the * upper 32 bits that way. For starters, this is less risky: */ uint64_t prod = (uint64_t)frac * (uint64_t)factorTable[idx]; /* * The expConvFactorTable are factor are correct iff the lower 3 exponent * bits are 1 (=7). Else we need to compensate by divding frac. * If the lower 3 bits are 7 we are right. * If the lower 3 bits are 6 we right-shift once * .. * If the lower 3 bits are 0 we right-shift 7x */ prod >>= (15 - (exp & 7)); /* * Now convert to decimal. */ uint8_t hadNonzeroDigit = 0; /* have seen a non-zero digit flag */ uint8_t outputIdx = 0; uint64_t decimal = 100000000000000ull; uint8_t saveMaxDigits = maxDigits; do { /* Compute next digit */ char digit = '0'; if (prod != 0) digit += prod / decimal; if (!hadNonzeroDigit) { /* Don't return results with a leading zero! Instead * skip those and decrement exp10 accordingly. */ if (digit == '0') { exp10--; if (prod != 0) prod = prod % decimal; decimal /= 10; continue; } /* Found the first non-zero digit */ hadNonzeroDigit = 1; /* If limiting decimals... */ if (fmode) { maxDigits = min(maxDigits, max(maxDecimals < 0, maxDecimals + exp10 + 1)); if (maxDigits == 0) break; } } if (prod != 0) prod = prod % decimal; decimal /= 10; /* Now we have a digit. */ if (digit < '0' + 10) { /* normal case. */ ftoa->digits[outputIdx] = digit; } else { /* * Uh, oh. Something went wrong with our conversion. Write * 9s and use the round-up code to report back to the caller * that we've carried */ for (outputIdx = 0; outputIdx < maxDigits; outputIdx++) ftoa->digits[outputIdx] = '9'; goto round_up; } outputIdx++; } while (outputIdx < maxDigits); /* Rounding: */ decimal *= 10; if (prod >= (decimal >> 1)) { uint8_t rounded; round_up: rounded = 0; while (outputIdx != 0) { /* Increment digit, check if we're done */ if (++ftoa->digits[outputIdx - 1] < '0' + 10) { rounded = 1; break; } ftoa->digits[--outputIdx] = '0'; /* and the loop continues, carrying to next digit. */ } if (!rounded) { /* Rounded past the first digit; * reset the leading digit to 1, * bump exp and tell the caller we've carried. * The remaining digits will already be '0', * so we don't need to mess with them */ ftoa->digits[0] = '1'; exp10++; if (fmode) maxDigits = min(saveMaxDigits, max(1, maxDecimals + exp10 + 1)); } } ftoa->exp = exp10; } ftoa->flags = flags; return maxDigits; } picolibc-1.8.11/libc/stdio/ftoa_ryu.c000066400000000000000000000275211513574234600174360ustar00rootroot00000000000000// Copyright 2018 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. // Runtime compiler options: // -DRYU_DEBUG Generate verbose debugging output to stdout. #define _NEED_IO_FLOAT32 #include "dtoa.h" #include "ryu/ryu.h" #include "ryu/common.h" #include "ryu/f2s_intrinsics.h" #include "ryu/digit_table.h" #define FLOAT_MANTISSA_BITS 23 #define FLOAT_EXPONENT_BITS 8 #define FLOAT_BIAS 127 // Returns the number of decimal digits in v, which must not contain more than 9 digits. static int decimalLength9(const uint32_t v) { int len = 1; uint32_t c = 10; while (c <= v) { len++; c = (c << 3) + (c << 1); } return len; } // A floating decimal representing m * 10^e. typedef struct floating_decimal_32 { uint32_t mantissa; // Decimal exponent's range is -45 to 38 // inclusive, and can fit in a short if needed. int16_t exponent; int16_t olength; } floating_decimal_32; static inline floating_decimal_32 f2d(const uint32_t ieeeMantissa, const uint32_t ieeeExponent, int max_digits, bool fmode, int max_decimals) { int32_t e2; uint32_t m2; if (ieeeExponent == 0) { // We subtract 2 so that the bounds computation has 2 additional bits. e2 = 1 - FLOAT_BIAS - FLOAT_MANTISSA_BITS - 2; m2 = ieeeMantissa; } else { e2 = (int32_t)ieeeExponent - FLOAT_BIAS - FLOAT_MANTISSA_BITS - 2; m2 = ((uint32_t)1u << FLOAT_MANTISSA_BITS) | ieeeMantissa; } const bool even = (m2 & 1) == 0; const bool acceptBounds = even; bool truncate_max = false; #ifdef RYU_DEBUG printf("-> %u * 2^%d\n", m2, e2 + 2); #endif // Step 2: Determine the interval of valid decimal representations. const uint32_t mv = 4 * m2; const uint32_t mp = 4 * m2 + 2; // Implicit bool -> int conversion. True is 1, false is 0. const uint32_t mmShift = ieeeMantissa != 0 || ieeeExponent <= 1; const uint32_t mm = 4 * m2 - 1 - mmShift; // Step 3: Convert to a decimal power base using 64-bit arithmetic. uint32_t vr, vp, vm; int32_t e10; bool vmIsTrailingZeros = false; bool vrIsTrailingZeros = false; uint8_t lastRemovedDigit = 0; if (e2 >= 0) { const uint32_t q = log10Pow2(e2); e10 = (int32_t)q; const int32_t k = FLOAT_POW5_INV_BITCOUNT + pow5bits((int32_t)q) - 1; const int32_t i = -e2 + (int32_t)q + k; vr = mulPow5InvDivPow2(mv, q, i); vp = mulPow5InvDivPow2(mp, q, i); vm = mulPow5InvDivPow2(mm, q, i); #ifdef RYU_DEBUG printf("%u * 2^%d / 10^%u\n", mv, e2, q); printf("V+=%u\nV =%u\nV-=%u\n", vp, vr, vm); #endif if (q != 0 && (vp - 1) / 10 <= vm / 10) { // We need to know one removed digit even if we are not going to loop below. We could // use q = X - 1 above, except that would require 33 bits for the result, and we've // found that 32-bit arithmetic is faster even on 64-bit machines. const int32_t l = FLOAT_POW5_INV_BITCOUNT + pow5bits((int32_t)(q - 1)) - 1; lastRemovedDigit = (uint8_t)(mulPow5InvDivPow2(mv, q - 1, -e2 + (int32_t)q - 1 + l) % 10); } if (q <= 9) { // The largest power of 5 that fits in 24 bits is 5^10, but q <= 9 seems to be safe as // well. Only one of mp, mv, and mm can be a multiple of 5, if any. if (mv % 5 == 0) { vrIsTrailingZeros = multipleOfPowerOf5_32(mv, q); } else if (acceptBounds) { vmIsTrailingZeros = multipleOfPowerOf5_32(mm, q); } else { vp -= multipleOfPowerOf5_32(mp, q); } } } else { const uint32_t q = log10Pow5(-e2); e10 = (int32_t)q + e2; const int32_t i = -e2 - (int32_t)q; const int32_t k = pow5bits(i) - FLOAT_POW5_BITCOUNT; int32_t j = (int32_t)q - k; vr = mulPow5divPow2(mv, (uint32_t)i, j); vp = mulPow5divPow2(mp, (uint32_t)i, j); vm = mulPow5divPow2(mm, (uint32_t)i, j); #ifdef RYU_DEBUG printf("%u * 5^%d / 10^%u\n", mv, -e2, q); printf("%u %d %d %d\n", q, i, k, j); printf("V+=%u\nV =%u\nV-=%u\n", vp, vr, vm); #endif if (q != 0 && (vp - 1) / 10 <= vm / 10) { j = (int32_t)q - 1 - (pow5bits(i + 1) - FLOAT_POW5_BITCOUNT); lastRemovedDigit = (uint8_t)(mulPow5divPow2(mv, (uint32_t)(i + 1), j) % 10); } if (q <= 1) { // {vr,vp,vm} is trailing zeros if {mv,mp,mm} has at least q trailing 0 bits. // mv = 4 * m2, so it always has at least two trailing 0 bits. vrIsTrailingZeros = true; if (acceptBounds) { // mm = mv - 1 - mmShift, so it has 1 trailing 0 bit iff mmShift == 1. vmIsTrailingZeros = mmShift == 1; } else { // mp = mv + 2, so it always has at least one trailing 0 bit. --vp; } } else if (q < 31) { // TODO(ulfjack): Use a tighter bound here. vrIsTrailingZeros = multipleOfPowerOf2_32(mv, q - 1); #ifdef RYU_DEBUG printf("vr is trailing zeros=%s\n", vrIsTrailingZeros ? "true" : "false"); #endif } } #ifdef RYU_DEBUG printf("e10=%d\n", e10); printf("V+=%u\nV =%u\nV-=%u\n", vp, vr, vm); printf("vm is trailing zeros=%s\n", vmIsTrailingZeros ? "true" : "false"); printf("vr is trailing zeros=%s\n", vrIsTrailingZeros ? "true" : "false"); #endif // Step 4: Find the shortest decimal representation in the interval of valid representations. int32_t removed = 0; uint32_t output; /* If limiting decimals, then limit the max digits * to no more than the number of digits left of the decimal * plus the number of digits right of the decimal * * exp: exponent value. If negative, there are * -exp - 1 zeros left of the first non-zero * digit in 'f' format. If non-negative, * there are exp digits to the left of * the decimal point * * max_decimals: Only used in 'f' format. Round to this many * digits to the right of the decimal point * (left if negative) * * max_digits: We can't convert more than this number of digits given * the limits of the buffer */ int save_max_digits = max_digits; if (fmode) { int exp = e10 + decimalLength9(vr) - 1; /* * This covers two cases: * * When exp is < 0, there are -exp-1 zeros taking up * space before we can display any of the real digits, * so we have to subtract those off max_decimals before * we round that (max_decimals - (-exp - 1)). This * may end up less than zero, in which case we have * no digits to display. * * When exp >= 0, there are exp + 1 digits left of the * decimal point *plus* max_decimals right of the * decimal point that need to be generated * * A single expression gives the right answer in both * cases, which is kinda cool * * When called from fcvt, max_decimals may be less * than zero, indicating that we want to round left of * the decimal point. In that case, make sure we generate * at least one digit */ max_digits = min_int(max_digits, max_int(max_decimals < 0, max_decimals + exp + 1)); } for (;;) { if (vp / 10 <= vm / 10) { if (decimalLength9(vr) <= max_digits || (max_digits == 0 && vr == 0)) break; else truncate_max = true; } #ifdef __clang__ // https://bugs.llvm.org/show_bug.cgi?id=23106 // The compiler does not realize that vm % 10 can be computed from vm / 10 // as vm - (vm / 10) * 10. vmIsTrailingZeros &= vm - (vm / 10) * 10 == 0; #else vmIsTrailingZeros &= vm % 10 == 0; #endif vrIsTrailingZeros &= lastRemovedDigit == 0; lastRemovedDigit = (uint8_t)(vr % 10); vr /= 10; vp /= 10; vm /= 10; ++removed; } #ifdef RYU_DEBUG printf("V+=%u\nV =%u\nV-=%u\n", vp, vr, vm); printf("d-10=%s\n", vmIsTrailingZeros ? "true" : "false"); #endif if (vmIsTrailingZeros) { while (vm % 10 == 0) { vrIsTrailingZeros &= lastRemovedDigit == 0; lastRemovedDigit = (uint8_t)(vr % 10); vr /= 10; vp /= 10; vm /= 10; ++removed; } } #ifdef RYU_DEBUG printf("%u %d\n", vr, lastRemovedDigit); printf("vr is trailing zeros=%s\n", vrIsTrailingZeros ? "true" : "false"); #endif if (vrIsTrailingZeros && lastRemovedDigit == 5 && vr % 2 == 0) { // Round even if the exact number is .....50..0. lastRemovedDigit = 4; } // We need to take vr + 1 if vr is outside bounds or we need to round up. output = vr; e10 += removed; uint8_t carry = ((!truncate_max && vr == vm && (!acceptBounds || !vmIsTrailingZeros)) || lastRemovedDigit >= 5); output += carry; int len = decimalLength9(output); if (carry) { /* This can only happen if output has carried out of the top digit */ if (len > max_digits) { /* Recompute max digits in this case */ if (fmode) { int exp = e10 + len - 1; max_digits = min_int(save_max_digits, max_int(1, max_decimals + exp + 1)); } if (len > max_digits) { output += 5; output /= 10; e10++; len--; } } } if (len > max_digits) len = max_digits; #ifdef RYU_DEBUG printf("V+=%u\nV =%u\nV-=%u\n", vp, vr, vm); printf("O=%u\n", output); printf("EXP=%d\n", exp); #endif floating_decimal_32 fd; fd.exponent = e10; fd.olength = len; fd.mantissa = output; return fd; } int __ftoa_engine(uint32_t bits, struct dtoa *dtoa, int max_digits, bool fmode, int max_decimals) { // Decode bits into sign, mantissa, and exponent. const bool ieeeSign = ((bits >> (FLOAT_MANTISSA_BITS + FLOAT_EXPONENT_BITS)) & 1) != 0; const uint64_t ieeeMantissa = bits & ((1ull << FLOAT_MANTISSA_BITS) - 1); const uint32_t ieeeExponent = (uint32_t)((bits >> FLOAT_MANTISSA_BITS) & ((1u << FLOAT_EXPONENT_BITS) - 1)); uint8_t flags = 0; if (ieeeSign) flags |= DTOA_MINUS; if (ieeeExponent == 0 && ieeeMantissa == 0) { flags |= DTOA_ZERO; dtoa->digits[0] = '0'; dtoa->flags = flags; dtoa->exp = 0; return 1; } if (ieeeExponent == ((1u << FLOAT_EXPONENT_BITS) - 1u)) { if (ieeeMantissa) { flags |= DTOA_NAN; } else { flags |= DTOA_INF; } dtoa->flags = flags; return 0; } floating_decimal_32 v; v = f2d(ieeeMantissa, ieeeExponent, max_digits, fmode, max_decimals); uint32_t mant = v.mantissa; int32_t olength = v.olength; int32_t exp = v.exponent + olength - 1; int i; for (i = 0; i < olength; i++) { dtoa->digits[olength - i - 1] = (mant % 10) + '0'; mant /= 10; } dtoa->exp = exp; dtoa->flags = flags; return olength; } picolibc-1.8.11/libc/stdio/ftox_engine.c000066400000000000000000000031761513574234600201130ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2023 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define DTOX_SIZE 4 #include "dtox_engine.c" picolibc-1.8.11/libc/stdio/ftrylockfile.c000066400000000000000000000037261513574234600203040ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" /* * This only serializes with other threads also using flockfile, * but it's about as good as we can reasonably manage without * actually adding per-file locking to every API. We also * don't have any try-lock ability in the picolibc lock API, so * we're stuck just blocking. */ int ftrylockfile(FILE *f) { (void)f; __LIBC_LOCK(); return 0; } picolibc-1.8.11/libc/stdio/funlockfile.c000066400000000000000000000033461513574234600201060ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" void funlockfile(FILE *f) { #ifdef __STDIO_LOCKING __funlockfile(f); #else (void)f; __LIBC_UNLOCK(); #endif } picolibc-1.8.11/libc/stdio/funopen.c000066400000000000000000000047401513574234600172560ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include #include FILE * funopen(const void *cookie, ssize_t (*readfn)(void *cookie, void *buf, size_t n), ssize_t (*writefn)(void *cookie, const void *buf, size_t n), __off_t (*seekfn)(void *cookie, __off_t off, int whence), int (*closefn)(void *cookie)) { struct __file_bufio *bf; char *buf; int open_flags = 0; if (readfn) open_flags |= __SRD; if (writefn) open_flags |= __SWR; /* Allocate file structure and necessary buffers */ bf = calloc(1, sizeof(struct __file_bufio) + BUFSIZ); if (bf == NULL) return NULL; buf = (char *)(bf + 1); *bf = (struct __file_bufio)FDEV_SETUP_BUFIO_PTR(cookie, buf, BUFSIZ, readfn, writefn, seekfn, closefn, open_flags, __BFALL); return (FILE *)bf; } picolibc-1.8.11/libc/stdio/fwide.c000066400000000000000000000035211513574234600166760ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int fwide(FILE *stream, int mode) { __flockfile(stream); if (mode != 0) stream->flags = (stream->flags & ~__SWIDE) | ((mode > 0) ? __SWIDE : 0); __funlock_return(stream, (stream->flags & __SWIDE) ? 1 : -1); } picolibc-1.8.11/libc/stdio/fwprintf.c000066400000000000000000000034271513574234600174440ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: fprintf.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int fwprintf(FILE *stream, const wchar_t *fmt, ...) { va_list ap; int i; va_start(ap, fmt); i = vfwprintf(stream, fmt, ap); va_end(ap); return i; } picolibc-1.8.11/libc/stdio/fwrite.c000066400000000000000000000072651513574234600171110ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: fwrite.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" #ifdef __FAST_BUFIO #include "../stdlib/mul_overflow.h" #endif size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) { size_t i, j; const uint8_t *cp = (const uint8_t *)ptr; __flockfile(stream); if ((stream->flags & __SWR) == 0 || size == 0) __funlock_return(stream, 0); #ifdef __FAST_BUFIO size_t bytes; struct __file_bufio *bf = (struct __file_bufio *)stream; if ((stream->flags & __SBUF) != 0 && (bf->bflags & __BLBF) == 0 && !mul_overflow(size, nmemb, &bytes) && bytes > 0) { __bufio_lock(stream); __bufio_setdir_locked(stream, __SWR); if (bytes < (unsigned)bf->size) { /* Small writes go through the buffer. */ while (bytes) { int this_time = bf->size - bf->len; if (this_time == 0) { int ret = __bufio_flush_locked(stream); if (ret) { stream->flags |= ret; break; } } if ((unsigned)this_time > bytes) this_time = bytes; memcpy(bf->buf + bf->len, cp, this_time); bf->len += this_time; cp += this_time; bytes -= this_time; } } else { /* Large writes go direct. */ if (__bufio_flush_locked(stream) >= 0) { while (bytes) { ssize_t len = bufio_write(bf, cp, bytes); if (len <= 0) { stream->flags |= _FDEV_ERR; break; } bytes -= len; cp += len; bf->pos += len; } } } __bufio_unlock(stream); __funlock_return(stream, (cp - (uint8_t *)ptr) / size); } #endif for (i = 0; i < nmemb; i++) for (j = 0; j < size; j++) if (stream->put(*cp++, stream) < 0) __funlock_return(stream, i); __funlock_return(stream, i); } picolibc-1.8.11/libc/stdio/fwscanf.c000066400000000000000000000033331513574234600172300ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int fwscanf(FILE *stream, const wchar_t *fmt, ...) { va_list ap; int i; va_start(ap, fmt); i = vfwscanf(stream, fmt, ap); va_end(ap); return i; } picolibc-1.8.11/libc/stdio/gcvt.c000066400000000000000000000033421513574234600165440ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" char * gcvt(double invalue, int ndigit, char *buf) { __d_sprintf(buf, "%.*g", ndigit, invalue); return buf; } picolibc-1.8.11/libc/stdio/gcvtf.c000066400000000000000000000033621513574234600167140ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" char * gcvtf(float invalue, int ndigit, char *buf) { __f_sprintf(buf, "%.*g", ndigit, __printf_float(invalue)); return buf; } picolibc-1.8.11/libc/stdio/gcvtl.c000066400000000000000000000033511513574234600167200ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" char * gcvtl(long double invalue, int ndigit, char *buf) { __d_sprintf(buf, "%.*Lg", ndigit, invalue); return buf; } picolibc-1.8.11/libc/stdio/getchar.c000066400000000000000000000036541513574234600172240ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: getchar.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" #undef getchar int getchar(void) { return getc(stdin); } #undef getchar_unlocked #ifdef __STDIO_LOCKING int getchar_unlocked(void) { return getc_unlocked(stdin); } #else #ifdef __strong_reference __strong_reference(getchar, getchar_unlocked); #else int getchar_unlocked(void) { return getchar(); } #endif #endif picolibc-1.8.11/libc/stdio/getdelim.c000066400000000000000000000046261513574234600174010ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2023 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #define INCR 16 _ssize_t getdelim(char ** restrict lineptr, size_t * restrict nptr, int delim, FILE * restrict stream) { char *line = *lineptr; size_t n = *nptr; _ssize_t count = 0; __flockfile(stream); for (;;) { int c = getc_unlocked(stream); if (c == EOF) break; if (count >= (_ssize_t)n) { size_t newsize = n + INCR; char *newline = realloc(line, newsize); if (newline == NULL) { count = -1; break; } line = newline; n = newsize; } line[count++] = c; if (c == delim) { line[count] = '\0'; break; } } *lineptr = line; *nptr = n; __funlock_return(stream, count); } picolibc-1.8.11/libc/stdio/getline.c000066400000000000000000000033671513574234600172370ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" _ssize_t getline(char ** restrict lineptr, size_t * restrict n, FILE * restrict stream) { return getdelim(lineptr, n, '\n', stream); } picolibc-1.8.11/libc/stdio/gets.c000066400000000000000000000041471513574234600165470ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: gets.c 1944 2009-04-01 23:12:20Z arcanum $ */ #define _PICOLIBC_USE_DEPRECATED_GETS #include "stdio_private.h" char * gets(char *str) { FILE *stream = stdin; char *cp = str; __flockfile(stream); for (;;) { int c = getc_unlocked(stream); switch (c) { case EOF: if (ferror(stream) || cp == str) __funlock_return(stream, NULL); __fallthrough; case '\n': *cp = '\0'; __funlock_return(stream, str); default: *cp++ = (char)c; break; } } } picolibc-1.8.11/libc/stdio/getwchar.c000066400000000000000000000031601513574234600174030ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #undef getwchar wint_t getwchar(void) { return getwc(stdin); } picolibc-1.8.11/libc/stdio/ldtoa_engine.c000066400000000000000000000073641513574234600202410ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2021 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _NEED_IO_LONG_DOUBLE #include "dtoa.h" #ifdef _NEED_IO_FLOAT_LARGE #define max(a, b) \ ({ \ __typeof(a) _a = a; \ __typeof(b) _b = b; \ _a > _b ? _a : _b; \ }) #define min(a, b) \ ({ \ __typeof(a) _a = a; \ __typeof(b) _b = b; \ _a < _b ? _a : _b; \ }) int __ldtoa_engine(long double x, struct dtoa *dtoa, int max_digits, bool fmode, int max_decimals) { int i; dtoa->flags = 0; if (signbit(x)) { dtoa->flags |= DTOA_MINUS; x = -x; } if (isnan(x)) { dtoa->flags |= DTOA_NAN; return max_digits; } else if (isinf(x)) { dtoa->flags |= DTOA_INF; return max_digits; } int expo; int decexp = 0; x = frexpl(x, &expo); /* move into [1-2) range */ x *= 2.0l; expo--; while (expo <= -2) { /* Make room to allow multiplication by 5 without overflow */ do { expo++; x *= 0.5l; } while (x >= 2.0l); x *= 5.0l; expo++; decexp--; } while (expo > 0) { /* divide by 10 */ x *= 0.2l; expo--; decexp++; /* get the value back in range */ do { x *= 2.0l; expo--; } while (x < 1.0l); } while (expo < 0) { x *= 0.5l; expo++; } if (x < 1.0l) { x *= 10.0l; decexp--; } /* x is now in the range 1 <= x < 10 */ int save_max_digits = max_digits; if (fmode) max_digits = min(max_digits, max(1, max_decimals + decexp + 1)); int decimals = max_digits; long double round = 0.5l; while (decimals--) { round *= 0.1l; } x += round; if (x >= 10.0l) { x *= 0.1l; decexp++; max_digits = min(save_max_digits, max(1, max_decimals + decexp + 1)); } /* convert to decimal */ for (i = 0; i < max_digits; i++) { int digit = (int)x; dtoa->digits[i] = '0' + digit; x -= digit; x *= 10.0l; } dtoa->exp = decexp; return max_digits; } #endif picolibc-1.8.11/libc/stdio/ldtox_engine.c000066400000000000000000000130621513574234600202600ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2023 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * Convert an 80-bit or 128-bit float to a string in hex ('a') format * * This chunk of code gets inserted into the vfprintf function in the * long double case when long double is larger than 64 bits. * * This code uses the 'u128' type to hold the floating point value as * an integer value. * * This code only works with long double type. */ #include "stdio_private.h" #if __SIZEOF_LONG_DOUBLE__ > 8 #define _NEED_IO_FLOAT_LARGE #include "dtoa.h" #if __LDBL_MANT_DIG__ == 64 #define LEXP_BIAS (__LDBL_MAX_EXP__ + 2) #define LEXP_INF (__LDBL_MAX_EXP__ - 3) #define LSIG_BITS (__LDBL_MANT_DIG__) #ifdef __m68k__ #define LDENORM_EXP_BIAS 0 #else #define LDENORM_EXP_BIAS 1 #define LSIG_MSB_INF _u128_lshift(to_u128(1), __LDBL_MANT_DIG__ - 1) #endif #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define LEXP_SHIFT __LDBL_MANT_DIG__ #define LSIGN_SHIFT 79 #endif #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define LEXP_SHIFT (__LDBL_MANT_DIG__ + 16) #define LSIGN_SHIFT (79 + 16) #endif #else #define LDENORM_EXP_BIAS 1 #define LSIGN_SHIFT 127 #define LEXP_BIAS (__LDBL_MAX_EXP__ - 1) #define LEXP_INF (__LDBL_MAX_EXP__) #define LSIG_MSB _u128_lshift(to_u128(1), __LDBL_MANT_DIG__ - 1) #define LSIG_BITS (__LDBL_MANT_DIG__ - 1) #define LEXP_SHIFT (__LDBL_MANT_DIG__ - 1) #endif #define LEXP_MASK ((__LDBL_MAX_EXP__ - 1) + __LDBL_MAX_EXP__) #define LSIG_SHIFT 0 #define LSIG_MASK _u128_minus_64(_u128_lshift(to_u128(1), LSIG_BITS), 1) #define TOCASE(c) ((c) - case_convert) #define LDTOX_NDIGS (__LDBL_MANT_DIG__ + 3) / 4 int __ldtox_engine(long double x, struct dtoa *dtoa, int prec, unsigned char case_convert) { _u128 fi, s; int exp; dtoa->flags = 0; fi = asuintld(x); if (_u128_and_64(_u128_rshift(fi, LSIGN_SHIFT), 1)) dtoa->flags = DTOA_MINUS; exp = _u128_and_64(_u128_rshift(fi, LEXP_SHIFT), LEXP_MASK); s = fi = _u128_lshift(_u128_and(fi, LSIG_MASK), LSIG_SHIFT); if (!_u128_is_zero(s) || exp != 0) { if (exp == 0) exp = LDENORM_EXP_BIAS; else { #ifdef LSIG_MSB s = _u128_or(s, LSIG_MSB); #endif } exp -= LEXP_BIAS; } if (prec < 0) prec = 0; else if (prec >= (LDTOX_NDIGS - 1)) prec = LDTOX_NDIGS - 1; else { int bits = ((LDTOX_NDIGS - 1) - prec) << 2; _u128 half = _u128_lshift(to_u128(1), bits - 1); _u128 mask = _u128_not(_u128_minus_64(_u128_lshift(half, 1), 1)); /* round even */ if (_u128_gt(_u128_and(s, _u128_not(mask)), half) || _u128_and_64(_u128_rshift(s, bits), 1) != 0) { s = _u128_plus(s, half); #if !defined(LSIG_MSB) && (__LDBL_MANT_DIG__ & 3) == 0 /* * Formats without an implicit '1' for the MSB and which * fill all four bits of the top digit might actually * overflow when rounding. Check for that and shift right. * We can do this without loss of accuracy because we just * carried all the way from 'half' to the top digit of the * value */ if (_u128_ge(s, _u128_lshift(to_u128(1), __LDBL_MANT_DIG__))) { s = _u128_rshift(s, 4); exp += 4; } #endif } s = _u128_and(s, mask); } if (exp == LEXP_INF) { #ifdef LSIG_MSB_INF if (!_u128_eq(fi, LSIG_MSB_INF)) #else if (!_u128_is_zero(fi)) #endif dtoa->flags |= DTOA_NAN; else dtoa->flags |= DTOA_INF; } else { int8_t d; for (d = LDTOX_NDIGS - 1; d >= 0; d--) { int dig = _u128_and_64(s, 0xf); s = _u128_rshift(s, 4); if (dig == 0 && d > prec) continue; if (dig <= 9) dig += '0'; else dig += TOCASE('a' - 10); dtoa->digits[d] = dig; if (prec < d) prec = d; } } dtoa->exp = exp; return prec; } #endif picolibc-1.8.11/libc/stdio/matchcaseprefix.c000066400000000000000000000036641513574234600207560ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2021 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" const char __match_inf[] = "INF"; const char __match_inity[] = "INITY"; const char __match_nan[] = "NAN"; bool __matchcaseprefix(const char *input, const char *pattern) { char p; while ((p = *pattern++)) { char i = *input++ & ~('a' - 'A'); if (i != p) return false; } return true; } picolibc-1.8.11/libc/stdio/meson.build000066400000000000000000000124011513574234600175730ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_stdio = [ 'asnprintf.c', 'asprintf.c', 'atomic_load.c', 'atomic_store.c', 'atold_engine.c', 'bufio.c', 'bufio_close.c', 'bufio_close_nf.c', 'bufio_setvbuf.c', 'clearerr.c', 'compare_exchange.c', 'dtox_engine.c', 'dprintf.c', 'ecvt.c', 'ecvtf.c', 'ecvtf_r.c', 'ecvtl.c', 'ecvtl_r.c', 'ecvt_r.c', 'exchange.c', 'fclose.c', 'fcvt.c', 'fcvtf.c', 'fcvtf_r.c', 'fcvtl.c', 'fcvtl_r.c', 'fcvt_r.c', 'fdevopen.c', 'fdopen.c', 'feof.c', 'ferror.c', 'fflush.c', 'fgetc.c', 'fgetpos.c', 'fgets.c', 'fgetwc.c', 'fgetws.c', 'fileno.c', 'filestrget.c', 'filestrputalloc.c', 'filestrput.c', 'filewstrget.c', 'flockfile.c', 'flockfile_init.c', 'fmemopen.c', 'fopen.c', 'fprintf.c', 'fputc.c', 'fputs.c', 'fputwc.c', 'fputws.c', 'fread.c', 'freopen.c', 'fscanf.c', 'fseek.c', 'fseeko.c', 'fsetpos.c', 'ftell.c', 'ftello.c', 'ftox_engine.c', 'ftrylockfile.c', 'funlockfile.c', 'funopen.c', 'fwide.c', 'fwprintf.c', 'fwrite.c', 'fwscanf.c', 'gcvt.c', 'gcvtf.c', 'gcvtl.c', 'getchar.c', 'getdelim.c', 'getline.c', 'gets.c', 'getwchar.c', 'ldtoa_engine.c', 'ldtox_engine.c', 'matchcaseprefix.c', 'mktemp.c', 'perror.c', 'printf.c', 'putchar.c', 'puts.c', 'putwchar.c', 'remove.c', 'rewind.c', 'scanf.c', 'setbuf.c', 'setbuffer.c', 'setlinebuf.c', 'setvbuf.c', 'sflags.c', 'snprintf.c', 'snprintfd.c', 'snprintff.c', 'sprintf.c', 'sprintfd.c', 'sprintff.c', 'sscanf.c', 'strfromd.c', 'strfromf.c', 'strfroml.c', 'strtod.c', 'strtod_l.c', 'strtof.c', 'strtof_l.c', 'strtoimax.c', 'strtoimax_l.c', 'strtol.c', 'strtold.c', 'strtold_l.c', 'strtol_l.c', 'strtoll.c', 'strtoll_l.c', 'strtoul.c', 'strtoul_l.c', 'strtoull.c', 'strtoull_l.c', 'strtoumax.c', 'strtoumax_l.c', 'swprintf.c', 'swprintfd.c', 'swscanf.c', 'tmpfile.c', 'tmpnam.c', 'ungetc.c', 'ungetwc.c', 'vasnprintf.c', 'vasprintf.c', 'vdprintf.c', 'vffprintf.c', 'vffscanf.c', 'vfiprintf.c', 'vfiscanf.c', 'vflprintf.c', 'vflscanf.c', 'vfmprintf.c', 'vfmscanf.c', 'vfprintf.c', 'vfscanf.c', 'vfwprintf.c', 'vfwscanf.c', 'vprintf.c', 'vscanf.c', 'vsnprintf.c', 'vsprintf.c', 'vsscanf.c', 'vswprintf.c', 'vswscanf.c', 'vwprintf.c', 'vwscanf.c', 'wcstod.c', 'wcstod_l.c', 'wcstof.c', 'wcstof_l.c', 'wcstoimax.c', 'wcstoimax_l.c', 'wcstol.c', 'wcstold.c', 'wcstold_l.c', 'wcstol_l.c', 'wcstoll.c', 'wcstoll_l.c', 'wcstoul.c', 'wcstoul_l.c', 'wcstoull.c', 'wcstoull_l.c', 'wcstoumax.c', 'wcstoumax_l.c', 'wprintf.c', 'wscanf.c', 'sprintf_s.c', 'vfprintf_s.c', 'vsnprintf_s.c', ] # exact float/string conversion code srcs_dtoa_ryu = [ 'atod_ryu.c', 'atof_ryu.c', 'dtoa_ryu.c', 'ftoa_ryu.c', 'ryu_divpow2.c', 'ryu_log10.c', 'ryu_log2pow5.c', 'ryu_pow5bits.c', 'ryu_table.c', 'ryu_umul128.c', ] # smaller float/string conversion code srcs_dtoa_float = [ 'atod_engine.c', 'atof_engine.c', 'dtoa_engine.c', 'ftoa_engine.c', ] if io_float_exact srcs_stdio += srcs_dtoa_ryu else srcs_stdio += srcs_dtoa_float endif # stdin/stdout/stderr using POSIX APIs srcs_stdio_posix_console = [ 'posixiob_stdin.c', 'posixiob_stdout.c', 'posixiob_stderr.c', ] if posix_console srcs_stdio += srcs_stdio_posix_console endif srcs_stdio_use = [] foreach file : srcs_stdio s_file = fs.replace_suffix(file, '.S') if file in srcs_machine message('libc/stdio/' + file + ': machine overrides generic') elif s_file in srcs_machine message('libc/stdio/' + s_file + ': machine overrides generic') else srcs_stdio_use += file endif endforeach src_stdio = files(srcs_stdio_use) picolibc-1.8.11/libc/stdio/mktemp.c000066400000000000000000000144011513574234600170740ustar00rootroot00000000000000/* * Copyright (c) 1987 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that: (1) source distributions retain this entire copyright * notice and comment, and (2) distributions including binaries display * the following acknowledgement: ``This product includes software * developed by the University of California, Berkeley and its contributors'' * in the documentation or other materials provided with the distribution. * Neither the name of the University nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* This is file MKTEMP.C */ /* This file may have been modified by DJ Delorie (Jan 1991). If so, ** these modifications are Copyright (C) 1991 DJ Delorie. */ /* FUNCTION <>, <>, <>, <>---generate unused file name INDEX mktemp INDEX mkstemp INDEX mkstemps INDEX mkostemps SYNOPSIS #include char *mktemp(char *<[path]>); int mkstemp(char *<[path]>); int mkstemps(char *<[path]>, int suffixlen); int mkostemps(char *<[path]>, int suffixlen, int flags); DESCRIPTION <>, <>, <>, and <> attempt to generate a file name that is not yet in use for any existing file. <>, <> and > create the file and open it for reading and writing; <> simply generates the file name (making <> a security risk). <> allow the addition of other <> flags, such as <>, <>, or <>. On platforms with a separate text mode, <> forces <>, while <> allows the choice between <>, <>, or 0 for default. You supply a simple pattern for the generated file name, as the string at <[path]>. The pattern should be a valid filename (including path information if you wish) ending with at least six `<>' characters. The generated filename will match the leading part of the name you supply, with the trailing `<>' characters replaced by some combination of digits and letters. With <> and >, the `<>' characters end <[suffixlen]> bytes before the end of the string. RETURNS <> returns the pointer <[path]> to the modified string representing an unused filename, unless it could not generate one, or the pattern you provided is not suitable for a filename; in that case, it returns <>. Be aware that there is an inherent race between generating the name and attempting to create a file by that name; you are advised to use <>. <>, <> and <> return a file descriptor to the newly created file, unless it could not generate an unused filename, or the pattern you provided is not suitable for a filename; in that case, it returns <<-1>>. NOTES Never use <>. The generated filenames are easy to guess and there's a race between the test if the file exists and the creation of the file. In combination this makes <> prone to attacks and using it is a security risk. Whenever possible use <> instead. It doesn't suffer the race condition. PORTABILITY ANSI C does not require either <> or <>; the System V Interface Definition requires <> as of Issue 2. POSIX 2001 requires <> while deprecating <>. <>, and <> are not standardized. Supporting OS subroutines required: <> */ #include "stdio_private.h" /* Our names are six characters from [0-9a-z] */ #define NUM_NAMES (36UL * 36UL * 36UL * 36UL * 36UL * 36UL) /* Attempts */ #define NUM_ATTEMPT (36UL * 36UL * 36UL) static int _gettemp(char *path, int suffixlen, int *doopen, int flags) { char *start, *trv; char *end; uint32_t attempt; end = path + strlen(path) - suffixlen; trv = end; /* Replace 'X' with 'a' */ while (path < trv && *--trv == 'X') *trv = 'a'; /* Make sure we got six Xs */ if (end - trv < 6) { errno = EINVAL; return 0; } start = trv + 1; for (attempt = 0; attempt < NUM_ATTEMPT; attempt++) { /* Generate a random filename index */ long filename = random() % NUM_NAMES; size_t i; /* Convert the random index into characters */ for (i = 0; i < 6; i++) { char c = filename % 36; filename /= 36; if (c < 10) c += '0'; else c += 'a' - 10; start[i] = c; } /* * Use open to check if the file exists to avoid depending on * stat or access. Don't rely on O_EXCL working, although if it * doesn't, this introduces a race condition */ int fd = open(path, O_RDONLY); if (fd < 0) { if (errno != EACCES) { if (errno != ENOENT) return 0; if (doopen) { fd = open(path, flags | O_CREAT | O_EXCL | O_RDWR, 0600); if (fd >= 0) { *doopen = fd; return 1; } if (errno != EEXIST) return 0; } else { return 1; } } } else close(fd); } return 0; } int mkstemp(char *template) { int fd; return (_gettemp(template, 0, &fd, 0) ? fd : -1); } char * mktemp(char *template) { return (_gettemp(template, 0, (int *)NULL, 0) ? template : (char *)NULL); } #ifndef O_BINARY #define O_BINARY 0 #endif #ifndef O_TEXT #define O_TEXT 0 #endif int mkstemps(char *template, int suffixlen) { int fd; return (_gettemp(template, suffixlen, &fd, O_BINARY) ? fd : -1); } int mkostemps(char *template, int suffixlen, int flags) { int fd; flags &= (O_APPEND | O_CLOEXEC | O_SYNC | O_BINARY | O_TEXT); return (_gettemp(template, suffixlen, &fd, flags) ? fd : -1); } picolibc-1.8.11/libc/stdio/perror.c000066400000000000000000000034111513574234600171070ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" void perror(const char *msg) { int err = errno; if (msg && *msg) fprintf(stderr, "%s: ", msg); fprintf(stderr, "%s\n", strerror(err)); } picolibc-1.8.11/libc/stdio/posixiob_stderr.c000066400000000000000000000042271513574234600210230ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #ifndef __PICOLIBC_STDERR_BUFSIZ #define __PICOLIBC_STDERR_BUFSIZ 1 #endif static char write_buf[__PICOLIBC_STDERR_BUFSIZ]; static struct __file_bufio __stderr = FDEV_SETUP_POSIX(2, write_buf, __PICOLIBC_STDERR_BUFSIZ, __SWR, __BLBF); FILE * const __posix_stderr = &__stderr.xfile.cfile.file; __weak_reference(__posix_stderr, stderr); #if __PICOLIBC_STDERR_BUFSIZE > 1 /* * Add a destructor function to get stderr flushed on * exit */ __attribute__((destructor(101))) static void posix_exit(void) { fflush(stderr); } #endif picolibc-1.8.11/libc/stdio/posixiob_stdin.c000066400000000000000000000035401513574234600206360ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" static char read_buf[BUFSIZ]; static struct __file_bufio __stdin = FDEV_SETUP_POSIX(0, read_buf, BUFSIZ, __SRD, 0); FILE * const __posix_stdin = &__stdin.xfile.cfile.file; __weak_reference(__posix_stdin, stdin); picolibc-1.8.11/libc/stdio/posixiob_stdout.c000066400000000000000000000040341513574234600210360ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" static char write_buf[BUFSIZ]; static struct __file_bufio __stdout = FDEV_SETUP_POSIX(1, write_buf, BUFSIZ, __SWR, __BLBF); FILE * const __posix_stdout = &__stdout.xfile.cfile.file; __weak_reference(__posix_stdout, stdout); /* * Add a destructor function to get stdout flushed on * exit */ __attribute__((destructor(101))) static void posix_exit(void) { if (stdout) fflush(stdout); } picolibc-1.8.11/libc/stdio/printf.c000066400000000000000000000034021513574234600171000ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: printf.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int printf(const char *fmt, ...) { va_list ap; int i; va_start(ap, fmt); i = vfprintf(stdout, fmt, ap); va_end(ap); return i; } picolibc-1.8.11/libc/stdio/putchar.c000066400000000000000000000036701513574234600172530ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: putchar.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" #undef putchar int putchar(int c) { return putc(c, stdout); } #undef putchar_unlocked #ifdef __STDIO_LOCKING int putchar_unlocked(int c) { return putc_unlocked(c, stdout); } #else #ifdef __strong_reference __strong_reference(putchar, putchar_unlocked); #else int putchar_unlocked(int c) { return putchar(c); } #endif #endif picolibc-1.8.11/libc/stdio/puts.c000066400000000000000000000041061513574234600165730ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: puts.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int puts(const char *str) { int (*put)(char, struct __file *); char c; int ret = EOF; FILE *out = stdout; __flockfile(out); if ((out->flags & __SWR) == 0) goto exit; put = out->put; while ((c = *str++) != '\0') if (put(c, out) < 0) goto flag_exit; if (put('\n', out) < 0) goto flag_exit; ret = 0; goto exit; flag_exit: out->flags |= __SERR; exit: __funlockfile(out); return ret; } picolibc-1.8.11/libc/stdio/putwchar.c000066400000000000000000000032621513574234600174370ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: putchar.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" #undef putwchar wint_t putwchar(wchar_t c) { return putwc(c, stdout); } picolibc-1.8.11/libc/stdio/remove.c000066400000000000000000000032561513574234600171020ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int remove(const char *pathname) { return unlink(pathname); } picolibc-1.8.11/libc/stdio/rewind.c000066400000000000000000000033731513574234600170750ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2021 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" void rewind(FILE *stream) { __flockfile(stream); (void)fseek(stream, 0L, SEEK_SET); clearerr(stream); __funlockfile(stream); } picolibc-1.8.11/libc/stdio/ryu/000077500000000000000000000000001513574234600162525ustar00rootroot00000000000000picolibc-1.8.11/libc/stdio/ryu/common.h000066400000000000000000000046321513574234600177200ustar00rootroot00000000000000// Copyright 2018 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. #ifndef RYU_COMMON_H #define RYU_COMMON_H #include #include #include #define assert(x) // #include #if __SIZEOF_POINTER__ == 4 #define RYU_32_BIT_PLATFORM #endif #ifdef __SIZEOF_INT128__ #define HAS_UINT128 #endif #if __SIZEOF_DOUBLE__ == 8 #define RYU64 double #elif __SIZEOF_LONG_DOUBLE__ == 8 #define RYU64 long double #endif static inline int max_int(int a, int b) { return a > b ? a : b; } static inline int min_int(int a, int b) { return a < b ? a : b; } // Returns e == 0 ? 1 : [log_2(5^e)]; requires 0 <= e <= 3528. int32_t __log2pow5(const int32_t e); #define log2pow5(e) __log2pow5(e) // Returns e == 0 ? 1 : ceil(log_2(5^e)); requires 0 <= e <= 3528. int32_t __ceil_log2pow5(const int32_t e); #define ceil_log2pow5(e) __ceil_log2pow5(e) // Returns e == 0 ? 1 : ceil(log_2(5^e)); requires 0 <= e <= 3528. int32_t __pow5bits(const int32_t e); #define pow5bits(e) __pow5bits(e) // Returns floor(log_10(2^e)); requires 0 <= e <= 1650. uint32_t __log10Pow2(const int32_t e); #define log10Pow2(e) __log10Pow2(e) // Returns floor(log_10(5^e)); requires 0 <= e <= 2620. uint32_t __log10Pow5(const int32_t e); #define log10Pow5(e) __log10Pow5(e) static inline uint32_t float_to_bits(const float f) { uint32_t bits = 0; memcpy(&bits, &f, sizeof(float)); return bits; } #ifdef RYU64 static inline uint64_t ryu64_to_bits(const RYU64 d) { uint64_t bits = 0; memcpy(&bits, &d, sizeof(d)); return bits; } #endif // These tables are generated by PrintDoubleLookupTable. #define DOUBLE_POW5_INV_BITCOUNT 125 #define DOUBLE_POW5_BITCOUNT 125 void __double_computePow5(const uint32_t i, uint64_t * const result); void __double_computeInvPow5(const uint32_t i, uint64_t * const result); #endif // RYU_COMMON_H picolibc-1.8.11/libc/stdio/ryu/d2s_intrinsics.h000066400000000000000000000273051513574234600213670ustar00rootroot00000000000000// Copyright 2018 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. #ifndef RYU_D2S_INTRINSICS_H #define RYU_D2S_INTRINSICS_H #include // Defines RYU_32_BIT_PLATFORM if applicable. #include "common.h" // ABSL avoids uint128_t on Win32 even if __SIZEOF_INT128__ is defined. // Let's do the same for now. #if defined(__SIZEOF_INT128__) && !defined(_MSC_VER) && !defined(RYU_ONLY_64_BIT_OPS) #define HAS_UINT128 #elif defined(_MSC_VER) && !defined(RYU_ONLY_64_BIT_OPS) && defined(_M_X64) #define HAS_64_BIT_INTRINSICS #endif #if defined(HAS_UINT128) typedef __uint128_t uint128_t; #endif #if defined(HAS_64_BIT_INTRINSICS) #include static inline uint64_t umul128(const uint64_t a, const uint64_t b, uint64_t * const productHi) { return _umul128(a, b, productHi); } static inline uint64_t shiftright128(const uint64_t lo, const uint64_t hi, const uint32_t dist) { // For the __shiftright128 intrinsic, the shift value is always // modulo 64. // In the current implementation of the double-precision version // of Ryu, the shift value is always < 64. (In the case // RYU_OPTIMIZE_SIZE == 0, the shift value is in the range [49, 58]. // Otherwise in the range [2, 59].) // However, this function is now also called by s2d, which requires supporting // the larger shift range (TODO: what is the actual range?). // Check this here in case a future change requires larger shift // values. In this case this function needs to be adjusted. assert(dist < 64); return __shiftright128(lo, hi, (unsigned char)dist); } #else // defined(HAS_64_BIT_INTRINSICS) uint64_t __umul128(const uint64_t a, const uint64_t b, uint64_t * const productHi); #define umul128(a, b, hi) __umul128(a, b, hi) uint64_t __shiftright128(const uint64_t lo, const uint64_t hi, const uint32_t dist); #define shiftright128(lo, hi, dist) __shiftright128(lo, hi, dist) #endif // defined(HAS_64_BIT_INTRINSICS) #if defined(RYU_32_BIT_PLATFORM) // Returns the high 64 bits of the 128-bit product of a and b. static inline uint64_t umulh(const uint64_t a, const uint64_t b) { // Reuse the umul128 implementation. // Optimizers will likely eliminate the instructions used to compute the // low part of the product. uint64_t hi; umul128(a, b, &hi); return hi; } // On 32-bit platforms, compilers typically generate calls to library // functions for 64-bit divisions, even if the divisor is a constant. // // E.g.: // https://bugs.llvm.org/show_bug.cgi?id=37932 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17958 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37443 // // The functions here perform division-by-constant using multiplications // in the same way as 64-bit compilers would do. // // NB: // The multipliers and shift values are the ones generated by clang x64 // for expressions like x/5, x/10, etc. static inline uint64_t div5(const uint64_t x) { return umulh(x, 0xCCCCCCCCCCCCCCCDu) >> 2; } static inline uint64_t div10(const uint64_t x) { return umulh(x, 0xCCCCCCCCCCCCCCCDu) >> 3; } static inline uint64_t div100(const uint64_t x) { return umulh(x >> 2, 0x28F5C28F5C28F5C3u) >> 2; } static inline uint64_t div1e8(const uint64_t x) { return umulh(x, 0xABCC77118461CEFDu) >> 26; } static inline uint64_t div1e9(const uint64_t x) { return umulh(x >> 9, 0x44B82FA09B5A53u) >> 11; } static inline uint32_t mod1e9(const uint64_t x) { // Avoid 64-bit math as much as possible. // Returning (uint32_t) (x - 1000000000 * div1e9(x)) would // perform 32x64-bit multiplication and 64-bit subtraction. // x and 1000000000 * div1e9(x) are guaranteed to differ by // less than 10^9, so their highest 32 bits must be identical, // so we can truncate both sides to uint32_t before subtracting. // We can also simplify (uint32_t) (1000000000 * div1e9(x)). // We can truncate before multiplying instead of after, as multiplying // the highest 32 bits of div1e9(x) can't affect the lowest 32 bits. return ((uint32_t)x) - 1000000000 * ((uint32_t)div1e9(x)); } #else // defined(RYU_32_BIT_PLATFORM) static inline uint64_t div5(const uint64_t x) { return x / 5; } static inline uint64_t div10(const uint64_t x) { return x / 10; } static inline uint64_t div100(const uint64_t x) { return x / 100; } static inline uint64_t div1e8(const uint64_t x) { return x / 100000000; } static inline uint64_t div1e9(const uint64_t x) { return x / 1000000000; } static inline uint32_t mod1e9(const uint64_t x) { return (uint32_t)(x - 1000000000 * div1e9(x)); } #endif // defined(RYU_32_BIT_PLATFORM) uint32_t __pow5Factor(uint64_t value); #define pow5Factor(v) __pow5Factor(v) // Returns true if value is divisible by 5^p. static inline bool multipleOfPowerOf5(const uint64_t value, const uint32_t p) { // I tried a case distinction on p, but there was no performance difference. return pow5Factor(value) >= p; } // Returns true if value is divisible by 2^p. static inline bool multipleOfPowerOf2(const uint64_t value, const uint32_t p) { assert(value != 0); assert(p < 64); // __builtin_ctzll doesn't appear to be faster here. return (value & ((1ull << p) - 1)) == 0; } // We need a 64x128-bit multiplication and a subsequent 128-bit shift. // Multiplication: // The 64-bit factor is variable and passed in, the 128-bit factor comes // from a lookup table. We know that the 64-bit factor only has 55 // significant bits (i.e., the 9 topmost bits are zeros). The 128-bit // factor only has 124 significant bits (i.e., the 4 topmost bits are // zeros). // Shift: // In principle, the multiplication result requires 55 + 124 = 179 bits to // represent. However, we then shift this value to the right by j, which is // at least j >= 115, so the result is guaranteed to fit into 179 - 115 = 64 // bits. This means that we only need the topmost 64 significant bits of // the 64x128-bit multiplication. // // There are several ways to do this: // 1. Best case: the compiler exposes a 128-bit type. // We perform two 64x64-bit multiplications, add the higher 64 bits of the // lower result to the higher result, and shift by j - 64 bits. // // We explicitly cast from 64-bit to 128-bit, so the compiler can tell // that these are only 64-bit inputs, and can map these to the best // possible sequence of assembly instructions. // x64 machines happen to have matching assembly instructions for // 64x64-bit multiplications and 128-bit shifts. // // 2. Second best case: the compiler exposes intrinsics for the x64 assembly // instructions mentioned in 1. // // 3. We only have 64x64 bit instructions that return the lower 64 bits of // the result, i.e., we have to use plain C. // Our inputs are less than the full width, so we have three options: // a. Ignore this fact and just implement the intrinsics manually. // b. Split both into 31-bit pieces, which guarantees no internal overflow, // but requires extra work upfront (unless we change the lookup table). // c. Split only the first factor into 31-bit pieces, which also guarantees // no internal overflow, but requires extra work since the intermediate // results are not perfectly aligned. #if defined(HAS_UINT128) // Best case: use 128-bit type. static inline uint64_t mulShift64(const uint64_t m, const uint64_t * const mul, const int32_t j) { const uint128_t b0 = ((uint128_t)m) * mul[0]; const uint128_t b2 = ((uint128_t)m) * mul[1]; return (uint64_t)(((b0 >> 64) + b2) >> (j - 64)); } static inline uint64_t mulShiftAll64(const uint64_t m, const uint64_t * const mul, const int32_t j, uint64_t * const vp, uint64_t * const vm, const uint32_t mmShift) { // m <<= 2; // uint128_t b0 = ((uint128_t) m) * mul[0]; // 0 // uint128_t b2 = ((uint128_t) m) * mul[1]; // 64 // // uint128_t hi = (b0 >> 64) + b2; // uint128_t lo = b0 & 0xffffffffffffffffull; // uint128_t factor = (((uint128_t) mul[1]) << 64) + mul[0]; // uint128_t vpLo = lo + (factor << 1); // *vp = (uint64_t) ((hi + (vpLo >> 64)) >> (j - 64)); // uint128_t vmLo = lo - (factor << mmShift); // *vm = (uint64_t) ((hi + (vmLo >> 64) - (((uint128_t) 1ull) << 64)) >> (j - 64)); // return (uint64_t) (hi >> (j - 64)); *vp = mulShift64(4 * m + 2, mul, j); *vm = mulShift64(4 * m - 1 - mmShift, mul, j); return mulShift64(4 * m, mul, j); } #elif defined(HAS_64_BIT_INTRINSICS) static inline uint64_t mulShift64(const uint64_t m, const uint64_t * const mul, const int32_t j) { // m is maximum 55 bits uint64_t high1; // 128 const uint64_t low1 = umul128(m, mul[1], &high1); // 64 uint64_t high0; // 64 umul128(m, mul[0], &high0); // 0 const uint64_t sum = high0 + low1; if (sum < high0) { ++high1; // overflow into high1 } return shiftright128(sum, high1, j - 64); } static inline uint64_t mulShiftAll64(const uint64_t m, const uint64_t * const mul, const int32_t j, uint64_t * const vp, uint64_t * const vm, const uint32_t mmShift) { *vp = mulShift64(4 * m + 2, mul, j); *vm = mulShift64(4 * m - 1 - mmShift, mul, j); return mulShift64(4 * m, mul, j); } #else // !defined(HAS_UINT128) && !defined(HAS_64_BIT_INTRINSICS) static inline uint64_t mulShift64(const uint64_t m, const uint64_t * const mul, const int32_t j) { // m is maximum 55 bits uint64_t high1; // 128 const uint64_t low1 = umul128(m, mul[1], &high1); // 64 uint64_t high0; // 64 umul128(m, mul[0], &high0); // 0 const uint64_t sum = high0 + low1; if (sum < high0) { ++high1; // overflow into high1 } return shiftright128(sum, high1, j - 64); } // This is faster if we don't have a 64x64->128-bit multiplication. static inline uint64_t mulShiftAll64(uint64_t m, const uint64_t * const mul, const int32_t j, uint64_t * const vp, uint64_t * const vm, const uint32_t mmShift) { m <<= 1; // m is maximum 55 bits uint64_t tmp; const uint64_t lo = umul128(m, mul[0], &tmp); uint64_t hi; const uint64_t mid = tmp + umul128(m, mul[1], &hi); hi += mid < tmp; // overflow into hi const uint64_t lo2 = lo + mul[0]; const uint64_t mid2 = mid + mul[1] + (lo2 < lo); const uint64_t hi2 = hi + (mid2 < mid); *vp = shiftright128(mid2, hi2, (uint32_t)(j - 64 - 1)); if (mmShift == 1) { const uint64_t lo3 = lo - mul[0]; const uint64_t mid3 = mid - mul[1] - (lo3 > lo); const uint64_t hi3 = hi - (mid3 > mid); *vm = shiftright128(mid3, hi3, (uint32_t)(j - 64 - 1)); } else { const uint64_t lo3 = lo + lo; const uint64_t mid3 = mid + mid + (lo3 < lo); const uint64_t hi3 = hi + hi + (mid3 < mid); const uint64_t lo4 = lo3 - mul[0]; const uint64_t mid4 = mid3 - mul[1] - (lo4 > lo3); const uint64_t hi4 = hi3 - (mid4 > mid3); *vm = shiftright128(mid4, hi4, (uint32_t)(j - 64)); } return shiftright128(mid, hi, (uint32_t)(j - 64 - 1)); } #endif // HAS_64_BIT_INTRINSICS #endif // RYU_D2S_INTRINSICS_H picolibc-1.8.11/libc/stdio/ryu/digit_table.h000066400000000000000000000037271513574234600207030ustar00rootroot00000000000000// Copyright 2018 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. #ifndef RYU_DIGIT_TABLE_H #define RYU_DIGIT_TABLE_H // A table of all two-digit numbers. This is used to speed up decimal digit // generation by copying pairs of digits into the final output. static const char DIGIT_TABLE[200] = { '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9', '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3', '9', '4', '0', '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', '5', '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9', '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', '7', '6', '8', '6', '9', '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9', '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', '7', '9', '8', '9', '9' }; #endif // RYU_DIGIT_TABLE_H picolibc-1.8.11/libc/stdio/ryu/f2s_intrinsics.h000066400000000000000000000036161513574234600213700ustar00rootroot00000000000000// Copyright 2018 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. #ifndef RYU_F2S_INTRINSICS_H #define RYU_F2S_INTRINSICS_H // Defines RYU_32_BIT_PLATFORM if applicable. #include "common.h" #define FLOAT_POW5_INV_BITCOUNT (DOUBLE_POW5_INV_BITCOUNT - 64) #define FLOAT_POW5_BITCOUNT (DOUBLE_POW5_BITCOUNT - 64) static inline uint32_t pow5factor_32(uint32_t value) { uint32_t count = 0; for (;;) { assert(value != 0); const uint32_t q = value / 5; const uint32_t r = value % 5; if (r != 0) { break; } value = q; ++count; } return count; } // Returns true if value is divisible by 5^p. static inline bool multipleOfPowerOf5_32(const uint32_t value, const uint32_t p) { return pow5factor_32(value) >= p; } // Returns true if value is divisible by 2^p. static inline bool multipleOfPowerOf2_32(const uint32_t value, const uint32_t p) { // __builtin_ctz doesn't appear to be faster here. return (value & ((1ul << p) - 1)) == 0; } uint32_t __mulPow5InvDivPow2(const uint32_t m, const uint32_t q, const int32_t j); #define mulPow5InvDivPow2(m, q, j) __mulPow5InvDivPow2(m, q, j) uint32_t __mulPow5divPow2(const uint32_t m, const uint32_t i, const int32_t j); #define mulPow5divPow2(m, i, j) __mulPow5divPow2(m, i, j) #endif // RYU_F2S_INTRINSICS_H picolibc-1.8.11/libc/stdio/ryu/ryu.h000066400000000000000000000024621513574234600172460ustar00rootroot00000000000000// Copyright 2018 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. #ifndef RYU_H #define RYU_H #define RYU_OPTIMIZE_SIZE #include int d2s_buffered_n(double f, char *result); void d2s_buffered(double f, char *result); char *d2s(double f); int f2s_buffered_n(float f, char *result); void f2s_buffered(float f, char *result); char *f2s(float f); int d2fixed_buffered_n(double d, uint32_t precision, char *result); void d2fixed_buffered(double d, uint32_t precision, char *result); char *d2fixed(double d, uint32_t precision); int d2exp_buffered_n(double d, uint32_t precision, char *result); void d2exp_buffered(double d, uint32_t precision, char *result); char *d2exp(double d, uint32_t precision); #endif // RYU_H picolibc-1.8.11/libc/stdio/ryu/ryu_parse.h000066400000000000000000000026041513574234600204360ustar00rootroot00000000000000// Copyright 2019 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. #ifndef RYU_PARSE_H #define RYU_PARSE_H // This is an experimental implementation of parsing strings to 64-bit floats // using a Ryu-like algorithm. At this time, it only support up to 17 non-zero // digits in the input, and also does not support all formats. Use at your own // risk. // // This implementation does not currently support -DRYU_OPTIMIZE_SIZE and always // compiles against the large lookup tables. enum Status { SUCCESS, INPUT_TOO_SHORT, INPUT_TOO_LONG, MALFORMED_INPUT }; enum Status s2d_n(const char *buffer, const int len, double *result); enum Status s2d(const char *buffer, double *result); enum Status s2f_n(const char *buffer, const int len, float *result); enum Status s2f(const char *buffer, float *result); #endif // RYU_PARSE_H picolibc-1.8.11/libc/stdio/ryu_divpow2.c000066400000000000000000000057351513574234600201020ustar00rootroot00000000000000// Copyright 2018 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. #include "ryu/f2s_intrinsics.h" // It seems to be slightly faster to avoid uint128_t here, although the // generated code for uint128_t looks slightly nicer. static inline uint32_t mulShift32(const uint32_t m, const uint64_t factor, const int32_t shift) { assert(shift > 32); // The casts here help MSVC to avoid calls to the __allmul library // function. const uint32_t factorLo = (uint32_t)(factor); const uint32_t factorHi = (uint32_t)(factor >> 32); const uint64_t bits0 = (uint64_t)m * factorLo; const uint64_t bits1 = (uint64_t)m * factorHi; /* * This function *does* get called with shift < 32 when converting * strings to floats, so disable this optimization */ #if defined(RYU_32_BIT_PLATFORM) // On 32-bit platforms we can avoid a 64-bit shift-right since we only // need the upper 32 bits of the result and the shift value is > 32. const uint32_t bits0Hi = (uint32_t)(bits0 >> 32); uint32_t bits1Lo = (uint32_t)(bits1); uint32_t bits1Hi = (uint32_t)(bits1 >> 32); bits1Lo += bits0Hi; bits1Hi += (bits1Lo < bits0Hi); if (shift >= 64) { // s2f can call this with a shift value >= 64, which we have to handle. // This could now be slower than the !defined(RYU_32_BIT_PLATFORM) case. return (uint32_t)(bits1Hi >> (shift - 64)); } else { const int32_t s = shift - 32; return (bits1Hi << (32 - s)) | (bits1Lo >> s); } #else // RYU_32_BIT_PLATFORM const uint64_t sum = (bits0 >> 32) + bits1; const uint64_t shiftedSum = sum >> (shift - 32); assert(shiftedSum <= UINT32_MAX); return (uint32_t)shiftedSum; #endif // RYU_32_BIT_PLATFORM } uint32_t __mulPow5InvDivPow2(const uint32_t m, const uint32_t q, const int32_t j) { // The inverse multipliers are defined as [2^x / 5^y] + 1; the upper 64 bits from the double // lookup table are the correct bits for [2^x / 5^y], so we have to add 1 here. Note that we // rely on the fact that the added 1 that's already stored in the table never overflows into the // upper 64 bits. uint64_t pow5[2]; __double_computeInvPow5(q, pow5); return mulShift32(m, pow5[1] + 1, j); } uint32_t __mulPow5divPow2(const uint32_t m, const uint32_t i, const int32_t j) { uint64_t pow5[2]; __double_computePow5(i, pow5); return mulShift32(m, pow5[1], j); } picolibc-1.8.11/libc/stdio/ryu_log10.c000066400000000000000000000023301513574234600174160ustar00rootroot00000000000000// Copyright 2018 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. #include "ryu/common.h" // Returns floor(log_10(2^e)); requires 0 <= e <= 1650. uint32_t __log10Pow2(const int32_t e) { // The first value this approximation fails for is 2^1651 which is just greater than 10^297. assert(e >= 0); assert(e <= 1650); return (((uint32_t)e) * 78913) >> 18; } // Returns floor(log_10(5^e)); requires 0 <= e <= 2620. uint32_t __log10Pow5(const int32_t e) { // The first value this approximation fails for is 5^2621 which is just greater than 10^1832. assert(e >= 0); assert(e <= 2620); return (((uint32_t)e) * 732923) >> 20; } picolibc-1.8.11/libc/stdio/ryu_log2pow5.c000066400000000000000000000023201513574234600201510ustar00rootroot00000000000000// Copyright 2018 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. #include "ryu/common.h" // Returns e == 0 ? 1 : [log_2(5^e)]; requires 0 <= e <= 3528. int32_t __log2pow5(const int32_t e) { // This approximation works up to the point that the multiplication overflows at e = 3529. // If the multiplication were done in 64 bits, it would fail at 5^4004 which is just greater // than 2^9297. assert(e >= 0); assert(e <= 3528); return (int32_t)((((uint32_t)e) * 1217359) >> 19); } // Returns e == 0 ? 1 : ceil(log_2(5^e)); requires 0 <= e <= 3528. int32_t __ceil_log2pow5(const int32_t e) { return log2pow5(e) + 1; } picolibc-1.8.11/libc/stdio/ryu_pow5bits.c000066400000000000000000000020121513574234600202450ustar00rootroot00000000000000// Copyright 2018 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. #include "ryu/common.h" int32_t __pow5bits(const int32_t e) { // This approximation works up to the point that the multiplication overflows at e = 3529. // If the multiplication were done in 64 bits, it would fail at 5^4004 which is just greater // than 2^9297. assert(e >= 0); assert(e <= 3528); return (int32_t)(((((uint32_t)e) * 1217359) >> 19) + 1); } picolibc-1.8.11/libc/stdio/ryu_table.c000066400000000000000000000177401513574234600175760ustar00rootroot00000000000000// Copyright 2018 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. // Defines HAS_UINT128 and uint128_t if applicable. #include #include "ryu/common.h" #include "ryu/d2s_intrinsics.h" static const uint64_t DOUBLE_POW5_INV_SPLIT2[15][2] = { { 1u, 2305843009213693952u }, { 5955668970331000884u, 1784059615882449851u }, { 8982663654677661702u, 1380349269358112757u }, { 7286864317269821294u, 2135987035920910082u }, { 7005857020398200553u, 1652639921975621497u }, { 17965325103354776697u, 1278668206209430417u }, { 8928596168509315048u, 1978643211784836272u }, { 10075671573058298858u, 1530901034580419511u }, { 597001226353042382u, 1184477304306571148u }, { 1527430471115325346u, 1832889850782397517u }, { 12533209867169019542u, 1418129833677084982u }, { 5577825024675947042u, 2194449627517475473u }, { 11006974540203867551u, 1697873161311732311u }, { 10313493231639821582u, 1313665730009899186u }, { 12701016819766672773u, 2032799256770390445u } }; static const uint32_t POW5_INV_OFFSETS[22] = { 0x54544554, 0x04055545, 0x10041000, 0x00400414, 0x40010000, 0x41155555, 0x00000454, 0x00010044, 0x40000000, 0x44000041, 0x50454450, 0x55550054, 0x51655554, 0x40004000, 0x01000001, 0x00010500, 0x51515411, 0x05555554, 0x50411500, 0x40040000, 0x05040110, 0x00000000, }; static const uint64_t DOUBLE_POW5_SPLIT2[13][2] = { { 0u, 1152921504606846976u }, { 0u, 1490116119384765625u }, { 1032610780636961552u, 1925929944387235853u }, { 7910200175544436838u, 1244603055572228341u }, { 16941905809032713930u, 1608611746708759036u }, { 13024893955298202172u, 2079081953128979843u }, { 6607496772837067824u, 1343575221513417750u }, { 17332926989895652603u, 1736530273035216783u }, { 13037379183483547984u, 2244412773384604712u }, { 1605989338741628675u, 1450417759929778918u }, { 9630225068416591280u, 1874621017369538693u }, { 665883850346957067u, 1211445438634777304u }, { 14931890668723713708u, 1565756531257009982u } }; static const uint32_t POW5_OFFSETS[21] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x40000000, 0x59695995, 0x55545555, 0x56555515, 0x41150504, 0x40555410, 0x44555145, 0x44504540, 0x45555550, 0x40004000, 0x96440440, 0x55565565, 0x54454045, 0x40154151, 0x55559155, 0x51405555, 0x00000105 }; #define POW5_TABLE_SIZE 26 static const uint64_t DOUBLE_POW5_TABLE[POW5_TABLE_SIZE] = { 1ull, 5ull, 25ull, 125ull, 625ull, 3125ull, 15625ull, 78125ull, 390625ull, 1953125ull, 9765625ull, 48828125ull, 244140625ull, 1220703125ull, 6103515625ull, 30517578125ull, 152587890625ull, 762939453125ull, 3814697265625ull, 19073486328125ull, 95367431640625ull, 476837158203125ull, 2384185791015625ull, 11920928955078125ull, 59604644775390625ull, 298023223876953125ull //, 1490116119384765625ull }; uint32_t __pow5Factor(uint64_t value) { const uint64_t m_inv_5 = 14757395258967641293u; // 5 * m_inv_5 = 1 (mod 2^64) const uint64_t n_div_5 = 3689348814741910323u; // #{ n | n = 0 (mod 2^64) } = 2^64 / 5 uint32_t count = 0; for (;;) { assert(value != 0); value *= m_inv_5; if (value > n_div_5) break; ++count; } return count; } #if defined(HAS_UINT128) // Computes 5^i in the form required by Ryu, and stores it in the given pointer. void __double_computePow5(const uint32_t i, uint64_t * const result) { const uint32_t base = i / POW5_TABLE_SIZE; const uint32_t base2 = base * POW5_TABLE_SIZE; const uint32_t offset = i - base2; const uint64_t * const mul = DOUBLE_POW5_SPLIT2[base]; if (offset == 0) { result[0] = mul[0]; result[1] = mul[1]; return; } const uint64_t m = DOUBLE_POW5_TABLE[offset]; const uint128_t b0 = ((uint128_t)m) * mul[0]; const uint128_t b2 = ((uint128_t)m) * mul[1]; const uint32_t delta = pow5bits(i) - pow5bits(base2); const uint128_t shiftedSum = (b0 >> delta) + (b2 << (64 - delta)) + ((POW5_OFFSETS[i / 16] >> ((i % 16) << 1)) & 3); result[0] = (uint64_t)shiftedSum; result[1] = (uint64_t)(shiftedSum >> 64); } // Computes 5^-i in the form required by Ryu, and stores it in the given pointer. void __double_computeInvPow5(const uint32_t i, uint64_t * const result) { const uint32_t base = (i + POW5_TABLE_SIZE - 1) / POW5_TABLE_SIZE; const uint32_t base2 = base * POW5_TABLE_SIZE; const uint32_t offset = base2 - i; const uint64_t * const mul = DOUBLE_POW5_INV_SPLIT2[base]; // 1/5^base2 if (offset == 0) { result[0] = mul[0]; result[1] = mul[1]; return; } const uint64_t m = DOUBLE_POW5_TABLE[offset]; // 5^offset const uint128_t b0 = ((uint128_t)m) * (mul[0] - 1); const uint128_t b2 = ((uint128_t)m) * mul[1]; // 1/5^base2 * 5^offset = 1/5^(base2-offset) = 1/5^i const uint32_t delta = pow5bits(base2) - pow5bits(i); const uint128_t shiftedSum = ((b0 >> delta) + (b2 << (64 - delta))) + 1 + ((POW5_INV_OFFSETS[i / 16] >> ((i % 16) << 1)) & 3); result[0] = (uint64_t)shiftedSum; result[1] = (uint64_t)(shiftedSum >> 64); } #else // defined(HAS_UINT128) // Computes 5^i in the form required by Ryu, and stores it in the given pointer. void __double_computePow5(const uint32_t i, uint64_t * const result) { const uint32_t base = i / POW5_TABLE_SIZE; const uint32_t base2 = base * POW5_TABLE_SIZE; const uint32_t offset = i - base2; const uint64_t * const mul = DOUBLE_POW5_SPLIT2[base]; if (offset == 0) { result[0] = mul[0]; result[1] = mul[1]; return; } const uint64_t m = DOUBLE_POW5_TABLE[offset]; uint64_t high1; const uint64_t low1 = umul128(m, mul[1], &high1); uint64_t high0; const uint64_t low0 = umul128(m, mul[0], &high0); const uint64_t sum = high0 + low1; if (sum < high0) { ++high1; // overflow into high1 } // high1 | sum | low0 const uint32_t delta = pow5bits(i) - pow5bits(base2); result[0] = shiftright128(low0, sum, delta) + ((POW5_OFFSETS[i / 16] >> ((i % 16) << 1)) & 3); result[1] = shiftright128(sum, high1, delta); } // Computes 5^-i in the form required by Ryu, and stores it in the given pointer. void __double_computeInvPow5(const uint32_t i, uint64_t * const result) { const uint32_t base = (i + POW5_TABLE_SIZE - 1) / POW5_TABLE_SIZE; const uint32_t base2 = base * POW5_TABLE_SIZE; const uint32_t offset = base2 - i; const uint64_t * const mul = DOUBLE_POW5_INV_SPLIT2[base]; // 1/5^base2 if (offset == 0) { result[0] = mul[0]; result[1] = mul[1]; return; } const uint64_t m = DOUBLE_POW5_TABLE[offset]; uint64_t high1; const uint64_t low1 = umul128(m, mul[1], &high1); uint64_t high0; const uint64_t low0 = umul128(m, mul[0] - 1, &high0); const uint64_t sum = high0 + low1; if (sum < high0) { ++high1; // overflow into high1 } // high1 | sum | low0 const uint32_t delta = pow5bits(base2) - pow5bits(i); result[0] = shiftright128(low0, sum, delta) + 1 + ((POW5_INV_OFFSETS[i / 16] >> ((i % 16) << 1)) & 3); result[1] = shiftright128(sum, high1, delta); } #endif // defined(HAS_UINT128) picolibc-1.8.11/libc/stdio/ryu_umul128.c000066400000000000000000000041341513574234600177150ustar00rootroot00000000000000// Copyright 2018 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. #include #include "ryu/common.h" #include "ryu/d2s_intrinsics.h" #if !defined(HAS_64_BIT_INTRINSICS) uint64_t __umul128(const uint64_t a, const uint64_t b, uint64_t * const productHi) { // The casts here help MSVC to avoid calls to the __allmul library function. const uint32_t aLo = (uint32_t)a; const uint32_t aHi = (uint32_t)(a >> 32); const uint32_t bLo = (uint32_t)b; const uint32_t bHi = (uint32_t)(b >> 32); const uint64_t b00 = (uint64_t)aLo * bLo; const uint64_t b01 = (uint64_t)aLo * bHi; const uint64_t b10 = (uint64_t)aHi * bLo; const uint64_t b11 = (uint64_t)aHi * bHi; const uint32_t b00Lo = (uint32_t)b00; const uint32_t b00Hi = (uint32_t)(b00 >> 32); const uint64_t mid1 = b10 + b00Hi; const uint32_t mid1Lo = (uint32_t)(mid1); const uint32_t mid1Hi = (uint32_t)(mid1 >> 32); const uint64_t mid2 = b01 + mid1Lo; const uint32_t mid2Lo = (uint32_t)(mid2); const uint32_t mid2Hi = (uint32_t)(mid2 >> 32); const uint64_t pHi = b11 + mid1Hi + mid2Hi; const uint64_t pLo = ((uint64_t)mid2Lo << 32) | b00Lo; *productHi = pHi; return pLo; } // Returns the lower 64 bits of (hi*2^64 + lo) >> dist, with 0 < dist < 64. uint64_t __shiftright128(const uint64_t lo, const uint64_t hi, const uint32_t dist) { // We don't need to handle the case dist >= 64 here (see above). assert(dist < 64); assert(dist > 0); return (hi << (64 - dist)) | (lo >> dist); } #endif picolibc-1.8.11/libc/stdio/scanf.c000066400000000000000000000033761513574234600167020ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: scanf.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int scanf(const char *fmt, ...) { va_list ap; int i; va_start(ap, fmt); i = vfscanf(stdin, fmt, ap); va_end(ap); return i; } picolibc-1.8.11/libc/stdio/scanf_private.h000066400000000000000000000104701513574234600204320ustar00rootroot00000000000000/* Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2008 Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SCANF_PRIVATE_H_ #define _SCANF_PRIVATE_H_ #if defined(STRTOF) #define _NEED_IO_FLOAT #elif defined(STRTOD) #define _NEED_IO_DOUBLE #elif defined(STRTOLD) #define _NEED_IO_DOUBLE #define _NEED_IO_LONG_DOUBLE #elif SCANF_VARIANT == __IO_VARIANT_MINIMAL #define _NEED_IO_SHRINK #if defined(__IO_MINIMAL_LONG_LONG) && __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__ #define _NEED_IO_LONG_LONG #endif #ifdef __IO_C99_FORMATS #define _NEED_IO_C99_FORMATS #endif #elif SCANF_VARIANT == __IO_VARIANT_INTEGER #define _NEED_IO_BRACKET #ifdef __IO_POS_ARGS #define _NEED_IO_POS_ARGS #endif #if defined(__IO_LONG_LONG) && __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__ #define _NEED_IO_LONG_LONG #endif #ifdef __IO_C99_FORMATS #define _NEED_IO_C99_FORMATS #endif #ifdef __IO_PERCENT_B #define _NEED_IO_PERCENT_B #endif #elif SCANF_VARIANT == __IO_VARIANT_LLONG #define _NEED_IO_BRACKET #ifdef __IO_POS_ARGS #define _NEED_IO_POS_ARGS #endif #if __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__ #define _NEED_IO_LONG_LONG #endif #ifdef __IO_C99_FORMATS #define _NEED_IO_C99_FORMATS #endif #ifdef __IO_PERCENT_B #define _NEED_IO_PERCENT_B #endif #elif SCANF_VARIANT == __IO_VARIANT_FLOAT #define _NEED_IO_BRACKET #if __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__ #define _NEED_IO_LONG_LONG #endif #define _NEED_IO_POS_ARGS #define _NEED_IO_C99_FORMATS #ifdef __IO_PERCENT_B #define _NEED_IO_PERCENT_B #endif #define _NEED_IO_FLOAT #elif SCANF_VARIANT == __IO_VARIANT_DOUBLE #define _NEED_IO_BRACKET #define _NEED_IO_WCHAR #if __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__ #define _NEED_IO_LONG_LONG #endif #define _NEED_IO_POS_ARGS #define _NEED_IO_C99_FORMATS #ifdef __IO_PERCENT_B #define _NEED_IO_PERCENT_B #endif #define _NEED_IO_DOUBLE #if defined(__IO_LONG_DOUBLE) && __SIZEOF_LONG_DOUBLE__ > __SIZEOF_DOUBLE__ #define _NEED_IO_LONG_DOUBLE #endif #else #error "Not a known scanf variant." #endif #if defined(WIDE_CHARS) && !defined(_NEED_IO_WCHAR) #define _NEED_IO_WCHAR #endif typedef unsigned int width_t; #define FL_STAR 0x01 /* '*': skip assignment */ #define FL_WIDTH 0x02 /* width is present */ #define FL_LONG 0x04 /* 'long' type modifier */ #if defined(_NEED_IO_LONG_LONG) || defined(_NEED_IO_LONG_DOUBLE) #define FL_LONGLONG 0x08 /* 'long long' type modifier */ #else #define FL_LONGLONG 0x00 /* 'long long' type modifier */ #endif #define FL_CHAR 0x10 /* 'char' type modifier */ #define FL_SHORT 0x20 /* 'short' type modifier */ #define FL_MINUS 0x40 /* minus flag (field or value) */ #define FL_ANY 0x80 /* any digit was read */ #define FL_OVFL 0x100 /* significand overflowed */ #define FL_DOT 0x200 /* decimal '.' was */ #define FL_MEXP 0x400 /* exponent 'e' is neg. */ #define FL_FHEX 0x800 /* hex significand */ #endif /* _SCANF_PRIVATE_H_ */ picolibc-1.8.11/libc/stdio/setbuf.c000066400000000000000000000033161513574234600170720ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" void setbuf(FILE *stream, char *buf) { setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ); } picolibc-1.8.11/libc/stdio/setbuffer.c000066400000000000000000000033341513574234600175670ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" void setbuffer(FILE *stream, char *buf, size_t size) { setvbuf(stream, buf, buf ? _IOFBF : _IONBF, size); } picolibc-1.8.11/libc/stdio/setlinebuf.c000066400000000000000000000032641513574234600177440ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2019 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" void setlinebuf(FILE *stream) { setvbuf(stream, NULL, _IOLBF, 0); } picolibc-1.8.11/libc/stdio/setvbuf.c000066400000000000000000000041661513574234600172640ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int setvbuf(FILE *stream, char *buf, int mode, size_t size) { struct __file_ext *xf = (struct __file_ext *)stream; int ret = 0; __flockfile(stream); if (stream->flags & __SEXT) { int (*setvbuf)(struct __file *, char *buf, int mode, size_t size); setvbuf = xf->setvbuf; if (!setvbuf && (stream->flags & __SBUF)) setvbuf = __bufio_setvbuf; if (setvbuf) ret = setvbuf(stream, buf, mode, size); } __funlock_return(stream, ret); } picolibc-1.8.11/libc/stdio/sflags.c000066400000000000000000000033421513574234600170600ustar00rootroot00000000000000/* * Copyright (c) 1990 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * and/or other materials related to such * distribution and use acknowledge that the software was developed * by the University of California, Berkeley. The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* No user fns here. Pesch 15apr92 */ #include "stdio_private.h" /* * Return the (stdio) flags for a given mode. Store the flags to be * passed to open() through *optr. * * Return 0 on error. */ int __stdio_flags(const char *mode, int *optr) { int ret; int o; switch (mode[0]) { case 'r': /* open for reading */ ret = __SRD; o = O_RDONLY; break; case 'w': /* open for writing */ ret = __SWR; o = O_WRONLY | O_CREAT | O_TRUNC; break; case 'a': /* open for appending */ ret = __SWR; o = O_WRONLY | O_CREAT | O_APPEND; break; default: /* illegal mode */ errno = EINVAL; return (0); } while (*++mode) { switch (*mode) { case '+': ret |= (__SRD | __SWR); o = (o & ~O_ACCMODE) | O_RDWR; break; default: break; } } *optr = o; return ret; } picolibc-1.8.11/libc/stdio/snprintf.c000066400000000000000000000037271513574234600174530ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: snprintf.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int snprintf(char *s, size_t n, const char *fmt, ...) { va_list ap; int i; struct __file_str f = FDEV_SETUP_STRING_WRITE(s, FDEV_STRING_WRITE_END(s, n)); va_start(ap, fmt); i = vfprintf(&f.file, fmt, ap); va_end(ap); if (n) *f.pos = '\0'; return i; } __ieee128_reference(snprintf, __snprintfieee128); picolibc-1.8.11/libc/stdio/snprintfd.c000066400000000000000000000032441513574234600176110ustar00rootroot00000000000000/* Copyright © 2021 Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define vfprintf __d_vfprintf #define snprintf __d_snprintf #define __snprintfieee128 __d_snprintfieee128 #include "snprintf.c" picolibc-1.8.11/libc/stdio/snprintff.c000066400000000000000000000032441513574234600176130ustar00rootroot00000000000000/* Copyright © 2021 Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define vfprintf __f_vfprintf #define snprintf __f_snprintf #define __snprintfieee128 __f_snprintfieee128 #include "snprintf.c" picolibc-1.8.11/libc/stdio/sprintf.c000066400000000000000000000036611513574234600172720ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: sprintf.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int sprintf(char *s, const char *fmt, ...) { va_list ap; struct __file_str f = FDEV_SETUP_STRING_WRITE(s, NULL); int i; va_start(ap, fmt); i = vfprintf(&f.file, fmt, ap); va_end(ap); if (i >= 0) s[i] = 0; return i; } __ieee128_reference(sprintf, __sprintfieee128); picolibc-1.8.11/libc/stdio/sprintf_s.c000066400000000000000000000051671513574234600176170ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define __STDC_WANT_LIB_EXT1__ 1 #include "stdio_private.h" #include #include #include #include "../stdlib/local_s.h" int sprintf_s(char * __restrict s, rsize_t bufsize, const char * __restrict fmt, ...) { bool write_null = true; const char *msg = ""; va_list args; int rc; if (s == NULL) { write_null = false; msg = "dest buffer is null"; goto handle_error; } else if ((bufsize == 0) || (CHECK_RSIZE(bufsize))) { write_null = false; msg = "invalid buffer size"; goto handle_error; } else { va_start(args, fmt); rc = vsnprintf_s(s, bufsize, fmt, args); va_end(args); } if (rc < 0) { rc = 0; } // Normal return path return rc; handle_error: if (__cur_handler != NULL) { __cur_handler(msg, NULL, -1); } rc = 0; /* standard stipulates this */ if (write_null && s != NULL) { s[0] = '\0'; /* again, standard requires this */ } return rc; } picolibc-1.8.11/libc/stdio/sprintfd.c000066400000000000000000000032361513574234600174340ustar00rootroot00000000000000/* Copyright © 2018 Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define vfprintf __d_vfprintf #define sprintf __d_sprintf #define __sprintfieee128 __d_sprintfieee128 #include "sprintf.c" picolibc-1.8.11/libc/stdio/sprintff.c000066400000000000000000000032361513574234600174360ustar00rootroot00000000000000/* Copyright © 2018 Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define vfprintf __f_vfprintf #define sprintf __f_sprintf #define __sprintfieee128 __f_sprintfieee128 #include "sprintf.c" picolibc-1.8.11/libc/stdio/sscanf.c000066400000000000000000000035311513574234600170560ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: sscanf.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int sscanf(const char *s, const char *fmt, ...) { va_list ap; int i; struct __file_str f = FDEV_SETUP_STRING_READ(s); va_start(ap, fmt); i = vfscanf(&f.file, fmt, ap); va_end(ap); return i; } picolibc-1.8.11/libc/stdio/stdio_private.h000066400000000000000000000601041513574234600204610ustar00rootroot00000000000000/* Copyright (c) 2002,2005, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: stdio_private.h 847 2005-09-06 18:49:15Z joerg_wunsch $ */ #ifndef _STDIO_PRIVATE_H_ #define _STDIO_PRIVATE_H_ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef __FSTAT_BUFSIZ #include #endif struct __file_str { struct __file file; /* main file struct */ char *pos; /* current buffer position */ char *end; /* end of buffer */ size_t size; /* size of allocated storage */ bool alloc; /* current storage was allocated */ }; int __file_str_get(FILE *stream); int __file_wstr_get(FILE *stream); int __file_str_put(char c, FILE *stream); int __file_str_put_alloc(char c, FILE *stream); extern const char __match_inf[]; extern const char __match_inity[]; extern const char __match_nan[]; /* Returns 'true' if prefix of input matches pattern, independent of * case. pattern is only upper case letters. */ bool __matchcaseprefix(const char *input, const char *pattern); /* * It is OK to discard the "const" qualifier here. f.buf is * non-const as in the generic case, this buffer is obtained * by malloc(). In the scanf case however, the buffer is * really only be read (by getc()), and as this our FILE f we * be discarded upon exiting sscanf(), nobody will ever get * a chance to get write access to it again. */ #define FDEV_SETUP_STRING_READ(_s) \ { \ .file = { .flags = __SRD, .get = __file_str_get, __LOCK_INIT_NONE }, \ .pos = (char *)(_s) \ } #define FDEV_SETUP_WSTRING_READ(_s) \ { \ .file = { .flags = __SRD, .get = __file_wstr_get, __LOCK_INIT_NONE }, \ .pos = (char *)(_s), \ .end = (char *)(_s) \ } #define FDEV_STRING_WRITE_END(_s, _n) (((int)(_n) < 0) ? NULL : ((_n) ? (_s) + (_n) - 1 : (_s))) #define FDEV_SETUP_STRING_WRITE(_s, _end) \ { \ .file = { .flags = __SWR, .put = __file_str_put, __LOCK_INIT_NONE }, \ .pos = (_s), \ .end = (_end), \ } #define FDEV_SETUP_STRING_ALLOC() \ { \ .file = { .flags = __SWR, .put = __file_str_put_alloc, __LOCK_INIT_NONE }, \ .pos = NULL, \ .end = NULL, \ .size = 0, \ .alloc = false, \ } #define FDEV_SETUP_STRING_ALLOC_BUF(_buf, _size) \ { \ .file = { .flags = __SWR, .put = __file_str_put_alloc, __LOCK_INIT_NONE }, \ .pos = _buf, \ .end = (char *)(_buf) + (_size), \ .size = _size, \ .alloc = false, \ } #define _FDEV_BUFIO_FD(bf) ((int)((intptr_t)(bf)->ptr)) #define IO_VARIANT_IS_FLOAT(v) ((v) == __IO_VARIANT_FLOAT || (v) == __IO_VARIANT_DOUBLE) /* * While there are notionally two different ways to invoke the * callbacks (one with an int and the other with a pointer), they are * functionally identical on many architectures. Check for that and * skip the extra code. */ #if __SIZEOF_POINTER__ == __SIZEOF_INT__ || defined(__x86_64) || defined(__arm__) \ || defined(__riscv) #define BUFIO_ABI_MATCHES #endif #if defined(__has_feature) #if __has_feature(undefined_behavior_sanitizer) #undef BUFIO_ABI_MATCHES #endif #endif /* Buffered I/O routines */ static inline ssize_t bufio_read(struct __file_bufio *bf, void *buf, size_t count) { #ifndef BUFIO_ABI_MATCHES if (!(bf->bflags & __BFPTR)) return (bf->read_int)(_FDEV_BUFIO_FD(bf), buf, count); #endif return (bf->read_ptr)((void *)bf->ptr, buf, count); } static inline ssize_t bufio_write(struct __file_bufio *bf, const void *buf, size_t count) { #ifndef BUFIO_ABI_MATCHES if (!(bf->bflags & __BFPTR)) return (bf->write_int)(_FDEV_BUFIO_FD(bf), buf, count); #endif return (bf->write_ptr)((void *)bf->ptr, buf, count); } static inline __off_t bufio_lseek(struct __file_bufio *bf, __off_t offset, int whence) { #ifndef BUFIO_ABI_MATCHES if (!(bf->bflags & __BFPTR)) { if (bf->lseek_int) return (bf->lseek_int)(_FDEV_BUFIO_FD(bf), offset, whence); } else #endif { if (bf->lseek_ptr) return (bf->lseek_ptr)((void *)bf->ptr, offset, whence); } return _FDEV_ERR; } static inline int bufio_close(struct __file_bufio *bf) { int ret = 0; #ifndef BUFIO_ABI_MATCHES if (!(bf->bflags & __BFPTR)) { if (bf->close_int) ret = (bf->close_int)(_FDEV_BUFIO_FD(bf)); } else #endif { if (bf->close_ptr) ret = (bf->close_ptr)((void *)bf->ptr); } return ret; } #define FDEV_SETUP_POSIX(fd, buf, size, rwflags, bflags) \ FDEV_SETUP_BUFIO(fd, buf, size, read, write, lseek, close, rwflags, bflags) #if defined(__FSTAT_BUFSIZ) && defined(_STAT_HAS_ST_BLKSIZE) static inline size_t bufio_get_buf_size(int fd) { struct stat stat; if (fstat(fd, &stat) == 0 && stat.st_blksize > 0) { return stat.st_blksize; } return BUFSIZ; } #else #define bufio_get_buf_size(fd) (BUFSIZ) #endif int __stdio_flags(const char *mode, int *optr); #ifdef __STDIO_LOCKING void __flockfile_init(FILE *f); #define __LOCK_NONE ((_LOCK_RECURSIVE_T)(uintptr_t)1) #define __LOCK_INIT_NONE .lock = __LOCK_NONE #else #define __LOCK_INIT_NONE #endif #define __funlock_return(f, v) \ do { \ __funlockfile(f); \ return (v); \ } while (0) static inline void __flockfile(FILE *f) { (void)f; #ifdef __STDIO_LOCKING if (!f->lock) __flockfile_init(f); if (f->lock != __LOCK_NONE) __lock_acquire_recursive(f->lock); #endif } static inline void __funlockfile(FILE *f) { (void)f; #ifdef __STDIO_LOCKING if (f->lock != __LOCK_NONE) __lock_release_recursive(f->lock); #endif } static inline void __flockfile_close(FILE *f) { (void)f; #ifdef __STDIO_LOCKING if (f->lock && f->lock != __LOCK_NONE) __lock_close(f->lock); #endif } /* Silence santizer errors when adding/subtracting 0 to a NULL pointer */ #ifdef __clang__ #define POINTER_MINUS(a, b) ((__typeof(a))((uintptr_t)(a) - (b) * sizeof((*a)))) #define POINTER_PLUS(a, b) ((__typeof(a))((uintptr_t)(a) + (b) * sizeof((*a)))) #else #define POINTER_MINUS(a, b) ((a) - (b)) #define POINTER_PLUS(a, b) ((a) + (b)) #endif int __d_vfprintf(FILE *__stream, const char *__fmt, va_list __ap) __FORMAT_ATTRIBUTE__(printf, 2, 0); int __f_vfprintf(FILE *__stream, const char *__fmt, va_list __ap) __FORMAT_ATTRIBUTE__(printf, 2, 0); int __i_vfprintf(FILE *__stream, const char *__fmt, va_list __ap) __FORMAT_ATTRIBUTE__(printf, 2, 0); int __l_vfprintf(FILE *__stream, const char *__fmt, va_list __ap) __FORMAT_ATTRIBUTE__(printf, 2, 0); int __m_vfprintf(FILE *__stream, const char *__fmt, va_list __ap) __FORMAT_ATTRIBUTE__(printf, 2, 0); int __d_sprintf(char *__s, const char *__fmt, ...) __FORMAT_ATTRIBUTE__(printf, 2, 0); int __f_sprintf(char *__s, const char *__fmt, ...) __FORMAT_ATTRIBUTE__(printf, 2, 0); int __i_sprintf(char *__s, const char *__fmt, ...) __FORMAT_ATTRIBUTE__(printf, 2, 0); int __l_sprintf(char *__s, const char *__fmt, ...) __FORMAT_ATTRIBUTE__(printf, 2, 0); int __m_sprintf(char *__s, const char *__fmt, ...) __FORMAT_ATTRIBUTE__(printf, 2, 0); int __d_snprintf(char *__s, size_t __n, const char *__fmt, ...) __FORMAT_ATTRIBUTE__(printf, 3, 0); int __f_snprintf(char *__s, size_t __n, const char *__fmt, ...) __FORMAT_ATTRIBUTE__(printf, 3, 0); int __i_snprintf(char *__s, size_t __n, const char *__fmt, ...) __FORMAT_ATTRIBUTE__(printf, 3, 0); int __l_snprintf(char *__s, size_t __n, const char *__fmt, ...) __FORMAT_ATTRIBUTE__(printf, 3, 0); int __m_snprintf(char *__s, size_t __n, const char *__fmt, ...) __FORMAT_ATTRIBUTE__(printf, 3, 0); int __d_vfscanf(FILE *__stream, const char *__fmt, va_list __ap) __FORMAT_ATTRIBUTE__(scanf, 2, 0); int __f_vfscanf(FILE *__stream, const char *__fmt, va_list __ap) __FORMAT_ATTRIBUTE__(scanf, 2, 0); int __i_vfscanf(FILE *__stream, const char *__fmt, va_list __ap) __FORMAT_ATTRIBUTE__(scanf, 2, 0); int __l_vfscanf(FILE *__stream, const char *__fmt, va_list __ap) __FORMAT_ATTRIBUTE__(scanf, 2, 0); int __m_vfscanf(FILE *__stream, const char *__fmt, va_list __ap) __FORMAT_ATTRIBUTE__(scanf, 2, 0); int __d_swprintf(wchar_t * __restrict, size_t, const wchar_t * __restrict, ...); #if __SIZEOF_DOUBLE__ == 8 #define FLOAT64 double #define _asdouble(x) _asfloat64(x) #elif __SIZEOF_LONG_DOUBLE__ == 8 #define FLOAT64 long double #endif #if __SIZEOF_DOUBLE__ == 4 #define FLOAT32 double #define _asdouble(x) ((double)_asfloat(x)) #elif __SIZEOF_FLOAT__ == 4 #define FLOAT32 float #elif __SIZEOF_LONG_DOUBLE__ == 4 #define FLOAT32 long double #endif #ifdef FLOAT64 FLOAT64 __atod_engine(uint64_t m10, int e10); #endif float __atof_engine(uint32_t m10, int e10); #ifdef __SIZEOF_INT128__ typedef __uint128_t _u128; typedef __int128_t _i128; #define to_u128(x) (x) #define from_u128(x) (x) #define _u128_to_ld(a) ((long double)(a)) #define _u128_is_zero(a) ((a) == 0) #define _i128_lt_zero(a) ((_i128)(a) < 0) #define _u128_plus_64(a, b) ((a) + (b)) #define _u128_plus(a, b) ((a) + (b)) #define _u128_minus(a, b) ((a) - (b)) #define _u128_minus_64(a, b) ((a) - (b)) #define _u128_times_10(a) ((a) * 10) #define _u128_times_base(a, b) ((a) * (b)) #define _u128_to_ld(a) ((long double)(a)) #define _u128_oflow(a) \ ((a) >= (((((_u128)0xffffffffffffffffULL) << 64) | 0xffffffffffffffffULL) - 9 / 10)) #define _u128_zero (_u128)0 #define _u128_lshift(a, b) ((_u128)(a) << (b)) #define _u128_lshift_64(a, b) ((_u128)(a) << (b)) #define _u128_rshift(a, b) ((a) >> (b)) #define _i128_rshift(a, b) ((_i128)(a) >> (b)) #define _u128_or_64(a, b) ((a) | (_u128)(b)) #define _u128_and_64(a, b) ((uint64_t)(a) & (b)) #define _u128_or(a, b) ((a) | (b)) #define _u128_and(a, b) ((a) & (b)) #define _u128_eq(a, b) ((a) == (b)) #define _u128_ge(a, b) ((a) >= (b)) #define _i128_ge(a, b) ((_i128)(a) >= (_i128)(b)) #define _u128_lt(a, b) ((a) < (b)) #define _i128_lt(a, b) ((_i128)(a) < (_i128)(b)) #define _u128_not(a) (~(a)) #else typedef struct { #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ uint64_t lo, hi; #else uint64_t hi, lo; #endif } _u128; #define _u128_zero (_u128) { 0, 0 } static inline _u128 to_u128(uint64_t x) { _u128 a = { .hi = 0, .lo = x }; return a; } static inline uint64_t from_u128(_u128 a) { return a.lo; } static inline long double _u128_to_ld(_u128 a) { return (long double)a.hi * ((long double)(1LL << 32) * (long double)(1LL << 32)) + (long double)a.lo; } static inline bool _u128_is_zero(_u128 a) { return a.hi == 0 && a.lo == 0; } static inline bool _i128_lt_zero(_u128 a) { return (int64_t)a.hi < 0; } static inline bool _u128_eq(_u128 a, _u128 b) { return (a.hi == b.hi) && (a.lo == b.lo); } static inline bool _u128_lt(_u128 a, _u128 b) { if (a.hi == b.hi) return a.lo < b.lo; return a.hi < b.hi; } static inline bool _i128_lt(_u128 a, _u128 b) { if (a.hi == b.hi) { if ((int64_t)a.hi < 0) return a.lo > b.lo; else return a.lo < b.lo; } return (int64_t)a.hi < (int64_t)b.hi; } static inline bool _u128_ge(_u128 a, _u128 b) { if (a.hi == b.hi) return a.lo >= b.lo; return a.hi >= b.hi; } static inline bool _i128_ge(_u128 a, _u128 b) { if (a.hi == b.hi) { if ((int64_t)a.hi < 0) return a.lo <= b.lo; else return a.lo >= b.lo; } return (int64_t)a.hi >= (int64_t)b.hi; } static inline _u128 _u128_plus_64(_u128 a, uint64_t b) { _u128 v; v.lo = a.lo + b; v.hi = a.hi; if (v.lo < a.lo) v.hi++; return v; } static inline _u128 _u128_plus(_u128 a, _u128 b) { _u128 v; v.lo = a.lo + b.lo; v.hi = a.hi + b.hi; if (v.lo < a.lo) v.hi++; return v; } static inline _u128 _u128_minus_64(_u128 a, uint64_t b) { _u128 v; v.lo = a.lo - b; v.hi = a.hi; if (v.lo > a.lo) v.hi--; return v; } static inline _u128 _u128_minus(_u128 a, _u128 b) { _u128 v; v.lo = a.lo - b.lo; v.hi = a.hi - b.hi; if (v.lo > a.lo) v.hi--; return v; } static inline _u128 _u128_lshift(_u128 a, int amt) { _u128 v; if (amt == 0) { v = a; } else if (amt < 64) { v.lo = a.lo << amt; v.hi = (a.lo >> (64 - amt)) | (a.hi << amt); } else { v.lo = 0; v.hi = a.lo << (amt - 64); } return v; } static inline _u128 _u128_lshift_64(uint64_t a, int amt) { _u128 v; if (amt == 0) { v.lo = a; v.hi = 0; } else if (amt < 64) { v.lo = a << amt; v.hi = (a >> (64 - amt)); } else { v.lo = 0; v.hi = a << (amt - 64); } return v; } static inline _u128 _u128_rshift(_u128 a, int amt) { _u128 v; if (amt == 0) { v = a; } else if (amt < 64) { v.lo = (a.hi << (64 - amt)) | (a.lo >> amt); v.hi = a.hi >> amt; } else { v.hi = 0; v.lo = a.hi >> (amt - 64); } return v; } static inline _u128 _u128_and(_u128 a, _u128 b) { _u128 v; v.hi = a.hi & b.hi; v.lo = a.lo & b.lo; return v; } static inline uint64_t _u128_and_64(_u128 a, uint64_t b) { return a.lo & b; } static inline _u128 _u128_or(_u128 a, _u128 b) { _u128 v; v.lo = a.lo | b.lo; v.hi = a.hi | b.hi; return v; } static inline _u128 _u128_or_64(_u128 a, uint64_t b) { _u128 v; v.lo = a.lo | b; v.hi = a.hi; return v; } static inline _u128 _u128_not(_u128 a) { _u128 v; v.lo = ~a.lo; v.hi = ~a.hi; return v; } static inline _u128 _u128_times_10(_u128 a) { return _u128_plus(_u128_lshift(a, 3), _u128_lshift(a, 1)); } static inline _u128 _u128_times_base(_u128 a, int base) { if (base == 10) return _u128_times_10(a); return _u128_lshift(a, 4); } static inline bool _u128_oflow(_u128 a) { return a.hi >= (0xffffffffffffffffULL - 9) / 10; } #endif #if __SIZEOF_LONG_DOUBLE__ > 8 static inline _u128 asuintld(long double f) { union { long double f; _u128 i; } v; _u128 i; v.f = f; i = v.i; #if defined(__IEEE_BIG_ENDIAN) && __SIZEOF_LONG_DOUBLE__ != 16 i = _u128_rshift(i, (16 - __SIZEOF_LONG_DOUBLE__) * 8); #endif return i; } static inline long double aslongdouble(_u128 i) { union { long double f; _u128 i; } v; #if defined(__IEEE_BIG_ENDIAN) && __SIZEOF_LONG_DOUBLE__ != 16 i = _u128_lshift(i, (16 - __SIZEOF_LONG_DOUBLE__) * 8); #endif v.i = i; return v.f; } #elif __SIZEOF_LONG_DOUBLE__ == 8 static inline uint64_t asuintld(long double f) { union { long double f; uint64_t i; } v; v.f = f; return v.i; } static inline long double aslongdouble(uint64_t i) { union { long double f; uint64_t i; } v; v.i = i; return v.f; } #elif __SIZEOF_LONG_DOUBLE__ == 4 static inline uint32_t asuintld(long double f) { union { long double f; uint32_t i; } v; v.f = f; return v.i; } static inline long double aslongdouble(uint32_t i) { union { long double f; uint32_t i; } v; v.i = i; return v.f; } #endif static inline bool _u128_gt(_u128 a, _u128 b) { return _u128_lt(b, a); } long double __atold_engine(_u128 m10, int e10); static inline __ungetc_t __non_atomic_exchange_ungetc(__ungetc_t *p, __ungetc_t v) { __ungetc_t e = *p; *p = v; return e; } static inline bool __non_atomic_compare_exchange_ungetc(__ungetc_t *p, __ungetc_t d, __ungetc_t v) { if (*p != d) return false; *p = v; return true; } static inline __ungetc_t __non_atomic_load_ungetc(const volatile __ungetc_t *p) { return *p; } static inline void __non_atomic_store_ungetc(__ungetc_t *p, __ungetc_t v) { *p = v; } #if defined(__LONG_DOUBLE_128__) && defined(__strong_reference) #if defined(__GNUCLIKE_PRAGMA_DIAGNOSTIC) && !defined(__clang__) #pragma GCC diagnostic ignored "-Wmissing-attributes" #endif #define __ieee128_reference(a, b) __strong_reference(a, b) #else #define __ieee128_reference(a, b) #endif #ifdef __ATOMIC_UNGETC #if __PICOLIBC_UNGETC_SIZE == 4 && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) #define PICOLIBC_HAVE_SYNC_COMPARE_AND_SWAP #endif #if __PICOLIBC_UNGETC_SIZE == 2 && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) #define PICOLIBC_HAVE_SYNC_COMPARE_AND_SWAP #endif #ifdef PICOLIBC_HAVE_SYNC_COMPARE_AND_SWAP /* Use built-in atomic functions if they exist */ #include static inline bool __atomic_compare_exchange_ungetc(__ungetc_t *p, __ungetc_t d, __ungetc_t v) { _Atomic __ungetc_t *pa = (_Atomic __ungetc_t *)p; return atomic_compare_exchange_strong(pa, &d, v); } static inline __ungetc_t __atomic_exchange_ungetc(__ungetc_t *p, __ungetc_t v) { _Atomic __ungetc_t *pa = (_Atomic __ungetc_t *)p; return atomic_exchange_explicit(pa, v, memory_order_relaxed); } static inline __ungetc_t __atomic_load_ungetc(const volatile __ungetc_t *p) { _Atomic __ungetc_t *pa = (_Atomic __ungetc_t *)p; return atomic_load(pa); } static inline void __atomic_store_ungetc(__ungetc_t *p, __ungetc_t v) { _Atomic __ungetc_t *pa = (_Atomic __ungetc_t *)p; atomic_store(pa, v); } #else bool __atomic_compare_exchange_ungetc(__ungetc_t *p, __ungetc_t d, __ungetc_t v); __ungetc_t __atomic_exchange_ungetc(__ungetc_t *p, __ungetc_t v); __ungetc_t __atomic_load_ungetc(const volatile __ungetc_t *p); void __atomic_store_ungetc(__ungetc_t *p, __ungetc_t v); __ungetc_t __picolibc_non_atomic_load_ungetc(const volatile __ungetc_t *p); __ungetc_t __picolibc_non_atomic_exchange_ungetc(__ungetc_t *p, __ungetc_t v); bool __picolibc_non_atomic_compare_exchange_ungetc(__ungetc_t *p, __ungetc_t d, __ungetc_t v); void __picolibc_non_atomic_store_ungetc(__ungetc_t *p, __ungetc_t v); #endif /* PICOLIBC_HAVE_SYNC_COMPARE_AND_SWAP */ #else #define __atomic_compare_exchange_ungetc(p, d, v) __non_atomic_compare_exchange_ungetc(p, d, v) #define __atomic_exchange_ungetc(p, v) __non_atomic_exchange_ungetc(p, v) #define __atomic_load_ungetc(p) (*(p)) #define __atomic_store_ungetc(p, v) (*(p) = (v)) #endif /* __ATOMIC_UNGETC */ /* * This operates like _tolower on upper case letters, but also works * correctly on lower case letters. */ #define TOLOWER(c) ((c) | ('a' - 'A')) /* * Convert a single character to the value of the digit for any * character 0 .. 9, A .. Z or a .. z * * Characters out of these ranges will return a value above 36 * * Work in unsigned int type to avoid extra instructions required for * unsigned char folding. The only time this matters is when * subtracting '0' from values below '0', which results in very large * unsigned values. */ static inline unsigned int digit_to_val(unsigned int c) { /* * Convert letters with some tricky code. * * TOLOWER(c-1) maps characters as follows (Skipping values not * greater than '9' (0x39), as those are skipped by the 'if'): * * Minus 1, bitwise-OR ('a' - 'A') (0x20): * * 0x3a..0x40 -> 0x39..0x3f * 0x41..0x60, 0x61..0x80 -> 0x60..0x7f * 0x81..0xa0, 0xa1..0xc0 -> 0xa0..0xbf * 0xc1..0xe0, 0xe1..0x00 -> 0xe0..0xff * * Plus '0' (0x30), minus 'a') (0x61), plus 11 (0xb), for * a total of minus 0x26: * * 0x3a..0x40 -> 0x39..0x3f -> 0x13..0x19 * 0x41..0x60, 0x61..0x80 -> 0x60..0x7f -> 0x3a..0x59 * 0x81..0xa0, 0xa1..0xc0 -> 0xa0..0xbf -> 0x7a..0x99 * 0xc1..0xe0, 0xe1..0x00 -> 0xe0..0xff -> 0xba..0xd9 */ if (c > '9') { /* * For the letters, we want TOLOWER(c) - 'a' + 10, but that * would map both '@' and '`' to 9. * * To work around this, subtract 1 before the bitwise-or so * that '@' (0x40) gets mapped down to 0x3f (0x3f | 0x20) * while '`' (0x60) gets mapped up to 0x7f (0x5f | 0x20), * moving them away from the letters (which end up in the * range 0x60..0x79). Then add the 1 back in when subtracting * 'a' and adding 10. * * Add in '0' so that it can get subtracted out in the common * code (c -= '0') below, avoiding an else clause. */ c = TOLOWER(c - 1) + ('0' - 'a' + 11); } /* * Now, include the range from NUL (0x00) through '9' (0x39) * * Minus '0' (0x30): * * 0x00..0x2f ->-0x30..-0x01 * 0x30..0x39 -> 0x00..0x09 * * 0x3a..0x40 -> 0x39..0x3f -> 0x13..0x19 ->-0x1d..-0x17 * 0x41..0x60, 0x61..0x80 -> 0x60..0x7f -> 0x3a..0x59 -> 0x0a..0x29 * * 0x81..0xa0, 0xa1..0xc0 -> 0xa0..0xbf -> 0x7a..0x99 -> 0x4a..0x69 * 0xc1..0xe0, 0xe1..0x00 -> 0xe0..0xff -> 0xba..0xd9 -> 0x8a..0xa9 * * The first starred row has the digits '0'..'9', while the second * starts with the letters 'A'..'Z' and 'a'..'z'. All of the other * rows end up with values above any allowed conversion base */ c -= '0'; return c; } #endif /* _STDIO_PRIVATE_H_ */ picolibc-1.8.11/libc/stdio/strfromd.c000066400000000000000000000033621513574234600174430ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2021 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int strfromd(char * restrict str, size_t n, const char * restrict format, double fp) { return __d_snprintf(str, n, format, fp); } picolibc-1.8.11/libc/stdio/strfromf.c000066400000000000000000000034011513574234600174370ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2021 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int strfromf(char * restrict str, size_t n, const char * restrict format, float fp) { return __f_snprintf(str, n, format, __printf_float(fp)); } picolibc-1.8.11/libc/stdio/strfroml.c000066400000000000000000000052261513574234600174540ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2021 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int strfroml(char * restrict str, size_t n, const char * restrict format, long double fp) { char nformat[32]; const char *f; bool found_percent; bool inserted_L; char *nf; /* if there's not space for a replacement format, just bail */ if (strlen(format) > sizeof(nformat) - 2) return __d_snprintf(str, n, format, (double)fp); nf = nformat; f = format; found_percent = false; inserted_L = false; while (*f) { char c = *f++; switch (c) { case '%': found_percent = true; break; case 'e': case 'E': case 'f': case 'F': case 'g': case 'G': case 'a': case 'A': if (found_percent && !inserted_L) { *nf++ = 'L'; inserted_L = true; } found_percent = false; break; default: break; } *nf++ = c; } *nf = '\0'; return __d_snprintf(str, n, nformat, fp); } picolibc-1.8.11/libc/stdio/strtod.c000066400000000000000000000070731513574234600171250ustar00rootroot00000000000000/* Copyright (c) 2002-2005 Michael Stumpf Copyright (c) 2006,2008 Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: strtod.c 2191 2010-11-05 13:45:57Z arcanum $ */ /** The strtod() function converts the initial portion of the string pointed to by \a nptr to double representation. The expected form of the string is an optional plus ( \c '+' ) or minus sign ( \c '-' ) followed by a sequence of digits optionally containing a decimal-point character, optionally followed by an exponent. An exponent consists of an \c 'E' or \c 'e', followed by an optional plus or minus sign, followed by a sequence of digits. Leading white-space characters in the string are skipped. The strtod() function returns the converted value, if any. If \a endptr is not \c NULL, a pointer to the character after the last character used in the conversion is stored in the location referenced by \a endptr. If no conversion is performed, zero is returned and the value of \a nptr is stored in the location referenced by \a endptr. If the correct value would cause overflow, plus or minus \c INFINITY is returned (according to the sign of the value), and \c ERANGE is stored in \c errno. If the correct value would cause underflow, zero is returned and \c ERANGE is stored in \c errno. */ #define STRTOD #include "stdio_private.h" #include "conv_flt.c" #ifdef WIDE_CHARS #define strtod wcstod #define strtold wcstold #endif double strtod(const CHAR *nptr, CHAR **endptr) { int len = 0; double flt; UCHAR ret; while (ISSPACE(nptr[len])) len++; ret = conv_flt(nptr, &len, INT_MAX, &flt, FL_LONG); if (!ret) { flt = 0.0; len = 0; } if (endptr) *endptr = (CHAR *)nptr + len; return flt; } #if defined(__HAVE_LONG_DOUBLE) && __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__ #ifdef __strong_reference __strong_reference_dup(strtod, strtold); #else long double strtold(const CHAR *nptr, CHAR **endptr) { return (long double)strtod(nptr, endptr); } #endif #endif picolibc-1.8.11/libc/stdio/strtod_l.c000066400000000000000000000042301513574234600174300ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #ifdef WIDE_CHARS #include #define strtod_l wcstod_l #define strtod wcstod #define strtold_l wcstold_l #define char wchar_t #endif double strtod_l(const char * __restrict s00, char ** __restrict se, locale_t loc) { (void)loc; return strtod(s00, se); } #if defined(__HAVE_LONG_DOUBLE) && defined(_LDBL_EQ_DBL) #ifdef __strong_reference __strong_reference_dup(strtod_l, strtold_l); #else long double strtold_l(const char *nptr, char **endptr, locale_t loc) { return (long double)strtod_l(nptr, endptr, loc); } #endif #endif picolibc-1.8.11/libc/stdio/strtof.c000066400000000000000000000064121513574234600171230ustar00rootroot00000000000000/* Copyright (c) 2002-2005 Michael Stumpf Copyright (c) 2006,2008 Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: strtof.c 2191 2010-11-05 13:45:57Z arcanum $ */ /** The strtof() function converts the initial portion of the string pointed to by \a nptr to float representation. The expected form of the string is an optional plus ( \c '+' ) or minus sign ( \c '-' ) followed by a sequence of digits optionally containing a decimal-point character, optionally followed by an exponent. An exponent consists of an \c 'E' or \c 'e', followed by an optional plus or minus sign, followed by a sequence of digits. Leading white-space characters in the string are skipped. The strtof() function returns the converted value, if any. If \a endptr is not \c NULL, a pointer to the character after the last character used in the conversion is stored in the location referenced by \a endptr. If no conversion is performed, zero is returned and the value of \a nptr is stored in the location referenced by \a endptr. If the correct value would cause overflow, plus or minus \c INFINITY is returned (according to the sign of the value), and \c ERANGE is stored in \c errno. If the correct value would cause underflow, zero is returned and \c ERANGE is stored in \c errno. */ #define STRTOF #include "stdio_private.h" #include "conv_flt.c" #ifdef WIDE_CHARS #define strtof wcstof #endif float strtof(const CHAR *nptr, CHAR **endptr) { int len = 0; float flt; UCHAR ret; while (ISSPACE(nptr[len])) len++; ret = conv_flt(nptr, &len, INT_MAX, &flt, 0); if (!ret) { flt = 0.0f; len = 0; } if (endptr) *endptr = (CHAR *)nptr + len; return flt; } picolibc-1.8.11/libc/stdio/strtof_l.c000066400000000000000000000035451513574234600174420ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #ifdef WIDE_CHARS #include #define strtof_l wcstof_l #define strtof wcstof #define char wchar_t #endif float strtof_l(const char * __restrict s00, char ** __restrict se, locale_t loc) { (void)loc; return strtof(s00, se); } picolibc-1.8.11/libc/stdio/strtoi.h000066400000000000000000000121101513574234600171230ustar00rootroot00000000000000/* Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2008 Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #include #ifdef WIDE_CHARS #include #include #define strtoi_char wchar_t #if __SIZEOF_WCHAR_T__ == 2 #define strtoi_uchar uint16_t #elif __SIZEOF_WCHAR_T__ == 4 #define strtoi_uchar uint32_t #endif #define strtoi_uint strtoi_uchar #define strtoi_isspace(c) iswspace(c) #else #define strtoi_char char #define strtoi_uint unsigned int #define strtoi_uchar unsigned char #define strtoi_isspace(c) isspace(c) #endif #ifndef strtoi_signed #define strtoi_utype strtoi_type #endif #if __HAVE_BUILTIN_MUL_OVERFLOW && __HAVE_BUILTIN_ADD_OVERFLOW && !defined(strtoi_signed) #define USE_OVERFLOW #endif strtoi_type strtoi(const strtoi_char * __restrict nptr, strtoi_char ** __restrict endptr, int ibase) { unsigned int base = ibase; /* Check for invalid base value */ if (base > 36 || base == 1) { errno = EINVAL; if (endptr) *endptr = (strtoi_char *)nptr; return 0; } #define FLAG_NEG 0x1 /* Negative. Must be 1 for ucutoff below */ #define FLAG_OFLOW 0x2 /* Value overflow */ const strtoi_uchar *s = (const strtoi_uchar *)nptr; strtoi_utype val = 0; unsigned char flags = 0; strtoi_uint i; /* Skip leading spaces */ do { i = *s++; } while (strtoi_isspace(i)); /* Parse a leading sign */ switch (i) { case '-': flags = FLAG_NEG; __fallthrough; case '+': i = *s++; } /* Leading '0' digit -- check for base indication */ if (i == '0') { if (TOLOWER(*s) == 'x' && ((base | 16) == 16)) { base = 16; /* Parsed the '0' */ nptr = (const strtoi_char *)s; i = s[1]; s += 2; } else if (base == 0) { base = 8; } } else if (base == 0) { base = 10; } #ifndef USE_OVERFLOW /* Compute values used to detect overflow. */ #ifdef strtoi_signed /* works because strtoi_min = (strtoi_type) ((strtoi_utype) strtoi_max + 1) */ strtoi_utype ucutoff = (strtoi_utype)strtoi_max + flags; strtoi_utype cutoff = ucutoff / base; unsigned int cutlim = ucutoff % base; #else strtoi_type cutoff = strtoi_max / base; unsigned int cutlim = strtoi_max % base; #endif #endif for (;;) { i = digit_to_val(i); /* detect invalid char */ if (i >= base) break; /* Add the new digit, checking for overflow */ #ifdef USE_OVERFLOW /* * This isn't used for signed values as it's tricky and * generates larger code. Yes, it avoids doing the divmod * above, but we'll assume an app doing math with signed * values will probably end up doing a divide somewhere */ if (__builtin_mul_overflow(val, (strtoi_type)base, &val) || __builtin_add_overflow(val, (strtoi_type)i, &val)) { flags |= FLAG_OFLOW; } #else if (val > cutoff || (val == cutoff && i > cutlim)) flags |= FLAG_OFLOW; else val = val * (strtoi_utype)base + (strtoi_utype)i; #endif /* Parsed another digit */ nptr = (const strtoi_char *)s; i = *s++; } /* Mark the end of the parsed region */ if (endptr != NULL) *endptr = (strtoi_char *)nptr; if (flags & FLAG_NEG) val = -val; if (flags & FLAG_OFLOW) { #ifdef strtoi_signed val = ucutoff; #else val = strtoi_max; #endif errno = ERANGE; } return (strtoi_type)val; } picolibc-1.8.11/libc/stdio/strtoimax.c000066400000000000000000000034701513574234600176350ustar00rootroot00000000000000/* Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2008 Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define strtoi_type intmax_t #define strtoi_utype uintmax_t #define strtoi_max INTMAX_MAX #define strtoi_min INTMAX_MIN #define strtoi_signed #ifdef WIDE_CHARS #define strtoi wcstoimax #else #define strtoi strtoimax #endif #include "strtoi.h" picolibc-1.8.11/libc/stdio/strtoimax_l.c000066400000000000000000000036411513574234600201500ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #include #ifdef WIDE_CHARS #include #define strtoimax_l wcstoimax_l #define strtoimax wcstoimax #define char wchar_t #endif intmax_t strtoimax_l(const char * __restrict s, char ** __restrict ptr, int base, locale_t loc) { (void)loc; return strtoimax(s, ptr, base); } picolibc-1.8.11/libc/stdio/strtol.c000066400000000000000000000034561513574234600171360ustar00rootroot00000000000000/* Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2008 Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define strtoi_type long #define strtoi_utype unsigned long #define strtoi_max LONG_MAX #define strtoi_min LONG_MIN #define strtoi_signed #ifdef WIDE_CHARS #define strtoi wcstol #else #define strtoi strtol #endif #include "strtoi.h" picolibc-1.8.11/libc/stdio/strtol_l.c000066400000000000000000000035621513574234600174470ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #ifdef WIDE_CHARS #include #define strtol_l wcstol_l #define strtol wcstol #define char wchar_t #endif long strtol_l(const char * __restrict s, char ** __restrict ptr, int base, locale_t loc) { (void)loc; return strtol(s, ptr, base); } picolibc-1.8.11/libc/stdio/strtold.c000066400000000000000000000066501513574234600173010ustar00rootroot00000000000000/* Copyright (c) 2002-2005 Michael Stumpf Copyright (c) 2006,2008 Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: strtod.c 2191 2010-11-05 13:45:57Z arcanum $ */ #define STRTOLD #include "stdio_private.h" #if defined(__HAVE_LONG_DOUBLE) && __SIZEOF_LONG_DOUBLE__ > __SIZEOF_DOUBLE__ /** The strtold() function converts the initial portion of the string pointed to by \a nptr to long double representation. The expected form of the string is an optional plus ( \c '+' ) or minus sign ( \c '-' ) followed by a sequence of digits optionally containing a decimal-point character, optionally followed by an exponent. An exponent consists of an \c 'E' or \c 'e', followed by an optional plus or minus sign, followed by a sequence of digits. Leading white-space characters in the string are skipped. The strtold() function returns the converted value, if any. If \a endptr is not \c NULL, a pointer to the character after the last character used in the conversion is stored in the location referenced by \a endptr. If no conversion is performed, zero is returned and the value of \a nptr is stored in the location referenced by \a endptr. If the correct value would cause overflow, plus or minus \c INFINITY is returned (according to the sign of the value), and \c ERANGE is stored in \c errno. If the correct value would cause underflow, zero is returned and \c ERANGE is stored in \c errno. */ #define STRTOLD #include "conv_flt.c" #ifdef WIDE_CHARS #define strtold wcstold #endif long double strtold(const CHAR *nptr, CHAR **endptr) { int len = 0; long double flt; UCHAR ret; while (ISSPACE(nptr[len])) len++; ret = conv_flt(nptr, &len, INT_MAX, &flt, FL_LONG); if (!ret) { flt = (long double)0.0; len = 0; } if (endptr) *endptr = (CHAR *)nptr + len; return flt; } #endif picolibc-1.8.11/libc/stdio/strtold_l.c000066400000000000000000000036651513574234600176170ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #if defined(__HAVE_LONG_DOUBLE) && !defined(_LDBL_EQ_DBL) #ifdef WIDE_CHARS #include #define strtold_l wcstold_l #define strtold wcstold #define char wchar_t #endif long double strtold_l(const char * __restrict s00, char ** __restrict se, locale_t loc) { (void)loc; return strtold(s00, se); } #endif picolibc-1.8.11/libc/stdio/strtoll.c000066400000000000000000000034741513574234600173120ustar00rootroot00000000000000/* Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2008 Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define strtoi_type long long #define strtoi_utype unsigned long long #define strtoi_max LLONG_MAX #define strtoi_min LLONG_MIN #define strtoi_signed #ifdef WIDE_CHARS #define strtoi wcstoll #else #define strtoi strtoll #endif #include "strtoi.h" picolibc-1.8.11/libc/stdio/strtoll_l.c000066400000000000000000000035761513574234600176300ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #ifdef WIDE_CHARS #include #define strtoll_l wcstoll_l #define strtoll wcstoll #define char wchar_t #endif long long strtoll_l(const char * __restrict s, char ** __restrict ptr, int base, locale_t loc) { (void)loc; return strtoll(s, ptr, base); } picolibc-1.8.11/libc/stdio/strtoul.c000066400000000000000000000033661513574234600173230ustar00rootroot00000000000000/* Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2008 Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define strtoi_type unsigned long #define strtoi_max ULONG_MAX #undef strtoi_signed #ifdef WIDE_CHARS #define strtoi wcstoul #else #define strtoi strtoul #endif #include "strtoi.h" picolibc-1.8.11/libc/stdio/strtoul_l.c000066400000000000000000000036021513574234600176270ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #ifdef WIDE_CHARS #include #define strtoul_l wcstoul_l #define strtoul wcstoul #define char wchar_t #endif unsigned long strtoul_l(const char * __restrict s, char ** __restrict ptr, int base, locale_t loc) { (void)loc; return strtoul(s, ptr, base); } picolibc-1.8.11/libc/stdio/strtoull.c000066400000000000000000000033761513574234600175000ustar00rootroot00000000000000/* Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2008 Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define strtoi_type unsigned long long #define strtoi_max ULLONG_MAX #undef strtoi_signed #ifdef WIDE_CHARS #define strtoi wcstoull #else #define strtoi strtoull #endif #include "strtoi.h" picolibc-1.8.11/libc/stdio/strtoull_l.c000066400000000000000000000036161513574234600200100ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #ifdef WIDE_CHARS #include #define strtoull_l wcstoull_l #define strtoull wcstoull #define char wchar_t #endif unsigned long long strtoull_l(const char * __restrict s, char ** __restrict ptr, int base, locale_t loc) { (void)loc; return strtoull(s, ptr, base); } picolibc-1.8.11/libc/stdio/strtoumax.c000066400000000000000000000033701513574234600176500ustar00rootroot00000000000000/* Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2008 Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define strtoi_type uintmax_t #define strtoi_max UINTMAX_MAX #undef strtoi_signed #ifdef WIDE_CHARS #define strtoi wcstoumax #else #define strtoi strtoumax #endif #include "strtoi.h" picolibc-1.8.11/libc/stdio/strtoumax_l.c000066400000000000000000000036421513574234600201650ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #include #ifdef WIDE_CHARS #include #define strtoumax_l wcstoumax_l #define strtoumax wcstoumax #define char wchar_t #endif uintmax_t strtoumax_l(const char * __restrict s, char ** __restrict ptr, int base, locale_t loc) { (void)loc; return strtoumax(s, ptr, base); } picolibc-1.8.11/libc/stdio/swprintf.c000066400000000000000000000037621513574234600174630ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2023 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int swprintf(wchar_t *s, size_t n, const wchar_t *fmt, ...) { va_list ap; int i; struct __file_str f = FDEV_SETUP_STRING_WRITE((char *)s, (char *)FDEV_STRING_WRITE_END(s, n)); f.file.flags |= __SWIDE; va_start(ap, fmt); i = vfwprintf(&f.file, fmt, ap); va_end(ap); if (n) memset(f.pos, 0, sizeof(wchar_t)); return i; } picolibc-1.8.11/libc/stdio/swprintfd.c000066400000000000000000000031511513574234600176170ustar00rootroot00000000000000/* Copyright © 2025 Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define vfwfprintf __d_vfwprintf #define swprintf __d_swprintf #include "swprintf.c" picolibc-1.8.11/libc/stdio/swscanf.c000066400000000000000000000034511513574234600172460ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int swscanf(const wchar_t *s, const wchar_t *fmt, ...) { va_list ap; int i; struct __file_str f = FDEV_SETUP_WSTRING_READ(s); va_start(ap, fmt); i = vfwscanf(&f.file, fmt, ap); va_end(ap); return i; } picolibc-1.8.11/libc/stdio/tmpfile.c000066400000000000000000000036711513574234600172460ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" FILE * tmpfile(void) { char tmpnam[L_tmpnam]; int fd; FILE *f; strcpy(tmpnam, "TXXXXXX"); fd = mkstemp(tmpnam); if (fd < 0) return NULL; /* Assume POSIX semantics for unlinking in-use files */ unlink(tmpnam); f = fdopen(fd, "w+"); if (f == NULL) close(fd); return f; } picolibc-1.8.11/libc/stdio/tmpnam.c000066400000000000000000000037741513574234600171060ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2022 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #ifdef __GNUCLIKE_PRAGMA_DIAGNOSTIC #pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wunknown-warning-option" #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif /* No requirement for re-entrancy for this variable */ static char _tmpnam[L_tmpnam]; char * tmpnam(char *s) { if (!s) s = _tmpnam; strcpy(s, "TXXXXXX"); return mktemp(s); } picolibc-1.8.11/libc/stdio/ultoa_invert.c000066400000000000000000000104321513574234600203120ustar00rootroot00000000000000/* Copyright © 2017 Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if !IO_VARIANT_IS_FLOAT(PRINTF_VARIANT) && defined(__IO_SMALL_ULTOA) /* * Enable fancy divmod for targets where we don't expect either * hardware division support or that software will commonly be using * the soft division code. That means platforms where 'long' is not at * least 64-bits get the fancy code for 64-bit values and platforms * where 'int' is not at least 32-bits also get the fancy code for * 32-bit values */ #if SIZEOF_ULTOA > __SIZEOF_LONG__ #define FANCY_DIVMOD static inline ultoa_unsigned_t udivmod10(ultoa_unsigned_t n, char *rp) { ultoa_unsigned_t q; char r; /* Compute n * 0x1999999999999999 / (2^64) ≃ n / 10 */ /* q = n * 0xc >> 4 */ q = (n >> 1) + (n >> 2); /* q = q * 0x11 >> 4 = (n * 0xc >> 4) * 0x11 >> 4 ≂ n * 0xcc >> 8 */ q = q + (q >> 4); /* q = q * 0x101 >> 8 = ((n * 0xc >> 4) * 0x11 >> 4) * 0x101 >> 8 ≂ (n * 0xcc >> 8) * 0x101 >> 8 ≂ n * 0xcccc >> 16 */ q = q + (q >> 8); /* q = q * 0x10001 >> 16 = (((n * 0xc >> 4) * 0x11 >> 4) * 0x101 >> 8) * 0x10001 >> 16 ≂ (n * 0xcccc >> 16) * 0x10001 >> 16 ≂ n * 0xcccccccc >> 32 */ q = q + (q >> 16); #if SIZEOF_ULTOA > 4 /* q = q * 0x100000001 >> 32 = ((((n * 0xc >> 4) * 0x11 >> 4) * 0x101 >> 8) * 0x10001 >> 16) * 0x100000001 >> 32 ≂ (n * 0xcccccccc >> 32) * 0x100000001 >> 32 ≂ n * cccccccccccccccc >> 64 */ q = q + (q >> 32); #endif /* q = q >> 3 = (((((n * 0xc >> 4) * 0x11 >> 4) * 0x101 >> 8) * 0x10001 >> 16) * 0x100000001 >> 32) >> 3 ≂ (n * cccccccccccccccc >> 64) >> 3 ≂ n * 0x1999999999999999 >> 64 */ q = q >> 3; /* r = n - q * 10 */ r = (char)(n - (((q << 2) + q) << 1)); /* * Because of the approximations above, q will * be +0/-1 of the real result. Check and adjust */ if (r > 9) { q++; r -= 10; } *rp = r; return q; } static inline ultoa_unsigned_t udivmod(ultoa_unsigned_t val, int base, char *dig) { switch (base) { #ifdef __IO_PERCENT_B case 2: *dig = val & 1; return val >> 1; #endif case 8: *dig = val & 7; return val >> 3; case 16: *dig = val & 15; return val >> 4; } return udivmod10(val, dig); } #endif #endif static __noinline char * __ultoa_invert(ultoa_unsigned_t val, char *str, int base) { char hex = ('a' - '0' - 10 + 16) - base; base &= 31; do { char v; #ifdef FANCY_DIVMOD val = udivmod(val, base, &v); #else v = val % base; val /= base; #endif if (v > 9) v += hex; v += '0'; *str++ = v; } while (val); return str; } picolibc-1.8.11/libc/stdio/ungetc.c000066400000000000000000000042271513574234600170710ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: ungetc.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int ungetc(int c, FILE *stream) { __flockfile(stream); /* * Streams that are not readable, or streams that already had * had an ungetc() before will cause an error. * * ungetc(EOF, ...) causes an error per definitionem. */ if ((stream->flags & __SRD) == 0 || c == EOF) __funlock_return(stream, EOF); if (!__atomic_compare_exchange_ungetc(&stream->unget, 0, (__ungetc_t)(unsigned char)c + 1)) __funlock_return(stream, EOF); stream->flags &= ~__SEOF; __funlock_return(stream, (unsigned char)c); } picolibc-1.8.11/libc/stdio/ungetwc.c000066400000000000000000000041121513574234600172510ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" wint_t ungetwc(wint_t c, FILE *stream) { __flockfile(stream); /* * Streams that are not readable, or streams that already had * had an ungetc() before will cause an error. * * ungetwc(WEOF, ...) causes an error per definition. */ if ((stream->flags & __SRD) == 0 || c == WEOF) __funlock_return(stream, WEOF); if (!__atomic_compare_exchange_ungetc(&stream->unget, 0, (__ungetc_t)c + 1)) __funlock_return(stream, WEOF); stream->flags &= ~__SEOF; __funlock_return(stream, c); } picolibc-1.8.11/libc/stdio/vasnprintf.c000066400000000000000000000045301513574234600177730ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" char * __disable_sanitizer vasnprintf(char *str, size_t *lenp, const char *fmt, va_list ap) { struct __file_str f = FDEV_SETUP_STRING_ALLOC_BUF(str, *lenp); int i; i = vfprintf(&f.file, fmt, ap); /* * Use fputc to append a NULL to handle * buffer overflow cases */ if (i >= 0) { if (fputc('\0', &f.file) < 0) i = EOF; } char *ret = POINTER_MINUS(f.end, f.size); if (i >= 0) { *lenp = (size_t)i; /* Try to shrink the buffer */ if (f.alloc) { char *s = realloc(ret, i + 1); if (s) ret = s; } } else { if (f.alloc) free(ret); ret = NULL; } return ret; } picolibc-1.8.11/libc/stdio/vasprintf.c000066400000000000000000000040721513574234600176160ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2020 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int __disable_sanitizer vasprintf(char **strp, const char *fmt, va_list ap) { struct __file_str f = FDEV_SETUP_STRING_ALLOC(); int i; i = vfprintf(&f.file, fmt, ap); char *buf = POINTER_MINUS(f.end, f.size); if (i >= 0) { char *s = realloc(buf, i + 1); if (s) { s[i] = 0; *strp = s; } else { i = EOF; } } if (i < 0) free(buf); return i; } picolibc-1.8.11/libc/stdio/vdprintf.c000066400000000000000000000040311513574234600174310ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" #define DPRINT_BUFSIZ 32 int vdprintf(int fd, const char *fmt, va_list ap) { char buf[DPRINT_BUFSIZ]; struct __file_bufio bf = FDEV_SETUP_BUFIO(fd, buf, sizeof(buf), NULL, write, NULL, NULL, __SWR, 0); int printf_ret = vfprintf(&bf.xfile.cfile.file, fmt, ap); int flush_ret = __bufio_flush(&bf.xfile.cfile.file); if (flush_ret != 0) return flush_ret; return printf_ret; } picolibc-1.8.11/libc/stdio/vffprintf.c000066400000000000000000000031661513574234600176110ustar00rootroot00000000000000/* Copyright © 2018 Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define PRINTF_VARIANT __IO_VARIANT_FLOAT #define PRINTF_NAME __f_vfprintf #include "vfprintf.c" picolibc-1.8.11/libc/stdio/vffscanf.c000066400000000000000000000031621513574234600173750ustar00rootroot00000000000000/* Copyright © 2018 Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define SCANF_VARIANT __IO_VARIANT_FLOAT #define SCANF_NAME __f_vfscanf #include "vfscanf.c" picolibc-1.8.11/libc/stdio/vfiprintf.c000066400000000000000000000031701513574234600176070ustar00rootroot00000000000000/* Copyright © 2018 Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define PRINTF_VARIANT __IO_VARIANT_INTEGER #define PRINTF_NAME __i_vfprintf #include "vfprintf.c" picolibc-1.8.11/libc/stdio/vfiscanf.c000066400000000000000000000031641513574234600174020ustar00rootroot00000000000000/* Copyright © 2018 Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define SCANF_VARIANT __IO_VARIANT_INTEGER #define SCANF_NAME __i_vfscanf #include "vfscanf.c" picolibc-1.8.11/libc/stdio/vflprintf.c000066400000000000000000000031661513574234600176170ustar00rootroot00000000000000/* Copyright © 2018 Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define PRINTF_VARIANT __IO_VARIANT_LLONG #define PRINTF_NAME __l_vfprintf #include "vfprintf.c" picolibc-1.8.11/libc/stdio/vflscanf.c000066400000000000000000000031621513574234600174030ustar00rootroot00000000000000/* Copyright © 2018 Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define SCANF_VARIANT __IO_VARIANT_LLONG #define SCANF_NAME __l_vfscanf #include "vfscanf.c" picolibc-1.8.11/libc/stdio/vfmprintf.c000066400000000000000000000031701513574234600176130ustar00rootroot00000000000000/* Copyright © 2018 Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define PRINTF_VARIANT __IO_VARIANT_MINIMAL #define PRINTF_NAME __m_vfprintf #include "vfprintf.c" picolibc-1.8.11/libc/stdio/vfmscanf.c000066400000000000000000000031641513574234600174060ustar00rootroot00000000000000/* Copyright © 2018 Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define SCANF_VARIANT __IO_VARIANT_MINIMAL #define SCANF_NAME __m_vfscanf #include "vfscanf.c" picolibc-1.8.11/libc/stdio/vfprintf.c000066400000000000000000000553541513574234600174510ustar00rootroot00000000000000/* Copyright (c) 2002, Alexander Popov (sasho@vip.bg) Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2005, Helmut Wallner Copyright (c) 2007, Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* From: Id: printf_p_new.c,v 1.1.1.9 2002/10/15 20:10:28 joerg_wunsch Exp */ /* $Id: vfprintf.c 2191 2010-11-05 13:45:57Z arcanum $ */ #ifndef PRINTF_NAME #define PRINTF_VARIANT __IO_VARIANT_DOUBLE #define PRINTF_NAME __d_vfprintf #endif #include "stdio_private.h" #include "../../libm/common/math_config.h" #include "../stdlib/local.h" /* * This file can be compiled into more than one flavour by setting * PRINTF_VARIANT to: * * __IO_VARIANT_MINIMAL: limited integer-only support with option for long long * * __IO_VARIANT_INTEGER: integer support except for long long with * options for positional params * * __IO_VARIANT_LLONG: full integer support including long long with * options for positional params * * __IO_VARIANT_FLOAT: full integer support along with float, but not double * * __IO_VARIANT_DOUBLE: full support */ #if __IO_DEFAULT != PRINTF_VARIANT || defined(WIDE_CHARS) #define vfprintf PRINTF_NAME #endif #ifdef WIDE_CHARS #define CHAR wchar_t #if __SIZEOF_WCHAR_T__ == 2 #define UCHAR uint16_t #elif __SIZEOF_WCHAR_T__ == 4 #define UCHAR uint32_t #endif #else #define CHAR char #define UCHAR unsigned char #endif /* * Compute which features are required. This should match the _HAS * values computed in stdio.h */ #if PRINTF_VARIANT == __IO_VARIANT_MINIMAL #define _NEED_IO_SHRINK #if defined(__IO_MINIMAL_LONG_LONG) && __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__ #define _NEED_IO_LONG_LONG #endif #ifdef __IO_C99_FORMATS #define _NEED_IO_C99_FORMATS #endif #elif PRINTF_VARIANT == __IO_VARIANT_INTEGER #if defined(__IO_LONG_LONG) && __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__ #define _NEED_IO_LONG_LONG #endif #ifdef __IO_POS_ARGS #define _NEED_IO_POS_ARGS #endif #ifdef __IO_C99_FORMATS #define _NEED_IO_C99_FORMATS #endif #ifdef __IO_PERCENT_B #define _NEED_IO_PERCENT_B #endif #elif PRINTF_VARIANT == __IO_VARIANT_LLONG #if __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__ #define _NEED_IO_LONG_LONG #endif #ifdef __IO_POS_ARGS #define _NEED_IO_POS_ARGS #endif #ifdef __IO_C99_FORMATS #define _NEED_IO_C99_FORMATS #endif #ifdef __IO_PERCENT_B #define _NEED_IO_PERCENT_B #endif #elif PRINTF_VARIANT == __IO_VARIANT_FLOAT #if __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__ #define _NEED_IO_LONG_LONG #endif #define _NEED_IO_POS_ARGS #define _NEED_IO_C99_FORMATS #ifdef __IO_PERCENT_B #define _NEED_IO_PERCENT_B #endif #define _NEED_IO_FLOAT #elif PRINTF_VARIANT == __IO_VARIANT_DOUBLE #if __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__ #define _NEED_IO_LONG_LONG #endif #if defined(_HAS_IO_WCHAR) || defined(WIDE_CHARS) #define _NEED_IO_WCHAR #endif #define _NEED_IO_POS_ARGS #define _NEED_IO_C99_FORMATS #ifdef __IO_PERCENT_B #define _NEED_IO_PERCENT_B #endif #define _NEED_IO_DOUBLE #if defined(__IO_LONG_DOUBLE) && __SIZEOF_LONG_DOUBLE__ > __SIZEOF_DOUBLE__ #define _NEED_IO_LONG_DOUBLE #endif #else #error invalid PRINTF_VARIANT #endif /* Figure out which multi-byte char support we need */ #if defined(_NEED_IO_WCHAR) && defined(__MB_CAPABLE) #ifdef WIDE_CHARS /* need to convert multi-byte chars to wide chars */ #define _NEED_IO_MBTOWIDE #else #define _NEED_IO_WIDETOMB #endif #endif #if IO_VARIANT_IS_FLOAT(PRINTF_VARIANT) #include "dtoa.h" #endif #if defined(_NEED_IO_FLOAT_LONG_DOUBLE) && __SIZEOF_LONG_DOUBLE__ > __SIZEOF_DOUBLE__ #define SKIP_FLOAT_ARG(flags, ap) \ do { \ if ((flags & (FL_LONG | FL_REPD_TYPE)) == (FL_LONG | FL_REPD_TYPE)) \ (void)va_arg(ap, long double); \ else \ (void)va_arg(ap, double); \ } while (0) #define FLOAT double #elif defined(_NEED_IO_FLOAT) #define SKIP_FLOAT_ARG(flags, ap) (void)va_arg(ap, uint32_t) #define FLOAT_UINT uint32_t #else #define SKIP_FLOAT_ARG(flags, ap) (void)va_arg(ap, double) #if __SIZEOF_DOUBLE__ == 8 #define FLOAT_UINT uint64_t #elif __SIZEOF_DOUBLE__ == 4 #define FLOAT_UINT uint32_t #endif #endif #ifdef _NEED_IO_LONG_LONG typedef unsigned long long ultoa_unsigned_t; typedef long long ultoa_signed_t; #define SIZEOF_ULTOA __SIZEOF_LONG_LONG__ #define arg_to_t(ap, flags, _s_, _result_) \ if ((flags) & FL_LONG) { \ if ((flags) & FL_REPD_TYPE) \ (_result_) = va_arg(ap, _s_ long long); \ else \ (_result_) = va_arg(ap, _s_ long); \ } else { \ (_result_) = va_arg(ap, _s_ int); \ if ((flags) & FL_SHORT) { \ if ((flags) & FL_REPD_TYPE) \ (_result_) = (_s_ char)(_result_); \ else \ (_result_) = (_s_ short)(_result_); \ } \ } #else typedef unsigned long ultoa_unsigned_t; typedef long ultoa_signed_t; #define SIZEOF_ULTOA __SIZEOF_LONG__ #define arg_to_t(ap, flags, _s_, _result_) \ if ((flags) & FL_LONG) { \ if ((flags) & FL_REPD_TYPE) \ (_result_) = (_s_ long)va_arg(ap, _s_ long long); \ else \ (_result_) = va_arg(ap, _s_ long); \ } else { \ (_result_) = va_arg(ap, _s_ int); \ if ((flags) & FL_SHORT) { \ if ((flags) & FL_REPD_TYPE) \ (_result_) = (_s_ char)(_result_); \ else \ (_result_) = (_s_ short)(_result_); \ } \ } #endif #if SIZEOF_ULTOA <= 4 #ifdef _NEED_IO_PERCENT_B #define PRINTF_BUF_SIZE 32 #else #define PRINTF_BUF_SIZE 11 #endif #else #ifdef _NEED_IO_PERCENT_B #define PRINTF_BUF_SIZE 64 #else #define PRINTF_BUF_SIZE 22 #endif #endif // At the call site the address of the result_var is taken (e.g. "&ap") // That way, it's clear that these macros *will* modify that variable #define arg_to_unsigned(ap, flags, result_var) arg_to_t(ap, flags, unsigned, result_var) #define arg_to_signed(ap, flags, result_var) arg_to_t(ap, flags, signed, result_var) #include "ultoa_invert.c" /* Order is relevant here and matches order in format string */ #ifdef _NEED_IO_SHRINK #define FL_ZFILL 0x0000 #define FL_PLUS 0x0000 #define FL_SPACE 0x0000 #define FL_LPAD 0x0000 #else #define FL_ZFILL 0x0001 #define FL_PLUS 0x0002 #define FL_SPACE 0x0004 #define FL_LPAD 0x0008 #endif /* else _NEED_IO_SHRINK */ #define FL_ALT 0x0010 #define FL_WIDTH 0x0020 #define FL_PREC 0x0040 #define FL_LONG 0x0080 #define FL_SHORT 0x0100 #define FL_REPD_TYPE 0x0200 #define FL_NEGATIVE 0x0400 #ifdef _NEED_IO_C99_FORMATS #define FL_FLTHEX 0x0800 #endif #define FL_FLTEXP 0x1000 #define FL_FLTFIX 0x2000 #ifdef _NEED_IO_C99_FORMATS #define CHECK_INT_SIZE(c, flags, letter, type) \ if (c == letter) { \ if (sizeof(type) == sizeof(int)) \ ; \ else if (sizeof(type) == sizeof(long)) \ flags |= FL_LONG; \ else if (sizeof(type) == sizeof(long long)) \ flags |= FL_LONG | FL_REPD_TYPE; \ else if (sizeof(type) == sizeof(short)) \ flags |= FL_SHORT; \ continue; \ } #define CHECK_C99_INT_SIZES(c, flags) \ CHECK_INT_SIZE(c, flags, 'j', intmax_t); \ CHECK_INT_SIZE(c, flags, 'z', size_t); \ CHECK_INT_SIZE(c, flags, 't', ptrdiff_t); #else #define CHECK_C99_INT_SIZES(c, flags) #endif #define CHECK_INT_SIZES(c, flags) \ { \ if (c == 'l') { \ if (flags & FL_LONG) \ flags |= FL_REPD_TYPE; \ flags |= FL_LONG; \ continue; \ } \ \ if (c == 'h') { \ if (flags & FL_SHORT) \ flags |= FL_REPD_TYPE; \ flags |= FL_SHORT; \ continue; \ } \ \ /* alias for 'll' */ \ if (c == 'L') { \ flags |= FL_REPD_TYPE; \ flags |= FL_LONG; \ continue; \ } \ CHECK_C99_INT_SIZES(c, flags); \ } #ifdef _NEED_IO_POS_ARGS typedef struct { va_list ap; } my_va_list; /* * Repeatedly scan the format string finding argument position values * and types to slowly walk the argument vector until it points at the * target_argno so that the outer printf code can then extract it. */ static void skip_to_arg(const CHAR *fmt_orig, my_va_list *ap, int target_argno) { unsigned c; /* holds a char from the format string */ uint16_t flags; int current_argno = 1; int argno; int width; const CHAR *fmt = fmt_orig; while (current_argno < target_argno) { for (;;) { c = *fmt++; if (!c) return; if (c == '%') { c = *fmt++; if (c != '%') break; } } flags = 0; width = 0; argno = 0; /* * Scan the format string until we hit current_argno. This can * either be a value, width or precision field. */ do { if (flags < FL_WIDTH) { switch (c) { case '0': continue; case '+': case ' ': continue; case '-': continue; case '#': continue; case '\'': continue; } } if (flags < FL_LONG) { if (c >= '0' && c <= '9') { c -= '0'; width = 10 * width + c; flags |= FL_WIDTH; continue; } if (c == '$') { /* * If we've already seen the value position, any * other positions will be either width or * precisions. We can handle those in the same * fashion as they're both 'int' type */ if (argno) { if (width == current_argno) { c = 'c'; argno = width; break; } } else argno = width; width = 0; continue; } if (c == '*') { width = 0; continue; } if (c == '.') { width = 0; continue; } } CHECK_INT_SIZES(c, flags); break; } while ((c = *fmt++) != 0); if (argno == 0) break; if (argno == current_argno) { if ((TOLOWER(c) >= 'e' && TOLOWER(c) <= 'g') #ifdef _NEED_IO_C99_FORMATS || TOLOWER(c) == 'a' #endif ) { SKIP_FLOAT_ARG(flags, ap->ap); } else if (c == 'c') { (void)va_arg(ap->ap, int); } else if (c == 's') { (void)va_arg(ap->ap, char *); } else if (c == 'd' || c == 'i') { ultoa_signed_t x_s; arg_to_signed(ap->ap, flags, x_s); } else { ultoa_unsigned_t x; arg_to_unsigned(ap->ap, flags, x); } ++current_argno; fmt = fmt_orig; } } } #endif #ifdef _NEED_IO_WIDETOMB /* * Compute the number of bytes to encode a wide string * in the current locale */ static size_t _mbslen(const wchar_t *s, size_t maxlen) { mbstate_t ps = { 0 }; wchar_t c; char tmp[MB_LEN_MAX]; size_t len = 0; while (len < maxlen && (c = *s++) != L'\0') { int clen; clen = __WCTOMB(tmp, c, &ps); if (clen == -1) return (size_t)clen; len += clen; } return len; } #endif #ifdef _NEED_IO_MBTOWIDE /* * Compute the number of wide chars to encode a multi-byte string * in the current locale */ static size_t _wcslen(const char *s, size_t maxlen) { mbstate_t ps = { 0 }; wchar_t c; size_t len = 0; while (len < maxlen && *s != '\0') { size_t clen = mbrtowc(&c, s, MB_LEN_MAX, &ps); if (c == L'\0') break; if (clen == (size_t)-1) return clen; s += clen; len++; } return len; } #endif #ifdef VFPRINTF_S int vfprintf_s(FILE * __restrict stream, const char * __restrict fmt, va_list ap_orig) #else int vfprintf(FILE *stream, const CHAR *fmt, va_list ap_orig) #endif { unsigned c; /* holds a char from the format string */ uint16_t flags; #ifdef _NEED_IO_POS_ARGS int argno; my_va_list my_ap; const CHAR *fmt_orig = fmt; #define ap my_ap.ap #else #define ap ap_orig #endif union { char buf[PRINTF_BUF_SIZE]; /* size for -1 in smallest base, without '\0' */ #ifdef _NEED_IO_WCHAR wchar_t wbuf[PRINTF_BUF_SIZE / 2]; /* for wide char output */ #endif #ifdef _NEED_IO_WIDETOMB char mb[MB_LEN_MAX]; #endif #if IO_VARIANT_IS_FLOAT(PRINTF_VARIANT) struct dtoa dtoa; #endif } u; const char *pnt; #ifndef _NEED_IO_SHRINK size_t size; #endif int stream_len = 0; #ifdef VFPRINTF_S const char *msg; if (stream == NULL) { msg = "output stream is null"; goto handle_error; } else if (fmt == NULL) { msg = "null format string"; goto handle_error; } #endif #ifndef my_putc #ifdef WIDE_CHARS #define my_putc(c, stream) \ do { \ ++stream_len; \ if (putwc(c, stream) == WEOF) \ goto fail; \ } while (0) #else int (*put)(char, FILE *) = stream->put; #define my_putc(c, stream) \ do { \ ++stream_len; \ if (put(c, stream) < 0) \ goto fail; \ } while (0) #endif #endif __flockfile(stream); if ((stream->flags & __SWR) == 0) __funlock_return(stream, EOF); #ifdef _NEED_IO_POS_ARGS va_copy(ap, ap_orig); #endif for (;;) { for (;;) { c = *fmt++; if (!c) goto ret; if (c == '%') { c = *fmt++; if (c != '%') break; } my_putc(c, stream); } flags = 0; #ifndef _NEED_IO_SHRINK int width = 0; int prec = 0; #endif #ifdef _NEED_IO_POS_ARGS argno = 0; #endif do { if (flags < FL_WIDTH) { switch (c) { case '0': flags |= FL_ZFILL; continue; case '+': flags |= FL_PLUS; __fallthrough; case ' ': flags |= FL_SPACE; continue; case '-': flags |= FL_LPAD; continue; case '#': flags |= FL_ALT; continue; case '\'': /* * C/POSIX locale has an empty thousands_sep * value, so we can just ignore this character */ continue; } } if (flags < FL_LONG) { if (c >= '0' && c <= '9') { #ifndef _NEED_IO_SHRINK c -= '0'; if (flags & FL_PREC) { prec = 10 * prec + c; } else { width = 10 * width + c; flags |= FL_WIDTH; } #endif continue; } if (c == '*') { #ifdef _NEED_IO_POS_ARGS /* * Positional args must be used together, so wait * for the value to appear before dealing with * width and precision fields */ if (argno) continue; #endif if (flags & FL_PREC) { #ifdef _NEED_IO_SHRINK (void)va_arg(ap, int); #else prec = va_arg(ap, int); #endif } else { #ifdef _NEED_IO_SHRINK (void)va_arg(ap, int); #else width = va_arg(ap, int); #endif flags |= FL_WIDTH; } continue; } if (c == '.') { if (flags & FL_PREC) goto ret; flags |= FL_PREC; continue; } #ifdef _NEED_IO_POS_ARGS /* Check for positional args */ if (c == '$') { /* Check if we've already got the arg position and * are adding width or precision fields */ if (argno) { va_end(ap); va_copy(ap, ap_orig); skip_to_arg(fmt_orig, &my_ap, (flags & FL_PREC) ? prec : width); if (flags & FL_PREC) prec = va_arg(ap, int); else width = va_arg(ap, int); } else { argno = width; flags = 0; width = 0; prec = 0; } continue; } #endif } CHECK_INT_SIZES(c, flags); break; } while ((c = *fmt++) != 0); #ifdef _NEED_IO_POS_ARGS /* Set arg pointers for positional args */ if (argno) { va_end(ap); va_copy(ap, ap_orig); skip_to_arg(fmt_orig, &my_ap, argno); } #endif #ifndef _NEED_IO_SHRINK /* This can happen only when prec is set via a '*' * specifier, in which case it works as if no precision * was specified. Set the precision to zero and clear the * flag. */ if (prec < 0) { prec = 0; flags &= ~FL_PREC; } /* Handle negative width when provided via a '*' */ if (width < 0) { width = -width; flags |= FL_LPAD; } #endif /* Only a format character is valid. */ #define TOCASE(c) ((c) - case_convert) #ifndef _NEED_IO_SHRINK if ((TOLOWER(c) >= 'e' && TOLOWER(c) <= 'g') #ifdef _NEED_IO_C99_FORMATS || TOLOWER(c) == 'a' #endif ) { #if IO_VARIANT_IS_FLOAT(PRINTF_VARIANT) #include "vfprintf_float.c" #else SKIP_FLOAT_ARG(flags, ap); pnt = "*float*"; size = sizeof("*float*") - 1; goto str_lpad; #endif } else #endif /* ifndef PRINT_SHRINK */ { int buf_len; #ifdef _NEED_IO_WCHAR wchar_t *wstr = NULL; #endif #ifdef _NEED_IO_WCHAR pnt = NULL; #endif if (c == 'c') { #include "vfprintf_char.c" } else if (c == 's') { #include "vfprintf_str.c" } #if defined(__IO_PERCENT_N) || defined(VFPRINTF_S) else if (c == 'n') { #include "vfprintf_n.c" } #endif else { #include "vfprintf_int.c" } } #ifndef _NEED_IO_SHRINK /* Tail is possible. */ while (width-- > 0) { my_putc(' ', stream); } #endif } /* for (;;) */ ret: #ifdef _NEED_IO_POS_ARGS va_end(ap); #endif __funlock_return(stream, stream_len); #undef my_putc #undef ap fail: stream->flags |= __SERR; stream_len = -1; goto ret; #ifdef VFPRINTF_S handle_error: if (__cur_handler != NULL) { __cur_handler(msg, NULL, -1); } if (stream) stream->flags |= __SERR; return -1; #endif } #if !defined(VFPRINTF_S) && !defined(WIDE_CHARS) #if PRINTF_VARIANT == __IO_DEFAULT #undef vfprintf #ifdef __strong_reference __strong_reference(vfprintf, PRINTF_NAME); #else int PRINTF_NAME(FILE *stream, const char *fmt, va_list ap) { return vfprintf(stream, fmt, ap); } #endif #endif #endif picolibc-1.8.11/libc/stdio/vfprintf_char.c000066400000000000000000000037511513574234600204400ustar00rootroot00000000000000/* Copyright (c) 2002, Alexander Popov (sasho@vip.bg) Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2005, Helmut Wallner Copyright (c) 2007, Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ { #ifdef _NEED_IO_SHRINK my_putc(va_arg(ap, int), stream); #else #ifdef _NEED_IO_WCHAR if (flags & FL_LONG) { u.wbuf[0] = va_arg(ap, wint_t); u.wbuf[1] = L'\0'; wstr = u.wbuf; goto wstr_lpad; } #endif u.buf[0] = va_arg(ap, int); pnt = u.buf; size = 1; goto str_lpad; #endif } picolibc-1.8.11/libc/stdio/vfprintf_float.c000066400000000000000000000271011513574234600206230ustar00rootroot00000000000000/* Copyright (c) 2002, Alexander Popov (sasho@vip.bg) Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2005, Helmut Wallner Copyright (c) 2007, Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ { uint8_t sign; /* sign character (or 0) */ uint8_t ndigs; /* number of digits to convert */ unsigned char case_convert; /* subtract to correct case */ int exp; /* exponent of most significant decimal digit */ int n; /* total width */ uint8_t ndigs_exp; /* number of digis in exponent */ /* deal with upper vs lower case */ case_convert = TOLOWER(c) - c; c = TOLOWER(c); #ifdef _NEED_IO_LONG_DOUBLE if ((flags & (FL_LONG | FL_REPD_TYPE)) == (FL_LONG | FL_REPD_TYPE)) { PRINTF_LONG_DOUBLE_TYPE fval; fval = PRINTF_LONG_DOUBLE_ARG(ap); ndigs = 0; #ifdef _NEED_IO_C99_FORMATS if (c == 'a') { c = 'p'; flags |= FL_FLTEXP | FL_FLTHEX; if (!(flags & FL_PREC)) prec = -1; prec = __lfloat_x_engine(fval, &u.dtoa, prec, case_convert); ndigs = prec + 1; exp = u.dtoa.exp; ndigs_exp = 1; } else #endif /* _NEED_IO_C99_FORMATS */ { int ndecimal = 0; /* digits after decimal (for 'f' format) */ bool fmode = false; if (!(flags & FL_PREC)) prec = 6; if (c == 'e') { ndigs = prec + 1; flags |= FL_FLTEXP; } else if (c == 'f') { ndigs = LONG_FLOAT_MAX_DIG; ndecimal = prec; flags |= FL_FLTFIX; fmode = true; } else { c += 'e' - 'g'; ndigs = prec; if (ndigs < 1) ndigs = 1; } if (ndigs > LONG_FLOAT_MAX_DIG) ndigs = LONG_FLOAT_MAX_DIG; ndigs = __lfloat_d_engine(fval, &u.dtoa, ndigs, fmode, ndecimal); exp = u.dtoa.exp; ndigs_exp = 2; } } else #endif { FLOAT_UINT fval; /* value to print */ fval = PRINTF_FLOAT_ARG(ap); ndigs = 0; #ifdef _NEED_IO_C99_FORMATS if (c == 'a') { c = 'p'; flags |= FL_FLTEXP | FL_FLTHEX; if (!(flags & FL_PREC)) prec = -1; ndigs = 1 + __float_x_engine(fval, &u.dtoa, prec, case_convert); if (prec <= ndigs) prec = ndigs - 1; exp = u.dtoa.exp; ndigs_exp = 1; } else #endif /* _NEED_IO_C99_FORMATS */ { int ndecimal = 0; /* digits after decimal (for 'f' format) */ bool fmode = false; if (!(flags & FL_PREC)) prec = 6; if (c == 'e') { ndigs = prec + 1; flags |= FL_FLTEXP; } else if (c == 'f') { ndigs = FLOAT_MAX_DIG; ndecimal = prec; flags |= FL_FLTFIX; fmode = true; } else { c += 'e' - 'g'; ndigs = prec; if (ndigs < 1) ndigs = 1; } if (ndigs > FLOAT_MAX_DIG) ndigs = FLOAT_MAX_DIG; ndigs = __float_d_engine(fval, &u.dtoa, ndigs, fmode, ndecimal); exp = u.dtoa.exp; ndigs_exp = 2; } } if (exp < -9 || 9 < exp) ndigs_exp = 2; if (exp < -99 || 99 < exp) ndigs_exp = 3; #ifdef _NEED_IO_FLOAT64 if (exp < -999 || 999 < exp) ndigs_exp = 4; #ifdef _NEED_IO_FLOAT_LARGE if (exp < -9999 || 9999 < exp) ndigs_exp = 5; #endif #endif sign = 0; if (u.dtoa.flags & DTOA_MINUS) sign = '-'; else if (flags & FL_PLUS) sign = '+'; else if (flags & FL_SPACE) sign = ' '; if (u.dtoa.flags & (DTOA_NAN | DTOA_INF)) { ndigs = sign ? 4 : 3; if (width > ndigs) { width -= ndigs; if (!(flags & FL_LPAD)) { do { my_putc(' ', stream); } while (--width); } } else { width = 0; } if (sign) my_putc(sign, stream); pnt = "inf"; if (u.dtoa.flags & DTOA_NAN) pnt = "nan"; while ((c = *pnt++)) my_putc(TOCASE(c), stream); } else { if (!(flags & (FL_FLTEXP | FL_FLTFIX))) { /* 'g(G)' format */ /* * On entry to this block, prec is * the number of digits to display. * * On exit, prec is the number of digits * to display after the decimal point */ /* Always show at least one digit */ if (prec == 0) prec = 1; /* * Remove trailing zeros. The ryu code can emit them * when rounding to fewer digits than required for * exact output, the imprecise code often emits them */ while (ndigs > 0 && u.dtoa.digits[ndigs - 1] == '0') ndigs--; /* Save requested precision */ int req_prec = prec; /* Limit output precision to ndigs unless '#' */ if (!(flags & FL_ALT)) prec = ndigs; /* * Figure out whether to use 'f' or 'e' format. The spec * says to use 'f' if the exponent is >= -4 and < requested * precision. */ if (-4 <= exp && exp < req_prec) { flags |= FL_FLTFIX; /* Compute how many digits to show after the decimal. * * If exp is negative, then we need to show that * many leading zeros plus the requested precision * * If exp is less than prec, then we need to show a * number of digits past the decimal point, * including (potentially) some trailing zeros * * (these two cases end up computing the same value, * and are both caught by the exp < prec test, * so they share the same branch of the 'if') * * If exp is at least 'prec', then we don't show * any digits past the decimal point. */ if (exp < prec) prec = prec - (exp + 1); else prec = 0; } else { /* Compute how many digits to show after the decimal */ prec = prec - 1; } } /* Conversion result length, width := free space length */ if (flags & FL_FLTFIX) n = (exp > 0 ? exp + 1 : 1); else { n = 3; /* 1e+ */ #ifdef _NEED_IO_C99_FORMATS if (flags & FL_FLTHEX) n += 2; /* or 0x1p+ */ #endif n += ndigs_exp; /* add exponent */ } if (sign) n += 1; if (prec) n += prec + 1; else if (flags & FL_ALT) n += 1; width = width > n ? width - n : 0; /* Output before first digit */ if (!(flags & (FL_LPAD | FL_ZFILL))) { while (width) { my_putc(' ', stream); width--; } } if (sign) my_putc(sign, stream); #ifdef _NEED_IO_C99_FORMATS if ((flags & FL_FLTHEX)) { my_putc('0', stream); my_putc(TOCASE('x'), stream); } #endif if (!(flags & FL_LPAD)) { while (width) { my_putc('0', stream); width--; } } if (flags & FL_FLTFIX) { /* 'f' format */ char out; /* At this point, we should have * * exp exponent of leftmost digit in u.dtoa.digits * ndigs number of buffer digits to print * prec number of digits after decimal * * In the loop, 'n' walks over the exponent value */ n = exp > 0 ? exp : 0; /* exponent of left digit */ do { /* Insert decimal point at correct place */ if (n == -1) my_putc('.', stream); /* Pull digits from buffer when in-range, * otherwise use 0 */ if (0 <= exp - n && exp - n < ndigs) out = u.dtoa.digits[exp - n]; else out = '0'; if (--n < -prec) { break; } my_putc(out, stream); } while (1); my_putc(out, stream); if ((flags & FL_ALT) && n == -1) my_putc('.', stream); } else { /* 'e(E)' format */ /* mantissa */ my_putc(u.dtoa.digits[0], stream); if (prec > 0) { my_putc('.', stream); int pos = 1; for (pos = 1; pos < 1 + prec; pos++) my_putc(pos < ndigs ? u.dtoa.digits[pos] : '0', stream); } else if (flags & FL_ALT) my_putc('.', stream); /* exponent */ my_putc(TOCASE(c), stream); sign = '+'; if (exp < 0) { exp = -exp; sign = '-'; } my_putc(sign, stream); #ifdef _NEED_IO_FLOAT_LARGE if (ndigs_exp > 4) { my_putc(exp / 10000 + '0', stream); exp %= 10000; } #endif #ifdef _NEED_IO_FLOAT64 if (ndigs_exp > 3) { my_putc(exp / 1000 + '0', stream); exp %= 1000; } #endif if (ndigs_exp > 2) { my_putc(exp / 100 + '0', stream); exp %= 100; } if (ndigs_exp > 1) { my_putc(exp / 10 + '0', stream); exp %= 10; } my_putc('0' + exp, stream); } } } picolibc-1.8.11/libc/stdio/vfprintf_int.c000066400000000000000000000122021513574234600203040ustar00rootroot00000000000000/* Copyright (c) 2002, Alexander Popov (sasho@vip.bg) Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2005, Helmut Wallner Copyright (c) 2007, Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ { if (c == 'd' || c == 'i') { ultoa_signed_t x_s; arg_to_signed(ap, flags, x_s); if (x_s < 0) { /* Use unsigned in case x_s is the largest negative value */ x_s = (ultoa_signed_t) - (ultoa_unsigned_t)x_s; flags |= FL_NEGATIVE; } flags &= ~FL_ALT; #ifndef _NEED_IO_SHRINK if (x_s == 0 && (flags & FL_PREC) && prec == 0) buf_len = 0; else #endif buf_len = __ultoa_invert(x_s, u.buf, 10) - u.buf; } else { int base; ultoa_unsigned_t x; if (c == 'u') { flags &= ~FL_ALT; base = 10; } else if (c == 'o') { base = 8; c = '\0'; } else if (c == 'p') { base = 16; flags |= FL_ALT; c = 'x'; if (sizeof(void *) > sizeof(int)) flags |= FL_LONG; } else if (TOLOWER(c) == 'x') { base = ('x' - c) | 16; #ifdef _NEED_IO_PERCENT_B } else if (TOLOWER(c) == 'b') { base = 2; #endif } else { my_putc('%', stream); my_putc(c, stream); continue; } flags &= ~(FL_PLUS | FL_SPACE); arg_to_unsigned(ap, flags, x); /* Zero gets no special alternate treatment */ if (x == 0) flags &= ~FL_ALT; #ifndef _NEED_IO_SHRINK if (x == 0 && (flags & FL_PREC) && prec == 0) buf_len = 0; else #endif buf_len = __ultoa_invert(x, u.buf, base) - u.buf; } #ifndef _NEED_IO_SHRINK int len = buf_len; /* Specified precision */ if (flags & FL_PREC) { /* Zfill ignored when precision specified */ flags &= ~FL_ZFILL; /* If the number is shorter than the precision, pad * on the left with zeros */ if (len < prec) { len = prec; /* Don't add the leading '0' for alternate octal mode */ if (c == '\0') flags &= ~FL_ALT; } } /* Alternate mode for octal/hex */ if (flags & FL_ALT) { len += 1; if (c != '\0') len += 1; } else if (flags & (FL_NEGATIVE | FL_PLUS | FL_SPACE)) { len += 1; } /* Pad on the left ? */ if (!(flags & FL_LPAD)) { /* Pad with zeros, using the same loop as the * precision modifier */ if (flags & FL_ZFILL) { prec = buf_len; if (len < width) { prec += width - len; len = width; } } while (len < width) { my_putc(' ', stream); len++; } } /* Width remaining on right after value */ width -= len; /* Output leading characters */ if (flags & FL_ALT) { my_putc('0', stream); if (c != '\0') my_putc(c, stream); } else if (flags & (FL_NEGATIVE | FL_PLUS | FL_SPACE)) { unsigned char z = ' '; if (flags & FL_PLUS) z = '+'; if (flags & FL_NEGATIVE) z = '-'; my_putc(z, stream); } /* Output leading zeros */ while (prec > buf_len) { my_putc('0', stream); prec--; } #else if (flags & FL_ALT) { my_putc('0', stream); if (c != '\0') my_putc(c, stream); } else if (flags & FL_NEGATIVE) my_putc('-', stream); #endif /* Output value */ while (buf_len) my_putc(u.buf[--buf_len], stream); } picolibc-1.8.11/libc/stdio/vfprintf_n.c000066400000000000000000000042301513574234600177510ustar00rootroot00000000000000/* Copyright (c) 2002, Alexander Popov (sasho@vip.bg) Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2005, Helmut Wallner Copyright (c) 2007, Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ { #ifdef VFPRINTF_S msg = "format string contains percent-n"; goto handle_error; #else if (flags & FL_LONG) { if (flags & FL_REPD_TYPE) *va_arg(ap, long long *) = stream_len; else *va_arg(ap, long *) = stream_len; } else if (flags & FL_SHORT) { if (flags & FL_REPD_TYPE) *va_arg(ap, char *) = stream_len; else *va_arg(ap, short *) = stream_len; } else { *va_arg(ap, int *) = stream_len; } #endif } picolibc-1.8.11/libc/stdio/vfprintf_s.c000066400000000000000000000034211513574234600177570ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define __STDC_WANT_LIB_EXT1__ 1 #include "stdio_private.h" #include #include #include #include "../stdlib/local_s.h" #define VFPRINTF_S #include "vfprintf.c"picolibc-1.8.11/libc/stdio/vfprintf_str.c000066400000000000000000000067371513574234600203420ustar00rootroot00000000000000/* Copyright (c) 2002, Alexander Popov (sasho@vip.bg) Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2005, Helmut Wallner Copyright (c) 2007, Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ { #ifdef _NEED_IO_WCHAR if (flags & FL_LONG) { wstr = va_arg(ap, wchar_t *); if (!wstr) goto str_null; wstr_lpad: size = (flags & FL_PREC) ? (size_t)prec : SIZE_MAX; #ifdef _NEED_IO_WIDETOMB size = _mbslen(wstr, size); if (size == (size_t)-1) goto ret; #else size = wcsnlen(wstr, size); #endif goto str_lpad; } else #endif pnt = va_arg(ap, char *); if (!pnt) { #ifdef _NEED_IO_WCHAR str_null: #endif #ifdef VFPRINTF_S msg = "arg corresponding to '%s' is null"; goto handle_error; #endif pnt = "(null)"; } #ifdef _NEED_IO_SHRINK char c; while ((c = *pnt++)) my_putc(c, stream); #else size = (flags & FL_PREC) ? (size_t)prec : SIZE_MAX; #ifdef _NEED_IO_MBTOWIDE size = _wcslen(pnt, size); #else size = strnlen(pnt, size); #endif str_lpad: if (!(flags & FL_LPAD)) { while ((size_t)width > size) { my_putc(' ', stream); width--; } } width -= size; #ifdef _NEED_IO_WCHAR if (wstr) { #ifdef _NEED_IO_WIDETOMB mbstate_t ps = { 0 }; while (size) { wchar_t c = *wstr++; char *m = u.mb; int mb_len = __WCTOMB(m, c, &ps); while (size && mb_len) { my_putc(*m++, stream); size--; mb_len--; } } #else while (size--) my_putc(*wstr++, stream); #endif } else #endif { #ifdef _NEED_IO_MBTOWIDE mbstate_t ps = { 0 }; while (size--) { wchar_t c; size_t mb_len = mbrtowc(&c, pnt, MB_LEN_MAX, &ps); my_putc(c, stream); pnt += mb_len; } #else while (size--) my_putc(*pnt++, stream); #endif } #endif } picolibc-1.8.11/libc/stdio/vfscanf.c000066400000000000000000000665301513574234600172370ustar00rootroot00000000000000/* Copyright (c) 2002,2004,2005 Joerg Wunsch Copyright (c) 2008 Dmitry Xmelkov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: vfscanf.c 2191 2010-11-05 13:45:57Z arcanum $ */ #ifndef SCANF_NAME #define SCANF_VARIANT __IO_VARIANT_DOUBLE #define SCANF_NAME __d_vfscanf #endif #include "stdio_private.h" #include #include "scanf_private.h" #include "../stdlib/local.h" #if __IO_DEFAULT != SCANF_VARIANT || defined(WIDE_CHARS) #define vfscanf SCANF_NAME #endif /* * Compute which features are required */ #ifdef _NEED_IO_LONG_LONG typedef unsigned long long uint_scanf_t; typedef long long int_scanf_t; #else typedef unsigned long uint_scanf_t; typedef long int_scanf_t; #endif /* Figure out which multi-byte char support we need */ #if defined(_NEED_IO_WCHAR) && defined(__MB_CAPABLE) #ifdef WIDE_CHARS /* need to convert wide chars to multi-byte chars */ #define _NEED_IO_WIDETOMB #else /* need to convert multi-byte chars to wide chars */ #define _NEED_IO_MBTOWIDE #endif #endif #ifdef WIDE_CHARS #define INT wint_t #define MY_EOF WEOF #define CHAR wchar_t #if __SIZEOF_WCHAR_T__ == 2 #define UCHAR uint16_t #elif __SIZEOF_WCHAR_T__ == 4 #define UCHAR uint32_t #endif #define GETC(s) getwc_unlocked(s) #define UNGETC(c, s) ungetwc(c, s) #define ISSPACE(c) iswspace(c) #define ISALNUM(c) iswalnum(c) #define IS_EOF(c) ((c) == WEOF) #define WINT wint_t #define IS_WEOF(c) ((c) == WEOF) #define ISWSPACE(c) iswspace(c) #define STRCHR(s, c) wcschr(s, c) #define CQ(a) L##a #else #define INT int #define MY_EOF EOF #define IS_EOF(c) ((c) < 0) #define CHAR char #define UCHAR unsigned char #define GETC(s) getc_unlocked(s) #define UNGETC(c, s) ungetc(c, s) #define ISSPACE(c) isspace(c) #define ISALNUM(c) isalnum(c) #define STRCHR(s, c) strchr(s, c) #define CQ(a) a #ifdef _NEED_IO_MBTOWIDE #define WINT wint_t #define MY_WEOF WEOF #define IS_WEOF(c) ((c) == WEOF) #define ISWSPACE(c) iswspace(c) #else #define WINT int #define IS_WEOF(c) IS_EOF(c) #define MY_WEOF MY_EOF #define ISWSPACE(c) ISSPACE(c) #endif #endif #ifdef WIDE_CHARS typedef struct { int len; INT unget; } scanf_context_t; #define SCANF_CONTEXT_INIT { .len = 0, .unget = MY_EOF } #define scanf_len(context) ((context)->len) #else typedef int scanf_context_t; #define SCANF_CONTEXT_INIT 0 #define scanf_len(context) (*(context)) #endif static INT scanf_getc(FILE *stream, scanf_context_t *context) { INT c; #ifdef WIDE_CHARS c = context->unget; context->unget = MY_EOF; if (IS_EOF(c)) #endif c = GETC(stream); if (!IS_EOF(c)) ++scanf_len(context); return c; } static void scanf_ungetc(INT c, FILE *stream, scanf_context_t *context) { if (!IS_EOF(c)) --scanf_len(context); #ifdef WIDE_CHARS (void)stream; context->unget = c; #else UNGETC(c, stream); #endif } #ifdef _NEED_IO_MBTOWIDE static WINT getmb(FILE *stream, scanf_context_t *context, mbstate_t *ps, uint16_t flags) { INT i; if (flags & FL_LONG) { wchar_t ch; char mb[MB_LEN_MAX]; size_t n = 0; int s; mbstate_t save; while (n < MB_LEN_MAX) { i = scanf_getc(stream, context); if (IS_EOF(i)) return WEOF; mb[n++] = (char)i; save = *ps; s = __MBTOWC(&ch, mb, n, ps); switch (s) { case -1: return WEOF; case -2: *ps = save; break; default: return (wint_t)ch; } } return WEOF; } else { i = scanf_getc(stream, context); if (IS_EOF(i)) return MY_WEOF; return (WINT)i; } } #else #define getmb(s, c, p, f) scanf_getc(s, c) #endif #ifdef _NEED_IO_WIDETOMB static void * _putmb(void *addr, wint_t wi, mbstate_t *ps, uint16_t flags) { if (flags & FL_LONG) { *(wchar_t *)addr = (wchar_t)wi; addr = (wchar_t *)addr + 1; } else { int s; s = __WCTOMB((char *)addr, (wchar_t)wi, ps); if (s == -1) return NULL; addr = (char *)addr + s; } return addr; } #define putmb(addr, wi, ps, flags, fail) \ do { \ if (addr) { \ addr = _putmb(addr, wi, ps, flags); \ if (!addr) \ fail; \ } \ } while (0); #else #ifdef _NEED_IO_WCHAR static void * _putmb(void *addr, wint_t wi, uint16_t flags) { if (flags & FL_LONG) { *(wchar_t *)addr = (wchar_t)wi; addr = (wchar_t *)addr + 1; } else { *(char *)addr = (char)wi; addr = (char *)addr + 1; } return addr; } #define putmb(addr, wi, ps, flags, fail) \ do { \ if (addr) { \ addr = _putmb(addr, wi, flags); \ if (!addr) \ fail; \ } \ } while (0) #else #define putmb(addr, wi, ps, flags, fail) \ do { \ if (addr) { \ *(char *)addr = (char)wi; \ addr = (char *)addr + 1; \ } \ } while (0) #endif #endif static void putval(void *addr, int_scanf_t val, uint16_t flags) { if (addr) { if (flags & FL_CHAR) *(char *)addr = val; #ifdef _NEED_IO_LONG_LONG else if (flags & FL_LONGLONG) *(long long *)addr = val; #endif else if (flags & FL_LONG) *(long *)addr = val; else if (flags & FL_SHORT) *(short *)addr = val; else *(int *)addr = val; } } static unsigned char conv_int(FILE *stream, scanf_context_t *context, width_t width, void *addr, uint16_t flags, unsigned int base) { uint_scanf_t val; INT i; i = scanf_getc(stream, context); /* after scanf_ungetc() */ switch (i) { case '-': flags |= FL_MINUS; __fallthrough; case '+': if (!--width || IS_EOF(i = scanf_getc(stream, context))) goto err; } val = 0; /* Leading '0' digit -- check for base indication */ if (i == '0') { if (!--width || IS_EOF(i = scanf_getc(stream, context))) goto putval; flags |= FL_ANY; if (TOLOWER(i) == 'x' && (base == 0 || base == 16)) { base = 16; if (!--width || IS_EOF(i = scanf_getc(stream, context))) goto putval; #ifdef _NEED_IO_PERCENT_B } else if (i == 'b' && base <= 2) { base = 2; if (!--width || IS_EOF(i = scanf_getc(stream, context))) goto putval; #endif } else if (base == 0 || base == 8) { base = 8; } } else if (base == 0) base = 10; do { unsigned int c = digit_to_val(i); if (c >= base) { scanf_ungetc(i, stream, context); break; } flags |= FL_ANY; val = val * base + c; if (!--width) goto putval; } while (!IS_EOF(i = scanf_getc(stream, context))); if (!(flags & FL_ANY)) goto err; putval: if (flags & FL_MINUS) val = -val; putval(addr, val, flags); return 1; err: return 0; } #ifdef _NEED_IO_BRACKET static const CHAR * conv_brk(FILE *stream, scanf_context_t *context, width_t width, void *addr, const CHAR *_fmt, uint16_t flags) { #if defined(_NEED_IO_MBTOWIDE) || defined(_NEED_IO_WIDETOMB) mbstate_t ps = { 0 }; #endif const CHAR *fmt; UCHAR f; bool fnegate = false; bool fany = false; (void)flags; if (*_fmt == '^') { fnegate = true; _fmt++; } do { WINT wi = getmb(stream, context, &ps, flags); UCHAR cbelow; UCHAR cabove = 0; bool fmatch = false; bool frange = false; /* * This is comically inefficient when matching a long string * as we re-scan the format string for every input * character. However, converting the specified scanset to a * more efficient data structure would require an allocation. */ fmt = _fmt; for (;;) { /* * POSIX is very clear that the format string contains * bytes, not multi-byte characters. Hence all that we can * match are wide characters which happen to fall in a range * which can be specified by byte values. * * glibc appears to parse the format string as multi-byte * characters, which makes sense, but appears to violate the * spec. */ f = *fmt++; if (!f) return NULL; if (fmt != _fmt + 1) { if (f == ']') break; if (f == '-' && !frange) { frange = true; continue; } } cbelow = f; if (frange) { cbelow = cabove; frange = false; } cabove = f; if ((WINT)cbelow <= wi && wi <= (WINT)cabove) fmatch = true; } if (IS_WEOF(wi)) break; if (fmatch == fnegate) { scanf_ungetc(wi, stream, context); break; } fany = true; putmb(addr, wi, &ps, flags, return NULL); width--; } while (width); if (!fany) return NULL; putmb(addr, 0, &ps, flags, return NULL); return fmt; } #endif /* _NEED_IO_BRACKET */ #if defined(_NEED_IO_FLOAT) || defined(_NEED_IO_DOUBLE) #include "conv_flt.c" #endif static INT skip_spaces(FILE *stream, scanf_context_t *context) { INT i; do { if (IS_EOF(i = scanf_getc(stream, context))) return i; } while (ISSPACE(i)); scanf_ungetc(i, stream, context); return i; } #ifdef _NEED_IO_POS_ARGS typedef struct { va_list ap; } my_va_list; static void skip_to_arg(my_va_list *ap, int target_argno) { int current_argno = 1; /* * Fortunately, all scanf args are pointers, * and so are the same size as void * */ while (current_argno < target_argno) { (void)va_arg(ap->ap, void *); current_argno++; } } #endif /** Formatted input. This function is the heart of the \b scanf family of functions. Characters are read from \a stream and processed in a way described by \a fmt. Conversion results will be assigned to the parameters passed via \a ap. The format string \a fmt is scanned for conversion specifications. Anything that doesn't comprise a conversion specification is taken as text that is matched literally against the input. White space in the format string will match any white space in the data (including none), all other characters match only itself. Processing is aborted as soon as the data and format string no longer match, or there is an error or end-of-file condition on \a stream. Most conversions skip leading white space before starting the actual conversion. Conversions are introduced with the character \b %. Possible options can follow the \b %: - a \c * indicating that the conversion should be performed but the conversion result is to be discarded; no parameters will be processed from \c ap, - the character \c h indicating that the argument is a pointer to short int (rather than int), - the 2 characters \c hh indicating that the argument is a pointer to char (rather than int). - the character \c l indicating that the argument is a pointer to long int (rather than int, for integer type conversions), or a pointer to \c double (for floating point conversions), In addition, a maximal field width may be specified as a nonzero positive decimal integer, which will restrict the conversion to at most this many characters from the input stream. This field width is limited to at most 255 characters which is also the default value (except for the %c conversion that defaults to 1). The following conversion flags are supported: - \c % Matches a literal \c % character. This is not a conversion. - \c d Matches an optionally signed decimal integer; the next pointer must be a pointer to \c int. - \c i Matches an optionally signed integer; the next pointer must be a pointer to \c int. The integer is read in base 16 if it begins with \b 0x or \b 0X, in base 8 if it begins with \b 0, and in base 10 otherwise. Only characters that correspond to the base are used. - \c o Matches an octal integer; the next pointer must be a pointer to unsigned int. - \c u Matches an optionally signed decimal integer; the next pointer must be a pointer to unsigned int. - \c x Matches an optionally signed hexadecimal integer; the next pointer must be a pointer to unsigned int. - \c f Matches an optionally signed floating-point number; the next pointer must be a pointer to \c float. - e, g, F, E, G Equivalent to \c f. - \c s Matches a sequence of non-white-space characters; the next pointer must be a pointer to \c char, and the array must be large enough to accept all the sequence and the terminating \c NUL character. The input string stops at white space or at the maximum field width, whichever occurs first. - \c c Matches a sequence of width count characters (default 1); the next pointer must be a pointer to \c char, and there must be enough room for all the characters (no terminating \c NUL is added). The usual skip of leading white space is suppressed. To skip white space first, use an explicit space in the format. - \c [ Matches a nonempty sequence of characters from the specified set of accepted characters; the next pointer must be a pointer to \c char, and there must be enough room for all the characters in the string, plus a terminating \c NUL character. The usual skip of leading white space is suppressed. The string is to be made up of characters in (or not in) a particular set; the set is defined by the characters between the open bracket \c [ character and a close bracket \c ] character. The set excludes those characters if the first character after the open bracket is a circumflex \c ^. To include a close bracket in the set, make it the first character after the open bracket or the circumflex; any other position will end the set. The hyphen character \c - is also special; when placed between two other characters, it adds all intervening characters to the set. To include a hyphen, make it the last character before the final close bracket. For instance, [^]0-9-] means the set of everything except close bracket, zero through nine, and hyphen. The string ends with the appearance of a character not in the (or, with a circumflex, in) set or when the field width runs out. Note that usage of this conversion enlarges the stack expense. - \c p Matches a pointer value (as printed by %p in printf()); the next pointer must be a pointer to \c void. - \c n Nothing is expected; instead, the number of characters consumed thus far from the input is stored through the next pointer, which must be a pointer to \c int. This is not a conversion, although it can be suppressed with the \c * flag. These functions return the number of input items assigned, which can be fewer than provided for, or even zero, in the event of a matching failure. Zero indicates that, while there was input available, no conversions were assigned; typically this is due to an invalid input character, such as an alphabetic character for a %d conversion. The value \c EOF is returned if an input failure occurs before any conversion such as an end-of-file occurs. If an error or end-of-file occurs after conversion has begun, the number of conversions which were successfully completed is returned. By default, all the conversions described above are available except the floating-point conversions and the width is limited to 255 characters. The float-point conversion will be available in the extended version provided by the library \c libscanf_flt.a. Also in this case the width is not limited (exactly, it is limited to 65535 characters). To link a program against the extended version, use the following compiler flags in the link stage: \code -Wl,-u,vfscanf -lscanf_flt -lm \endcode A third version is available for environments that are tight on space. In addition to the restrictions of the standard one, this version implements no %[ specification. This version is provided in the library \c libscanf_min.a, and can be requested using the following options in the link stage: \code -Wl,-u,vfscanf -lscanf_min -lm \endcode */ int vfscanf(FILE *stream, const CHAR *fmt, va_list ap_orig) { unsigned char nconvs; UCHAR c; width_t width; void *addr; #ifdef _NEED_IO_POS_ARGS my_va_list my_ap; #define ap my_ap.ap va_copy(ap, ap_orig); #else #define ap ap_orig #endif uint16_t flags; INT i; scanf_context_t context = SCANF_CONTEXT_INIT; __flockfile(stream); nconvs = 0; /* Initialization of stream_flags at each pass simplifies the register allocation with GCC 3.3 - 4.2. Only the GCC 4.3 is good to move it to the begin. */ while ((c = *fmt++) != 0) { if (ISSPACE(c)) { skip_spaces(stream, &context); } else if (c != '%' || (c = *fmt++) == '%') { /* Ordinary character. */ if (IS_EOF(i = scanf_getc(stream, &context))) goto eof; if ((UCHAR)i != c) { scanf_ungetc(i, stream, &context); break; } } else { flags = 0; if (c == '*') { flags = FL_STAR; c = *fmt++; } for (;;) { width = 0; while ((c -= '0') < 10) { flags |= FL_WIDTH; width = width * 10 + c; c = *fmt++; } c += '0'; if (flags & FL_WIDTH) { #ifdef _NEED_IO_POS_ARGS if (c == '$') { flags &= ~FL_WIDTH; va_end(ap); va_copy(ap, ap_orig); skip_to_arg(&my_ap, width); c = *fmt++; continue; } #endif /* C99 says that width must be greater than zero. To simplify program do treat 0 as error in format. */ if (!width) break; } else { width = ~0; } break; } switch (c) { case 'h': flags |= FL_SHORT; c = *fmt++; if (c == 'h') { flags |= FL_CHAR; c = *fmt++; } break; case 'l': flags |= FL_LONG; c = *fmt++; if (c == 'l') { flags |= FL_LONGLONG; c = *fmt++; } break; case 'L': flags |= FL_LONG | FL_LONGLONG; c = *fmt++; break; #ifdef _NEED_IO_C99_FORMATS #ifdef _NEED_IO_LONG_LONG #define CHECK_LONGLONG(type) else if (sizeof(type) == sizeof(long long)) flags |= FL_LONGLONG #else #define CHECK_LONGLONG(type) #endif #define CHECK_INT_SIZE(letter, type) \ case letter: \ if (sizeof(type) != sizeof(int)) { \ if (sizeof(type) == sizeof(long)) \ flags |= FL_LONG; \ else if (sizeof(type) == sizeof(short)) \ flags |= FL_SHORT; \ CHECK_LONGLONG(type); \ } \ c = *fmt++; \ break; CHECK_INT_SIZE('j', intmax_t); CHECK_INT_SIZE('z', size_t); CHECK_INT_SIZE('t', ptrdiff_t); #endif } #ifdef _NEED_IO_PERCENT_B #define CNV_BASE "cdinopsuxXb" #else #define CNV_BASE "cdinopsuxX" #endif #ifdef _NEED_IO_BRACKET #define CNV_BRACKET "[" #else #define CNV_BRACKET "" #endif #if defined(_NEED_IO_FLOAT) || defined(_NEED_IO_DOUBLE) #define CNV_FLOAT "aefgAEFG" #else #define CNV_FLOAT "" #endif #define CNV_LIST CNV_BASE CNV_BRACKET CNV_FLOAT if (!c || !strchr(CNV_LIST, c)) break; addr = (flags & FL_STAR) ? 0 : va_arg(ap, void *); if (c == 'n') { putval(addr, (unsigned)scanf_len(&context), flags); continue; } if (c == 'c') { if (!(flags & FL_WIDTH)) width = 1; bool have_put = false; #if defined(_NEED_IO_MBTOWIDE) || defined(_NEED_IO_WIDETOMB) mbstate_t ps = { 0 }; #endif do { WINT wi = getmb(stream, &context, &ps, flags); if (IS_WEOF(wi)) { if (have_put) break; goto eof; } putmb(addr, wi, &ps, flags, goto eof); have_put = true; } while (--width); c = 1; /* no matter with smart GCC */ #ifdef _NEED_IO_BRACKET } else if (c == '[') { fmt = conv_brk(stream, &context, width, addr, fmt, flags); c = (fmt != 0); #endif } else { unsigned int base = 0; if (IS_EOF(skip_spaces(stream, &context))) goto eof; switch (c) { case 's': { #if defined(_NEED_IO_MBTOWIDE) || defined(_NEED_IO_WIDETOMB) mbstate_t ps = { 0 }; #endif /* Now we have 1 nospace symbol. */ do { WINT wi = getmb(stream, &context, &ps, flags); if (IS_WEOF(wi)) break; if (ISWSPACE(wi)) { scanf_ungetc(wi, stream, &context); break; } putmb(addr, wi, &ps, flags, goto eof); } while (--width); putmb(addr, 0, &ps, flags, goto eof); c = 1; /* no matter with smart GCC */ break; } #if defined(_NEED_IO_FLOAT) || defined(_NEED_IO_DOUBLE) case 'p': if (sizeof(void *) > sizeof(int)) flags |= FL_LONG; __fallthrough; case 'x': case 'X': base = 16; goto conv_int; #ifdef _NEED_IO_PERCENT_B case 'b': base = 2; goto conv_int; #endif case 'd': case 'u': base = 10; goto conv_int; case 'o': base = 8; __fallthrough; case 'i': conv_int: c = conv_int(stream, &context, width, addr, flags, base); break; default: /* a,A,e,E,f,F,g,G */ c = conv_flt(stream, &context, width, addr, flags); break; #else case 'd': case 'u': base = 10; goto conv_int; #ifdef _NEED_IO_PERCENT_B case 'b': base = 2; goto conv_int; #endif case 'o': base = 8; __fallthrough; case 'i': goto conv_int; case 'p': if (sizeof(void *) > sizeof(int)) flags |= FL_LONG; __fallthrough; default: /* p,x,X */ base = 16; conv_int: c = conv_int(stream, &context, width, addr, flags, base); break; #endif } } /* else */ if (!c) { if (stream->flags & __SERR || ((stream->flags & __SEOF) && nconvs == 0)) goto eof; break; } if (!(flags & FL_STAR)) nconvs += 1; } /* else */ } /* while */ #ifdef _NEED_IO_POS_ARGS va_end(ap); #endif #ifdef WIDE_CHARS if (!IS_EOF(context.unget)) UNGETC(context.unget, stream); #endif __funlock_return(stream, nconvs); eof: #ifdef _NEED_IO_POS_ARGS va_end(ap); #endif #ifdef WIDE_CHARS if (!IS_EOF(context.unget)) UNGETC(context.unget, stream); #endif __funlock_return(stream, nconvs ? nconvs : EOF); } #undef ap #if !defined(WIDE_CHARS) #if SCANF_VARIANT == __IO_DEFAULT #undef vfscanf #ifdef __strong_reference __strong_reference(vfscanf, SCANF_NAME); #else int SCANF_NAME(FILE *stream, const char *fmt, va_list ap) { return vfscanf(stream, fmt, ap); } #endif #endif #endif picolibc-1.8.11/libc/stdio/vfwprintf.c000066400000000000000000000032071513574234600176260ustar00rootroot00000000000000/* Copyright © 2018 Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define PRINTF_VARIANT __IO_VARIANT_DOUBLE #define PRINTF_NAME vfwprintf #define WIDE_CHARS #include "vfprintf.c" picolibc-1.8.11/libc/stdio/vfwscanf.c000066400000000000000000000032031513574234600174120ustar00rootroot00000000000000/* Copyright © 2018 Keith Packard All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define SCANF_VARIANT __IO_VARIANT_DOUBLE #define SCANF_NAME vfwscanf #define WIDE_CHARS #include "vfscanf.c" picolibc-1.8.11/libc/stdio/vprintf.c000066400000000000000000000032711513574234600172720ustar00rootroot00000000000000/* Copyright (c) 2005, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: vprintf.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int vprintf(const char *fmt, va_list ap) { return vfprintf(stdout, fmt, ap); } picolibc-1.8.11/libc/stdio/vscanf.c000066400000000000000000000032651513574234600170650ustar00rootroot00000000000000/* Copyright (c) 2005, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: vscanf.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int vscanf(const char *fmt, va_list ap) { return vfscanf(stdin, fmt, ap); } picolibc-1.8.11/libc/stdio/vsnprintf.c000066400000000000000000000036411513574234600176340ustar00rootroot00000000000000/* Copyright (c) 2003, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: vsnprintf.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int vsnprintf(char *s, size_t n, const char *fmt, va_list ap) { int i; struct __file_str f = FDEV_SETUP_STRING_WRITE(s, FDEV_STRING_WRITE_END(s, n)); i = vfprintf(&f.file, fmt, ap); if (n) *f.pos = '\0'; return i; } __ieee128_reference(vsnprintf, __vsnprintfieee128); picolibc-1.8.11/libc/stdio/vsnprintf_s.c000066400000000000000000000060241513574234600201540ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define __STDC_WANT_LIB_EXT1__ 1 #include "stdio_private.h" #include #include #include #include "../stdlib/local_s.h" int vsnprintf_s(char * __restrict s, rsize_t n, const char * __restrict fmt, va_list arg) { bool write_null = true; const char *msg = ""; int rc; if (s == NULL) { write_null = false; msg = "dest buffer is null"; goto handle_error; } else if ((n == 0) || (CHECK_RSIZE(n))) { write_null = false; msg = "invalid buffer size"; goto handle_error; } else if (fmt == NULL) { msg = "null format string"; goto handle_error; } else { struct __file_str f = FDEV_SETUP_STRING_WRITE(s, FDEV_STRING_WRITE_END(s, n)); rc = vfprintf_s(&f.file, fmt, arg); if (n) { *f.pos = '\0'; } } if (rc < 0) { msg = "output error"; goto handle_error; } else if (rc > INT_MAX) { msg = "output size exceeds max limit"; goto handle_error; } else if ((unsigned int)rc >= n) { msg = "dest buffer overflow"; goto handle_error; } else { s[rc] = '\0'; } // Normal return path return rc; handle_error: if (__cur_handler != NULL) { __cur_handler(msg, NULL, -1); } rc = -1; if (write_null && s != NULL && n > 0) { s[0] = '\0'; /* again, standard requires this */ } return rc; } picolibc-1.8.11/libc/stdio/vsprintf.c000066400000000000000000000035101513574234600174510ustar00rootroot00000000000000/* Copyright (c) 2003, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: vsprintf.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int vsprintf(char *s, const char *fmt, va_list ap) { struct __file_str f = FDEV_SETUP_STRING_WRITE(s, NULL); int i; i = vfprintf(&f.file, fmt, ap); if (i >= 0) s[i] = 0; return i; } picolibc-1.8.11/libc/stdio/vsscanf.c000066400000000000000000000033031513574234600172410ustar00rootroot00000000000000/* Copyright (c) 2005, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int vsscanf(const char *s, const char *fmt, va_list ap) { struct __file_str f = FDEV_SETUP_STRING_READ(s); return vfscanf(&f.file, fmt, ap); } picolibc-1.8.11/libc/stdio/vswprintf.c000066400000000000000000000036711513574234600176500ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2023 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int vswprintf(wchar_t *s, size_t n, const wchar_t *fmt, va_list ap) { struct __file_str f = FDEV_SETUP_STRING_WRITE((char *)s, (char *)FDEV_STRING_WRITE_END(s, n)); int i; f.file.flags |= __SWIDE; i = vfwprintf(&f.file, fmt, ap); if (n) memset(f.pos, 0, sizeof(wchar_t)); return i; } picolibc-1.8.11/libc/stdio/vswscanf.c000066400000000000000000000033141513574234600174320ustar00rootroot00000000000000/* Copyright (c) 2005, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int vswscanf(const wchar_t *s, const wchar_t *fmt, va_list ap) { struct __file_str f = FDEV_SETUP_WSTRING_READ(s); return vfwscanf(&f.file, fmt, ap); } picolibc-1.8.11/libc/stdio/vwprintf.c000066400000000000000000000032761513574234600174660ustar00rootroot00000000000000/* Copyright (c) 2005, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: vprintf.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int vwprintf(const wchar_t *fmt, va_list ap) { return vfwprintf(stdout, fmt, ap); } picolibc-1.8.11/libc/stdio/vwscanf.c000066400000000000000000000032011513574234600172420ustar00rootroot00000000000000/* Copyright (c) 2005, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int vwscanf(const wchar_t *fmt, va_list ap) { return vfwscanf(stdin, fmt, ap); } picolibc-1.8.11/libc/stdio/wcstod.c000066400000000000000000000032141513574234600171020ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include #include "strtod.c" picolibc-1.8.11/libc/stdio/wcstod_l.c000066400000000000000000000031721513574234600174200ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include "strtod_l.c" picolibc-1.8.11/libc/stdio/wcstof.c000066400000000000000000000032141513574234600171040ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include #include "strtof.c" picolibc-1.8.11/libc/stdio/wcstof_l.c000066400000000000000000000031721513574234600174220ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include "strtof_l.c" picolibc-1.8.11/libc/stdio/wcstoimax.c000066400000000000000000000031731513574234600176210ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include "strtoimax.c" picolibc-1.8.11/libc/stdio/wcstoimax_l.c000066400000000000000000000031751513574234600201360ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include "strtoimax_l.c" picolibc-1.8.11/libc/stdio/wcstol.c000066400000000000000000000031701513574234600171130ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include "strtol.c" picolibc-1.8.11/libc/stdio/wcstol_l.c000066400000000000000000000031721513574234600174300ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include "strtol_l.c" picolibc-1.8.11/libc/stdio/wcstold.c000066400000000000000000000032151513574234600172570ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include #include "strtold.c" picolibc-1.8.11/libc/stdio/wcstold_l.c000066400000000000000000000031731513574234600175750ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include "strtold_l.c" picolibc-1.8.11/libc/stdio/wcstoll.c000066400000000000000000000031711513574234600172700ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include "strtoll.c" picolibc-1.8.11/libc/stdio/wcstoll_l.c000066400000000000000000000031731513574234600176050ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include "strtoll_l.c" picolibc-1.8.11/libc/stdio/wcstoul.c000066400000000000000000000031711513574234600173010ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include "strtoul.c" picolibc-1.8.11/libc/stdio/wcstoul_l.c000066400000000000000000000031731513574234600176160ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include "strtoul_l.c" picolibc-1.8.11/libc/stdio/wcstoull.c000066400000000000000000000031721513574234600174560ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include "strtoull.c" picolibc-1.8.11/libc/stdio/wcstoull_l.c000066400000000000000000000031741513574234600177730ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include "strtoull_l.c" picolibc-1.8.11/libc/stdio/wcstoumax.c000066400000000000000000000031731513574234600176350ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include "strtoumax.c" picolibc-1.8.11/libc/stdio/wcstoumax_l.c000066400000000000000000000031751513574234600201520ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define WIDE_CHARS #include "strtoumax_l.c" picolibc-1.8.11/libc/stdio/wprintf.c000066400000000000000000000034101513574234600172660ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id: fprintf.c 1944 2009-04-01 23:12:20Z arcanum $ */ #include "stdio_private.h" int wprintf(const wchar_t *fmt, ...) { va_list ap; int i; va_start(ap, fmt); i = vfwprintf(stdout, fmt, ap); va_end(ap); return i; } picolibc-1.8.11/libc/stdio/wscanf.c000066400000000000000000000033131513574234600170600ustar00rootroot00000000000000/* Copyright (c) 2002, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "stdio_private.h" int wscanf(const wchar_t *fmt, ...) { va_list ap; int i; va_start(ap, fmt); i = vfwscanf(stdin, fmt, ap); va_end(ap); return i; } picolibc-1.8.11/libc/stdlib/000077500000000000000000000000001513574234600155725ustar00rootroot00000000000000picolibc-1.8.11/libc/stdlib/CMakeLists.txt000066400000000000000000000054561513574234600203440ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources( a64l.c abort.c abs.c aligned_alloc.c arc4random.c arc4random_uniform.c assert.c assert_func.c assert_no_arg.c atof.c atoff.c atoi.c atol.c atoll.c btowc.c div.c drand48.c ejtouc.c environ.c eprintf.c erand48.c _Exit.c getenv.c getenv_r.c getopt.c getsubopt.c imaxabs.c imaxdiv.c itoa.c jitouc.c jrand48.c l64a.c labs.c lcong48.c ldiv.c llabs.c lldiv.c lrand48.c mblen.c mbrlen.c mbrtowc.c mbsinit.c mbsnrtowcs.c mbsrtowcs.c mbstowcs.c mbtowc.c mbtowc_r.c mrand48.c nrand48.c putenv.c rand48.c rand.c random.c rand_r.c reallocarray.c reallocf.c rpmatch.c sb_charsets.c seed48.c setenv.c sjtouc.c srand.c srand48.c srandom.c system.c uctoji.c uctoej.c uctosj.c utoa.c wcrtomb.c wcsnrtombs.c wcsrtombs.c wcstombs.c wctob.c wctomb.c wctomb_r.c atexit.c exit.c exitprocs.c onexit.c cxa-atexit.c set_constraint_handler_s.c ignore_handler_s.c ) if(ENABLE_MALLOC) picolibc_sources( calloc.c free.c getpagesize.c mallinfo.c malloc.c malloc-stats.c malloc-usable-size.c mallopt.c memalign.c posix-memalign.c pvalloc.c realloc.c valloc.c ) endif() picolibc-1.8.11/libc/stdlib/Makefile000066400000000000000000000000631513574234600172310ustar00rootroot00000000000000jis_charsets.h: mk-jis-charsets.py python $< > $@ picolibc-1.8.11/libc/stdlib/_Exit.c000066400000000000000000000017731513574234600170160ustar00rootroot00000000000000/* Copyright (c) 2002 Jeff Johnston */ /* FUNCTION <<_Exit>>---end program execution with no cleanup processing INDEX _Exit SYNOPSIS #include void _Exit(int <[code]>); DESCRIPTION Use <<_Exit>> to return control from a program to the host operating environment. Use the argument <[code]> to pass an exit status to the operating environment: two particular values, <> and <>, are defined in `<>' to indicate success or failure in a portable fashion. <<_Exit>> differs from <> in that it does not run any application-defined cleanup functions registered with <> and it does not clean up files and streams. It is identical to <<_exit>>. RETURNS <<_Exit>> does not return to its caller. PORTABILITY <<_Exit>> is defined by the C99 standard. Supporting OS subroutines required: <<_exit>>. */ #include #include /* for _exit() declaration */ void _Exit(int code) { _exit(code); } picolibc-1.8.11/libc/stdlib/a64l.c000066400000000000000000000101741513574234600165070ustar00rootroot00000000000000/* Copyright (c) 2002 Jeff Johnston */ /* FUNCTION <>, <>---convert between radix-64 ASCII string and long INDEX a64l INDEX l64a SYNOPSIS #include long a64l(const char *<[input]>); char *l64a(long <[input]>); DESCRIPTION Conversion is performed between long and radix-64 characters. The <> routine transforms up to 32 bits of input value starting from least significant bits to the most significant bits. The input value is split up into a maximum of 5 groups of 6 bits and possibly one group of 2 bits (bits 31 and 30). Each group of 6 bits forms a value from 0--63 which is translated into a character as follows: O+ o 0 = '.' o 1 = '/' o 2--11 = '0' to '9' o 12--37 = 'A' to 'Z' o 38--63 = 'a' to 'z' O- When the remaining bits are zero or all bits have been translated, a null terminator is appended to the string. An input value of 0 results in the empty string. The <> function performs the reverse translation. Each character is used to generate a 6-bit value for up to 30 bits and then a 2-bit value to complete a 32-bit result. The null terminator means that the remaining digits are 0. An empty input string or NULL string results in 0L. An invalid string results in undefined behavior. If the size of a long is greater than 32 bits, the result is sign-extended. RETURNS <> returns a null-terminated string of 0 to 6 characters. <> returns the 32-bit translated value from the input character string. PORTABILITY <> and <> are non-ANSI and are defined by the Single Unix Specification. Supporting OS subroutines required: None. */ #define _DEFAULT_SOURCE #include #include long a64l(const char *input) { const char *ptr; char ch; int i, digit; unsigned long result = 0; if (input == NULL) return 0; ptr = input; /* it easiest to go from most significant digit to least so find end of input or up to 6 characters worth */ for (i = 0; i < 6; ++i) { if (*ptr) ++ptr; } while (ptr > input) { ch = *(--ptr); #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) if (ch >= 'a') digit = (ch - 'a') + 38; else if (ch >= 'A') digit = (ch - 'A') + 12; else if (ch >= '0') digit = (ch - '0') + 2; else if (ch == '/') digit = 1; else digit = 0; #else /* !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) */ switch (ch) { case '/': digit = 1; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': digit = (ch - '0') + 2; break; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': digit = (ch - 'A') + 12; break; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': digit = (ch - 'a') + 38; break; default: digit = 0; break; } #endif /* !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) */ result = (result << 6) + digit; } return (long int)result; } picolibc-1.8.11/libc/stdlib/abort.c000066400000000000000000000030011513574234600170370ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* NetWare can not use this implementation of abort. It provides its own version of abort in clib.nlm. If we can not use clib.nlm, then we must write abort in sys/netware. */ #ifdef ABORT_PROVIDED int _dummy_abort = 1; #else /* FUNCTION <>---abnormal termination of a program INDEX abort SYNOPSIS #include void abort(void); DESCRIPTION Use <> to signal that your program has detected a condition it cannot deal with. Normally, <> ends your program's execution. Before terminating your program, <> raises the exception <> (using `<>'). If you have used <> to register an exception handler for this condition, that handler has the opportunity to retain control, thereby avoiding program termination. In this implementation, <> does not perform any stream- or file-related cleanup (the host environment may do so; if not, you can arrange for your program to do its own cleanup with a <> exception handler). RETURNS <> does not return to its caller. PORTABILITY ANSI C requires <>. Supporting OS subroutines required: <<_exit>> and optionally, <>. */ #include #include #include void abort(void) { #ifdef ABORT_MESSAGE write(2, "Abort called\n", sizeof("Abort called\n") - 1); #endif while (1) { raise(SIGABRT); _exit(1); } } #endif picolibc-1.8.11/libc/stdlib/abs.c000066400000000000000000000013461513574234600165070ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* FUNCTION <>---integer absolute value (magnitude) INDEX abs SYNOPSIS #include int abs(int <[i]>); DESCRIPTION <> returns @tex $|x|$, @end tex the absolute value of <[i]> (also called the magnitude of <[i]>). That is, if <[i]> is negative, the result is the opposite of <[i]>, but if <[i]> is nonnegative the result is <[i]>. The similar function <> uses and returns <> rather than <> values. RETURNS The result is a nonnegative integer. PORTABILITY <> is ANSI. No supporting OS subroutines are required. */ #include int abs(int i) { return (i < 0) ? -i : i; } picolibc-1.8.11/libc/stdlib/aligned_alloc.c000066400000000000000000000032201513574234600205100ustar00rootroot00000000000000/* C11 aligned_alloc Copyright (c) 2020 Arm Ltd. All rights reserved. SPDX-License-Identifier: BSD-3-Clause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the company may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #ifndef __strong_reference void * aligned_alloc(size_t align, size_t size) { return memalign(align, size); } #endif picolibc-1.8.11/libc/stdlib/arc4random.c000066400000000000000000000130471513574234600177750ustar00rootroot00000000000000/* $OpenBSD: arc4random.c,v 1.58 2022/07/31 13:41:45 tb Exp $ */ /* * Copyright (c) 1996, David Mazieres * Copyright (c) 2008, Damien Miller * Copyright (c) 2013, Markus Friedl * Copyright (c) 2014, Theo de Raadt * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* * ChaCha based random number generator for OpenBSD. */ #define _DEFAULT_SOURCE #include #include #include #include #include #include #include #include #include #define KEYSTREAM_ONLY #include "chacha_private.h" #define minimum(a, b) ((a) < (b) ? (a) : (b)) #if defined(__GNUC__) || defined(_MSC_VER) #define inline __inline #else /* __GNUC__ || _MSC_VER */ #define inline #endif /* !__GNUC__ && !_MSC_VER */ #define KEYSZ 32 #define IVSZ 8 #define BLOCKSZ 64 #define RSBUFSZ (16 * BLOCKSZ) #if SIZE_MAX <= 65535 #define REKEY_BASE ((size_t)32 * 1024) /* NB. should be a power of 2 */ #elif SIZE_MAX <= 1048575 #define REKEY_BASE ((size_t)256 * 1024) /* NB. should be a power of 2 */ #else #define REKEY_BASE ((size_t)1024 * 1024) /* NB. should be a power of 2 */ #endif /* Marked MAP_INHERIT_ZERO, so zero'd out in fork children. */ static struct _rs { size_t rs_have; /* valid bytes at end of rs_buf */ size_t rs_count; /* bytes till reseed */ } *rs; /* Maybe be preserved in fork children, if _rs_allocate() decides. */ static struct _rsx { chacha_ctx rs_chacha; /* chacha context for random keystream */ unsigned char rs_buf[RSBUFSZ]; /* keystream blocks */ } *rsx; static inline int _rs_allocate(struct _rs **, struct _rsx **); static inline void _rs_forkdetect(void); #include "arc4random.h" static inline void _rs_rekey(unsigned char *dat, size_t datlen); static inline void _rs_init(unsigned char *buf, size_t n) { if (n < KEYSZ + IVSZ) return; if (rs == NULL) { if (_rs_allocate(&rs, &rsx) == -1) abort(); } chacha_keysetup(&rsx->rs_chacha, buf, KEYSZ * 8); chacha_ivsetup(&rsx->rs_chacha, buf + KEYSZ); } static void _rs_stir(void) { uint8_t rnd[KEYSZ + IVSZ]; uint32_t rekey_fuzz = 0; memset(rnd, 0, (KEYSZ + IVSZ) * sizeof(u_char)); if (getentropy(rnd, sizeof rnd) == -1) _getentropy_fail(); if (!rs) _rs_init(rnd, sizeof(rnd)); else _rs_rekey(rnd, sizeof(rnd)); explicit_bzero(rnd, sizeof(rnd)); /* discard source seed */ /* invalidate rs_buf */ rs->rs_have = 0; memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf)); /* rekey interval should not be predictable */ chacha_encrypt_bytes(&rsx->rs_chacha, (uint8_t *)&rekey_fuzz, (uint8_t *)&rekey_fuzz, sizeof(rekey_fuzz)); rs->rs_count = REKEY_BASE + (rekey_fuzz % REKEY_BASE); } static inline void _rs_stir_if_needed(size_t len) { _rs_forkdetect(); if (!rs || rs->rs_count <= len) _rs_stir(); if (rs->rs_count <= len) rs->rs_count = 0; else rs->rs_count -= len; } static inline void _rs_rekey(unsigned char *dat, size_t datlen) { #ifndef KEYSTREAM_ONLY memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf)); #endif /* fill rs_buf with the keystream */ chacha_encrypt_bytes(&rsx->rs_chacha, rsx->rs_buf, rsx->rs_buf, sizeof(rsx->rs_buf)); /* mix in optional user provided data */ if (dat) { size_t i, m; m = minimum(datlen, KEYSZ + IVSZ); for (i = 0; i < m; i++) rsx->rs_buf[i] ^= dat[i]; } /* immediately reinit for backtracking resistance */ _rs_init(rsx->rs_buf, KEYSZ + IVSZ); memset(rsx->rs_buf, 0, KEYSZ + IVSZ); rs->rs_have = sizeof(rsx->rs_buf) - KEYSZ - IVSZ; } static inline void _rs_random_buf(void *_buf, size_t n) { unsigned char *buf = (unsigned char *)_buf; unsigned char *keystream; size_t m; _rs_stir_if_needed(n); while (n > 0) { if (rs->rs_have > 0) { m = minimum(n, rs->rs_have); keystream = rsx->rs_buf + sizeof(rsx->rs_buf) - rs->rs_have; memcpy(buf, keystream, m); memset(keystream, 0, m); buf += m; n -= m; rs->rs_have -= m; } if (rs->rs_have == 0) _rs_rekey(NULL, 0); } } static inline void _rs_random_u32(uint32_t *val) { unsigned char *keystream; _rs_stir_if_needed(sizeof(*val)); if (rs->rs_have < sizeof(*val)) _rs_rekey(NULL, 0); keystream = rsx->rs_buf + sizeof(rsx->rs_buf) - rs->rs_have; memcpy(val, keystream, sizeof(*val)); memset(keystream, 0, sizeof(*val)); rs->rs_have -= sizeof(*val); } uint32_t arc4random(void) { uint32_t val; _ARC4_LOCK(); _rs_random_u32(&val); _ARC4_UNLOCK(); return val; } void arc4random_buf(void *buf, size_t n) { _ARC4_LOCK(); _rs_random_buf(buf, n); _ARC4_UNLOCK(); } picolibc-1.8.11/libc/stdlib/arc4random.h000066400000000000000000000045211513574234600177770ustar00rootroot00000000000000/*- * Copyright (c) 2016 embedded brains GmbH * 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. */ /* * Newlib ports may override the default implementations via the following * define and macros * o _ARC4RANDOM_DATA, * o _ARC4RANDOM_GETENTROPY_FAIL(), * o _ARC4RANDOM_ALLOCATE(rsp, rspx), and * o _ARC4RANDOM_FORKDETECT(). */ #include #include #include #define _ARC4_LOCK() __LIBC_LOCK() #define _ARC4_UNLOCK() __LIBC_UNLOCK() #ifdef _ARC4RANDOM_DATA _ARC4RANDOM_DATA #else static struct { struct _rs rs; struct _rsx rsx; } _arc4random_data; #endif static inline void _getentropy_fail(void) { #ifdef _ARC4RANDOM_GETENTROPY_FAIL _ARC4RANDOM_GETENTROPY_FAIL(); #else raise(SIGKILL); #endif } static inline int _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) { #ifdef _ARC4RANDOM_ALLOCATE _ARC4RANDOM_ALLOCATE(rsp, rsxp); #else *rsp = &_arc4random_data.rs; *rsxp = &_arc4random_data.rsx; return (0); #endif } static inline void _rs_forkdetect(void) { #ifdef _ARC4RANDOM_FORKDETECT _ARC4RANDOM_FORKDETECT(); #endif } picolibc-1.8.11/libc/stdlib/arc4random_uniform.c000066400000000000000000000035431513574234600215340ustar00rootroot00000000000000/* $OpenBSD: arc4random_uniform.c,v 1.2 2015/09/13 08:31:47 guenther Exp $ */ /* * Copyright (c) 2008, Damien Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #define _DEFAULT_SOURCE #include #include /* * Calculate a uniformly distributed random number less than upper_bound * avoiding "modulo bias". * * Uniformity is achieved by generating new random numbers until the one * returned is outside the range [0, 2**32 % upper_bound). This * guarantees the selected random number will be inside * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound) * after reduction modulo upper_bound. */ uint32_t arc4random_uniform(uint32_t upper_bound) { uint32_t r, min; if (upper_bound < 2) return 0; /* 2**32 % x == (2**32 - x) % x */ min = -upper_bound % upper_bound; /* * This could theoretically loop forever but each retry has * p > 0.5 (worst case, usually far better) of selecting a * number inside the range we need, so it should rarely need * to re-roll. */ for (;;) { r = arc4random(); if (r >= min) break; } return r % upper_bound; } picolibc-1.8.11/libc/stdlib/assert.c000066400000000000000000000032421513574234600172400ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* FUNCTION <>---macro for debugging diagnostics INDEX assert SYNOPSIS #include void assert(int <[expression]>); DESCRIPTION Use this macro to embed debuggging diagnostic statements in your programs. The argument <[expression]> should be an expression which evaluates to true (nonzero) when your program is working as you intended. When <[expression]> evaluates to false (zero), <> calls <>, after first printing a message showing what failed and where: . Assertion failed: <[expression]>, file <[filename]>, line <[lineno]>, function: <[func]> If the name of the current function is not known (for example, when using a C89 compiler that does not understand __func__), the function location is omitted. The macro is defined to permit you to turn off all uses of <> at compile time by defining <> as a preprocessor variable. If you do this, the <> macro expands to . (void(0)) RETURNS <> does not return a value. PORTABILITY The <> macro is required by ANSI, as is the behavior when <> is defined. Supporting OS subroutines required (only if enabled): <>, <>, <>, <>, <>, <>, <>, <>, <>. */ #include #include #include void __assert(const char *failedexpr, const char *file, int line) { __assert_func(file, line, NULL, failedexpr); /* NOTREACHED */ } picolibc-1.8.11/libc/stdlib/assert_func.c000066400000000000000000000036671513574234600202660ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* FUNCTION <>---macro for debugging diagnostics INDEX assert SYNOPSIS #include void assert(int <[expression]>); DESCRIPTION Use this macro to embed debuggging diagnostic statements in your programs. The argument <[expression]> should be an expression which evaluates to true (nonzero) when your program is working as you intended. When <[expression]> evaluates to false (zero), <> calls <>, after first printing a message showing what failed and where: . Assertion failed: <[expression]>, file <[filename]>, line <[lineno]>, function: <[func]> If the name of the current function is not known (for example, when using a C89 compiler that does not understand __func__), the function location is omitted. The macro is defined to permit you to turn off all uses of <> at compile time by defining <> as a preprocessor variable. If you do this, the <> macro expands to . (void(0)) RETURNS <> does not return a value. PORTABILITY The <> macro is required by ANSI, as is the behavior when <> is defined. Supporting OS subroutines required (only if enabled): <>, <>, <>, <>, <>, <>, <>, <>, <>. */ #include #include #include #ifndef __HAVE_ASSERT_FUNC /* func can be NULL, in which case no function information is given. */ void __assert_func(const char *file, int line, const char *func, const char *failedexpr) { fprintf(stderr, "assertion \"%s\" failed: file \"%s\", line %d%s%s\n", failedexpr, file, line, func ? ", function: " : "", func ? func : ""); abort(); /* NOTREACHED */ } #endif /* __HAVE_ASSERT_FUNC */ picolibc-1.8.11/libc/stdlib/assert_no_arg.c000066400000000000000000000031561513574234600205710ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* FUNCTION <>---macro for debugging diagnostics INDEX assert SYNOPSIS #include void assert(int <[expression]>); DESCRIPTION Use this macro to embed debuggging diagnostic statements in your programs. The argument <[expression]> should be an expression which evaluates to true (nonzero) when your program is working as you intended. When <[expression]> evaluates to false (zero), <> calls <>, after first printing a message showing what failed and where: . Assertion failed: <[expression]>, file <[filename]>, line <[lineno]>, function: <[func]> If the name of the current function is not known (for example, when using a C89 compiler that does not understand __func__), the function location is omitted. The macro is defined to permit you to turn off all uses of <> at compile time by defining <> as a preprocessor variable. If you do this, the <> macro expands to . (void(0)) RETURNS <> does not return a value. PORTABILITY The <> macro is required by ANSI, as is the behavior when <> is defined. Supporting OS subroutines required (only if enabled): <>, <>, <>, <>, <>, <>, <>, <>, <>. */ #include #include #include void __assert_no_args(void) { fprintf(stderr, "assertion failed\n"); abort(); } picolibc-1.8.11/libc/stdlib/atexit.c000066400000000000000000000035121513574234600172350ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2021 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include #include "local-onexit.h" #ifdef ENABLE_PICOLIBC_EXIT int atexit(void (*func)(void)) { union on_exit_func func_u = { .atexit = func }; return _on_exit(PICO_ONEXIT_ATEXIT, func_u, NULL); } #endif picolibc-1.8.11/libc/stdlib/atexit.h000066400000000000000000000026571513574234600172530ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* * Common definitions for atexit-like routines */ #include enum __atexit_types { __et_atexit, __et_onexit, __et_cxa }; #ifdef _GLOBAL_ATEXIT #define __THREAD_LOCAL_ATEXIT #else #define __THREAD_LOCAL_ATEXIT __THREAD_LOCAL #endif #define _ATEXIT_SIZE 32 /* must be at least 32 to guarantee ANSI conformance */ struct _on_exit_args { void *_fnargs[_ATEXIT_SIZE]; /* user fn args */ void *_dso_handle[_ATEXIT_SIZE]; /* Bitmask is set if user function takes arguments. */ uint32_t _fntypes; /* type of exit routine - Must have at least _ATEXIT_SIZE bits */ /* Bitmask is set if function was registered via __cxa_atexit. */ uint32_t _is_cxa; }; struct _atexit { struct _atexit *_next; /* next in list */ int _ind; /* next index in this table */ /* Some entries may already have been called, and will be NULL. */ void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */ struct _on_exit_args _on_exit_args; }; extern __THREAD_LOCAL_ATEXIT struct _atexit _atexit0; extern __THREAD_LOCAL_ATEXIT struct _atexit *_atexit; void __call_exitprocs(int, void *); int __register_exitproc(int, void (*fn)(void), void *, void *); void __cxa_finalize(void *d); int __cxa_atexit(void (*fn)(void *), void *arg, void *d); picolibc-1.8.11/libc/stdlib/atof.c000066400000000000000000000037471513574234600167020ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* FUNCTION <>, <>---string to double or float INDEX atof INDEX atoff SYNOPSIS #include double atof(const char *<[s]>); float atoff(const char *<[s]>); DESCRIPTION <> converts the initial portion of a string to a <>. <> converts the initial portion of a string to a <>. The functions parse the character string <[s]>, locating a substring which can be converted to a floating-point value. The substring must match the format: . [+|-]<[digits]>[.][<[digits]>][(e|E)[+|-]<[digits]>] The substring converted is the longest initial fragment of <[s]> that has the expected format, beginning with the first non-whitespace character. The substring is empty if <> is empty, consists entirely of whitespace, or if the first non-whitespace character is something other than <<+>>, <<->>, <<.>>, or a digit. <)>> is implemented as <, NULL)>>. <)>> is implemented as <, NULL)>>. RETURNS <> returns the converted substring value, if any, as a <>; or <<0.0>>, if no conversion could be performed. If the correct value is out of the range of representable values, plus or minus <> is returned, and <> is stored in <>. If the correct value would cause underflow, <<0.0>> is returned and <> is stored in <>. <> obeys the same rules as <>, except that it returns a <>. PORTABILITY <> is ANSI C. <>, <>, and <> are subsumed by <> and <>, but are used extensively in existing code. These functions are less reliable, but may be faster if the argument is verified to be in a valid range. Supporting OS subroutines required: <>, <>, <>, <>, <>, <>, <>. */ #include double atof(const char *s) { return strtod(s, NULL); } picolibc-1.8.11/libc/stdlib/atoff.c000066400000000000000000000003001513574234600170260ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ #define _DEFAULT_SOURCE #include float atoff(const char *s) { return strtof(s, NULL); } picolibc-1.8.11/libc/stdlib/atoi.c000066400000000000000000000022531513574234600166740ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* FUNCTION <>, <>---string to integer INDEX atoi INDEX atol INDEX _atoi_r INDEX _atol_r SYNOPSIS #include int atoi(const char *<[s]>); long atol(const char *<[s]>); int _atoi_r(struct _reent *<[ptr]>, const char *<[s]>); long _atol_r(struct _reent *<[ptr]>, const char *<[s]>); DESCRIPTION <> converts the initial portion of a string to an <>. <> converts the initial portion of a string to a <>. <> is implemented as <<(int)strtol(s, NULL, 10).>> <> is implemented as <> <<_atoi_r>> and <<_atol_r>> are reentrant versions of <> and <> respectively, passing the reentrancy struct pointer. RETURNS The functions return the converted value, if any. If no conversion was made, <<0>> is returned. PORTABILITY <>, <> are ANSI. No supporting OS subroutines are required. */ /* * Andy Wilson, 2-Oct-89. */ #include int atoi(const char *s) { return (int)strtol(s, NULL, 10); } picolibc-1.8.11/libc/stdlib/atol.c000066400000000000000000000003141513574234600166730ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* * Andy Wilson, 2-Oct-89. */ #include long atol(const char *s) { return strtol(s, NULL, 10); } picolibc-1.8.11/libc/stdlib/atoll.c000066400000000000000000000047311513574234600170560ustar00rootroot00000000000000/* FUNCTION <>---convert a string to a long long integer INDEX atoll INDEX _atoll_r SYNOPSIS #include long long atoll(const char *<[str]>); long long _atoll_r(struct _reent *<[ptr]>, const char *<[str]>); DESCRIPTION The function <> converts the initial portion of the string pointed to by <<*<[str]>>> to a type <>. A call to atoll(str) in this implementation is equivalent to strtoll(str, (char **)NULL, 10) including behavior on error. The alternate function <<_atoll_r>> is a reentrant version. The extra argument <[reent]> is a pointer to a reentrancy structure. RETURNS The converted value. PORTABILITY <> is ISO 9899 (C99) and POSIX 1003.1-2001 compatable. No supporting OS subroutines are required. */ /* * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include long long atoll(const char *str) { return strtoll(str, (char **)NULL, 10); } picolibc-1.8.11/libc/stdlib/btowc.c000066400000000000000000000010651513574234600170560ustar00rootroot00000000000000/* Copyright (c) 2002 Thomas Fitzsimmons */ #include #include #include #include #include "local.h" wint_t btowc(int c) { mbstate_t mbs; int retval = 0; wchar_t pwc; unsigned char b; if (c == EOF) return WEOF; b = (unsigned char)c; /* Put mbs in initial state. */ memset(&mbs, '\0', sizeof(mbs)); retval = __MBTOWC(&pwc, (const char *)&b, 1, &mbs); if (retval != 0 && retval != 1) return WEOF; return (wint_t)pwc; } picolibc-1.8.11/libc/stdlib/calloc.c000066400000000000000000000034401513574234600171740ustar00rootroot00000000000000/* * Copyright (c) 2012, 2013 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "local-malloc.h" #include "mul_overflow.h" /* * Implement calloc by multiplying sizes (with overflow check) and * calling malloc (which already sets to zero) */ void * calloc(size_t n, size_t elem) { size_t bytes; if (mul_overflow(n, elem, &bytes)) { errno = ENOMEM; return NULL; } return malloc(bytes); } picolibc-1.8.11/libc/stdlib/chacha_private.h000066400000000000000000000162511513574234600207110ustar00rootroot00000000000000/* Copyright (c) 1996, David Mazieres Copyright (c) 2008, Damien Miller Copyright (c) 2013, Markus Friedl Copyright (c) 2014, Theo de Raadt Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* chacha-merged.c version 20080118 D. J. Bernstein Public domain. */ /* $OpenBSD: chacha_private.h,v 1.3 2022/02/28 21:56:29 dtucker Exp $ */ #include typedef uint8_t u8; typedef uint32_t u32; typedef struct { u32 input[16]; /* could be compressed */ } chacha_ctx; #define U8V(v) ((u8)(v)) #define U32V(v) ((u32)(v)) #define ROTL32(v, n) (U32V((v) << (n)) | ((v) >> (32 - (n)))) #define U8TO32_LITTLE(p) \ (((u32)((p)[0])) | ((u32)((p)[1]) << 8) | ((u32)((p)[2]) << 16) | ((u32)((p)[3]) << 24)) #define U32TO8_LITTLE(p, v) \ do { \ (p)[0] = U8V((v)); \ (p)[1] = U8V((v) >> 8); \ (p)[2] = U8V((v) >> 16); \ (p)[3] = U8V((v) >> 24); \ } while (0) #define ROTATE(v, c) (ROTL32(v, c)) #define XOR(v, w) ((v) ^ (w)) #define PLUS(v, w) (U32V((v) + (w))) #define PLUSONE(v) (PLUS((v), 1)) #define QUARTERROUND(a, b, c, d) \ a = PLUS(a, b); \ d = ROTATE(XOR(d, a), 16); \ c = PLUS(c, d); \ b = ROTATE(XOR(b, c), 12); \ a = PLUS(a, b); \ d = ROTATE(XOR(d, a), 8); \ c = PLUS(c, d); \ b = ROTATE(XOR(b, c), 7); #ifdef __GNUCLIKE_PRAGMA_DIAGNOSTIC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wunknown-warning-option" #pragma GCC diagnostic ignored "-Wunterminated-string-initialization" #endif static const char sigma[16] = "expand 32-byte k"; static const char tau[16] = "expand 16-byte k"; static void chacha_keysetup(chacha_ctx *x, const u8 *k, u32 kbits) { const char *constants; x->input[4] = U8TO32_LITTLE(k + 0); x->input[5] = U8TO32_LITTLE(k + 4); x->input[6] = U8TO32_LITTLE(k + 8); x->input[7] = U8TO32_LITTLE(k + 12); if (kbits == 256) { /* recommended */ k += 16; constants = sigma; } else { /* kbits == 128 */ constants = tau; } x->input[8] = U8TO32_LITTLE(k + 0); x->input[9] = U8TO32_LITTLE(k + 4); x->input[10] = U8TO32_LITTLE(k + 8); x->input[11] = U8TO32_LITTLE(k + 12); x->input[0] = U8TO32_LITTLE(constants + 0); x->input[1] = U8TO32_LITTLE(constants + 4); x->input[2] = U8TO32_LITTLE(constants + 8); x->input[3] = U8TO32_LITTLE(constants + 12); } static void chacha_ivsetup(chacha_ctx *x, const u8 *iv) { x->input[12] = 0; x->input[13] = 0; x->input[14] = U8TO32_LITTLE(iv + 0); x->input[15] = U8TO32_LITTLE(iv + 4); } static void chacha_encrypt_bytes(chacha_ctx *x, const u8 *m, u8 *c, u32 bytes) { u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15; u8 tmp[64]; u8 *ctarget = tmp; u_int i; if (!bytes) return; j0 = x->input[0]; j1 = x->input[1]; j2 = x->input[2]; j3 = x->input[3]; j4 = x->input[4]; j5 = x->input[5]; j6 = x->input[6]; j7 = x->input[7]; j8 = x->input[8]; j9 = x->input[9]; j10 = x->input[10]; j11 = x->input[11]; j12 = x->input[12]; j13 = x->input[13]; j14 = x->input[14]; j15 = x->input[15]; for (;;) { if (bytes < 64) { for (i = 0; i < bytes; ++i) tmp[i] = m[i]; m = tmp; ctarget = c; c = tmp; } x0 = j0; x1 = j1; x2 = j2; x3 = j3; x4 = j4; x5 = j5; x6 = j6; x7 = j7; x8 = j8; x9 = j9; x10 = j10; x11 = j11; x12 = j12; x13 = j13; x14 = j14; x15 = j15; for (i = 20; i > 0; i -= 2) { QUARTERROUND(x0, x4, x8, x12) QUARTERROUND(x1, x5, x9, x13) QUARTERROUND(x2, x6, x10, x14) QUARTERROUND(x3, x7, x11, x15) QUARTERROUND(x0, x5, x10, x15) QUARTERROUND(x1, x6, x11, x12) QUARTERROUND(x2, x7, x8, x13) QUARTERROUND(x3, x4, x9, x14) } x0 = PLUS(x0, j0); x1 = PLUS(x1, j1); x2 = PLUS(x2, j2); x3 = PLUS(x3, j3); x4 = PLUS(x4, j4); x5 = PLUS(x5, j5); x6 = PLUS(x6, j6); x7 = PLUS(x7, j7); x8 = PLUS(x8, j8); x9 = PLUS(x9, j9); x10 = PLUS(x10, j10); x11 = PLUS(x11, j11); x12 = PLUS(x12, j12); x13 = PLUS(x13, j13); x14 = PLUS(x14, j14); x15 = PLUS(x15, j15); #ifndef KEYSTREAM_ONLY x0 = XOR(x0, U8TO32_LITTLE(m + 0)); x1 = XOR(x1, U8TO32_LITTLE(m + 4)); x2 = XOR(x2, U8TO32_LITTLE(m + 8)); x3 = XOR(x3, U8TO32_LITTLE(m + 12)); x4 = XOR(x4, U8TO32_LITTLE(m + 16)); x5 = XOR(x5, U8TO32_LITTLE(m + 20)); x6 = XOR(x6, U8TO32_LITTLE(m + 24)); x7 = XOR(x7, U8TO32_LITTLE(m + 28)); x8 = XOR(x8, U8TO32_LITTLE(m + 32)); x9 = XOR(x9, U8TO32_LITTLE(m + 36)); x10 = XOR(x10, U8TO32_LITTLE(m + 40)); x11 = XOR(x11, U8TO32_LITTLE(m + 44)); x12 = XOR(x12, U8TO32_LITTLE(m + 48)); x13 = XOR(x13, U8TO32_LITTLE(m + 52)); x14 = XOR(x14, U8TO32_LITTLE(m + 56)); x15 = XOR(x15, U8TO32_LITTLE(m + 60)); #endif j12 = PLUSONE(j12); if (!j12) { j13 = PLUSONE(j13); /* stopping at 2^70 bytes per nonce is user's responsibility */ } U32TO8_LITTLE(c + 0, x0); U32TO8_LITTLE(c + 4, x1); U32TO8_LITTLE(c + 8, x2); U32TO8_LITTLE(c + 12, x3); U32TO8_LITTLE(c + 16, x4); U32TO8_LITTLE(c + 20, x5); U32TO8_LITTLE(c + 24, x6); U32TO8_LITTLE(c + 28, x7); U32TO8_LITTLE(c + 32, x8); U32TO8_LITTLE(c + 36, x9); U32TO8_LITTLE(c + 40, x10); U32TO8_LITTLE(c + 44, x11); U32TO8_LITTLE(c + 48, x12); U32TO8_LITTLE(c + 52, x13); U32TO8_LITTLE(c + 56, x14); U32TO8_LITTLE(c + 60, x15); if (bytes <= 64) { if (bytes < 64) { for (i = 0; i < bytes; ++i) ctarget[i] = c[i]; } x->input[12] = j12; x->input[13] = j13; return; } bytes -= 64; c += 64; #ifndef KEYSTREAM_ONLY m += 64; #endif } } picolibc-1.8.11/libc/stdlib/cxa-atexit.c000066400000000000000000000035661513574234600200170ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2021 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _GNU_SOURCE #include #include "local-onexit.h" #ifdef ENABLE_PICOLIBC_EXIT int __cxa_atexit(void (*func)(void *), void *arg, void *d) { union on_exit_func func_u = { .cxa_atexit = func }; (void)d; return _on_exit(PICO_ONEXIT_CXA_ATEXIT, func_u, arg); } #endif picolibc-1.8.11/libc/stdlib/div.c000066400000000000000000000074411513574234600165260ustar00rootroot00000000000000/* FUNCTION <
>---divide two integers INDEX div SYNOPSIS #include div_t div(int <[n]>, int <[d]>); DESCRIPTION Divide @tex $n/d$, @end tex @ifnottex <[n]>/<[d]>, @end ifnottex returning quotient and remainder as two integers in a structure <>. RETURNS The result is represented with the structure . typedef struct . { . int quot; . int rem; . } div_t; where the <> field represents the quotient, and <> the remainder. For nonzero <[d]>, if `<<<[r]> = div(<[n]>,<[d]>);>>' then <[n]> equals `<<<[r]>.rem + <[d]>*<[r]>.quot>>'. To divide <> rather than <> values, use the similar function <>. PORTABILITY <
> is ANSI. No supporting OS subroutines are required. */ /* * Copyright (c) 1990 Regents of the University of California. * All rights reserved. * * This code is derived from software contributed to Berkeley by * Chris Torek. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include /* div_t */ div_t div(int num, int denom) { div_t r; r.quot = num / denom; r.rem = num % denom; /* * The ANSI standard says that |r.quot| <= |n/d|, where * n/d is to be computed in infinite precision. In other * words, we should always truncate the quotient towards * 0, never -infinity or +infinity. * * Machine division and remainer may work either way when * one or both of n or d is negative. If only one is * negative and r.quot has been truncated towards -inf, * r.rem will have the same sign as denom and the opposite * sign of num; if both are negative and r.quot has been * truncated towards -inf, r.rem will be positive (will * have the opposite sign of num). These are considered * `wrong'. * * If both are num and denom are positive, r will always * be positive. * * This all boils down to: * if num >= 0, but r.rem < 0, we got the wrong answer. * In that case, to get the right answer, add 1 to r.quot and * subtract denom from r.rem. * if num < 0, but r.rem > 0, we also have the wrong answer. * In this case, to get the right answer, subtract 1 from r.quot and * add denom to r.rem. */ if (num >= 0 && r.rem < 0) { ++r.quot; r.rem -= denom; } else if (num < 0 && r.rem > 0) { --r.quot; r.rem += denom; } return (r); } picolibc-1.8.11/libc/stdlib/drand48.c000066400000000000000000000011561513574234600172050ustar00rootroot00000000000000/* * Copyright (c) 1993 Martin Birgmeier * All rights reserved. * * You may redistribute unmodified or modified versions of this source * code provided that the above copyright notice and this and the * following conditions are retained. * * This software is provided ``as is'', and comes with no warranties * of any kind. I shall in no event be liable for anything that happens * to anyone/anything when using this software. */ #define _DEFAULT_SOURCE #include "rand48.h" double _drand48_r(struct _rand48 *r) { return _erand48_r(r, r->_seed); } double drand48(void) { return _drand48_r(&_rand48); } picolibc-1.8.11/libc/stdlib/ejtouc.c000066400000000000000000000065601513574234600172360ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #ifdef __MB_EXTENDED_CHARSETS_JIS #define define_jis_x0208 #define define_jis_x0213 #include "jis.h" wint_t __euc_jp_to_unicode(uint32_t euc_jp) { uint8_t byte0 = euc_jp >> 16; uint8_t byte1 = euc_jp >> 8; uint8_t byte2 = euc_jp; const uint16_t *codes; const struct jis_charmap *map; uint8_t first_row, last_row; uint16_t unicode; switch (byte0) { case 0x8f: codes = __euc_jp_jis_x0213_codes; map = __euc_jp_jis_x0213_map; first_row = __euc_jp_jis_x0213_first_row; last_row = __euc_jp_jis_x0213_last_row; break; case 0x00: switch (byte1) { case 0x00: /* ASCII */ if (byte2 < 0xa0 && byte2 != 0x8f && byte2 != 0x8e) return byte2; return WEOF; case 0x8e: /* Half-width Katakana */ if (0xa1 <= byte2 && byte2 <= 0xdf) return (uint16_t)byte2 - 0xa1U + 0xff61U; return WEOF; default: codes = __euc_jp_jis_x0208_codes; map = __euc_jp_jis_x0208_map; first_row = __euc_jp_jis_x0208_first_row; last_row = __euc_jp_jis_x0208_last_row; break; } break; default: return WEOF; } if (byte1 < first_row || last_row < byte1) return WEOF; map = &map[byte1 - first_row]; if (map->offset == 0xffff || byte2 < map->first || map->last < byte2) return WEOF; codes = &codes[map->offset]; unicode = codes[byte2 - map->first]; if (unicode == __euc_jp_invalid_unicode) return WEOF; return unicode; } #endif /* __MB_EXTENDED_CHARSETS_JIS */ picolibc-1.8.11/libc/stdlib/environ.c000066400000000000000000000034601513574234600174210ustar00rootroot00000000000000/* Copyright (c) 1995, 1996, 2002 Red Hat Incorporated. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * The name of Red Hat Incorporated may not be used to endorse * or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Provide a definition of `environ' if crt0.o doesn't. */ static const char * const initial_env[] = { 0 }; /* Posix says `environ' is a pointer to a null terminated list of pointers. Hence `environ' itself is never NULL. */ char **environ = (char **)&initial_env[0]; picolibc-1.8.11/libc/stdlib/eprintf.c000066400000000000000000000017411513574234600174100ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* This is an implementation of the __eprintf function which is compatible with the assert.h which is distributed with gcc. This function is provided because in some cases libgcc.a will not provide __eprintf. This will happen if inhibit_libc is defined, which is done because at the time that libgcc2.c is compiled, the correct may not be available. newlib provides its own copy of assert.h, which calls __assert, not __eprintf. However, in some cases you may accidentally wind up compiling with the gcc assert.h. In such a case, this __eprintf will be used if there does not happen to be one in libgcc2.c. */ #define _GNU_SOURCE #include #include void __eprintf(const char *format, const char *file, unsigned int line, const char *expression) { (void)fprintf(stderr, format, file, line, expression); abort(); /*NOTREACHED*/ } picolibc-1.8.11/libc/stdlib/erand48.c000066400000000000000000000013561513574234600172100ustar00rootroot00000000000000/* * Copyright (c) 1993 Martin Birgmeier * All rights reserved. * * You may redistribute unmodified or modified versions of this source * code provided that the above copyright notice and this and the * following conditions are retained. * * This software is provided ``as is'', and comes with no warranties * of any kind. I shall in no event be liable for anything that happens * to anyone/anything when using this software. */ #include "rand48.h" double _erand48_r(struct _rand48 *r, unsigned short xseed[3]) { __dorand48(r, xseed); return ldexp((double)xseed[0], -48) + ldexp((double)xseed[1], -32) + ldexp((double)xseed[2], -16); } double erand48(unsigned short xseed[3]) { return _erand48_r(&_rand48, xseed); } picolibc-1.8.11/libc/stdlib/exit.c000066400000000000000000000035401513574234600167110ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2021 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include "local-onexit.h" #ifdef ENABLE_PICOLIBC_EXIT void exit(int code) { #ifdef __INIT_FINI_ARRAY __libc_fini_array(); #else if (__call_exitprocs) __call_exitprocs(code, NULL); #endif _exit(code); } #endif picolibc-1.8.11/libc/stdlib/exitprocs.c000066400000000000000000000072121513574234600177600ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2021 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include #include #include #include #include "local-onexit.h" #ifdef ENABLE_PICOLIBC_EXIT struct on_exit { union on_exit_func func; void *arg; enum pico_onexit_kind kind; }; static struct on_exit on_exits[ATEXIT_MAX]; int _on_exit(enum pico_onexit_kind kind, union on_exit_func func, void *arg) { int ret = -1; int o; __LIBC_LOCK(); for (o = 0; o < ATEXIT_MAX; o++) { if (on_exits[o].kind == PICO_ONEXIT_EMPTY) { on_exits[o].func = func; on_exits[o].arg = arg; on_exits[o].kind = kind; ret = 0; break; } } __LIBC_UNLOCK(); return ret; } /* * _call_exitprocs is in the same file as _on_exit so that the destructor * will be included when any _on_exit function is used. */ #ifdef __INIT_FINI_ARRAY static void __call_exitprocs(void) #define code 0 #define param 0 #else void __call_exitprocs(int code, void *param) #endif { (void)param; for (;;) { int i; union on_exit_func func = { 0 }; enum pico_onexit_kind kind = PICO_ONEXIT_EMPTY; void *arg = 0; __LIBC_LOCK(); for (i = ATEXIT_MAX - 1; i >= 0; i--) { kind = on_exits[i].kind; if (kind != PICO_ONEXIT_EMPTY) { func = on_exits[i].func; arg = on_exits[i].arg; memset(&on_exits[i], '\0', sizeof(struct on_exit)); break; } } __LIBC_UNLOCK(); switch (kind) { case PICO_ONEXIT_EMPTY: return; case PICO_ONEXIT_ONEXIT: func.on_exit(code, arg); break; case PICO_ONEXIT_ATEXIT: func.atexit(); break; case PICO_ONEXIT_CXA_ATEXIT: func.cxa_atexit(arg); break; } } } #ifdef __INIT_FINI_ARRAY static const void *__call_exitprocs_ref __section(".fini_array_onexit") __used = __call_exitprocs; #endif #endif picolibc-1.8.11/libc/stdlib/free.c000066400000000000000000000067611513574234600166710ustar00rootroot00000000000000/* * Copyright (c) 2012, 2013 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "local-malloc.h" /* * Algorithm: * Maintain a global free chunk_t single link list, headed by global * variable __malloc_free_list. * When free, insert the to-be-freed chunk_t into free list. The place to * insert should make sure all chunks are sorted by address from low to * high. Then merge with neighbor chunks if adjacent. */ void __malloc_free(void *free_p) { chunk_t *p_to_free; chunk_t **p, *r; if (free_p == NULL) return; p_to_free = ptr_to_chunk(free_p); #ifdef __MALLOC_CLEAR_FREED memset(p_to_free, 0, chunk_usable(p_to_free)); #else p_to_free->next = NULL; #endif #if MALLOC_DEBUG __malloc_validate_block(p_to_free); #endif MALLOC_LOCK; for (p = &__malloc_free_list; (r = *p) != NULL; p = &r->next) { /* Insert in address order */ if (p_to_free <= r) { /* Check for double free */ if (p_to_free == r) { errno = ENOMEM; goto unlock; } break; } /* Merge blocks together */ if (chunk_after(r) == p_to_free) { *_size_ref(r) += _size(p_to_free); p_to_free = r; r = r->next; goto no_insert; } } p_to_free->next = r; *p = p_to_free; no_insert: /* Merge blocks together */ if (chunk_after(p_to_free) == r) { #ifdef __GNUCLIKE_PRAGMA_DIAGNOSTIC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wunknown-warning-option" #pragma GCC diagnostic ignored "-Wanalyzer-null-dereference" #endif *_size_ref(p_to_free) += _size(r); #ifdef __GNUCLIKE_PRAGMA_DIAGNOSTIC #pragma GCC diagnostic pop #endif p_to_free->next = r->next; } unlock: MALLOC_UNLOCK; } #ifdef __strong_reference #if defined(__GNUCLIKE_PRAGMA_DIAGNOSTIC) && !defined(__clang__) #pragma GCC diagnostic ignored "-Wmissing-attributes" #endif __strong_reference(__malloc_free, free); __strong_reference(__malloc_free, cfree); #else void cfree(void *ptr) { free(ptr); } #endif picolibc-1.8.11/libc/stdlib/gdtoa.h000066400000000000000000000131551513574234600170460ustar00rootroot00000000000000/**************************************************************** The author of this software is David M. Gay. Copyright (C) 1998 by Lucent Technologies All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that the copyright notice and this permission notice and warranty disclaimer appear in supporting documentation, and that the name of Lucent or any of its entities not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ****************************************************************/ /* Please send bug reports to David M. Gay (dmg at acm dot org, * with " at " changed at "@" and " dot " changed to "."). */ #ifndef GDTOA_H_INCLUDED #define GDTOA_H_INCLUDED #include /* for size_t */ #define PROTO_NORMAL(x) #define __BEGIN_HIDDEN_DECLS #define __END_HIDDEN_DECLS #define DEF_STRONG(x) #ifndef ULong #define ULong __ULong #endif #ifndef ANSI #ifdef KR_headers #define ANSI(x) () #define Void /*nothing*/ #else #define ANSI(x) x #define Void void #endif #endif /* ANSI */ #ifndef CONST #ifdef KR_headers #define CONST /* blank */ #else #define CONST const #endif #endif /* CONST */ enum { /* return values from strtodg */ STRTOG_Zero = 0x000, STRTOG_Normal = 0x001, STRTOG_Denormal = 0x002, STRTOG_Infinite = 0x003, STRTOG_NaN = 0x004, STRTOG_NaNbits = 0x005, STRTOG_NoNumber = 0x006, STRTOG_NoMemory = 0x007, STRTOG_Retmask = 0x00f, /* The following may be or-ed into one of the above values. */ STRTOG_Inexlo = 0x010, /* returned result rounded toward zero */ STRTOG_Inexhi = 0x020, /* returned result rounded away from zero */ STRTOG_Inexact = 0x030, STRTOG_Underflow = 0x040, STRTOG_Overflow = 0x080, STRTOG_Neg = 0x100 /* does not affect STRTOG_Inexlo or STRTOG_Inexhi */ }; typedef struct FPI { int nbits; int emin; int emax; int rounding; int sudden_underflow; } FPI; enum { /* FPI.rounding values: same as FLT_ROUNDS */ FPI_Round_zero = 0, FPI_Round_near = 1, FPI_Round_up = 2, FPI_Round_down = 3 }; typedef unsigned short __UShort; typedef struct _Bigint Bigint; extern char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve); extern char *__gdtoa(FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, int *decpt, char **rve); extern void __freedtoa(char *); extern float strtof ANSI((CONST char *, char **)); extern double strtod ANSI((CONST char *, char **)); extern int __strtodg ANSI((CONST char *, char **, FPI *, Long *, ULong *)); char *__hdtoa(double, const char *, int, int *, int *, char **); char *__hldtoa(long double, const char *, int, int *, int *, char **); char *__ldtoa(long double, int, int, int *, int *, char **); PROTO_NORMAL(__dtoa); PROTO_NORMAL(__gdtoa); PROTO_NORMAL(__freedtoa); PROTO_NORMAL(__hdtoa); PROTO_NORMAL(__hldtoa); PROTO_NORMAL(__ldtoa); __BEGIN_HIDDEN_DECLS extern char *__g_ddfmt ANSI((char *, double *, int, size_t)); extern char *__g_dfmt ANSI((char *, double *, int, size_t)); extern char *__g_ffmt ANSI((char *, float *, int, size_t)); extern char *__g_Qfmt ANSI((char *, void *, int, size_t)); extern char *__g_xfmt ANSI((char *, void *, int, size_t)); extern char *__g_xLfmt ANSI((char *, void *, int, size_t)); extern int __strtoId ANSI((CONST char *, char **, double *, double *)); extern int __strtoIdd ANSI((CONST char *, char **, double *, double *)); extern int __strtoIf ANSI((CONST char *, char **, float *, float *)); extern int __strtoIQ ANSI((CONST char *, char **, void *, void *)); extern int __strtoIx ANSI((CONST char *, char **, void *, void *)); extern int __strtoIxL ANSI((CONST char *, char **, void *, void *)); extern int __strtord ANSI((CONST char *, char **, int, double *)); extern int __strtordd ANSI((CONST char *, char **, int, double *)); extern int __strtorf ANSI((CONST char *, char **, int, float *)); extern int __strtorQ ANSI((CONST char *, char **, int, void *)); extern int __strtorx ANSI((CONST char *, char **, int, void *)); extern int __strtorxL ANSI((CONST char *, char **, int, void *)); #if 1 extern int __strtodI ANSI((CONST char *, char **, double *)); extern int __strtopd ANSI((CONST char *, char **, double *)); extern int __strtopdd ANSI((CONST char *, char **, double *)); extern int __strtopf ANSI((CONST char *, char **, float *)); extern int __strtopQ ANSI((CONST char *, char **, void *)); extern int __strtopx ANSI((CONST char *, char **, void *)); extern int __strtopxL ANSI((CONST char *, char **, void *)); #else #define __strtopd(s, se, x) strtord(s, se, 1, x) #define __strtopdd(s, se, x) strtordd(s, se, 1, x) #define __strtopf(s, se, x) strtorf(s, se, 1, x) #define __strtopQ(s, se, x) strtorQ(s, se, 1, x) #define __strtopx(s, se, x) strtorx(s, se, 1, x) #define __strtopxL(s, se, x) strtorxL(s, se, 1, x) #endif __END_HIDDEN_DECLS #endif /* GDTOA_H_INCLUDED */ picolibc-1.8.11/libc/stdlib/getenv.c000066400000000000000000000036371513574234600172370ustar00rootroot00000000000000/* FUNCTION <>---look up environment variable INDEX getenv INDEX environ SYNOPSIS #include char *getenv(const char *<[name]>); DESCRIPTION <> searches the list of environment variable names and values (using the global pointer ``<>'') for a variable whose name matches the string at <[name]>. If a variable name matches, <> returns a pointer to the associated value. RETURNS A pointer to the (string) value of the environment variable, or <> if there is no such environment variable. PORTABILITY <> is ANSI, but the rules for properly forming names of environment variables vary from one system to another. <> requires a global pointer <>. */ /* * Copyright (c) 1987, 2000 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that: (1) source distributions retain this entire copyright * notice and comment, and (2) distributions including binaries display * the following acknowledgement: ``This product includes software * developed by the University of California, Berkeley and its contributors'' * in the documentation or other materials provided with the distribution. * Neither the name of the University nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #define _GNU_SOURCE #include #include #include /* * getenv -- * Returns ptr to value associated with name, if any, else NULL. */ char * getenv(const char *name) { int offset; return _findenv(name, &offset); } picolibc-1.8.11/libc/stdlib/getenv_r.c000066400000000000000000000064401513574234600175530ustar00rootroot00000000000000/* FUNCTION <<_getenv_r>>---look up environment variable INDEX _getenv_r INDEX environ SYNOPSIS #include char *_getenv_r(struct _reent *<[reent_ptr]>, const char *<[name]>); DESCRIPTION <<_getenv_r>> searches the list of environment variable names and values (using the global pointer ``<>'') for a variable whose name matches the string at <[name]>. If a variable name matches, <<_getenv_r>> returns a pointer to the associated value. RETURNS A pointer to the (string) value of the environment variable, or <> if there is no such environment variable. PORTABILITY <<_getenv_r>> is not ANSI; the rules for properly forming names of environment variables vary from one system to another. This implementation does not permit '=' to be in identifiers. <<_getenv_r>> requires a global pointer <>. */ /* This file may have been modified by DJ Delorie (Jan 1991). If so, ** these modifications are Copyright (C) 1991 DJ Delorie. */ /* * Copyright (c) 1987 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that: (1) source distributions retain this entire copyright * notice and comment, and (2) distributions including binaries display * the following acknowledgement: ``This product includes software * developed by the University of California, Berkeley and its contributors'' * in the documentation or other materials provided with the distribution. * Neither the name of the University nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #define _GNU_SOURCE #include #include #include #include "envlock.h" extern char **environ; /* Only deal with a pointer to environ, to work around subtle bugs with shared libraries and/or small data systems where the user declares his own 'environ'. */ static char ***p_environ = &environ; /* * _findenv -- * Returns pointer to value associated with name, if any, else NULL. * Sets offset to be the offset of the name/value combination in the * environmental array, for use by setenv(3) and unsetenv(3). * * This routine *should* be a static; don't use it. */ char * _findenv(register const char *name, int *offset) { register int len; register char **p; const char *c; ENV_LOCK; /* In some embedded systems, this does not get set. This protects newlib from dereferencing a bad pointer. */ if (!*p_environ) { ENV_UNLOCK; return NULL; } c = name; while (*c && *c != '=') c++; /* Identifiers may not contain an '=', so cannot match if does */ if (*c != '=') { len = c - name; for (p = *p_environ; *p; ++p) if (!strncmp(*p, name, len)) if (*(c = *p + len) == '=') { *offset = p - *p_environ; ENV_UNLOCK; return (char *)(++c); } } ENV_UNLOCK; return NULL; } picolibc-1.8.11/libc/stdlib/getopt.c000066400000000000000000000377431513574234600172560ustar00rootroot00000000000000/**************************************************************************** getopt.c - Read command line options AUTHOR: Gregory Pietsch CREATED Fri Jan 10 21:13:05 1997 DESCRIPTION: The getopt() function parses the command line arguments. Its arguments argc and argv are the argument count and array as passed to the main() function on program invocation. The argument optstring is a list of available option characters. If such a character is followed by a colon (`:'), the option takes an argument, which is placed in optarg. If such a character is followed by two colons, the option takes an optional argument, which is placed in optarg. If the option does not take an argument, optarg is NULL. The external variable optind is the index of the next array element of argv to be processed; it communicates from one call to the next which element to process. The getopt_long() function works like getopt() except that it also accepts long options started by two dashes `--'. If these take values, it is either in the form --arg=value or --arg value It takes the additional arguments longopts which is a pointer to the first element of an array of type struct option. The last element of the array has to be filled with NULL for the name field. The longind pointer points to the index of the current long option relative to longopts if it is non-NULL. The getopt() function returns the option character if the option was found successfully, `:' if there was a missing parameter for one of the options, `?' for an unknown option character, and EOF for the end of the option list. The getopt_long() function's return value is described in the header file. The function getopt_long_only() is identical to getopt_long(), except that a plus sign `+' can introduce long options as well as `--'. The following describes how to deal with options that follow non-option argv-elements. If the caller did not specify anything, the default is REQUIRE_ORDER if the environment variable POSIXLY_CORRECT is defined, PERMUTE otherwise. REQUIRE_ORDER means don't recognize them as options; stop option processing when the first non-option is seen. This is what Unix does. This mode of operation is selected by either setting the environment variable POSIXLY_CORRECT, or using `+' as the first character of the optstring parameter. PERMUTE is the default. We permute the contents of ARGV as we scan, so that eventually all the non-options are at the end. This allows options to be given in any order, even with programs that were not written to expect this. RETURN_IN_ORDER is an option available to programs that were written to expect options and other argv-elements in any order and that care about the ordering of the two. We describe each non-option argv-element as if it were the argument of an option with character code 1. Using `-' as the first character of the optstring parameter selects this mode of operation. The special argument `--' forces an end of option-scanning regardless of the value of ordering. In the case of RETURN_IN_ORDER, only `--' can cause getopt() and friends to return EOF with optind != argc. 2012-08-26: Tried to make the error handling more sus4-like. The functions return a colon if getopt() and friends detect a missing argument and the first character of shortopts/optstring starts with a colon (`:'). If getopt() and friends detect a missing argument and shortopts/optstring does not start with a colon, the function returns a question mark (`?'). If it was a missing argument to a short option, optopt is set to the character in question. The colon goes after the ordering character (`+' or `-'). COPYRIGHT NOTICE AND DISCLAIMER: Copyright (C) 1997 Gregory Pietsch This file and the accompanying getopt.h header file are hereby placed in the public domain without restrictions. Just give the author credit, don't claim you wrote it or prevent anyone else from using it. Gregory Pietsch's current e-mail address: gpietsch@comcast.net ****************************************************************************/ #ifndef HAVE_GETOPT /* include files */ #include #include #include #define __need_getopt_newlib #include /* macros */ /* types */ typedef enum GETOPT_ORDERING_T { PERMUTE, RETURN_IN_ORDER, REQUIRE_ORDER } GETOPT_ORDERING_T; /* globally-defined variables */ char *optarg = 0; int optind = 0; int opterr = 1; int optopt = '?'; /* static variables */ static int optwhere = 0; static int permute_from = 0; static int num_nonopts = 0; /* functions */ /* reverse_argv_elements: reverses num elements starting at argv */ static void reverse_argv_elements(char **argv, int num) { int i; char *tmp; for (i = 0; i < (num >> 1); i++) { tmp = argv[i]; argv[i] = argv[num - i - 1]; argv[num - i - 1] = tmp; } } /* permute: swap two blocks of argv-elements given their lengths */ static void permute(char * const argv[], int len1, int len2) { reverse_argv_elements((char **)argv, len1); reverse_argv_elements((char **)argv, len1 + len2); reverse_argv_elements((char **)argv, len2); } /* is_option: is this argv-element an option or the end of the option list? */ static int is_option(char *argv_element, int only) { return ((argv_element == 0) || (argv_element[0] == '-') || (only && argv_element[0] == '+')); } /* read_globals: read the values from the globals into a getopt_data structure */ static void read_globals(struct getopt_data *data) { data->optarg = optarg; data->optind = optind; data->opterr = opterr; data->optopt = optopt; data->optwhere = optwhere; data->permute_from = permute_from; data->num_nonopts = num_nonopts; } /* write_globals: write the values into the globals from a getopt_data structure */ static void write_globals(struct getopt_data *data) { optarg = data->optarg; optind = data->optind; opterr = data->opterr; optopt = data->optopt; optwhere = data->optwhere; permute_from = data->permute_from; num_nonopts = data->num_nonopts; } /* getopt_internal: the function that does all the dirty work NOTE: to reduce the code and RAM footprint this function uses fputs()/fputc() to do output to stderr instead of fprintf(). */ static int getopt_internal(int argc, char * const argv[], const char *shortopts, const struct option *longopts, int *longind, int only, struct getopt_data *data) { GETOPT_ORDERING_T ordering = PERMUTE; int optindex = 0; size_t match_chars = 0; char *possible_arg = 0; int longopt_match = -1; int has_arg = -1; char *cp = 0; int arg_next = 0; int initial_colon = 0; /* if this is our first time through */ if (data->optind <= 0) { data->optind = 1; data->optwhere = 1; data->permute_from = 0; data->num_nonopts = 0; } /* first, deal with silly parameters and easy stuff */ if (argc == 0 || argv == 0 || (shortopts == 0 && longopts == 0) || data->optind >= argc || argv[data->optind] == 0) return EOF; if (strcmp(argv[data->optind], "--") == 0) { data->optind++; return EOF; } /* define ordering */ if (shortopts != 0 && (*shortopts == '-' || *shortopts == '+')) { ordering = (*shortopts == '-') ? RETURN_IN_ORDER : REQUIRE_ORDER; shortopts++; } else ordering = (getenv("POSIXLY_CORRECT") != 0) ? REQUIRE_ORDER : PERMUTE; /* check for initial colon in shortopts */ if (shortopts != 0 && *shortopts == ':') { ++shortopts; initial_colon = 1; } /* * based on ordering, find our next option, if we're at the beginning of * one */ if (data->optwhere == 1) { switch (ordering) { default: /* shouldn't happen */ case PERMUTE: data->permute_from = data->optind; data->num_nonopts = 0; while (data->optind < argc && !is_option(argv[data->optind], only)) { data->optind++; data->num_nonopts++; } if (data->optind >= argc || argv[data->optind] == 0) { /* no more options */ data->optind = data->permute_from; return EOF; } else if (strcmp(argv[data->optind], "--") == 0) { /* no more options, but have to get `--' out of the way */ permute(argv + data->permute_from, data->num_nonopts, 1); data->optind = data->permute_from + 1; return EOF; } break; case RETURN_IN_ORDER: if (!is_option(argv[data->optind], only)) { data->optarg = argv[data->optind++]; return (data->optopt = 1); } break; case REQUIRE_ORDER: if (!is_option(argv[data->optind], only)) return EOF; break; } } /* End of option list? */ if (data->optind >= argc || argv[data->optind] == 0) return EOF; /* we've got an option, so parse it */ /* first, is it a long option? */ if (longopts != 0 && (memcmp(argv[data->optind], "--", 2) == 0 || (only && argv[data->optind][0] == '-')) && data->optwhere == 1) { /* handle long options */ if (memcmp(argv[data->optind], "--", 2) == 0) data->optwhere = 2; longopt_match = -1; possible_arg = strchr(argv[data->optind] + data->optwhere, '='); if (possible_arg == 0) { /* no =, so next argv might be arg */ match_chars = strlen(argv[data->optind]); possible_arg = argv[data->optind] + match_chars; match_chars = match_chars - data->optwhere; } else match_chars = (possible_arg - argv[data->optind]) - data->optwhere; for (optindex = 0; longopts[optindex].name != 0; ++optindex) { if (memcmp(argv[data->optind] + data->optwhere, longopts[optindex].name, match_chars) == 0) { /* do we have an exact match? */ if (match_chars == strlen(longopts[optindex].name)) { longopt_match = optindex; break; } /* do any characters match? */ else { if (longopt_match < 0) longopt_match = optindex; else { /* we have ambiguous options */ if (data->opterr) { fputs(argv[0], stderr); fputs(": option `", stderr); fputs(argv[data->optind], stderr); fputs("' is ambiguous (could be `--", stderr); fputs(longopts[longopt_match].name, stderr); fputs("' or `--", stderr); fputs(longopts[optindex].name, stderr); fputs("')\n", stderr); } return (data->optopt = '?'); } } } } if (longopt_match >= 0) has_arg = longopts[longopt_match].has_arg; } /* if we didn't find a long option, is it a short option? */ if (longopt_match < 0 && shortopts != 0) { cp = strchr(shortopts, argv[data->optind][data->optwhere]); if (cp == 0) { /* couldn't find option in shortopts */ if (data->opterr) { fputs(argv[0], stderr); fputs(": invalid option -- `-", stderr); fputc(argv[data->optind][data->optwhere], stderr); fputs("'\n", stderr); } data->optwhere++; if (argv[data->optind][data->optwhere] == '\0') { data->optind++; data->optwhere = 1; } return (data->optopt = '?'); } has_arg = ((cp[1] == ':') ? ((cp[2] == ':') ? OPTIONAL_ARG : REQUIRED_ARG) : NO_ARG); possible_arg = argv[data->optind] + data->optwhere + 1; data->optopt = *cp; } /* get argument and reset data->optwhere */ arg_next = 0; switch (has_arg) { case OPTIONAL_ARG: if (*possible_arg == '=') possible_arg++; data->optarg = (*possible_arg != '\0') ? possible_arg : 0; data->optwhere = 1; break; case REQUIRED_ARG: if (*possible_arg == '=') possible_arg++; if (*possible_arg != '\0') { data->optarg = possible_arg; data->optwhere = 1; } else if (data->optind + 1 >= argc) { if (data->opterr) { fputs(argv[0], stderr); fputs(": argument required for option `-", stderr); if (longopt_match >= 0) { fputc('-', stderr); fputs(longopts[longopt_match].name, stderr); data->optopt = initial_colon ? ':' : '\?'; } else { fputc(*cp, stderr); data->optopt = *cp; } fputs("'\n", stderr); } data->optind++; return initial_colon ? ':' : '\?'; } else { data->optarg = argv[data->optind + 1]; arg_next = 1; data->optwhere = 1; } break; default: /* shouldn't happen */ case NO_ARG: if (longopt_match < 0) { data->optwhere++; if (argv[data->optind][data->optwhere] == '\0') data->optwhere = 1; } else data->optwhere = 1; data->optarg = 0; break; } /* do we have to permute or otherwise modify data->optind? */ if (ordering == PERMUTE && data->optwhere == 1 && data->num_nonopts != 0) { permute(argv + data->permute_from, data->num_nonopts, 1 + arg_next); data->optind = data->permute_from + 1 + arg_next; } else if (data->optwhere == 1) data->optind = data->optind + 1 + arg_next; /* finally return */ if (longopt_match >= 0) { if (longind != 0) *longind = longopt_match; if (longopts[longopt_match].flag != 0) { *(longopts[longopt_match].flag) = longopts[longopt_match].val; return 0; } else return longopts[longopt_match].val; } else return data->optopt; } int getopt(int argc, char * const argv[], const char *optstring) { struct getopt_data data; int r; read_globals(&data); r = getopt_internal(argc, argv, optstring, 0, 0, 0, &data); write_globals(&data); return r; } int getopt_long(int argc, char * const argv[], const char *shortopts, const struct option *longopts, int *longind) { struct getopt_data data; int r; read_globals(&data); r = getopt_internal(argc, argv, shortopts, longopts, longind, 0, &data); write_globals(&data); return r; } int getopt_long_only(int argc, char * const argv[], const char *shortopts, const struct option *longopts, int *longind) { struct getopt_data data; int r; read_globals(&data); r = getopt_internal(argc, argv, shortopts, longopts, longind, 1, &data); write_globals(&data); return r; } int __getopt_r(int argc, char * const argv[], const char *optstring, struct getopt_data *data) { return getopt_internal(argc, argv, optstring, 0, 0, 0, data); } int __getopt_long_r(int argc, char * const argv[], const char *shortopts, const struct option *longopts, int *longind, struct getopt_data *data) { return getopt_internal(argc, argv, shortopts, longopts, longind, 0, data); } int __getopt_long_only_r(int argc, char * const argv[], const char *shortopts, const struct option *longopts, int *longind, struct getopt_data *data) { return getopt_internal(argc, argv, shortopts, longopts, longind, 1, data); } #endif /* !HAVE_GETOPT */ /* end of file GETOPT.C */ picolibc-1.8.11/libc/stdlib/getpagesize.c000066400000000000000000000030221513574234600202420ustar00rootroot00000000000000/* * Copyright (c) 2012, 2013 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "local-malloc.h" int getpagesize(void) { return MALLOC_PAGE_ALIGN; } picolibc-1.8.11/libc/stdlib/getsubopt.3000066400000000000000000000100521513574234600176700ustar00rootroot00000000000000.\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)getsubopt.3 8.1 (Berkeley) 6/9/93 .\" $FreeBSD: src/lib/libc/stdlib/getsubopt.3,v 1.9 2001/09/07 14:46:35 asmodai Exp $ .\" .Dd June 9, 1993 .Dt GETSUBOPT 3 .Os .Sh NAME .Nm getsubopt .Nd get sub options from an argument .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In unistd.h .Vt extern char *suboptarg ; .Ft int .Fn getsubopt "char **optionp" "char * const *tokens" "char **valuep" .Sh DESCRIPTION The .Fn getsubopt function parses a string containing tokens delimited by one or more tab, space or comma .Pq Ql \&, characters. It is intended for use in parsing groups of option arguments provided as part of a utility command line. .Pp The argument .Fa optionp is a pointer to a pointer to the string. The argument .Fa tokens is a pointer to a .Dv NULL Ns -terminated array of pointers to strings. .Pp The .Fn getsubopt function returns the zero-based offset of the pointer in the .Fa tokens array referencing a string which matches the first token in the string, or, \-1 if the string contains no tokens or .Fa tokens does not contain a matching string. .Pp If the token is of the form ``name=value'', the location referenced by .Fa valuep will be set to point to the start of the ``value'' portion of the token. .Pp On return from .Fn getsubopt , .Fa optionp will be set to point to the start of the next token in the string, or the null at the end of the string if no more tokens are present. The external variable .Fa suboptarg will be set to point to the start of the current token, or .Dv NULL if no tokens were present. The argument .Fa valuep will be set to point to the ``value'' portion of the token, or .Dv NULL if no ``value'' portion was present. .Sh EXAMPLES .Bd -literal -compact char *tokens[] = { #define ONE 0 "one", #define TWO 1 "two", NULL }; \&... extern char *optarg, *suboptarg; char *options, *value; while ((ch = getopt(argc, argv, "ab:")) != \-1) { switch(ch) { case 'a': /* process ``a'' option */ break; case 'b': options = optarg; while (*options) { switch(getsubopt(&options, tokens, &value)) { case ONE: /* process ``one'' sub option */ break; case TWO: /* process ``two'' sub option */ if (!value) error("no value for two"); i = atoi(value); break; case \-1: if (suboptarg) error("illegal sub option %s", suboptarg); else error("missing sub option"); break; } break; } .Ed .Sh SEE ALSO .Xr getopt 3 , .Xr strsep 3 .Sh HISTORY The .Fn getsubopt function first appeared in .Bx 4.4 . picolibc-1.8.11/libc/stdlib/getsubopt.c000066400000000000000000000062561513574234600177630ustar00rootroot00000000000000/*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include #include #include /* * The SVID interface to getsubopt provides no way of figuring out which * part of the suboptions list wasn't matched. This makes error messages * tricky... The extern variable suboptarg is a pointer to the token * which didn't match. */ char *suboptarg; int getsubopt(char **optionp, char * const *tokens, char **valuep) { int cnt; char *p; suboptarg = *valuep = NULL; if (!optionp || !*optionp) return (-1); /* skip leading white-space, commas */ for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p) ; if (!*p) { *optionp = p; return (-1); } /* save the start of the token, and skip the rest of the token. */ for (suboptarg = p; *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';) ; if (*p) { /* * If there's an equals sign, set the value pointer, and * skip over the value part of the token. Terminate the * token. */ if (*p == '=') { *p = '\0'; for (*valuep = ++p; *p && *p != ',' && *p != ' ' && *p != '\t'; ++p) ; if (*p) *p++ = '\0'; } else *p++ = '\0'; /* Skip any whitespace or commas after this token. */ for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p) ; } /* set optionp for next round. */ *optionp = p; for (cnt = 0; *tokens; ++tokens, ++cnt) if (!strcmp(suboptarg, *tokens)) return (cnt); return (-1); } picolibc-1.8.11/libc/stdlib/ignore_handler_s.c000066400000000000000000000034371513574234600212470ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define __STDC_WANT_LIB_EXT1__ 1 #include void ignore_handler_s(const char * __restrict msg, void * __restrict ptr, __errno_t error) { (void)msg; (void)ptr; (void)error; return; }picolibc-1.8.11/libc/stdlib/imaxabs.c000066400000000000000000000027071513574234600173700ustar00rootroot00000000000000/*- * Copyright (c) 2001 Mike Barcroft * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include intmax_t imaxabs(intmax_t j) { return (j < 0 ? -j : j); } picolibc-1.8.11/libc/stdlib/imaxdiv.c000066400000000000000000000034151513574234600174020ustar00rootroot00000000000000/*- * Copyright (c) 2001 Mike Barcroft * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include /* See comments in div.c for implementation details. */ imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom) { imaxdiv_t retval; retval.quot = numer / denom; retval.rem = numer % denom; #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) if (numer >= 0 && retval.rem < 0) { retval.quot++; retval.rem -= denom; } #endif return (retval); } picolibc-1.8.11/libc/stdlib/itoa.c000066400000000000000000000030251513574234600166720ustar00rootroot00000000000000/* Copyright (c) 2014 Corinna Vinschen */ /* FUNCTION <>---integer to string INDEX itoa SYNOPSIS #include char *itoa(int <[value]>, char *<[str]>, int <[base]>); char *__itoa(int <[value]>, char *<[str]>, int <[base]>); DESCRIPTION <> converts the integer <[value]> to a null-terminated string using the specified base, which must be between 2 and 36, inclusive. If <[base]> is 10, <[value]> is treated as signed and the string will be prefixed with '-' if negative. For all other bases, <[value]> is treated as unsigned. <[str]> should be an array long enough to contain the converted value, which in the worst case is sizeof(int)*8+1 bytes. RETURNS A pointer to the string, <[str]>, or NULL if <[base]> is invalid. PORTABILITY <> is non-ANSI. No supporting OS subroutine calls are required. */ #define _DEFAULT_SOURCE #include char * __itoa(int value, char *str, int base) { unsigned uvalue; int i = 0; /* Check base is supported. */ if ((base < 2) || (base > 36)) { str[0] = '\0'; return NULL; } /* Negative numbers are only supported for decimal. * Cast to unsigned to avoid overflow for maximum negative value. */ if ((base == 10) && (value < 0)) { str[i++] = '-'; uvalue = (unsigned)-value; } else uvalue = (unsigned)value; __utoa(uvalue, &str[i], base); return str; } char * itoa(int value, char *str, int base) { return __itoa(value, str, base); } picolibc-1.8.11/libc/stdlib/jis.h000066400000000000000000000037531513574234600165400ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _JIS_H_ #define _JIS_H_ #include "jis_charsets.h" #define INVALID_JIS __euc_jp_invalid_jis uint32_t __unicode_to_euc_jp(wchar_t unicode); wint_t __euc_jp_to_unicode(uint32_t euc_jp); uint16_t __unicode_to_shift_jis(wchar_t unicode); wint_t __shift_jis_to_unicode(uint16_t shift_jis); uint16_t __unicode_to_jis(wchar_t unicode); wint_t __jis_to_unicode(uint16_t jis); #endif /* _JIS_H_ */ picolibc-1.8.11/libc/stdlib/jis_charsets.h000066400000000000000000011741511513574234600204360ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This file is auto-generated from mk-jis-charsets.py */ /* clang-format off */ #ifndef _JIS_CHARSETS_H_ #define _JIS_CHARSETS_H_ struct jis_charmap { uint8_t first; uint8_t last; uint16_t offset; }; #define __euc_jp_invalid_jis 0xffff #define __euc_jp_invalid_unicode 0xffff #define __euc_jp_split_codes 0x4000 /* unicode tables */ #ifdef define_unicode #define __euc_jp_unicode_first_row 0x00 #define __euc_jp_unicode_last_row 0x9f #ifndef split_unicode #define split_unicode_offset 0 #endif static const uint16_t __euc_jp_unicode_codes[] = { /* 0x00: 0xa1 - 0xff */ 0x22c2, 0xa1f1, 0xa1f2, 0x22f0, 0x005c, 0x22c3, 0xa1f8, 0xa1af, 0x22ed, 0x22ec, 0xffff, 0xa2cc, 0xffff, 0x22ee, 0x22b4, 0xa1eb, 0xa1de, 0xffff, 0xffff, 0xa1ad, 0xffff, 0xa2f9, 0xffff, 0x22b1, 0xffff, 0x22eb, 0xffff, 0xffff, 0xffff, 0xffff, 0x22c4, 0x2aa2, 0x2aa1, 0x2aa4, 0x2aaa, 0x2aa3, 0x2aa9, 0x29a1, 0x2aae, 0x2ab2, 0x2ab1, 0x2ab4, 0x2ab3, 0x2ac0, 0x2abf, 0x2ac2, 0x2ac1, 0xffff, 0x2ad0, 0x2ad2, 0x2ad1, 0x2ad4, 0x2ad8, 0x2ad3, 0xa1df, 0x29ac, 0x2ae3, 0x2ae2, 0x2ae5, 0x2ae4, 0x2af2, 0x29b0, 0x29ce, 0x2ba2, 0x2ba1, 0x2ba4, 0x2baa, 0x2ba3, 0x2ba9, 0x29c1, 0x2bae, 0x2bb2, 0x2bb1, 0x2bb4, 0x2bb3, 0x2bc0, 0x2bbf, 0x2bc2, 0x2bc1, 0x29c3, 0x2bd0, 0x2bd2, 0x2bd1, 0x2bd4, 0x2bd8, 0x2bd3, 0xa1e0, 0x29cc, 0x2be3, 0x2be2, 0x2be5, 0x2be4, 0x2bf2, 0x29d0, 0x2bf3, /* 0x01: 0x00 - 0xf5 */ 0x2aa7, 0x2ba7, 0x2aa5, 0x2ba5, 0x2aa8, 0x2ba8, 0x2aab, 0x2bab, 0x2aac, 0x2bac, 0x2aaf, 0x2baf, 0x2aad, 0x2bad, 0x2ab0, 0x2bb0, 0x29a2, 0x29c2, 0x2ab7, 0x2bb7, 0xffff, 0xffff, 0x2ab6, 0x2bb6, 0x2ab8, 0x2bb8, 0x2ab5, 0x2bb5, 0x2aba, 0x2bba, 0x2abb, 0x2bbb, 0x2abd, 0x2bbd, 0x2abc, 0xffff, 0x2abe, 0x2bbe, 0x29a4, 0x29c4, 0x2ac7, 0x2bc7, 0x2ac5, 0x2bc5, 0xffff, 0xffff, 0x2ac6, 0x2bc6, 0x2ac4, 0x29c5, 0x29a6, 0x29c6, 0x2ac8, 0x2bc8, 0x2ac9, 0x2bc9, 0x29c7, 0x2aca, 0x2bca, 0x2acc, 0x2bcc, 0x2acb, 0x2bcb, 0x29a9, 0x29c9, 0x29a8, 0x29c8, 0x2acd, 0x2bcd, 0x2acf, 0x2bcf, 0x2ace, 0x2bce, 0x29ca, 0x29ab, 0x29cb, 0x2ad7, 0x2bd7, 0xffff, 0xffff, 0x2ad6, 0x2bd6, 0x29ad, 0x29cd, 0x2ad9, 0x2bd9, 0x2adb, 0x2bdb, 0x2ada, 0x2bda, 0x2adc, 0x2bdc, 0x2add, 0x2bdd, 0x2adf, 0x2bdf, 0x2ade, 0x2bde, 0x2ae1, 0x2be1, 0x2ae0, 0x2be0, 0x29af, 0x29cf, 0x2aec, 0x2bec, 0x2ae9, 0x2be9, 0x2ae6, 0x2be6, 0x2aeb, 0x2beb, 0x2ae8, 0x2be8, 0x2aea, 0x2bea, 0x2af1, 0x2bf1, 0x2af4, 0x2bf4, 0x2af3, 0x2af5, 0x2bf5, 0x2af7, 0x2bf7, 0x2af6, 0x2bf6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x2aa6, 0x2ba6, 0x2ac3, 0x2bc3, 0x2ad5, 0x2bd5, 0x2ae7, 0x2be7, 0x2af0, 0x2bf0, 0x2aed, 0x2bed, 0x2aef, 0x2bef, 0x2aee, 0x2bee, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x2bb9, /* 0x02: 0xc7 - 0xdd */ 0x22b0, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x22af, 0x22b2, 0x22b6, 0x22b5, 0xffff, 0x22b3, /* 0x03: 0x84 - 0xce */ 0x22b8, 0x22b9, 0x26e1, 0xffff, 0x26e2, 0x26e3, 0x26e4, 0xffff, 0x26e7, 0xffff, 0x26e9, 0x26ec, 0x26f6, 0xa6a1, 0xa6a2, 0xa6a3, 0xa6a4, 0xa6a5, 0xa6a6, 0xa6a7, 0xa6a8, 0xa6a9, 0xa6aa, 0xa6ab, 0xa6ac, 0xa6ad, 0xa6ae, 0xa6af, 0xa6b0, 0xa6b1, 0xffff, 0xa6b2, 0xa6b3, 0xa6b4, 0xa6b5, 0xa6b6, 0xa6b7, 0xa6b8, 0x26e5, 0x26ea, 0x26f1, 0x26f2, 0x26f3, 0x26f4, 0x26fb, 0xa6c1, 0xa6c2, 0xa6c3, 0xa6c4, 0xa6c5, 0xa6c6, 0xa6c7, 0xa6c8, 0xa6c9, 0xa6ca, 0xa6cb, 0xa6cc, 0xa6cd, 0xa6ce, 0xa6cf, 0xa6d0, 0xa6d1, 0x26f8, 0xa6d2, 0xa6d3, 0xa6d4, 0xa6d5, 0xa6d6, 0xa6d7, 0xa6d8, 0x26f5, 0x26fa, 0x26f7, 0x26f9, 0x26fc, /* 0x04: 0x01 - 0x5f */ 0xa7a7, 0x27c2, 0x27c3, 0x27c4, 0x27c5, 0x27c6, 0x27c7, 0x27c8, 0x27c9, 0x27ca, 0x27cb, 0x27cc, 0xffff, 0x27cd, 0x27ce, 0xa7a1, 0xa7a2, 0xa7a3, 0xa7a4, 0xa7a5, 0xa7a6, 0xa7a8, 0xa7a9, 0xa7aa, 0xa7ab, 0xa7ac, 0xa7ad, 0xa7ae, 0xa7af, 0xa7b0, 0xa7b1, 0xa7b2, 0xa7b3, 0xa7b4, 0xa7b5, 0xa7b6, 0xa7b7, 0xa7b8, 0xa7b9, 0xa7ba, 0xa7bb, 0xa7bc, 0xa7bd, 0xa7be, 0xa7bf, 0xa7c0, 0xa7c1, 0xa7d1, 0xa7d2, 0xa7d3, 0xa7d4, 0xa7d5, 0xa7d6, 0xa7d8, 0xa7d9, 0xa7da, 0xa7db, 0xa7dc, 0xa7dd, 0xa7de, 0xa7df, 0xa7e0, 0xa7e1, 0xa7e2, 0xa7e3, 0xa7e4, 0xa7e5, 0xa7e6, 0xa7e7, 0xa7e8, 0xa7e9, 0xa7ea, 0xa7eb, 0xa7ec, 0xa7ed, 0xa7ee, 0xa7ef, 0xa7f0, 0xa7f1, 0xffff, 0xa7d7, 0x27f2, 0x27f3, 0x27f4, 0x27f5, 0x27f6, 0x27f7, 0x27f8, 0x27f9, 0x27fa, 0x27fb, 0x27fc, 0xffff, 0x27fd, 0x27fe, /* 0x20: 0x10 - 0x3e */ 0xa1be, 0xffff, 0xffff, 0xffff, 0xffff, 0xa1bd, 0xa1c2, 0xffff, 0xa1c6, 0xa1c7, 0xffff, 0xffff, 0xa1c8, 0xa1c9, 0xffff, 0xffff, 0xa2f7, 0xa2f8, 0xffff, 0xffff, 0xffff, 0xa1c5, 0xa1c4, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2f3, 0xffff, 0xa1ec, 0xa1ed, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2a8, 0xffff, 0xffff, 0x007e, /* 0x21: 0x03 - 0xd4 */ 0xa1ee, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x22f1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x22ef, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2f2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2ab, 0xa2ac, 0xa2aa, 0xa2ad, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2cd, 0xffff, 0xa2ce, /* 0x22: 0x00 - 0xa5 */ 0xa2cf, 0xffff, 0xa2df, 0xa2d0, 0xffff, 0xffff, 0xffff, 0xa2e0, 0xa2ba, 0xffff, 0xffff, 0xa2bb, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa1dd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2e5, 0xffff, 0xffff, 0xa2e7, 0xa1e7, 0xffff, 0xa2dc, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2ca, 0xa2cb, 0xa2c1, 0xa2c0, 0xa2e9, 0xa2ea, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa1e8, 0xa2e8, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2e6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2e2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa1e2, 0xa2e1, 0xffff, 0xffff, 0xffff, 0xffff, 0xa1e5, 0xa1e6, 0xffff, 0xffff, 0xa2e3, 0xa2e4, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2be, 0xa2bf, 0xffff, 0xffff, 0xa2bc, 0xa2bd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2dd, /* 0x23: 0x12 - 0x12 */ 0xa2de, /* 0x25: 0x00 - 0xef */ 0xa8a1, 0xa8ac, 0xa8a2, 0xa8ad, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa8a3, 0xffff, 0xffff, 0xa8ae, 0xa8a4, 0xffff, 0xffff, 0xa8af, 0xa8a6, 0xffff, 0xffff, 0xa8b1, 0xa8a5, 0xffff, 0xffff, 0xa8b0, 0xa8a7, 0xa8bc, 0xffff, 0xffff, 0xa8b7, 0xffff, 0xffff, 0xa8b2, 0xa8a9, 0xa8be, 0xffff, 0xffff, 0xa8b9, 0xffff, 0xffff, 0xa8b4, 0xa8a8, 0xffff, 0xffff, 0xa8b8, 0xa8bd, 0xffff, 0xffff, 0xa8b3, 0xa8aa, 0xffff, 0xffff, 0xa8ba, 0xa8bf, 0xffff, 0xffff, 0xa8b5, 0xa8ab, 0xffff, 0xffff, 0xa8bb, 0xffff, 0xffff, 0xa8c0, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa8b6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2a3, 0xa2a2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2a5, 0xa2a4, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2a7, 0xa2a6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2a1, 0xa1fe, 0xffff, 0xffff, 0xffff, 0xa1fb, 0xffff, 0xffff, 0xa1fd, 0xa1fc, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2fe, /* 0x26: 0x05 - 0x6f */ 0xa1fa, 0xa1f9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa1ea, 0xffff, 0xa1e9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa2f6, 0xffff, 0xffff, 0xa2f5, 0xffff, 0xa2f4, /* 0x30: 0x00 - 0xfe */ 0xa1a1, 0xa1a2, 0xa1a3, 0xa1b7, 0xffff, 0xa1b9, 0xa1ba, 0xa1bb, 0xa1d2, 0xa1d3, 0xa1d4, 0xa1d5, 0xa1d6, 0xa1d7, 0xa1d8, 0xa1d9, 0xa1da, 0xa1db, 0xa2a9, 0xa2ae, 0xa1cc, 0xa1cd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa1c1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa4a1, 0xa4a2, 0xa4a3, 0xa4a4, 0xa4a5, 0xa4a6, 0xa4a7, 0xa4a8, 0xa4a9, 0xa4aa, 0xa4ab, 0xa4ac, 0xa4ad, 0xa4ae, 0xa4af, 0xa4b0, 0xa4b1, 0xa4b2, 0xa4b3, 0xa4b4, 0xa4b5, 0xa4b6, 0xa4b7, 0xa4b8, 0xa4b9, 0xa4ba, 0xa4bb, 0xa4bc, 0xa4bd, 0xa4be, 0xa4bf, 0xa4c0, 0xa4c1, 0xa4c2, 0xa4c3, 0xa4c4, 0xa4c5, 0xa4c6, 0xa4c7, 0xa4c8, 0xa4c9, 0xa4ca, 0xa4cb, 0xa4cc, 0xa4cd, 0xa4ce, 0xa4cf, 0xa4d0, 0xa4d1, 0xa4d2, 0xa4d3, 0xa4d4, 0xa4d5, 0xa4d6, 0xa4d7, 0xa4d8, 0xa4d9, 0xa4da, 0xa4db, 0xa4dc, 0xa4dd, 0xa4de, 0xa4df, 0xa4e0, 0xa4e1, 0xa4e2, 0xa4e3, 0xa4e4, 0xa4e5, 0xa4e6, 0xa4e7, 0xa4e8, 0xa4e9, 0xa4ea, 0xa4eb, 0xa4ec, 0xa4ed, 0xa4ee, 0xa4ef, 0xa4f0, 0xa4f1, 0xa4f2, 0xa4f3, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa1ab, 0xa1ac, 0xa1b5, 0xa1b6, 0xffff, 0xffff, 0xa5a1, 0xa5a2, 0xa5a3, 0xa5a4, 0xa5a5, 0xa5a6, 0xa5a7, 0xa5a8, 0xa5a9, 0xa5aa, 0xa5ab, 0xa5ac, 0xa5ad, 0xa5ae, 0xa5af, 0xa5b0, 0xa5b1, 0xa5b2, 0xa5b3, 0xa5b4, 0xa5b5, 0xa5b6, 0xa5b7, 0xa5b8, 0xa5b9, 0xa5ba, 0xa5bb, 0xa5bc, 0xa5bd, 0xa5be, 0xa5bf, 0xa5c0, 0xa5c1, 0xa5c2, 0xa5c3, 0xa5c4, 0xa5c5, 0xa5c6, 0xa5c7, 0xa5c8, 0xa5c9, 0xa5ca, 0xa5cb, 0xa5cc, 0xa5cd, 0xa5ce, 0xa5cf, 0xa5d0, 0xa5d1, 0xa5d2, 0xa5d3, 0xa5d4, 0xa5d5, 0xa5d6, 0xa5d7, 0xa5d8, 0xa5d9, 0xa5da, 0xa5db, 0xa5dc, 0xa5dd, 0xa5de, 0xa5df, 0xa5e0, 0xa5e1, 0xa5e2, 0xa5e3, 0xa5e4, 0xa5e5, 0xa5e6, 0xa5e7, 0xa5e8, 0xa5e9, 0xa5ea, 0xa5eb, 0xa5ec, 0xa5ed, 0xa5ee, 0xa5ef, 0xa5f0, 0xa5f1, 0xa5f2, 0xa5f3, 0xa5f4, 0xa5f5, 0xa5f6, 0xffff, 0xffff, 0xffff, 0xffff, 0xa1a6, 0xa1bc, 0xa1b3, 0xa1b4, /* 0x4e: 0x00 - 0xff */ 0xb0ec, 0xc3fa, 0x30a1, 0xbcb7, 0x30a2, 0x30a3, 0xffff, 0xcbfc, 0xbee6, 0xbbb0, 0xbee5, 0xb2bc, 0x30a4, 0xc9d4, 0xcdbf, 0xffff, 0xd0a2, 0xb1af, 0x30a5, 0xffff, 0xb3ee, 0xd0a3, 0xc0a4, 0xd2c2, 0xb5d6, 0xcaba, 0xffff, 0xffff, 0xffff, 0xffff, 0xbee7, 0x30a6, 0xffff, 0xcebe, 0xffff, 0x30a7, 0x30a8, 0xffff, 0xcac2, 0xffff, 0x30a9, 0xffff, 0xd0a4, 0x30aa, 0xffff, 0xc3e6, 0x30ab, 0x30ac, 0x30ad, 0xd0a5, 0xb6fa, 0xffff, 0xffff, 0x30ae, 0xd0a6, 0xffff, 0xb4dd, 0xc3b0, 0xffff, 0xbce7, 0xd0a7, 0xffff, 0xffff, 0xd0a8, 0x30af, 0x30b0, 0xd0a9, 0xc7b5, 0x30b1, 0xb5d7, 0xffff, 0x30b2, 0xffff, 0xffff, 0xffff, 0xc7b7, 0xffff, 0xc6e3, 0xb8c3, 0xcbb3, 0xffff, 0x30b3, 0xffff, 0xffff, 0xffff, 0xe9c9, 0xd0aa, 0xbee8, 0xd0ab, 0xb2b5, 0x30b4, 0xffff, 0x30b5, 0xb6e5, 0xb8f0, 0xcce9, 0xffff, 0xffff, 0xd6a6, 0x30b6, 0xffff, 0xffff, 0xffff, 0xffff, 0x30b7, 0x30b8, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xcdf0, 0xffff, 0xc6fd, 0x30b9, 0x30ba, 0xffff, 0xffff, 0xffff, 0x30bb, 0xffff, 0xffff, 0xffff, 0xffff, 0xb4a5, 0x30bc, 0xb5b5, 0xffff, 0xd0ac, 0xffff, 0xffff, 0xd0ad, 0xcebb, 0xffff, 0xcdbd, 0xc1e8, 0xd0af, 0xbbf6, 0xc6f3, 0x30bd, 0xd0b2, 0xffff, 0xffff, 0xb1be, 0xb8df, 0xffff, 0xb8de, 0xb0e6, 0x30be, 0x30bf, 0xcfcb, 0xcfca, 0xffff, 0xbab3, 0xb0a1, 0x30c0, 0xd0b3, 0xd0b4, 0xd0b5, 0xcbb4, 0xd0b6, 0xffff, 0xb8f2, 0xb0e7, 0xcbf2, 0xffff, 0xb5fc, 0xffff, 0xffff, 0xb5fd, 0xb5fe, 0xc4e2, 0xcebc, 0x30c1, 0xd0b7, 0xffff, 0xffff, 0xd0b8, 0xffff, 0xffff, 0xd0b9, 0xffff, 0xffff, 0x30c2, 0xbfcd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xbdba, 0xbfce, 0xd0be, 0x30c3, 0xd0bc, 0xffff, 0xd0bd, 0xb5d8, 0xffff, 0xffff, 0xbaa3, 0xb2f0, 0xffff, 0xd0bb, 0xd0ba, 0xcaa9, 0x30c4, 0xffff, 0xffff, 0xffff, 0xbbc6, 0xbbc5, 0xc2be, 0xd0bf, 0xc9d5, 0xc0e7, 0x30c5, 0x30c6, 0xffff, 0xa1b8, 0xd0c0, 0xd0c2, 0x30c7, 0x30c8, 0x30c9, 0xc2e5, 0xcee1, 0xb0ca, 0xffff, 0xffff, 0x30ca, 0xffff, 0xffff, 0xffff, 0xffff, 0xd0c1, 0xb2be, 0x30cb, 0xb6c4, 0x30cc, 0xc3e7, 0x30cd, 0xffff, 0x30ce, 0xb7ef, 0xd0c3, 0xffff, 0xffff, 0xffff, 0xc7a4, 0xffff, 0x30cf, 0x30d0, 0x30d1, /* 0x4f: 0x00 - 0xff */ 0x30d2, 0xb4eb, 0x30d3, 0x30d4, 0xffff, 0xffff, 0xffff, 0xffff, 0x30d5, 0xd0c4, 0xb0cb, 0x30d6, 0x30d7, 0xb8e0, 0xb4ec, 0xc9fa, 0xc8b2, 0xb5d9, 0x30d8, 0xffff, 0xffff, 0x30d9, 0x30da, 0x30db, 0xffff, 0x30dc, 0xb2f1, 0xffff, 0xd0e7, 0xc5c1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x30dd, 0xc7ec, 0xd0c6, 0x30de, 0xffff, 0x30e0, 0xc8bc, 0x30e1, 0xcee2, 0x30e2, 0xbfad, 0x30e3, 0xbbc7, 0x30e4, 0xbbf7, 0xb2c0, 0x30e5, 0xffff, 0x30e6, 0xffff, 0x30e7, 0xc4d1, 0xffff, 0xffff, 0xc3a2, 0xd0ca, 0x30e8, 0x30e9, 0xffff, 0x30ea, 0x30eb, 0xb0cc, 0xc4e3, 0xbdbb, 0xbab4, 0xcda4, 0x30ec, 0xc2ce, 0x30ed, 0xb2bf, 0x30ee, 0xd0c9, 0x30ef, 0xcdbe, 0xd0c5, 0xd0c7, 0xbaee, 0xd0c8, 0xd5a4, 0x30f0, 0x30df, 0xffff, 0xffff, 0x30f1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xd0d0, 0x30f2, 0xffff, 0x30f3, 0xffff, 0x30f4, 0xd0d3, 0xd0d1, 0x30f5, 0xffff, 0xb2c2, 0xffff, 0xcabb, 0xd0cb, 0x30f6, 0x30f7, 0x30f8, 0x30f9, 0xd0cf, 0xb8f3, 0x30fa, 0x30fb, 0xbbc8, 0xffff, 0x30fc, 0x30fd, 0xb4a6, 0x30fe, 0x31a1, 0xd0d4, 0xffff, 0xd0cc, 0x31a2, 0x31a3, 0xcee3, 0x31a4, 0xbbf8, 0x31a5, 0xd0cd, 0x31a6, 0xd0d2, 0x31a7, 0x31a8, 0x31a9, 0xffff, 0xd0d5, 0x31aa, 0xd0ce, 0x31ab, 0x31ac, 0xb6a1, 0xffff, 0xb0cd, 0x31ad, 0x31ae, 0xb6a2, 0xb2c1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xd5a5, 0xffff, 0xcbf9, 0xc9ee, 0xb8f4, 0xffff, 0xffff, 0x31af, 0xffff, 0xffff, 0xbfaf, 0xceb7, 0x31b0, 0xffff, 0x31b1, 0xffff, 0x31b2, 0x31b3, 0x31b4, 0x31b5, 0xcad8, 0x31b6, 0x31b7, 0xb7b8, 0xc2a5, 0xb2e4, 0x31b8, 0x31b9, 0xffff, 0x31ba, 0x31bb, 0xbdd3, 0x31bc, 0x31bd, 0x31be, 0xd0d9, 0x31bf, 0xd0de, 0xd0dc, 0x31c0, 0xffff, 0xd0d7, 0xffff, 0xffff, 0xc2af, 0xd0da, 0xffff, 0xd0dd, 0xd0db, 0x31c1, 0xcadd, 0xffff, 0xd0d8, 0x31c2, 0xbfae, 0x31c3, 0xcbf3, 0xd0df, 0xd0e0, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xbda4, 0xd0ed, 0x31c4, 0xffff, 0x31c5, 0xc7d0, 0xffff, 0xc9b6, 0xd0e8, 0xffff, 0xcaf0, 0xffff, 0xb2b6, 0xffff, 0x31c6, 0x31c7, 0xd0ec, 0x31c8, /* 0x50: 0x00 - 0xfe */ 0x31c9, 0x31ca, 0xffff, 0xffff, 0x31cb, 0xd0e6, 0xd0ef, 0x31cc, 0xffff, 0xc1d2, 0x31cd, 0xb8c4, 0x31ce, 0xc7dc, 0x31cf, 0xe0c7, 0x31d0, 0xd0ee, 0xc5dd, 0x31d1, 0xd0e3, 0xffff, 0xb8f6, 0x31d2, 0x31d3, 0xb8f5, 0xd0e1, 0x31d4, 0x31d5, 0x31d6, 0x31d7, 0xbcda, 0xffff, 0xd0e9, 0x31d8, 0xcaef, 0xc3cd, 0xd0e5, 0xb7f1, 0x31d9, 0xd0e2, 0xd0ea, 0xd0e4, 0xced1, 0xd0eb, 0xcfc1, 0x31da, 0xffff, 0x31db, 0xffff, 0x31dc, 0x31dd, 0xffff, 0x31de, 0xb6e6, 0xffff, 0xffff, 0xb7f0, 0xffff, 0x31f6, 0xffff, 0xffff, 0xffff, 0xffff, 0x31df, 0x31e0, 0x31e1, 0xd0f0, 0xffff, 0x31e2, 0x31e3, 0xd0f1, 0xd0f5, 0xb0ce, 0x31e4, 0xffff, 0x31e5, 0xffff, 0x31e6, 0xcad0, 0xd0f4, 0x31e7, 0x31e8, 0x31e9, 0xffff, 0xd0f3, 0xd0f7, 0x31ea, 0xffff, 0x31eb, 0xd0f6, 0xffff, 0xc4e4, 0xffff, 0xffff, 0x31ec, 0x31ed, 0xffff, 0x31ee, 0x31ef, 0xffff, 0xb7f2, 0x31f0, 0x31f1, 0xffff, 0xffff, 0x31f2, 0xffff, 0xd0f8, 0x31f3, 0xffff, 0xffff, 0x31f4, 0x31f5, 0xbcc5, 0xffff, 0xc2a6, 0xc4e5, 0xb6f6, 0xffff, 0xd0f9, 0xffff, 0xffff, 0xffff, 0xffff, 0xb5b6, 0xffff, 0xffff, 0xd0fa, 0x31f7, 0xffff, 0x31f8, 0x31f9, 0xd0fc, 0x31fa, 0xffff, 0xffff, 0xffff, 0x31fb, 0xffff, 0xffff, 0xcbb5, 0x31fc, 0x31fd, 0x31fe, 0xb7e6, 0x32a1, 0x32a2, 0x32a3, 0xffff, 0x32a4, 0xffff, 0xbbb1, 0xc8f7, 0xd0fb, 0x32a5, 0x32a6, 0xffff, 0x32a7, 0x32a8, 0x32a9, 0x32aa, 0x32ab, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x32ac, 0xffff, 0xbac5, 0xcdc3, 0xffff, 0x32ad, 0x32ae, 0xffff, 0xd0fe, 0xd1a3, 0xd0fd, 0xbac4, 0xffff, 0xbdfd, 0xffff, 0x32af, 0x32b0, 0xffff, 0xffff, 0x32b1, 0xb7b9, 0xffff, 0x32b2, 0xffff, 0xd1a4, 0x32b3, 0x32b4, 0xb6cf, 0xffff, 0x32b5, 0xffff, 0xd1a1, 0xd1a2, 0xffff, 0x32b6, 0xc6af, 0x32b7, 0xc1fc, 0x32b8, 0xb6a3, 0xffff, 0x32b9, 0x32ba, 0xcbcd, 0xd1a5, 0xffff, 0x32bb, 0xffff, 0xcebd, 0xffff, 0x32bc, 0x32bd, 0xd1a6, 0x32be, 0xffff, 0xffff, 0x32bf, 0xd1a9, 0x32c0, 0xd1a7, 0x32c1, 0xc1ce, 0x32c2, 0x32c3, 0xffff, 0xffff, 0xffff, 0xd1a8, 0xd1aa, 0x32c4, 0xffff, 0x32c5, 0x32d1, 0xffff, 0xffff, 0xd1ac, 0x32c6, 0xffff, 0xffff, 0xd1ab, 0x32c7, 0xcac8, 0xffff, 0xffff, 0x32c8, /* 0x51: 0x00 - 0xfe */ 0xb5b7, 0xd1ae, 0xd1af, 0x32c9, 0xb2af, 0xffff, 0x32ca, 0x32cb, 0x32cc, 0xd1ad, 0xffff, 0x32cd, 0x32ce, 0x32cf, 0x32d0, 0xffff, 0x32d2, 0xffff, 0xbcf4, 0xffff, 0xd1b2, 0xd1b1, 0xd1b0, 0x32d3, 0xd0d6, 0x32d4, 0xd1b3, 0x32d5, 0x32d6, 0x32d7, 0x32d8, 0xbdfe, 0xffff, 0xd1b4, 0xffff, 0x32d9, 0xffff, 0xffff, 0xffff, 0x32da, 0x32db, 0xffff, 0xcda5, 0xffff, 0x32dc, 0x32dd, 0xffff, 0x32de, 0xffff, 0x32df, 0xccd9, 0x32e0, 0x32e1, 0x32e2, 0xffff, 0xd1b6, 0x32e3, 0x32e4, 0xd1b5, 0xd1b8, 0xd1b7, 0xffff, 0xffff, 0xd1b9, 0xd1ba, 0xb0f4, 0x32e5, 0xb8b5, 0xb7bb, 0xbdbc, 0xc3fb, 0xb6a4, 0xc0e8, 0xb8f7, 0x32e6, 0xb9ee, 0xd1bc, 0xccc8, 0xc5c6, 0x32e7, 0xbbf9, 0xffff, 0xd1bb, 0x32e8, 0xd1bd, 0x32e9, 0xffff, 0x32ea, 0x32eb, 0xffff, 0xc5de, 0xffff, 0xb3f5, 0xffff, 0xffff, 0x32ec, 0xffff, 0xffff, 0xd1be, 0xffff, 0x32ed, 0xc6fe, 0x32ee, 0xffff, 0xc1b4, 0xd1c0, 0xd1c1, 0xc8ac, 0xb8f8, 0xcfbb, 0xd1c2, 0xffff, 0xffff, 0xb6a6, 0xffff, 0xffff, 0xffff, 0xcabc, 0xc2b6, 0xb6f1, 0xc5b5, 0xffff, 0xffff, 0xffff, 0xb7f3, 0xffff, 0x32ef, 0xffff, 0xd1c3, 0xffff, 0xd1c4, 0x32f0, 0x32f1, 0xc6e2, 0xb1df, 0xffff, 0xffff, 0xd1c7, 0xbafd, 0x32f2, 0xd1c6, 0xbac6, 0x32f3, 0xd1c8, 0xe6ee, 0xd1c9, 0xcbc1, 0xd1ca, 0xffff, 0xd1cb, 0xd1cc, 0xbee9, 0x32f4, 0xbccc, 0xffff, 0xffff, 0xffff, 0x32f5, 0xffff, 0xffff, 0xb4a7, 0x32f6, 0xd1cf, 0x32f7, 0xd1cd, 0xccbd, 0xd1ce, 0xffff, 0xc9da, 0xd1d0, 0xd1d1, 0xd1d2, 0xc5df, 0x32f8, 0xffff, 0xffff, 0xd1d6, 0xd1d4, 0xd1d5, 0xd1d3, 0xbae3, 0xd1d7, 0xccea, 0xcee4, 0x32f9, 0xffff, 0x32fa, 0xffff, 0x32fb, 0xd1d8, 0x32fc, 0x32fd, 0xffff, 0xffff, 0x32fe, 0xffff, 0xc0a8, 0xd1d9, 0xbdda, 0xffff, 0x33a1, 0xd1da, 0xffff, 0xc3fc, 0xcebf, 0xc5e0, 0xffff, 0x33a2, 0xffff, 0x33a3, 0x33a4, 0x33a5, 0xffff, 0x33a6, 0xd2c5, 0xffff, 0x33a7, 0xffff, 0xffff, 0xd1db, 0xf4a5, 0xb6c5, 0x33a8, 0xffff, 0xd1dc, 0xcbde, 0x33a9, 0xffff, 0xffff, 0x33aa, 0xbde8, 0xc2fc, 0xffff, 0xd1de, 0xc6e4, 0xffff, 0xffff, 0xd1df, 0x33ab, 0xffff, 0xd1e0, 0xb3ae, 0x33ac, 0x33ad, 0x33ae, 0xd1e1, 0xb6a7, 0x33af, 0xc6cc, 0xb1fa, 0xbdd0, 0xffff, 0xffff, 0xc8a1, 0xd1e2, /* 0x52: 0x00 - 0xff */ 0xc5e1, 0x33b0, 0x33b1, 0xbfcf, 0xd1e3, 0x33b2, 0xcaac, 0xc0da, 0xb4a2, 0xffff, 0xb4a9, 0xd1e4, 0xffff, 0xffff, 0xd1e6, 0xffff, 0xffff, 0xb7ba, 0x33b3, 0x33b4, 0xd1e5, 0x33b5, 0x33b6, 0xcef3, 0x33b7, 0xffff, 0xffff, 0xffff, 0xffff, 0xbde9, 0xffff, 0xffff, 0xffff, 0xffff, 0x33b8, 0xffff, 0xc8bd, 0xcacc, 0xffff, 0xd1e7, 0x33b9, 0xcdf8, 0xd1e8, 0xffff, 0xffff, 0xffff, 0xd1e9, 0xffff, 0xc5fe, 0x33ba, 0x33bb, 0xd1ea, 0xffff, 0x33bc, 0xc0a9, 0xbafe, 0xb7f4, 0xd1eb, 0xbbc9, 0xb9ef, 0x33bd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc4e6, 0xd1ed, 0x33be, 0xffff, 0xc2a7, 0xffff, 0x33bf, 0xbaef, 0xd1ee, 0xd1ef, 0xc1b0, 0xffff, 0xd1ec, 0xffff, 0xffff, 0xffff, 0xffff, 0xd1f1, 0x33c0, 0xcbb6, 0x33c1, 0x33c2, 0xffff, 0x33c3, 0xb9e4, 0x33c4, 0xffff, 0xd1f0, 0x33c5, 0x33c6, 0x33c7, 0xffff, 0xb7f5, 0xbade, 0xc7ed, 0x33c8, 0xffff, 0xffff, 0xd1f4, 0xd1f2, 0xffff, 0xffff, 0xffff, 0x33c9, 0xc9fb, 0xbeea, 0xd1fb, 0xb3e4, 0xd1f5, 0xd1f3, 0xc1cf, 0xffff, 0x33ca, 0x33cb, 0x33cc, 0xffff, 0xffff, 0xffff, 0xd1f7, 0xffff, 0xd1f6, 0x33cd, 0xffff, 0x33ce, 0xb3c4, 0xffff, 0x33cf, 0xffff, 0xb7e0, 0xd1fc, 0xcead, 0x33d0, 0xffff, 0x33d1, 0xd1f8, 0xffff, 0xffff, 0xffff, 0xd1fd, 0xd1fa, 0x33d2, 0xd1f9, 0x33d3, 0x33d4, 0x33d5, 0x33d6, 0xffff, 0x33d7, 0xcecf, 0x33d8, 0xffff, 0xffff, 0xb8f9, 0xb2c3, 0xffff, 0xffff, 0xcef4, 0x33d9, 0x33da, 0x33db, 0x33dc, 0xffff, 0xbdf5, 0xc5d8, 0xb9e5, 0xd2a2, 0xd2a3, 0xffff, 0x33dd, 0x33de, 0xcee5, 0xffff, 0xffff, 0xcfab, 0xd2a5, 0x33df, 0x33e0, 0x33e1, 0xb8fa, 0x33e2, 0x33e3, 0xd2a4, 0x33e4, 0xb3af, 0xffff, 0x33e5, 0xd2a6, 0xffff, 0xcbd6, 0x33e6, 0xc4bc, 0x33e7, 0xcda6, 0x33e8, 0xcad9, 0xffff, 0xffff, 0x33e9, 0xd2a7, 0xffff, 0x33ea, 0xffff, 0x33eb, 0xf0d5, 0xffff, 0x33ec, 0xc6b0, 0x33ed, 0xd2a8, 0xb4aa, 0xccb3, 0xffff, 0x33ee, 0x33ef, 0xbea1, 0xd2a9, 0xcae7, 0xd2ad, 0x33f0, 0xc0aa, 0xd2aa, 0xb6d0, 0x33f1, 0xd2ab, 0xb4ab, 0x33f2, 0x33f3, 0x33f4, 0xffff, 0x33f5, 0xffff, 0xffff, 0xffff, 0x33f6, 0x33f7, 0xb7ae, 0xd2ae, 0x33f8, 0xd2af, 0x33f9, 0x33fa, 0xd2b0, 0xd2b1, 0xbcdb, 0xffff, 0xffff, 0xffff, 0xb8fb, 0xccde, /* 0x53: 0x00 - 0xfa */ 0x33fb, 0xcce8, 0xc6f7, 0x33fc, 0xffff, 0xcaf1, 0xd2b2, 0xffff, 0xd2b3, 0xffff, 0x33fd, 0x33fe, 0x34a1, 0xd2b5, 0xffff, 0xd2b7, 0xd2b6, 0x34a2, 0xffff, 0x34a3, 0xffff, 0xd2b8, 0xb2bd, 0xcbcc, 0x34a4, 0xbafc, 0xd2b9, 0x34a5, 0x34a6, 0xc1d9, 0x34a7, 0x34a8, 0xbea2, 0xb6a9, 0xffff, 0xd2ba, 0xffff, 0x34a9, 0xffff, 0x34aa, 0x34ab, 0x34ac, 0xc8db, 0x34ad, 0x34ae, 0x34af, 0xffff, 0xd2bb, 0x34b0, 0xd2bc, 0x34b1, 0xd2bd, 0xffff, 0x34b2, 0xffff, 0xffff, 0xd2be, 0xc9a4, 0xb6e8, 0xb0e5, 0x34b3, 0x34b4, 0x34b5, 0xc6bf, 0xd2bf, 0xbdbd, 0x34b6, 0xc0e9, 0xffff, 0xd2c1, 0xd2c0, 0xbea3, 0xb8e1, 0xd2c3, 0xc8be, 0x34b8, 0x34b7, 0xd2c4, 0xffff, 0xffff, 0xffff, 0xc8dc, 0xc2b4, 0xc2ee, 0xb6a8, 0xffff, 0xffff, 0xc6ee, 0xc3b1, 0x34b9, 0xc7ee, 0x34ba, 0xcbce, 0xffff, 0xd2c6, 0xffff, 0xc0ea, 0x34bb, 0xffff, 0x34bc, 0xffff, 0x34bd, 0xb7b5, 0xffff, 0xffff, 0xd2c7, 0xffff, 0xffff, 0x34be, 0x34bf, 0xd2c8, 0xb1ac, 0xb0f5, 0xb4ed, 0x34c0, 0xc2a8, 0xb5d1, 0xcdf1, 0xffff, 0xd2cb, 0xb2b7, 0x34c1, 0xffff, 0xd2ca, 0xffff, 0xffff, 0x34c2, 0xb6aa, 0xffff, 0xffff, 0xd2cc, 0x34c3, 0xccf1, 0xffff, 0xffff, 0x34c4, 0x34c5, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x34c6, 0xffff, 0xffff, 0xffff, 0xffff, 0x34c7, 0x34c8, 0xffff, 0xd2cd, 0xffff, 0xced2, 0x34c9, 0xb8fc, 0xffff, 0xffff, 0x34ca, 0xffff, 0xb8b6, 0xd2ce, 0x34cb, 0xffff, 0xffff, 0x34cc, 0xd2d0, 0xd2cf, 0xffff, 0xbfdf, 0xb1b9, 0x34cd, 0x34ce, 0xffff, 0xb1de, 0xd2d1, 0x34cf, 0xd2d2, 0xffff, 0x34d0, 0xb8b7, 0x34d1, 0x34d2, 0xd2d3, 0x34d3, 0x34d4, 0xffff, 0x34d5, 0xb5ee, 0xffff, 0x34d6, 0xffff, 0xffff, 0x34d7, 0xffff, 0xbbb2, 0xd2d4, 0xffff, 0x34d8, 0xffff, 0xffff, 0xcbf4, 0xbab5, 0xb5da, 0xcda7, 0xc1d0, 0xc8bf, 0xbcfd, 0x34d9, 0xffff, 0xffff, 0x34da, 0x34db, 0xbdc7, 0x34dc, 0xbce8, 0xbcf5, 0xffff, 0xbdf6, 0x34dd, 0xc8c0, 0xffff, 0x34de, 0x34df, 0xd2d7, 0x34e0, 0xb1c3, 0xc1d1, 0xb8fd, 0xb8c5, 0xb6e7, 0x34e1, 0x34e2, 0xd2db, 0xc3a1, 0xc2fe, 0xb6ab, 0xbea4, 0xd2dc, 0xd2da, 0xb2c4, 0xc2e6, 0xbcb8, 0xbbcb, 0xb1a6, 0xffff, 0x34e3, 0xb3f0, 0xb9e6, 0xbbca, 0xffff, 0xd2dd, /* 0x54: 0x01 - 0xff */ 0xd2de, 0x34e4, 0xb5c9, 0xb3c6, 0xffff, 0xffff, 0xffff, 0xb9e7, 0xb5c8, 0xc4df, 0xb1a5, 0xc6b1, 0xccbe, 0xb9a1, 0xcdf9, 0xc5c7, 0xb8fe, 0xffff, 0x34e5, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x34e6, 0xb7af, 0xffff, 0xd2e7, 0xffff, 0xb6e3, 0xcbca, 0x34e7, 0xffff, 0xffff, 0xffff, 0xffff, 0xc8dd, 0x34e8, 0x34e9, 0xd2e6, 0x34ea, 0xb4de, 0xd2e1, 0xd2e2, 0xd2e4, 0x34eb, 0xffff, 0x34ec, 0xffff, 0xffff, 0x34ed, 0x34ee, 0xd2e5, 0xffff, 0xb5db, 0xbfe1, 0xffff, 0xcaad, 0xd2e3, 0xd2df, 0xb8e3, 0xffff, 0xd2e0, 0xffff, 0xcfa4, 0x34ef, 0x34f0, 0xffff, 0xcaf2, 0x34f1, 0xc4e8, 0xb8e2, 0xb9f0, 0xffff, 0xffff, 0x34f2, 0xd2e8, 0x34f3, 0xffff, 0xc6dd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x34f4, 0xd2ec, 0xffff, 0xffff, 0x34f5, 0xffff, 0x34f6, 0xffff, 0x34f7, 0x34f8, 0xbcfe, 0x34f9, 0xbcf6, 0x34fa, 0xffff, 0x34fb, 0x34fc, 0xffff, 0xd2ef, 0xd2ed, 0xffff, 0xcca3, 0x34fd, 0xd2ea, 0xd2f3, 0xd2ee, 0xffff, 0xffff, 0xffff, 0xd2f1, 0xb8c6, 0xccbf, 0xffff, 0x34fe, 0xd2f2, 0x35a1, 0xffff, 0x35a2, 0xd2f4, 0x35a3, 0xd2f6, 0xffff, 0x35a4, 0x35a5, 0xffff, 0xbaf0, 0xcfc2, 0x35a6, 0xd2eb, 0xd2e9, 0xd2f5, 0x35a7, 0xd2f0, 0xffff, 0xffff, 0x35a8, 0x35a9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x35aa, 0xffff, 0xffff, 0x35ab, 0xffff, 0x35ac, 0xd2f8, 0xffff, 0xd3a3, 0xd2fa, 0x35ad, 0x35ae, 0xd2fe, 0x35af, 0x35b0, 0xd3a1, 0xd2fb, 0x35b1, 0x35b2, 0xd3be, 0xffff, 0x35b3, 0xbae9, 0xb3b1, 0xffff, 0xffff, 0xffff, 0x35b4, 0xd2f9, 0x35b5, 0x35b6, 0x35b7, 0xd3a5, 0xb0f6, 0xd3a4, 0x35b8, 0xb0a5, 0xc9ca, 0xd3a2, 0xffff, 0xd2fc, 0xffff, 0x35b9, 0xd2f7, 0xd2fd, 0xbac8, 0x35ba, 0xffff, 0xffff, 0x35bb, 0x35bc, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xd3a6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x35bd, 0xb0f7, 0xd3af, 0xffff, 0xffff, 0xd3a7, 0xd3a8, 0xffff, 0xbea5, 0xcbe9, 0x35be, 0xffff, 0x35bf, 0xd3ad, 0xd3ac, 0x35c0, 0xffff, 0xffff, 0xc5af, 0xffff, 0xffff, 0xffff, 0x35c1, 0xffff, 0xffff, 0xffff, 0xd3ae, 0xffff, 0x35c2, 0xd3ab, 0x35c3, 0x35c4, /* 0x55: 0x00 - 0xff */ 0x35c5, 0x35c6, 0xffff, 0xffff, 0xb1b4, 0x35c7, 0xbab6, 0xbfb0, 0x35c8, 0x35c9, 0xffff, 0xffff, 0x35ca, 0x35cb, 0x35cc, 0xd3a9, 0xc5e2, 0xffff, 0xffff, 0xffff, 0xd3aa, 0x35cd, 0xb0a2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x35ce, 0x35cf, 0xffff, 0xffff, 0xd3b4, 0xcda3, 0xffff, 0xbea7, 0x35d0, 0xd3ba, 0xffff, 0x35d1, 0x35d2, 0xffff, 0xd3b9, 0xd3b0, 0xffff, 0x35d3, 0x35d4, 0x35d5, 0xc2c3, 0xffff, 0xd3b1, 0x35d6, 0xffff, 0xffff, 0xc2ef, 0xd3b6, 0xbea6, 0x35d7, 0xffff, 0x35d8, 0x35d9, 0xffff, 0xd3b3, 0x35da, 0xffff, 0xcce4, 0x35db, 0x35dc, 0xffff, 0xb7bc, 0xffff, 0xffff, 0xd3b7, 0xd3b8, 0x35dd, 0xffff, 0x35de, 0x35df, 0xd3b5, 0xd3bb, 0x35e0, 0xffff, 0x35e1, 0x35e2, 0xffff, 0xd3b2, 0x35e3, 0xffff, 0x35e4, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xd3c1, 0xd3c6, 0xffff, 0xd3c2, 0x35e5, 0xd3bd, 0x35e6, 0x35e7, 0xd3c7, 0xc1b1, 0xffff, 0x35e8, 0xd3c9, 0x35e9, 0xb9a2, 0xd3bf, 0xc3fd, 0xffff, 0xffff, 0x35ea, 0x35eb, 0xffff, 0x35ec, 0x35ed, 0x35ee, 0x35ef, 0xffff, 0xffff, 0x35f0, 0xd3c3, 0xd3bc, 0xb4ad, 0xffff, 0xb4ee, 0xb3e5, 0xd3c4, 0xd3c0, 0xffff, 0xffff, 0xffff, 0x35f1, 0x35f2, 0xffff, 0xffff, 0xb7f6, 0xd3ca, 0xd3c8, 0xc1d3, 0xb5ca, 0xb6ac, 0x35f3, 0xd3c5, 0xffff, 0xb6f4, 0xffff, 0x35f4, 0xffff, 0xffff, 0xffff, 0xb1c4, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x35f5, 0xffff, 0x35f6, 0xffff, 0x35f7, 0xd3ce, 0xd3cc, 0x35f8, 0xd4a7, 0xffff, 0x35f9, 0xffff, 0x35fa, 0x35fb, 0xffff, 0x35fc, 0xffff, 0xffff, 0x35fd, 0x35fe, 0x36a1, 0xd3d1, 0xffff, 0xffff, 0x36a2, 0x36a3, 0xffff, 0xd3cb, 0x36a4, 0xd3cf, 0xffff, 0x36a5, 0xd3cd, 0xffff, 0xffff, 0x36a6, 0xbbcc, 0xd3d0, 0xffff, 0xffff, 0xffff, 0xffff, 0x36a7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x36a8, 0xd3d3, 0xffff, 0xd3d8, 0xffff, 0xffff, 0xffff, 0xd3d6, 0xd3d5, 0x36a9, /* 0x56: 0x05 - 0xff */ 0x36aa, 0xc3b2, 0xffff, 0x36ab, 0xb2c5, 0x36ac, 0xffff, 0xffff, 0x36ad, 0x36ae, 0x36af, 0x36b0, 0x36b1, 0x36b2, 0xffff, 0xd3d2, 0xffff, 0xd3d4, 0xbea8, 0xb1b3, 0x36b3, 0xffff, 0xd3d7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb2de, 0xffff, 0xffff, 0x36b4, 0xffff, 0xffff, 0xd3e2, 0x36b5, 0xbefc, 0xd3de, 0x36b6, 0xd3dc, 0x36b7, 0xd3dd, 0x36b8, 0xd3df, 0x36b9, 0xffff, 0x36ba, 0x36bb, 0x36bc, 0xffff, 0x36bd, 0x36be, 0x36bf, 0xb1bd, 0x36c0, 0x36c1, 0xffff, 0x36c2, 0xffff, 0xffff, 0x36c3, 0xffff, 0x36c4, 0xc1b9, 0x36c5, 0xd3d9, 0x36c6, 0xd3da, 0xffff, 0xffff, 0xffff, 0x36c7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb3fa, 0xffff, 0xffff, 0x36c8, 0xffff, 0x36c9, 0x36ca, 0x36cb, 0x36cc, 0xd3e1, 0xffff, 0x36cd, 0xffff, 0xb4ef, 0x36ce, 0xd3e4, 0xd3e0, 0xd3e3, 0x36cf, 0xffff, 0x36d0, 0xffff, 0x36d1, 0x36d2, 0xffff, 0xcaae, 0x36d3, 0xffff, 0xffff, 0xc6d5, 0xffff, 0xc8b8, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xd3e6, 0xffff, 0xffff, 0xffff, 0x36d4, 0x36d5, 0xd3e5, 0xb3c5, 0x36d6, 0xffff, 0xd3e7, 0x36d7, 0x36d8, 0xffff, 0xffff, 0xd3ea, 0xffff, 0xffff, 0xffff, 0xffff, 0xd3e9, 0x36d9, 0xffff, 0xffff, 0xffff, 0x36da, 0x36db, 0xffff, 0xffff, 0x36dc, 0x36dd, 0x36de, 0xd3e8, 0xffff, 0xc7b9, 0xffff, 0xffff, 0xd3eb, 0x36df, 0x36e0, 0x36e1, 0x36e2, 0xffff, 0x36e3, 0x36e4, 0x36e5, 0xd3ec, 0xffff, 0xffff, 0x36e6, 0xffff, 0x36e7, 0xd3ee, 0xffff, 0xd3ed, 0x36e8, 0xffff, 0xffff, 0xffff, 0xffff, 0xd3f0, 0xffff, 0x36e9, 0xffff, 0xd3f3, 0xd3f1, 0xd3ef, 0xd3f2, 0xffff, 0x36ea, 0xffff, 0xffff, 0xd3f4, 0x36eb, 0x36ec, 0x36ed, 0x36f0, 0x36f1, 0xd3f5, 0x36ee, 0x36ef, 0xd3f6, 0xffff, 0xd3f7, 0xffff, 0xffff, 0xffff, 0xd3f8, 0xd1c5, 0x36f2, 0xbcfc, 0xbbcd, 0x36f3, 0x36f4, 0xb2f3, 0x36f5, 0xb0f8, 0x36f6, 0xffff, 0xc3c4, 0x36f7, 0x36f8, 0x36f9, 0x36fa, 0x36fb, 0xffff, 0xffff, 0x36fd, 0xffff, 0x36fe, 0xd3f9, 0xffff, 0xbaa4, 0x36fc, 0xb0cf, 0xbfde, 0xffff, 0xffff, 0x37a1, 0x37a2, 0xffff, 0xd3fa, 0xb8c7, 0xffff, 0xffff, 0xb9f1, 0xffff, 0xd3fc, /* 0x57: 0x00 - 0xff */ 0xd3fb, 0x37a3, 0x37a4, 0xcae0, 0xd3fd, 0xffff, 0xffff, 0x37a5, 0xd4a1, 0xd3fe, 0x37a6, 0xd4a2, 0x37a7, 0xd4a3, 0xffff, 0xb7f7, 0xffff, 0x37a8, 0xb1e0, 0xd4a4, 0xffff, 0x37a9, 0xd4a6, 0xffff, 0xd4a5, 0xffff, 0x37aa, 0x37ab, 0xd4a8, 0x37ac, 0xffff, 0xc5da, 0x37ad, 0xffff, 0x37ae, 0x37af, 0x37b0, 0x37b1, 0xd4a9, 0xb0b5, 0xbadf, 0x37b2, 0x37b3, 0xffff, 0x37b4, 0xb7bd, 0x37b5, 0x37b6, 0xc3cf, 0xffff, 0xffff, 0x37b7, 0x37b8, 0xffff, 0xffff, 0xd4aa, 0xd4ab, 0xffff, 0xffff, 0xd4ad, 0xffff, 0x37b9, 0x37ba, 0x37bb, 0xd4ae, 0xffff, 0xbae4, 0xffff, 0xffff, 0x37bc, 0x37bd, 0xb6d1, 0xffff, 0xffff, 0xcbb7, 0xffff, 0x37be, 0x37bf, 0xd4ac, 0xd4af, 0xbac1, 0xb9a3, 0x37c0, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xd4b3, 0x37c1, 0xffff, 0xbaa5, 0x37c2, 0xc3b3, 0x37c3, 0x37c4, 0xd4b0, 0xc4da, 0x37c5, 0xffff, 0x37c6, 0x37c7, 0x37c8, 0x37c9, 0x37ca, 0xffff, 0x37cb, 0x37cc, 0x37cd, 0xffff, 0x37ce, 0xffff, 0x37cf, 0x37d0, 0x37d1, 0x37d2, 0xffff, 0x37d3, 0xd4b4, 0xffff, 0x37d4, 0xbfe2, 0x37d5, 0xffff, 0xffff, 0xffff, 0xffff, 0xd4b2, 0xd4b5, 0xffff, 0xb7bf, 0x37d6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xd4b6, 0x37d7, 0x37e0, 0xffff, 0x37d8, 0xffff, 0x37d9, 0x37da, 0xffff, 0x37db, 0x37dc, 0x37dd, 0x37de, 0xd4b7, 0x37df, 0xb9a4, 0xb3c0, 0xd4b9, 0xffff, 0xffff, 0x37e1, 0x37e2, 0x37e3, 0xd4ba, 0xffff, 0x37e4, 0xffff, 0xffff, 0xffff, 0xd4bb, 0xffff, 0xffff, 0xd4b8, 0xffff, 0xffff, 0xffff, 0xffff, 0x37e5, 0xffff, 0xffff, 0xffff, 0xffff, 0x37e6, 0xffff, 0xffff, 0xd4b1, 0xffff, 0xffff, 0xd4bc, 0xffff, 0xffff, 0xd4bd, 0x37e7, 0x37e8, 0xffff, 0xffff, 0xcbe4, 0x37e9, 0xffff, 0xbeeb, 0x37ea, 0xffff, 0xffff, 0xd4bf, 0xd4c0, 0xd4be, 0x37eb, 0xd4c2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc7b8, 0x37ec, 0x37ed, 0xb0e8, 0xc9d6, 0x37fe, 0xffff, 0xd4c3, 0x37ee, 0xffff, 0x37ef, 0x37f0, 0xffff, 0x37f1, 0xffff, 0xffff, 0xffff, 0x37f2, 0xffff, 0xffff, 0x37f3, 0xffff, 0xffff, 0xffff, 0xbefd, 0x37f4, 0x37f5, 0xbcb9, 0x37f6, 0xc7dd, 0xb4f0, 0xffff, 0xbaeb, 0x37f7, 0x37f8, 0x37f9, /* 0x58: 0x00 - 0xfd */ 0xcbd9, 0xffff, 0xc6b2, 0x37fa, 0x37fb, 0xb7f8, 0xc2cf, 0xffff, 0x37fc, 0x37fd, 0xd4c1, 0xd4c4, 0x38a1, 0x38a2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc2c4, 0xffff, 0xffff, 0xffff, 0xd4c5, 0xffff, 0x38a3, 0xffff, 0xd4c6, 0x38a4, 0x38a5, 0x38a6, 0xd4c8, 0xffff, 0xffff, 0xc4e9, 0xffff, 0x38a7, 0x38a8, 0xffff, 0xffff, 0xb4ae, 0xffff, 0xffff, 0x38a9, 0xffff, 0xf4a1, 0xb1e1, 0xcaf3, 0x38aa, 0xffff, 0xbeec, 0xc5c8, 0xffff, 0xffff, 0xffff, 0x38ab, 0xbae6, 0xffff, 0xffff, 0xd4ce, 0xffff, 0x38ac, 0xcabd, 0xcedd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x38ad, 0xb2f4, 0xd4ca, 0x38ae, 0x38af, 0xffff, 0x38b0, 0x38b1, 0xc1ba, 0xd4cd, 0xffff, 0xc5e3, 0x38b2, 0xffff, 0xc5c9, 0xc5e4, 0xc8b9, 0xc4cd, 0xffff, 0xffff, 0xffff, 0xbac9, 0x38b3, 0xffff, 0x38b4, 0xd4c9, 0xffff, 0x38b5, 0xffff, 0xffff, 0x38b6, 0x38b7, 0xb1f6, 0xffff, 0xc5b6, 0xffff, 0xffff, 0xffff, 0xffff, 0xd4cb, 0xffff, 0xd4c7, 0xffff, 0xffff, 0xbfd0, 0xffff, 0xffff, 0x38b8, 0xd4cf, 0xffff, 0xffff, 0x38b9, 0xffff, 0xbdce, 0x38ba, 0x38bb, 0x38bc, 0xffff, 0xb6ad, 0xffff, 0xd4d0, 0xffff, 0x38bd, 0x38be, 0x38bf, 0x38c0, 0xffff, 0x38c1, 0x38c2, 0xffff, 0x38c3, 0x38c4, 0xffff, 0xffff, 0xcae8, 0x38c5, 0xffff, 0x38c6, 0xc1fd, 0xffff, 0xffff, 0xffff, 0xffff, 0xc4c6, 0x38c7, 0xffff, 0xd4d2, 0x38c8, 0x38c9, 0x38ca, 0xffff, 0xffff, 0xffff, 0x38cb, 0xffff, 0xcbcf, 0x38cc, 0xffff, 0xd4d3, 0xffff, 0xffff, 0xd4d8, 0xffff, 0xffff, 0x38cd, 0x38ce, 0xcaaf, 0xffff, 0xffff, 0xffff, 0xffff, 0xd4d7, 0xd4d1, 0xd4d4, 0xd4d6, 0x38d0, 0xffff, 0xbaa6, 0xffff, 0xffff, 0xcac9, 0x38d1, 0xffff, 0x38cf, 0xd4d9, 0xffff, 0xc3c5, 0x38d2, 0xffff, 0xb2f5, 0xffff, 0xbeed, 0x38d3, 0x38d4, 0xffff, 0x38d5, 0xd4db, 0x38d6, 0xd4da, 0x38d7, 0xb9e8, 0x38d8, 0xd4dc, 0xd4de, 0xd4dd, 0x38d9, 0xffff, 0xd4e0, 0x38da, 0xd4d5, 0xd4e2, 0xffff, 0x38db, 0x38dc, 0xffff, 0xd4e1, 0xd4df, 0xffff, 0xffff, 0xffff, 0x38dd, 0xffff, 0xbbce, 0xbfd1, 0xffff, 0xc1d4, 0xd4e3, 0xc0bc, 0xb0ed, 0xc7e4, 0x38de, 0xffff, 0xffff, 0xffff, 0xc4db, 0xffff, 0xd4e5, 0xd4e4, 0xd4e6, 0xd4e7, 0xd4e8, /* 0x59: 0x02 - 0xff */ 0xd4e9, 0xffff, 0xffff, 0x38df, 0x38e0, 0xffff, 0xffff, 0xcad1, 0xd4ea, 0x38e1, 0x38e2, 0xffff, 0xffff, 0xb2c6, 0xd4eb, 0xffff, 0x38e3, 0x38e4, 0x38e5, 0xcdbc, 0xb3b0, 0xffff, 0xd2c9, 0xbdc8, 0xc2bf, 0xd4ec, 0xcceb, 0x38e7, 0xffff, 0xffff, 0xffff, 0x38e8, 0xccb4, 0x38e9, 0x38ea, 0xd4ee, 0xffff, 0xc2e7, 0x38eb, 0xc5b7, 0xc2c0, 0xc9d7, 0xd4ef, 0xd4f0, 0xb1fb, 0x38ec, 0x38ed, 0xbcba, 0xd4f1, 0x38ee, 0xffff, 0x38ef, 0x38f0, 0xb0d0, 0xd4f2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xd4f3, 0x38f1, 0xffff, 0xffff, 0xffff, 0x38f2, 0xb1e2, 0xffff, 0x38f3, 0xb4f1, 0xc6e0, 0xcaf4, 0xffff, 0xffff, 0xffff, 0xffff, 0xd4f7, 0xc1d5, 0xd4f6, 0xb7c0, 0x38f4, 0x38f5, 0xcbdb, 0xd4f5, 0xffff, 0xc5e5, 0xd4f9, 0x38f6, 0xd4f8, 0x38f7, 0xffff, 0x38f8, 0x38f9, 0x38fa, 0xd4fb, 0x38fb, 0xd4fa, 0x38fc, 0xffff, 0xb1fc, 0xffff, 0xd4fc, 0xbea9, 0xd4fe, 0xc3a5, 0x38fd, 0xd4fd, 0x38fe, 0xcab3, 0x39a1, 0xffff, 0xffff, 0x39a2, 0xbdf7, 0xc5db, 0x39a3, 0x39a4, 0xffff, 0xd5a1, 0x39a5, 0xffff, 0x39a6, 0x39a7, 0xb9a5, 0xffff, 0xffff, 0xffff, 0xd5a2, 0xc7a1, 0xc8de, 0xccd1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc7a5, 0x39a8, 0x39a9, 0xd5ab, 0x39aa, 0xffff, 0xffff, 0xffff, 0x39ab, 0xb5b8, 0xffff, 0x39ac, 0xcdc5, 0x39ad, 0xffff, 0xccaf, 0xffff, 0xd6ac, 0xffff, 0xd5a3, 0xffff, 0x39ae, 0xffff, 0xffff, 0xffff, 0xd5a6, 0x39af, 0xc2c5, 0xffff, 0x39b0, 0xcbb8, 0xffff, 0xffff, 0xffff, 0xc5ca, 0x39b1, 0x39b2, 0x39b3, 0x39b4, 0xffff, 0xd5a7, 0x39b5, 0xffff, 0xffff, 0xffff, 0x39b6, 0xffff, 0xcbe5, 0x39b7, 0xbaca, 0x39b8, 0xffff, 0xbeaa, 0xffff, 0xffff, 0x39b9, 0xffff, 0x39ba, 0x39bb, 0xffff, 0xd5a8, 0xffff, 0x39bc, 0xbbd0, 0x39bd, 0xbbcf, 0xffff, 0x39be, 0xffff, 0xffff, 0xb0b9, 0xb8c8, 0x39bf, 0xc0ab, 0xb0d1, 0xffff, 0xffff, 0xffff, 0xffff, 0xd5ac, 0xd5ad, 0xffff, 0xd5aa, 0x39c0, 0x39c1, 0x39c2, 0xffff, 0xffff, 0xffff, 0x39c3, 0x39c4, 0xb1b8, 0xb4af, 0x39c5, 0xd5a9, 0xffff, 0xccc5, 0xc9b1, 0xffff, 0xffff, 0x39c6, 0x39c7, 0xffff, 0x39c8, 0x39c9, 0xffff, 0x39ca, 0xffff, 0xb0a8, 0x39cb, 0xffff, 0xffff, 0xffff, 0xb0f9, 0xffff, 0xffff, 0xffff, 0xbbd1, /* 0x5a: 0x00 - 0xfd */ 0x39cc, 0xb0d2, 0xffff, 0xb0a3, 0x39cd, 0xffff, 0xffff, 0xffff, 0xffff, 0xd5b2, 0xffff, 0xffff, 0x39ce, 0x39cf, 0x39d0, 0xffff, 0xffff, 0xd5b0, 0x39d1, 0x39d2, 0xffff, 0xffff, 0xffff, 0xffff, 0xccbc, 0xffff, 0xd5b3, 0xffff, 0xd5b1, 0xffff, 0x39d3, 0xd5af, 0xbfb1, 0xffff, 0xffff, 0x39d4, 0x39d5, 0xd5ae, 0xffff, 0x39d6, 0x39d7, 0xcada, 0x39d8, 0xffff, 0xffff, 0x39d9, 0xffff, 0xb8e4, 0x39da, 0xffff, 0xffff, 0xffff, 0xffff, 0xd5b7, 0xd5b8, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xbeab, 0xffff, 0xffff, 0xffff, 0xd5b4, 0xcfac, 0xffff, 0xffff, 0x39db, 0x39dc, 0xc7cc, 0x39dd, 0x39de, 0xd5b6, 0xffff, 0xffff, 0x39df, 0xffff, 0xffff, 0xffff, 0x39e0, 0xffff, 0xffff, 0xffff, 0xffff, 0x39e1, 0xffff, 0xffff, 0xffff, 0xffff, 0xbaa7, 0xffff, 0xffff, 0xffff, 0x39e2, 0xffff, 0xffff, 0xffff, 0xd5b9, 0x39e3, 0xffff, 0x39e4, 0xc9d8, 0x39e5, 0xffff, 0xffff, 0xd5ba, 0xffff, 0xd5b5, 0x39e6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x39e7, 0xffff, 0xffff, 0x39e8, 0x39e9, 0xffff, 0xffff, 0x39ea, 0xccbb, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x39eb, 0xffff, 0xffff, 0xffff, 0xffff, 0x39ec, 0xffff, 0xc7de, 0x39ed, 0xffff, 0xffff, 0x39ee, 0xffff, 0xffff, 0x39ef, 0xd5bb, 0xc9b2, 0x39f0, 0xffff, 0x39f1, 0x39f2, 0x39f3, 0xffff, 0x39f4, 0xffff, 0xffff, 0xffff, 0xffff, 0x39f5, 0xffff, 0xffff, 0xffff, 0xffff, 0x39f6, 0xffff, 0xffff, 0xffff, 0xffff, 0x39f7, 0x39f8, 0x39f9, 0xffff, 0x39fa, 0xffff, 0xffff, 0x39fb, 0xffff, 0x39fc, 0x39fd, 0xd5bc, 0xd5c0, 0xd5bd, 0x39fe, 0xffff, 0xb2c7, 0xd5bf, 0xffff, 0x3aa1, 0xffff, 0x3aa2, 0xffff, 0x3aa3, 0xbcbb, 0xffff, 0xd5be, 0xb7f9, 0xffff, 0xffff, 0x3aa4, 0xd5cc, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xd5c5, 0xd5c2, 0xffff, 0xffff, 0x3aa5, 0xffff, 0x3aa6, 0xffff, 0xffff, 0xffff, 0x3aa7, 0xc3e4, 0xffff, 0xd5c1, 0xffff, 0x3aa8, 0xd5c3, 0xffff, 0xffff, 0xd5c4, 0x3aa9, 0xffff, 0xffff, 0xffff, 0x3aaa, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3aab, 0x3aac, 0xffff, 0xffff, 0xffff, 0xd5c6, 0xd5c7, 0xffff, 0x3aad, /* 0x5b: 0x00 - 0xff */ 0x3aae, 0x3aaf, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3ab0, 0xb4f2, 0xffff, 0xd5c9, 0xd5c8, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xd5ca, 0x3ab1, 0xffff, 0x3ab3, 0xffff, 0x3ab4, 0xffff, 0x3ab5, 0xffff, 0xffff, 0xffff, 0x3ab6, 0xbeee, 0xffff, 0xffff, 0x3ab7, 0xffff, 0xffff, 0xffff, 0xffff, 0xd5cd, 0xffff, 0xc4dc, 0x3ab8, 0xffff, 0xffff, 0xb1c5, 0xffff, 0xd5cb, 0xffff, 0x3ab2, 0xffff, 0xd5ce, 0xffff, 0x3ab9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xd5cf, 0xffff, 0xd5d2, 0x3aba, 0xffff, 0xd5d0, 0xffff, 0xd5d1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3abb, 0x3abc, 0xffff, 0xffff, 0xffff, 0xbbd2, 0xd5d3, 0x3abd, 0xffff, 0xb9a6, 0xd5d4, 0x3abe, 0xbbfa, 0xc2b8, 0xffff, 0xd5d5, 0xd5d6, 0xbbda, 0xb9a7, 0x3abf, 0xccd2, 0xffff, 0xffff, 0xffff, 0xb5a8, 0xb8c9, 0xd5d7, 0xb3d8, 0xffff, 0x3ac0, 0xd5d8, 0xffff, 0xc2b9, 0xffff, 0xffff, 0x3ac1, 0x3ac2, 0xd5d9, 0xd6a3, 0xffff, 0xd5da, 0xffff, 0xd5db, 0xffff, 0xffff, 0xd5dc, 0xffff, 0xd5de, 0xffff, 0x3ac3, 0x3ac4, 0x3ac5, 0x3ac6, 0xd5df, 0x3ac7, 0xffff, 0xd5e0, 0x3ac8, 0xc2f0, 0x3ac9, 0xb1a7, 0xbce9, 0xb0c2, 0x3aca, 0xc1d7, 0xb4b0, 0xbcb5, 0x3acb, 0xb9a8, 0x3acc, 0x3acd, 0xffff, 0x3ace, 0x3acf, 0xc5e6, 0x3ad0, 0xbda1, 0xb4b1, 0xc3e8, 0xc4ea, 0xb0b8, 0xb5b9, 0xcaf5, 0xffff, 0xbcc2, 0xffff, 0xffff, 0xb5d2, 0xc0eb, 0xbcbc, 0xcda8, 0xd5e1, 0xffff, 0x3ad1, 0x3ad2, 0xffff, 0xffff, 0x3ad3, 0x3ad4, 0xb5dc, 0x3ad5, 0xbacb, 0x3ad6, 0x3ad7, 0xb3b2, 0xb1e3, 0xbeac, 0xb2c8, 0x3ad8, 0xd5e2, 0xcdc6, 0x3ad9, 0xffff, 0x3ada, 0xffff, 0xffff, 0xbdc9, 0x3adb, 0x3adc, 0xbce4, 0xd5e3, 0xb4f3, 0xc6d2, 0xcca9, 0xd5e4, 0xffff, 0xd5e5, 0xffff, 0xffff, 0xc9d9, 0x3add, 0xffff, 0x3ade, 0xd5e7, 0xffff, 0xb4a8, 0xb6f7, 0xd5e6, 0xffff, 0x3adf, 0x3ae0, 0x3ae1, 0x3ae2, 0x3ae3, 0xb4b2, 0xffff, 0xbfb2, 0xd5eb, 0xbba1, 0x3ae4, 0xb2c9, 0xd5ea, 0xffff, 0xd5e8, 0xd5ec, 0xd5e9, 0xc7ab, 0xdccd, 0xbfb3, 0xffff, 0xd5ed, 0xffff, 0xffff, 0xcec0, 0x3ae5, 0xd5ee, 0x3ae6, 0xffff, 0xd5f0, 0x3ae7, 0xc3fe, 0xd5ef, 0xffff, 0xc0a3, 0xffff, 0xbbfb, 0xffff, 0xffff, 0x3ae8, 0xc2d0, 0xbcf7, /* 0x5c: 0x01 - 0xfd */ 0xc9f5, 0xc0ec, 0xffff, 0xbccd, 0xd5f1, 0xbead, 0xd5f2, 0xd5f3, 0xb0d3, 0xc2ba, 0xbfd2, 0x3ae9, 0xd5f4, 0xc6b3, 0xbeae, 0xffff, 0xbeaf, 0xffff, 0xd5f5, 0xffff, 0xffff, 0xc0ed, 0x3aea, 0xffff, 0xffff, 0xbeb0, 0xffff, 0xffff, 0xffff, 0x3aeb, 0x3aec, 0xd5f6, 0xffff, 0xd5f7, 0x3aed, 0xcce0, 0xffff, 0x3aee, 0xffff, 0xd5f8, 0x3aef, 0xffff, 0x3af0, 0x3af1, 0xb6c6, 0x3af2, 0xffff, 0x3af3, 0xbda2, 0x3af4, 0xffff, 0xffff, 0x3af5, 0x3af6, 0xffff, 0xd5f9, 0xd5fa, 0xbcdc, 0xbfac, 0xc6f4, 0xbfd4, 0xc8f8, 0xc7a2, 0xb6c9, 0xd5fb, 0xffff, 0xffff, 0xffff, 0xb5ef, 0xd5fc, 0xffff, 0xb6fe, 0xffff, 0xc6cf, 0xb2b0, 0xffff, 0xbbd3, 0xd5fd, 0xd6a2, 0xd6a1, 0xb6fd, 0xffff, 0xd5fe, 0xffff, 0xc5b8, 0xffff, 0xffff, 0xffff, 0x3af7, 0x3af8, 0xffff, 0x3af9, 0xffff, 0xc2b0, 0xffff, 0xc5cb, 0xbcc8, 0x3afa, 0x3afb, 0xc1d8, 0xcdfa, 0xffff, 0x3afc, 0x3afd, 0x3afe, 0xffff, 0xffff, 0xd6a4, 0x3ba1, 0xd6a5, 0xc6d6, 0x3ba2, 0xbbb3, 0xffff, 0xffff, 0x3ba3, 0x3ba4, 0xd6a7, 0xffff, 0xffff, 0xd6a8, 0x3ba5, 0x3ba6, 0x3ba7, 0x3ba8, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3ba9, 0x3baa, 0xffff, 0x3bab, 0xffff, 0xd6a9, 0xffff, 0xffff, 0x3bac, 0xb4f4, 0xd6aa, 0x3bad, 0xffff, 0xd6ab, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3bae, 0xffff, 0x3baf, 0x3bb0, 0xb2ac, 0x3bb1, 0x3bb2, 0xffff, 0xffff, 0x3bb3, 0xffff, 0xc1bb, 0xb4e4, 0x3bb4, 0xd6ad, 0xcca8, 0xffff, 0xffff, 0xffff, 0xffff, 0xc2d2, 0x3bb5, 0xb3d9, 0x3bb6, 0x3bb7, 0xd6af, 0xd6b1, 0xb4df, 0xffff, 0x3bb8, 0xd6ae, 0xd6b0, 0xffff, 0xd6b3, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xd6b2, 0xffff, 0xd6b4, 0xffff, 0x3bb9, 0xffff, 0x3bba, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3bbb, 0xffff, 0xffff, 0xffff, 0xffff, 0x3bbd, 0xffff, 0xd6b5, 0xffff, 0xffff, 0xffff, 0x3bbc, 0xffff, 0xffff, 0xc6bd, 0xb6ae, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb2e5, 0xd6b6, 0xd6bb, 0xffff, 0xffff, 0xd6b9, 0x3bbe, 0xcaf7, 0xcaf6, 0x3bbf, 0x3bc0, 0xffff, 0x3bc1, 0xffff, 0xc5e7, 0xffff, 0xffff, 0xffff, 0xd6b8, 0xbdd4, 0xffff, 0xd6b7, /* 0x5d: 0x01 - 0xfe */ 0x3bc2, 0xffff, 0xffff, 0xffff, 0xffff, 0x3bc3, 0xbff2, 0xffff, 0xffff, 0xffff, 0xd6bc, 0xffff, 0x3bc4, 0xbaea, 0xffff, 0xffff, 0xd6c2, 0x3bc5, 0xffff, 0xd6c3, 0xd6bd, 0xb3b3, 0xd6be, 0xd6c7, 0xd6c6, 0xd6c5, 0xd6c1, 0xffff, 0xffff, 0xffff, 0xd6c0, 0xffff, 0xffff, 0xd6c4, 0x3bc7, 0x3bc8, 0xffff, 0x3bc9, 0x3bca, 0xffff, 0xcaf8, 0xffff, 0x3bc6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3bcb, 0xffff, 0xffff, 0x3bcc, 0xffff, 0xffff, 0xffff, 0xffff, 0x3bcd, 0xffff, 0xffff, 0xffff, 0x3bce, 0xffff, 0x3bcf, 0xffff, 0xffff, 0x3bd0, 0x3bd1, 0xffff, 0xffff, 0x3bd2, 0xffff, 0x3bd3, 0xffff, 0x3bd7, 0xd6cb, 0xd6c8, 0xffff, 0xd6ca, 0xffff, 0xcdf2, 0x3bd5, 0xd6c9, 0xffff, 0xffff, 0x3bd4, 0xffff, 0xffff, 0xffff, 0x3bd6, 0xffff, 0xffff, 0xd6bf, 0xffff, 0xffff, 0x3bd8, 0x3bd9, 0x3bda, 0x3bdb, 0xffff, 0x3bdc, 0xffff, 0xffff, 0xffff, 0xffff, 0xbff3, 0x3bdd, 0xffff, 0xd6cc, 0x3bde, 0xffff, 0xbab7, 0x3bdf, 0xffff, 0xffff, 0xd6cd, 0xffff, 0xffff, 0xd6ce, 0xffff, 0xffff, 0x3be0, 0x3be1, 0xffff, 0xffff, 0xffff, 0x3be2, 0x3be3, 0xffff, 0x3be4, 0xd6d1, 0x3be5, 0xd6d0, 0xffff, 0xffff, 0xd6cf, 0x3be6, 0xffff, 0x3be7, 0xc5e8, 0xd6ba, 0xffff, 0xffff, 0xffff, 0xd6d7, 0xffff, 0x3be8, 0x3be9, 0x3bea, 0x3beb, 0xffff, 0xffff, 0xffff, 0x3bec, 0xffff, 0x3bed, 0xffff, 0xd6d3, 0xffff, 0x3bee, 0x3bef, 0xffff, 0xd6d2, 0xffff, 0xffff, 0xffff, 0xffff, 0x3bf0, 0xffff, 0xffff, 0xffff, 0x3bf1, 0xd6d4, 0xffff, 0xd6d5, 0xffff, 0x3bf2, 0xffff, 0x66f4, 0xffff, 0x3bf3, 0xffff, 0xffff, 0xd6d8, 0x3bf4, 0x3bf5, 0xcee6, 0xffff, 0xd6d9, 0xd6d6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3bf6, 0xffff, 0xffff, 0xffff, 0x3bf7, 0xffff, 0xd6da, 0xffff, 0x3bf8, 0xb4e0, 0xd6db, 0x3bfa, 0xffff, 0x3bf9, 0xffff, 0xd6dd, 0xd6dc, 0xffff, 0xffff, 0xd6de, 0xffff, 0x3bfb, 0x3bfc, 0xffff, 0xd6df, 0xffff, 0xc0ee, 0xbda3, 0xffff, 0x3bfd, 0xbde4, 0xffff, 0xc1e3, 0x3bfe, 0xb9a9, 0xbab8, 0xb9aa, 0xb5f0, 0x3ca1, 0xffff, 0xd6e0, 0xffff, 0xffff, 0xbab9, 0xffff, 0xffff, 0xb8ca, 0xd6e1, 0xcca6, 0xc7c3, 0xd6e2, 0xffff, 0xb9ab, 0x3ca2, 0x3ca3, 0xffff, 0xb4ac, 0xffff, 0xc3a7, 0xb6d2, /* 0x5e: 0x00 - 0xff */ 0x3ca4, 0xffff, 0xbbd4, 0xc9db, 0xffff, 0xffff, 0xc8c1, 0x3ca5, 0xffff, 0xffff, 0xffff, 0xd6e3, 0xb4f5, 0x3ca6, 0xffff, 0xffff, 0xffff, 0xd6e6, 0x3ca7, 0xffff, 0x3ca8, 0x3ca9, 0xc4a1, 0xffff, 0x3caa, 0xd6e5, 0xd6e4, 0xd6e7, 0xffff, 0xc4eb, 0xffff, 0x3cab, 0x3cac, 0xffff, 0xffff, 0xffff, 0xffff, 0xbfe3, 0xffff, 0xffff, 0x3cae, 0xffff, 0xffff, 0xbbd5, 0xffff, 0xc0ca, 0x3cad, 0xc2d3, 0xb5a2, 0xffff, 0x3caf, 0xc4a2, 0xffff, 0x3cb0, 0xd6e8, 0xd6e9, 0xbeef, 0xffff, 0xffff, 0xffff, 0xffff, 0xcbb9, 0x3cb1, 0xffff, 0xd6ec, 0xffff, 0xffff, 0xd6eb, 0xd6ea, 0xc9fd, 0xffff, 0xd6f3, 0xffff, 0x3cb4, 0xffff, 0x3cb2, 0xcbda, 0xffff, 0xd6ed, 0xffff, 0x3cb3, 0x3cb5, 0xffff, 0xffff, 0xd6ef, 0xcbeb, 0x3cb6, 0xd6ee, 0x3cb7, 0xffff, 0xffff, 0x3cb8, 0x3cb9, 0xffff, 0x3cba, 0xd6f0, 0xffff, 0xc8a8, 0xd6f1, 0xcabe, 0xd6f2, 0xffff, 0xffff, 0xffff, 0x3cbb, 0xffff, 0x3cbc, 0x3cbd, 0x3cbe, 0x3cbf, 0x3cc0, 0xffff, 0x3cc1, 0xffff, 0xb4b3, 0xcabf, 0xc7af, 0xd6f4, 0xd6f5, 0xffff, 0xb9ac, 0xb4b4, 0xd6f6, 0xb8b8, 0xcdc4, 0xcda9, 0xb4f6, 0xd6f8, 0x3cc2, 0xc4a3, 0xffff, 0xb9ad, 0xbeb1, 0xffff, 0xffff, 0xc8df, 0xffff, 0xffff, 0xbeb2, 0x3cc3, 0xffff, 0xffff, 0x3cc4, 0xbdf8, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc4ec, 0xcaf9, 0xc5b9, 0xffff, 0xffff, 0xb9ae, 0xffff, 0xc9dc, 0xffff, 0xffff, 0xffff, 0xd6f9, 0xffff, 0x3cc5, 0xffff, 0x3cc6, 0x3cc7, 0xc5d9, 0xbac2, 0x3cc8, 0xffff, 0x3cc9, 0xb8cb, 0x3cca, 0xc4ed, 0xffff, 0xffff, 0xffff, 0x3ccb, 0xffff, 0x3ccc, 0xffff, 0xb0c3, 0xbdee, 0xb9af, 0xcdc7, 0xffff, 0xffff, 0xffff, 0xffff, 0x3ccd, 0x3cce, 0x3ccf, 0xffff, 0xd6fa, 0xd6fb, 0xc7d1, 0xffff, 0xffff, 0x3cd0, 0xffff, 0xd6fc, 0xcef7, 0xcfad, 0x3cd2, 0x3cd1, 0xffff, 0x3cd3, 0xd6fe, 0xd6fd, 0x3cd4, 0x3cd5, 0xb3c7, 0x3cd6, 0x3cd7, 0xd7a1, 0xffff, 0xffff, 0xffff, 0xd7a4, 0xd7a5, 0x3cd8, 0xd7a3, 0x3cd9, 0xc9c0, 0xbeb3, 0xd7a7, 0xd7a6, 0xd7a2, 0xffff, 0x3cda, 0xffff, 0xffff, 0xd7a8, 0xd7a9, 0xffff, 0x3cdb, 0xd7aa, 0xffff, 0xffff, 0xffff, 0xd7ad, 0xd7ab, 0xffff, 0xd7ac, 0xd7ae, 0xffff, 0xb1e4, 0xc4ee, 0xd7af, 0xffff, 0xb7fa, 0xb2f6, 0xc7b6, 0xffff, 0xd7b0, 0xc6fb, /* 0x5f: 0x01 - 0xff */ 0xcadb, 0x3cdc, 0xd7b1, 0xcfae, 0xffff, 0x3cdd, 0x3cde, 0x3cdf, 0xd7b2, 0xcac0, 0xd7b5, 0xd0a1, 0xd0b1, 0x3ce0, 0xbcb0, 0xc6f5, 0xd7b6, 0xffff, 0xb5dd, 0xc4a4, 0xb0fa, 0xd7b7, 0xcaa6, 0xb9b0, 0x3ce1, 0xffff, 0xc3d0, 0x3ce2, 0x3ce3, 0xffff, 0xc4ef, 0xffff, 0x3ce4, 0x3ce5, 0x3ce6, 0x3ce7, 0xccef, 0xb8b9, 0xb8cc, 0x3ce8, 0xd7b8, 0xffff, 0x3ce9, 0x3cea, 0xd7b9, 0x3ceb, 0xd7bf, 0x3cec, 0xbce5, 0xffff, 0xffff, 0x3ced, 0xc4a5, 0x3cee, 0xb6af, 0xd7ba, 0xffff, 0xffff, 0x3cef, 0xc9ab, 0x3cf0, 0xc3c6, 0x3cf1, 0x3cf2, 0xd7bb, 0xffff, 0xffff, 0x3cf3, 0x3cf4, 0xffff, 0x3cf5, 0xd7bc, 0xffff, 0xb6b0, 0xffff, 0xd7bd, 0x3cf6, 0xd7be, 0xffff, 0x3cf7, 0xd7c0, 0xffff, 0xc5f6, 0x3cf8, 0xffff, 0xd7c1, 0xd7c2, 0x3cf9, 0xd7c3, 0xffff, 0x3cfa, 0xd7b4, 0xd7b3, 0xffff, 0xffff, 0x3cfb, 0xd7c4, 0xb7c1, 0x3cfc, 0x3cfd, 0xffff, 0xc9a7, 0x3cfe, 0xffff, 0xbacc, 0xc9b7, 0xc4a6, 0xc9cb, 0xd7c5, 0xffff, 0x3da1, 0xbeb4, 0xb1c6, 0x3da2, 0xd7c6, 0x3da3, 0x3da4, 0xffff, 0xd7c7, 0x3da5, 0xccf2, 0x3da6, 0xffff, 0xc8e0, 0x3da7, 0x3da8, 0xd7ca, 0xb1fd, 0xc0ac, 0xd7c9, 0xd7c8, 0xb7c2, 0xc2d4, 0xffff, 0xd7ce, 0xd7cc, 0x3da9, 0xd7cb, 0xcea7, 0xb8e5, 0x3daa, 0xffff, 0x3dab, 0xbdf9, 0xd7cd, 0xc5cc, 0xbdbe, 0xffff, 0xffff, 0x3dac, 0xc6c0, 0xd7d1, 0xd7d0, 0xffff, 0xffff, 0x3dad, 0x3dae, 0xd7cf, 0xffff, 0xd7d2, 0xb8e6, 0x3daf, 0xffff, 0x3db2, 0xffff, 0xffff, 0x3db0, 0xd7d3, 0xc9fc, 0xbddb, 0x3db1, 0x3db3, 0xd7d4, 0xc8f9, 0x3db4, 0x3db5, 0x3db6, 0xffff, 0xc6c1, 0xc4a7, 0xffff, 0xffff, 0xffff, 0x3db7, 0xc5b0, 0xffff, 0xffff, 0xd7d5, 0xb5ab, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xbfb4, 0x3db8, 0xc9ac, 0xffff, 0x3db9, 0x3dba, 0x3dbb, 0xffff, 0x3dbc, 0xb4f7, 0xc7a6, 0xffff, 0xffff, 0x3dbd, 0x3dbe, 0x3dbf, 0x3dc0, 0x3dc1, 0xffff, 0xd7d6, 0xbbd6, 0xcbba, 0xcbbb, 0xffff, 0xffff, 0xb1fe, 0xd7db, 0x3dc2, 0xffff, 0xc3e9, 0x3dc3, 0x3dc4, 0xffff, 0xd7d8, 0xffff, 0xffff, 0xffff, 0x3dc5, 0x3dc6, 0x3dc7, 0xb2f7, 0x3dc8, 0x3dc9, 0x3dca, 0x3dcb, 0xd8ad, 0xd7da, 0x3dcc, 0x3dcd, 0xffff, 0xc7b0, 0x3dce, 0xffff, 0xd7d9, 0xffff, 0x3dcf, 0xd7d7, 0x3dd0, 0xb9fa, 0xffff, 0xd7dd, /* 0x60: 0x07 - 0xfd */ 0x3dd1, 0xffff, 0xffff, 0x3dd2, 0xffff, 0xffff, 0x3dd3, 0xd7e3, 0xd7e9, 0xd7e1, 0xffff, 0xc5dc, 0x3dd4, 0x3dd5, 0xd7e6, 0xc9dd, 0x3dd6, 0x3dd7, 0xd7e0, 0x3dd8, 0xd7e5, 0xcee7, 0xbbd7, 0xffff, 0x3dd9, 0xc2d5, 0xd7de, 0xffff, 0xffff, 0x3dda, 0xb5de, 0xd7e8, 0xc0ad, 0xb1e5, 0xd7e2, 0xb2f8, 0xd7e7, 0xffff, 0x3ddb, 0xffff, 0xb6b1, 0xffff, 0xd7e4, 0xffff, 0x3ddc, 0xffff, 0x3ddd, 0xffff, 0xffff, 0xffff, 0xffff, 0xd7ea, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3dde, 0xd7ec, 0xd7f6, 0xd7f4, 0xffff, 0xffff, 0xd7f1, 0x3ddf, 0x3de0, 0x3de1, 0xd7f0, 0xcef8, 0x3de2, 0xd7f2, 0xffff, 0xffff, 0xb6b2, 0x3de3, 0xb9b1, 0xffff, 0x3de4, 0xbdfa, 0x3de5, 0x3de6, 0xffff, 0xd7f9, 0xd7eb, 0xffff, 0xffff, 0x3de7, 0xffff, 0xd7ef, 0xd7df, 0x3de8, 0xb2fa, 0xd7f3, 0xd7f5, 0xc3d1, 0xffff, 0x3de9, 0xbaa8, 0xb2b8, 0xd7ed, 0xd7f8, 0xd7f7, 0xb6b3, 0xffff, 0xc2a9, 0xb3e6, 0x3dea, 0xffff, 0xffff, 0xffff, 0xb7c3, 0xffff, 0xd7ee, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3deb, 0x3dec, 0xffff, 0xd7fa, 0x3ded, 0xd7fd, 0xd8a1, 0xffff, 0x3dee, 0xffff, 0x3def, 0xbcbd, 0x3df0, 0xd8a7, 0xc4f0, 0xd7fb, 0x3df1, 0xffff, 0xffff, 0x3df2, 0xd8a5, 0x3df3, 0xb2f9, 0x3df4, 0xd8a3, 0xd8a4, 0x3df5, 0xffff, 0xd7fe, 0xd8a2, 0xffff, 0x3df6, 0x3df7, 0xb8e7, 0xcdaa, 0xffff, 0x3df8, 0xb4b5, 0x3df9, 0x3dfa, 0xb1d9, 0xd8a6, 0x3dfb, 0xc7ba, 0xb0ad, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3dfc, 0x3dfd, 0xc8e1, 0xd7dc, 0xd8ac, 0xd8b0, 0xcce5, 0x3dfe, 0xd8a9, 0xffff, 0xffff, 0x3ea1, 0xc5e9, 0xd8ae, 0x3ea2, 0xffff, 0xffff, 0xffff, 0x3ea3, 0xffff, 0x3ea4, 0xbef0, 0xd8af, 0xc6d7, 0x3ea5, 0x3ea6, 0x3ea7, 0x3ea8, 0xffff, 0xffff, 0x3ea9, 0x3eaa, 0xffff, 0xcfc7, 0xffff, 0xd8ab, 0x3eab, 0x3eac, 0xffff, 0xffff, 0xd8b1, 0x3ead, 0xb9fb, 0x3eae, 0xc0cb, 0x3eaf, 0x3eb0, 0xb0d4, 0xd8aa, 0xd8a8, 0x3eb1, 0xc1da, 0xffff, 0x3eb2, 0xffff, 0xd7fc, 0xbbb4, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc2c6, 0xd8bd, 0x3eb3, 0xc1db, 0xd8b8, 0x3eb4, 0xd8b5, 0xd8b6, 0x3eb5, 0xbce6, 0xd8b9, 0xd8bc, 0x3eb6, 0x3eb7, /* 0x61: 0x00 - 0xff */ 0xd8b7, 0xbda5, 0x3eb8, 0xd8ba, 0xffff, 0xffff, 0xd8b4, 0x3eb9, 0xccfc, 0xccfb, 0x3eba, 0xffff, 0x3ebb, 0xd8be, 0xd8bf, 0xb0d5, 0x3ebc, 0x3ebd, 0x3ebe, 0x3ebf, 0x3ec0, 0xd8b3, 0x3ec1, 0x3ec2, 0xffff, 0x3ec3, 0xb6f2, 0xb0a6, 0x3ec4, 0xffff, 0x3ec5, 0xb4b6, 0xffff, 0xd8bb, 0x3ec6, 0xffff, 0xffff, 0xffff, 0xffff, 0xd8c3, 0xd8c2, 0xffff, 0x3ec7, 0x3ec8, 0xd8c7, 0xffff, 0xffff, 0xffff, 0x3ec9, 0x3eca, 0xffff, 0xffff, 0xd8c8, 0x3ecb, 0x3ecc, 0x3ecd, 0xffff, 0x3ece, 0xffff, 0xffff, 0xd8c6, 0xd8c9, 0xd8c1, 0xd8c5, 0xffff, 0x3ecf, 0xd8ca, 0xffff, 0xd8cb, 0x3ed0, 0x3ed1, 0xd8c0, 0xbbfc, 0x3ed2, 0xd8c4, 0xc2d6, 0xb9b2, 0xd8b2, 0xbfb5, 0xffff, 0xffff, 0xffff, 0xffff, 0xd8d8, 0xffff, 0xcae9, 0xffff, 0xffff, 0xd8ce, 0xd8cf, 0xd8d0, 0xffff, 0xffff, 0xd8d7, 0x3ed3, 0xd8d6, 0x3ed4, 0xffff, 0xcbfd, 0xb4b7, 0xffff, 0xd8d4, 0xffff, 0xb7c5, 0xb3b4, 0xffff, 0xffff, 0xd8d1, 0x3ed5, 0xffff, 0xceb8, 0xd8d3, 0xb0d6, 0xd8d5, 0x3ed6, 0xd8cc, 0xd8d2, 0xd8d9, 0xb7c4, 0xd8cd, 0x3ed7, 0xffff, 0xffff, 0x3ed8, 0x3ed9, 0xffff, 0xcddd, 0x3eda, 0x3edb, 0x3edc, 0xcdab, 0x3edd, 0x3ede, 0xffff, 0xffff, 0xd8dc, 0xffff, 0xffff, 0xd8e0, 0x3edf, 0xffff, 0x3ee0, 0xc1fe, 0xffff, 0xcef9, 0xd8e1, 0x3ee1, 0x3ee2, 0xd8de, 0xffff, 0xd8db, 0x3ee3, 0x3ee4, 0xd8da, 0xd8df, 0xffff, 0x3ee5, 0x3ee6, 0xffff, 0x3ee7, 0x3ee8, 0xffff, 0xffff, 0xffff, 0xcab0, 0x3ee9, 0xffff, 0xc6b4, 0x3eea, 0xb7c6, 0x3eeb, 0xd8e2, 0xd8dd, 0x3eec, 0xd8e3, 0xffff, 0xffff, 0xffff, 0xb7fb, 0xffff, 0xffff, 0xffff, 0xb2b1, 0xffff, 0x3eed, 0x3eee, 0xd8eb, 0xffff, 0x3eef, 0xffff, 0xb4b8, 0xffff, 0x3ef0, 0x3ef1, 0x3ef2, 0xd8e9, 0xffff, 0xffff, 0xd8ea, 0xbaa9, 0xd8e8, 0xd8e6, 0xd8e5, 0xd8ec, 0xd8e4, 0xd8ee, 0x3ef3, 0x3ef4, 0xb2fb, 0xffff, 0xffff, 0xffff, 0xffff, 0x3ef5, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3ef6, 0x3ef7, 0x3ef8, 0x3ef9, 0xffff, 0x3efa, 0x3efb, 0xd8f0, 0xffff, 0x3efe, 0xd8ef, 0x3efc, 0xffff, 0x3efd, 0xffff, 0xffff, 0x3fa1, 0x3fa2, 0xffff, 0x3fa3, 0xffff, 0xffff, 0xc4a8, 0xffff, 0xd8f3, 0xffff, 0xd8f1, 0xd8e7, 0xb7fc, 0xffff, 0xd8f2, 0xffff, 0xd8f6, 0xd8f5, 0xd8f7, 0xd8f4, /* 0x62: 0x00 - 0xff */ 0xd8f8, 0x3fa4, 0xffff, 0x3fa5, 0x3fa6, 0xffff, 0xffff, 0x3fa7, 0xd8f9, 0xd8fa, 0xcaea, 0xffff, 0xd8fc, 0xd8fb, 0xbdbf, 0xffff, 0xc0ae, 0xb2e6, 0xb2fc, 0x3fa8, 0xd8fd, 0x3fa9, 0xb0bf, 0xffff, 0xffff, 0xffff, 0xc0cc, 0xd8fe, 0x3faa, 0xecc3, 0xd9a1, 0xb7e1, 0x3fab, 0xd9a2, 0x3fac, 0x3fad, 0xffff, 0xffff, 0xc0ef, 0x3fae, 0xffff, 0x3faf, 0xd9a3, 0x3fb0, 0xffff, 0xffff, 0xd9a4, 0xb5ba, 0xd9a5, 0xffff, 0xd9a6, 0xd9a7, 0xc2d7, 0xffff, 0xffff, 0xffff, 0xb8cd, 0x3fb1, 0xffff, 0xcce1, 0xffff, 0x3fb2, 0xffff, 0xcbbc, 0xbdea, 0xd9a8, 0x3fb3, 0x3fb4, 0x3fb5, 0xffff, 0x3fb6, 0xc0f0, 0xeebd, 0xc8e2, 0xffff, 0xbcea, 0x3fb7, 0xbacd, 0xd9a9, 0xffff, 0x3fb8, 0x3fb9, 0x3fba, 0xc2c7, 0x3fbb, 0xcaa7, 0x3fbc, 0xffff, 0xc2f1, 0xffff, 0x3fbd, 0xd9ac, 0x3fbe, 0xffff, 0xd9aa, 0xffff, 0xd9ad, 0xffff, 0xffff, 0xd9ab, 0x3fbf, 0xffff, 0xffff, 0xffff, 0xd9ae, 0xffff, 0xffff, 0xffff, 0xffff, 0x3fc0, 0xcab1, 0x3fc1, 0xffff, 0xb0b7, 0xffff, 0x3fc2, 0xffff, 0xffff, 0xc9de, 0xffff, 0xffff, 0xc8e3, 0x3fc3, 0xffff, 0xd9af, 0x3fc4, 0xd9b2, 0xbeb5, 0xb5bb, 0xffff, 0xd9b0, 0xd9b7, 0xbeb6, 0xffff, 0xffff, 0xffff, 0xffff, 0xd9b1, 0xc7c4, 0xffff, 0xffff, 0x3fc5, 0x3fc6, 0x3fc7, 0x3fc8, 0xcdde, 0xd9b3, 0xd9b4, 0xd9b8, 0xc5ea, 0xd9b5, 0xb9b3, 0xc0de, 0xffff, 0xffff, 0xd9c6, 0xc8b4, 0xffff, 0xc2f2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3fc9, 0xffff, 0x3fca, 0xffff, 0xffff, 0xc8e4, 0xdaad, 0xffff, 0xffff, 0xffff, 0xffff, 0xcafa, 0xffff, 0x3fcb, 0xffff, 0xc4f1, 0x3fcc, 0x3fcd, 0xffff, 0xcbf5, 0x3fce, 0xd9bb, 0xb2a1, 0xc3ea, 0x3fcf, 0x3fd0, 0xffff, 0xffff, 0xd9c4, 0xffff, 0x3fd1, 0xc3b4, 0xd9be, 0xd9c5, 0xd9c0, 0xd9c7, 0xd9c3, 0xffff, 0xd9c2, 0xc7ef, 0x3fd2, 0xd9bc, 0xb2fd, 0xd9ba, 0xb5f1, 0xc2f3, 0xd9b6, 0x3fd3, 0x3fd4, 0xd9b9, 0xb9b4, 0xc0db, 0x3fd5, 0xbeb7, 0xd9c1, 0xc7d2, 0xffff, 0xffff, 0xb5f2, 0xb3c8, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3fd6, 0xffff, 0xb3e7, 0xbfa1, 0xd9c9, 0xd9ce, 0xffff, 0xd9ca, 0x3fd7, 0xb7fd, 0x3fd8, 0xd9cf, 0xbba2, 0xb9e9, 0xffff, 0xffff, 0xffff, 0xffff, 0x3fd9, 0x3fda, 0xbda6, 0xd9bd, /* 0x63: 0x01 - 0xfa */ 0xbbfd, 0xd9cc, 0x3fdb, 0x3fdc, 0xffff, 0xffff, 0xbbd8, 0xd9cd, 0xb0c4, 0x3fdd, 0x3fde, 0xd9c8, 0x3fdf, 0xffff, 0xffff, 0x3fe0, 0xc4a9, 0xffff, 0x3fe1, 0xffff, 0xffff, 0x3fe2, 0xffff, 0x3fe3, 0xb5f3, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb6b4, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xd9cb, 0xb0a7, 0x3fe4, 0x3fe5, 0xbac3, 0xffff, 0x3fe6, 0xffff, 0xbfb6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3fe7, 0x3fe8, 0xffff, 0xffff, 0x3fe9, 0xc4f2, 0xffff, 0x3fea, 0xc8d4, 0xd9d1, 0xc1de, 0xffff, 0x3feb, 0x3fec, 0x3fed, 0x3fee, 0xffff, 0x3fef, 0xffff, 0xffff, 0xc2aa, 0x3ff0, 0x3ff1, 0xbbab, 0xd9d2, 0x3ff2, 0xd9d4, 0xd9d0, 0xffff, 0x3ff3, 0x3ff4, 0x3ff5, 0xcae1, 0xffff, 0xc4bd, 0x3ff6, 0xffff, 0xffff, 0x3ff7, 0xc1dc, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3ff8, 0x3ff9, 0xcafb, 0xbcce, 0xd9e0, 0xffff, 0xd9df, 0x3ffa, 0x3ffb, 0xbff8, 0xffff, 0xffff, 0x3ffc, 0xb7fe, 0xffff, 0x3ffd, 0x3ffe, 0xd9d9, 0xbeb9, 0x40a1, 0xffff, 0xc6e8, 0xc7b1, 0x40a2, 0x40a3, 0xffff, 0x40a4, 0xd9d7, 0xffff, 0x40a5, 0xc1dd, 0x40a6, 0xffff, 0xffff, 0x40a7, 0xbcf8, 0xd9dc, 0x40a8, 0xffff, 0xbeb8, 0xffff, 0xd9d6, 0xd9db, 0x40a9, 0xffff, 0xc7d3, 0xffff, 0x40aa, 0x40ab, 0xd9d5, 0xffff, 0xb7a1, 0x40ac, 0x40ad, 0xb3dd, 0xffff, 0xffff, 0x40ae, 0xd9dd, 0xceab, 0xbace, 0xc3b5, 0xd9da, 0x40af, 0xc0dc, 0x40b0, 0xb9b5, 0xbfe4, 0xb1e6, 0xc1bc, 0xd9d8, 0xb5c5, 0x40b1, 0x40b2, 0x40b3, 0xffff, 0xffff, 0xb7c7, 0xffff, 0xc4cf, 0xd9de, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc1df, 0xffff, 0x40b4, 0xd9e1, 0xffff, 0xd9e3, 0x40b5, 0xffff, 0xc2b7, 0xd9e9, 0x40b6, 0xd9e4, 0xffff, 0x40b7, 0xd9e6, 0xffff, 0xffff, 0xffff, 0xffff, 0x40b8, 0xc9c1, 0xc4f3, 0x40b9, 0xd9e7, 0x40ba, 0x40bb, 0x40bc, 0xcdac, 0xffff, 0xffff, 0xffff, 0xcdc8, 0xb4b9, 0x40bd, 0xffff, 0xffff, 0xffff, 0x40be, 0xb0ae, 0xffff, 0xd9e5, 0xffff, 0x40bf, 0xffff, 0xffff, 0xffff, 0xd9e2, 0x40c0, 0xffff, 0x40c1, 0xffff, 0xb4f8, 0xffff, 0xffff, 0xffff, 0x40c2, 0x40c3, 0xb1e7, 0x40c4, 0xd9e8, 0xffff, 0x40c5, 0x40c6, 0xcdc9, /* 0x64: 0x06 - 0xff */ 0xd9ec, 0xffff, 0xffff, 0x40c7, 0x40c8, 0xffff, 0xffff, 0xc2bb, 0xffff, 0xd9f3, 0x40c9, 0xffff, 0x40ca, 0xd9ed, 0x40cb, 0xffff, 0xd9ea, 0xd9f1, 0x40cc, 0xffff, 0xffff, 0xffff, 0xd9d3, 0xffff, 0x40cd, 0xffff, 0x40ce, 0xffff, 0x40cf, 0xffff, 0x40d0, 0x40d1, 0xd9ee, 0xffff, 0xd9f2, 0x40d2, 0x40d3, 0xffff, 0xc8c2, 0xc5eb, 0xffff, 0x40d4, 0x40d5, 0xffff, 0xffff, 0xffff, 0xd9eb, 0x40d6, 0xd9ef, 0xffff, 0xffff, 0xffff, 0xb7c8, 0xffff, 0xffff, 0x40d7, 0xbaf1, 0x40d8, 0xffff, 0xffff, 0xc0dd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x40d9, 0xffff, 0xffff, 0xd9f7, 0x40da, 0xffff, 0x40db, 0x40dc, 0x40dd, 0x40de, 0xffff, 0xffff, 0xffff, 0xc5a6, 0xffff, 0x40df, 0x40e0, 0x40e1, 0x40e2, 0xffff, 0x40e3, 0x40e4, 0x40e5, 0xffff, 0x40e6, 0xffff, 0xffff, 0xffff, 0xd9f4, 0xffff, 0xcbe0, 0xffff, 0xffff, 0xffff, 0x40e7, 0xffff, 0xd9f5, 0xffff, 0xffff, 0xffff, 0x40e8, 0x40e9, 0xffff, 0xd9f6, 0xffff, 0xccce, 0xffff, 0xc0a2, 0x40ea, 0xffff, 0x40eb, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb7e2, 0xffff, 0x40ec, 0xffff, 0x40ed, 0xd9fd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x40ee, 0x40ef, 0x40f0, 0xbbb5, 0xd9fa, 0xffff, 0xd9f9, 0xffff, 0xffff, 0x40f1, 0x40f2, 0xc7b2, 0x40f3, 0xffff, 0x40f4, 0xc6b5, 0x40f5, 0xffff, 0x40f6, 0xffff, 0x40f7, 0xc5b1, 0xd9fb, 0x40f8, 0xffff, 0x40f9, 0xd9fc, 0xffff, 0xc9ef, 0x40fa, 0xc7c5, 0xbba3, 0xffff, 0xc0f1, 0xffff, 0xcbd0, 0x40fb, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb3c9, 0xffff, 0xdaa5, 0xd9fe, 0x40fc, 0x40fd, 0x40fe, 0xffff, 0xcdca, 0xdaa7, 0xffff, 0x41a1, 0xdaa3, 0xffff, 0xdaa4, 0xffff, 0x41a2, 0x41a3, 0x41a4, 0x41a5, 0xc1e0, 0x41a6, 0xffff, 0x41a7, 0x41a8, 0xdaa2, 0xffff, 0xd9bf, 0x41a9, 0xffff, 0x41aa, 0xdaa6, 0xffff, 0xdaa1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdaab, 0xdaac, 0xc5a7, 0xdaae, 0x41ab, 0x41ac, 0xbba4, 0xdaa9, 0xffff, 0x41ad, 0x41ae, 0xffff, 0xb5bc, 0x41af, 0xffff, 0xdaaf, 0x41b0, 0xdaa8, 0xdab3, 0xffff, 0xdab2, 0x41b1, 0xdab1, 0x41b2, 0xffff, 0xffff, 0xdab4, 0x41b3, 0xffff, 0xdab6, 0xbef1, 0x41b4, /* 0x65: 0x00 - 0xff */ 0xdab5, 0x41b5, 0xffff, 0xffff, 0x41b6, 0xdab9, 0xffff, 0xffff, 0x41b7, 0x41b8, 0x41b9, 0xffff, 0xffff, 0xffff, 0xffff, 0x41ba, 0xffff, 0xffff, 0xffff, 0x41bb, 0x41bc, 0xffff, 0x41bd, 0xffff, 0xdab7, 0x41be, 0xffff, 0x41bf, 0xdab8, 0xd9f0, 0x41c0, 0x41c1, 0xffff, 0xffff, 0x41c2, 0xdabb, 0xdaba, 0xffff, 0x41c3, 0xffff, 0xffff, 0x41c4, 0xd9f8, 0xdabc, 0xdab0, 0xffff, 0x41c5, 0xbbd9, 0xffff, 0x41c6, 0xffff, 0xffff, 0xdabd, 0xdabe, 0xdac0, 0xdabf, 0xdac1, 0xb2fe, 0x41c7, 0xb9b6, 0x41c8, 0x41c9, 0xcafc, 0xc0af, 0xffff, 0xffff, 0xffff, 0x41ca, 0xffff, 0xb8ce, 0xffff, 0x41cb, 0xdac3, 0x41cc, 0xffff, 0xffff, 0xffff, 0xdac6, 0xffff, 0xc9d2, 0x41cd, 0xb5df, 0x41ce, 0xffff, 0x41cf, 0xdac5, 0xdac4, 0xc7d4, 0xdac7, 0xb6b5, 0xffff, 0xffff, 0xffff, 0xdac9, 0xdac8, 0x41d0, 0x41d1, 0xffff, 0xb4ba, 0xbbb6, 0xffff, 0xffff, 0xc6d8, 0x41d2, 0xffff, 0xffff, 0xffff, 0x41d3, 0xb7c9, 0xffff, 0xffff, 0xffff, 0xbff4, 0xffff, 0xdaca, 0xffff, 0xc0b0, 0xc5a8, 0xffff, 0xc9df, 0xdacb, 0xffff, 0x41d4, 0xffff, 0xffff, 0x41d5, 0xffff, 0xffff, 0xffff, 0x41d6, 0xdacc, 0xdacd, 0xffff, 0x41d7, 0xffff, 0xcab8, 0xd5dd, 0xc0c6, 0x41d8, 0xffff, 0xc9cc, 0xffff, 0xbad8, 0xffff, 0xc8e5, 0xc8c3, 0x41d9, 0xffff, 0xffff, 0x41da, 0xffff, 0xc5cd, 0x41db, 0xcec1, 0xffff, 0xdacf, 0xbcd0, 0x41dc, 0xffff, 0xdad0, 0x41dd, 0xb0b6, 0xffff, 0x41de, 0xb6d4, 0xc0cd, 0x41df, 0xc9e0, 0xffff, 0xffff, 0xffff, 0xdad1, 0xbbc2, 0xc3c7, 0x41e0, 0xbbdb, 0xbfb7, 0xffff, 0x41e1, 0x41e2, 0x41e3, 0xffff, 0xffff, 0xdad2, 0xffff, 0xcafd, 0xffff, 0xffff, 0xb1f7, 0xbbdc, 0xffff, 0x41e4, 0xffff, 0xdad5, 0x41e5, 0xdad3, 0xdad6, 0xceb9, 0xdad4, 0xffff, 0x41e6, 0x41e7, 0xffff, 0xc0fb, 0xdad7, 0xffff, 0x41e8, 0xc2b2, 0x41e9, 0xffff, 0xdad8, 0xffff, 0x41ea, 0xffff, 0x41eb, 0xb4fa, 0x41ec, 0xdada, 0xffff, 0xdad9, 0xffff, 0xffff, 0xffff, 0x41ed, 0xdadb, 0xdadc, 0xb4fb, 0xffff, 0xffff, 0xc6fc, 0xc3b6, 0xb5ec, 0xbbdd, 0xc1e1, 0xffff, 0xffff, 0xbddc, 0xb0b0, 0xffff, 0xffff, 0x41ee, 0xdadd, 0x41ef, 0xffff, 0x41f0, 0x41f1, 0xffff, 0xffff, 0xffff, 0x41f2, 0xb2a2, 0xdae1, 0xffff, 0xffff, 0x41f3, 0x41f4, /* 0x66: 0x00 - 0xff */ 0x41f5, 0xffff, 0xb9b7, 0xdae0, 0x41f6, 0xffff, 0xbaab, 0xbeba, 0x41f7, 0x41f8, 0xdadf, 0xffff, 0xbebb, 0x41f9, 0xccc0, 0xbaaa, 0xffff, 0x41fa, 0x41fb, 0xb0d7, 0xc0ce, 0x41fc, 0x41fd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdae6, 0x41fe, 0x42a1, 0xc0b1, 0xb1c7, 0x42a2, 0x42a3, 0x42a4, 0x42a5, 0xbdd5, 0x42a6, 0xcbe6, 0xbaf2, 0x42a7, 0x42a8, 0x42a9, 0x42aa, 0xbebc, 0x42ab, 0xc0a7, 0x42ac, 0x42ad, 0xffff, 0x42ae, 0xdae5, 0xdae3, 0xdae4, 0x42b0, 0xffff, 0x42af, 0xffff, 0xffff, 0xc3eb, 0xffff, 0xffff, 0xdba6, 0x42b1, 0xdaea, 0xbbfe, 0xb9b8, 0xdae8, 0x42b2, 0x42b3, 0xffff, 0xffff, 0xdae9, 0x42b4, 0xbfb8, 0x42b5, 0xffff, 0x42b7, 0xdae7, 0xffff, 0x42b6, 0xbbaf, 0xffff, 0xffff, 0xffff, 0xffff, 0x42b8, 0x42b9, 0x42ba, 0xffff, 0x42bb, 0x42bc, 0xdaec, 0xdaeb, 0xdaf0, 0x42bd, 0x42be, 0xdaf1, 0xffff, 0xdaed, 0xffff, 0xb3a2, 0xdaee, 0xdaef, 0xc8d5, 0x42c0, 0x42c1, 0x42c2, 0xffff, 0xc9e1, 0xb7ca, 0xdaf2, 0xffff, 0xffff, 0x42c4, 0xc0b2, 0x42c5, 0xbebd, 0x42c7, 0x42c8, 0x42c9, 0xc3d2, 0x42ca, 0x42cc, 0xffff, 0x42c3, 0x42c6, 0x42cb, 0xb6c7, 0xffff, 0xdaf3, 0xdaf7, 0xffff, 0xffff, 0xb2cb, 0xdaf4, 0xdaf6, 0xffff, 0x42cd, 0x42ce, 0x42cf, 0xdaf5, 0xffff, 0x42d0, 0xbdeb, 0x42d1, 0xffff, 0xffff, 0xffff, 0xc3c8, 0xb0c5, 0xdaf8, 0x42d2, 0x42d3, 0x42d4, 0x42d5, 0xdaf9, 0xffff, 0x42d6, 0x42d7, 0xffff, 0xc4aa, 0xffff, 0x42d8, 0xffff, 0xcef1, 0xffff, 0xffff, 0xffff, 0xffff, 0xbbc3, 0xffff, 0x42d9, 0xcaeb, 0xffff, 0xffff, 0x42da, 0x42db, 0xffff, 0xcbbd, 0x42dc, 0xffff, 0xffff, 0xdba2, 0xdafb, 0xffff, 0x42dd, 0xdafe, 0xffff, 0xdafd, 0x42de, 0x42df, 0xdafa, 0x42e0, 0x42e1, 0xdba1, 0xffff, 0xffff, 0xc6de, 0x42e2, 0xdafc, 0xffff, 0xffff, 0x42e3, 0xffff, 0x42e4, 0x42e5, 0xffff, 0xffff, 0xffff, 0xffff, 0x42e6, 0xffff, 0xdba3, 0xffff, 0xffff, 0xbdec, 0xdba4, 0x42e7, 0xcdcb, 0xc7f8, 0xffff, 0x42e8, 0xdba5, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdba7, 0xffff, 0x42e9, 0xdba8, 0xffff, 0x42ea, 0x42eb, 0xffff, 0x42ec, 0xffff, 0xdba9, 0xffff, 0xb6ca, 0xb1c8, 0xb9b9, 0xdbaa, 0xffff, 0xdbab, 0xbdf1, 0xc1e2, 0x42ed, 0x42bf, 0xd2d8, 0xc1be, 0xc1bd, 0xc2d8, /* 0x67: 0x00 - 0xff */ 0xbac7, 0xffff, 0xffff, 0xd0f2, 0xffff, 0x42ee, 0xffff, 0x42ef, 0xb7ee, 0xcdad, 0xffff, 0xcafe, 0xffff, 0xc9fe, 0x42f0, 0xdbac, 0xffff, 0xffff, 0xffff, 0x42f1, 0xbaf3, 0xc4bf, 0xdbad, 0xcfaf, 0xffff, 0x42f2, 0xffff, 0xcbbe, 0x42f3, 0xc4ab, 0xdbae, 0xb4fc, 0x42f4, 0xffff, 0x42f5, 0xffff, 0xffff, 0xffff, 0xdbaf, 0xdbb0, 0xccda, 0xffff, 0xcca4, 0xcbf6, 0xcbdc, 0xbba5, 0xdbb2, 0xffff, 0xffff, 0xbceb, 0xffff, 0x42f6, 0xcbd1, 0xffff, 0xdbb4, 0xdbb7, 0xdbb6, 0xffff, 0xb4f9, 0xffff, 0xffff, 0xb5e0, 0x42f7, 0xdbb3, 0xffff, 0xdbb5, 0xffff, 0xffff, 0xffff, 0x42f8, 0xdbb8, 0x42f9, 0x42fa, 0xbff9, 0xffff, 0xffff, 0x42fb, 0xffff, 0xcdfb, 0xb0c9, 0xbae0, 0xc2bc, 0xffff, 0xbcdd, 0x42fc, 0x42fd, 0xbef3, 0xffff, 0xffff, 0xdbbb, 0xffff, 0xffff, 0xc5ce, 0x42fe, 0xdbb9, 0xc2ab, 0xdbba, 0xbef2, 0xccdd, 0xdbbc, 0xdbbd, 0xcde8, 0x43a1, 0xffff, 0xffff, 0xffff, 0xdbc2, 0xffff, 0x43a2, 0xb9ba, 0x43a3, 0xc7d5, 0xdbbf, 0xc5ec, 0xdade, 0xdae2, 0x43a4, 0xb5cf, 0x43a5, 0xc7c7, 0xffff, 0xffff, 0xffff, 0x43a6, 0xdbc1, 0xffff, 0xbebe, 0xc8c4, 0xffff, 0x43a7, 0xffff, 0xffff, 0x43a8, 0xdbc7, 0xffff, 0xc8fa, 0xffff, 0xdbbe, 0xffff, 0xdbc4, 0xdbc3, 0xffff, 0x43a9, 0x43aa, 0xc0cf, 0x43ab, 0xffff, 0x43ac, 0xffff, 0xcbed, 0x43ad, 0xced3, 0x43ae, 0x43af, 0xcbe7, 0x43b0, 0xb2cc, 0xbbde, 0xffff, 0xffff, 0xcfc8, 0xdbc6, 0xbff5, 0xffff, 0xffff, 0xffff, 0xdbc5, 0xffff, 0xffff, 0xdbc0, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb8cf, 0x43b1, 0x43b2, 0x43b3, 0xdbcc, 0xdbca, 0x43b4, 0xb2cd, 0xdbc8, 0xdbce, 0xdbd4, 0xffff, 0x43b5, 0x43b6, 0x43b7, 0xffff, 0xffff, 0x43b9, 0xc2c8, 0x43ba, 0x43bb, 0xcac1, 0x43bc, 0xdbd6, 0xffff, 0x43bd, 0x43be, 0xc9a2, 0xffff, 0xffff, 0xffff, 0xdbd5, 0xc7f0, 0xcbbf, 0xb4bb, 0x43bf, 0xc0f7, 0xbdc0, 0xffff, 0xffff, 0x43c0, 0xc4d3, 0x43c1, 0xcdae, 0xffff, 0x43c2, 0xdbd1, 0xdbd0, 0xffff, 0xffff, 0x43c3, 0xdbd2, 0xffff, 0xdbcf, 0xffff, 0x43c4, 0xdbd7, 0xffff, 0xdbcd, 0xffff, 0xffff, 0xdbcb, 0xffff, 0xdbd3, 0xdbc9, 0x43c5, 0xc3ec, 0x43c6, 0xccf8, 0xbcc6, 0xbaf4, 0x43c7, 0x43c8, 0xffff, 0x43b8, 0xffff, 0xbaba, 0xffff, 0xffff, 0xcbef, 0xb3c1, /* 0x68: 0x02 - 0xfd */ 0xc4ce, 0xc6ca, 0xb1c9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc0f2, 0x43ca, 0xffff, 0xc0b4, 0xb7aa, 0xffff, 0x43cb, 0xffff, 0xffff, 0xffff, 0x43cc, 0xdbd9, 0x43cd, 0xffff, 0xb9bb, 0xb3fc, 0xffff, 0xffff, 0xffff, 0xffff, 0x43cf, 0x43ce, 0xdbdb, 0xb3f4, 0xdbe1, 0x43d0, 0x43d1, 0xffff, 0x43d2, 0x43d3, 0x43d4, 0xdbde, 0x43d5, 0xc0f3, 0xffff, 0xffff, 0xffff, 0xb3cb, 0xbaac, 0xffff, 0x43d6, 0xb3ca, 0xbacf, 0xffff, 0x43d7, 0xdbdc, 0xb7e5, 0xb7cb, 0xc5ed, 0x43d8, 0x43d9, 0xdbda, 0xffff, 0xb0c6, 0xffff, 0x43da, 0xffff, 0x43db, 0xdbdd, 0xdbdf, 0xffff, 0xb6cd, 0xb7ac, 0x43c9, 0xb4bc, 0xb5cb, 0x43dc, 0xffff, 0x43dd, 0x43de, 0xdbe2, 0xffff, 0x43df, 0xbaf9, 0xcbf1, 0xffff, 0xbbb7, 0xffff, 0xffff, 0xffff, 0xdbe3, 0xffff, 0xffff, 0xffff, 0xc9b0, 0xffff, 0xffff, 0xffff, 0x43e0, 0xffff, 0xffff, 0x43e1, 0x43e2, 0x43e3, 0x43e4, 0x43e5, 0xffff, 0xdbef, 0x43e6, 0xb2b3, 0xdbe4, 0xffff, 0x43e7, 0x43e8, 0x43e9, 0x43ea, 0xffff, 0xdbf5, 0xdbe5, 0xffff, 0xcec2, 0x43eb, 0xdbec, 0x43ec, 0xc7df, 0x43ed, 0xffff, 0x43ee, 0xffff, 0xffff, 0xffff, 0xffff, 0xdbf4, 0xffff, 0xdbe7, 0xffff, 0xffff, 0xffff, 0xb0b4, 0xdbe9, 0xffff, 0x43ef, 0xb9bc, 0x43f0, 0xffff, 0x43f1, 0xdbeb, 0x43f2, 0xdbea, 0xffff, 0xdbe6, 0xdbf1, 0x43f3, 0xbebf, 0x43f4, 0xffff, 0x43f5, 0xd4ed, 0xb8e8, 0xcdfc, 0x43f6, 0x43f7, 0xffff, 0xffff, 0xdbe8, 0x43f8, 0xc4f4, 0xb3a3, 0xbaad, 0x43f9, 0xdbe0, 0xffff, 0xdbf0, 0xb3e1, 0xffff, 0xffff, 0xdbee, 0xdbf2, 0x43fa, 0xc5ee, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb4fe, 0x43fb, 0xdcb2, 0xffff, 0x43fc, 0xccc9, 0xdbf7, 0xb4fd, 0x43fd, 0xdbfe, 0xffff, 0x43fe, 0x44a1, 0x44a2, 0xcbc0, 0x44a3, 0xdca1, 0xdca3, 0x44a4, 0xdca7, 0xdbf9, 0x44a5, 0xc3aa, 0xffff, 0x44a6, 0x44a7, 0xffff, 0xc5ef, 0xdcab, 0xdbfc, 0xffff, 0xdca8, 0xffff, 0x44a8, 0xffff, 0xdca2, 0x44a9, 0xffff, 0x44aa, 0x44ab, 0x44ac, 0x44ad, 0xbfb9, 0xdcac, 0x44ae, 0x44af, 0xc0b3, 0xffff, 0xffff, 0x44b0, 0x44b1, 0xffff, 0xffff, 0xdcaa, 0xb4bd, 0x44b2, 0x44b3, 0x44b4, /* 0x69: 0x00 - 0xff */ 0xcfd0, 0xdbf6, 0xffff, 0xffff, 0xdca6, 0xb0d8, 0x44b5, 0xffff, 0xdbf8, 0x44b6, 0x44b7, 0xccba, 0xdbfd, 0xbfa2, 0xc4c7, 0xdbf3, 0x44b8, 0x44b9, 0xdca5, 0x44ba, 0xffff, 0xffff, 0x44bb, 0x44bc, 0xffff, 0xbffa, 0xdcaf, 0xb3f1, 0xb8a1, 0xffff, 0xffff, 0xffff, 0xffff, 0xdcb1, 0xdbfa, 0xdcb0, 0xffff, 0xdca9, 0xdbfb, 0xffff, 0xdcad, 0xffff, 0xdcae, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdcbf, 0x44bd, 0xffff, 0x44be, 0xc6ce, 0x44bf, 0xdca4, 0xffff, 0x44c0, 0xdcbb, 0xffff, 0x44c1, 0xffff, 0xdcbd, 0xffff, 0xc4d8, 0xffff, 0xffff, 0x44c2, 0xffff, 0xffff, 0x44c3, 0xffff, 0xffff, 0xffff, 0x44c4, 0xcdcc, 0xffff, 0xffff, 0xffff, 0x44c5, 0xffff, 0xffff, 0xffff, 0xffff, 0xc9f6, 0xdcb8, 0xc2ca, 0xffff, 0x44c6, 0xffff, 0xdcbe, 0xc1bf, 0x44c7, 0xdcb5, 0xdcc2, 0xdcc1, 0xffff, 0xc6ef, 0xdcc0, 0xc6ea, 0x44c8, 0x44c9, 0x44ca, 0x44cb, 0xffff, 0x44cc, 0x44cd, 0xdcc4, 0xdcb7, 0x44ce, 0xb6c8, 0xdcba, 0xbddd, 0x44cf, 0x44d0, 0x44d1, 0xc7e0, 0xdcbc, 0xb6cb, 0xffff, 0xdcb4, 0xdcb6, 0xdcb3, 0x44d2, 0x44d3, 0xcfb0, 0xb3da, 0xdcb9, 0x44d4, 0x44d5, 0xdcc3, 0xb3b5, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xbae7, 0xffff, 0xffff, 0x44d6, 0xb1dd, 0xffff, 0xffff, 0xdcd4, 0x44d7, 0xffff, 0xcfb1, 0xdcd7, 0x44d8, 0xffff, 0x44d9, 0xffff, 0xffff, 0xbfba, 0xdcd6, 0xffff, 0xffff, 0xffff, 0xdcd5, 0x44da, 0xffff, 0xffff, 0xffff, 0x44db, 0x44dc, 0xdcd2, 0x44dd, 0xffff, 0xffff, 0x44de, 0xffff, 0x44df, 0xdcc6, 0x44e0, 0xffff, 0xdce3, 0xdcc5, 0xffff, 0xdcd8, 0xffff, 0xffff, 0x44e1, 0x44e2, 0xffff, 0x44e3, 0xdcd0, 0x44e4, 0xffff, 0xdccb, 0xdcc8, 0xffff, 0xdcc9, 0xffff, 0xdcd1, 0xffff, 0x44e5, 0xffff, 0xf4a2, 0x44e6, 0xffff, 0xdcce, 0xb9bd, 0xc4c8, 0xc1e4, 0xdccc, 0xffff, 0xdcc7, 0x44e7, 0xffff, 0xdcca, 0xffff, 0xffff, 0x44e8, 0x44e9, 0xcdcd, 0xcbea, 0xffff, 0xffff, 0xffff, 0xdccf, 0xdcd9, 0xffff, 0xffff, 0xffff, 0x44ea, 0xffff, 0xffff, 0x44eb, 0xffff, 0xdce1, 0xdcda, 0xffff, 0xffff, 0xdce7, 0xffff, 0xdce5, 0x44ec, 0x44ed, 0xffff, 0x44ee, 0xdce0, 0x44ef, 0xffff, 0x44f0, 0xffff, 0xffff, 0xffff, 0xdcdf, 0xffff, 0xc4d0, 0xffff, 0xc1e5, 0x44f1, 0xdcdd, /* 0x6a: 0x00 - 0xfd */ 0x44f2, 0x44f3, 0xdcdb, 0x44f4, 0xffff, 0xdce2, 0xffff, 0xffff, 0xffff, 0xffff, 0xdce8, 0xc8f5, 0xdcee, 0xffff, 0xffff, 0x44f5, 0xffff, 0x44f6, 0xdce9, 0xdcec, 0xdce6, 0x44f7, 0xffff, 0xc3f4, 0xffff, 0xc9b8, 0x44f8, 0xdcdc, 0xffff, 0x44f9, 0xdce4, 0xbec0, 0x44fa, 0xcccf, 0xdcf8, 0xdceb, 0x44fb, 0xffff, 0xffff, 0xffff, 0x44fc, 0xb8a2, 0xb2a3, 0xb3df, 0xffff, 0xffff, 0xdcd3, 0xffff, 0x44fd, 0xffff, 0x44fe, 0xffff, 0x45a1, 0xbec1, 0xdcf0, 0x45a2, 0xdcf7, 0xbcf9, 0xb3f2, 0x45a3, 0xffff, 0xc3ae, 0x45a4, 0x45a5, 0xffff, 0xffff, 0xffff, 0xffff, 0xdced, 0x45a6, 0x45a7, 0xdcf2, 0xdcf6, 0x45a8, 0x45a9, 0xb6b6, 0xffff, 0xffff, 0x45aa, 0xffff, 0x45ab, 0x45ac, 0x45ad, 0xffff, 0xffff, 0x45ae, 0x45af, 0xffff, 0xb5cc, 0xdcf4, 0xffff, 0x45b0, 0xffff, 0xffff, 0xffff, 0xb5a1, 0xffff, 0xc6cb, 0xdcf3, 0xffff, 0x45b1, 0xffff, 0xdcf5, 0x45b2, 0xffff, 0xffff, 0x45b3, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x45b4, 0xdcef, 0x45b5, 0xffff, 0xffff, 0xffff, 0xffff, 0xdcf1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x45b6, 0xb3e0, 0xc3c9, 0x45b7, 0xffff, 0x45b8, 0xdcfc, 0xffff, 0x45b9, 0x45ba, 0xffff, 0x45bb, 0xffff, 0x45bc, 0xffff, 0xdcfa, 0xb8e9, 0xffff, 0xdcf9, 0x45bd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdda1, 0xffff, 0xffff, 0xffff, 0x45be, 0xdbd8, 0x45bf, 0x45c0, 0x45c1, 0xdcfb, 0xffff, 0xdcfd, 0xdcfe, 0xffff, 0x45c2, 0xffff, 0xffff, 0xffff, 0xffff, 0xddac, 0x45c3, 0xdda8, 0xffff, 0xdbed, 0x45c4, 0x45c5, 0x45c6, 0xffff, 0xdda7, 0x45c7, 0xffff, 0xffff, 0xffff, 0xdda6, 0xffff, 0xffff, 0xdda3, 0xffff, 0x45c8, 0x45c9, 0x45ca, 0xffff, 0xdcea, 0xdda5, 0xdda4, 0xffff, 0xffff, 0x45cb, 0xffff, 0x45cd, 0x45cc, 0xffff, 0xffff, 0x45ce, 0xffff, 0xffff, 0xffff, 0x45cf, 0xddaa, 0xffff, 0xcfa6, 0x45d0, 0x45d1, 0x45d2, 0xffff, 0xffff, 0xffff, 0xddad, 0xb6fb, 0x45d3, 0x45d4, 0xdda9, 0xddab, 0xffff, 0xffff, 0xffff, 0xffff, 0x45d5, 0xffff, 0xffff, 0x45d6, 0xc8a7, 0xffff, 0xddae, 0xffff, 0x45d7, 0xffff, 0xffff, 0xffff, 0x45d8, 0x45d9, 0x45da, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xddb2, 0xddaf, 0x45db, 0x45dc, /* 0x6b: 0x02 - 0xff */ 0x45dd, 0x45de, 0xcdf3, 0xddb0, 0x45df, 0x45e0, 0xffff, 0x45e1, 0xdcde, 0xffff, 0xffff, 0xffff, 0xffff, 0x45e2, 0x45e3, 0x45e4, 0xddb3, 0xffff, 0xffff, 0xffff, 0xddb4, 0x45e5, 0xffff, 0xffff, 0xffff, 0x45e6, 0xffff, 0xb1b5, 0x45e7, 0xddb6, 0xb7e7, 0xbca1, 0xffff, 0xb6d5, 0x45e8, 0xffff, 0xffff, 0xb2a4, 0x45e9, 0xffff, 0xffff, 0x45ea, 0x45eb, 0xffff, 0xffff, 0x45ec, 0xffff, 0xffff, 0xcddf, 0xffff, 0xffff, 0x45ed, 0x45ee, 0xddb8, 0xddb7, 0xddba, 0xb5bd, 0x45ef, 0xffff, 0xb6d6, 0xb4be, 0x45f0, 0xffff, 0xffff, 0xffff, 0xddbd, 0xffff, 0xffff, 0x45f1, 0xddbc, 0xffff, 0xddbe, 0x45f2, 0xffff, 0xb2ce, 0x45f3, 0xc3b7, 0xffff, 0xddbf, 0xffff, 0x45f4, 0xb4bf, 0xddc1, 0xffff, 0x45f5, 0xffff, 0x45f6, 0xddc0, 0xffff, 0xddc2, 0xffff, 0x45f7, 0xffff, 0xddc3, 0x45f8, 0xddc4, 0xbbdf, 0xc0b5, 0xbaa1, 0xffff, 0xc9f0, 0x45f9, 0xffff, 0xcae2, 0xcfc4, 0x45fa, 0xffff, 0xffff, 0x45fb, 0xbbf5, 0x45fc, 0xffff, 0xffff, 0xbad0, 0xcef2, 0x45fd, 0xffff, 0xffff, 0xddc5, 0xddc6, 0xffff, 0xbbe0, 0xffff, 0x45fe, 0x46a1, 0xddc7, 0xddc8, 0xffff, 0x46a2, 0xddca, 0xddc9, 0x46a3, 0xcbd8, 0xffff, 0xffff, 0xbdde, 0xbcec, 0xbbc4, 0xffff, 0xddcb, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xddcd, 0xbfa3, 0x46a4, 0xddcc, 0xffff, 0xffff, 0x46a5, 0xffff, 0xffff, 0xddce, 0x46a6, 0x46a7, 0xffff, 0x46a8, 0x46a9, 0xddcf, 0xffff, 0xffff, 0xffff, 0x46aa, 0x46ab, 0xddd0, 0xddd1, 0x46ac, 0x46ad, 0x46ae, 0xddd2, 0x46af, 0xddd4, 0xddd3, 0xddd5, 0xb2a5, 0xc3ca, 0xffff, 0xddd6, 0x46b0, 0x46b1, 0xbba6, 0xb3cc, 0xddd7, 0x46b2, 0x46b3, 0xc5c2, 0xd4cc, 0xffff, 0xffff, 0x46b4, 0x46b5, 0xb5a3, 0xddd8, 0xffff, 0xffff, 0x46b6, 0xffff, 0xddd9, 0x46b7, 0xcaec, 0xcbe8, 0xffff, 0xffff, 0xffff, 0xc6c7, 0xddda, 0xc8e6, 0xffff, 0x46b8, 0xffff, 0xc8fb, 0xffff, 0x46b9, 0xccd3, 0xffff, 0xffff, 0xffff, 0xdddb, 0xffff, 0x46ba, 0xffff, 0x46bb, 0xffff, 0xffff, 0x46bc, 0x46bd, 0xffff, 0xffff, 0xffff, 0xdddd, 0xdddc, 0xffff, 0x46be, 0xdddf, 0xffff, 0x46bf, 0xffff, 0xddde, 0xffff, 0xffff, 0xffff, 0x46c0, 0xffff, 0x46c1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x46c2, /* 0x6c: 0x02 - 0xf4 */ 0x46c3, 0xffff, 0x46c4, 0x46c5, 0xffff, 0xffff, 0xdde1, 0x46c6, 0xffff, 0xffff, 0xffff, 0x46c7, 0x46c8, 0xbbe1, 0x46c9, 0xccb1, 0x46ca, 0xdde2, 0xdde3, 0xffff, 0xffff, 0xb5a4, 0xffff, 0x46cb, 0xffff, 0xdde4, 0xffff, 0xffff, 0xffff, 0x46cc, 0xffff, 0xffff, 0xffff, 0xdde6, 0xdde5, 0xffff, 0x46cd, 0x46ce, 0x46cf, 0xffff, 0xffff, 0xffff, 0x46d0, 0xffff, 0x46d1, 0xffff, 0xffff, 0xffff, 0xffff, 0x46d2, 0xbfe5, 0x46d3, 0x46d4, 0xc9b9, 0xb1ca, 0xffff, 0x46d5, 0x46d6, 0xffff, 0xffff, 0xc8c5, 0x46d7, 0xc4f5, 0xbdc1, 0xb5e1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x46d8, 0x46d9, 0xffff, 0x46da, 0xc8c6, 0x46db, 0xbcae, 0xffff, 0x46dc, 0xffff, 0x46dd, 0xdde8, 0xffff, 0xb4c0, 0xffff, 0x46de, 0xb1f8, 0x46df, 0x46e0, 0xc6f2, 0xdde7, 0xb9be, 0xc3d3, 0xffff, 0xdde9, 0xffff, 0xffff, 0xffff, 0xffff, 0x47b6, 0xddf1, 0xffff, 0xddea, 0x46e1, 0xffff, 0x46e2, 0xffff, 0x46e3, 0xc2c1, 0xffff, 0xb5e2, 0xddf2, 0x46e4, 0xffff, 0x46e5, 0xffff, 0x46e6, 0x46e7, 0xb7e8, 0x46e8, 0xffff, 0xb5a5, 0xddf0, 0xffff, 0xffff, 0xddee, 0xddeb, 0xcde0, 0xffff, 0x46e9, 0x46ea, 0x46eb, 0xc4c0, 0x46ec, 0xffff, 0xffff, 0xc6d9, 0xddec, 0xffff, 0xffff, 0xddf4, 0xffff, 0xddf3, 0xb7a3, 0x46ed, 0x46ee, 0xb2ad, 0x46ef, 0x46f0, 0xbabb, 0xdded, 0xddef, 0x46f1, 0xffff, 0xffff, 0x46f2, 0xffff, 0xcbd7, 0xc2f4, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xcbf7, 0xffff, 0xffff, 0xddfc, 0xffff, 0x46f3, 0xddfd, 0x46f4, 0xb2cf, 0x46f5, 0xffff, 0xffff, 0xffff, 0xcaa8, 0xccfd, 0xdea1, 0xbca3, 0xbec2, 0xddf8, 0xddfe, 0xb1e8, 0xffff, 0xb6b7, 0x46f6, 0xffff, 0xddf5, 0xddfa, 0x46f7, 0xffff, 0xffff, 0xc0f4, 0xc7f1, 0xffff, 0xc8e7, 0x46f8, 0xffff, 0x46f9, 0x46fa, 0x46fb, 0x46fc, 0xddf7, 0x46fd, 0xcba1, 0x46fe, 0xddf9, 0xffff, 0xdea4, 0x47a1, 0xdea2, 0x47a2, 0xddfb, 0xffff, 0xffff, 0x47a3, 0xcba2, 0xc7c8, 0xb5e3, 0xffff, 0xc5a5, 0xffff, 0x47a4, 0xc3ed, 0x47a5, 0xdea5, 0x47a6, 0x47a7, 0xffff, 0x47a8, 0xdea3, 0xc2d9, 0xddf6, 0x47a9, 0xb1cb, 0x47aa, /* 0x6d: 0x04 - 0xfc */ 0x47ab, 0xffff, 0xffff, 0x47ac, 0xffff, 0xffff, 0x47ad, 0xcdce, 0xdeb0, 0xffff, 0x47ae, 0x47af, 0xffff, 0x47b0, 0xdeaf, 0x47b1, 0xffff, 0xffff, 0xffff, 0xc0f6, 0xffff, 0xdeac, 0x47b2, 0xcdec, 0xffff, 0xffff, 0xc6b6, 0xdea6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc4c5, 0x47b3, 0x47b4, 0x47b5, 0xb1cc, 0xb9bf, 0xdea9, 0xffff, 0xffff, 0x47b7, 0x47b8, 0xffff, 0x47b9, 0xbda7, 0xdeae, 0xffff, 0xdead, 0xdea8, 0xffff, 0xdeab, 0x47ba, 0xffff, 0xb3e8, 0x47bb, 0xdeaa, 0xc7c9, 0x47bc, 0xffff, 0xceae, 0xffff, 0xffff, 0xbef4, 0xc0f5, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x47bd, 0xffff, 0xdeb6, 0xdeb4, 0xffff, 0xc9cd, 0xffff, 0x47be, 0x47bf, 0xffff, 0x47c0, 0xffff, 0xdeb1, 0xdeb3, 0x47c1, 0xb1ba, 0x47c2, 0xffff, 0xb9c0, 0xcfb2, 0xffff, 0xb3bd, 0xffff, 0xc9e2, 0x47c3, 0x47c4, 0xffff, 0xffff, 0xffff, 0xcde1, 0xffff, 0xffff, 0xb3a4, 0xbfbb, 0xdeb5, 0xffff, 0xffff, 0x47c5, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x47c6, 0xffff, 0xffff, 0xdeba, 0xffff, 0x47c7, 0xbec3, 0xffff, 0xffff, 0xffff, 0xcdb0, 0xffff, 0xdeb7, 0xffff, 0xffff, 0x47c8, 0x47c9, 0xdeb2, 0x47ca, 0xdeb8, 0x47cb, 0x47cc, 0x47cd, 0xcede, 0xffff, 0xc5f3, 0xc6c2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x47ce, 0xffff, 0x47cf, 0xffff, 0xffff, 0xb3b6, 0xffff, 0xffff, 0xb1d5, 0xffff, 0x47d0, 0xdebe, 0xffff, 0x47d1, 0xdec1, 0x47d2, 0xffff, 0xffff, 0xcec3, 0x47d3, 0xffff, 0x47d4, 0xcde4, 0xffff, 0xffff, 0xffff, 0x47d5, 0xdec8, 0xdec2, 0xdebf, 0x47d6, 0xffff, 0x47d7, 0xced4, 0xdec5, 0xffff, 0x47d8, 0x47d9, 0xffff, 0xbdca, 0xdec7, 0xffff, 0xffff, 0xdecc, 0x47da, 0xffff, 0xc5f1, 0xdeca, 0xffff, 0x47db, 0xffff, 0x47dc, 0xdec4, 0x47dd, 0x47de, 0xc3b8, 0x47df, 0xffff, 0xdecb, 0x47e0, 0xdec0, 0xffff, 0xdec6, 0x47e1, 0xdecd, 0xb0fc, 0xdec3, 0xffff, 0xdece, 0x47e2, 0x47e3, 0xbfbc, 0xffff, 0xbddf, 0x47e4, 0xcaa5, 0x47e5, 0xbaae, 0xffff, 0xdebb, 0xdec9, 0xc5ba, 0x47e6, /* 0x6e: 0x00 - 0xff */ 0x47e7, 0xffff, 0xffff, 0xffff, 0x47e8, 0xc0b6, 0xffff, 0xb3e9, 0xbad1, 0xbec4, 0xdebd, 0xbdc2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb7cc, 0xffff, 0xdebc, 0xffff, 0xffff, 0xffff, 0xded2, 0xbded, 0xb8ba, 0xffff, 0xdee1, 0x47e9, 0xdedb, 0xb5f4, 0xc5cf, 0x47ea, 0xded6, 0xdedf, 0xb0af, 0xb1b2, 0x47eb, 0xffff, 0xb2b9, 0xffff, 0xded8, 0xc2ac, 0xdecf, 0xded1, 0xb9c1, 0xffff, 0xffff, 0x47ec, 0xffff, 0xffff, 0xffff, 0x47ed, 0xffff, 0xdee2, 0x47ee, 0xdedd, 0x47ef, 0x47f0, 0xffff, 0xded5, 0xffff, 0xffff, 0xffff, 0xffff, 0xdedc, 0x47f1, 0x47f2, 0xffff, 0xffff, 0x47f3, 0x47f4, 0xccab, 0x47f5, 0xffff, 0xdeda, 0xdede, 0x47f6, 0xffff, 0x47f7, 0x47f8, 0x47f9, 0x47fa, 0xffff, 0xb8d0, 0x47fb, 0xbec5, 0xffff, 0xffff, 0xc3b9, 0x47fc, 0x47fd, 0x47fe, 0xded4, 0xffff, 0xffff, 0x48a1, 0x48a2, 0xffff, 0xffff, 0xffff, 0xcdaf, 0x48a3, 0xffff, 0xffff, 0xded7, 0xffff, 0xffff, 0xded0, 0xc5f2, 0xffff, 0xffff, 0xded3, 0x48a4, 0xffff, 0xffff, 0xded9, 0xffff, 0xffff, 0xffff, 0xffff, 0x48a5, 0xffff, 0x48a6, 0xcfd1, 0xbcbe, 0xcbfe, 0xffff, 0xdee3, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc8ae, 0x48a7, 0xffff, 0xdeef, 0xb8bb, 0xffff, 0xffff, 0x48a8, 0xffff, 0xffff, 0xbde0, 0xffff, 0xdee5, 0x48a9, 0xffff, 0xffff, 0xceaf, 0xb9c2, 0xffff, 0xdef2, 0x48aa, 0xffff, 0xb0ee, 0xffff, 0xffff, 0xdef0, 0xffff, 0x48ab, 0xffff, 0xffff, 0xdee4, 0xffff, 0xffff, 0x48ac, 0x48ad, 0xdeea, 0xffff, 0x48ae, 0xdeec, 0x48af, 0xffff, 0xffff, 0xcdcf, 0xdee7, 0xffff, 0xffff, 0xc5ae, 0x48b0, 0xffff, 0xdee9, 0xffff, 0x48b1, 0x48b2, 0x48b3, 0xdef1, 0x48b4, 0xdeeb, 0xccc7, 0xffff, 0x48b5, 0x48b6, 0xdee6, 0x48b7, 0xbca2, 0xdefe, 0x48b8, 0x48b9, 0x48ba, 0xffff, 0xb3ea, 0xffff, 0xdee8, 0xdeed, 0xdeee, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc2ec, 0xc2da, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x48bb, 0xdef6, 0x48bc, 0x48bd, 0xdefc, 0xffff, 0xffff, 0xdefa, 0xffff, 0xc5a9, 0xffff, 0xffff, 0xdfa3, 0xdef7, 0x48be, 0xffff, 0x48bf, 0xffff, 0x48c0, 0xdef8, 0xdee0, /* 0x6f: 0x01 - 0xfe */ 0xb5f9, 0xc9ba, 0xffff, 0x48c1, 0xffff, 0xbcbf, 0xffff, 0x48c2, 0xb9f7, 0x48c3, 0xffff, 0x48c4, 0x48c5, 0xffff, 0xcfb3, 0xffff, 0xdef4, 0xffff, 0xdfa2, 0xb1e9, 0xc1e6, 0x48c6, 0xffff, 0x48c7, 0xffff, 0x48c8, 0x48c9, 0xffff, 0xffff, 0xffff, 0xffff, 0xc7f9, 0xffff, 0xb4c1, 0xcefa, 0xffff, 0xffff, 0x48ca, 0xffff, 0xffff, 0x48cb, 0x48cc, 0xcca1, 0xc4d2, 0x48d3, 0xffff, 0x48cd, 0x48ce, 0xdefb, 0xdefd, 0x48cf, 0xffff, 0xffff, 0x48d0, 0xffff, 0xc1b2, 0xffff, 0xffff, 0x48d1, 0x48d2, 0xffff, 0xdfa1, 0xdef9, 0xffff, 0xdef3, 0xffff, 0xffff, 0xffff, 0xb4c3, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x48d4, 0xffff, 0x48d5, 0x48d6, 0x48d7, 0xb7e9, 0xffff, 0xffff, 0x48d8, 0xdfaf, 0x48d9, 0x48da, 0xdfaa, 0xc0f8, 0x48db, 0x48dc, 0xb3e3, 0xffff, 0x48dd, 0x48de, 0xffff, 0xbde1, 0xffff, 0xdfb3, 0xffff, 0x48df, 0xffff, 0xffff, 0xffff, 0x48e0, 0xdfac, 0xc4ac, 0xdfa9, 0xc4d9, 0xffff, 0xffff, 0xffff, 0xdfcc, 0xffff, 0xffff, 0xffff, 0xdfa6, 0xffff, 0xdfa5, 0xffff, 0xdfae, 0x48e1, 0x48e2, 0xffff, 0xdfa8, 0xdfa7, 0xdfad, 0x48e3, 0xc0a1, 0xffff, 0xdfa4, 0x48e4, 0x48e5, 0xffff, 0xffff, 0x48e6, 0x48e7, 0x48e8, 0xdfb0, 0xffff, 0x48e9, 0xdfb1, 0x48ea, 0x48eb, 0x48ec, 0xffff, 0x48ed, 0xb4c2, 0xffff, 0xffff, 0x48ee, 0xffff, 0xffff, 0xffff, 0xffff, 0x48ef, 0x48f0, 0xdfb6, 0xffff, 0xdfb5, 0xdfb7, 0x48f1, 0x48f2, 0x48f3, 0x48f4, 0xffff, 0xdfba, 0xffff, 0xffff, 0xffff, 0x48f5, 0x48f6, 0x48f7, 0xc5c3, 0xffff, 0xdfb4, 0xffff, 0x48f8, 0x48f9, 0xffff, 0xffff, 0xdfb8, 0xffff, 0xffff, 0x48fa, 0xffff, 0xffff, 0xffff, 0xb7e3, 0xc2f9, 0xdfb2, 0xc7bb, 0xffff, 0x48fb, 0xdfb9, 0x48fc, 0x48fd, 0xffff, 0x48fe, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdfbe, 0xdfbc, 0xffff, 0xffff, 0xdfbf, 0xffff, 0x49a1, 0xdfc2, 0xffff, 0xffff, 0x49a2, 0xdfbb, 0xb9ea, 0xc7a8, 0xffff, 0xffff, 0xdeb9, 0xffff, 0xffff, 0xffff, 0x49a3, 0x49a4, 0xffff, 0xcdf4, 0xdfbd, 0xffff, 0xdfc1, 0xc2f5, 0x49a5, 0xdfc0, 0xffff, 0xdfab, 0xffff, 0x49a6, 0xefe9, 0xffff, 0xffff, 0x49a7, 0xdfc5, 0xffff, 0x49a8, 0x49a9, 0xdfc9, /* 0x70: 0x00 - 0xfd */ 0x49aa, 0xdfc7, 0xffff, 0xffff, 0xffff, 0x49ab, 0x49ac, 0x49ad, 0xffff, 0xdfc3, 0xffff, 0xdfc4, 0xffff, 0x49ae, 0xffff, 0xdfc8, 0xffff, 0xdfc6, 0xffff, 0xffff, 0xffff, 0xc9ce, 0xffff, 0x49af, 0xdfce, 0xffff, 0xdfcb, 0xdfca, 0xffff, 0xdfcd, 0xc6d4, 0xdfcf, 0x49b0, 0xffff, 0xffff, 0x49b1, 0xffff, 0xffff, 0xc3f5, 0xc2ed, 0xffff, 0xffff, 0xffff, 0xffff, 0xc0a5, 0xffff, 0xffff, 0x49b2, 0xdfd0, 0xffff, 0xdfd2, 0xffff, 0x49b3, 0xffff, 0xffff, 0x49b4, 0xffff, 0x49b5, 0xffff, 0xffff, 0x49b6, 0xffff, 0xdfd1, 0xffff, 0xffff, 0xffff, 0xffff, 0x49b7, 0x49b8, 0xffff, 0xffff, 0xffff, 0x49b9, 0x49ba, 0x49bb, 0x49bc, 0xdef5, 0xffff, 0x49c1, 0xffff, 0xffff, 0xdfd3, 0xffff, 0xffff, 0x49bd, 0x49be, 0xffff, 0xffff, 0xc6e7, 0xffff, 0xffff, 0xffff, 0xffff, 0x49bf, 0x49c0, 0xffff, 0xffff, 0xffff, 0xffff, 0xdfd4, 0x49c2, 0x49c3, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb2d0, 0x49c4, 0xffff, 0x49c5, 0xc5f4, 0xb3a5, 0xffff, 0xffff, 0xffff, 0xffff, 0x49c6, 0x49c7, 0xffff, 0xb5e4, 0xffff, 0xffff, 0xffff, 0xbcde, 0xbad2, 0x49c8, 0xffff, 0xffff, 0x49c9, 0xffff, 0xffff, 0xffff, 0x49ca, 0x49cb, 0xffff, 0xffff, 0xcfa7, 0xbfe6, 0xffff, 0xffff, 0xffff, 0xb1ea, 0xffff, 0xffff, 0xffff, 0xdfd6, 0xffff, 0x49cc, 0x49cd, 0x49ce, 0x49cf, 0x49d0, 0xdfd5, 0xffff, 0x49d1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x49d2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x49d3, 0xdfd9, 0xc3ba, 0xdfdc, 0xdfd7, 0x49d4, 0x49d5, 0xffff, 0xdfdb, 0x49d6, 0xffff, 0xffff, 0x49d7, 0xdfda, 0xc5c0, 0xb0d9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xcef5, 0xffff, 0x49d8, 0xdfde, 0xffff, 0xffff, 0xffff, 0xb1a8, 0xffff, 0x49d9, 0xffff, 0x49da, 0x49db, 0x49dc, 0x49dd, 0xffff, 0x49de, 0xdfe0, 0xffff, 0xffff, 0x49df, 0xdfdf, 0xffff, 0xdfdd, 0xffff, 0xffff, 0xffff, 0xffff, 0x49e0, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdfd8, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xcba3, 0x49e1, 0xffff, 0xffff, 0xdfe2, /* 0x71: 0x03 - 0xff */ 0x49e2, 0x49e3, 0x49e4, 0x49e5, 0x49e6, 0xffff, 0xdfe1, 0xffff, 0x49e7, 0x49e8, 0xffff, 0xffff, 0x49e9, 0xffff, 0xffff, 0xffff, 0xffff, 0xb1eb, 0xffff, 0xffff, 0xffff, 0xffff, 0xdfe4, 0xcab2, 0xffff, 0xdfe3, 0xffff, 0x49ea, 0xffff, 0x49eb, 0xccb5, 0xffff, 0xffff, 0xffff, 0xffff, 0xbec7, 0xffff, 0xffff, 0xffff, 0xffff, 0x49ec, 0xffff, 0x49ed, 0xffff, 0x49ee, 0x49ef, 0x49f0, 0xffff, 0xffff, 0xffff, 0xffff, 0xc1b3, 0xffff, 0x49f1, 0xffff, 0xffff, 0xffff, 0xbec6, 0xffff, 0xffff, 0xffff, 0xffff, 0x49f2, 0xffff, 0xffff, 0xffff, 0x49f3, 0x49f4, 0x49f5, 0xffff, 0xcefb, 0x49f6, 0x49f7, 0xdfea, 0xffff, 0xc0f9, 0xffff, 0x49f8, 0xffff, 0x49f9, 0xffff, 0xffff, 0xdfe6, 0xdfeb, 0x49fa, 0xffff, 0xb1ec, 0x49fb, 0xffff, 0x49fc, 0xffff, 0x49fd, 0xffff, 0x49fe, 0xffff, 0xdfe9, 0xffff, 0xc7e1, 0xdfe5, 0xdfe8, 0xbec8, 0x4aa1, 0xc8d1, 0xffff, 0xffff, 0xdfec, 0xffff, 0xbcd1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x4aa2, 0xffff, 0xffff, 0xffff, 0xc0fa, 0xffff, 0xffff, 0x4aa3, 0xffff, 0xffff, 0xffff, 0xdfef, 0x4aa4, 0xffff, 0x4aa5, 0xdfe7, 0xffff, 0xb7a7, 0xffff, 0x4aa6, 0xffff, 0xffff, 0xdfed, 0xffff, 0xffff, 0x4aa7, 0xffff, 0xcdd0, 0xdff0, 0xffff, 0xffff, 0xffff, 0xf4a6, 0x4aa8, 0x4aa9, 0xffff, 0xffff, 0xffff, 0xbdcf, 0x4aaa, 0xffff, 0x4aab, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdff1, 0xffff, 0xffff, 0xffff, 0xdff2, 0xffff, 0xffff, 0x4aac, 0x4aad, 0xc7ae, 0x4aae, 0x4aaf, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdff4, 0x4ab0, 0xffff, 0xffff, 0xffff, 0xdff5, 0x4ab1, 0x4ab2, 0x4ab3, 0xffff, 0xc7b3, 0x4ab4, 0xffff, 0xffff, 0xffff, 0xc5f5, 0xdff7, 0xffff, 0x4ab5, 0x4ab6, 0xffff, 0xdff9, 0xffff, 0xced5, 0xffff, 0xdff6, 0x4ab7, 0xdff8, 0xb1ed, 0x4ab8, 0xdff3, 0xffff, 0x4ab9, 0x4aba, 0xffff, 0x4abb, 0xffff, 0xffff, 0xd3db, 0xdffa, 0xffff, 0xffff, 0xffff, 0xffff, 0xc1e7, 0xbbb8, 0xdffc, 0xffff, 0xffff, 0xffff, 0xffff, 0xdffb, 0xbfa4, 0xd2d9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdffd, 0xffff, 0xffff, 0x4abc, 0xe0a1, 0xffff, 0xdfee, 0xdffe, 0xffff, 0x4abd, 0xe0a2, /* 0x72: 0x00 - 0xfe */ 0x4abe, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc7fa, 0x4abf, 0x4ac0, 0x4ac1, 0xffff, 0xffff, 0xffff, 0xe0a3, 0xffff, 0xffff, 0xe0a4, 0xffff, 0xffff, 0x4ac2, 0xffff, 0xffff, 0xffff, 0x4ac3, 0xffff, 0xffff, 0x4ac4, 0xe0a5, 0xffff, 0x4ac5, 0xffff, 0x4ac6, 0xffff, 0xffff, 0xffff, 0xffff, 0x4ac7, 0xffff, 0xffff, 0xffff, 0xe0a6, 0xffff, 0xc4de, 0x4ac8, 0xe0a8, 0xe0a7, 0xffff, 0x4ac9, 0xe0a9, 0xffff, 0xe0aa, 0xffff, 0x4aca, 0xbcdf, 0xc9e3, 0xffff, 0x4acb, 0x4acc, 0xccec, 0xe0ab, 0xe0ac, 0xc1d6, 0xbca4, 0xe0ad, 0xe0ae, 0x4acd, 0x4ace, 0x4acf, 0xffff, 0x4ad0, 0xe0af, 0xcad2, 0xc8c7, 0xffff, 0xffff, 0xe0b0, 0xc7d7, 0xffff, 0x4ad1, 0x4ad2, 0x4ad3, 0xffff, 0xc4ad, 0x4ad4, 0xffff, 0x4ad5, 0x4ad6, 0xffff, 0xe0b1, 0xb2e7, 0x4ad7, 0xb5ed, 0x4ad8, 0xccc6, 0x4ad9, 0xccb6, 0x4ada, 0xb2b4, 0xcfb4, 0x4adb, 0xffff, 0xffff, 0xffff, 0xcbd2, 0x4adc, 0xcaaa, 0xffff, 0x4add, 0xffff, 0xffff, 0x4ade, 0x4adf, 0xffff, 0x4ae0, 0xc0b7, 0xffff, 0xe0b2, 0xffff, 0xffff, 0x4ae1, 0x4ae2, 0xc6c3, 0xffff, 0x4ae3, 0x4ae4, 0xb8a3, 0xe0b3, 0x4ae5, 0xbad4, 0xe0b5, 0xe0b4, 0xffff, 0x4ae6, 0xffff, 0xffff, 0xe0b6, 0xffff, 0x4ae7, 0xffff, 0xffff, 0xffff, 0x4ae8, 0x4ae9, 0xffff, 0xffff, 0xffff, 0xe0b7, 0x4aea, 0xffff, 0xffff, 0xe0b8, 0xffff, 0xffff, 0xffff, 0xffff, 0x4aeb, 0xffff, 0xffff, 0xffff, 0xffff, 0xb5be, 0xffff, 0xe0b9, 0xffff, 0xffff, 0xffff, 0xffff, 0xe0ba, 0x4aec, 0xffff, 0xffff, 0xffff, 0xb8a4, 0x4aed, 0x4aee, 0xc8c8, 0xffff, 0x4aef, 0xe0bc, 0xffff, 0x4af0, 0xffff, 0xbef5, 0xffff, 0xffff, 0xe0bb, 0xffff, 0xffff, 0xffff, 0xffff, 0x4af1, 0xffff, 0xffff, 0x4af2, 0xb6b8, 0xe0bd, 0xe0bf, 0xffff, 0xe0be, 0x4af3, 0xffff, 0x4af4, 0xffff, 0xffff, 0x4af5, 0xffff, 0xe0c0, 0xffff, 0xb8d1, 0xffff, 0xe0c1, 0xffff, 0xffff, 0x4af6, 0x4af7, 0xb6e9, 0x4af8, 0xc1c0, 0xffff, 0xb9fd, 0xffff, 0xffff, 0xffff, 0x4af9, 0xe0c3, 0xe0c4, 0xe0c2, 0xffff, 0xffff, 0x4afa, 0xffff, 0xffff, 0xffff, 0xbced, 0xffff, 0xffff, 0xc6c8, 0xb6b9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x4afb, 0x4afc, 0xffff, 0xffff, 0xe0c6, 0xc3ac, 0xe0c5, 0x4afd, 0x4afe, 0xcfb5, 0xc7e2, 0x4ba1, /* 0x73: 0x02 - 0xff */ 0x4ba2, 0xffff, 0x4ba3, 0x4ba4, 0xffff, 0x4ba5, 0xffff, 0xffff, 0xe0c9, 0x4ba6, 0xffff, 0x4ba7, 0xffff, 0xffff, 0xffff, 0xffff, 0x4ba8, 0x4ba9, 0xffff, 0xffff, 0xe0cb, 0xe0c8, 0x4baa, 0x4bab, 0xffff, 0xccd4, 0xe0ca, 0xe0cc, 0x4bac, 0xcec4, 0xffff, 0xffff, 0x4bad, 0xffff, 0x4bae, 0xe0d0, 0xffff, 0x4baf, 0x4bb0, 0xe0cf, 0xc3f6, 0xc7ad, 0x4bb1, 0xffff, 0xb8a5, 0xe0ce, 0xffff, 0x4bb2, 0x4bb3, 0xffff, 0xe0cd, 0x4bb4, 0xcdb1, 0xcdb2, 0xffff, 0xffff, 0x4bb5, 0x4bb6, 0xffff, 0x4bb7, 0xe0d1, 0xb1ee, 0xffff, 0xffff, 0xffff, 0x4bb8, 0xb9f6, 0xbbe2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x4bb9, 0xe0d2, 0xe0d3, 0x4bba, 0xffff, 0x4bbb, 0xffff, 0xffff, 0xffff, 0x4bbc, 0xe0d5, 0x4bbd, 0xffff, 0xffff, 0xffff, 0xffff, 0x4bbe, 0x4bbf, 0x4bc0, 0x4bc1, 0xffff, 0xffff, 0xbdc3, 0xffff, 0xffff, 0x4bc2, 0x4bc3, 0xe0d7, 0x4bc4, 0xe0d6, 0x4bc5, 0x4bc6, 0xffff, 0x4bc7, 0x4bc8, 0xe0d8, 0x4bc9, 0xb3cd, 0xffff, 0xffff, 0xe0da, 0xffff, 0x4bca, 0xe0d9, 0x4bcb, 0xe0dc, 0xe0db, 0x4bcc, 0xffff, 0xffff, 0xffff, 0x4bcd, 0x4bce, 0xffff, 0x4bcf, 0xb8bc, 0x4bd0, 0x4bd1, 0xcea8, 0xffff, 0xb6cc, 0xffff, 0xb2a6, 0xffff, 0xffff, 0x4bd2, 0xffff, 0x4bd3, 0xffff, 0xffff, 0x4bd4, 0xffff, 0x4bd5, 0xb6ea, 0x4bd6, 0x4bd7, 0xffff, 0xffff, 0xffff, 0x4bd8, 0xffff, 0x4bd9, 0x4bda, 0x4bdb, 0xffff, 0x4bdc, 0xffff, 0xffff, 0x4bdd, 0x4bde, 0xffff, 0xffff, 0xb4e1, 0x4bdf, 0x4be0, 0xffff, 0x4be1, 0xffff, 0xffff, 0xffff, 0xffff, 0xcee8, 0xe0de, 0xffff, 0x4be2, 0xffff, 0x4be3, 0xffff, 0x4be4, 0xffff, 0xe0e0, 0x4be5, 0x4be6, 0xffff, 0x4be7, 0xe0e1, 0xffff, 0xb2d1, 0xffff, 0xffff, 0x4be8, 0x4be9, 0xffff, 0xe0dd, 0x4bea, 0xbbb9, 0x4beb, 0x4bec, 0xc4c1, 0xe0df, 0x4bed, 0xffff, 0xffff, 0x4bee, 0x4bef, 0xffff, 0xffff, 0x4bf0, 0xffff, 0xffff, 0x4bf1, 0xffff, 0xffff, 0xffff, 0x4bf2, 0xe0e4, 0xffff, 0xbcee, 0x4bf3, 0xffff, 0x4bf4, 0xffff, 0xe0e2, 0x4bf5, 0x4bf6, 0xffff, 0x4bf7, 0xb7be, 0xffff, 0xffff, 0xc8c9, 0xe0e3, 0xffff, 0xffff, 0xe0fe, 0xffff, 0xffff, 0x4bf8, 0x4bf9, 0xffff, 0x4bfa, 0xe0e9, 0x4bfb, 0x4bfc, 0x4bfd, 0xffff, 0x4bfe, 0xb8bd, 0x4ca1, /* 0x74: 0x00 - 0xff */ 0x4ca2, 0x4ca3, 0xffff, 0xb5e5, 0x4ca4, 0xe0e6, 0xcdfd, 0x4ca5, 0xffff, 0xceb0, 0x4ca6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x4ca7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x4ca8, 0x4ca9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc2f6, 0xffff, 0x4caa, 0xe0e8, 0x4cab, 0xffff, 0x4cac, 0x4cad, 0x4cae, 0x4caf, 0x4cb0, 0x4cb1, 0x4cb2, 0x4cb3, 0x4cb4, 0x4cb5, 0xe0ea, 0xced6, 0xb6d7, 0xc8fc, 0xc7ca, 0xffff, 0xffff, 0x4cb6, 0xe0eb, 0xffff, 0xffff, 0xffff, 0xffff, 0xe0ed, 0x4cb7, 0xe0f0, 0xffff, 0x4cb8, 0x4cb9, 0xffff, 0x4cba, 0x4cbb, 0xffff, 0xffff, 0xffff, 0x4cbc, 0xffff, 0x4cbd, 0xffff, 0xffff, 0xffff, 0x4cbe, 0x4cbf, 0xffff, 0xffff, 0xe0ec, 0xffff, 0x4cc0, 0xffff, 0xe0ef, 0xb8ea, 0xb1cd, 0xe0f1, 0x4cc1, 0xbff0, 0xe0ee, 0xcedc, 0xffff, 0x4cc2, 0xe0f4, 0xf4a4, 0xffff, 0x4cc3, 0x4cc4, 0x4cc5, 0xe0f2, 0xe0f5, 0x4cc6, 0xffff, 0x4cc7, 0x4cc8, 0xe0e7, 0xe0f3, 0x4cc9, 0x4cca, 0xbabc, 0xffff, 0xffff, 0xe0f6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe0f7, 0xffff, 0x4ccb, 0x4ccc, 0xffff, 0xcdfe, 0xffff, 0x4ccd, 0x4cce, 0x4ccf, 0xffff, 0x4cd0, 0xffff, 0xe0f8, 0xffff, 0xffff, 0xffff, 0x4cd1, 0x4cd2, 0x4cd3, 0x4cd4, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x4cd5, 0x4cd6, 0x4cd7, 0xffff, 0x4cd8, 0xffff, 0xe0f9, 0x4cd9, 0x4cda, 0x4cdb, 0xe0e5, 0x4cdc, 0xffff, 0xffff, 0x4cdd, 0xe0fa, 0x4cde, 0x4cdf, 0x4ce0, 0x4ce1, 0xffff, 0xffff, 0x4ce2, 0x4ce3, 0xb4c4, 0x4ce4, 0x4ce5, 0xffff, 0xffff, 0x4ce6, 0xffff, 0xffff, 0xffff, 0x4ce7, 0xffff, 0x4ce8, 0xffff, 0xbca5, 0xffff, 0x4ce9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x4cea, 0x4ceb, 0xe0fb, 0xffff, 0x4cec, 0xffff, 0xffff, 0xe0fc, 0x4ced, 0xffff, 0xffff, 0x4cee, 0xe0fd, 0xffff, 0xffff, 0xffff, 0x4cef, 0xffff, 0x4cf0, 0x4cf1, 0xb1bb, 0xffff, 0x4cf2, 0x4cf3, 0xe1a1, 0xffff, 0xc9bb, 0xe1a2, 0x4cf4, 0xffff, 0xb4a4, 0xe1a3, 0x4cf5, 0xe1a4, 0x4cf6, 0x4cf7, 0xffff, 0xffff, 0xe1a5, 0x4cf8, 0xe1a7, 0xe1a8, 0xe1a6, 0xffff, 0x4cf9, 0xffff, 0xc9d3, 0xe1aa, 0xe1a9, 0xffff, 0x4cfa, 0x4cfb, 0x4cfc, 0xffff, 0xffff, 0x4cfd, /* 0x75: 0x03 - 0xff */ 0xe1ac, 0xe1ab, 0xe1ad, 0x4cfe, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe1ae, 0xe1b0, 0xe1af, 0xffff, 0xffff, 0xb9f9, 0x4da1, 0xe1b2, 0xffff, 0xe1b1, 0x4da2, 0x4da3, 0xb4c5, 0xffff, 0xbfd3, 0xffff, 0xc5bc, 0xffff, 0xe1b3, 0xc0b8, 0x4da4, 0x4da5, 0xffff, 0xbbba, 0x4da6, 0xb1f9, 0xe1b4, 0x4da7, 0xcdd1, 0x4da8, 0x4da9, 0xcae3, 0xe1b5, 0xffff, 0xffff, 0x4daa, 0xc5c4, 0xcdb3, 0xb9c3, 0xbfbd, 0xffff, 0xffff, 0x4dab, 0xc3cb, 0xd2b4, 0x4dac, 0xc4ae, 0xb2e8, 0xe1b6, 0x4dad, 0x4dae, 0x4daf, 0x4db0, 0xffff, 0xffff, 0x4db1, 0xe1b7, 0xffff, 0xe1bc, 0x4db2, 0x4db3, 0xe1ba, 0xe1b9, 0xdac2, 0xb3a6, 0xe1b8, 0x4db4, 0xb0da, 0x4db5, 0xc8aa, 0x4db6, 0xffff, 0xc8ca, 0xffff, 0xffff, 0x4db7, 0xffff, 0xceb1, 0xe1bd, 0xe1bb, 0xc3dc, 0xc0a6, 0x4db8, 0x4db9, 0xc8ab, 0x4dba, 0xc9ad, 0xffff, 0xe1bf, 0xceac, 0xb7cd, 0xe1c0, 0xffff, 0xe1be, 0xc8d6, 0xe1c1, 0xffff, 0xe1c2, 0xffff, 0x4dbb, 0xb0db, 0x4dbc, 0xffff, 0xbef6, 0xe1c7, 0xffff, 0xe1c4, 0xc6ed, 0xe1c3, 0x4dbd, 0x4dbe, 0x4dbf, 0x4dc0, 0x4dc1, 0x4dc2, 0xb5a6, 0xffff, 0x4dc3, 0xe1ca, 0xffff, 0xffff, 0x4dc4, 0xe1c5, 0xe1c6, 0xffff, 0xe1c9, 0xe1c8, 0xc9a5, 0xffff, 0xffff, 0xc1c2, 0xc1c1, 0x4dc5, 0xb5bf, 0x4dc6, 0x4dc7, 0xe1cb, 0x4dc8, 0xffff, 0xffff, 0xffff, 0x4dc9, 0xe1cc, 0xffff, 0x4dca, 0xe1cd, 0xffff, 0xffff, 0xffff, 0xffff, 0x4dcb, 0xe1cf, 0x4dcc, 0xe1ce, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb1d6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe1d7, 0xc8e8, 0xe1d1, 0x4dcd, 0xe1d3, 0xffff, 0xffff, 0xe1d5, 0xbfbe, 0x4dce, 0xffff, 0xe1d6, 0xe1d4, 0xbcc0, 0x4dcf, 0x4dd0, 0x4dd1, 0xe1d0, 0xe1d2, 0x4dd2, 0xc9c2, 0x4dd3, 0xbec9, 0xffff, 0xffff, 0xe1d9, 0xffff, 0x4dd4, 0xe1d8, 0x4dd5, 0x4dd6, 0xffff, 0xffff, 0xe1da, 0xffff, 0xbca6, 0xbaaf, 0xffff, 0x4dd7, 0xc5f7, 0xe1db, 0xffff, 0xc4cb, 0x4dd8, 0xffff, 0xe1dd, 0x4dd9, 0x4dda, 0x4ddb, 0xcea1, 0xe1dc, 0x4ddc, 0xffff, 0xffff, 0x4ddd, 0xffff, 0xc1e9, 0xffff, 0xffff, 0x4dde, 0xffff, 0x4ddf, 0x4de0, 0xe1e2, 0x4de1, 0xe1e4, 0xe1e5, 0xc3d4, 0xffff, 0xffff, 0xffff, 0xffff, 0x4de2, 0xe1e3, 0xffff, 0xe1e0, 0xffff, 0xe1de, 0xe1df, /* 0x76: 0x00 - 0xfe */ 0x4de3, 0xe1e1, 0x4de4, 0x4de5, 0x4de6, 0xffff, 0xffff, 0x4de7, 0x4de8, 0xe1e8, 0x4de9, 0xe1e6, 0x4dea, 0xe1e7, 0xffff, 0x4deb, 0xffff, 0xffff, 0x4dec, 0x4ded, 0xffff, 0x4dee, 0x4def, 0xffff, 0xffff, 0x4df0, 0xffff, 0x4df1, 0x4df2, 0x4df3, 0x4df4, 0xe1e9, 0xe1eb, 0xe1ec, 0xe1ed, 0x4df5, 0xe1ee, 0x4df6, 0x4df7, 0xe1ea, 0xffff, 0x4df8, 0xffff, 0xffff, 0xffff, 0x4df9, 0xffff, 0xffff, 0xe1f0, 0xffff, 0x4dfa, 0x4dfb, 0xe1ef, 0x4dfc, 0xffff, 0xffff, 0x4dfd, 0x4dfe, 0x4ea1, 0xe1f1, 0x4ea2, 0xffff, 0xffff, 0xffff, 0x4ea4, 0x4ea5, 0xcec5, 0x4ea6, 0x4ea7, 0x4ea8, 0xe1f4, 0xe1f2, 0xe1f3, 0x4ea9, 0x4ea3, 0x4eaa, 0xb4e2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xccfe, 0xffff, 0xffff, 0x4eab, 0xcaca, 0xffff, 0xe1f6, 0x4eac, 0xffff, 0xffff, 0xe1f5, 0xffff, 0xffff, 0x4ead, 0xffff, 0xe1f7, 0xe1f8, 0xffff, 0x4eae, 0x4eaf, 0xffff, 0xe1fc, 0xe1f9, 0xe1fa, 0xe1fb, 0xffff, 0xe1fd, 0x4eb0, 0x4eb1, 0x4eb2, 0xe1fe, 0x4eb3, 0xe2a1, 0xffff, 0x4eb4, 0xffff, 0xe2a2, 0xffff, 0xe2a3, 0xffff, 0xc8af, 0xc5d0, 0xe2a4, 0xc7f2, 0xc9b4, 0xffff, 0xe2a5, 0x4eb5, 0xffff, 0xe2a6, 0xc5aa, 0x4eb6, 0xb3a7, 0xb9c4, 0xe2a7, 0xffff, 0xffff, 0xe2a8, 0x4eb7, 0x4eb8, 0xe2a9, 0xffff, 0xbba9, 0xffff, 0xffff, 0xe2ab, 0xffff, 0x4eb9, 0xe2aa, 0xffff, 0xffff, 0xe2ac, 0xe2ad, 0x4eba, 0x4ebb, 0x4ebc, 0xffff, 0x4ebd, 0x4ebe, 0xffff, 0x4ebf, 0x4ec0, 0x4ec1, 0x4ec2, 0x4ec3, 0x4ec4, 0x4ec5, 0xffff, 0x4ec6, 0xffff, 0xffff, 0x4ec7, 0xc8e9, 0xffff, 0xe2ae, 0xffff, 0xffff, 0xffff, 0xe2af, 0xffff, 0xffff, 0xf3e9, 0xe2b0, 0xe2b1, 0xe2b2, 0xffff, 0xffff, 0x4ec8, 0xffff, 0xbbae, 0xffff, 0x4ec9, 0xe2b3, 0xc7d6, 0xffff, 0x4eca, 0xcbdf, 0xffff, 0xb1ce, 0x4ecb, 0xb1d7, 0x4ecc, 0x4ecd, 0xe2b4, 0x4ece, 0xffff, 0xffff, 0xffff, 0xe2b6, 0xffff, 0x4ecf, 0xffff, 0xe2b5, 0xc5f0, 0xffff, 0x4ed0, 0xffff, 0xc0b9, 0xddb9, 0xffff, 0xe2b7, 0xccc1, 0x4ed1, 0xe2b8, 0xffff, 0xb4c6, 0xc8d7, 0xe2b9, 0x4ed2, 0xe2ba, 0x4ed3, 0xffff, 0xe2bb, 0xffff, 0x4ed4, 0xffff, 0xccdc, 0xffff, 0x4ed5, 0x4ed6, 0xccd5, 0xffff, 0xc4be, 0xffff, 0x4ed7, 0xffff, 0xc1ea, 0x4ed8, 0xffff, 0xe2bd, 0x4ed9, 0xffff, 0xbde2, /* 0x77: 0x00 - 0xfc */ 0x4eda, 0xbeca, 0xffff, 0xffff, 0xe2c0, 0xffff, 0x4edb, 0xe2bf, 0xe2be, 0xc8fd, 0x4edc, 0xb4c7, 0xb8a9, 0xffff, 0x4edd, 0xffff, 0xffff, 0xffff, 0x4ede, 0xffff, 0x4edf, 0x4ee0, 0xffff, 0x4ee1, 0xffff, 0x4ee2, 0x4ee3, 0xe2c6, 0x4ee4, 0xffff, 0xe2c3, 0xbfbf, 0xccb2, 0xffff, 0x4ee5, 0xffff, 0xe2c2, 0xe2c4, 0xe2c5, 0xffff, 0x4ee6, 0xe2c1, 0xffff, 0xffff, 0xffff, 0x4ee7, 0x4ee8, 0x4ee9, 0xffff, 0xffff, 0xffff, 0xffff, 0x4eea, 0x4eeb, 0x4eec, 0xe2c7, 0xe2c8, 0x4eed, 0xc4af, 0xffff, 0xb4e3, 0x4eee, 0x4eef, 0xffff, 0xc3e5, 0xffff, 0x4ef0, 0xffff, 0xffff, 0x4ef1, 0x4ef2, 0xe2c9, 0xffff, 0xffff, 0x4ef3, 0xffff, 0xffff, 0x4ef4, 0x4ef5, 0x4ef6, 0xffff, 0xffff, 0x4ef7, 0xffff, 0xffff, 0xffff, 0x4ef8, 0x4ef9, 0xffff, 0xffff, 0xe2ca, 0xe2cd, 0x4efa, 0xffff, 0x4efb, 0x4efc, 0x4efd, 0xbfe7, 0x4efe, 0xc6c4, 0x4fa1, 0xe2ce, 0xcbd3, 0x4fa2, 0xe2cb, 0xffff, 0x4fa3, 0xe2cc, 0x4fa4, 0xffff, 0xffff, 0xffff, 0x4fa5, 0xffff, 0x4fa6, 0x4fa7, 0x4fa8, 0xffff, 0xffff, 0xffff, 0xffff, 0xe2d1, 0x4fa9, 0xffff, 0xffff, 0x4faa, 0xe2d0, 0xe2cf, 0x4fab, 0xffff, 0xffff, 0xffff, 0x4fac, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe2d3, 0x4fad, 0x4fae, 0xe2d2, 0xffff, 0xffff, 0xe2d4, 0xffff, 0xffff, 0x4faf, 0x4fb0, 0x4fb1, 0xffff, 0xffff, 0xffff, 0x4fb2, 0xffff, 0xffff, 0xffff, 0xe2d6, 0x4fb3, 0xe2d5, 0xffff, 0x4fb4, 0xffff, 0xffff, 0xcacd, 0xffff, 0x4fb5, 0xffff, 0xffff, 0x4fb6, 0xffff, 0xbdd6, 0xcec6, 0x4fb7, 0x4fb8, 0xe2d7, 0x4fb9, 0xffff, 0xc6b7, 0xffff, 0x4fba, 0xe2d8, 0xffff, 0xffff, 0xe2d9, 0xffff, 0xe2dd, 0xe2db, 0xe2dc, 0x4fbb, 0xe2da, 0xffff, 0xffff, 0xffff, 0x4fbc, 0xffff, 0xffff, 0xffff, 0xe2de, 0xffff, 0x4fbd, 0xffff, 0xffff, 0xffff, 0xe2df, 0xffff, 0xffff, 0xffff, 0x4fbe, 0x4fbf, 0xffff, 0xffff, 0x4fc0, 0xffff, 0xe2e0, 0xffff, 0x4fc1, 0xe2e1, 0xccb7, 0xe2e2, 0xffff, 0x4fc2, 0x4fc3, 0x4fc4, 0xffff, 0xccf0, 0xe2e3, 0x4fc5, 0xc3ce, 0x4fc6, 0xc7ea, 0xffff, 0xb6eb, 0x4fc7, 0xffff, 0x4fc8, 0xc3bb, 0xe2e4, 0xb6ba, 0x4fc9, 0x4fca, 0xffff, 0xc0d0, 0x4fcb, 0xffff, 0xffff, 0xffff, 0x4fcc, 0xffff, 0xffff, 0x4fcd, 0xe2e5, /* 0x78: 0x02 - 0xff */ 0xbabd, 0xffff, 0xffff, 0x4fce, 0x4fcf, 0xffff, 0xffff, 0x4fd0, 0xffff, 0xffff, 0xe2e6, 0x4fd1, 0x4fd2, 0xffff, 0xffff, 0x4fd3, 0xe2e7, 0xffff, 0xb8a6, 0xbad5, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x4fd4, 0xffff, 0xffff, 0xe2e9, 0x4fd5, 0x4fd6, 0x4fd7, 0xffff, 0xc5d6, 0xbad6, 0xb5ce, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x4fd8, 0x4fd9, 0xffff, 0x4fda, 0xffff, 0xcba4, 0xffff, 0xc7cb, 0x4fdb, 0xffff, 0x4fdc, 0xffff, 0xffff, 0xc5d7, 0xffff, 0xffff, 0xffff, 0xffff, 0xb9dc, 0xffff, 0xffff, 0xffff, 0x4fdd, 0x4fde, 0xe2eb, 0xffff, 0x4fdf, 0x4fe0, 0xffff, 0xffff, 0xffff, 0x4fe1, 0xffff, 0x4fe2, 0xffff, 0xffff, 0xffff, 0x4fe3, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x4fe4, 0xbecb, 0x4fe5, 0xffff, 0x4fe6, 0x4fe7, 0xffff, 0x4fe8, 0x4fe9, 0xffff, 0xffff, 0xffff, 0x4fea, 0xffff, 0x4feb, 0xceb2, 0xb9c5, 0xffff, 0x4fec, 0xb8a7, 0xffff, 0xffff, 0xc8a3, 0xffff, 0xe2ed, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x4fed, 0xffff, 0xe2ef, 0xffff, 0x4fee, 0xffff, 0xffff, 0xb8eb, 0xffff, 0xffff, 0xffff, 0xffff, 0xe2ee, 0xc4f6, 0xffff, 0xffff, 0x4fef, 0xffff, 0xe2f1, 0xb3b7, 0xe2ec, 0x4ff0, 0xffff, 0xc8ea, 0xffff, 0xb1b0, 0x4ff1, 0xbaec, 0xffff, 0xcfd2, 0x4ff2, 0xffff, 0xe2f0, 0xffff, 0xffff, 0x4ff4, 0x4ff5, 0x4ff6, 0xffff, 0x4ff3, 0xffff, 0xe2f2, 0x4ff7, 0xffff, 0xffff, 0xcacb, 0x4ff8, 0xc0d9, 0xe2f4, 0xffff, 0x4ff9, 0x4ffa, 0xffff, 0xe2f5, 0x4ffb, 0x4ffc, 0x4ffd, 0x4ffe, 0xffff, 0xe2f3, 0xffff, 0xffff, 0xffff, 0xffff, 0xb3ce, 0x50a1, 0xe2fb, 0x50a2, 0xe2fa, 0x50a3, 0xffff, 0xbca7, 0xffff, 0xffff, 0xffff, 0xe2fc, 0xe2f7, 0x50a4, 0x50a5, 0x50a6, 0xe2fd, 0xe2f8, 0x50a7, 0xffff, 0x50a8, 0xffff, 0xc8d8, 0xe2f6, 0x50a9, 0x50aa, 0xe2f9, 0x50ab, 0x50ac, 0xffff, 0xffff, 0xffff, 0xe3a2, 0x50ae, 0xffff, 0xffff, 0xffff, 0x50af, 0x50b0, 0x50b1, 0xffff, 0xffff, 0x50ad, 0xffff, 0x50b2, 0xe3a1, 0xcbe1, 0xffff, 0x50b3, 0xffff, 0xe2fe, 0xffff, 0xffff, 0xb0eb, 0xffff, 0xffff, 0x50b4, 0x50b5, 0xe3a4, 0xffff, 0x50b7, 0x50b8, 0xffff, 0xffff, 0x50b9, 0x50ba, 0xffff, 0xe3a3, 0xffff, 0x50bb, /* 0x79: 0x00 - 0xfc */ 0x50b6, 0xbecc, 0xffff, 0xffff, 0xffff, 0xffff, 0x50bc, 0xe3a5, 0xffff, 0xffff, 0xffff, 0xffff, 0x50bd, 0xffff, 0xc1c3, 0xffff, 0x50be, 0xe3a7, 0xe3a6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe3a8, 0x50bf, 0xffff, 0x50c0, 0xffff, 0x50c1, 0x50c2, 0x50c3, 0xffff, 0xffff, 0xffff, 0xffff, 0x50c4, 0xe2e8, 0x50c5, 0xffff, 0x50c6, 0xe2ea, 0xe3aa, 0xe3a9, 0x50c7, 0xffff, 0xffff, 0xffff, 0x50c8, 0xffff, 0xffff, 0x50c9, 0x50ca, 0xffff, 0xffff, 0xffff, 0xffff, 0xbca8, 0x50cb, 0xcee9, 0x50cc, 0xbcd2, 0x50cd, 0xe3ab, 0xb7b7, 0xffff, 0xffff, 0x50ce, 0x50cf, 0x50d0, 0xb5c0, 0xb5a7, 0xbbe3, 0x50d1, 0x50d2, 0xffff, 0xffff, 0xffff, 0x50d3, 0xcdb4, 0x50d4, 0xffff, 0xe3b1, 0x50d5, 0xe3b0, 0xc1c4, 0xe3ad, 0x50d6, 0xffff, 0xe3af, 0x50d7, 0x50d8, 0xbdcb, 0xbfc0, 0xe3ae, 0xe3ac, 0xffff, 0xc7aa, 0xffff, 0xffff, 0xbecd, 0xffff, 0x50d9, 0xc9bc, 0x50da, 0xffff, 0x50db, 0xffff, 0xbad7, 0xffff, 0xffff, 0xffff, 0xffff, 0x50dc, 0xffff, 0xffff, 0xffff, 0xffff, 0xc5f8, 0xffff, 0x50dd, 0xe3b2, 0x50de, 0x50df, 0xffff, 0x50e0, 0xe3b3, 0xe3c9, 0xb6d8, 0xffff, 0xffff, 0xcfbd, 0xc1b5, 0xffff, 0xffff, 0xffff, 0xffff, 0xe3b4, 0x50e1, 0x50e2, 0xb2d2, 0xc4f7, 0xcaa1, 0xffff, 0x50e3, 0xffff, 0x50e4, 0x50e5, 0x50e6, 0x50e7, 0xffff, 0x50e8, 0xffff, 0xffff, 0x50e9, 0x50ea, 0xe3b5, 0xffff, 0xffff, 0xffff, 0x50eb, 0xffff, 0xffff, 0xffff, 0xffff, 0xb5fa, 0xe3b6, 0x50ec, 0x50ed, 0xe3b8, 0x50ee, 0xffff, 0xffff, 0xe3b9, 0x50ef, 0xc7a9, 0x50f0, 0xffff, 0xe3ba, 0x50f1, 0xffff, 0xffff, 0xffff, 0x50f2, 0xe3bb, 0xe3bc, 0x50f3, 0xffff, 0xb6d9, 0xb2d3, 0xc6c5, 0xbda8, 0xbbe4, 0x50f4, 0xffff, 0x50f5, 0xffff, 0xffff, 0x50f6, 0x50f7, 0xe3bd, 0x50f8, 0xbda9, 0xffff, 0xffff, 0xffff, 0x50f9, 0xffff, 0xb2ca, 0xc9c3, 0xffff, 0x50fa, 0xe3be, 0x50fb, 0xffff, 0xc8eb, 0xffff, 0x50fc, 0xffff, 0xffff, 0x50fd, 0x50fe, 0xc1c5, 0x51a1, 0xe3c1, 0x51a2, 0xe3c2, 0xc7e9, 0x51a3, 0xbfc1, 0xe3bf, 0xffff, 0xc3e1, 0x51a4, 0x51a5, 0xe3c0, 0x51a6, 0xffff, 0xffff, 0xbece, 0x51a7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x51a8, 0xffff, 0xffff, 0xb0dc, 0x51a9, /* 0x7a: 0x00 - 0xff */ 0xb5a9, 0xffff, 0x51aa, 0x51ab, 0xffff, 0xffff, 0xffff, 0x51ac, 0xe3c3, 0x51ad, 0x51ae, 0xc4f8, 0x51af, 0xe3c4, 0xc0c7, 0xffff, 0xffff, 0x51b0, 0xffff, 0xffff, 0xccad, 0x51b1, 0xffff, 0xc9a3, 0xe3c5, 0xe3c6, 0xc3d5, 0x51b2, 0xcec7, 0xffff, 0x51b3, 0xe3c8, 0xe3c7, 0x51b4, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x51b5, 0xffff, 0xffff, 0xffff, 0x51b6, 0xffff, 0x51b7, 0xbcef, 0x51b8, 0x51b9, 0xe3ca, 0xb0f0, 0xffff, 0x51ba, 0x51bb, 0xffff, 0xe3cd, 0x51bc, 0x51bd, 0x51be, 0xe3cb, 0xb2d4, 0xb7ce, 0xe3cc, 0xb9c6, 0xb9f2, 0xffff, 0xcae6, 0xe3ce, 0x51bf, 0x51c0, 0xcbd4, 0x51c1, 0x51c2, 0xe3d0, 0xffff, 0xffff, 0x51c3, 0xc0d1, 0xb1cf, 0xb2ba, 0xb0ac, 0xffff, 0xffff, 0xffff, 0xffff, 0x51c4, 0x51c5, 0xe3cf, 0xffff, 0x51c6, 0xffff, 0xffff, 0x51c7, 0x51c8, 0xffff, 0x51c9, 0x51ca, 0xe3d1, 0xe3d2, 0xbef7, 0xffff, 0x51cb, 0xffff, 0x51cc, 0xffff, 0xe3d3, 0x51cd, 0xb3cf, 0xffff, 0x51ce, 0xffff, 0xffff, 0xe3d5, 0xffff, 0xffff, 0xffff, 0xb7ea, 0x51cf, 0xb5e6, 0xffff, 0x51d0, 0xe3d6, 0xb6f5, 0xffff, 0xffff, 0xe3d7, 0x51d1, 0xc0fc, 0x51d2, 0xc6cd, 0x51d3, 0xc0e0, 0xbaf5, 0x51d4, 0x51d5, 0xffff, 0xe3d8, 0xffff, 0x51d6, 0x51d7, 0xffff, 0xffff, 0xffff, 0xffff, 0x51d8, 0x51d9, 0xc3e2, 0xc1eb, 0x51da, 0xe3da, 0xe3dc, 0xe3d9, 0xe3db, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x51db, 0xb7a2, 0x51dc, 0xffff, 0xffff, 0x51dd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe3dd, 0xb7a6, 0xffff, 0x51de, 0xffff, 0xb5e7, 0xcdd2, 0xe3df, 0xffff, 0xffff, 0x51df, 0xffff, 0x51e0, 0xe3e0, 0xffff, 0xffff, 0x51e1, 0xb1ae, 0x51e2, 0x51e3, 0xffff, 0xffff, 0xe3e3, 0xffff, 0xffff, 0xffff, 0xb3f6, 0xe3e2, 0xe3e1, 0x51e4, 0xe3e5, 0xe3de, 0x51e5, 0xe3e6, 0xcea9, 0x51e6, 0xe3e7, 0x51e7, 0xe3e8, 0xffff, 0x51e8, 0xd4f4, 0xe3ea, 0xffff, 0xe3e9, 0xffff, 0xffff, 0xffff, 0xe3eb, 0xe3ec, 0x51e9, 0xceb5, 0xe3ed, 0xffff, 0xf0ef, 0xbecf, 0xe3ee, 0xe3ef, 0xbdd7, 0xffff, 0xc6b8, 0xe3f0, 0xffff, 0x51ea, 0x51eb, 0xc3a8, 0x51ec, 0x51ed, 0xe3f1, 0xffff, 0xc3bc, 0xe3f2, 0x51ee, 0xffff, 0xffff, 0x51ef, 0xffff, 0xb6a5, 0xffff, 0xd1bf, 0xc3dd, 0xbcb3, 0x51f0, 0xffff, 0x51f1, 0x51f2, 0xb4c8, /* 0x7b: 0x02 - 0xfe */ 0xe3f3, 0xffff, 0xe4a2, 0xffff, 0xe3f6, 0x51f3, 0xb5e8, 0xffff, 0xe3f5, 0xe4a4, 0xffff, 0xffff, 0xffff, 0xe3f4, 0xffff, 0xbed0, 0xffff, 0xffff, 0x51f4, 0xffff, 0xffff, 0xffff, 0xe3f8, 0xe3f9, 0xffff, 0xc5ab, 0xffff, 0xffff, 0xe3fa, 0x51f5, 0xb3de, 0xffff, 0xffff, 0x51f6, 0xffff, 0xbfda, 0xc9e4, 0x51f7, 0xe3fc, 0x51f8, 0x51f9, 0x51fa, 0xc2e8, 0x51fb, 0x51fc, 0x51fd, 0x51fe, 0x52a1, 0xffff, 0xe3f7, 0x52a2, 0xe3fb, 0xe3fd, 0xffff, 0xffff, 0xbafb, 0xffff, 0xffff, 0xffff, 0x52a3, 0xffff, 0x52a4, 0x52a5, 0x52a6, 0xffff, 0xffff, 0xffff, 0xe4a6, 0xc9ae, 0x52a7, 0xc8a6, 0xc5f9, 0xffff, 0xb6da, 0xe4a5, 0xe4a3, 0x52a8, 0xc8b5, 0xe3fe, 0xc3de, 0xc5fb, 0xffff, 0xc5fa, 0x52a9, 0xbaf6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe4b8, 0xffff, 0xffff, 0x52aa, 0xffff, 0xffff, 0xffff, 0x52ab, 0xe4a8, 0x52ac, 0xe4aa, 0xffff, 0x52ad, 0x52ae, 0xffff, 0xe4ad, 0x52af, 0xe4ae, 0x52b0, 0xe4ab, 0xe4ac, 0x52b1, 0x52b2, 0xe4a9, 0xe4a7, 0xffff, 0x52b3, 0xffff, 0xffff, 0xe4a1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x52b4, 0xffff, 0xcacf, 0xb2d5, 0xffff, 0x52b5, 0xffff, 0xe4b5, 0xffff, 0xe4b2, 0x52b6, 0xe4b7, 0x52b7, 0x52b8, 0xe4b6, 0xffff, 0xc7f3, 0xcca7, 0x52b9, 0xbbbb, 0xe4b0, 0xe4b9, 0xe4b4, 0x52ba, 0xe4b3, 0xe4af, 0x52bb, 0xe4b1, 0x52bc, 0xb4c9, 0xffff, 0xffff, 0xffff, 0x52bd, 0xffff, 0xffff, 0xffff, 0xffff, 0xc3bd, 0xffff, 0x52be, 0xc0fd, 0xffff, 0x52bf, 0x52c0, 0xc8a2, 0x52c1, 0xffff, 0xe4be, 0x52c2, 0x52c3, 0xffff, 0xc8a4, 0xffff, 0x52c4, 0x52c5, 0x52c6, 0x52c7, 0xffff, 0xffff, 0xc0e1, 0xe4bb, 0x52c8, 0xffff, 0xc8cf, 0x52c9, 0xe4bf, 0xcad3, 0x52ca, 0xc3db, 0x52cb, 0xe4ba, 0xe4bc, 0xffff, 0xffff, 0xe4bd, 0xffff, 0xffff, 0xffff, 0xffff, 0x52cc, 0xffff, 0x52cd, 0x52ce, 0xffff, 0x52cf, 0x52d0, 0x52d1, 0xffff, 0xe4c0, 0xffff, 0xffff, 0xbcc4, 0xffff, 0xffff, 0xffff, 0xc6c6, 0xe4c5, 0xe4c4, 0xffff, 0x52d2, 0xe4c1, 0x52d3, 0xffff, 0xffff, 0xcfb6, 0xffff, 0xffff, 0xffff, 0xffff, 0x52d4, 0xe4ca, 0x52d5, 0x52d6, 0xe4ce, 0xe4cb, 0x52d7, 0x52d8, 0x52d9, 0xffff, 0x52da, 0xffff, 0x52db, /* 0x7c: 0x00 - 0xfe */ 0xe4c7, 0x52dc, 0x52dd, 0x52de, 0x52df, 0xffff, 0x52e0, 0xe4c8, 0xffff, 0x52e1, 0xffff, 0x52e2, 0x52e3, 0xe4cd, 0x52e4, 0x52e5, 0xffff, 0xe4c2, 0xd2d5, 0xe4c9, 0xe4c3, 0xffff, 0xffff, 0xe4cc, 0xffff, 0x52e6, 0xffff, 0x52e7, 0xffff, 0xffff, 0xffff, 0xe4d2, 0x52e8, 0xb4ca, 0xffff, 0xe4cf, 0xffff, 0x52e9, 0x52ea, 0xe4d0, 0x52eb, 0xffff, 0xe4d1, 0xe4d4, 0x52ec, 0xffff, 0xffff, 0xffff, 0xffff, 0x52ed, 0xffff, 0x52ee, 0x52ef, 0xffff, 0x52f0, 0xe4d3, 0xc8f6, 0x52f1, 0x52f2, 0xffff, 0xffff, 0xe4d5, 0xcefc, 0xcaed, 0xe4da, 0xffff, 0xffff, 0xe4d7, 0xffff, 0xffff, 0x52f3, 0xffff, 0xffff, 0xffff, 0x52f4, 0xffff, 0xe4d6, 0xc0d2, 0xffff, 0xe4d9, 0xe4db, 0x52f6, 0x52f7, 0x52f8, 0xe4d8, 0x52f5, 0xe4df, 0xffff, 0xe4dc, 0x52f9, 0x52fa, 0x52fb, 0x52fc, 0x52fd, 0x52fe, 0xe4dd, 0xe4c6, 0x53a1, 0xffff, 0x53a2, 0xe4de, 0xe4e0, 0xffff, 0x53a3, 0xffff, 0x53a4, 0xffff, 0xffff, 0xe4e1, 0x53a5, 0x53a6, 0xffff, 0x53a7, 0xffff, 0x53a8, 0xcac6, 0xffff, 0xe4e2, 0xffff, 0xffff, 0xffff, 0x53a9, 0xffff, 0xffff, 0x53aa, 0x53ab, 0xcce2, 0xffff, 0xffff, 0xb6ce, 0xb7a9, 0xe4e3, 0xffff, 0xffff, 0x53ac, 0x53ad, 0xffff, 0xcab4, 0xffff, 0xbfe8, 0xffff, 0xccb0, 0xffff, 0x53ae, 0xe4e4, 0xffff, 0xceb3, 0xffff, 0x53af, 0xc7f4, 0xffff, 0xc1c6, 0xc7b4, 0xffff, 0xffff, 0xbdcd, 0xffff, 0xffff, 0x53b0, 0xb0c0, 0x53b1, 0xe4e9, 0xe4e7, 0xffff, 0xe4e5, 0xb4a1, 0x53b2, 0xbed1, 0xe4ea, 0xffff, 0xffff, 0xe4e8, 0xffff, 0xe4e6, 0xe4ee, 0xffff, 0x53b3, 0xe4ed, 0xe4ec, 0xe4eb, 0xffff, 0xffff, 0x53b4, 0x53b5, 0xffff, 0xe4ef, 0x53b6, 0x53b7, 0x53b8, 0xe4f0, 0xc0ba, 0x53b9, 0xe4f1, 0xffff, 0xe4f3, 0xffff, 0x53ba, 0xe4f2, 0xffff, 0x53bb, 0x53bc, 0x53bd, 0xb8d2, 0xffff, 0xffff, 0x53be, 0xc1b8, 0x53bf, 0xffff, 0xffff, 0xe4f5, 0x53c0, 0x53c1, 0x53c2, 0xc5fc, 0x53c3, 0xe4f4, 0x53c4, 0x53c5, 0xffff, 0xe4f6, 0x53c6, 0xcab5, 0xc1ec, 0xb9c7, 0xffff, 0xe4f7, 0xffff, 0xffff, 0xffff, 0x53c7, 0xcec8, 0xffff, 0x53c8, 0xffff, 0x53c9, 0xffff, 0xffff, 0xffff, 0xe4f9, 0xffff, 0xffff, 0xe4fa, 0xffff, 0xe4fb, 0x53ca, 0xe4fc, 0xffff, 0xbbe5, 0xffff, 0xe4fd, 0xb7cf, 0xffff, 0xffff, 0xb5ea, /* 0x7d: 0x00 - 0xfb */ 0xb5aa, 0xffff, 0xe5a1, 0x53cb, 0xccf3, 0xb9c8, 0xe4fe, 0x53cc, 0x53cd, 0x53ce, 0xe5a4, 0xcce6, 0xffff, 0xc7bc, 0xffff, 0x53cf, 0xc9b3, 0x53d0, 0x53d1, 0x53d2, 0xbde3, 0xe5a3, 0x53d3, 0xbcd3, 0xb9c9, 0xbbe6, 0xb5e9, 0xcab6, 0xe5a2, 0x53d4, 0x53d5, 0xffff, 0xc1c7, 0xcbc2, 0xbaf7, 0x53d6, 0xffff, 0xffff, 0x53d7, 0xffff, 0xffff, 0xffff, 0x53d8, 0xbbe7, 0xc4dd, 0x53d9, 0xe5a7, 0xcedf, 0xbad9, 0x53da, 0xe5a8, 0xbfc2, 0xffff, 0xe5aa, 0xffff, 0xffff, 0xffff, 0xbed2, 0xbab0, 0xffff, 0x53db, 0x53dc, 0x53dd, 0xe5a9, 0x53de, 0x53df, 0xbdaa, 0xb8be, 0xc1c8, 0xe5a5, 0xe5ab, 0x53e0, 0x53e1, 0xffff, 0xffff, 0xe5a6, 0xb7d0, 0x53e2, 0xe5ae, 0xe5b2, 0xb7eb, 0x53e3, 0xffff, 0x53e4, 0xffff, 0xffff, 0xe5ad, 0x53e5, 0xffff, 0x53e6, 0x53e7, 0xe5b6, 0x53e8, 0x53e9, 0xb9ca, 0xffff, 0xffff, 0xcded, 0xb0bc, 0xe5b3, 0xffff, 0x53ea, 0xb5eb, 0x53eb, 0xe5b0, 0xffff, 0x53ec, 0xffff, 0xffff, 0xffff, 0xe5b1, 0xffff, 0x53ed, 0xc5fd, 0xe5af, 0xe5ac, 0xffff, 0xb3a8, 0xc0e4, 0xffff, 0x53ee, 0xb8a8, 0x53ef, 0x53f0, 0xffff, 0xe5b8, 0xffff, 0x53f1, 0xffff, 0x53f2, 0x53f3, 0x53f4, 0xffff, 0x53f5, 0x53f6, 0xffff, 0x53f7, 0xe5b5, 0xffff, 0x53f8, 0x53f9, 0x53fa, 0xffff, 0xe5b7, 0xffff, 0x53fb, 0xffff, 0xe5b4, 0xffff, 0xffff, 0x53fc, 0x53fd, 0xffff, 0xb7d1, 0xc2b3, 0xe5b9, 0xc1ee, 0x53fe, 0x54a1, 0xe5c6, 0xffff, 0xffff, 0xe5c2, 0xe5bc, 0xffff, 0xffff, 0x54a2, 0x54a3, 0xffff, 0xffff, 0x54a4, 0xe5c0, 0xbcfa, 0xb0dd, 0xe5bb, 0xe5c3, 0xe5c7, 0xb9cb, 0xccd6, 0x54a5, 0xc4d6, 0xe5bd, 0x54a6, 0x54a7, 0xe5c5, 0x54a8, 0xe5ba, 0xc3be, 0xffff, 0xe5bf, 0xb0bd, 0xccca, 0xffff, 0xffff, 0x54a9, 0x54aa, 0x54ab, 0x54ac, 0x54ad, 0xe5be, 0xffff, 0xffff, 0xb6db, 0xc8ec, 0x54ae, 0x54af, 0x54b0, 0xc1ed, 0xffff, 0xced0, 0xbdef, 0xffff, 0xffff, 0xe5ee, 0xffff, 0x54b1, 0xe5c8, 0x54b2, 0xc0fe, 0xffff, 0xe5c4, 0xe5c9, 0xe5cb, 0xffff, 0xc4f9, 0xe5ce, 0x54b4, 0xffff, 0xe5ca, 0x54b5, 0x54b6, 0xffff, 0xcad4, 0xb4cb, 0x54b7, 0x54b8, 0xcccb, 0x54b9, 0xffff, 0xb0de, 0xffff, 0x54ba, 0xe5cd, 0xffff, 0xcefd, 0x54bb, 0x54bc, 0xffff, 0xffff, 0x54bd, 0x54be, 0xe5cc, /* 0x7e: 0x00 - 0x9e */ 0x54b3, 0xb1ef, 0xffff, 0xffff, 0xc6ec, 0xe5cf, 0xffff, 0xffff, 0x54bf, 0xe5d6, 0xe5d0, 0xe5d7, 0xffff, 0xffff, 0xffff, 0xffff, 0x54c0, 0x54c1, 0xe5d3, 0xffff, 0xffff, 0x54c2, 0xffff, 0x54c3, 0xffff, 0xffff, 0xffff, 0xc7fb, 0x54c4, 0x54c5, 0xbcca, 0xe5d5, 0x54c6, 0xe5d2, 0xe5d8, 0xe5d1, 0xffff, 0xffff, 0xbdc4, 0x54c7, 0x54c8, 0xffff, 0xffff, 0xcba5, 0x54c9, 0x54ca, 0xbdcc, 0x54cb, 0xffff, 0xe5d4, 0xe5e0, 0x54cc, 0xffff, 0xe5dc, 0x54cd, 0xe5df, 0xffff, 0xe5dd, 0xe5e1, 0xe5db, 0xffff, 0xe5c1, 0xc0d3, 0x54ce, 0xffff, 0xc8cb, 0xffff, 0xe5de, 0x54cf, 0x54d0, 0xe5d9, 0x54d1, 0xffff, 0xffff, 0xc1a1, 0xb7d2, 0xffff, 0xbdab, 0x54d2, 0xffff, 0x54d3, 0xffff, 0x54d4, 0xffff, 0xbfa5, 0xc1b6, 0xe5e4, 0xffff, 0x54d5, 0xe5e6, 0xe5e7, 0xffff, 0xffff, 0xe5e3, 0xe5e5, 0x54d6, 0xffff, 0x54d7, 0x54d8, 0xffff, 0xffff, 0x54d9, 0xe5da, 0xe5e2, 0xffff, 0xe5ea, 0xe5e9, 0x54da, 0xffff, 0xcbfa, 0x54db, 0x54dc, 0xb7ab, 0xffff, 0xffff, 0x54dd, 0xffff, 0xffff, 0xffff, 0xffff, 0x54de, 0xe5e8, 0xffff, 0xe5ec, 0xe5eb, 0xe5ef, 0x54df, 0xe5f1, 0xffff, 0x54e0, 0xbbbc, 0xe5ed, 0xffff, 0xffff, 0x54e1, 0x54e2, 0xe5f2, 0xe5f3, 0x54e3, 0xffff, 0xe5f4, 0x54e4, 0xe5fa, 0xc5bb, 0xe5f6, 0x54e5, 0xe5f5, 0xe5f7, 0xe5f8, 0x54e6, 0xe5f9, 0xffff, 0x54e7, 0xffff, 0x54e8, 0xe5fb, 0xe5fc, 0x54e9, 0x54ea, /* 0x7f: 0x36 - 0xff */ 0xb4cc, 0xffff, 0xe5fd, 0xffff, 0xe5fe, 0x54ec, 0x54eb, 0x54ed, 0x54ee, 0x54ef, 0xffff, 0xffff, 0xffff, 0x54f0, 0x54f1, 0xe6a1, 0xffff, 0x54f2, 0xffff, 0xffff, 0xffff, 0xffff, 0xe6a2, 0xe6a3, 0xe6a4, 0x54f3, 0xe6a5, 0xe6a6, 0x54f4, 0x54f5, 0xe6a8, 0xe6a7, 0xffff, 0xffff, 0xe6a9, 0xffff, 0xffff, 0x54f6, 0x54f7, 0x54f8, 0xffff, 0xe6aa, 0xe6ab, 0x54f9, 0xffff, 0x54fa, 0x54fb, 0x54fc, 0x54fd, 0xe6ae, 0xe6ac, 0xe6ad, 0xbae1, 0xb7d3, 0xffff, 0x54fe, 0xc3d6, 0xffff, 0xc8b3, 0x55a1, 0xbdf0, 0xffff, 0xffff, 0xc7cd, 0xffff, 0xc8ed, 0xe6af, 0xd8ed, 0xffff, 0xffff, 0xffff, 0x55a2, 0x55a3, 0x55a4, 0x55a5, 0xffff, 0xe6b0, 0xe6b2, 0xffff, 0xcde5, 0xe6b1, 0xe6b4, 0xe6b3, 0xffff, 0xcdd3, 0x55a6, 0xe6b5, 0x55a7, 0xc8fe, 0x55a8, 0x55a9, 0x55aa, 0xffff, 0xffff, 0xe6b6, 0xffff, 0x55ab, 0x55ac, 0xffff, 0xffff, 0xe6b9, 0xffff, 0x55ad, 0xe6b8, 0xe6b7, 0xffff, 0xffff, 0x55ae, 0x55af, 0xe6ba, 0xb7b2, 0xffff, 0x55b0, 0xffff, 0xc1a2, 0xb5c1, 0x55b1, 0xffff, 0xffff, 0x55b2, 0xe6be, 0xe6bb, 0xffff, 0xffff, 0xe6bc, 0xffff, 0x55b3, 0xffff, 0xe6bf, 0xffff, 0xe6c0, 0xe6bd, 0xffff, 0xffff, 0x55b4, 0xb1a9, 0xffff, 0x55b5, 0x55b6, 0xb2a7, 0xffff, 0x55b7, 0xffff, 0xe6c2, 0xe6c3, 0xffff, 0x55b8, 0xffff, 0xe6c4, 0xffff, 0xcde2, 0xffff, 0x55b9, 0x55ba, 0xffff, 0xffff, 0xbdac, 0xffff, 0xe6c6, 0xe6c5, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x55bb, 0xffff, 0xffff, 0xffff, 0x55bc, 0xbfe9, 0xe6c7, 0xffff, 0x55bd, 0xffff, 0x55be, 0xe6c8, 0xffff, 0x55bf, 0xe6c9, 0xffff, 0xb4e5, 0x55c0, 0xffff, 0x55c1, 0x55c2, 0xb4cd, 0xffff, 0x55c3, 0xe6ca, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe6cb, 0x55c4, 0xcbdd, 0xcde3, 0x55c5, 0x55c6, 0x55c7, /* 0x80: 0x00 - 0xfe */ 0xcdd4, 0xcfb7, 0xffff, 0xb9cd, 0xe6ce, 0xbcd4, 0xe6cd, 0x55c8, 0x55c9, 0xffff, 0x55ca, 0xe6cf, 0xbca9, 0x55cb, 0x55cc, 0x55cd, 0xc2d1, 0x55ce, 0xe6d0, 0x55cf, 0x55d0, 0xb9cc, 0x55d1, 0xccd7, 0xe6d1, 0xe6d2, 0xffff, 0xffff, 0xe6d3, 0x55d2, 0x55d3, 0x55d4, 0x55d5, 0xe6d4, 0xffff, 0xffff, 0x55d6, 0xffff, 0x55d7, 0xffff, 0xe6d5, 0xffff, 0xffff, 0xffff, 0x55d8, 0xffff, 0x55d9, 0xffff, 0x55da, 0xffff, 0xffff, 0xbcaa, 0x55db, 0x55dc, 0xcced, 0x55dd, 0xffff, 0x55de, 0x55df, 0xe6d7, 0x55e0, 0xc3bf, 0x55e1, 0xe6d6, 0x55e2, 0xffff, 0xffff, 0xffff, 0x55e3, 0xffff, 0xe6d9, 0xffff, 0xffff, 0xffff, 0xe6d8, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe6da, 0xffff, 0xffff, 0xffff, 0xc0bb, 0xffff, 0xe6db, 0xffff, 0xe6dc, 0xffff, 0xffff, 0xffff, 0xcab9, 0xe6dd, 0x55e4, 0xc1ef, 0xe6de, 0xffff, 0x55e5, 0xffff, 0x55e6, 0xffff, 0xe6df, 0xffff, 0xffff, 0xffff, 0xffff, 0x55e7, 0xffff, 0xcefe, 0xe6e2, 0x55e8, 0xe6e1, 0xe6e0, 0xc4b0, 0x55e9, 0xe6e3, 0xbfa6, 0xffff, 0xe6e4, 0xffff, 0xffff, 0xffff, 0xe6e5, 0xcfb8, 0xe6e6, 0xffff, 0x55ea, 0xffff, 0xffff, 0xe6e7, 0xe6e9, 0xe6e8, 0xc8a5, 0x55eb, 0xc6f9, 0xffff, 0xcfbe, 0xc8a9, 0xffff, 0x55ec, 0xffff, 0xffff, 0xffff, 0xffff, 0xe6eb, 0xffff, 0xffff, 0xbed3, 0xffff, 0xc9aa, 0xffff, 0xe6ec, 0xe6ea, 0x55ed, 0xb4ce, 0x55ee, 0xffff, 0xffff, 0xb8d4, 0xbbe8, 0xffff, 0xffff, 0xc8ee, 0x55ef, 0x55f0, 0xffff, 0xb8aa, 0xcbc3, 0x55f1, 0xe6ef, 0xe6ed, 0xffff, 0xb9ce, 0xffff, 0xb9cf, 0xb0e9, 0xffff, 0xbae8, 0xffff, 0xffff, 0xffff, 0x55f2, 0x55f3, 0xc7d9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb0df, 0xe6f4, 0xffff, 0xc3c0, 0xffff, 0x55f4, 0xffff, 0xffff, 0xffff, 0xc7d8, 0x55f5, 0xc2db, 0x55f6, 0xffff, 0xffff, 0x55f7, 0xffff, 0x55f8, 0x55f9, 0xe6f6, 0x55fa, 0x55fb, 0xe6f2, 0xe6f5, 0xe6f0, 0xffff, 0xe6f3, 0xcba6, 0xffff, 0x55fc, 0xb8d5, 0xffff, 0xffff, 0xb0fd, 0xe6f1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x55fd, 0x55fe, 0xe6f8, 0x56a1, 0xe6f9, 0x56a2, 0x56a3, 0xc6b9, 0xffff, 0x56a4, 0xffff, 0xb6bb, 0x56a5, 0x56a6, 0xffff, 0xe7a6, 0xc7bd, 0x56a7, /* 0x81: 0x02 - 0xff */ 0xbbe9, 0x56a8, 0xffff, 0xb6bc, 0xc0c8, 0xcfc6, 0xccae, 0xe6f7, 0xc0d4, 0x56a9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x56aa, 0x56ab, 0x56ac, 0xffff, 0xb5d3, 0xe6fa, 0x56ad, 0xffff, 0x56ae, 0xffff, 0x56af, 0xffff, 0xffff, 0xe6fc, 0x56b0, 0xffff, 0xffff, 0x56b1, 0xffff, 0xe6fb, 0xffff, 0xffff, 0x56b2, 0xffff, 0xffff, 0xe6fd, 0x56b3, 0xc3a6, 0xffff, 0xc7be, 0xffff, 0x56b4, 0xffff, 0xffff, 0xffff, 0xc4b1, 0x56b5, 0xffff, 0x56b6, 0xffff, 0xe7a3, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x56b7, 0xe7a2, 0x56b8, 0xffff, 0xffff, 0x56b9, 0xe6fe, 0x56ba, 0xffff, 0xbfd5, 0xffff, 0xc9e5, 0xe7a5, 0x56bb, 0xe7a4, 0xb9d0, 0xcfd3, 0xffff, 0x56bc, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe7b5, 0x56bd, 0x56be, 0xffff, 0xffff, 0xffff, 0xe7a9, 0xe7aa, 0x56bf, 0x56c0, 0x56c1, 0xffff, 0xbcf0, 0xffff, 0x56c2, 0xe7a8, 0x56c3, 0xb9f8, 0xe7a7, 0xffff, 0xffff, 0xe7ab, 0xffff, 0xffff, 0x56c4, 0xc4b2, 0xcaa2, 0xc1a3, 0xffff, 0xffff, 0xffff, 0xffff, 0xc2dc, 0xe7af, 0x56c5, 0xe7b0, 0xe7ac, 0x56c7, 0x56c8, 0x56c9, 0xffff, 0xe7ad, 0xffff, 0xe7ae, 0x56ca, 0xffff, 0xffff, 0x56cb, 0xb9d1, 0x56c6, 0xffff, 0xffff, 0xe7b6, 0xffff, 0xe7b2, 0x56cc, 0xffff, 0x56cd, 0xffff, 0xc9e6, 0x56ce, 0xcbec, 0xc9a8, 0x56cf, 0xffff, 0xe7b1, 0xffff, 0x56d0, 0xe7b4, 0xe7b3, 0xffff, 0xffff, 0xffff, 0xcbc4, 0xe7b7, 0xffff, 0xffff, 0xffff, 0xffff, 0x56d1, 0xffff, 0xe7b8, 0xffff, 0x56d2, 0xc1b7, 0x56d3, 0xe7b9, 0xffff, 0xffff, 0xe7bb, 0xffff, 0xe7bf, 0x56d4, 0xffff, 0xe7bc, 0xe7ba, 0xc7bf, 0xe7bd, 0xffff, 0xe7be, 0x56d6, 0xffff, 0x56d7, 0xb2b2, 0xffff, 0xe7c5, 0xe7c0, 0x56d8, 0x56d5, 0xffff, 0xe7c1, 0x56d9, 0x56da, 0xffff, 0xe7c2, 0xffff, 0xc2a1, 0xffff, 0x56db, 0xffff, 0x56dc, 0xe7c4, 0xe7c3, 0xe7c6, 0x56dd, 0xffff, 0x56de, 0x56df, 0xe7c7, 0xe7c8, 0x56e0, 0xffff, 0xbfc3, 0x56e1, 0xb2e9, 0xffff, 0xe7c9, 0xced7, 0xffff, 0xbcab, 0x56e2, 0x56e3, 0xbdad, 0xffff, 0xffff, 0x56e4, 0x56e5, 0x56e6, 0xbbea, 0xc3d7, 0x56e7, 0x56e8, 0xffff, 0x56e9, 0x56ea, 0xe7ca, 0xe7cb, 0xb1b1, 0x56eb, 0xe7cc, 0x56ec, /* 0x82: 0x00 - 0xfe */ 0x56ed, 0xe7cd, 0xe7ce, 0x56ee, 0xffff, 0xe7cf, 0xffff, 0xe7d0, 0xb6bd, 0xdaaa, 0xe7d1, 0xffff, 0xc0e5, 0xe7d2, 0xbccb, 0x56ef, 0xe7d3, 0xffff, 0xd0b0, 0x56f0, 0x56f1, 0xffff, 0xe7d4, 0xcade, 0xb4dc, 0x56f2, 0x56f3, 0xc1a4, 0xbdd8, 0x56f4, 0xc9f1, 0xbdae, 0xffff, 0x56f5, 0x56f6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x56f7, 0xe7d5, 0xb9d2, 0xe7d6, 0xc8cc, 0xffff, 0xe7e4, 0xffff, 0xffff, 0xffff, 0x56f8, 0xe7d8, 0x56f9, 0xc2c9, 0xc7f5, 0xb8bf, 0xe7d7, 0xc1a5, 0x56fa, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe7d9, 0xffff, 0xffff, 0x56fb, 0x56fc, 0x56fd, 0x56fe, 0xc4fa, 0xffff, 0xffff, 0xffff, 0x57a1, 0xffff, 0xffff, 0x57a2, 0x57a3, 0xffff, 0x57a4, 0xffff, 0xffff, 0xffff, 0xffff, 0x57a5, 0xffff, 0xe7db, 0xe7da, 0xe7dd, 0xffff, 0x57a6, 0xe7dc, 0xffff, 0xe7de, 0x57a7, 0xffff, 0xe7e0, 0x57a8, 0xe7df, 0xffff, 0xb4cf, 0x57a9, 0xe7e1, 0xffff, 0xe7e2, 0xe7e3, 0xffff, 0x57aa, 0xbab1, 0xcec9, 0xffff, 0xe7e5, 0xbfa7, 0xffff, 0x57ab, 0xffff, 0xb1f0, 0xe7e6, 0xe7e7, 0xffff, 0xffff, 0x57ac, 0xffff, 0x57ad, 0xe7e8, 0x57ae, 0x57af, 0x57b0, 0xffff, 0x57b1, 0x57b2, 0xffff, 0xffff, 0x57b3, 0xffff, 0x57b4, 0x57b5, 0xb0f2, 0xffff, 0xe7e9, 0x57b6, 0xffff, 0xffff, 0x57b7, 0xe7ea, 0xffff, 0x57b8, 0xffff, 0x57b9, 0xffff, 0x57ba, 0xc9e7, 0x57bb, 0x57bc, 0xffff, 0xbcc7, 0xffff, 0xe7ec, 0x57bd, 0x57be, 0xffff, 0x57bf, 0x57c0, 0xb3a9, 0xb0b2, 0x57c1, 0x57c2, 0x57c3, 0x57c4, 0xe7eb, 0xe7ee, 0xc7ce, 0x57c5, 0xbfc4, 0x57c6, 0xb2d6, 0x57c7, 0xcba7, 0x57c8, 0xffff, 0xffff, 0x57c9, 0xb7dd, 0xb6dc, 0x57ca, 0xe7ed, 0x57cb, 0xb2ea, 0x57cc, 0x57cd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb4a3, 0x57ce, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x57cf, 0xb1f1, 0xe7f2, 0xceea, 0xc2dd, 0x57d0, 0xffff, 0xc9c4, 0xffff, 0xe7fe, 0x57d1, 0xb2d7, 0xe7fc, 0xffff, 0xe7fa, 0xe7f1, 0x57d2, 0xe7ef, 0x57d3, 0xe7f0, 0x57d4, 0xbce3, 0xb6ec, 0xc3f7, 0x57d5, 0xffff, 0x57d6, 0xc6d1, 0xffff, 0x57d7, 0xffff, 0x57d8, 0xffff, 0xb1d1, 0xffff, 0xe7f4, 0xe7f3, 0xffff, 0x57d9, 0x57da, 0xffff, 0xe7f9, 0xe7f5, 0xe7f8, 0xffff, 0x57db, 0x57dc, /* 0x83: 0x00 - 0xfd */ 0x57dd, 0x57de, 0xccd0, 0xe7f7, 0xb2d8, 0xb3fd, 0xe7fb, 0x57df, 0x57e0, 0xe7fd, 0x57e1, 0x57e2, 0xffff, 0xffff, 0xb7d4, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe8a3, 0xe8ac, 0xe8ad, 0xffff, 0xffff, 0x57e4, 0xb0ab, 0x57e5, 0x57e6, 0x57e7, 0xffff, 0x57e8, 0x57e9, 0xe8b4, 0xffff, 0xffff, 0xffff, 0xffff, 0xb0f1, 0xffff, 0xffff, 0xe8ab, 0x57ea, 0x57eb, 0x57ec, 0xe8aa, 0x57ed, 0xe8a5, 0xe8a4, 0x57ee, 0xe8a2, 0xe8a1, 0xc3e3, 0x57ef, 0xc2fb, 0xe8a7, 0x57f0, 0xffff, 0x57f1, 0x57f2, 0xffff, 0xffff, 0xe8a6, 0xffff, 0x57f3, 0x57f4, 0x57f5, 0xe8a9, 0xffff, 0x57f6, 0xffff, 0xc1f0, 0xb7d5, 0xffff, 0xffff, 0x57f7, 0x57f8, 0xb1c1, 0xe8a8, 0x57f9, 0xb9d3, 0x58be, 0x57e3, 0x57fa, 0x57fb, 0x57fc, 0xc1f1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x57fd, 0xffff, 0xffff, 0xe8ba, 0xffff, 0xe8bb, 0xffff, 0xb2d9, 0x57fe, 0xffff, 0xffff, 0xb2ae, 0xe8b8, 0x58a1, 0xffff, 0x58a2, 0x58a3, 0xffff, 0x58a4, 0xffff, 0x58a5, 0xe8ae, 0x58a6, 0xe8b6, 0xffff, 0xe8bd, 0xe8b7, 0xffff, 0xffff, 0x58a7, 0xe8b5, 0xffff, 0xffff, 0xffff, 0x58a8, 0xe7f6, 0x58a9, 0x58aa, 0xe8b3, 0xffff, 0x58ab, 0x58ac, 0xe8af, 0x58ad, 0x58ae, 0x58af, 0xb4d0, 0xe8b1, 0xe8bc, 0xffff, 0xe8b2, 0xffff, 0xffff, 0xffff, 0x58b0, 0x58b1, 0xe8be, 0x58b2, 0xe8b0, 0xc7fc, 0x58b3, 0x58cc, 0xffff, 0xffff, 0xffff, 0xcde9, 0xffff, 0xffff, 0xffff, 0xe8b9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe8cf, 0x58b4, 0x58b5, 0x58b6, 0xe8c7, 0xffff, 0xffff, 0xffff, 0xbffb, 0xffff, 0x58b7, 0xffff, 0x58b8, 0xb5c6, 0xffff, 0xb6dd, 0xffff, 0xe8c2, 0x58b9, 0x58ba, 0x58bb, 0xffff, 0xb2db, 0x58bc, 0xffff, 0xbed4, 0xffff, 0xe8c5, 0xffff, 0xffff, 0xffff, 0xbada, 0x58bd, 0xffff, 0xc5d1, 0xe8ca, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x58bf, 0xcaee, 0x58c0, 0xe8c1, 0xffff, 0xffff, 0xffff, 0xb2da, 0xb8d6, 0xc9a9, 0xe8cb, 0xffff, 0xe8bf, 0xffff, 0x58c1, 0xe8c8, 0x58c2, 0x58c3, 0xffff, 0xe8d2, 0x58c4, 0xe8c3, /* 0x84: 0x01 - 0xff */ 0x58c5, 0xffff, 0xe8c4, 0xc6ba, 0xffff, 0x58c6, 0xe8c9, 0xffff, 0xffff, 0x58c7, 0xe8c6, 0xcba8, 0xe8cc, 0xb0e0, 0x58c8, 0xffff, 0x58c9, 0xffff, 0xe8c0, 0xffff, 0x58ca, 0xffff, 0xffff, 0xffff, 0x58cb, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe8ce, 0xffff, 0xe8cd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc7eb, 0xe8d4, 0xffff, 0xe8df, 0xffff, 0xffff, 0x58cd, 0xffff, 0xb3fe, 0xffff, 0xffff, 0xffff, 0xe8e2, 0xffff, 0xffff, 0xe8d0, 0x58ce, 0xffff, 0xffff, 0xe8d5, 0xcdee, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x58cf, 0xe8de, 0x58d0, 0x58d1, 0xcdd5, 0x58d2, 0xffff, 0xffff, 0x58d3, 0xceaa, 0x58d4, 0xffff, 0x58d5, 0x58d6, 0xffff, 0xffff, 0xffff, 0x58d7, 0xc3f8, 0x58d8, 0x58d9, 0x58da, 0xb3eb, 0x58db, 0xffff, 0xffff, 0xffff, 0x58dc, 0xc9f2, 0xe8e4, 0xc6a1, 0x58dd, 0x58de, 0xb0b1, 0x58df, 0xffff, 0xe8dd, 0x58e0, 0xe8d9, 0xc1f2, 0xe8d3, 0xe8db, 0xe8e0, 0x58e1, 0xc7ac, 0xffff, 0x58e2, 0x58e3, 0xb0aa, 0x58e4, 0xe8d8, 0x58e5, 0xe8e1, 0xc9f8, 0xffff, 0x58e6, 0x58e7, 0xffff, 0xffff, 0xffff, 0x58e8, 0xe8dc, 0xffff, 0xe8d7, 0x58e9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xbed5, 0xffff, 0xffff, 0xffff, 0xffff, 0xbdaf, 0xffff, 0x58ea, 0x58eb, 0xbcac, 0x58ec, 0xffff, 0xffff, 0xffff, 0xccd8, 0xffff, 0xffff, 0xc9c7, 0xffff, 0x58ed, 0xe8e7, 0xffff, 0xe8f0, 0xffff, 0xffff, 0xffff, 0xffff, 0x58ee, 0xffff, 0x58ef, 0x58f0, 0x58f1, 0xffff, 0xffff, 0xe8da, 0xffff, 0x58f2, 0xffff, 0x58f3, 0xb3f7, 0xffff, 0x58f4, 0xffff, 0xffff, 0xffff, 0xbef8, 0xe8e5, 0x58f5, 0xe8ea, 0xc1f3, 0x58f6, 0x58f7, 0xe8e6, 0x58f8, 0xe8ed, 0x58f9, 0xffff, 0xc3df, 0xffff, 0xe8ee, 0x58fa, 0x58fb, 0xcdd6, 0xe8e3, 0xb3b8, 0x58fc, 0xe8e9, 0xffff, 0x58fd, 0xe8ec, 0xccac, 0xffff, 0x58fe, 0xffff, 0xffff, 0xe8ef, 0xffff, 0xffff, 0xe8e8, 0xe8eb, 0xffff, 0x59a1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x59a2, 0xffff, 0xffff, 0x59a3, 0xffff, 0xcba9, 0xffff, 0xcfa1, 0x59a4, 0x59a5, 0x59a6, 0x59a7, 0xffff, 0xe8f3, 0xffff, 0xffff, 0x59a8, 0xffff, 0xffff, 0x59aa, 0x59ab, 0xe8fa, 0x59ac, 0xffff, 0xe8f2, /* 0x85: 0x00 - 0xff */ 0xbcc3, 0xffff, 0x59ad, 0x59ae, 0xffff, 0xffff, 0xe8d1, 0x59af, 0xffff, 0xffff, 0xffff, 0xffff, 0x59b0, 0xffff, 0x59b1, 0xffff, 0x59b2, 0xcace, 0xffff, 0xcca2, 0xe8f9, 0xe8f8, 0xffff, 0xe8f4, 0xe8f5, 0xffff, 0xb1b6, 0xffff, 0x59b3, 0xffff, 0x59b4, 0xe8f7, 0xffff, 0xe8f1, 0x59b5, 0x59b6, 0x59b7, 0x59b8, 0xc4d5, 0x59b9, 0xffff, 0xffff, 0x59ba, 0x59bb, 0xe8f6, 0xb0fe, 0xffff, 0x59bc, 0xffff, 0xffff, 0x59a9, 0x59bd, 0x59be, 0xc2a2, 0x59bf, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xcac3, 0xffff, 0x59c0, 0xe8fb, 0xe9a1, 0xffff, 0xc8d9, 0xffff, 0xffff, 0x59c1, 0xffff, 0xe8fe, 0xbed6, 0xbcc9, 0xe9a3, 0xffff, 0xffff, 0xb6be, 0x59c2, 0x59c3, 0x59c4, 0x59c5, 0x59c6, 0xffff, 0xe9a4, 0x59c7, 0xc9f9, 0xe8fd, 0x59c8, 0xe8d6, 0xffff, 0x59c9, 0x59ca, 0x59cb, 0x59cc, 0x59cd, 0x59ce, 0x59cf, 0xe8fc, 0x59d0, 0xffff, 0xffff, 0xffff, 0xcfcf, 0xc6a2, 0xc9f3, 0x59d1, 0xffff, 0xe9ab, 0xffff, 0x59d2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe9b1, 0xffff, 0x59d3, 0x59d4, 0x59d5, 0xffff, 0x59d6, 0xe9b2, 0x59d7, 0xe9a5, 0x59d8, 0xffff, 0xffff, 0xc7f6, 0x59d9, 0x59da, 0xe9af, 0xe9a7, 0x59db, 0xe9a9, 0x59dc, 0x59dd, 0xffff, 0xffff, 0x59de, 0xe9b3, 0xe9a8, 0xffff, 0x59df, 0xe9ac, 0xffff, 0xffff, 0xb1f2, 0x59e0, 0xc6e5, 0xffff, 0xe9ad, 0xe9b0, 0x59e1, 0xffff, 0x59e2, 0x59e3, 0xffff, 0x59e4, 0xffff, 0xe9a6, 0x59e5, 0xc1a6, 0x59e6, 0xe9aa, 0xbba7, 0xbfc5, 0xb7b0, 0xccf4, 0x59f4, 0xccf9, 0xbdf2, 0xffff, 0xffff, 0xffff, 0xffff, 0x59e7, 0xffff, 0x59e8, 0x59e9, 0x59ea, 0xe9b7, 0xe9b5, 0xffff, 0x59eb, 0x59ec, 0x59ed, 0x59ee, 0xffff, 0xcfce, 0x59ef, 0xffff, 0xffff, 0xffff, 0xffff, 0x59f0, 0xffff, 0xe9b4, 0x59f1, 0x59f2, 0xffff, 0xcdf5, 0x59f3, 0xe9b6, 0xe9b8, 0xffff, 0xffff, 0xffff, 0xffff, 0xe9b9, 0xffff, 0xffff, 0x59f5, 0xffff, 0x59f6, 0xffff, 0xe9bc, 0xe9ba, 0xffff, 0x59f7, 0x59f8, 0xffff, 0xffff, 0xffff, 0xc6a3, 0xe9bb, 0x59f9, 0xffff, 0x59fa, 0xc8cd, 0xe9ae, 0xffff, 0xffff, 0x59fb, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x59fc, 0xffff, 0xffff, 0x59fd, 0xbdf3, 0xffff, 0xe9bd, 0xe9c2, 0xc1f4, 0x59fe, 0xffff, 0xe9c1, 0x5aa1, /* 0x86: 0x00 - 0xfe */ 0x5aa2, 0xffff, 0xe9a2, 0xffff, 0x5aa3, 0x5aa4, 0xe9c3, 0xc1c9, 0xffff, 0xffff, 0xe9be, 0xe9c0, 0xffff, 0x5aa5, 0x5aa6, 0xffff, 0x5aa7, 0x5aa8, 0x5aa9, 0xe9bf, 0xffff, 0xffff, 0xddb1, 0xdda2, 0x5aaa, 0x5aab, 0xe9c5, 0x5aac, 0xffff, 0xffff, 0x5aad, 0xffff, 0xffff, 0x5aae, 0xe9c4, 0xffff, 0xffff, 0xffff, 0xffff, 0x5aaf, 0xffff, 0x5ab0, 0xffff, 0xffff, 0xffff, 0xcdf6, 0xffff, 0xe2bc, 0xe9c6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x5ab1, 0xffff, 0x5ab2, 0xffff, 0x5ab3, 0xffff, 0x5ab4, 0x5ab5, 0xffff, 0xe9c7, 0x5ab6, 0x38e6, 0x5ab7, 0xffff, 0xffff, 0xffff, 0x5ab8, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe9c8, 0xb8d7, 0xffff, 0xb5d4, 0xffff, 0x5ab9, 0x5aba, 0xe9ca, 0xd1dd, 0x5abb, 0x5abc, 0x5abd, 0x5abe, 0xb5f5, 0xffff, 0xceba, 0x5abf, 0xb6f3, 0xe9cb, 0x5ac0, 0x5ac1, 0x5ac2, 0x5ac3, 0x5ac4, 0xffff, 0xffff, 0xe9cc, 0xffff, 0x5ac5, 0xffff, 0xc3ee, 0x5ac6, 0xffff, 0xffff, 0x5ac7, 0xffff, 0xe9cd, 0xffff, 0xffff, 0xffff, 0x5ac8, 0x5ac9, 0x5aca, 0xffff, 0xc6fa, 0x5acb, 0xb0ba, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x5aed, 0xffff, 0xb2e3, 0xe9d2, 0xe9d3, 0x5acc, 0xffff, 0xffff, 0xffff, 0x5acd, 0xffff, 0xe9ce, 0xffff, 0xbbbd, 0x5ace, 0xffff, 0x5acf, 0xffff, 0x5ad0, 0xffff, 0x5ad1, 0xffff, 0xffff, 0xffff, 0xffff, 0x5ad2, 0xffff, 0xe9cf, 0xc7c2, 0xffff, 0x5ad3, 0x5ad4, 0x5ad5, 0xe9d0, 0xe9d1, 0xe9db, 0xffff, 0x5ad6, 0xffff, 0xe9d5, 0xe9d8, 0x5ad7, 0xffff, 0x5ad8, 0x5ad9, 0x5ada, 0xe9d4, 0x5adb, 0x5adc, 0x5add, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x5ade, 0x5adf, 0x5ae0, 0xffff, 0x5ae1, 0xe9d6, 0x5ae2, 0xe9d7, 0xbcd8, 0xffff, 0xe9d9, 0xffff, 0xc3c1, 0xffff, 0xb7d6, 0xb3c2, 0xffff, 0xffff, 0x5ae3, 0x5ae4, 0xffff, 0xe9dc, 0x5ae5, 0xffff, 0x5ae6, 0xffff, 0xb3bf, 0x5ae7, 0xe9e1, 0x5ae8, 0xffff, 0xe9dd, 0xe9e0, 0x5ae9, 0xffff, 0xffff, 0x5aea, 0xc8ba, 0x5aeb, 0xffff, 0x5aec, 0xffff, 0xe9de, 0xffff, 0xffff, 0xe9df, 0xc9c8, 0xc8da, 0xe9e2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc2fd, 0xe9ec, 0x5aee, 0xe9e8, 0x5aef, 0x5af0, 0xb2eb, /* 0x87: 0x00 - 0xff */ 0xe9e6, 0xffff, 0xcbaa, 0xe9e7, 0x5af1, 0x5af2, 0xe9e4, 0x5af3, 0xe9e5, 0xe9ea, 0xe9ed, 0x5af4, 0xffff, 0xe9eb, 0x5af5, 0x5af6, 0x5af7, 0xe9e9, 0xe9e3, 0x5af8, 0x5af9, 0xffff, 0xffff, 0xffff, 0xc3d8, 0x5afa, 0xe9f4, 0xffff, 0xccaa, 0xffff, 0x5afb, 0x5afc, 0xffff, 0x5afd, 0xffff, 0x5afe, 0xffff, 0xe9f2, 0xffff, 0xffff, 0x5ba1, 0xe9f3, 0xffff, 0xffff, 0xffff, 0xffff, 0x5ba2, 0x5ba3, 0xffff, 0x5ba4, 0x5ba5, 0xffff, 0xe9ee, 0xffff, 0xffff, 0xe9f0, 0xffff, 0x5ba6, 0x5ba7, 0xe9f1, 0x5ba8, 0x5ba9, 0x5baa, 0xe9ef, 0x5bab, 0xffff, 0xffff, 0x5bac, 0xffff, 0x5bad, 0xffff, 0xffff, 0xffff, 0xc0e6, 0xffff, 0xcfb9, 0xe9f8, 0x5bae, 0xe9f9, 0xffff, 0xffff, 0xffff, 0xffff, 0xeaa1, 0xffff, 0xbfaa, 0xffff, 0xe9fb, 0x5baf, 0xe9fe, 0xffff, 0xffff, 0xffff, 0x5bb0, 0xffff, 0xe9f6, 0xe9f5, 0x5bb1, 0xffff, 0xeaa2, 0x5bb2, 0x5bb3, 0xb2dc, 0xffff, 0xe9fc, 0xffff, 0xeaa3, 0xffff, 0xffff, 0xffff, 0xe9fd, 0x5bb4, 0xffff, 0x5bb5, 0x5bb6, 0xffff, 0xe9fa, 0xffff, 0xc4b3, 0xffff, 0xe9f7, 0xffff, 0xffff, 0x5bb7, 0xffff, 0xffff, 0xffff, 0xc7e8, 0xffff, 0xffff, 0xeaa7, 0x5bb8, 0x5bb9, 0x5bba, 0x5bbb, 0x5bbc, 0x5bbd, 0x5bbe, 0xffff, 0x5bbf, 0x5bc0, 0xcdbb, 0xffff, 0xffff, 0x5bc1, 0xffff, 0xffff, 0x5bc2, 0xffff, 0x5bc3, 0xffff, 0x5bc4, 0x5bc5, 0x5bc6, 0xffff, 0xffff, 0xffff, 0xffff, 0x5bc7, 0xeaa6, 0x5bc8, 0xffff, 0xeaa5, 0x5bc9, 0xffff, 0xffff, 0xffff, 0x5bca, 0xffff, 0xffff, 0xffff, 0xeaae, 0x5bcb, 0x5bcc, 0x5bcd, 0xeaa8, 0xffff, 0x5bce, 0xffff, 0xeab0, 0xffff, 0x5bcf, 0xffff, 0xffff, 0xffff, 0xffff, 0xcde6, 0xeab3, 0xffff, 0xeaaa, 0x5bd0, 0x5bd1, 0xeaab, 0x5bd2, 0xffff, 0xffff, 0xeaaf, 0xffff, 0xeab2, 0xeab1, 0x5bd3, 0x5bd4, 0x5bd5, 0xeaa9, 0xffff, 0xffff, 0x5bd6, 0xffff, 0xeaac, 0xffff, 0xeabd, 0xffff, 0xffff, 0x5bd7, 0x5bd8, 0xffff, 0xffff, 0x5bd9, 0x5bda, 0xffff, 0x5bdb, 0xffff, 0xffff, 0x5bdc, 0xeab6, 0xffff, 0x5bdd, 0x5bde, 0x5bdf, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x5be0, 0x5be1, 0xffff, 0x5be2, 0xffff, 0xeab4, 0xffff, 0x5be3, 0xeab5, 0x5be4, 0xffff, 0xffff, 0xeaba, 0xeabb, 0x5be5, 0xb3aa, 0x5be6, 0xb5c2, 0xffff, 0xffff, 0xeab9, 0x5be7, #ifdef split_unicode }; #define split_unicode_offset 239 /* 0x4000 - 16145 */ static const uint16_t __euc_jp_unicode_codes_second[] = { #endif /* 0x88: 0x01 - 0xfe */ 0x5be8, 0xffff, 0x5be9, 0xffff, 0xeaa4, 0x5bea, 0xffff, 0xffff, 0x5beb, 0x5bec, 0x5bed, 0xffff, 0xeab8, 0xeabc, 0xeab7, 0x5bee, 0xeabe, 0x5bf0, 0x5bf1, 0x5bf2, 0xeac0, 0xeabf, 0xffff, 0x5bf3, 0x5bef, 0x5bf4, 0x5bf5, 0x5bf6, 0xffff, 0x5bf7, 0x5bf8, 0xffff, 0xeac2, 0xeac1, 0xe9da, 0xffff, 0xffff, 0xffff, 0xeac6, 0x5bf9, 0xffff, 0xffff, 0xffff, 0xffff, 0x5bfa, 0x5bfb, 0xffff, 0x5bfc, 0xeac3, 0x5bfd, 0xffff, 0xffff, 0x5bfe, 0xeac4, 0xffff, 0xffff, 0xeac5, 0x5ca1, 0xeac7, 0x5ca2, 0xffff, 0xffff, 0xffff, 0xb7ec, 0x5ca3, 0xeac9, 0x5ca4, 0xeac8, 0x5ca5, 0xbdb0, 0xffff, 0x5ca6, 0x5ca7, 0x5ca8, 0x5ca9, 0xb9d4, 0xdea7, 0x5caa, 0xffff, 0xffff, 0x5cab, 0xeaca, 0xbdd1, 0xffff, 0x5cac, 0x5cad, 0xb3b9, 0x5cae, 0xeacb, 0x5caf, 0xb1d2, 0x5cb0, 0xbed7, 0xeacc, 0x5cb1, 0x5cb2, 0xb9d5, 0xeacd, 0xb0e1, 0x5cb3, 0xffff, 0xffff, 0xffff, 0xc9bd, 0x5cb4, 0xffff, 0xeace, 0xffff, 0xffff, 0xffff, 0xffff, 0xbfea, 0x5cb5, 0xead5, 0xffff, 0xffff, 0xead2, 0xffff, 0xc3ef, 0xffff, 0x5cb6, 0xffff, 0x5cb7, 0xffff, 0xead3, 0xead0, 0xb6de, 0x5cb8, 0xeacf, 0xead6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb7b6, 0xffff, 0xffff, 0xc2de, 0xffff, 0xeadc, 0xffff, 0xffff, 0xffff, 0xffff, 0xead8, 0xffff, 0xffff, 0xffff, 0xc2b5, 0xead7, 0x5cb9, 0xeada, 0x5cba, 0x5cbb, 0x5cbc, 0xffff, 0xead1, 0x5cbd, 0x5cbe, 0xffff, 0xeadb, 0xffff, 0xeadd, 0xffff, 0xffff, 0xffff, 0x5cbf, 0xffff, 0x5cc0, 0xc8ef, 0xffff, 0xffff, 0xead9, 0xffff, 0xeade, 0xeae0, 0xffff, 0xffff, 0xb8d3, 0xead4, 0xffff, 0xb0c1, 0xffff, 0xffff, 0x5cc1, 0xffff, 0xffff, 0x5cc2, 0x5cc3, 0xeadf, 0x5cc4, 0xbadb, 0xcef6, 0xeae1, 0xeae2, 0xc1f5, 0xffff, 0xffff, 0xffff, 0xffff, 0x5cc5, 0x5cc6, 0x5cc7, 0x5cc8, 0x5cc9, 0xcea2, 0xffff, 0x5cca, 0x5ccb, 0x5ccc, 0xeae3, 0xcdb5, 0xffff, 0xffff, 0xeae4, 0xeae5, 0xffff, 0x5ccd, 0xcae4, 0xeae6, 0x5cce, 0xbac0, 0xffff, 0xcea3, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x5ccf, 0xeaeb, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x5cd0, 0x5cd1, 0x5cd2, 0xeaec, 0xbed8, 0xeaea, 0x5cd3, 0xffff, 0x5cd4, 0xcde7, 0xeae7, 0xffff, 0xffff, 0xeae9, 0xc0bd, 0xbffe, /* 0x89: 0x01 - 0xff */ 0x5cd5, 0xeae8, 0xffff, 0xeaed, 0xffff, 0x5cd6, 0xcaa3, 0xffff, 0xffff, 0xeaef, 0xffff, 0xeaee, 0x5cd7, 0x5cd8, 0x5cd9, 0xb3ec, 0xffff, 0xcbab, 0xeaf0, 0xffff, 0x5cda, 0x5cdb, 0xffff, 0x5cdc, 0x5cdd, 0x5cde, 0xffff, 0x5cdf, 0xeafc, 0xeaf2, 0xffff, 0x5ce0, 0xffff, 0xffff, 0xffff, 0xffff, 0xeaf3, 0x5ce1, 0x5ce2, 0x5ce3, 0xffff, 0xeaf4, 0xeaf5, 0xffff, 0xffff, 0xffff, 0xffff, 0x5ce4, 0x5ce5, 0x5ce6, 0xffff, 0xffff, 0x5ce7, 0xeaf9, 0xffff, 0xeafa, 0x5ce8, 0x5ce9, 0xeaf8, 0xffff, 0xffff, 0x5cea, 0xffff, 0x5ceb, 0xeaf6, 0x5cec, 0xeaf1, 0xeaf7, 0x5ced, 0x5cee, 0xffff, 0xffff, 0x5cef, 0xffff, 0xffff, 0xeafb, 0xf0b7, 0xffff, 0x5cf0, 0xffff, 0xffff, 0x5cf1, 0xffff, 0xffff, 0xffff, 0xb2a8, 0x5cf2, 0xffff, 0xffff, 0x5cf3, 0x5cf4, 0x5cf5, 0xffff, 0xeafe, 0xb6df, 0xeafd, 0x5cf6, 0x5cf7, 0x5cf8, 0xeba2, 0xffff, 0xeba1, 0xffff, 0xffff, 0xffff, 0xeba4, 0x5cf9, 0xffff, 0xeba3, 0x5cfa, 0xeba5, 0x5cfb, 0xffff, 0xbdb1, 0x5cfc, 0xeba6, 0x5cfd, 0xffff, 0xeba7, 0xffff, 0xffff, 0x5cfe, 0x5da1, 0x5da2, 0x5da3, 0xeba8, 0xc0be, 0xffff, 0xcdd7, 0xffff, 0xeba9, 0xffff, 0xffff, 0xcaa4, 0xc7c6, 0xebaa, 0x5da4, 0xebab, 0xb8ab, 0xffff, 0x5da5, 0xffff, 0xb5ac, 0x5da6, 0xffff, 0xffff, 0xebac, 0x5da7, 0x5da8, 0xbbeb, 0xc7c1, 0xebad, 0xffff, 0xb3d0, 0x5da9, 0x5daa, 0xffff, 0xffff, 0x5dab, 0x5dac, 0xebae, 0xffff, 0xffff, 0xffff, 0x5dad, 0xebb0, 0xcdf7, 0xffff, 0xebaf, 0xbfc6, 0xffff, 0xebb1, 0xffff, 0xffff, 0xebb2, 0x5dae, 0xffff, 0xebb3, 0xb4d1, 0x5daf, 0x5db0, 0x5db1, 0x5db2, 0xffff, 0xffff, 0xebb4, 0xffff, 0x5db3, 0xebb5, 0xffff, 0xebb6, 0xebb7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb3d1, 0xffff, 0x5db4, 0x5db5, 0x5db6, 0x5db7, 0x5db8, 0xffff, 0xebb8, 0xffff, 0xebb9, 0xebba, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb2f2, 0xffff, 0x5db9, 0xbfa8, 0xebbb, 0xffff, 0x5dba, 0xffff, 0x5dbb, 0xffff, 0x5dbc, 0xffff, 0xffff, 0xffff, 0x5dbd, 0xffff, 0x5dbe, 0xebbc, 0xffff, 0x5dbf, 0xffff, 0xebbd, 0x5dc0, 0xffff, 0xffff, 0xffff, 0x5dc1, 0xffff, 0x5dc2, /* 0x8a: 0x00 - 0xff */ 0xb8c0, 0xffff, 0xc4fb, 0xebbe, 0x5dc3, 0x5dc4, 0xffff, 0x5dc5, 0xb7d7, 0xffff, 0xbfd6, 0xffff, 0xebc1, 0xffff, 0xc6a4, 0x5dc6, 0xebc0, 0x5dc7, 0x5dc8, 0xb7b1, 0x5dc9, 0x5dca, 0xebbf, 0xc2f7, 0xb5ad, 0xffff, 0xffff, 0xebc2, 0xffff, 0xebc3, 0x5dcb, 0xbed9, 0x5dcc, 0xffff, 0x5dcd, 0xb7ed, 0x5dce, 0xebc4, 0x5dcf, 0xffff, 0xffff, 0xffff, 0xcbac, 0x5dd0, 0x5dd1, 0xc0df, 0xffff, 0x5dd2, 0xffff, 0xb5f6, 0xffff, 0xccf5, 0xc1ca, 0x5dd3, 0xebc5, 0x5dd4, 0xffff, 0xffff, 0xbfc7, 0xc3f0, 0xbeda, 0x5dd5, 0x5dd6, 0xffff, 0x5dd7, 0xebc6, 0xffff, 0x5dd8, 0xffff, 0x5dd9, 0xebc9, 0x5dda, 0xebca, 0x5ddb, 0xffff, 0xffff, 0xffff, 0x5ddc, 0x5ddd, 0xffff, 0xbabe, 0xc2c2, 0xebc8, 0x5dde, 0xbedb, 0xc9be, 0x5ddf, 0x5de0, 0x5de1, 0xffff, 0xffff, 0xebc7, 0x5de2, 0x5de3, 0xbbec, 0xffff, 0xb1d3, 0x5de4, 0xebce, 0xb7d8, 0xffff, 0x5de5, 0xbbee, 0x5de6, 0xffff, 0xbbed, 0xffff, 0xcfcd, 0xebcd, 0xebcc, 0xc1a7, 0xffff, 0xb5cd, 0xcfc3, 0xb3ba, 0xbedc, 0xffff, 0x5de7, 0x5de8, 0x5de9, 0xffff, 0x5dea, 0x5deb, 0x5dec, 0xebcb, 0xffff, 0x5ded, 0x5dee, 0x5def, 0xffff, 0xebd0, 0x5df0, 0xebd1, 0xebcf, 0x5df1, 0xb8d8, 0xffff, 0xcdc0, 0xffff, 0x5df2, 0xbbef, 0xc7a7, 0xffff, 0x5df3, 0x5df4, 0xebd4, 0x5df5, 0xc0c0, 0xffff, 0xc3c2, 0x5df6, 0x5df7, 0xcdb6, 0x5df8, 0xebd7, 0xffff, 0xffff, 0xffff, 0xb8ec, 0x5df9, 0xc0bf, 0xebd3, 0xffff, 0xebd8, 0xb8ed, 0xebd5, 0xebd6, 0x5dfa, 0xebd2, 0x5dfb, 0xffff, 0xffff, 0xc0e2, 0xc6c9, 0x5dfc, 0x5dfd, 0xc3af, 0xffff, 0xb2dd, 0x5dfe, 0xffff, 0xffff, 0x5ea1, 0x5ea2, 0xffff, 0xc8f0, 0xffff, 0x5ea3, 0xb5c3, 0xffff, 0x5ea4, 0xc4b4, 0xffff, 0xffff, 0xebdb, 0x5ea5, 0xebd9, 0xffff, 0x5ea6, 0xc3cc, 0x5ea7, 0x5ea8, 0x5ea9, 0xc0c1, 0xb4d2, 0xebda, 0xffff, 0xbfdb, 0xffff, 0x5eaa, 0xceca, 0x5eab, 0x5eac, 0x5ead, 0xcfc0, 0x5eae, 0xffff, 0xffff, 0xebdc, 0xebe7, 0xc4b5, 0x5eaf, 0xebe6, 0x5eb0, 0xebe3, 0xebeb, 0xebe4, 0xffff, 0xebe0, 0xffff, 0xc4fc, 0xebdf, 0xffff, 0xffff, 0xffff, 0xebdd, 0x5eb1, 0xcda1, 0xbbf0, 0xffff, 0x5eb2, 0xebe1, 0xffff, 0xebde, 0x5eb3, 0x5eb4, 0x5eb5, 0xebe5, 0xbdf4, 0xffff, 0xb8c1, 0xffff, 0x5eb6, 0xffff, 0xc2fa, 0x5eb7, /* 0x8b: 0x00 - 0x9f */ 0xcbc5, 0xb1da, 0xb0e2, 0xffff, 0xc6a5, 0x5eb8, 0x5eb9, 0xebe9, 0xffff, 0xffff, 0x5ebf, 0x5eba, 0xebe8, 0xffff, 0xc6e6, 0xffff, 0xebed, 0x5ebb, 0xffff, 0xffff, 0xebe2, 0xffff, 0xebec, 0xebee, 0xffff, 0xb8ac, 0xebea, 0xb9d6, 0x5ebc, 0xbcd5, 0x5ebd, 0x5ebe, 0xebef, 0xcdd8, 0xffff, 0xffff, 0xffff, 0xffff, 0xebf2, 0xffff, 0xebf5, 0xffff, 0xffff, 0xebf3, 0xc9b5, 0x5ec0, 0xffff, 0xffff, 0x5ec1, 0xffff, 0xffff, 0xebf0, 0xffff, 0xffff, 0xffff, 0x5ec2, 0xffff, 0xb6e0, 0xffff, 0xffff, 0x5ec3, 0xffff, 0xebf4, 0xffff, 0xffff, 0xebf6, 0x5ec4, 0x5ec5, 0x5ec6, 0x5ec7, 0x5ec8, 0xffff, 0x5ec9, 0xebfa, 0xffff, 0xffff, 0xebf7, 0x5ece, 0xebf9, 0xebf8, 0xffff, 0xffff, 0x5eca, 0x5ecb, 0x5ecc, 0xffff, 0xebfb, 0xffff, 0xbcb1, 0x5ecd, 0xebfd, 0xebfc, 0xc9e8, 0xffff, 0x5ecf, 0xeca1, 0xffff, 0xffff, 0xffff, 0x5ed0, 0xffff, 0xffff, 0xb7d9, 0xffff, 0xffff, 0xffff, 0xffff, 0xebfe, 0xeca2, 0x5ed1, 0xffff, 0xeca3, 0xb5c4, 0xe6c1, 0xbef9, 0xffff, 0xeca4, 0xffff, 0x5ed2, 0xb8ee, 0x5ed3, 0x5ed4, 0xffff, 0xffff, 0x5ed5, 0xeca5, 0x5ed6, 0xffff, 0xeca6, 0x5ed7, 0xffff, 0xbbbe, 0x5ed8, 0x5ed9, 0xffff, 0xffff, 0xffff, 0xffff, 0xdace, 0x5eda, 0xeca7, 0x5edb, 0xeca8, 0x5edc, 0xbdb2, 0xffff, 0xeca9, 0xecaa, 0x5edd, 0x5ede, 0xecab, 0xffff, 0xffff, 0xecac, 0xecad, 0xffff, 0x5edf, 0xffff, 0x5ee0, 0x5ee1, /* 0x8c: 0x37 - 0xff */ 0xc3ab, 0x5ee2, 0x5ee3, 0xecae, 0xffff, 0xffff, 0x5ee4, 0x5ee5, 0xecb0, 0xffff, 0xecaf, 0xffff, 0xffff, 0xffff, 0x5ee6, 0xc6a6, 0x5ee7, 0xecb1, 0x5ee8, 0xcbad, 0x5ee9, 0xecb2, 0xffff, 0xecb3, 0x5eea, 0xecb4, 0x5eeb, 0xffff, 0x5eec, 0x5eed, 0xecb5, 0xffff, 0x5eee, 0x5eef, 0x5ef2, 0xc6da, 0x5ef0, 0xffff, 0x5ef1, 0xffff, 0xffff, 0xffff, 0xbedd, 0xecb6, 0x5ef3, 0x5ef4, 0xffff, 0x5ef5, 0xffff, 0x5ef6, 0x5ef7, 0xb9eb, 0xd0ae, 0xecb7, 0x5ef8, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x5ef9, 0xffff, 0x5efa, 0x5efb, 0xffff, 0xecb8, 0xc9bf, 0xecb9, 0x5efc, 0xecc1, 0xffff, 0x5efd, 0xffff, 0xffff, 0xffff, 0xecba, 0xffff, 0xffff, 0xecbc, 0x5efe, 0x5fa1, 0xffff, 0xecbb, 0xecbd, 0x5fa2, 0xcbc6, 0xecbe, 0xecbf, 0xffff, 0x5fa3, 0xffff, 0x5fa4, 0x5fa5, 0xecc0, 0xffff, 0xffff, 0xffff, 0xecc2, 0x5fa6, 0xffff, 0x5fa7, 0x5fa8, 0xb3ad, 0xc4e7, 0xffff, 0xc9e9, 0xbae2, 0xb9d7, 0xffff, 0x5fa9, 0xffff, 0xffff, 0xc9cf, 0xb2df, 0xc8ce, 0xecc5, 0xb4d3, 0xc0d5, 0xecc4, 0xecc9, 0xc3f9, 0xcce3, 0xffff, 0xecc7, 0xecc8, 0xb5ae, 0xffff, 0xecca, 0xc7e3, 0xc2df, 0x5faa, 0x5fab, 0xc8f1, 0xc5bd, 0xecc6, 0xffff, 0xcbc7, 0xb2ec, 0xeccc, 0xcfa8, 0xc4c2, 0xcfc5, 0x5fac, 0x5fad, 0xbbf1, 0xeccb, 0x5fae, 0xc2b1, 0x5faf, 0xffff, 0xecdc, 0xc1a8, 0x5fb0, 0xffff, 0xc6f8, 0xffff, 0xc9d0, 0xffff, 0x5fb2, 0x5fb1, 0xffff, 0xffff, 0x5fb3, 0xeccf, 0xbbbf, 0xbbf2, 0x5fb4, 0xbede, 0xffff, 0xc7e5, 0x5fb5, 0xb8ad, 0xecce, 0xeccd, 0xffff, 0xc9ea, 0xffff, 0x5fb6, 0xffff, 0xbcc1, 0xffff, 0x5fb7, 0xc5d2, 0xffff, 0x5fb8, 0x5fb9, 0xffff, 0x5fba, 0xffff, 0xffff, 0x5fbb, 0xffff, 0x5fbc, 0x5fbd, 0xffff, 0xecd1, 0xecd2, 0xb9d8, 0xecd0, 0x5fbe, 0x5fbf, /* 0x8d: 0x01 - 0xff */ 0x5fc0, 0xffff, 0x5fc1, 0xecd3, 0xecd4, 0xffff, 0xecd6, 0xc2a3, 0x5fc2, 0xecd5, 0xb4e6, 0xffff, 0xecd8, 0xffff, 0xecd7, 0xecd9, 0xffff, 0x5fc3, 0xecdb, 0xecdd, 0xffff, 0xecde, 0x5fc4, 0xffff, 0xffff, 0xffff, 0x5fc5, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc0d6, 0x5fc6, 0xbccf, 0xecdf, 0xffff, 0x5fc7, 0xffff, 0xb3d2, 0x5fc8, 0xece0, 0x5fc9, 0xffff, 0xc1f6, 0xece1, 0xffff, 0xece2, 0xc9eb, 0xffff, 0xffff, 0xb5af, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x5fca, 0xffff, 0xece3, 0x5fcb, 0xffff, 0x5fcc, 0xc4b6, 0xffff, 0xffff, 0x5fcd, 0xffff, 0xb1db, 0xffff, 0xffff, 0x5fce, 0xffff, 0xffff, 0x5fcf, 0x5fd0, 0xffff, 0xffff, 0xffff, 0x5fd1, 0xffff, 0xffff, 0xffff, 0xece4, 0xffff, 0xffff, 0xffff, 0xffff, 0x5fd2, 0x5fd3, 0x5fd4, 0xffff, 0xffff, 0xbcf1, 0xffff, 0xffff, 0x5fd5, 0xffff, 0xbff6, 0xffff, 0xffff, 0x5fd6, 0x5fd7, 0xffff, 0xffff, 0x5fd8, 0xffff, 0xffff, 0x5fd9, 0xc2ad, 0xffff, 0x5fda, 0xffff, 0x5fdb, 0xffff, 0x5fdc, 0xece7, 0x5fdd, 0x5fef, 0xffff, 0xece6, 0xffff, 0x5fde, 0xffff, 0xece5, 0xffff, 0xffff, 0x5fdf, 0x5fe0, 0x5fe1, 0x5fe2, 0xffff, 0x5fe3, 0xeced, 0xeceb, 0xffff, 0x5fe4, 0xece8, 0xffff, 0x5fe5, 0xffff, 0xffff, 0x5fe6, 0x5fe7, 0xecea, 0x5fe8, 0xffff, 0x5fe9, 0xece9, 0xecec, 0xffff, 0xb5f7, 0xffff, 0xecf0, 0xffff, 0xc0d7, 0xffff, 0xecf1, 0x5fea, 0x5feb, 0xffff, 0x5fec, 0xb8d9, 0xffff, 0xecee, 0xecef, 0x5fed, 0xffff, 0xffff, 0xcfa9, 0x5fee, 0x5ff0, 0x5ff1, 0xc4b7, 0x5ff2, 0xc1a9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xecf2, 0x5ff3, 0xffff, 0xecf5, /* 0x8e: 0x01 - 0xfe */ 0x5ff4, 0xffff, 0xffff, 0x5ff5, 0x5ff6, 0x5ff7, 0xffff, 0xecf3, 0xecf4, 0xcdd9, 0x5ff8, 0xffff, 0xffff, 0xffff, 0xc6a7, 0xecf8, 0x5ff9, 0xffff, 0xffff, 0x5ffa, 0xffff, 0x5ffb, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xecf6, 0xecf7, 0xecf9, 0x5ffc, 0x5ffd, 0x5ffe, 0x60a1, 0xffff, 0xffff, 0x60a2, 0x60a3, 0xffff, 0xffff, 0xeda9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xecfc, 0x60a4, 0xffff, 0x60a5, 0xecfd, 0xecfb, 0x60a6, 0x60a7, 0x60a8, 0x60a9, 0xffff, 0xffff, 0xffff, 0x60aa, 0xffff, 0xffff, 0x60ab, 0x60ac, 0xecfa, 0xffff, 0xc4fd, 0xffff, 0xffff, 0xeda1, 0xeda5, 0xeda2, 0xecfe, 0x60ad, 0xeda3, 0x60ae, 0x60af, 0x60b0, 0xeda4, 0xffff, 0xffff, 0xffff, 0x60b1, 0xedab, 0xffff, 0xffff, 0xffff, 0xeda6, 0xffff, 0x60b2, 0x60b3, 0x60b4, 0x60b5, 0xc0d8, 0xeda8, 0x60b6, 0x60b7, 0xedaa, 0xeda7, 0xffff, 0xffff, 0xffff, 0xffff, 0x60b8, 0xffff, 0xffff, 0x60b9, 0x60ba, 0xffff, 0x60bb, 0x60bc, 0x60bd, 0xedad, 0xffff, 0xbdb3, 0xffff, 0xedac, 0xffff, 0xffff, 0x60be, 0x60bf, 0x60c0, 0xedae, 0xffff, 0xffff, 0xffff, 0xffff, 0xedaf, 0x60c1, 0x60c2, 0xedb2, 0xedb1, 0xffff, 0xedb0, 0xffff, 0x60c3, 0xedb4, 0xedb3, 0xffff, 0xccf6, 0xffff, 0xffff, 0x60c4, 0xedb6, 0x60c5, 0xedb5, 0xedb7, 0x60c6, 0xffff, 0xffff, 0xffff, 0xedb8, 0x60c7, 0x60c8, 0xffff, 0x60c9, 0x60ca, 0xffff, 0xffff, 0xedba, 0x60cb, 0xffff, 0xffff, 0xffff, 0xffff, 0x60cc, 0xffff, 0x60cd, 0xedb9, 0xbfc8, 0xedbb, 0x60ce, 0x60cf, 0xb6ed, 0xedbc, 0xedbe, 0xffff, 0x60d0, 0xffff, 0x60d1, 0xffff, 0xffff, 0xffff, 0xffff, 0x60d2, 0x60d3, 0xffff, 0xffff, 0xedbf, 0xffff, 0x60d4, 0x60d5, 0xffff, 0x60d6, 0x60d7, 0xedc0, 0xedbd, 0x60d8, 0xedc1, 0xffff, 0xbcd6, 0xedc2, 0xb5b0, 0xb7b3, 0xffff, 0x60d9, 0xffff, 0x60da, 0xb8ae, 0xffff, 0x60db, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xedc3, 0x60dc, 0xffff, 0xffff, 0xc6f0, 0xffff, 0xffff, 0xc5be, 0xedc4, 0xffff, 0xffff, 0xffff, 0xffff, 0x60dd, 0xffff, 0xffff, 0xedc7, 0xffff, 0x60e4, 0x60de, 0xffff, 0x60df, 0x60e0, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x60e1, 0xbcb4, 0x60e2, 0x60e3, 0xedc6, 0xedc5, 0xb7da, 0xedc8, /* 0x8f: 0x00 - 0xfe */ 0x60e5, 0xffff, 0x60e6, 0xb3d3, 0xffff, 0xedca, 0xffff, 0x60e7, 0x60e8, 0xbadc, 0xedc9, 0xffff, 0xedd2, 0xffff, 0xffff, 0x60e9, 0x60ea, 0xffff, 0xedcc, 0xedce, 0xcae5, 0xedcb, 0x60eb, 0x60ec, 0x60ed, 0xedcd, 0xffff, 0xedd1, 0xedcf, 0xb5b1, 0x60ee, 0xedd0, 0x60ef, 0x60f0, 0xffff, 0x60f1, 0xffff, 0x60f2, 0xedd3, 0x60f3, 0x60f4, 0xc7da, 0xced8, 0xffff, 0x60f5, 0x60f6, 0x60f7, 0xbdb4, 0xffff, 0xffff, 0xffff, 0xedd4, 0x60f8, 0x60f9, 0x60fa, 0x60fb, 0xcda2, 0xedd6, 0x60fc, 0xedd5, 0xffff, 0xffff, 0xedd9, 0xcdc1, 0x60fd, 0x60fe, 0xedd8, 0x61a1, 0xb3ed, 0xedd7, 0xeddc, 0x61a2, 0xffff, 0xeddb, 0xffff, 0xffff, 0xedda, 0xc5b2, 0xeddd, 0x61a3, 0xffff, 0x61a4, 0x61a5, 0x61a6, 0x61a7, 0x61a8, 0xffff, 0xedde, 0x61a9, 0xffff, 0xffff, 0xffff, 0xeddf, 0x61aa, 0x61ab, 0xb9ec, 0xffff, 0xb7a5, 0xede0, 0xede1, 0xede2, 0x61ac, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xbfc9, 0xede3, 0x61ad, 0xbcad, 0xede4, 0x61ae, 0x61af, 0xffff, 0xede5, 0x61b0, 0x61b1, 0x61b2, 0xd2a1, 0xd1fe, 0xffff, 0xffff, 0xffff, 0xffff, 0xede6, 0xe5f0, 0xede7, 0xc3a4, 0xbfab, 0xc7c0, 0xffff, 0xffff, 0x61b3, 0x61b4, 0xede8, 0x61b5, 0xffff, 0xcad5, 0xc4d4, 0xb9fe, 0xffff, 0x61b6, 0xc3a9, 0x61b7, 0x61b8, 0xb1aa, 0xffff, 0xcbf8, 0xbfd7, 0x61b9, 0xffff, 0xffff, 0xffff, 0x61ba, 0x61bb, 0xffff, 0x61bc, 0xb7de, 0xffff, 0x61bd, 0xb6e1, 0x61be, 0x61bf, 0xcad6, 0x61c0, 0xffff, 0xffff, 0xffff, 0xffff, 0xede9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x61c1, 0xffff, 0xedeb, 0x61c2, 0x61c3, 0xedea, 0xb2e0, 0xffff, 0x61c4, 0xc6f6, 0xedec, 0xc7f7, 0xffff, 0xc5b3, 0x61c5, 0xeded, 0xbdd2, 0x61c6, 0xffff, 0xffff, 0xedef, 0x61c7, 0x61c8, 0xccc2, 0xedfe, 0xedf1, 0xedf2, 0x61c9, 0xffff, 0xc4c9, 0x61ca, /* 0x90: 0x00 - 0xff */ 0xc2e0, 0xc1f7, 0x61cb, 0xc6a8, 0x61cc, 0xedf0, 0xb5d5, 0xffff, 0x61cd, 0xffff, 0xffff, 0xedf9, 0x61ce, 0xedf6, 0xeea5, 0xc6a9, 0xc3e0, 0xedf3, 0xffff, 0xc4fe, 0xc5d3, 0xedf4, 0xedf8, 0xbfe0, 0x61cf, 0xc7e7, 0xc4cc, 0x61d0, 0xffff, 0xc0c2, 0xedf7, 0xc2ae, 0xc2a4, 0xedf5, 0xb0a9, 0xcfa2, 0xffff, 0xffff, 0xffff, 0xedfa, 0x61d1, 0x61d2, 0x61d4, 0xffff, 0x61d5, 0x61d6, 0xc2e1, 0x61d3, 0xffff, 0xbdb5, 0xbfca, 0x61d7, 0x61d8, 0xedfc, 0xedfb, 0x61d9, 0xb0ef, 0xedfd, 0xffff, 0xffff, 0xc9af, 0xffff, 0xeea7, 0x61da, 0xffff, 0xc6db, 0xbfeb, 0x61db, 0x61dc, 0xc3d9, 0xffff, 0xb6f8, 0xffff, 0xeea6, 0xcdb7, 0xb1bf, 0x61dd, 0xcad7, 0xb2e1, 0xeea1, 0xeea2, 0xeea3, 0xeea4, 0xc6bb, 0xc3a3, 0xb0e3, 0xeea8, 0xffff, 0xeea9, 0xf4a3, 0xffff, 0x61de, 0xc2bd, 0x61df, 0xeeaa, 0xffff, 0xb1f3, 0xc1cc, 0x61e0, 0xb8af, 0xffff, 0xcdda, 0x61e1, 0x61e2, 0xeeab, 0xc5ac, 0xffff, 0xffff, 0x61e3, 0xc1f8, 0xbcd7, 0xeeac, 0x61e4, 0xffff, 0xeeaf, 0xffff, 0x61e5, 0xbde5, 0xeead, 0xc1ab, 0xc1aa, 0x61e6, 0xb0e4, 0xffff, 0xcecb, 0xeeb1, 0xffff, 0xc8f2, 0xeeb3, 0xeeb2, 0xeeb0, 0xe3e4, 0xb4d4, 0x61e7, 0xffff, 0xedee, 0x61e8, 0xeeb5, 0xeeb4, 0x61e9, 0x61ea, 0xffff, 0x61eb, 0xeeb6, 0x61ec, 0xcdb8, 0xffff, 0xffff, 0xffff, 0x61ed, 0xffff, 0x61ee, 0x61ef, 0x61f0, 0xffff, 0x61f1, 0xffff, 0xffff, 0xffff, 0xffff, 0x61f2, 0x61f3, 0x61f4, 0xc6e1, 0xffff, 0x61f5, 0xcbae, 0xffff, 0xeeb7, 0xffff, 0xbcd9, 0xffff, 0xffff, 0xffff, 0xffff, 0xeeb8, 0x61f6, 0xeeb9, 0x61f7, 0x61f8, 0x61f9, 0xeeba, 0x61fa, 0xffff, 0xc5a1, 0xffff, 0xffff, 0xffff, 0xffff, 0x61fb, 0x61fd, 0xffff, 0xffff, 0xb0ea, 0xffff, 0x61fe, 0x62a1, 0x62a2, 0xffff, 0x62a3, 0x62a4, 0xffff, 0xb9d9, 0xffff, 0x61fc, 0xffff, 0xcfba, 0xffff, 0xffff, 0xffff, 0x62ad, 0xffff, 0xffff, 0x62a5, 0xffff, 0x62a6, 0x62a7, 0x62a8, 0xffff, 0xeebe, 0x62a9, 0x62aa, 0xffff, 0x62ab, 0xffff, 0xb7b4, 0xeebb, 0xffff, 0xeebc, 0x62ac, 0xffff, 0xffff, 0xc9f4, 0xffff, 0xffff, 0x62af, 0xffff, 0xb3d4, 0xffff, 0x62b0, 0x62b1, 0xffff, 0xffff, 0xffff, 0x62b2, 0xcdb9, 0x62ae, 0xb6bf, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc5d4, 0x62b3, 0x62b4, /* 0x91: 0x00 - 0xff */ 0x62b5, 0xffff, 0xeebf, 0xffff, 0x62b6, 0x62b7, 0x62b8, 0xffff, 0x62b9, 0xffff, 0xffff, 0xffff, 0xffff, 0x62ba, 0xffff, 0xffff, 0x62bb, 0xffff, 0xeec0, 0xffff, 0x62bc, 0xffff, 0x62bd, 0x62be, 0x62bf, 0xeec1, 0x62c0, 0xffff, 0x62c1, 0xffff, 0x62c2, 0xffff, 0x62c3, 0xffff, 0x62c5, 0x62c6, 0xffff, 0x62c4, 0xffff, 0x62c7, 0xffff, 0x62c8, 0xffff, 0xffff, 0xffff, 0xc5a2, 0x62c9, 0x62ca, 0xeec3, 0x62cb, 0xeec2, 0xffff, 0x62cc, 0xffff, 0x62cd, 0x62ce, 0xffff, 0x62cf, 0x62d0, 0xffff, 0x62d1, 0x62d2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x62d3, 0xffff, 0xffff, 0xffff, 0x62d4, 0x62d5, 0xc6d3, 0xeec4, 0xbdb6, 0xbce0, 0xc7db, 0xc3f1, 0x62d6, 0xffff, 0xffff, 0xbcf2, 0x62d7, 0xbfec, 0xffff, 0xeec5, 0x62d8, 0xeec6, 0x62d9, 0x62da, 0x62db, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x62dc, 0xbfdd, 0xeec7, 0x62dd, 0xeec8, 0xffff, 0x62de, 0xffff, 0xeec9, 0xcdef, 0xffff, 0xbdb7, 0x62df, 0xffff, 0xffff, 0xffff, 0xffff, 0xeecb, 0xeeca, 0x62e0, 0xb9da, 0xffff, 0xb9f3, 0xbbc0, 0x62e1, 0x62e2, 0x62e3, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x62e4, 0xeece, 0x62e5, 0xffff, 0x62e6, 0x62e7, 0xbde6, 0xffff, 0xeecd, 0x62e8, 0xeecc, 0xffff, 0xc2e9, 0x62e9, 0xffff, 0xb8ef, 0x62ea, 0xc0c3, 0x62eb, 0x62ec, 0x62ed, 0xffff, 0xc8b0, 0x62ee, 0xffff, 0xffff, 0xffff, 0xbdb9, 0xffff, 0x62ef, 0xffff, 0xffff, 0x62f0, 0xeecf, 0xffff, 0xbedf, 0xffff, 0x62f1, 0xffff, 0x62f2, 0xffff, 0xeed2, 0xeed0, 0x62f3, 0x62f4, 0x62f5, 0xeed1, 0x62f6, 0x62f7, 0x62f8, 0x62f9, 0xeed4, 0xeed3, 0x62fa, 0xffff, 0xbefa, 0xffff, 0xeed5, 0x62fb, 0x62fc, 0x62fd, 0xffff, 0x62fe, 0xeed6, 0xeed7, 0x63a1, 0x63a2, 0xffff, 0x63a3, 0xc8d0, 0xbad3, 0xbce1, 0xeed8, 0xffff, 0xeed9, 0xcea4, 0xbdc5, 0xccee, 0xcecc, 0xeeda, 0xb6e2, 0xffff, 0x63a4, 0x63a5, 0xffff, 0xeedb, 0x63a6, 0xc5a3, 0x63a7, 0x63a8, 0xeede, 0xb3f8, 0xbfcb, 0x63a9, 0xeedc, 0xffff, 0xeedd, 0xffff, 0xc4e0, 0x63aa, 0x63ab, 0xcbd5, 0xb6fc, 0xffff, 0x63ac, 0x63ad, 0xffff, 0x63ae, 0x63af, 0x63b0, 0x63b1, 0x63b2, 0x63b3, 0xffff, 0xffff, 0xffff, 0xeee0, 0xeee1, 0x63b4, 0xffff, 0x63b5, 0xffff, 0x63b6, 0xeedf, 0x63b7, 0xffff, 0xeee3, /* 0x92: 0x00 - 0xff */ 0x63b8, 0x63b9, 0xffff, 0xffff, 0x63ba, 0x63bb, 0x63bc, 0x63bd, 0xffff, 0x63be, 0x63bf, 0xffff, 0x63c0, 0xc6df, 0xb3c3, 0xffff, 0x63c1, 0xeee7, 0x63c2, 0x63c3, 0xeee4, 0xeee6, 0x63c4, 0xffff, 0x63c5, 0xffff, 0xffff, 0xffff, 0x63c6, 0x63c7, 0xeee2, 0xffff, 0xffff, 0xffff, 0xffff, 0x63c8, 0x63c9, 0x63ca, 0x63cb, 0xffff, 0x63cc, 0xefcf, 0xffff, 0xffff, 0xeee5, 0xffff, 0x63cd, 0x63ce, 0x63cf, 0xffff, 0xffff, 0x63d0, 0xceeb, 0x63d1, 0x63d2, 0xb8da, 0x63d3, 0x63d4, 0x63d5, 0xffff, 0x63d6, 0xffff, 0x63d7, 0xeeef, 0x63d8, 0xffff, 0x63d9, 0x63da, 0xc5b4, 0xeeea, 0x63db, 0x63dc, 0xeeed, 0xeeeb, 0x63dd, 0xeef0, 0xffff, 0x63de, 0x63df, 0x63e0, 0xeef1, 0x63e1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xeee9, 0x63e2, 0x63e3, 0xeef6, 0xb1f4, 0x63e4, 0x63e5, 0xeee8, 0xffff, 0x63e6, 0x63e7, 0xc8ad, 0xffff, 0xeeec, 0x63e8, 0xbee0, 0x63e9, 0x63ea, 0x63eb, 0xffff, 0xffff, 0xffff, 0xffff, 0x63ec, 0x63ed, 0x63ee, 0xb9db, 0xffff, 0xffff, 0xffff, 0x63ef, 0x63f0, 0x63f1, 0x63f2, 0x63f3, 0xffff, 0x63f4, 0x63f5, 0x63f6, 0xcbc8, 0x63f7, 0xb6e4, 0xffff, 0xffff, 0xbdc6, 0xffff, 0xc6bc, 0xffff, 0xffff, 0x63f8, 0x63f9, 0x63fa, 0xffff, 0xffff, 0x63fb, 0x63fc, 0xffff, 0xffff, 0xc1ad, 0x63fd, 0xeef4, 0xffff, 0xeeee, 0xeef3, 0x63fe, 0xccc3, 0x64a1, 0xc4b8, 0xeef5, 0xeef2, 0xffff, 0xffff, 0x64a2, 0x64a3, 0xffff, 0xffff, 0xffff, 0x64a4, 0x64a5, 0xffff, 0x64a6, 0x64a7, 0xffff, 0xffff, 0x64a8, 0xffff, 0xc1ac, 0xffff, 0x64a9, 0xffff, 0xffff, 0x64aa, 0xffff, 0xffff, 0xffff, 0x64ab, 0xeef9, 0x64ac, 0xeef8, 0x64ad, 0x64ae, 0x64af, 0x64b0, 0xffff, 0x64b1, 0x64b2, 0x64b3, 0x64b4, 0x64b5, 0xffff, 0x64b6, 0x64b7, 0x64b8, 0x64b9, 0xffff, 0xffff, 0x64ba, 0x64bb, 0x64bc, 0x64bd, 0xeef7, 0x64be, 0xffff, 0xcbaf, 0x64bf, 0xffff, 0x64c0, 0xffff, 0x64c1, 0x64c2, 0x64c3, 0xffff, 0xffff, 0x64c4, 0x64c5, 0xffff, 0x64c6, 0x64c7, 0x64c8, 0xffff, 0x64c9, 0xbdfb, 0x64ca, 0xffff, 0x64cb, 0x64cc, 0xeefa, 0xcadf, 0xffff, 0x64cd, 0xb1d4, 0x64ce, 0xffff, 0x64cf, 0xffff, 0xc9c6, 0xc3f2, 0xffff, 0xffff, 0xffff, 0xffff, 0xb5f8, 0x64d0, 0xeefc, 0x64d1, 0xb9dd, 0xffff, 0xffff, 0x64d2, /* 0x93: 0x00 - 0xfd */ 0x64d3, 0xffff, 0x64d4, 0xffff, 0xffff, 0xffff, 0xbbac, 0xffff, 0x64d5, 0xffff, 0xffff, 0xffff, 0xffff, 0x64d6, 0xffff, 0xeefb, 0xbfed, 0x64d7, 0xffff, 0xffff, 0x64d8, 0x64d9, 0xffff, 0xffff, 0xbfee, 0xefa1, 0xefa3, 0xffff, 0x64da, 0x64db, 0x64dc, 0x64dd, 0xbefb, 0x64de, 0xefa2, 0xefa4, 0x64df, 0x64e0, 0xb6d3, 0x64e1, 0xc9c5, 0x64e2, 0x64e3, 0xbce2, 0xcfa3, 0xffff, 0xeefe, 0xbaf8, 0xffff, 0xffff, 0xcfbf, 0x64e4, 0x64e5, 0xefa6, 0x64e6, 0x64e7, 0xffff, 0xffff, 0xefa5, 0xefa7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xeefd, 0xffff, 0xffff, 0x64e8, 0x64e9, 0x64ea, 0xffff, 0xc6e9, 0xffff, 0xc5d5, 0xffff, 0xffff, 0x64eb, 0x64ec, 0x64ed, 0xffff, 0xc4d7, 0x64ee, 0xefac, 0x64ef, 0x64f0, 0xffff, 0x64f1, 0xc3c3, 0xefa8, 0xffff, 0x64f2, 0xffff, 0xefa9, 0xffff, 0xffff, 0xffff, 0x64f3, 0x64f4, 0xffff, 0x64f5, 0xffff, 0x64f6, 0x64f7, 0xffff, 0xb7ad, 0x64f8, 0xefab, 0x64f9, 0x64fa, 0x64fb, 0xffff, 0x64fc, 0x64fd, 0xb8b0, 0x64fe, 0xffff, 0xffff, 0xffff, 0x65a1, 0xffff, 0xefaa, 0x65a2, 0xbee1, 0x65a3, 0x65a4, 0x65a5, 0x65a6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x65a7, 0xffff, 0x65a8, 0x65a9, 0xb3f9, 0x65aa, 0xffff, 0x65ab, 0xffff, 0xffff, 0x65ac, 0xffff, 0xefb0, 0x65ad, 0xbabf, 0xc1f9, 0x65ae, 0xffff, 0xc4ca, 0x65af, 0xffff, 0xffff, 0x65b0, 0xffff, 0xffff, 0x65b1, 0xffff, 0x65b2, 0x65b3, 0xffff, 0x65b4, 0xb3bb, 0x65b5, 0x65bb, 0xffff, 0x65b6, 0xefae, 0xefaf, 0xc4c3, 0xffff, 0xefad, 0xffff, 0xffff, 0xffff, 0x65b7, 0x65b8, 0x65b9, 0xffff, 0xffff, 0xefb1, 0x65ba, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x65bc, 0xffff, 0xefb7, 0x65bd, 0x65be, 0x65bf, 0x65c0, 0xefba, 0x65c1, 0x65c2, 0x65c3, 0x65c4, 0x65c5, 0xffff, 0xffff, 0xefb9, 0xc5ad, 0xffff, 0x65c6, 0xffff, 0xffff, 0xefb2, 0xefb3, 0xefb6, 0x65c7, 0xffff, 0xffff, 0x65c8, 0xefb8, 0x65c9, 0x65ca, 0xffff, 0xb6c0, 0x65cb, 0xffff, 0xefbb, 0xefb5, 0x65cc, 0x65cd, 0xefb4, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x65cf, 0x65d0, 0x65ce, 0x65d1, 0x65d2, 0xffff, 0x65d3, /* 0x94: 0x01 - 0x84 */ 0x65d4, 0x65d5, 0xefbf, 0x65d6, 0xffff, 0xffff, 0xefc0, 0x65d7, 0x65d8, 0xffff, 0xffff, 0xffff, 0x65d9, 0x65da, 0x65db, 0xefc1, 0xffff, 0xffff, 0xefbe, 0xefbd, 0x65dc, 0x65dd, 0x65de, 0xbee2, 0xc6aa, 0xefbc, 0xffff, 0xffff, 0xffff, 0xffff, 0x65df, 0xffff, 0xefc5, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xefc3, 0xffff, 0xffff, 0x65e0, 0x65e1, 0xffff, 0x65e2, 0x65e3, 0x65e4, 0x65e5, 0xefc4, 0xefc2, 0xffff, 0xc2f8, 0xffff, 0xefc6, 0x65e6, 0xffff, 0x65e8, 0xffff, 0x65e7, 0xffff, 0xefc7, 0xffff, 0x65e9, 0xefc9, 0x65ea, 0xffff, 0xffff, 0x65eb, 0xffff, 0x65ec, 0xffff, 0x65ed, 0xffff, 0xffff, 0xffff, 0xffff, 0xb4d5, 0xefc8, 0xccfa, 0xffff, 0x65ee, 0xffff, 0xffff, 0xffff, 0x65ef, 0xefd4, 0xefca, 0x65f0, 0xffff, 0xefcd, 0x65f1, 0xefcb, 0x65f2, 0xefcc, 0x65f3, 0xffff, 0xffff, 0xffff, 0xffff, 0x65f4, 0xffff, 0xefce, 0x65f5, 0xffff, 0x65f6, 0x65f7, 0x65f8, 0xefd0, 0x65f9, 0x65fa, 0xffff, 0xffff, 0xefd1, 0xffff, 0xefd2, 0xffff, 0xffff, 0xffff, 0xffff, 0xefd5, 0xefd3, 0xefd6, 0xefd8, 0xffff, 0xefd7, 0xffff, 0x65fc, 0x65fb, /* 0x95: 0x77 - 0xe6 */ 0xc4b9, 0x65fd, 0x65fe, 0xffff, 0xffff, 0xffff, 0xffff, 0x66a1, 0xffff, 0xcce7, 0xffff, 0xefd9, 0xc1ae, 0x66a2, 0xffff, 0xffff, 0xefda, 0x66a3, 0xcac4, 0xefdb, 0xb3ab, 0x66a4, 0x66a5, 0x66a6, 0xb1bc, 0xffff, 0xb4d7, 0xffff, 0xb4d6, 0xefdc, 0xffff, 0xefdd, 0xffff, 0xefde, 0xefdf, 0xffff, 0xffff, 0xffff, 0x66a7, 0x66a8, 0x66a9, 0xefe0, 0x66aa, 0xb4d8, 0xb3d5, 0xb9de, 0xc8b6, 0x66ab, 0xefe2, 0xefe1, 0x66ac, 0xffff, 0x66ad, 0x66ae, 0xefe3, 0xffff, 0xffff, 0xffff, 0xffff, 0xb1dc, 0xffff, 0x66af, 0xffff, 0x66b0, 0xffff, 0xffff, 0xefe6, 0x66b1, 0xefe5, 0xefe4, 0x66b2, 0xefe7, 0x66b3, 0xffff, 0xffff, 0xffff, 0xefea, 0xffff, 0xffff, 0x66b4, 0xb0c7, 0x66b5, 0x66b6, 0xefe8, 0x66b7, 0xefec, 0xefeb, 0xffff, 0xffff, 0x66b8, 0x66b9, 0x66ba, 0x66bb, 0xefee, 0xefed, 0xefef, 0xffff, 0xc6ae, 0x66bc, 0x66bd, 0xffff, 0xeff0, 0x66be, 0x66bf, 0x66c0, 0x66c1, 0xeff1, 0xeff3, 0xffff, 0x66c2, 0xeff2, 0x66c3, /* 0x96: 0x1c - 0xfb */ 0xc9ec, 0x66c4, 0x66c5, 0xffff, 0xffff, 0xeff4, 0x66c6, 0xffff, 0x66c7, 0x66c8, 0x66c9, 0xffff, 0xeff5, 0xffff, 0xbae5, 0xffff, 0x66ca, 0xffff, 0xeff6, 0xeff7, 0xffff, 0x66cb, 0xcbc9, 0x66cc, 0xffff, 0xffff, 0xffff, 0x66cd, 0x66ce, 0x66cf, 0x66d0, 0xc1cb, 0x66d1, 0x66d2, 0xffff, 0xb0a4, 0xc2cb, 0x66d3, 0xeff8, 0xffff, 0xc9ed, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xeffb, 0xeff9, 0xb9df, 0xffff, 0xeffa, 0xb8c2, 0xffff, 0x66d4, 0xffff, 0x66d5, 0xffff, 0x66d6, 0x66d7, 0x66d8, 0xffff, 0xffff, 0xcac5, 0xeffd, 0xf0a1, 0xeffe, 0xf0a2, 0xffff, 0x66d9, 0xb1a1, 0xbfd8, 0xbdfc, 0xb4d9, 0xf0a3, 0xffff, 0xffff, 0xffff, 0xc7e6, 0xffff, 0xf0a5, 0xffff, 0x66da, 0xffff, 0xb1a2, 0xffff, 0xf0a4, 0xc4c4, 0x66db, 0xcecd, 0xc6ab, 0xeffc, 0xcea6, 0xffff, 0xb8b1, 0x66dc, 0x66dd, 0xcddb, 0x66de, 0x66df, 0xffff, 0x66e0, 0x66e1, 0x66e2, 0x66e3, 0xb6f9, 0xceb4, 0xffff, 0xb7a8, 0x66e4, 0xc2e2, 0xe7a1, 0xffff, 0xf0a6, 0xb3ac, 0xbfef, 0xffff, 0x66e5, 0xffff, 0xffff, 0xb3d6, 0xf0a8, 0x66e6, 0xf0a9, 0xf0a7, 0xb7e4, 0x66e7, 0xbadd, 0xbee3, 0x66e8, 0xffff, 0x66e9, 0xb1a3, 0xffff, 0xffff, 0xced9, 0x66ea, 0x66eb, 0x66ec, 0xf0ab, 0xeeae, 0x66ed, 0xf0aa, 0xffff, 0xffff, 0xffff, 0x66ee, 0x66ef, 0xf0ae, 0xf0ac, 0xf0ad, 0x66f0, 0xf0af, 0xffff, 0xf0b0, 0xceec, 0xf0b1, 0xf0b2, 0x66f1, 0xc0c9, 0xc8bb, 0xffff, 0xffff, 0xffff, 0xbffd, 0xb4e7, 0xffff, 0xffff, 0xcdba, 0xb2ed, 0xbdb8, 0xb8db, 0xffff, 0xf0b5, 0x66f2, 0xf0b4, 0xbbf3, 0xf0b6, 0xf0b3, 0xffff, 0xffff, 0xbba8, 0x66f3, 0xffff, 0xffff, 0xf0ba, 0xeaad, 0xffff, 0x66f5, 0xd2d6, 0x66f6, 0xbff7, 0xf0b8, 0x66f7, 0x66f8, 0x66f9, 0xffff, 0xffff, 0xcea5, 0xc6f1, 0xffff, 0xffff, 0xffff, 0xffff, 0xb1ab, 0x66fa, 0xc0e3, 0xbcb6, 0xffff, 0xffff, 0xffff, 0x66fb, 0xcab7, 0x66fc, 0xb1c0, 0xffff, 0xffff, 0xffff, 0xceed, 0xcdeb, 0xffff, 0xf0bb, 0x66fd, 0xc5c5, /* 0x97: 0x00 - 0xff */ 0xbcfb, 0xffff, 0x66fe, 0x67a1, 0xf0bc, 0x67a2, 0xf0bd, 0xbfcc, 0xf0be, 0x67a3, 0xceee, 0xffff, 0xffff, 0xf0b9, 0xf0c0, 0xf0c2, 0xffff, 0xf0c1, 0xffff, 0xf0bf, 0xffff, 0xffff, 0xf0c3, 0xffff, 0xffff, 0xf0c4, 0x67a4, 0x67a5, 0xc1fa, 0x67a6, 0xb2e2, 0xffff, 0xffff, 0x67a7, 0x67a8, 0x67a9, 0xf0c5, 0xffff, 0xffff, 0xccb8, 0x67aa, 0xffff, 0xf0c6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xf0c7, 0x67ab, 0xcfaa, 0x67ac, 0xffff, 0xffff, 0xffff, 0xffff, 0xdbb1, 0xf0c8, 0xffff, 0xffff, 0xffff, 0xf0c9, 0xf0ca, 0xffff, 0xffff, 0x67ad, 0xf0ce, 0x67ae, 0xf0cb, 0xffff, 0xf0cc, 0xffff, 0xf0cd, 0xf0cf, 0x67af, 0xffff, 0xffff, 0xffff, 0x67b0, 0x67b1, 0xffff, 0xffff, 0xc0c4, 0xffff, 0xffff, 0x67b2, 0xccf7, 0x67b3, 0x67b4, 0xc0c5, 0x67b5, 0x67b6, 0xf0d0, 0xffff, 0xc8f3, 0xffff, 0xf0d1, 0xf3d3, 0xcccc, 0x67b7, 0xf0d2, 0xffff, 0xf0d3, 0x67b8, 0xf0d4, 0xb3d7, 0x67b9, 0xf0d6, 0xffff, 0xbfd9, 0x67ba, 0xffff, 0xffff, 0xf0d7, 0xffff, 0x67bb, 0xb7a4, 0xffff, 0x67bc, 0x67bd, 0x67be, 0xf0d8, 0xf0dc, 0x67bf, 0xf0da, 0x67c0, 0xffff, 0x67c1, 0x67c2, 0xf0db, 0xffff, 0xffff, 0xb3f3, 0xf0d9, 0xf0dd, 0xffff, 0xffff, 0x67c3, 0xffff, 0xf0de, 0xffff, 0xb0c8, 0xffff, 0xf0df, 0xf0e0, 0xffff, 0xffff, 0xffff, 0xffff, 0x67c4, 0x67c5, 0x67c6, 0xbee4, 0x67c7, 0x67c8, 0xffff, 0xf0e1, 0xffff, 0x67c9, 0x67ca, 0xb5c7, 0xffff, 0x67cb, 0xf0e4, 0xffff, 0xffff, 0xf0e3, 0xffff, 0xf0e2, 0xffff, 0xffff, 0xebf1, 0x67cc, 0xcadc, 0x67cd, 0xffff, 0xffff, 0x67ce, 0x67cf, 0xf0e5, 0xf0e6, 0x67d0, 0x67d1, 0xffff, 0x67d2, 0x67d3, 0x67d4, 0xffff, 0x67d5, 0xffff, 0x67d6, 0x67d7, 0xffff, 0x67d8, 0xffff, 0xf0e7, 0x67d9, 0x67da, 0xf0e8, 0x67db, 0xf0e9, 0x67dc, 0x67dd, 0xf0ea, 0x67de, 0x67df, 0x67e0, 0xffff, 0x67e1, 0x67e2, 0xffff, 0xb4da, 0x67e3, 0xffff, 0xffff, 0x67e4, 0x67e5, 0x67e6, 0xffff, 0x67ea, 0xf0eb, 0x67e7, 0x67e8, 0xffff, 0x67e9, 0x67eb, 0xffff, 0xffff, 0x67ec, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xf0ec, 0xc7a3, 0x67ed, 0xffff, 0x67ee, 0xf0ee, 0xb2bb, 0x67ef, 0xf0f1, 0xf0f0, 0x67f0, 0x67f1, 0xffff, 0x67f2, 0xb1a4, 0xffff, 0xffff, 0xffff, 0xb6c1, /* 0x98: 0x01 - 0xfe */ 0xcac7, 0xc4ba, 0xbaa2, 0xffff, 0xb9e0, 0xbde7, 0x67f3, 0xbfdc, 0xffff, 0x67f4, 0xffff, 0xf0f3, 0x67f6, 0x67f7, 0xf0f2, 0xcdc2, 0xb4e8, 0xc8d2, 0xc6dc, 0x67f8, 0xffff, 0x67f9, 0xbffc, 0xcece, 0x67f5, 0xb7db, 0xffff, 0x67fa, 0xffff, 0x67fb, 0xffff, 0x67fc, 0xf0f6, 0xffff, 0x67fd, 0xf0f5, 0x68a8, 0x67fe, 0xffff, 0xffff, 0xffff, 0xffff, 0x68a1, 0xcbcb, 0xc6ac, 0x68a2, 0x68a3, 0x68a4, 0xffff, 0x68a5, 0x68a6, 0xb1d0, 0x68a7, 0xffff, 0xf0f7, 0xf0f4, 0xffff, 0xffff, 0xc9d1, 0xcdea, 0xf0f8, 0x68a9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x68aa, 0xffff, 0xf0f9, 0x68ab, 0xffff, 0xffff, 0x68ac, 0xf0fb, 0xc2ea, 0xb3db, 0xb3dc, 0xf0fa, 0xffff, 0x68ad, 0x68ae, 0x68af, 0xb4e9, 0xb8b2, 0x68b0, 0x68b1, 0xb4ea, 0x68b2, 0x68b3, 0xc5bf, 0xffff, 0xffff, 0xcee0, 0xffff, 0xffff, 0xffff, 0x68b4, 0x68b5, 0xffff, 0x68b6, 0x68b7, 0xb8dc, 0xffff, 0xffff, 0x68b8, 0xf0fc, 0x68b9, 0xffff, 0xffff, 0xf0fd, 0xf0fe, 0xf1a1, 0xffff, 0xf1a3, 0xf1a2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc9f7, 0xffff, 0xf1a4, 0x68ba, 0xffff, 0x68bb, 0x68bc, 0xf1a5, 0x68bd, 0xf1a6, 0xffff, 0xffff, 0x68be, 0xffff, 0xf1a7, 0x68bf, 0x68c0, 0xffff, 0x68c1, 0x68c2, 0xffff, 0xffff, 0xffff, 0x68c3, 0xffff, 0xffff, 0x68c4, 0xf1a9, 0xf1a8, 0x68c5, 0xf1aa, 0xffff, 0x68c6, 0xffff, 0xffff, 0xffff, 0x68c7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc8f4, 0xe6cc, 0xffff, 0xffff, 0xbfa9, 0xffff, 0x68c8, 0xb5b2, 0x68c9, 0xffff, 0x68ca, 0x68cb, 0x68cc, 0xffff, 0xf1ab, 0x68cd, 0xf1ac, 0xffff, 0xd2ac, 0xddbb, 0xc8d3, 0xffff, 0xffff, 0xb0fb, 0x68ce, 0xb0bb, 0xffff, 0x68cf, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xbbf4, 0xcbb0, 0xbefe, /* 0x99: 0x02 - 0xff */ 0x68d0, 0xf1ad, 0xffff, 0xccdf, 0xffff, 0x68d1, 0x68d2, 0xf1ae, 0xcddc, 0xffff, 0xb1c2, 0xffff, 0xffff, 0xffff, 0xbbc1, 0x68d3, 0xf1af, 0xb2ee, 0xf1b0, 0x68d4, 0x68d5, 0x68d6, 0xf1b1, 0xffff, 0x68d7, 0x68d8, 0x68d9, 0xf1b3, 0xf1b4, 0x68da, 0xf1b6, 0xf1b2, 0x68db, 0xffff, 0xf1b5, 0xffff, 0x68dc, 0x68dd, 0xb4db, 0xffff, 0xffff, 0x68de, 0xf1b7, 0xffff, 0xf1b8, 0xffff, 0xffff, 0x68df, 0x68e0, 0x68e1, 0x68e2, 0x68e3, 0xffff, 0xffff, 0xffff, 0x68e4, 0x68e5, 0x68e6, 0x68e7, 0xf1b9, 0xf1ba, 0xffff, 0x68e8, 0x68e9, 0xf1bb, 0xffff, 0xffff, 0xf1bd, 0x68ea, 0x68eb, 0x68ec, 0xf1bc, 0xffff, 0xf1bf, 0xf1c2, 0x68ed, 0x68ee, 0xffff, 0xf1be, 0xf1c0, 0xf1c1, 0xffff, 0x68ef, 0xf1c3, 0xffff, 0xb6c2, 0x68f0, 0x68f1, 0xffff, 0x68f2, 0x68f3, 0xffff, 0x68f4, 0x68f5, 0x68f6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xbcf3, 0xf1c4, 0xf1c5, 0xb9e1, 0xffff, 0x68f7, 0xffff, 0x68f8, 0xffff, 0x68f9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xf1c6, 0x68fa, 0xffff, 0xb3be, 0xffff, 0xffff, 0xffff, 0xc7cf, 0xf1c7, 0xf1c8, 0xffff, 0x68fb, 0x68fc, 0x68fd, 0xc3da, 0xc6eb, 0x68fe, 0xffff, 0xffff, 0xffff, 0x69a1, 0x69a2, 0xffff, 0xf1c9, 0x69a3, 0xffff, 0x69a4, 0xffff, 0xc7fd, 0xffff, 0x69a5, 0xc2cc, 0xb1d8, 0xb6ee, 0xffff, 0xb6ef, 0x69a6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc3f3, 0xf1ce, 0xb6f0, 0x69a7, 0x69a8, 0xb2ef, 0xffff, 0xffff, 0xf1cd, 0x69a9, 0x69aa, 0xf1cb, 0x69ab, 0xf1cc, 0x69ac, 0xf1ca, 0xffff, 0xffff, 0xf1d8, 0xffff, 0xffff, 0xffff, 0xffff, 0x69ad, 0xffff, 0xffff, 0x69ae, 0x69af, 0x69b0, 0xf1cf, 0xf1d0, 0xffff, 0x69b1, 0xf1d1, 0xf1d2, 0xffff, 0x69b2, 0x69b3, 0xffff, 0xffff, 0xf1d4, 0x69b4, 0xffff, 0xf1d3, 0xffff, 0x69b5, 0x69b6, 0xbdd9, /* 0x9a: 0x01 - 0xff */ 0xf1d5, 0x69b7, 0x69b8, 0x69b9, 0xf1d7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x69ba, 0x69bb, 0xffff, 0xb5b3, 0xf1d6, 0x69bc, 0x69bd, 0xc1fb, 0xb8b3, 0xffff, 0xffff, 0x69be, 0xffff, 0xffff, 0xf1d9, 0xffff, 0xffff, 0xffff, 0xffff, 0x69bf, 0xffff, 0x69c0, 0xffff, 0x69c1, 0x69c2, 0x69c3, 0xffff, 0xffff, 0x69c4, 0xc2cd, 0xffff, 0xffff, 0xf1da, 0xffff, 0x69c5, 0x69c6, 0xffff, 0xc6ad, 0xffff, 0xffff, 0x69c7, 0xffff, 0x69c8, 0x69c9, 0xf1db, 0x69ca, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xf1e0, 0xffff, 0xf1de, 0x69cc, 0xf1dd, 0xf1df, 0x69cd, 0xf1dc, 0xffff, 0x69cb, 0xffff, 0xffff, 0x69ce, 0x69cf, 0x69d0, 0xf1e2, 0x69d1, 0xffff, 0xffff, 0x69d2, 0xffff, 0xffff, 0x69d3, 0xf1e1, 0x69d4, 0xf1e4, 0xffff, 0xffff, 0xb6c3, 0xf1e3, 0xffff, 0x69d5, 0xffff, 0xf1e5, 0xffff, 0xffff, 0xf1e6, 0xffff, 0xf1e8, 0xf1e7, 0xffff, 0xffff, 0xffff, 0xf1e9, 0xf1eb, 0xf1ea, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xb9fc, 0xffff, 0x69d6, 0xffff, 0x69d7, 0xf1ec, 0x69d8, 0x69d9, 0xf1ed, 0xffff, 0x69da, 0xffff, 0x69db, 0x69dc, 0x69dd, 0xffff, 0xb3bc, 0x69de, 0xffff, 0x69df, 0xf1ee, 0xffff, 0x69e0, 0x69e1, 0xf1ef, 0x69e2, 0xffff, 0x69e3, 0xbff1, 0xffff, 0x69e4, 0xffff, 0x69e5, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x69e6, 0xf1f0, 0x69e7, 0xf1f1, 0x69e8, 0xf1f2, 0xf1f3, 0x69e9, 0x69ea, 0x69eb, 0xb9e2, 0xffff, 0xffff, 0x69ec, 0x69ed, 0xffff, 0xf1f4, 0xf1f5, 0x69ee, 0xffff, 0xf1f6, 0xf1f7, 0x69ef, 0x69f0, 0xf1f8, 0x69f1, 0xffff, 0x69f2, 0xc8b1, 0xf1fa, 0x69f3, 0xc9a6, 0xf1fb, 0xf1f9, 0xffff, 0xf1fd, 0x69f4, 0x69f5, 0xf1fc, 0x69f6, 0xffff, 0xf1fe, 0xffff, 0x69f7, 0x69f8, 0xf2a1, 0xffff, 0x69f9, 0xffff, 0x69fa, /* 0x9b: 0x00 - 0xff */ 0x69fb, 0x69fc, 0x69fd, 0x69fe, 0x6aa1, 0x6aa2, 0xf2a2, 0xffff, 0x6aa3, 0x6aa4, 0xffff, 0x6aa5, 0x6aa6, 0x6aa7, 0x6aa8, 0xffff, 0x6aa9, 0xffff, 0x6aaa, 0xffff, 0xffff, 0xffff, 0x6aab, 0xffff, 0xf2a3, 0x6aac, 0xf2a4, 0x6aad, 0x6aae, 0xffff, 0xffff, 0xf2a5, 0x6aaf, 0xffff, 0xf2a6, 0xf2a7, 0xffff, 0xf2a8, 0x6ab0, 0xf2a9, 0xf2aa, 0xf2ab, 0xf2ac, 0x6ab1, 0xffff, 0x6ab2, 0xf2ad, 0xf2ae, 0xffff, 0xddb5, 0xf2af, 0x6ab3, 0x6ab4, 0x6ab5, 0xffff, 0x6ab6, 0xffff, 0x6ab7, 0x6ab8, 0xe4f8, 0xb5b4, 0x6ab9, 0xffff, 0xffff, 0xffff, 0xb3a1, 0xbab2, 0xf2b1, 0xf2b0, 0xcca5, 0xffff, 0xffff, 0x6aba, 0xffff, 0xffff, 0x6abb, 0x6abc, 0xf2b3, 0xf2b4, 0xf2b2, 0xffff, 0xf2b5, 0xffff, 0xffff, 0xcbe2, 0x6abd, 0x6abe, 0x6abf, 0xf2b6, 0xffff, 0xb5fb, 0x6ac0, 0xffff, 0xffff, 0x6ac1, 0xffff, 0xffff, 0x6ac2, 0xffff, 0x6ac3, 0xffff, 0x6ac4, 0x6ac5, 0xffff, 0x6ac6, 0xffff, 0x6ac7, 0x6ac8, 0x6ac9, 0x6aca, 0x6acb, 0xcfa5, 0xffff, 0xffff, 0xffff, 0x6acc, 0xf2b7, 0x6acd, 0xffff, 0x6ace, 0x6acf, 0x6ad0, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x6ad1, 0x6ad2, 0xffff, 0xffff, 0xf2b9, 0x6ad3, 0x6ad4, 0x6ad5, 0x6ad6, 0xffff, 0x6ad7, 0x6ad8, 0x6ad9, 0xffff, 0x6ada, 0xb0be, 0x6adb, 0x6adc, 0xf2ba, 0xcaab, 0xf2b8, 0x6add, 0xffff, 0xf2bb, 0xf2bc, 0xffff, 0xffff, 0x6ade, 0xffff, 0xffff, 0x6adf, 0x6ae0, 0xf2bd, 0xf2be, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x6ae1, 0x6ae2, 0xf2bf, 0x6ae3, 0xcbee, 0xbbad, 0x6ae4, 0xbafa, 0xc1af, 0xffff, 0x6ae5, 0x6ae6, 0x6ae7, 0xffff, 0xf2c0, 0xffff, 0xffff, 0x6ae8, 0x6ae9, 0xf2c3, 0xffff, 0x6aea, 0x6aeb, 0xffff, 0x6aec, 0x6aed, 0xf2c1, 0x6aee, 0xffff, 0xffff, 0xffff, 0xffff, 0xf2c4, 0x6aef, 0x6af0, 0xb8f1, 0xf2c2, 0xffff, 0xffff, 0xffff, 0x6af1, 0xf2c5, 0x6af2, 0xf2c6, 0xf2c7, 0xffff, 0xf2cb, 0xffff, 0xbbaa, 0x6af3, 0x6af4, 0xffff, 0xffff, 0xc2e4, 0xffff, 0x6af5, 0xffff, 0x6af6, 0xffff, 0xf2cc, 0xf2c9, 0xf2c8, 0xf2ca, 0x6af7, 0xffff, 0x6af8, 0xb7df, 0xffff, 0x6af9, 0x6afa, 0xffff, 0xffff, 0xffff, 0x6afb, 0xf2d0, 0xf2cf, 0xf2ce, 0x6afc, 0xffff, 0xb0b3, 0xffff, 0x6afd, 0x6afe, 0x6ba1, 0x6ba2, 0xffff, 0xffff, 0x6ba3, 0xffff, 0x6ba4, /* 0x9c: 0x00 - 0xf9 */ 0x6ba5, 0xffff, 0x6ba6, 0xffff, 0xf2da, 0xffff, 0xf2d6, 0xffff, 0xf2d7, 0xf2d3, 0xf2d9, 0x6ba7, 0xf2d5, 0xb3e2, 0xffff, 0x6ba8, 0xcfcc, 0x6ba9, 0xf2d8, 0xf2d4, 0xf2d2, 0xf2d1, 0x6baa, 0xffff, 0x6bab, 0x6bac, 0x6bad, 0xf2dc, 0x6bae, 0xffff, 0x6baf, 0xffff, 0xffff, 0xf2df, 0x6bb0, 0x6bb1, 0xf2de, 0xf2dd, 0x6bb2, 0x6bb3, 0x6bb4, 0x6bb5, 0x6bb6, 0xffff, 0xffff, 0xc9c9, 0xf2db, 0xb0f3, 0xf2e0, 0x6bb7, 0xf2e2, 0xffff, 0xffff, 0x6bb8, 0x6bb9, 0x6bba, 0xffff, 0xb3ef, 0xf2cd, 0xb1b7, 0xffff, 0x6bbb, 0xf2e4, 0xffff, 0xffff, 0x6bbc, 0xffff, 0x6bbd, 0x6bbe, 0x6bbf, 0xf2e3, 0xf2e1, 0xc3ad, 0x6bc0, 0x6bc1, 0xffff, 0xffff, 0xffff, 0x6bc2, 0x6bc3, 0x6bc4, 0xffff, 0xcbf0, 0x6bc5, 0x6bc6, 0xffff, 0x6bc7, 0xceda, 0x6bc8, 0xffff, 0xf2e5, 0x6bc9, 0x6bd0, 0x6bca, 0x6bcb, 0x6bcc, 0xf2e6, 0xffff, 0xffff, 0x6bcd, 0xffff, 0xffff, 0xffff, 0xf2e7, 0x6bd2, 0x6bce, 0x6bcf, 0x6bd1, 0xffff, 0xffff, 0x6bd3, 0xffff, 0x6bd4, 0xffff, 0x6bd5, 0xffff, 0xffff, 0x6bd6, 0xf2e8, 0x6bd7, 0xf2e9, 0xffff, 0xffff, 0x6bd8, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc4bb, 0x6bd9, 0xf2ea, 0xffff, 0xc8b7, 0xffff, 0xf2ef, 0xf2eb, 0xffff, 0xffff, 0xffff, 0xf2ec, 0xffff, 0x6bda, 0xcbb1, 0xccc4, 0xffff, 0xc6d0, 0x6bdb, 0xffff, 0x6bdc, /* 0x9d: 0x02 - 0xfe */ 0x6bde, 0xf2f0, 0xffff, 0xffff, 0xf2f1, 0xc6be, 0xf2ee, 0xf2ed, 0xffff, 0x6bdd, 0xffff, 0xffff, 0xb2aa, 0xffff, 0xffff, 0x6bdf, 0xf2f9, 0xffff, 0xffff, 0xf2f8, 0xffff, 0x6be0, 0x6be1, 0xffff, 0xffff, 0xb1f5, 0x6be2, 0x6be3, 0x6be4, 0xf2f6, 0xffff, 0xffff, 0xffff, 0xf2f5, 0xffff, 0xffff, 0xf2f3, 0xffff, 0xb3fb, 0xffff, 0xf2f2, 0xbcb2, 0xb2a9, 0xffff, 0xffff, 0x6be5, 0x6be6, 0xffff, 0x6be7, 0x6be8, 0x6be9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x6bea, 0xb9e3, 0x6beb, 0x6bed, 0xf2fc, 0xf2fb, 0xffff, 0xf2fa, 0x6bee, 0x6bef, 0xf2f7, 0x6bec, 0xf2fd, 0x6bf0, 0xf2fe, 0xffff, 0x6bf1, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xf3a5, 0xf3a4, 0xffff, 0x6bf2, 0x6bf3, 0xffff, 0xffff, 0xffff, 0xffff, 0xf3a6, 0xffff, 0xffff, 0xb1ad, 0xf3a1, 0xf3a2, 0x6bf4, 0xb9f4, 0xccb9, 0x6bf6, 0x6bf5, 0xf3a3, 0x6bf7, 0xffff, 0xffff, 0xffff, 0x6bf8, 0x6bf9, 0x6bfa, 0xcbb2, 0xffff, 0xffff, 0xf3ab, 0x6bfb, 0xffff, 0xf3a7, 0xffff, 0xffff, 0xffff, 0x6bfc, 0x6bfd, 0xffff, 0xffff, 0xf3ac, 0x6bfe, 0x6ca1, 0xffff, 0x6ca2, 0xffff, 0xffff, 0xffff, 0xffff, 0x6ca3, 0x6ca4, 0xffff, 0x6ca5, 0xf3a9, 0xffff, 0xf3a8, 0x6ca6, 0xffff, 0xffff, 0x6ca7, 0x6ca8, 0xb7dc, 0xffff, 0xffff, 0x6ca9, 0x6caa, 0xffff, 0x6cab, 0x6cac, 0x6cad, 0x6cae, 0xffff, 0xf3ad, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x6caf, 0xffff, 0xffff, 0xf3ae, 0xffff, 0xffff, 0xffff, 0xffff, 0xf3af, 0x6cb0, 0xf3aa, 0x6cb1, 0xffff, 0x6cb2, 0xf2f4, 0xffff, 0x6cb3, 0xf3b0, 0xffff, 0xc4e1, 0x6cb4, 0xffff, 0xffff, 0xf3b4, 0x6cb5, 0xf3b5, 0xf3b3, 0x6cb6, 0xffff, 0xffff, 0x6cb7, 0xffff, 0xf3b2, 0xf3b8, 0x6cb8, 0xf3b1, 0xffff, 0xf3b6, 0x6cb9, 0xffff, 0x6cba, 0x6cbb, 0xffff, 0xffff, 0xffff, 0xffff, 0xf3b7, 0xffff, 0xffff, 0xffff, 0xf3ba, 0x6cbc, 0x6cbd, 0x6cbe, 0x6cbf, 0xffff, 0xf3b9, 0x6cc0, 0xffff, 0xffff, 0xffff, 0x6cc1, 0x6cc2, 0x6cc3, 0xffff, 0xffff, 0xffff, 0xffff, 0x6cc4, 0xf3bc, 0x6cc5, 0xffff, 0x6cc6, 0xffff, 0x6cc7, 0xffff, 0xf3bd, 0x6cc8, 0xf3be, 0x6cc9, 0xffff, 0xcfc9, 0x6cca, 0x6ccb, 0xffff, 0xffff, 0xffff, 0xf3bb, 0xc2eb, 0xbaed, 0xffff, 0xffff, 0xf3bf, 0x6ccc, /* 0x9e: 0x02 - 0xff */ 0x6cce, 0xffff, 0xffff, 0xffff, 0xffff, 0x6ccf, 0xffff, 0xffff, 0x6ccd, 0xffff, 0xffff, 0xffff, 0x6cd0, 0xffff, 0x6cd1, 0x6cd2, 0x6cd3, 0xffff, 0xffff, 0x6cd4, 0x6cd5, 0xffff, 0xffff, 0x6cd6, 0xf3c0, 0xf3c1, 0x6cd7, 0x6cd8, 0xf3c2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xf3c3, 0xffff, 0xffff, 0xb8b4, 0xf3c4, 0x6cd9, 0x6cda, 0x6cdb, 0xf3c5, 0xffff, 0xbcaf, 0x6cdc, 0xf3c6, 0x6cdd, 0x6cde, 0x6cdf, 0x6ce0, 0xffff, 0x6ce1, 0xf3c7, 0xffff, 0xffff, 0xf3c8, 0xf3c9, 0xffff, 0x6ce2, 0x6ce3, 0xffff, 0xf3cc, 0xf3ca, 0xcfbc, 0xffff, 0xf3cb, 0x6ce4, 0xceef, 0x6ce5, 0xffff, 0xffff, 0x6ce6, 0xffff, 0xf3cd, 0x6ce7, 0xcedb, 0xffff, 0xffff, 0xffff, 0xffff, 0x6ce8, 0xf3ce, 0xc7fe, 0xffff, 0x6ce9, 0xf3cf, 0xf3d1, 0xffff, 0x6cea, 0xf3d2, 0x6ceb, 0x6cec, 0x6ced, 0xffff, 0xffff, 0x6cee, 0x6cef, 0x6cf0, 0xffff, 0xffff, 0xf3d0, 0xb9ed, 0xcccd, 0xcbe3, 0xd6f7, 0xffff, 0xdde0, 0xcbfb, 0xffff, 0xffff, 0xffff, 0xffff, 0xb2ab, 0xffff, 0x6cf1, 0xffff, 0x6cf2, 0xffff, 0xffff, 0x6cf3, 0xf3d4, 0xb5d0, 0xf3d5, 0xf3d6, 0xf3d7, 0xffff, 0xb9f5, 0xffff, 0xf3d8, 0x6cf4, 0xffff, 0xffff, 0xe0d4, 0xccdb, 0xffff, 0xc2e3, 0xf3d9, 0xf3db, 0xf3da, 0x6cf5, 0xf3dc, 0xffff, 0xffff, 0xffff, 0x6cf6, 0xf3dd, 0xffff, 0x6cf7, 0xf3de, 0xffff, 0xffff, 0xffff, 0x6cf8, 0x6cf9, 0x6cfa, 0xf3df, 0x6cfb, 0x6cfc, 0x6cfd, 0xffff, 0xf3e0, 0x6cfe, 0xf3e1, 0xf3e2, 0x6da1, 0xf3e3, 0xffff, 0xf3e4, 0xf3e5, 0xf3e6, 0xffff, 0x6da2, /* 0x9f: 0x02 - 0xa5 */ 0x6da3, 0x6da4, 0xffff, 0xffff, 0xffff, 0xf3e7, 0xf3e8, 0x6da5, 0xffff, 0xffff, 0xffff, 0xffff, 0xc5a4, 0x6da6, 0x6da7, 0x6da8, 0x6da9, 0xb8dd, 0x6daa, 0xf3ea, 0x6dab, 0x6dac, 0xffff, 0x6dad, 0x6dae, 0x6daf, 0xffff, 0xffff, 0xffff, 0x6db0, 0xc1cd, 0xf3eb, 0x6db1, 0xffff, 0xffff, 0xffff, 0x6db2, 0xffff, 0xffff, 0xffff, 0x6db3, 0x6db4, 0xf3ec, 0xffff, 0xffff, 0x6db5, 0xffff, 0x6db6, 0x6db7, 0xffff, 0x6db8, 0xffff, 0xffff, 0x6db9, 0xffff, 0x6dba, 0x6dbb, 0xc9a1, 0x6dbc, 0x6dbd, 0xf3ed, 0x6dbe, 0xffff, 0x6dbf, 0xffff, 0x6dc0, 0x6dc1, 0x6dc2, 0x6dc3, 0x6dc4, 0xffff, 0xffff, 0xf3ee, 0xe3b7, 0xffff, 0xffff, 0xecda, 0xf0ed, 0xffff, 0xffff, 0xf3ef, 0x6dc5, 0xf3f0, 0x6dc6, 0x6dc7, 0x6dc8, 0x6dc9, 0xffff, 0x6dca, 0xffff, 0xffff, 0x6dcb, 0x6dcc, 0xf3f2, 0xf3f3, 0xf3f4, 0xcef0, 0xf3f1, 0xffff, 0xffff, 0xf3f5, 0xf3f6, 0x6dcd, 0x6dce, 0xf3f8, 0xffff, 0xf3f7, 0x6dcf, 0x6dd0, 0x6dd1, 0x6dd2, 0x6dd3, 0xf3fa, 0x6dd4, 0xffff, 0x6dd5, 0xf3fb, 0xf3f9, 0xffff, 0xffff, 0x6dd6, 0xffff, 0xffff, 0x6dd7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xceb6, 0xffff, 0x6dd8, 0x6dd9, 0x6dda, 0x6ddb, 0xffff, 0x6ddc, 0xf3fc, 0x6ddd, 0x6dde, 0xffff, 0xffff, 0xffff, 0xffff, 0xf3fd, 0xe3d4, 0x6ddf, 0xffff, 0xf3fe, 0x6de0, 0x6de1, 0x6de2, 0xffff, 0x6de3, }; static const struct jis_charmap __euc_jp_unicode_map[] = { { .first = 0xa1, .last = 0xff, .offset = 0 }, /* 0x0 */ { .first = 0x00, .last = 0xf5, .offset = 95 }, /* 0x1 */ { .first = 0xc7, .last = 0xdd, .offset = 341 }, /* 0x2 */ { .first = 0x84, .last = 0xce, .offset = 364 }, /* 0x3 */ { .first = 0x01, .last = 0x5f, .offset = 439 }, /* 0x4 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x5 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x6 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x7 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x8 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x9 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xa */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xb */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xc */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xd */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xe */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xf */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x10 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x11 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x12 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x13 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x14 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x15 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x16 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x17 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x18 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x19 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x1a */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x1b */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x1c */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x1d */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x1e */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x1f */ { .first = 0x10, .last = 0x3e, .offset = 534 }, /* 0x20 */ { .first = 0x03, .last = 0xd4, .offset = 581 }, /* 0x21 */ { .first = 0x00, .last = 0xa5, .offset = 791 }, /* 0x22 */ { .first = 0x12, .last = 0x12, .offset = 957 }, /* 0x23 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x24 */ { .first = 0x00, .last = 0xef, .offset = 958 }, /* 0x25 */ { .first = 0x05, .last = 0x6f, .offset = 1198 }, /* 0x26 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x27 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x28 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x29 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x2a */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x2b */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x2c */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x2d */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x2e */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x2f */ { .first = 0x00, .last = 0xfe, .offset = 1305 }, /* 0x30 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x31 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x32 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x33 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x34 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x35 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x36 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x37 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x38 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x39 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x3a */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x3b */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x3c */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x3d */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x3e */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x3f */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x40 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x41 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x42 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x43 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x44 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x45 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x46 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x47 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x48 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x49 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x4a */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x4b */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x4c */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x4d */ { .first = 0x00, .last = 0xff, .offset = 1560 }, /* 0x4e */ { .first = 0x00, .last = 0xff, .offset = 1816 }, /* 0x4f */ { .first = 0x00, .last = 0xfe, .offset = 2072 }, /* 0x50 */ { .first = 0x00, .last = 0xfe, .offset = 2327 }, /* 0x51 */ { .first = 0x00, .last = 0xff, .offset = 2582 }, /* 0x52 */ { .first = 0x00, .last = 0xfa, .offset = 2838 }, /* 0x53 */ { .first = 0x01, .last = 0xff, .offset = 3089 }, /* 0x54 */ { .first = 0x00, .last = 0xff, .offset = 3344 }, /* 0x55 */ { .first = 0x05, .last = 0xff, .offset = 3600 }, /* 0x56 */ { .first = 0x00, .last = 0xff, .offset = 3851 }, /* 0x57 */ { .first = 0x00, .last = 0xfd, .offset = 4107 }, /* 0x58 */ { .first = 0x02, .last = 0xff, .offset = 4361 }, /* 0x59 */ { .first = 0x00, .last = 0xfd, .offset = 4615 }, /* 0x5a */ { .first = 0x00, .last = 0xff, .offset = 4869 }, /* 0x5b */ { .first = 0x01, .last = 0xfd, .offset = 5125 }, /* 0x5c */ { .first = 0x01, .last = 0xfe, .offset = 5378 }, /* 0x5d */ { .first = 0x00, .last = 0xff, .offset = 5632 }, /* 0x5e */ { .first = 0x01, .last = 0xff, .offset = 5888 }, /* 0x5f */ { .first = 0x07, .last = 0xfd, .offset = 6143 }, /* 0x60 */ { .first = 0x00, .last = 0xff, .offset = 6390 }, /* 0x61 */ { .first = 0x00, .last = 0xff, .offset = 6646 }, /* 0x62 */ { .first = 0x01, .last = 0xfa, .offset = 6902 }, /* 0x63 */ { .first = 0x06, .last = 0xff, .offset = 7152 }, /* 0x64 */ { .first = 0x00, .last = 0xff, .offset = 7402 }, /* 0x65 */ { .first = 0x00, .last = 0xff, .offset = 7658 }, /* 0x66 */ { .first = 0x00, .last = 0xff, .offset = 7914 }, /* 0x67 */ { .first = 0x02, .last = 0xfd, .offset = 8170 }, /* 0x68 */ { .first = 0x00, .last = 0xff, .offset = 8422 }, /* 0x69 */ { .first = 0x00, .last = 0xfd, .offset = 8678 }, /* 0x6a */ { .first = 0x02, .last = 0xff, .offset = 8932 }, /* 0x6b */ { .first = 0x02, .last = 0xf4, .offset = 9186 }, /* 0x6c */ { .first = 0x04, .last = 0xfc, .offset = 9429 }, /* 0x6d */ { .first = 0x00, .last = 0xff, .offset = 9678 }, /* 0x6e */ { .first = 0x01, .last = 0xfe, .offset = 9934 }, /* 0x6f */ { .first = 0x00, .last = 0xfd, .offset = 10188 }, /* 0x70 */ { .first = 0x03, .last = 0xff, .offset = 10442 }, /* 0x71 */ { .first = 0x00, .last = 0xfe, .offset = 10695 }, /* 0x72 */ { .first = 0x02, .last = 0xff, .offset = 10950 }, /* 0x73 */ { .first = 0x00, .last = 0xff, .offset = 11204 }, /* 0x74 */ { .first = 0x03, .last = 0xff, .offset = 11460 }, /* 0x75 */ { .first = 0x00, .last = 0xfe, .offset = 11713 }, /* 0x76 */ { .first = 0x00, .last = 0xfc, .offset = 11968 }, /* 0x77 */ { .first = 0x02, .last = 0xff, .offset = 12221 }, /* 0x78 */ { .first = 0x00, .last = 0xfc, .offset = 12475 }, /* 0x79 */ { .first = 0x00, .last = 0xff, .offset = 12728 }, /* 0x7a */ { .first = 0x02, .last = 0xfe, .offset = 12984 }, /* 0x7b */ { .first = 0x00, .last = 0xfe, .offset = 13237 }, /* 0x7c */ { .first = 0x00, .last = 0xfb, .offset = 13492 }, /* 0x7d */ { .first = 0x00, .last = 0x9e, .offset = 13744 }, /* 0x7e */ { .first = 0x36, .last = 0xff, .offset = 13903 }, /* 0x7f */ { .first = 0x00, .last = 0xfe, .offset = 14105 }, /* 0x80 */ { .first = 0x02, .last = 0xff, .offset = 14360 }, /* 0x81 */ { .first = 0x00, .last = 0xfe, .offset = 14614 }, /* 0x82 */ { .first = 0x00, .last = 0xfd, .offset = 14869 }, /* 0x83 */ { .first = 0x01, .last = 0xff, .offset = 15123 }, /* 0x84 */ { .first = 0x00, .last = 0xff, .offset = 15378 }, /* 0x85 */ { .first = 0x00, .last = 0xfe, .offset = 15634 }, /* 0x86 */ { .first = 0x00, .last = 0xff, .offset = 15889 }, /* 0x87 */ { .first = 0x01, .last = 0xfe, .offset = 16145 + split_unicode_offset }, /* 0x88 */ { .first = 0x01, .last = 0xff, .offset = 16399 + split_unicode_offset }, /* 0x89 */ { .first = 0x00, .last = 0xff, .offset = 16654 + split_unicode_offset }, /* 0x8a */ { .first = 0x00, .last = 0x9f, .offset = 16910 + split_unicode_offset }, /* 0x8b */ { .first = 0x37, .last = 0xff, .offset = 17070 + split_unicode_offset }, /* 0x8c */ { .first = 0x01, .last = 0xff, .offset = 17271 + split_unicode_offset }, /* 0x8d */ { .first = 0x01, .last = 0xfe, .offset = 17526 + split_unicode_offset }, /* 0x8e */ { .first = 0x00, .last = 0xfe, .offset = 17780 + split_unicode_offset }, /* 0x8f */ { .first = 0x00, .last = 0xff, .offset = 18035 + split_unicode_offset }, /* 0x90 */ { .first = 0x00, .last = 0xff, .offset = 18291 + split_unicode_offset }, /* 0x91 */ { .first = 0x00, .last = 0xff, .offset = 18547 + split_unicode_offset }, /* 0x92 */ { .first = 0x00, .last = 0xfd, .offset = 18803 + split_unicode_offset }, /* 0x93 */ { .first = 0x01, .last = 0x84, .offset = 19057 + split_unicode_offset }, /* 0x94 */ { .first = 0x77, .last = 0xe6, .offset = 19189 + split_unicode_offset }, /* 0x95 */ { .first = 0x1c, .last = 0xfb, .offset = 19301 + split_unicode_offset }, /* 0x96 */ { .first = 0x00, .last = 0xff, .offset = 19525 + split_unicode_offset }, /* 0x97 */ { .first = 0x01, .last = 0xfe, .offset = 19781 + split_unicode_offset }, /* 0x98 */ { .first = 0x02, .last = 0xff, .offset = 20035 + split_unicode_offset }, /* 0x99 */ { .first = 0x01, .last = 0xff, .offset = 20289 + split_unicode_offset }, /* 0x9a */ { .first = 0x00, .last = 0xff, .offset = 20544 + split_unicode_offset }, /* 0x9b */ { .first = 0x00, .last = 0xf9, .offset = 20800 + split_unicode_offset }, /* 0x9c */ { .first = 0x02, .last = 0xfe, .offset = 21050 + split_unicode_offset }, /* 0x9d */ { .first = 0x02, .last = 0xff, .offset = 21303 + split_unicode_offset }, /* 0x9e */ { .first = 0x02, .last = 0xa5, .offset = 21557 + split_unicode_offset }, /* 0x9f */ }; #endif /* unicode */ /* unicode_ff tables */ #ifdef define_unicode_ff #define __euc_jp_unicode_ff_first_col 0x01 #define __euc_jp_unicode_ff_last_col 0xe5 #ifndef split_unicode_ff #define split_unicode_ff_offset 0 #endif static const uint16_t __euc_jp_unicode_ff_codes[] = { /* 0xff: 0x01 - 0xe5 */ 0xa1aa, 0xffff, 0xa1f4, 0xa1f0, 0xa1f3, 0xa1f5, 0xffff, 0xa1ca, 0xa1cb, 0xa1f6, 0xa1dc, 0xa1a4, 0xffff, 0xa1a5, 0xa1bf, 0xa3b0, 0xa3b1, 0xa3b2, 0xa3b3, 0xa3b4, 0xa3b5, 0xa3b6, 0xa3b7, 0xa3b8, 0xa3b9, 0xa1a7, 0xa1a8, 0xa1e3, 0xa1e1, 0xa1e4, 0xa1a9, 0xa1f7, 0xa3c1, 0xa3c2, 0xa3c3, 0xa3c4, 0xa3c5, 0xa3c6, 0xa3c7, 0xa3c8, 0xa3c9, 0xa3ca, 0xa3cb, 0xa3cc, 0xa3cd, 0xa3ce, 0xa3cf, 0xa3d0, 0xa3d1, 0xa3d2, 0xa3d3, 0xa3d4, 0xa3d5, 0xa3d6, 0xa3d7, 0xa3d8, 0xa3d9, 0xa3da, 0xa1ce, 0xa1c0, 0xa1cf, 0xa1b0, 0xa1b2, 0xa1ae, 0xa3e1, 0xa3e2, 0xa3e3, 0xa3e4, 0xa3e5, 0xa3e6, 0xa3e7, 0xa3e8, 0xa3e9, 0xa3ea, 0xa3eb, 0xa3ec, 0xa3ed, 0xa3ee, 0xa3ef, 0xa3f0, 0xa3f1, 0xa3f2, 0xa3f3, 0xa3f4, 0xa3f5, 0xa3f6, 0xa3f7, 0xa3f8, 0xa3f9, 0xa3fa, 0xa1d0, 0xa1c3, 0xa1d1, 0x22b7, 0xffff, 0xffff, 0x8ea1, 0x8ea2, 0x8ea3, 0x8ea4, 0x8ea5, 0x8ea6, 0x8ea7, 0x8ea8, 0x8ea9, 0x8eaa, 0x8eab, 0x8eac, 0x8ead, 0x8eae, 0x8eaf, 0x8eb0, 0x8eb1, 0x8eb2, 0x8eb3, 0x8eb4, 0x8eb5, 0x8eb6, 0x8eb7, 0x8eb8, 0x8eb9, 0x8eba, 0x8ebb, 0x8ebc, 0x8ebd, 0x8ebe, 0x8ebf, 0x8ec0, 0x8ec1, 0x8ec2, 0x8ec3, 0x8ec4, 0x8ec5, 0x8ec6, 0x8ec7, 0x8ec8, 0x8ec9, 0x8eca, 0x8ecb, 0x8ecc, 0x8ecd, 0x8ece, 0x8ecf, 0x8ed0, 0x8ed1, 0x8ed2, 0x8ed3, 0x8ed4, 0x8ed5, 0x8ed6, 0x8ed7, 0x8ed8, 0x8ed9, 0x8eda, 0x8edb, 0x8edc, 0x8edd, 0x8ede, 0x8edf, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa1b1, 0xffff, 0xa1ef, }; #endif /* unicode_ff */ /* jis_x0208 tables */ #ifdef define_jis_x0208 #define __euc_jp_jis_x0208_first_row 0x8e #define __euc_jp_jis_x0208_last_row 0xf4 #ifndef split_jis_x0208 #define split_jis_x0208_offset 0 #endif static const uint16_t __euc_jp_jis_x0208_codes[] = { /* 0x8e: 0xa1 - 0xdf*/ 0xff61, 0xff62, 0xff63, 0xff64, 0xff65, 0xff66, 0xff67, 0xff68, 0xff69, 0xff6a, 0xff6b, 0xff6c, 0xff6d, 0xff6e, 0xff6f, 0xff70, 0xff71, 0xff72, 0xff73, 0xff74, 0xff75, 0xff76, 0xff77, 0xff78, 0xff79, 0xff7a, 0xff7b, 0xff7c, 0xff7d, 0xff7e, 0xff7f, 0xff80, 0xff81, 0xff82, 0xff83, 0xff84, 0xff85, 0xff86, 0xff87, 0xff88, 0xff89, 0xff8a, 0xff8b, 0xff8c, 0xff8d, 0xff8e, 0xff8f, 0xff90, 0xff91, 0xff92, 0xff93, 0xff94, 0xff95, 0xff96, 0xff97, 0xff98, 0xff99, 0xff9a, 0xff9b, 0xff9c, 0xff9d, 0xff9e, 0xff9f, /* 0xa1: 0xa1 - 0xfe*/ 0x3000, 0x3001, 0x3002, 0xff0c, 0xff0e, 0x30fb, 0xff1a, 0xff1b, 0xff1f, 0xff01, 0x309b, 0x309c, 0x00b4, 0xff40, 0x00a8, 0xff3e, 0xffe3, 0xff3f, 0x30fd, 0x30fe, 0x309d, 0x309e, 0x3003, 0x4edd, 0x3005, 0x3006, 0x3007, 0x30fc, 0x2015, 0x2010, 0xff0f, 0xff3c, 0x301c, 0x2016, 0xff5c, 0x2026, 0x2025, 0x2018, 0x2019, 0x201c, 0x201d, 0xff08, 0xff09, 0x3014, 0x3015, 0xff3b, 0xff3d, 0xff5b, 0xff5d, 0x3008, 0x3009, 0x300a, 0x300b, 0x300c, 0x300d, 0x300e, 0x300f, 0x3010, 0x3011, 0xff0b, 0x2212, 0x00b1, 0x00d7, 0x00f7, 0xff1d, 0x2260, 0xff1c, 0xff1e, 0x2266, 0x2267, 0x221e, 0x2234, 0x2642, 0x2640, 0x00b0, 0x2032, 0x2033, 0x2103, 0xffe5, 0xff04, 0x00a2, 0x00a3, 0xff05, 0xff03, 0xff06, 0xff0a, 0xff20, 0x00a7, 0x2606, 0x2605, 0x25cb, 0x25cf, 0x25ce, 0x25c7, /* 0xa2: 0xa1 - 0xfe*/ 0x25c6, 0x25a1, 0x25a0, 0x25b3, 0x25b2, 0x25bd, 0x25bc, 0x203b, 0x3012, 0x2192, 0x2190, 0x2191, 0x2193, 0x3013, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x2208, 0x220b, 0x2286, 0x2287, 0x2282, 0x2283, 0x222a, 0x2229, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x2227, 0x2228, 0x00ac, 0x21d2, 0x21d4, 0x2200, 0x2203, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x2220, 0x22a5, 0x2312, 0x2202, 0x2207, 0x2261, 0x2252, 0x226a, 0x226b, 0x221a, 0x223d, 0x221d, 0x2235, 0x222b, 0x222c, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x212b, 0x2030, 0x266f, 0x266d, 0x266a, 0x2020, 0x2021, 0x00b6, 0xffff, 0xffff, 0xffff, 0xffff, 0x25ef, /* 0xa3: 0xb0 - 0xfa*/ 0xff10, 0xff11, 0xff12, 0xff13, 0xff14, 0xff15, 0xff16, 0xff17, 0xff18, 0xff19, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xff21, 0xff22, 0xff23, 0xff24, 0xff25, 0xff26, 0xff27, 0xff28, 0xff29, 0xff2a, 0xff2b, 0xff2c, 0xff2d, 0xff2e, 0xff2f, 0xff30, 0xff31, 0xff32, 0xff33, 0xff34, 0xff35, 0xff36, 0xff37, 0xff38, 0xff39, 0xff3a, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xff41, 0xff42, 0xff43, 0xff44, 0xff45, 0xff46, 0xff47, 0xff48, 0xff49, 0xff4a, 0xff4b, 0xff4c, 0xff4d, 0xff4e, 0xff4f, 0xff50, 0xff51, 0xff52, 0xff53, 0xff54, 0xff55, 0xff56, 0xff57, 0xff58, 0xff59, 0xff5a, /* 0xa4: 0xa1 - 0xf3*/ 0x3041, 0x3042, 0x3043, 0x3044, 0x3045, 0x3046, 0x3047, 0x3048, 0x3049, 0x304a, 0x304b, 0x304c, 0x304d, 0x304e, 0x304f, 0x3050, 0x3051, 0x3052, 0x3053, 0x3054, 0x3055, 0x3056, 0x3057, 0x3058, 0x3059, 0x305a, 0x305b, 0x305c, 0x305d, 0x305e, 0x305f, 0x3060, 0x3061, 0x3062, 0x3063, 0x3064, 0x3065, 0x3066, 0x3067, 0x3068, 0x3069, 0x306a, 0x306b, 0x306c, 0x306d, 0x306e, 0x306f, 0x3070, 0x3071, 0x3072, 0x3073, 0x3074, 0x3075, 0x3076, 0x3077, 0x3078, 0x3079, 0x307a, 0x307b, 0x307c, 0x307d, 0x307e, 0x307f, 0x3080, 0x3081, 0x3082, 0x3083, 0x3084, 0x3085, 0x3086, 0x3087, 0x3088, 0x3089, 0x308a, 0x308b, 0x308c, 0x308d, 0x308e, 0x308f, 0x3090, 0x3091, 0x3092, 0x3093, /* 0xa5: 0xa1 - 0xf6*/ 0x30a1, 0x30a2, 0x30a3, 0x30a4, 0x30a5, 0x30a6, 0x30a7, 0x30a8, 0x30a9, 0x30aa, 0x30ab, 0x30ac, 0x30ad, 0x30ae, 0x30af, 0x30b0, 0x30b1, 0x30b2, 0x30b3, 0x30b4, 0x30b5, 0x30b6, 0x30b7, 0x30b8, 0x30b9, 0x30ba, 0x30bb, 0x30bc, 0x30bd, 0x30be, 0x30bf, 0x30c0, 0x30c1, 0x30c2, 0x30c3, 0x30c4, 0x30c5, 0x30c6, 0x30c7, 0x30c8, 0x30c9, 0x30ca, 0x30cb, 0x30cc, 0x30cd, 0x30ce, 0x30cf, 0x30d0, 0x30d1, 0x30d2, 0x30d3, 0x30d4, 0x30d5, 0x30d6, 0x30d7, 0x30d8, 0x30d9, 0x30da, 0x30db, 0x30dc, 0x30dd, 0x30de, 0x30df, 0x30e0, 0x30e1, 0x30e2, 0x30e3, 0x30e4, 0x30e5, 0x30e6, 0x30e7, 0x30e8, 0x30e9, 0x30ea, 0x30eb, 0x30ec, 0x30ed, 0x30ee, 0x30ef, 0x30f0, 0x30f1, 0x30f2, 0x30f3, 0x30f4, 0x30f5, 0x30f6, /* 0xa6: 0xa1 - 0xd8*/ 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, 0x03a0, 0x03a1, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7, 0x03a8, 0x03a9, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, 0x03c0, 0x03c1, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, 0x03c8, 0x03c9, /* 0xa7: 0xa1 - 0xf1*/ 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0401, 0x0416, 0x0417, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0451, 0x0436, 0x0437, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, 0x043f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e, 0x044f, /* 0xa8: 0xa1 - 0xc0*/ 0x2500, 0x2502, 0x250c, 0x2510, 0x2518, 0x2514, 0x251c, 0x252c, 0x2524, 0x2534, 0x253c, 0x2501, 0x2503, 0x250f, 0x2513, 0x251b, 0x2517, 0x2523, 0x2533, 0x252b, 0x253b, 0x254b, 0x2520, 0x252f, 0x2528, 0x2537, 0x253f, 0x251d, 0x2530, 0x2525, 0x2538, 0x2542, /* 0xb0: 0xa1 - 0xfe*/ 0x4e9c, 0x5516, 0x5a03, 0x963f, 0x54c0, 0x611b, 0x6328, 0x59f6, 0x9022, 0x8475, 0x831c, 0x7a50, 0x60aa, 0x63e1, 0x6e25, 0x65ed, 0x8466, 0x82a6, 0x9bf5, 0x6893, 0x5727, 0x65a1, 0x6271, 0x5b9b, 0x59d0, 0x867b, 0x98f4, 0x7d62, 0x7dbe, 0x9b8e, 0x6216, 0x7c9f, 0x88b7, 0x5b89, 0x5eb5, 0x6309, 0x6697, 0x6848, 0x95c7, 0x978d, 0x674f, 0x4ee5, 0x4f0a, 0x4f4d, 0x4f9d, 0x5049, 0x56f2, 0x5937, 0x59d4, 0x5a01, 0x5c09, 0x60df, 0x610f, 0x6170, 0x6613, 0x6905, 0x70ba, 0x754f, 0x7570, 0x79fb, 0x7dad, 0x7def, 0x80c3, 0x840e, 0x8863, 0x8b02, 0x9055, 0x907a, 0x533b, 0x4e95, 0x4ea5, 0x57df, 0x80b2, 0x90c1, 0x78ef, 0x4e00, 0x58f1, 0x6ea2, 0x9038, 0x7a32, 0x8328, 0x828b, 0x9c2f, 0x5141, 0x5370, 0x54bd, 0x54e1, 0x56e0, 0x59fb, 0x5f15, 0x98f2, 0x6deb, 0x80e4, 0x852d, /* 0xb1: 0xa1 - 0xfe*/ 0x9662, 0x9670, 0x96a0, 0x97fb, 0x540b, 0x53f3, 0x5b87, 0x70cf, 0x7fbd, 0x8fc2, 0x96e8, 0x536f, 0x9d5c, 0x7aba, 0x4e11, 0x7893, 0x81fc, 0x6e26, 0x5618, 0x5504, 0x6b1d, 0x851a, 0x9c3b, 0x59e5, 0x53a9, 0x6d66, 0x74dc, 0x958f, 0x5642, 0x4e91, 0x904b, 0x96f2, 0x834f, 0x990c, 0x53e1, 0x55b6, 0x5b30, 0x5f71, 0x6620, 0x66f3, 0x6804, 0x6c38, 0x6cf3, 0x6d29, 0x745b, 0x76c8, 0x7a4e, 0x9834, 0x82f1, 0x885b, 0x8a60, 0x92ed, 0x6db2, 0x75ab, 0x76ca, 0x99c5, 0x60a6, 0x8b01, 0x8d8a, 0x95b2, 0x698e, 0x53ad, 0x5186, 0x5712, 0x5830, 0x5944, 0x5bb4, 0x5ef6, 0x6028, 0x63a9, 0x63f4, 0x6cbf, 0x6f14, 0x708e, 0x7114, 0x7159, 0x71d5, 0x733f, 0x7e01, 0x8276, 0x82d1, 0x8597, 0x9060, 0x925b, 0x9d1b, 0x5869, 0x65bc, 0x6c5a, 0x7525, 0x51f9, 0x592e, 0x5965, 0x5f80, 0x5fdc, /* 0xb2: 0xa1 - 0xfe*/ 0x62bc, 0x65fa, 0x6a2a, 0x6b27, 0x6bb4, 0x738b, 0x7fc1, 0x8956, 0x9d2c, 0x9d0e, 0x9ec4, 0x5ca1, 0x6c96, 0x837b, 0x5104, 0x5c4b, 0x61b6, 0x81c6, 0x6876, 0x7261, 0x4e59, 0x4ffa, 0x5378, 0x6069, 0x6e29, 0x7a4f, 0x97f3, 0x4e0b, 0x5316, 0x4eee, 0x4f55, 0x4f3d, 0x4fa1, 0x4f73, 0x52a0, 0x53ef, 0x5609, 0x590f, 0x5ac1, 0x5bb6, 0x5be1, 0x79d1, 0x6687, 0x679c, 0x67b6, 0x6b4c, 0x6cb3, 0x706b, 0x73c2, 0x798d, 0x79be, 0x7a3c, 0x7b87, 0x82b1, 0x82db, 0x8304, 0x8377, 0x83ef, 0x83d3, 0x8766, 0x8ab2, 0x5629, 0x8ca8, 0x8fe6, 0x904e, 0x971e, 0x868a, 0x4fc4, 0x5ce8, 0x6211, 0x7259, 0x753b, 0x81e5, 0x82bd, 0x86fe, 0x8cc0, 0x96c5, 0x9913, 0x99d5, 0x4ecb, 0x4f1a, 0x89e3, 0x56de, 0x584a, 0x58ca, 0x5efb, 0x5feb, 0x602a, 0x6094, 0x6062, 0x61d0, 0x6212, 0x62d0, 0x6539, /* 0xb3: 0xa1 - 0xfe*/ 0x9b41, 0x6666, 0x68b0, 0x6d77, 0x7070, 0x754c, 0x7686, 0x7d75, 0x82a5, 0x87f9, 0x958b, 0x968e, 0x8c9d, 0x51f1, 0x52be, 0x5916, 0x54b3, 0x5bb3, 0x5d16, 0x6168, 0x6982, 0x6daf, 0x788d, 0x84cb, 0x8857, 0x8a72, 0x93a7, 0x9ab8, 0x6d6c, 0x99a8, 0x86d9, 0x57a3, 0x67ff, 0x86ce, 0x920e, 0x5283, 0x5687, 0x5404, 0x5ed3, 0x62e1, 0x64b9, 0x683c, 0x6838, 0x6bbb, 0x7372, 0x78ba, 0x7a6b, 0x899a, 0x89d2, 0x8d6b, 0x8f03, 0x90ed, 0x95a3, 0x9694, 0x9769, 0x5b66, 0x5cb3, 0x697d, 0x984d, 0x984e, 0x639b, 0x7b20, 0x6a2b, 0x6a7f, 0x68b6, 0x9c0d, 0x6f5f, 0x5272, 0x559d, 0x6070, 0x62ec, 0x6d3b, 0x6e07, 0x6ed1, 0x845b, 0x8910, 0x8f44, 0x4e14, 0x9c39, 0x53f6, 0x691b, 0x6a3a, 0x9784, 0x682a, 0x515c, 0x7ac3, 0x84b2, 0x91dc, 0x938c, 0x565b, 0x9d28, 0x6822, 0x8305, 0x8431, /* 0xb4: 0xa1 - 0xfe*/ 0x7ca5, 0x5208, 0x82c5, 0x74e6, 0x4e7e, 0x4f83, 0x51a0, 0x5bd2, 0x520a, 0x52d8, 0x52e7, 0x5dfb, 0x559a, 0x582a, 0x59e6, 0x5b8c, 0x5b98, 0x5bdb, 0x5e72, 0x5e79, 0x60a3, 0x611f, 0x6163, 0x61be, 0x63db, 0x6562, 0x67d1, 0x6853, 0x68fa, 0x6b3e, 0x6b53, 0x6c57, 0x6f22, 0x6f97, 0x6f45, 0x74b0, 0x7518, 0x76e3, 0x770b, 0x7aff, 0x7ba1, 0x7c21, 0x7de9, 0x7f36, 0x7ff0, 0x809d, 0x8266, 0x839e, 0x89b3, 0x8acc, 0x8cab, 0x9084, 0x9451, 0x9593, 0x9591, 0x95a2, 0x9665, 0x97d3, 0x9928, 0x8218, 0x4e38, 0x542b, 0x5cb8, 0x5dcc, 0x73a9, 0x764c, 0x773c, 0x5ca9, 0x7feb, 0x8d0b, 0x96c1, 0x9811, 0x9854, 0x9858, 0x4f01, 0x4f0e, 0x5371, 0x559c, 0x5668, 0x57fa, 0x5947, 0x5b09, 0x5bc4, 0x5c90, 0x5e0c, 0x5e7e, 0x5fcc, 0x63ee, 0x673a, 0x65d7, 0x65e2, 0x671f, 0x68cb, 0x68c4, /* 0xb5: 0xa1 - 0xfe*/ 0x6a5f, 0x5e30, 0x6bc5, 0x6c17, 0x6c7d, 0x757f, 0x7948, 0x5b63, 0x7a00, 0x7d00, 0x5fbd, 0x898f, 0x8a18, 0x8cb4, 0x8d77, 0x8ecc, 0x8f1d, 0x98e2, 0x9a0e, 0x9b3c, 0x4e80, 0x507d, 0x5100, 0x5993, 0x5b9c, 0x622f, 0x6280, 0x64ec, 0x6b3a, 0x72a0, 0x7591, 0x7947, 0x7fa9, 0x87fb, 0x8abc, 0x8b70, 0x63ac, 0x83ca, 0x97a0, 0x5409, 0x5403, 0x55ab, 0x6854, 0x6a58, 0x8a70, 0x7827, 0x6775, 0x9ecd, 0x5374, 0x5ba2, 0x811a, 0x8650, 0x9006, 0x4e18, 0x4e45, 0x4ec7, 0x4f11, 0x53ca, 0x5438, 0x5bae, 0x5f13, 0x6025, 0x6551, 0x673d, 0x6c42, 0x6c72, 0x6ce3, 0x7078, 0x7403, 0x7a76, 0x7aae, 0x7b08, 0x7d1a, 0x7cfe, 0x7d66, 0x65e7, 0x725b, 0x53bb, 0x5c45, 0x5de8, 0x62d2, 0x62e0, 0x6319, 0x6e20, 0x865a, 0x8a31, 0x8ddd, 0x92f8, 0x6f01, 0x79a6, 0x9b5a, 0x4ea8, 0x4eab, 0x4eac, /* 0xb6: 0xa1 - 0xfe*/ 0x4f9b, 0x4fa0, 0x50d1, 0x5147, 0x7af6, 0x5171, 0x51f6, 0x5354, 0x5321, 0x537f, 0x53eb, 0x55ac, 0x5883, 0x5ce1, 0x5f37, 0x5f4a, 0x602f, 0x6050, 0x606d, 0x631f, 0x6559, 0x6a4b, 0x6cc1, 0x72c2, 0x72ed, 0x77ef, 0x80f8, 0x8105, 0x8208, 0x854e, 0x90f7, 0x93e1, 0x97ff, 0x9957, 0x9a5a, 0x4ef0, 0x51dd, 0x5c2d, 0x6681, 0x696d, 0x5c40, 0x66f2, 0x6975, 0x7389, 0x6850, 0x7c81, 0x50c5, 0x52e4, 0x5747, 0x5dfe, 0x9326, 0x65a4, 0x6b23, 0x6b3d, 0x7434, 0x7981, 0x79bd, 0x7b4b, 0x7dca, 0x82b9, 0x83cc, 0x887f, 0x895f, 0x8b39, 0x8fd1, 0x91d1, 0x541f, 0x9280, 0x4e5d, 0x5036, 0x53e5, 0x533a, 0x72d7, 0x7396, 0x77e9, 0x82e6, 0x8eaf, 0x99c6, 0x99c8, 0x99d2, 0x5177, 0x611a, 0x865e, 0x55b0, 0x7a7a, 0x5076, 0x5bd3, 0x9047, 0x9685, 0x4e32, 0x6adb, 0x91e7, 0x5c51, 0x5c48, /* 0xb7: 0xa1 - 0xfe*/ 0x6398, 0x7a9f, 0x6c93, 0x9774, 0x8f61, 0x7aaa, 0x718a, 0x9688, 0x7c82, 0x6817, 0x7e70, 0x6851, 0x936c, 0x52f2, 0x541b, 0x85ab, 0x8a13, 0x7fa4, 0x8ecd, 0x90e1, 0x5366, 0x8888, 0x7941, 0x4fc2, 0x50be, 0x5211, 0x5144, 0x5553, 0x572d, 0x73ea, 0x578b, 0x5951, 0x5f62, 0x5f84, 0x6075, 0x6176, 0x6167, 0x61a9, 0x63b2, 0x643a, 0x656c, 0x666f, 0x6842, 0x6e13, 0x7566, 0x7a3d, 0x7cfb, 0x7d4c, 0x7d99, 0x7e4b, 0x7f6b, 0x830e, 0x834a, 0x86cd, 0x8a08, 0x8a63, 0x8b66, 0x8efd, 0x981a, 0x9d8f, 0x82b8, 0x8fce, 0x9be8, 0x5287, 0x621f, 0x6483, 0x6fc0, 0x9699, 0x6841, 0x5091, 0x6b20, 0x6c7a, 0x6f54, 0x7a74, 0x7d50, 0x8840, 0x8a23, 0x6708, 0x4ef6, 0x5039, 0x5026, 0x5065, 0x517c, 0x5238, 0x5263, 0x55a7, 0x570f, 0x5805, 0x5acc, 0x5efa, 0x61b2, 0x61f8, 0x62f3, 0x6372, /* 0xb8: 0xa1 - 0xfe*/ 0x691c, 0x6a29, 0x727d, 0x72ac, 0x732e, 0x7814, 0x786f, 0x7d79, 0x770c, 0x80a9, 0x898b, 0x8b19, 0x8ce2, 0x8ed2, 0x9063, 0x9375, 0x967a, 0x9855, 0x9a13, 0x9e78, 0x5143, 0x539f, 0x53b3, 0x5e7b, 0x5f26, 0x6e1b, 0x6e90, 0x7384, 0x73fe, 0x7d43, 0x8237, 0x8a00, 0x8afa, 0x9650, 0x4e4e, 0x500b, 0x53e4, 0x547c, 0x56fa, 0x59d1, 0x5b64, 0x5df1, 0x5eab, 0x5f27, 0x6238, 0x6545, 0x67af, 0x6e56, 0x72d0, 0x7cca, 0x88b4, 0x80a1, 0x80e1, 0x83f0, 0x864e, 0x8a87, 0x8de8, 0x9237, 0x96c7, 0x9867, 0x9f13, 0x4e94, 0x4e92, 0x4f0d, 0x5348, 0x5449, 0x543e, 0x5a2f, 0x5f8c, 0x5fa1, 0x609f, 0x68a7, 0x6a8e, 0x745a, 0x7881, 0x8a9e, 0x8aa4, 0x8b77, 0x9190, 0x4e5e, 0x9bc9, 0x4ea4, 0x4f7c, 0x4faf, 0x5019, 0x5016, 0x5149, 0x516c, 0x529f, 0x52b9, 0x52fe, 0x539a, 0x53e3, 0x5411, /* 0xb9: 0xa1 - 0xfe*/ 0x540e, 0x5589, 0x5751, 0x57a2, 0x597d, 0x5b54, 0x5b5d, 0x5b8f, 0x5de5, 0x5de7, 0x5df7, 0x5e78, 0x5e83, 0x5e9a, 0x5eb7, 0x5f18, 0x6052, 0x614c, 0x6297, 0x62d8, 0x63a7, 0x653b, 0x6602, 0x6643, 0x66f4, 0x676d, 0x6821, 0x6897, 0x69cb, 0x6c5f, 0x6d2a, 0x6d69, 0x6e2f, 0x6e9d, 0x7532, 0x7687, 0x786c, 0x7a3f, 0x7ce0, 0x7d05, 0x7d18, 0x7d5e, 0x7db1, 0x8015, 0x8003, 0x80af, 0x80b1, 0x8154, 0x818f, 0x822a, 0x8352, 0x884c, 0x8861, 0x8b1b, 0x8ca2, 0x8cfc, 0x90ca, 0x9175, 0x9271, 0x783f, 0x92fc, 0x95a4, 0x964d, 0x9805, 0x9999, 0x9ad8, 0x9d3b, 0x525b, 0x52ab, 0x53f7, 0x5408, 0x58d5, 0x62f7, 0x6fe0, 0x8c6a, 0x8f5f, 0x9eb9, 0x514b, 0x523b, 0x544a, 0x56fd, 0x7a40, 0x9177, 0x9d60, 0x9ed2, 0x7344, 0x6f09, 0x8170, 0x7511, 0x5ffd, 0x60da, 0x9aa8, 0x72db, 0x8fbc, /* 0xba: 0xa1 - 0xfe*/ 0x6b64, 0x9803, 0x4eca, 0x56f0, 0x5764, 0x58be, 0x5a5a, 0x6068, 0x61c7, 0x660f, 0x6606, 0x6839, 0x68b1, 0x6df7, 0x75d5, 0x7d3a, 0x826e, 0x9b42, 0x4e9b, 0x4f50, 0x53c9, 0x5506, 0x5d6f, 0x5de6, 0x5dee, 0x67fb, 0x6c99, 0x7473, 0x7802, 0x8a50, 0x9396, 0x88df, 0x5750, 0x5ea7, 0x632b, 0x50b5, 0x50ac, 0x518d, 0x6700, 0x54c9, 0x585e, 0x59bb, 0x5bb0, 0x5f69, 0x624d, 0x63a1, 0x683d, 0x6b73, 0x6e08, 0x707d, 0x91c7, 0x7280, 0x7815, 0x7826, 0x796d, 0x658e, 0x7d30, 0x83dc, 0x88c1, 0x8f09, 0x969b, 0x5264, 0x5728, 0x6750, 0x7f6a, 0x8ca1, 0x51b4, 0x5742, 0x962a, 0x583a, 0x698a, 0x80b4, 0x54b2, 0x5d0e, 0x57fc, 0x7895, 0x9dfa, 0x4f5c, 0x524a, 0x548b, 0x643e, 0x6628, 0x6714, 0x67f5, 0x7a84, 0x7b56, 0x7d22, 0x932f, 0x685c, 0x9bad, 0x7b39, 0x5319, 0x518a, 0x5237, /* 0xbb: 0xa1 - 0xfe*/ 0x5bdf, 0x62f6, 0x64ae, 0x64e6, 0x672d, 0x6bba, 0x85a9, 0x96d1, 0x7690, 0x9bd6, 0x634c, 0x9306, 0x9bab, 0x76bf, 0x6652, 0x4e09, 0x5098, 0x53c2, 0x5c71, 0x60e8, 0x6492, 0x6563, 0x685f, 0x71e6, 0x73ca, 0x7523, 0x7b97, 0x7e82, 0x8695, 0x8b83, 0x8cdb, 0x9178, 0x9910, 0x65ac, 0x66ab, 0x6b8b, 0x4ed5, 0x4ed4, 0x4f3a, 0x4f7f, 0x523a, 0x53f8, 0x53f2, 0x55e3, 0x56db, 0x58eb, 0x59cb, 0x59c9, 0x59ff, 0x5b50, 0x5c4d, 0x5e02, 0x5e2b, 0x5fd7, 0x601d, 0x6307, 0x652f, 0x5b5c, 0x65af, 0x65bd, 0x65e8, 0x679d, 0x6b62, 0x6b7b, 0x6c0f, 0x7345, 0x7949, 0x79c1, 0x7cf8, 0x7d19, 0x7d2b, 0x80a2, 0x8102, 0x81f3, 0x8996, 0x8a5e, 0x8a69, 0x8a66, 0x8a8c, 0x8aee, 0x8cc7, 0x8cdc, 0x96cc, 0x98fc, 0x6b6f, 0x4e8b, 0x4f3c, 0x4f8d, 0x5150, 0x5b57, 0x5bfa, 0x6148, 0x6301, 0x6642, /* 0xbc: 0xa1 - 0xfe*/ 0x6b21, 0x6ecb, 0x6cbb, 0x723e, 0x74bd, 0x75d4, 0x78c1, 0x793a, 0x800c, 0x8033, 0x81ea, 0x8494, 0x8f9e, 0x6c50, 0x9e7f, 0x5f0f, 0x8b58, 0x9d2b, 0x7afa, 0x8ef8, 0x5b8d, 0x96eb, 0x4e03, 0x53f1, 0x57f7, 0x5931, 0x5ac9, 0x5ba4, 0x6089, 0x6e7f, 0x6f06, 0x75be, 0x8cea, 0x5b9f, 0x8500, 0x7be0, 0x5072, 0x67f4, 0x829d, 0x5c61, 0x854a, 0x7e1e, 0x820e, 0x5199, 0x5c04, 0x6368, 0x8d66, 0x659c, 0x716e, 0x793e, 0x7d17, 0x8005, 0x8b1d, 0x8eca, 0x906e, 0x86c7, 0x90aa, 0x501f, 0x52fa, 0x5c3a, 0x6753, 0x707c, 0x7235, 0x914c, 0x91c8, 0x932b, 0x82e5, 0x5bc2, 0x5f31, 0x60f9, 0x4e3b, 0x53d6, 0x5b88, 0x624b, 0x6731, 0x6b8a, 0x72e9, 0x73e0, 0x7a2e, 0x816b, 0x8da3, 0x9152, 0x9996, 0x5112, 0x53d7, 0x546a, 0x5bff, 0x6388, 0x6a39, 0x7dac, 0x9700, 0x56da, 0x53ce, 0x5468, /* 0xbd: 0xa1 - 0xfe*/ 0x5b97, 0x5c31, 0x5dde, 0x4fee, 0x6101, 0x62fe, 0x6d32, 0x79c0, 0x79cb, 0x7d42, 0x7e4d, 0x7fd2, 0x81ed, 0x821f, 0x8490, 0x8846, 0x8972, 0x8b90, 0x8e74, 0x8f2f, 0x9031, 0x914b, 0x916c, 0x96c6, 0x919c, 0x4ec0, 0x4f4f, 0x5145, 0x5341, 0x5f93, 0x620e, 0x67d4, 0x6c41, 0x6e0b, 0x7363, 0x7e26, 0x91cd, 0x9283, 0x53d4, 0x5919, 0x5bbf, 0x6dd1, 0x795d, 0x7e2e, 0x7c9b, 0x587e, 0x719f, 0x51fa, 0x8853, 0x8ff0, 0x4fca, 0x5cfb, 0x6625, 0x77ac, 0x7ae3, 0x821c, 0x99ff, 0x51c6, 0x5faa, 0x65ec, 0x696f, 0x6b89, 0x6df3, 0x6e96, 0x6f64, 0x76fe, 0x7d14, 0x5de1, 0x9075, 0x9187, 0x9806, 0x51e6, 0x521d, 0x6240, 0x6691, 0x66d9, 0x6e1a, 0x5eb6, 0x7dd2, 0x7f72, 0x66f8, 0x85af, 0x85f7, 0x8af8, 0x52a9, 0x53d9, 0x5973, 0x5e8f, 0x5f90, 0x6055, 0x92e4, 0x9664, 0x50b7, 0x511f, /* 0xbe: 0xa1 - 0xfe*/ 0x52dd, 0x5320, 0x5347, 0x53ec, 0x54e8, 0x5546, 0x5531, 0x5617, 0x5968, 0x59be, 0x5a3c, 0x5bb5, 0x5c06, 0x5c0f, 0x5c11, 0x5c1a, 0x5e84, 0x5e8a, 0x5ee0, 0x5f70, 0x627f, 0x6284, 0x62db, 0x638c, 0x6377, 0x6607, 0x660c, 0x662d, 0x6676, 0x677e, 0x68a2, 0x6a1f, 0x6a35, 0x6cbc, 0x6d88, 0x6e09, 0x6e58, 0x713c, 0x7126, 0x7167, 0x75c7, 0x7701, 0x785d, 0x7901, 0x7965, 0x79f0, 0x7ae0, 0x7b11, 0x7ca7, 0x7d39, 0x8096, 0x83d6, 0x848b, 0x8549, 0x885d, 0x88f3, 0x8a1f, 0x8a3c, 0x8a54, 0x8a73, 0x8c61, 0x8cde, 0x91a4, 0x9266, 0x937e, 0x9418, 0x969c, 0x9798, 0x4e0a, 0x4e08, 0x4e1e, 0x4e57, 0x5197, 0x5270, 0x57ce, 0x5834, 0x58cc, 0x5b22, 0x5e38, 0x60c5, 0x64fe, 0x6761, 0x6756, 0x6d44, 0x72b6, 0x7573, 0x7a63, 0x84b8, 0x8b72, 0x91b8, 0x9320, 0x5631, 0x57f4, 0x98fe, /* 0xbf: 0xa1 - 0xfe*/ 0x62ed, 0x690d, 0x6b96, 0x71ed, 0x7e54, 0x8077, 0x8272, 0x89e6, 0x98df, 0x8755, 0x8fb1, 0x5c3b, 0x4f38, 0x4fe1, 0x4fb5, 0x5507, 0x5a20, 0x5bdd, 0x5be9, 0x5fc3, 0x614e, 0x632f, 0x65b0, 0x664b, 0x68ee, 0x699b, 0x6d78, 0x6df1, 0x7533, 0x75b9, 0x771f, 0x795e, 0x79e6, 0x7d33, 0x81e3, 0x82af, 0x85aa, 0x89aa, 0x8a3a, 0x8eab, 0x8f9b, 0x9032, 0x91dd, 0x9707, 0x4eba, 0x4ec1, 0x5203, 0x5875, 0x58ec, 0x5c0b, 0x751a, 0x5c3d, 0x814e, 0x8a0a, 0x8fc5, 0x9663, 0x976d, 0x7b25, 0x8acf, 0x9808, 0x9162, 0x56f3, 0x53a8, 0x9017, 0x5439, 0x5782, 0x5e25, 0x63a8, 0x6c34, 0x708a, 0x7761, 0x7c8b, 0x7fe0, 0x8870, 0x9042, 0x9154, 0x9310, 0x9318, 0x968f, 0x745e, 0x9ac4, 0x5d07, 0x5d69, 0x6570, 0x67a2, 0x8da8, 0x96db, 0x636e, 0x6749, 0x6919, 0x83c5, 0x9817, 0x96c0, 0x88fe, /* 0xc0: 0xa1 - 0xfe*/ 0x6f84, 0x647a, 0x5bf8, 0x4e16, 0x702c, 0x755d, 0x662f, 0x51c4, 0x5236, 0x52e2, 0x59d3, 0x5f81, 0x6027, 0x6210, 0x653f, 0x6574, 0x661f, 0x6674, 0x68f2, 0x6816, 0x6b63, 0x6e05, 0x7272, 0x751f, 0x76db, 0x7cbe, 0x8056, 0x58f0, 0x88fd, 0x897f, 0x8aa0, 0x8a93, 0x8acb, 0x901d, 0x9192, 0x9752, 0x9759, 0x6589, 0x7a0e, 0x8106, 0x96bb, 0x5e2d, 0x60dc, 0x621a, 0x65a5, 0x6614, 0x6790, 0x77f3, 0x7a4d, 0x7c4d, 0x7e3e, 0x810a, 0x8cac, 0x8d64, 0x8de1, 0x8e5f, 0x78a9, 0x5207, 0x62d9, 0x63a5, 0x6442, 0x6298, 0x8a2d, 0x7a83, 0x7bc0, 0x8aac, 0x96ea, 0x7d76, 0x820c, 0x8749, 0x4ed9, 0x5148, 0x5343, 0x5360, 0x5ba3, 0x5c02, 0x5c16, 0x5ddd, 0x6226, 0x6247, 0x64b0, 0x6813, 0x6834, 0x6cc9, 0x6d45, 0x6d17, 0x67d3, 0x6f5c, 0x714e, 0x717d, 0x65cb, 0x7a7f, 0x7bad, 0x7dda, /* 0xc1: 0xa1 - 0xfe*/ 0x7e4a, 0x7fa8, 0x817a, 0x821b, 0x8239, 0x85a6, 0x8a6e, 0x8cce, 0x8df5, 0x9078, 0x9077, 0x92ad, 0x9291, 0x9583, 0x9bae, 0x524d, 0x5584, 0x6f38, 0x7136, 0x5168, 0x7985, 0x7e55, 0x81b3, 0x7cce, 0x564c, 0x5851, 0x5ca8, 0x63aa, 0x66fe, 0x66fd, 0x695a, 0x72d9, 0x758f, 0x758e, 0x790e, 0x7956, 0x79df, 0x7c97, 0x7d20, 0x7d44, 0x8607, 0x8a34, 0x963b, 0x9061, 0x9f20, 0x50e7, 0x5275, 0x53cc, 0x53e2, 0x5009, 0x55aa, 0x58ee, 0x594f, 0x723d, 0x5b8b, 0x5c64, 0x531d, 0x60e3, 0x60f3, 0x635c, 0x6383, 0x633f, 0x63bb, 0x64cd, 0x65e9, 0x66f9, 0x5de3, 0x69cd, 0x69fd, 0x6f15, 0x71e5, 0x4e89, 0x75e9, 0x76f8, 0x7a93, 0x7cdf, 0x7dcf, 0x7d9c, 0x8061, 0x8349, 0x8358, 0x846c, 0x84bc, 0x85fb, 0x88c5, 0x8d70, 0x9001, 0x906d, 0x9397, 0x971c, 0x9a12, 0x50cf, 0x5897, 0x618e, /* 0xc2: 0xa1 - 0xfe*/ 0x81d3, 0x8535, 0x8d08, 0x9020, 0x4fc3, 0x5074, 0x5247, 0x5373, 0x606f, 0x6349, 0x675f, 0x6e2c, 0x8db3, 0x901f, 0x4fd7, 0x5c5e, 0x8cca, 0x65cf, 0x7d9a, 0x5352, 0x8896, 0x5176, 0x63c3, 0x5b58, 0x5b6b, 0x5c0a, 0x640d, 0x6751, 0x905c, 0x4ed6, 0x591a, 0x592a, 0x6c70, 0x8a51, 0x553e, 0x5815, 0x59a5, 0x60f0, 0x6253, 0x67c1, 0x8235, 0x6955, 0x9640, 0x99c4, 0x9a28, 0x4f53, 0x5806, 0x5bfe, 0x8010, 0x5cb1, 0x5e2f, 0x5f85, 0x6020, 0x614b, 0x6234, 0x66ff, 0x6cf0, 0x6ede, 0x80ce, 0x817f, 0x82d4, 0x888b, 0x8cb8, 0x9000, 0x902e, 0x968a, 0x9edb, 0x9bdb, 0x4ee3, 0x53f0, 0x5927, 0x7b2c, 0x918d, 0x984c, 0x9df9, 0x6edd, 0x7027, 0x5353, 0x5544, 0x5b85, 0x6258, 0x629e, 0x62d3, 0x6ca2, 0x6fef, 0x7422, 0x8a17, 0x9438, 0x6fc1, 0x8afe, 0x8338, 0x51e7, 0x86f8, 0x53ea, /* 0xc3: 0xa1 - 0xfe*/ 0x53e9, 0x4f46, 0x9054, 0x8fb0, 0x596a, 0x8131, 0x5dfd, 0x7aea, 0x8fbf, 0x68da, 0x8c37, 0x72f8, 0x9c48, 0x6a3d, 0x8ab0, 0x4e39, 0x5358, 0x5606, 0x5766, 0x62c5, 0x63a2, 0x65e6, 0x6b4e, 0x6de1, 0x6e5b, 0x70ad, 0x77ed, 0x7aef, 0x7baa, 0x7dbb, 0x803d, 0x80c6, 0x86cb, 0x8a95, 0x935b, 0x56e3, 0x58c7, 0x5f3e, 0x65ad, 0x6696, 0x6a80, 0x6bb5, 0x7537, 0x8ac7, 0x5024, 0x77e5, 0x5730, 0x5f1b, 0x6065, 0x667a, 0x6c60, 0x75f4, 0x7a1a, 0x7f6e, 0x81f4, 0x8718, 0x9045, 0x99b3, 0x7bc9, 0x755c, 0x7af9, 0x7b51, 0x84c4, 0x9010, 0x79e9, 0x7a92, 0x8336, 0x5ae1, 0x7740, 0x4e2d, 0x4ef2, 0x5b99, 0x5fe0, 0x62bd, 0x663c, 0x67f1, 0x6ce8, 0x866b, 0x8877, 0x8a3b, 0x914e, 0x92f3, 0x99d0, 0x6a17, 0x7026, 0x732a, 0x82e7, 0x8457, 0x8caf, 0x4e01, 0x5146, 0x51cb, 0x558b, 0x5bf5, /* 0xc4: 0xa1 - 0xfe*/ 0x5e16, 0x5e33, 0x5e81, 0x5f14, 0x5f35, 0x5f6b, 0x5fb4, 0x61f2, 0x6311, 0x66a2, 0x671d, 0x6f6e, 0x7252, 0x753a, 0x773a, 0x8074, 0x8139, 0x8178, 0x8776, 0x8abf, 0x8adc, 0x8d85, 0x8df3, 0x929a, 0x9577, 0x9802, 0x9ce5, 0x52c5, 0x6357, 0x76f4, 0x6715, 0x6c88, 0x73cd, 0x8cc3, 0x93ae, 0x9673, 0x6d25, 0x589c, 0x690e, 0x69cc, 0x8ffd, 0x939a, 0x75db, 0x901a, 0x585a, 0x6802, 0x63b4, 0x69fb, 0x4f43, 0x6f2c, 0x67d8, 0x8fbb, 0x8526, 0x7db4, 0x9354, 0x693f, 0x6f70, 0x576a, 0x58f7, 0x5b2c, 0x7d2c, 0x722a, 0x540a, 0x91e3, 0x9db4, 0x4ead, 0x4f4e, 0x505c, 0x5075, 0x5243, 0x8c9e, 0x5448, 0x5824, 0x5b9a, 0x5e1d, 0x5e95, 0x5ead, 0x5ef7, 0x5f1f, 0x608c, 0x62b5, 0x633a, 0x63d0, 0x68af, 0x6c40, 0x7887, 0x798e, 0x7a0b, 0x7de0, 0x8247, 0x8a02, 0x8ae6, 0x8e44, 0x9013, /* 0xc5: 0xa1 - 0xfe*/ 0x90b8, 0x912d, 0x91d8, 0x9f0e, 0x6ce5, 0x6458, 0x64e2, 0x6575, 0x6ef4, 0x7684, 0x7b1b, 0x9069, 0x93d1, 0x6eba, 0x54f2, 0x5fb9, 0x64a4, 0x8f4d, 0x8fed, 0x9244, 0x5178, 0x586b, 0x5929, 0x5c55, 0x5e97, 0x6dfb, 0x7e8f, 0x751c, 0x8cbc, 0x8ee2, 0x985b, 0x70b9, 0x4f1d, 0x6bbf, 0x6fb1, 0x7530, 0x96fb, 0x514e, 0x5410, 0x5835, 0x5857, 0x59ac, 0x5c60, 0x5f92, 0x6597, 0x675c, 0x6e21, 0x767b, 0x83df, 0x8ced, 0x9014, 0x90fd, 0x934d, 0x7825, 0x783a, 0x52aa, 0x5ea6, 0x571f, 0x5974, 0x6012, 0x5012, 0x515a, 0x51ac, 0x51cd, 0x5200, 0x5510, 0x5854, 0x5858, 0x5957, 0x5b95, 0x5cf6, 0x5d8b, 0x60bc, 0x6295, 0x642d, 0x6771, 0x6843, 0x68bc, 0x68df, 0x76d7, 0x6dd8, 0x6e6f, 0x6d9b, 0x706f, 0x71c8, 0x5f53, 0x75d8, 0x7977, 0x7b49, 0x7b54, 0x7b52, 0x7cd6, 0x7d71, 0x5230, /* 0xc6: 0xa1 - 0xfe*/ 0x8463, 0x8569, 0x85e4, 0x8a0e, 0x8b04, 0x8c46, 0x8e0f, 0x9003, 0x900f, 0x9419, 0x9676, 0x982d, 0x9a30, 0x95d8, 0x50cd, 0x52d5, 0x540c, 0x5802, 0x5c0e, 0x61a7, 0x649e, 0x6d1e, 0x77b3, 0x7ae5, 0x80f4, 0x8404, 0x9053, 0x9285, 0x5ce0, 0x9d07, 0x533f, 0x5f97, 0x5fb3, 0x6d9c, 0x7279, 0x7763, 0x79bf, 0x7be4, 0x6bd2, 0x72ec, 0x8aad, 0x6803, 0x6a61, 0x51f8, 0x7a81, 0x6934, 0x5c4a, 0x9cf6, 0x82eb, 0x5bc5, 0x9149, 0x701e, 0x5678, 0x5c6f, 0x60c7, 0x6566, 0x6c8c, 0x8c5a, 0x9041, 0x9813, 0x5451, 0x66c7, 0x920d, 0x5948, 0x90a3, 0x5185, 0x4e4d, 0x51ea, 0x8599, 0x8b0e, 0x7058, 0x637a, 0x934b, 0x6962, 0x99b4, 0x7e04, 0x7577, 0x5357, 0x6960, 0x8edf, 0x96e3, 0x6c5d, 0x4e8c, 0x5c3c, 0x5f10, 0x8fe9, 0x5302, 0x8cd1, 0x8089, 0x8679, 0x5eff, 0x65e5, 0x4e73, 0x5165, /* 0xc7: 0xa1 - 0xfe*/ 0x5982, 0x5c3f, 0x97ee, 0x4efb, 0x598a, 0x5fcd, 0x8a8d, 0x6fe1, 0x79b0, 0x7962, 0x5be7, 0x8471, 0x732b, 0x71b1, 0x5e74, 0x5ff5, 0x637b, 0x649a, 0x71c3, 0x7c98, 0x4e43, 0x5efc, 0x4e4b, 0x57dc, 0x56a2, 0x60a9, 0x6fc3, 0x7d0d, 0x80fd, 0x8133, 0x81bf, 0x8fb2, 0x8997, 0x86a4, 0x5df4, 0x628a, 0x64ad, 0x8987, 0x6777, 0x6ce2, 0x6d3e, 0x7436, 0x7834, 0x5a46, 0x7f75, 0x82ad, 0x99ac, 0x4ff3, 0x5ec3, 0x62dd, 0x6392, 0x6557, 0x676f, 0x76c3, 0x724c, 0x80cc, 0x80ba, 0x8f29, 0x914d, 0x500d, 0x57f9, 0x5a92, 0x6885, 0x6973, 0x7164, 0x72fd, 0x8cb7, 0x58f2, 0x8ce0, 0x966a, 0x9019, 0x877f, 0x79e4, 0x77e7, 0x8429, 0x4f2f, 0x5265, 0x535a, 0x62cd, 0x67cf, 0x6cca, 0x767d, 0x7b94, 0x7c95, 0x8236, 0x8584, 0x8feb, 0x66dd, 0x6f20, 0x7206, 0x7e1b, 0x83ab, 0x99c1, 0x9ea6, /* 0xc8: 0xa1 - 0xfe*/ 0x51fd, 0x7bb1, 0x7872, 0x7bb8, 0x8087, 0x7b48, 0x6ae8, 0x5e61, 0x808c, 0x7551, 0x7560, 0x516b, 0x9262, 0x6e8c, 0x767a, 0x9197, 0x9aea, 0x4f10, 0x7f70, 0x629c, 0x7b4f, 0x95a5, 0x9ce9, 0x567a, 0x5859, 0x86e4, 0x96bc, 0x4f34, 0x5224, 0x534a, 0x53cd, 0x53db, 0x5e06, 0x642c, 0x6591, 0x677f, 0x6c3e, 0x6c4e, 0x7248, 0x72af, 0x73ed, 0x7554, 0x7e41, 0x822c, 0x85e9, 0x8ca9, 0x7bc4, 0x91c6, 0x7169, 0x9812, 0x98ef, 0x633d, 0x6669, 0x756a, 0x76e4, 0x78d0, 0x8543, 0x86ee, 0x532a, 0x5351, 0x5426, 0x5983, 0x5e87, 0x5f7c, 0x60b2, 0x6249, 0x6279, 0x62ab, 0x6590, 0x6bd4, 0x6ccc, 0x75b2, 0x76ae, 0x7891, 0x79d8, 0x7dcb, 0x7f77, 0x80a5, 0x88ab, 0x8ab9, 0x8cbb, 0x907f, 0x975e, 0x98db, 0x6a0b, 0x7c38, 0x5099, 0x5c3e, 0x5fae, 0x6787, 0x6bd8, 0x7435, 0x7709, 0x7f8e, /* 0xc9: 0xa1 - 0xfe*/ 0x9f3b, 0x67ca, 0x7a17, 0x5339, 0x758b, 0x9aed, 0x5f66, 0x819d, 0x83f1, 0x8098, 0x5f3c, 0x5fc5, 0x7562, 0x7b46, 0x903c, 0x6867, 0x59eb, 0x5a9b, 0x7d10, 0x767e, 0x8b2c, 0x4ff5, 0x5f6a, 0x6a19, 0x6c37, 0x6f02, 0x74e2, 0x7968, 0x8868, 0x8a55, 0x8c79, 0x5edf, 0x63cf, 0x75c5, 0x79d2, 0x82d7, 0x9328, 0x92f2, 0x849c, 0x86ed, 0x9c2d, 0x54c1, 0x5f6c, 0x658c, 0x6d5c, 0x7015, 0x8ca7, 0x8cd3, 0x983b, 0x654f, 0x74f6, 0x4e0d, 0x4ed8, 0x57e0, 0x592b, 0x5a66, 0x5bcc, 0x51a8, 0x5e03, 0x5e9c, 0x6016, 0x6276, 0x6577, 0x65a7, 0x666e, 0x6d6e, 0x7236, 0x7b26, 0x8150, 0x819a, 0x8299, 0x8b5c, 0x8ca0, 0x8ce6, 0x8d74, 0x961c, 0x9644, 0x4fae, 0x64ab, 0x6b66, 0x821e, 0x8461, 0x856a, 0x90e8, 0x5c01, 0x6953, 0x98a8, 0x847a, 0x8557, 0x4f0f, 0x526f, 0x5fa9, 0x5e45, 0x670d, /* 0xca: 0xa1 - 0xfe*/ 0x798f, 0x8179, 0x8907, 0x8986, 0x6df5, 0x5f17, 0x6255, 0x6cb8, 0x4ecf, 0x7269, 0x9b92, 0x5206, 0x543b, 0x5674, 0x58b3, 0x61a4, 0x626e, 0x711a, 0x596e, 0x7c89, 0x7cde, 0x7d1b, 0x96f0, 0x6587, 0x805e, 0x4e19, 0x4f75, 0x5175, 0x5840, 0x5e63, 0x5e73, 0x5f0a, 0x67c4, 0x4e26, 0x853d, 0x9589, 0x965b, 0x7c73, 0x9801, 0x50fb, 0x58c1, 0x7656, 0x78a7, 0x5225, 0x77a5, 0x8511, 0x7b86, 0x504f, 0x5909, 0x7247, 0x7bc7, 0x7de8, 0x8fba, 0x8fd4, 0x904d, 0x4fbf, 0x52c9, 0x5a29, 0x5f01, 0x97ad, 0x4fdd, 0x8217, 0x92ea, 0x5703, 0x6355, 0x6b69, 0x752b, 0x88dc, 0x8f14, 0x7a42, 0x52df, 0x5893, 0x6155, 0x620a, 0x66ae, 0x6bcd, 0x7c3f, 0x83e9, 0x5023, 0x4ff8, 0x5305, 0x5446, 0x5831, 0x5949, 0x5b9d, 0x5cf0, 0x5cef, 0x5d29, 0x5e96, 0x62b1, 0x6367, 0x653e, 0x65b9, 0x670b, /* 0xcb: 0xa1 - 0xfe*/ 0x6cd5, 0x6ce1, 0x70f9, 0x7832, 0x7e2b, 0x80de, 0x82b3, 0x840c, 0x84ec, 0x8702, 0x8912, 0x8a2a, 0x8c4a, 0x90a6, 0x92d2, 0x98fd, 0x9cf3, 0x9d6c, 0x4e4f, 0x4ea1, 0x508d, 0x5256, 0x574a, 0x59a8, 0x5e3d, 0x5fd8, 0x5fd9, 0x623f, 0x66b4, 0x671b, 0x67d0, 0x68d2, 0x5192, 0x7d21, 0x80aa, 0x81a8, 0x8b00, 0x8c8c, 0x8cbf, 0x927e, 0x9632, 0x5420, 0x982c, 0x5317, 0x50d5, 0x535c, 0x58a8, 0x64b2, 0x6734, 0x7267, 0x7766, 0x7a46, 0x91e6, 0x52c3, 0x6ca1, 0x6b86, 0x5800, 0x5e4c, 0x5954, 0x672c, 0x7ffb, 0x51e1, 0x76c6, 0x6469, 0x78e8, 0x9b54, 0x9ebb, 0x57cb, 0x59b9, 0x6627, 0x679a, 0x6bce, 0x54e9, 0x69d9, 0x5e55, 0x819c, 0x6795, 0x9baa, 0x67fe, 0x9c52, 0x685d, 0x4ea6, 0x4fe3, 0x53c8, 0x62b9, 0x672b, 0x6cab, 0x8fc4, 0x4fad, 0x7e6d, 0x9ebf, 0x4e07, 0x6162, 0x6e80, /* 0xcc: 0xa1 - 0xfe*/ 0x6f2b, 0x8513, 0x5473, 0x672a, 0x9b45, 0x5df3, 0x7b95, 0x5cac, 0x5bc6, 0x871c, 0x6e4a, 0x84d1, 0x7a14, 0x8108, 0x5999, 0x7c8d, 0x6c11, 0x7720, 0x52d9, 0x5922, 0x7121, 0x725f, 0x77db, 0x9727, 0x9d61, 0x690b, 0x5a7f, 0x5a18, 0x51a5, 0x540d, 0x547d, 0x660e, 0x76df, 0x8ff7, 0x9298, 0x9cf4, 0x59ea, 0x725d, 0x6ec5, 0x514d, 0x68c9, 0x7dbf, 0x7dec, 0x9762, 0x9eba, 0x6478, 0x6a21, 0x8302, 0x5984, 0x5b5f, 0x6bdb, 0x731b, 0x76f2, 0x7db2, 0x8017, 0x8499, 0x5132, 0x6728, 0x9ed9, 0x76ee, 0x6762, 0x52ff, 0x9905, 0x5c24, 0x623b, 0x7c7e, 0x8cb0, 0x554f, 0x60b6, 0x7d0b, 0x9580, 0x5301, 0x4e5f, 0x51b6, 0x591c, 0x723a, 0x8036, 0x91ce, 0x5f25, 0x77e2, 0x5384, 0x5f79, 0x7d04, 0x85ac, 0x8a33, 0x8e8d, 0x9756, 0x67f3, 0x85ae, 0x9453, 0x6109, 0x6108, 0x6cb9, 0x7652, /* 0xcd: 0xa1 - 0xfe*/ 0x8aed, 0x8f38, 0x552f, 0x4f51, 0x512a, 0x52c7, 0x53cb, 0x5ba5, 0x5e7d, 0x60a0, 0x6182, 0x63d6, 0x6709, 0x67da, 0x6e67, 0x6d8c, 0x7336, 0x7337, 0x7531, 0x7950, 0x88d5, 0x8a98, 0x904a, 0x9091, 0x90f5, 0x96c4, 0x878d, 0x5915, 0x4e88, 0x4f59, 0x4e0e, 0x8a89, 0x8f3f, 0x9810, 0x50ad, 0x5e7c, 0x5996, 0x5bb9, 0x5eb8, 0x63da, 0x63fa, 0x64c1, 0x66dc, 0x694a, 0x69d8, 0x6d0b, 0x6eb6, 0x7194, 0x7528, 0x7aaf, 0x7f8a, 0x8000, 0x8449, 0x84c9, 0x8981, 0x8b21, 0x8e0a, 0x9065, 0x967d, 0x990a, 0x617e, 0x6291, 0x6b32, 0x6c83, 0x6d74, 0x7fcc, 0x7ffc, 0x6dc0, 0x7f85, 0x87ba, 0x88f8, 0x6765, 0x83b1, 0x983c, 0x96f7, 0x6d1b, 0x7d61, 0x843d, 0x916a, 0x4e71, 0x5375, 0x5d50, 0x6b04, 0x6feb, 0x85cd, 0x862d, 0x89a7, 0x5229, 0x540f, 0x5c65, 0x674e, 0x68a8, 0x7406, 0x7483, /* 0xce: 0xa1 - 0xfe*/ 0x75e2, 0x88cf, 0x88e1, 0x91cc, 0x96e2, 0x9678, 0x5f8b, 0x7387, 0x7acb, 0x844e, 0x63a0, 0x7565, 0x5289, 0x6d41, 0x6e9c, 0x7409, 0x7559, 0x786b, 0x7c92, 0x9686, 0x7adc, 0x9f8d, 0x4fb6, 0x616e, 0x65c5, 0x865c, 0x4e86, 0x4eae, 0x50da, 0x4e21, 0x51cc, 0x5bee, 0x6599, 0x6881, 0x6dbc, 0x731f, 0x7642, 0x77ad, 0x7a1c, 0x7ce7, 0x826f, 0x8ad2, 0x907c, 0x91cf, 0x9675, 0x9818, 0x529b, 0x7dd1, 0x502b, 0x5398, 0x6797, 0x6dcb, 0x71d0, 0x7433, 0x81e8, 0x8f2a, 0x96a3, 0x9c57, 0x9e9f, 0x7460, 0x5841, 0x6d99, 0x7d2f, 0x985e, 0x4ee4, 0x4f36, 0x4f8b, 0x51b7, 0x52b1, 0x5dba, 0x601c, 0x73b2, 0x793c, 0x82d3, 0x9234, 0x96b7, 0x96f6, 0x970a, 0x9e97, 0x9f62, 0x66a6, 0x6b74, 0x5217, 0x52a3, 0x70c8, 0x88c2, 0x5ec9, 0x604b, 0x6190, 0x6f23, 0x7149, 0x7c3e, 0x7df4, 0x806f, /* 0xcf: 0xa1 - 0xd3*/ 0x84ee, 0x9023, 0x932c, 0x5442, 0x9b6f, 0x6ad3, 0x7089, 0x8cc2, 0x8def, 0x9732, 0x52b4, 0x5a41, 0x5eca, 0x5f04, 0x6717, 0x697c, 0x6994, 0x6d6a, 0x6f0f, 0x7262, 0x72fc, 0x7bed, 0x8001, 0x807e, 0x874b, 0x90ce, 0x516d, 0x9e93, 0x7984, 0x808b, 0x9332, 0x8ad6, 0x502d, 0x548c, 0x8a71, 0x6b6a, 0x8cc4, 0x8107, 0x60d1, 0x67a0, 0x9df2, 0x4e99, 0x4e98, 0x9c10, 0x8a6b, 0x85c1, 0x8568, 0x6900, 0x6e7e, 0x7897, 0x8155, /* 0xd0: 0xa1 - 0xfe*/ 0x5f0c, 0x4e10, 0x4e15, 0x4e2a, 0x4e31, 0x4e36, 0x4e3c, 0x4e3f, 0x4e42, 0x4e56, 0x4e58, 0x4e82, 0x4e85, 0x8c6b, 0x4e8a, 0x8212, 0x5f0d, 0x4e8e, 0x4e9e, 0x4e9f, 0x4ea0, 0x4ea2, 0x4eb0, 0x4eb3, 0x4eb6, 0x4ece, 0x4ecd, 0x4ec4, 0x4ec6, 0x4ec2, 0x4ed7, 0x4ede, 0x4eed, 0x4edf, 0x4ef7, 0x4f09, 0x4f5a, 0x4f30, 0x4f5b, 0x4f5d, 0x4f57, 0x4f47, 0x4f76, 0x4f88, 0x4f8f, 0x4f98, 0x4f7b, 0x4f69, 0x4f70, 0x4f91, 0x4f6f, 0x4f86, 0x4f96, 0x5118, 0x4fd4, 0x4fdf, 0x4fce, 0x4fd8, 0x4fdb, 0x4fd1, 0x4fda, 0x4fd0, 0x4fe4, 0x4fe5, 0x501a, 0x5028, 0x5014, 0x502a, 0x5025, 0x5005, 0x4f1c, 0x4ff6, 0x5021, 0x5029, 0x502c, 0x4ffe, 0x4fef, 0x5011, 0x5006, 0x5043, 0x5047, 0x6703, 0x5055, 0x5050, 0x5048, 0x505a, 0x5056, 0x506c, 0x5078, 0x5080, 0x509a, 0x5085, 0x50b4, 0x50b2, /* 0xd1: 0xa1 - 0xfe*/ 0x50c9, 0x50ca, 0x50b3, 0x50c2, 0x50d6, 0x50de, 0x50e5, 0x50ed, 0x50e3, 0x50ee, 0x50f9, 0x50f5, 0x5109, 0x5101, 0x5102, 0x5116, 0x5115, 0x5114, 0x511a, 0x5121, 0x513a, 0x5137, 0x513c, 0x513b, 0x513f, 0x5140, 0x5152, 0x514c, 0x5154, 0x5162, 0x7af8, 0x5169, 0x516a, 0x516e, 0x5180, 0x5182, 0x56d8, 0x518c, 0x5189, 0x518f, 0x5191, 0x5193, 0x5195, 0x5196, 0x51a4, 0x51a6, 0x51a2, 0x51a9, 0x51aa, 0x51ab, 0x51b3, 0x51b1, 0x51b2, 0x51b0, 0x51b5, 0x51bd, 0x51c5, 0x51c9, 0x51db, 0x51e0, 0x8655, 0x51e9, 0x51ed, 0x51f0, 0x51f5, 0x51fe, 0x5204, 0x520b, 0x5214, 0x520e, 0x5227, 0x522a, 0x522e, 0x5233, 0x5239, 0x524f, 0x5244, 0x524b, 0x524c, 0x525e, 0x5254, 0x526a, 0x5274, 0x5269, 0x5273, 0x527f, 0x527d, 0x528d, 0x5294, 0x5292, 0x5271, 0x5288, 0x5291, 0x8fa8, /* 0xd2: 0xa1 - 0xfe*/ 0x8fa7, 0x52ac, 0x52ad, 0x52bc, 0x52b5, 0x52c1, 0x52cd, 0x52d7, 0x52de, 0x52e3, 0x52e6, 0x98ed, 0x52e0, 0x52f3, 0x52f5, 0x52f8, 0x52f9, 0x5306, 0x5308, 0x7538, 0x530d, 0x5310, 0x530f, 0x5315, 0x531a, 0x5323, 0x532f, 0x5331, 0x5333, 0x5338, 0x5340, 0x5346, 0x5345, 0x4e17, 0x5349, 0x534d, 0x51d6, 0x535e, 0x5369, 0x536e, 0x5918, 0x537b, 0x5377, 0x5382, 0x5396, 0x53a0, 0x53a6, 0x53a5, 0x53ae, 0x53b0, 0x53b6, 0x53c3, 0x7c12, 0x96d9, 0x53df, 0x66fc, 0x71ee, 0x53ee, 0x53e8, 0x53ed, 0x53fa, 0x5401, 0x543d, 0x5440, 0x542c, 0x542d, 0x543c, 0x542e, 0x5436, 0x5429, 0x541d, 0x544e, 0x548f, 0x5475, 0x548e, 0x545f, 0x5471, 0x5477, 0x5470, 0x5492, 0x547b, 0x5480, 0x5476, 0x5484, 0x5490, 0x5486, 0x54c7, 0x54a2, 0x54b8, 0x54a5, 0x54ac, 0x54c4, 0x54c8, 0x54a8, /* 0xd3: 0xa1 - 0xfe*/ 0x54ab, 0x54c2, 0x54a4, 0x54be, 0x54bc, 0x54d8, 0x54e5, 0x54e6, 0x550f, 0x5514, 0x54fd, 0x54ee, 0x54ed, 0x54fa, 0x54e2, 0x5539, 0x5540, 0x5563, 0x554c, 0x552e, 0x555c, 0x5545, 0x5556, 0x5557, 0x5538, 0x5533, 0x555d, 0x5599, 0x5580, 0x54af, 0x558a, 0x559f, 0x557b, 0x557e, 0x5598, 0x559e, 0x55ae, 0x557c, 0x5583, 0x55a9, 0x5587, 0x55a8, 0x55da, 0x55c5, 0x55df, 0x55c4, 0x55dc, 0x55e4, 0x55d4, 0x5614, 0x55f7, 0x5616, 0x55fe, 0x55fd, 0x561b, 0x55f9, 0x564e, 0x5650, 0x71df, 0x5634, 0x5636, 0x5632, 0x5638, 0x566b, 0x5664, 0x562f, 0x566c, 0x566a, 0x5686, 0x5680, 0x568a, 0x56a0, 0x5694, 0x568f, 0x56a5, 0x56ae, 0x56b6, 0x56b4, 0x56c2, 0x56bc, 0x56c1, 0x56c3, 0x56c0, 0x56c8, 0x56ce, 0x56d1, 0x56d3, 0x56d7, 0x56ee, 0x56f9, 0x5700, 0x56ff, 0x5704, 0x5709, /* 0xd4: 0xa1 - 0xfe*/ 0x5708, 0x570b, 0x570d, 0x5713, 0x5718, 0x5716, 0x55c7, 0x571c, 0x5726, 0x5737, 0x5738, 0x574e, 0x573b, 0x5740, 0x574f, 0x5769, 0x57c0, 0x5788, 0x5761, 0x577f, 0x5789, 0x5793, 0x57a0, 0x57b3, 0x57a4, 0x57aa, 0x57b0, 0x57c3, 0x57c6, 0x57d4, 0x57d2, 0x57d3, 0x580a, 0x57d6, 0x57e3, 0x580b, 0x5819, 0x581d, 0x5872, 0x5821, 0x5862, 0x584b, 0x5870, 0x6bc0, 0x5852, 0x583d, 0x5879, 0x5885, 0x58b9, 0x589f, 0x58ab, 0x58ba, 0x58de, 0x58bb, 0x58b8, 0x58ae, 0x58c5, 0x58d3, 0x58d1, 0x58d7, 0x58d9, 0x58d8, 0x58e5, 0x58dc, 0x58e4, 0x58df, 0x58ef, 0x58fa, 0x58f9, 0x58fb, 0x58fc, 0x58fd, 0x5902, 0x590a, 0x5910, 0x591b, 0x68a6, 0x5925, 0x592c, 0x592d, 0x5932, 0x5938, 0x593e, 0x7ad2, 0x5955, 0x5950, 0x594e, 0x595a, 0x5958, 0x5962, 0x5960, 0x5967, 0x596c, 0x5969, /* 0xd5: 0xa1 - 0xfe*/ 0x5978, 0x5981, 0x599d, 0x4f5e, 0x4fab, 0x59a3, 0x59b2, 0x59c6, 0x59e8, 0x59dc, 0x598d, 0x59d9, 0x59da, 0x5a25, 0x5a1f, 0x5a11, 0x5a1c, 0x5a09, 0x5a1a, 0x5a40, 0x5a6c, 0x5a49, 0x5a35, 0x5a36, 0x5a62, 0x5a6a, 0x5a9a, 0x5abc, 0x5abe, 0x5acb, 0x5ac2, 0x5abd, 0x5ae3, 0x5ad7, 0x5ae6, 0x5ae9, 0x5ad6, 0x5afa, 0x5afb, 0x5b0c, 0x5b0b, 0x5b16, 0x5b32, 0x5ad0, 0x5b2a, 0x5b36, 0x5b3e, 0x5b43, 0x5b45, 0x5b40, 0x5b51, 0x5b55, 0x5b5a, 0x5b5b, 0x5b65, 0x5b69, 0x5b70, 0x5b73, 0x5b75, 0x5b78, 0x6588, 0x5b7a, 0x5b80, 0x5b83, 0x5ba6, 0x5bb8, 0x5bc3, 0x5bc7, 0x5bc9, 0x5bd4, 0x5bd0, 0x5be4, 0x5be6, 0x5be2, 0x5bde, 0x5be5, 0x5beb, 0x5bf0, 0x5bf6, 0x5bf3, 0x5c05, 0x5c07, 0x5c08, 0x5c0d, 0x5c13, 0x5c20, 0x5c22, 0x5c28, 0x5c38, 0x5c39, 0x5c41, 0x5c46, 0x5c4e, 0x5c53, /* 0xd6: 0xa1 - 0xfe*/ 0x5c50, 0x5c4f, 0x5b71, 0x5c6c, 0x5c6e, 0x4e62, 0x5c76, 0x5c79, 0x5c8c, 0x5c91, 0x5c94, 0x599b, 0x5cab, 0x5cbb, 0x5cb6, 0x5cbc, 0x5cb7, 0x5cc5, 0x5cbe, 0x5cc7, 0x5cd9, 0x5ce9, 0x5cfd, 0x5cfa, 0x5ced, 0x5d8c, 0x5cea, 0x5d0b, 0x5d15, 0x5d17, 0x5d5c, 0x5d1f, 0x5d1b, 0x5d11, 0x5d14, 0x5d22, 0x5d1a, 0x5d19, 0x5d18, 0x5d4c, 0x5d52, 0x5d4e, 0x5d4b, 0x5d6c, 0x5d73, 0x5d76, 0x5d87, 0x5d84, 0x5d82, 0x5da2, 0x5d9d, 0x5dac, 0x5dae, 0x5dbd, 0x5d90, 0x5db7, 0x5dbc, 0x5dc9, 0x5dcd, 0x5dd3, 0x5dd2, 0x5dd6, 0x5ddb, 0x5deb, 0x5df2, 0x5df5, 0x5e0b, 0x5e1a, 0x5e19, 0x5e11, 0x5e1b, 0x5e36, 0x5e37, 0x5e44, 0x5e43, 0x5e40, 0x5e4e, 0x5e57, 0x5e54, 0x5e5f, 0x5e62, 0x5e64, 0x5e47, 0x5e75, 0x5e76, 0x5e7a, 0x9ebc, 0x5e7f, 0x5ea0, 0x5ec1, 0x5ec2, 0x5ec8, 0x5ed0, 0x5ecf, /* 0xd7: 0xa1 - 0xfe*/ 0x5ed6, 0x5ee3, 0x5edd, 0x5eda, 0x5edb, 0x5ee2, 0x5ee1, 0x5ee8, 0x5ee9, 0x5eec, 0x5ef1, 0x5ef3, 0x5ef0, 0x5ef4, 0x5ef8, 0x5efe, 0x5f03, 0x5f09, 0x5f5d, 0x5f5c, 0x5f0b, 0x5f11, 0x5f16, 0x5f29, 0x5f2d, 0x5f38, 0x5f41, 0x5f48, 0x5f4c, 0x5f4e, 0x5f2f, 0x5f51, 0x5f56, 0x5f57, 0x5f59, 0x5f61, 0x5f6d, 0x5f73, 0x5f77, 0x5f83, 0x5f82, 0x5f7f, 0x5f8a, 0x5f88, 0x5f91, 0x5f87, 0x5f9e, 0x5f99, 0x5f98, 0x5fa0, 0x5fa8, 0x5fad, 0x5fbc, 0x5fd6, 0x5ffb, 0x5fe4, 0x5ff8, 0x5ff1, 0x5fdd, 0x60b3, 0x5fff, 0x6021, 0x6060, 0x6019, 0x6010, 0x6029, 0x600e, 0x6031, 0x601b, 0x6015, 0x602b, 0x6026, 0x600f, 0x603a, 0x605a, 0x6041, 0x606a, 0x6077, 0x605f, 0x604a, 0x6046, 0x604d, 0x6063, 0x6043, 0x6064, 0x6042, 0x606c, 0x606b, 0x6059, 0x6081, 0x608d, 0x60e7, 0x6083, 0x609a, /* 0xd8: 0xa1 - 0xfe*/ 0x6084, 0x609b, 0x6096, 0x6097, 0x6092, 0x60a7, 0x608b, 0x60e1, 0x60b8, 0x60e0, 0x60d3, 0x60b4, 0x5ff0, 0x60bd, 0x60c6, 0x60b5, 0x60d8, 0x614d, 0x6115, 0x6106, 0x60f6, 0x60f7, 0x6100, 0x60f4, 0x60fa, 0x6103, 0x6121, 0x60fb, 0x60f1, 0x610d, 0x610e, 0x6147, 0x613e, 0x6128, 0x6127, 0x614a, 0x613f, 0x613c, 0x612c, 0x6134, 0x613d, 0x6142, 0x6144, 0x6173, 0x6177, 0x6158, 0x6159, 0x615a, 0x616b, 0x6174, 0x616f, 0x6165, 0x6171, 0x615f, 0x615d, 0x6153, 0x6175, 0x6199, 0x6196, 0x6187, 0x61ac, 0x6194, 0x619a, 0x618a, 0x6191, 0x61ab, 0x61ae, 0x61cc, 0x61ca, 0x61c9, 0x61f7, 0x61c8, 0x61c3, 0x61c6, 0x61ba, 0x61cb, 0x7f79, 0x61cd, 0x61e6, 0x61e3, 0x61f6, 0x61fa, 0x61f4, 0x61ff, 0x61fd, 0x61fc, 0x61fe, 0x6200, 0x6208, 0x6209, 0x620d, 0x620c, 0x6214, 0x621b, /* 0xd9: 0xa1 - 0xfe*/ 0x621e, 0x6221, 0x622a, 0x622e, 0x6230, 0x6232, 0x6233, 0x6241, 0x624e, 0x625e, 0x6263, 0x625b, 0x6260, 0x6268, 0x627c, 0x6282, 0x6289, 0x627e, 0x6292, 0x6293, 0x6296, 0x62d4, 0x6283, 0x6294, 0x62d7, 0x62d1, 0x62bb, 0x62cf, 0x62ff, 0x62c6, 0x64d4, 0x62c8, 0x62dc, 0x62cc, 0x62ca, 0x62c2, 0x62c7, 0x629b, 0x62c9, 0x630c, 0x62ee, 0x62f1, 0x6327, 0x6302, 0x6308, 0x62ef, 0x62f5, 0x6350, 0x633e, 0x634d, 0x641c, 0x634f, 0x6396, 0x638e, 0x6380, 0x63ab, 0x6376, 0x63a3, 0x638f, 0x6389, 0x639f, 0x63b5, 0x636b, 0x6369, 0x63be, 0x63e9, 0x63c0, 0x63c6, 0x63e3, 0x63c9, 0x63d2, 0x63f6, 0x63c4, 0x6416, 0x6434, 0x6406, 0x6413, 0x6426, 0x6436, 0x651d, 0x6417, 0x6428, 0x640f, 0x6467, 0x646f, 0x6476, 0x644e, 0x652a, 0x6495, 0x6493, 0x64a5, 0x64a9, 0x6488, 0x64bc, /* 0xda: 0xa1 - 0xfe*/ 0x64da, 0x64d2, 0x64c5, 0x64c7, 0x64bb, 0x64d8, 0x64c2, 0x64f1, 0x64e7, 0x8209, 0x64e0, 0x64e1, 0x62ac, 0x64e3, 0x64ef, 0x652c, 0x64f6, 0x64f4, 0x64f2, 0x64fa, 0x6500, 0x64fd, 0x6518, 0x651c, 0x6505, 0x6524, 0x6523, 0x652b, 0x6534, 0x6535, 0x6537, 0x6536, 0x6538, 0x754b, 0x6548, 0x6556, 0x6555, 0x654d, 0x6558, 0x655e, 0x655d, 0x6572, 0x6578, 0x6582, 0x6583, 0x8b8a, 0x659b, 0x659f, 0x65ab, 0x65b7, 0x65c3, 0x65c6, 0x65c1, 0x65c4, 0x65cc, 0x65d2, 0x65db, 0x65d9, 0x65e0, 0x65e1, 0x65f1, 0x6772, 0x660a, 0x6603, 0x65fb, 0x6773, 0x6635, 0x6636, 0x6634, 0x661c, 0x664f, 0x6644, 0x6649, 0x6641, 0x665e, 0x665d, 0x6664, 0x6667, 0x6668, 0x665f, 0x6662, 0x6670, 0x6683, 0x6688, 0x668e, 0x6689, 0x6684, 0x6698, 0x669d, 0x66c1, 0x66b9, 0x66c9, 0x66be, 0x66bc, /* 0xdb: 0xa1 - 0xfe*/ 0x66c4, 0x66b8, 0x66d6, 0x66da, 0x66e0, 0x663f, 0x66e6, 0x66e9, 0x66f0, 0x66f5, 0x66f7, 0x670f, 0x6716, 0x671e, 0x6726, 0x6727, 0x9738, 0x672e, 0x673f, 0x6736, 0x6741, 0x6738, 0x6737, 0x6746, 0x675e, 0x6760, 0x6759, 0x6763, 0x6764, 0x6789, 0x6770, 0x67a9, 0x677c, 0x676a, 0x678c, 0x678b, 0x67a6, 0x67a1, 0x6785, 0x67b7, 0x67ef, 0x67b4, 0x67ec, 0x67b3, 0x67e9, 0x67b8, 0x67e4, 0x67de, 0x67dd, 0x67e2, 0x67ee, 0x67b9, 0x67ce, 0x67c6, 0x67e7, 0x6a9c, 0x681e, 0x6846, 0x6829, 0x6840, 0x684d, 0x6832, 0x684e, 0x68b3, 0x682b, 0x6859, 0x6863, 0x6877, 0x687f, 0x689f, 0x688f, 0x68ad, 0x6894, 0x689d, 0x689b, 0x6883, 0x6aae, 0x68b9, 0x6874, 0x68b5, 0x68a0, 0x68ba, 0x690f, 0x688d, 0x687e, 0x6901, 0x68ca, 0x6908, 0x68d8, 0x6922, 0x6926, 0x68e1, 0x690c, 0x68cd, /* 0xdc: 0xa1 - 0xfe*/ 0x68d4, 0x68e7, 0x68d5, 0x6936, 0x6912, 0x6904, 0x68d7, 0x68e3, 0x6925, 0x68f9, 0x68e0, 0x68ef, 0x6928, 0x692a, 0x691a, 0x6923, 0x6921, 0x68c6, 0x6979, 0x6977, 0x695c, 0x6978, 0x696b, 0x6954, 0x697e, 0x696e, 0x6939, 0x6974, 0x693d, 0x6959, 0x6930, 0x6961, 0x695e, 0x695d, 0x6981, 0x696a, 0x69b2, 0x69ae, 0x69d0, 0x69bf, 0x69c1, 0x69d3, 0x69be, 0x69ce, 0x5be8, 0x69ca, 0x69dd, 0x69bb, 0x69c3, 0x69a7, 0x6a2e, 0x6991, 0x69a0, 0x699c, 0x6995, 0x69b4, 0x69de, 0x69e8, 0x6a02, 0x6a1b, 0x69ff, 0x6b0a, 0x69f9, 0x69f2, 0x69e7, 0x6a05, 0x69b1, 0x6a1e, 0x69ed, 0x6a14, 0x69eb, 0x6a0a, 0x6a12, 0x6ac1, 0x6a23, 0x6a13, 0x6a44, 0x6a0c, 0x6a72, 0x6a36, 0x6a78, 0x6a47, 0x6a62, 0x6a59, 0x6a66, 0x6a48, 0x6a38, 0x6a22, 0x6a90, 0x6a8d, 0x6aa0, 0x6a84, 0x6aa2, 0x6aa3, /* 0xdd: 0xa1 - 0xfe*/ 0x6a97, 0x8617, 0x6abb, 0x6ac3, 0x6ac2, 0x6ab8, 0x6ab3, 0x6aac, 0x6ade, 0x6ad1, 0x6adf, 0x6aaa, 0x6ada, 0x6aea, 0x6afb, 0x6b05, 0x8616, 0x6afa, 0x6b12, 0x6b16, 0x9b31, 0x6b1f, 0x6b38, 0x6b37, 0x76dc, 0x6b39, 0x98ee, 0x6b47, 0x6b43, 0x6b49, 0x6b50, 0x6b59, 0x6b54, 0x6b5b, 0x6b5f, 0x6b61, 0x6b78, 0x6b79, 0x6b7f, 0x6b80, 0x6b84, 0x6b83, 0x6b8d, 0x6b98, 0x6b95, 0x6b9e, 0x6ba4, 0x6baa, 0x6bab, 0x6baf, 0x6bb2, 0x6bb1, 0x6bb3, 0x6bb7, 0x6bbc, 0x6bc6, 0x6bcb, 0x6bd3, 0x6bdf, 0x6bec, 0x6beb, 0x6bf3, 0x6bef, 0x9ebe, 0x6c08, 0x6c13, 0x6c14, 0x6c1b, 0x6c24, 0x6c23, 0x6c5e, 0x6c55, 0x6c62, 0x6c6a, 0x6c82, 0x6c8d, 0x6c9a, 0x6c81, 0x6c9b, 0x6c7e, 0x6c68, 0x6c73, 0x6c92, 0x6c90, 0x6cc4, 0x6cf1, 0x6cd3, 0x6cbd, 0x6cd7, 0x6cc5, 0x6cdd, 0x6cae, 0x6cb1, 0x6cbe, /* 0xde: 0xa1 - 0xfe*/ 0x6cba, 0x6cdb, 0x6cef, 0x6cd9, 0x6cea, 0x6d1f, 0x884d, 0x6d36, 0x6d2b, 0x6d3d, 0x6d38, 0x6d19, 0x6d35, 0x6d33, 0x6d12, 0x6d0c, 0x6d63, 0x6d93, 0x6d64, 0x6d5a, 0x6d79, 0x6d59, 0x6d8e, 0x6d95, 0x6fe4, 0x6d85, 0x6df9, 0x6e15, 0x6e0a, 0x6db5, 0x6dc7, 0x6de6, 0x6db8, 0x6dc6, 0x6dec, 0x6dde, 0x6dcc, 0x6de8, 0x6dd2, 0x6dc5, 0x6dfa, 0x6dd9, 0x6de4, 0x6dd5, 0x6dea, 0x6dee, 0x6e2d, 0x6e6e, 0x6e2e, 0x6e19, 0x6e72, 0x6e5f, 0x6e3e, 0x6e23, 0x6e6b, 0x6e2b, 0x6e76, 0x6e4d, 0x6e1f, 0x6e43, 0x6e3a, 0x6e4e, 0x6e24, 0x6eff, 0x6e1d, 0x6e38, 0x6e82, 0x6eaa, 0x6e98, 0x6ec9, 0x6eb7, 0x6ed3, 0x6ebd, 0x6eaf, 0x6ec4, 0x6eb2, 0x6ed4, 0x6ed5, 0x6e8f, 0x6ea5, 0x6ec2, 0x6e9f, 0x6f41, 0x6f11, 0x704c, 0x6eec, 0x6ef8, 0x6efe, 0x6f3f, 0x6ef2, 0x6f31, 0x6eef, 0x6f32, 0x6ecc, /* 0xdf: 0xa1 - 0xfe*/ 0x6f3e, 0x6f13, 0x6ef7, 0x6f86, 0x6f7a, 0x6f78, 0x6f81, 0x6f80, 0x6f6f, 0x6f5b, 0x6ff3, 0x6f6d, 0x6f82, 0x6f7c, 0x6f58, 0x6f8e, 0x6f91, 0x6fc2, 0x6f66, 0x6fb3, 0x6fa3, 0x6fa1, 0x6fa4, 0x6fb9, 0x6fc6, 0x6faa, 0x6fdf, 0x6fd5, 0x6fec, 0x6fd4, 0x6fd8, 0x6ff1, 0x6fee, 0x6fdb, 0x7009, 0x700b, 0x6ffa, 0x7011, 0x7001, 0x700f, 0x6ffe, 0x701b, 0x701a, 0x6f74, 0x701d, 0x7018, 0x701f, 0x7030, 0x703e, 0x7032, 0x7051, 0x7063, 0x7099, 0x7092, 0x70af, 0x70f1, 0x70ac, 0x70b8, 0x70b3, 0x70ae, 0x70df, 0x70cb, 0x70dd, 0x70d9, 0x7109, 0x70fd, 0x711c, 0x7119, 0x7165, 0x7155, 0x7188, 0x7166, 0x7162, 0x714c, 0x7156, 0x716c, 0x718f, 0x71fb, 0x7184, 0x7195, 0x71a8, 0x71ac, 0x71d7, 0x71b9, 0x71be, 0x71d2, 0x71c9, 0x71d4, 0x71ce, 0x71e0, 0x71ec, 0x71e7, 0x71f5, 0x71fc, /* 0xe0: 0xa1 - 0xfe*/ 0x71f9, 0x71ff, 0x720d, 0x7210, 0x721b, 0x7228, 0x722d, 0x722c, 0x7230, 0x7232, 0x723b, 0x723c, 0x723f, 0x7240, 0x7246, 0x724b, 0x7258, 0x7274, 0x727e, 0x7282, 0x7281, 0x7287, 0x7292, 0x7296, 0x72a2, 0x72a7, 0x72b9, 0x72b2, 0x72c3, 0x72c6, 0x72c4, 0x72ce, 0x72d2, 0x72e2, 0x72e0, 0x72e1, 0x72f9, 0x72f7, 0x500f, 0x7317, 0x730a, 0x731c, 0x7316, 0x731d, 0x7334, 0x732f, 0x7329, 0x7325, 0x733e, 0x734e, 0x734f, 0x9ed8, 0x7357, 0x736a, 0x7368, 0x7370, 0x7378, 0x7375, 0x737b, 0x737a, 0x73c8, 0x73b3, 0x73ce, 0x73bb, 0x73c0, 0x73e5, 0x73ee, 0x73de, 0x74a2, 0x7405, 0x746f, 0x7425, 0x73f8, 0x7432, 0x743a, 0x7455, 0x743f, 0x745f, 0x7459, 0x7441, 0x745c, 0x7469, 0x7470, 0x7463, 0x746a, 0x7476, 0x747e, 0x748b, 0x749e, 0x74a7, 0x74ca, 0x74cf, 0x74d4, 0x73f1, /* 0xe1: 0xa1 - 0xfe*/ 0x74e0, 0x74e3, 0x74e7, 0x74e9, 0x74ee, 0x74f2, 0x74f0, 0x74f1, 0x74f8, 0x74f7, 0x7504, 0x7503, 0x7505, 0x750c, 0x750e, 0x750d, 0x7515, 0x7513, 0x751e, 0x7526, 0x752c, 0x753c, 0x7544, 0x754d, 0x754a, 0x7549, 0x755b, 0x7546, 0x755a, 0x7569, 0x7564, 0x7567, 0x756b, 0x756d, 0x7578, 0x7576, 0x7586, 0x7587, 0x7574, 0x758a, 0x7589, 0x7582, 0x7594, 0x759a, 0x759d, 0x75a5, 0x75a3, 0x75c2, 0x75b3, 0x75c3, 0x75b5, 0x75bd, 0x75b8, 0x75bc, 0x75b1, 0x75cd, 0x75ca, 0x75d2, 0x75d9, 0x75e3, 0x75de, 0x75fe, 0x75ff, 0x75fc, 0x7601, 0x75f0, 0x75fa, 0x75f2, 0x75f3, 0x760b, 0x760d, 0x7609, 0x761f, 0x7627, 0x7620, 0x7621, 0x7622, 0x7624, 0x7634, 0x7630, 0x763b, 0x7647, 0x7648, 0x7646, 0x765c, 0x7658, 0x7661, 0x7662, 0x7668, 0x7669, 0x766a, 0x7667, 0x766c, 0x7670, /* 0xe2: 0xa1 - 0xfe*/ 0x7672, 0x7676, 0x7678, 0x767c, 0x7680, 0x7683, 0x7688, 0x768b, 0x768e, 0x7696, 0x7693, 0x7699, 0x769a, 0x76b0, 0x76b4, 0x76b8, 0x76b9, 0x76ba, 0x76c2, 0x76cd, 0x76d6, 0x76d2, 0x76de, 0x76e1, 0x76e5, 0x76e7, 0x76ea, 0x862f, 0x76fb, 0x7708, 0x7707, 0x7704, 0x7729, 0x7724, 0x771e, 0x7725, 0x7726, 0x771b, 0x7737, 0x7738, 0x7747, 0x775a, 0x7768, 0x776b, 0x775b, 0x7765, 0x777f, 0x777e, 0x7779, 0x778e, 0x778b, 0x7791, 0x77a0, 0x779e, 0x77b0, 0x77b6, 0x77b9, 0x77bf, 0x77bc, 0x77bd, 0x77bb, 0x77c7, 0x77cd, 0x77d7, 0x77da, 0x77dc, 0x77e3, 0x77ee, 0x77fc, 0x780c, 0x7812, 0x7926, 0x7820, 0x792a, 0x7845, 0x788e, 0x7874, 0x7886, 0x787c, 0x789a, 0x788c, 0x78a3, 0x78b5, 0x78aa, 0x78af, 0x78d1, 0x78c6, 0x78cb, 0x78d4, 0x78be, 0x78bc, 0x78c5, 0x78ca, 0x78ec, /* 0xe3: 0xa1 - 0xfe*/ 0x78e7, 0x78da, 0x78fd, 0x78f4, 0x7907, 0x7912, 0x7911, 0x7919, 0x792c, 0x792b, 0x7940, 0x7960, 0x7957, 0x795f, 0x795a, 0x7955, 0x7953, 0x797a, 0x797f, 0x798a, 0x799d, 0x79a7, 0x9f4b, 0x79aa, 0x79ae, 0x79b3, 0x79b9, 0x79ba, 0x79c9, 0x79d5, 0x79e7, 0x79ec, 0x79e1, 0x79e3, 0x7a08, 0x7a0d, 0x7a18, 0x7a19, 0x7a20, 0x7a1f, 0x7980, 0x7a31, 0x7a3b, 0x7a3e, 0x7a37, 0x7a43, 0x7a57, 0x7a49, 0x7a61, 0x7a62, 0x7a69, 0x9f9d, 0x7a70, 0x7a79, 0x7a7d, 0x7a88, 0x7a97, 0x7a95, 0x7a98, 0x7a96, 0x7aa9, 0x7ac8, 0x7ab0, 0x7ab6, 0x7ac5, 0x7ac4, 0x7abf, 0x9083, 0x7ac7, 0x7aca, 0x7acd, 0x7acf, 0x7ad5, 0x7ad3, 0x7ad9, 0x7ada, 0x7add, 0x7ae1, 0x7ae2, 0x7ae6, 0x7aed, 0x7af0, 0x7b02, 0x7b0f, 0x7b0a, 0x7b06, 0x7b33, 0x7b18, 0x7b19, 0x7b1e, 0x7b35, 0x7b28, 0x7b36, 0x7b50, /* 0xe4: 0xa1 - 0xfe*/ 0x7b7a, 0x7b04, 0x7b4d, 0x7b0b, 0x7b4c, 0x7b45, 0x7b75, 0x7b65, 0x7b74, 0x7b67, 0x7b70, 0x7b71, 0x7b6c, 0x7b6e, 0x7b9d, 0x7b98, 0x7b9f, 0x7b8d, 0x7b9c, 0x7b9a, 0x7b8b, 0x7b92, 0x7b8f, 0x7b5d, 0x7b99, 0x7bcb, 0x7bc1, 0x7bcc, 0x7bcf, 0x7bb4, 0x7bc6, 0x7bdd, 0x7be9, 0x7c11, 0x7c14, 0x7be6, 0x7be5, 0x7c60, 0x7c00, 0x7c07, 0x7c13, 0x7bf3, 0x7bf7, 0x7c17, 0x7c0d, 0x7bf6, 0x7c23, 0x7c27, 0x7c2a, 0x7c1f, 0x7c37, 0x7c2b, 0x7c3d, 0x7c4c, 0x7c43, 0x7c54, 0x7c4f, 0x7c40, 0x7c50, 0x7c58, 0x7c5f, 0x7c64, 0x7c56, 0x7c65, 0x7c6c, 0x7c75, 0x7c83, 0x7c90, 0x7ca4, 0x7cad, 0x7ca2, 0x7cab, 0x7ca1, 0x7ca8, 0x7cb3, 0x7cb2, 0x7cb1, 0x7cae, 0x7cb9, 0x7cbd, 0x7cc0, 0x7cc5, 0x7cc2, 0x7cd8, 0x7cd2, 0x7cdc, 0x7ce2, 0x9b3b, 0x7cef, 0x7cf2, 0x7cf4, 0x7cf6, 0x7cfa, 0x7d06, /* 0xe5: 0xa1 - 0xfe*/ 0x7d02, 0x7d1c, 0x7d15, 0x7d0a, 0x7d45, 0x7d4b, 0x7d2e, 0x7d32, 0x7d3f, 0x7d35, 0x7d46, 0x7d73, 0x7d56, 0x7d4e, 0x7d72, 0x7d68, 0x7d6e, 0x7d4f, 0x7d63, 0x7d93, 0x7d89, 0x7d5b, 0x7d8f, 0x7d7d, 0x7d9b, 0x7dba, 0x7dae, 0x7da3, 0x7db5, 0x7dc7, 0x7dbd, 0x7dab, 0x7e3d, 0x7da2, 0x7daf, 0x7ddc, 0x7db8, 0x7d9f, 0x7db0, 0x7dd8, 0x7ddd, 0x7de4, 0x7dde, 0x7dfb, 0x7df2, 0x7de1, 0x7e05, 0x7e0a, 0x7e23, 0x7e21, 0x7e12, 0x7e31, 0x7e1f, 0x7e09, 0x7e0b, 0x7e22, 0x7e46, 0x7e66, 0x7e3b, 0x7e35, 0x7e39, 0x7e43, 0x7e37, 0x7e32, 0x7e3a, 0x7e67, 0x7e5d, 0x7e56, 0x7e5e, 0x7e59, 0x7e5a, 0x7e79, 0x7e6a, 0x7e69, 0x7e7c, 0x7e7b, 0x7e83, 0x7dd5, 0x7e7d, 0x8fae, 0x7e7f, 0x7e88, 0x7e89, 0x7e8c, 0x7e92, 0x7e90, 0x7e93, 0x7e94, 0x7e96, 0x7e8e, 0x7e9b, 0x7e9c, 0x7f38, 0x7f3a, /* 0xe6: 0xa1 - 0xfe*/ 0x7f45, 0x7f4c, 0x7f4d, 0x7f4e, 0x7f50, 0x7f51, 0x7f55, 0x7f54, 0x7f58, 0x7f5f, 0x7f60, 0x7f68, 0x7f69, 0x7f67, 0x7f78, 0x7f82, 0x7f86, 0x7f83, 0x7f88, 0x7f87, 0x7f8c, 0x7f94, 0x7f9e, 0x7f9d, 0x7f9a, 0x7fa3, 0x7faf, 0x7fb2, 0x7fb9, 0x7fae, 0x7fb6, 0x7fb8, 0x8b71, 0x7fc5, 0x7fc6, 0x7fca, 0x7fd5, 0x7fd4, 0x7fe1, 0x7fe6, 0x7fe9, 0x7ff3, 0x7ff9, 0x98dc, 0x8006, 0x8004, 0x800b, 0x8012, 0x8018, 0x8019, 0x801c, 0x8021, 0x8028, 0x803f, 0x803b, 0x804a, 0x8046, 0x8052, 0x8058, 0x805a, 0x805f, 0x8062, 0x8068, 0x8073, 0x8072, 0x8070, 0x8076, 0x8079, 0x807d, 0x807f, 0x8084, 0x8086, 0x8085, 0x809b, 0x8093, 0x809a, 0x80ad, 0x5190, 0x80ac, 0x80db, 0x80e5, 0x80d9, 0x80dd, 0x80c4, 0x80da, 0x80d6, 0x8109, 0x80ef, 0x80f1, 0x811b, 0x8129, 0x8123, 0x812f, 0x814b, /* 0xe7: 0xa1 - 0xfe*/ 0x968b, 0x8146, 0x813e, 0x8153, 0x8151, 0x80fc, 0x8171, 0x816e, 0x8165, 0x8166, 0x8174, 0x8183, 0x8188, 0x818a, 0x8180, 0x8182, 0x81a0, 0x8195, 0x81a4, 0x81a3, 0x815f, 0x8193, 0x81a9, 0x81b0, 0x81b5, 0x81be, 0x81b8, 0x81bd, 0x81c0, 0x81c2, 0x81ba, 0x81c9, 0x81cd, 0x81d1, 0x81d9, 0x81d8, 0x81c8, 0x81da, 0x81df, 0x81e0, 0x81e7, 0x81fa, 0x81fb, 0x81fe, 0x8201, 0x8202, 0x8205, 0x8207, 0x820a, 0x820d, 0x8210, 0x8216, 0x8229, 0x822b, 0x8238, 0x8233, 0x8240, 0x8259, 0x8258, 0x825d, 0x825a, 0x825f, 0x8264, 0x8262, 0x8268, 0x826a, 0x826b, 0x822e, 0x8271, 0x8277, 0x8278, 0x827e, 0x828d, 0x8292, 0x82ab, 0x829f, 0x82bb, 0x82ac, 0x82e1, 0x82e3, 0x82df, 0x82d2, 0x82f4, 0x82f3, 0x82fa, 0x8393, 0x8303, 0x82fb, 0x82f9, 0x82de, 0x8306, 0x82dc, 0x8309, 0x82d9, /* 0xe8: 0xa1 - 0xfe*/ 0x8335, 0x8334, 0x8316, 0x8332, 0x8331, 0x8340, 0x8339, 0x8350, 0x8345, 0x832f, 0x832b, 0x8317, 0x8318, 0x8385, 0x839a, 0x83aa, 0x839f, 0x83a2, 0x8396, 0x8323, 0x838e, 0x8387, 0x838a, 0x837c, 0x83b5, 0x8373, 0x8375, 0x83a0, 0x8389, 0x83a8, 0x83f4, 0x8413, 0x83eb, 0x83ce, 0x83fd, 0x8403, 0x83d8, 0x840b, 0x83c1, 0x83f7, 0x8407, 0x83e0, 0x83f2, 0x840d, 0x8422, 0x8420, 0x83bd, 0x8438, 0x8506, 0x83fb, 0x846d, 0x842a, 0x843c, 0x855a, 0x8484, 0x8477, 0x846b, 0x84ad, 0x846e, 0x8482, 0x8469, 0x8446, 0x842c, 0x846f, 0x8479, 0x8435, 0x84ca, 0x8462, 0x84b9, 0x84bf, 0x849f, 0x84d9, 0x84cd, 0x84bb, 0x84da, 0x84d0, 0x84c1, 0x84c6, 0x84d6, 0x84a1, 0x8521, 0x84ff, 0x84f4, 0x8517, 0x8518, 0x852c, 0x851f, 0x8515, 0x8514, 0x84fc, 0x8540, 0x8563, 0x8558, 0x8548, /* 0xe9: 0xa1 - 0xfe*/ 0x8541, 0x8602, 0x854b, 0x8555, 0x8580, 0x85a4, 0x8588, 0x8591, 0x858a, 0x85a8, 0x856d, 0x8594, 0x859b, 0x85ea, 0x8587, 0x859c, 0x8577, 0x857e, 0x8590, 0x85c9, 0x85ba, 0x85cf, 0x85b9, 0x85d0, 0x85d5, 0x85dd, 0x85e5, 0x85dc, 0x85f9, 0x860a, 0x8613, 0x860b, 0x85fe, 0x85fa, 0x8606, 0x8622, 0x861a, 0x8630, 0x863f, 0x864d, 0x4e55, 0x8654, 0x865f, 0x8667, 0x8671, 0x8693, 0x86a3, 0x86a9, 0x86aa, 0x868b, 0x868c, 0x86b6, 0x86af, 0x86c4, 0x86c6, 0x86b0, 0x86c9, 0x8823, 0x86ab, 0x86d4, 0x86de, 0x86e9, 0x86ec, 0x86df, 0x86db, 0x86ef, 0x8712, 0x8706, 0x8708, 0x8700, 0x8703, 0x86fb, 0x8711, 0x8709, 0x870d, 0x86f9, 0x870a, 0x8734, 0x873f, 0x8737, 0x873b, 0x8725, 0x8729, 0x871a, 0x8760, 0x875f, 0x8778, 0x874c, 0x874e, 0x8774, 0x8757, 0x8768, 0x876e, 0x8759, /* 0xea: 0xa1 - 0xfe*/ 0x8753, 0x8763, 0x876a, 0x8805, 0x87a2, 0x879f, 0x8782, 0x87af, 0x87cb, 0x87bd, 0x87c0, 0x87d0, 0x96d6, 0x87ab, 0x87c4, 0x87b3, 0x87c7, 0x87c6, 0x87bb, 0x87ef, 0x87f2, 0x87e0, 0x880f, 0x880d, 0x87fe, 0x87f6, 0x87f7, 0x880e, 0x87d2, 0x8811, 0x8816, 0x8815, 0x8822, 0x8821, 0x8831, 0x8836, 0x8839, 0x8827, 0x883b, 0x8844, 0x8842, 0x8852, 0x8859, 0x885e, 0x8862, 0x886b, 0x8881, 0x887e, 0x889e, 0x8875, 0x887d, 0x88b5, 0x8872, 0x8882, 0x8897, 0x8892, 0x88ae, 0x8899, 0x88a2, 0x888d, 0x88a4, 0x88b0, 0x88bf, 0x88b1, 0x88c3, 0x88c4, 0x88d4, 0x88d8, 0x88d9, 0x88dd, 0x88f9, 0x8902, 0x88fc, 0x88f4, 0x88e8, 0x88f2, 0x8904, 0x890c, 0x890a, 0x8913, 0x8943, 0x891e, 0x8925, 0x892a, 0x892b, 0x8941, 0x8944, 0x893b, 0x8936, 0x8938, 0x894c, 0x891d, 0x8960, 0x895e, /* 0xeb: 0xa1 - 0xfe*/ 0x8966, 0x8964, 0x896d, 0x896a, 0x896f, 0x8974, 0x8977, 0x897e, 0x8983, 0x8988, 0x898a, 0x8993, 0x8998, 0x89a1, 0x89a9, 0x89a6, 0x89ac, 0x89af, 0x89b2, 0x89ba, 0x89bd, 0x89bf, 0x89c0, 0x89da, 0x89dc, 0x89dd, 0x89e7, 0x89f4, 0x89f8, 0x8a03, 0x8a16, 0x8a10, 0x8a0c, 0x8a1b, 0x8a1d, 0x8a25, 0x8a36, 0x8a41, 0x8a5b, 0x8a52, 0x8a46, 0x8a48, 0x8a7c, 0x8a6d, 0x8a6c, 0x8a62, 0x8a85, 0x8a82, 0x8a84, 0x8aa8, 0x8aa1, 0x8a91, 0x8aa5, 0x8aa6, 0x8a9a, 0x8aa3, 0x8ac4, 0x8acd, 0x8ac2, 0x8ada, 0x8aeb, 0x8af3, 0x8ae7, 0x8ae4, 0x8af1, 0x8b14, 0x8ae0, 0x8ae2, 0x8af7, 0x8ade, 0x8adb, 0x8b0c, 0x8b07, 0x8b1a, 0x8ae1, 0x8b16, 0x8b10, 0x8b17, 0x8b20, 0x8b33, 0x97ab, 0x8b26, 0x8b2b, 0x8b3e, 0x8b28, 0x8b41, 0x8b4c, 0x8b4f, 0x8b4e, 0x8b49, 0x8b56, 0x8b5b, 0x8b5a, 0x8b6b, /* 0xec: 0xa1 - 0xfe*/ 0x8b5f, 0x8b6c, 0x8b6f, 0x8b74, 0x8b7d, 0x8b80, 0x8b8c, 0x8b8e, 0x8b92, 0x8b93, 0x8b96, 0x8b99, 0x8b9a, 0x8c3a, 0x8c41, 0x8c3f, 0x8c48, 0x8c4c, 0x8c4e, 0x8c50, 0x8c55, 0x8c62, 0x8c6c, 0x8c78, 0x8c7a, 0x8c82, 0x8c89, 0x8c85, 0x8c8a, 0x8c8d, 0x8c8e, 0x8c94, 0x8c7c, 0x8c98, 0x621d, 0x8cad, 0x8caa, 0x8cbd, 0x8cb2, 0x8cb3, 0x8cae, 0x8cb6, 0x8cc8, 0x8cc1, 0x8ce4, 0x8ce3, 0x8cda, 0x8cfd, 0x8cfa, 0x8cfb, 0x8d04, 0x8d05, 0x8d0a, 0x8d07, 0x8d0f, 0x8d0d, 0x8d10, 0x9f4e, 0x8d13, 0x8ccd, 0x8d14, 0x8d16, 0x8d67, 0x8d6d, 0x8d71, 0x8d73, 0x8d81, 0x8d99, 0x8dc2, 0x8dbe, 0x8dba, 0x8dcf, 0x8dda, 0x8dd6, 0x8dcc, 0x8ddb, 0x8dcb, 0x8dea, 0x8deb, 0x8ddf, 0x8de3, 0x8dfc, 0x8e08, 0x8e09, 0x8dff, 0x8e1d, 0x8e1e, 0x8e10, 0x8e1f, 0x8e42, 0x8e35, 0x8e30, 0x8e34, 0x8e4a, /* 0xed: 0xa1 - 0xfe*/ 0x8e47, 0x8e49, 0x8e4c, 0x8e50, 0x8e48, 0x8e59, 0x8e64, 0x8e60, 0x8e2a, 0x8e63, 0x8e55, 0x8e76, 0x8e72, 0x8e7c, 0x8e81, 0x8e87, 0x8e85, 0x8e84, 0x8e8b, 0x8e8a, 0x8e93, 0x8e91, 0x8e94, 0x8e99, 0x8eaa, 0x8ea1, 0x8eac, 0x8eb0, 0x8ec6, 0x8eb1, 0x8ebe, 0x8ec5, 0x8ec8, 0x8ecb, 0x8edb, 0x8ee3, 0x8efc, 0x8efb, 0x8eeb, 0x8efe, 0x8f0a, 0x8f05, 0x8f15, 0x8f12, 0x8f19, 0x8f13, 0x8f1c, 0x8f1f, 0x8f1b, 0x8f0c, 0x8f26, 0x8f33, 0x8f3b, 0x8f39, 0x8f45, 0x8f42, 0x8f3e, 0x8f4c, 0x8f49, 0x8f46, 0x8f4e, 0x8f57, 0x8f5c, 0x8f62, 0x8f63, 0x8f64, 0x8f9c, 0x8f9f, 0x8fa3, 0x8fad, 0x8faf, 0x8fb7, 0x8fda, 0x8fe5, 0x8fe2, 0x8fea, 0x8fef, 0x9087, 0x8ff4, 0x9005, 0x8ff9, 0x8ffa, 0x9011, 0x9015, 0x9021, 0x900d, 0x901e, 0x9016, 0x900b, 0x9027, 0x9036, 0x9035, 0x9039, 0x8ff8, /* 0xee: 0xa1 - 0xfe*/ 0x904f, 0x9050, 0x9051, 0x9052, 0x900e, 0x9049, 0x903e, 0x9056, 0x9058, 0x905e, 0x9068, 0x906f, 0x9076, 0x96a8, 0x9072, 0x9082, 0x907d, 0x9081, 0x9080, 0x908a, 0x9089, 0x908f, 0x90a8, 0x90af, 0x90b1, 0x90b5, 0x90e2, 0x90e4, 0x6248, 0x90db, 0x9102, 0x9112, 0x9119, 0x9132, 0x9130, 0x914a, 0x9156, 0x9158, 0x9163, 0x9165, 0x9169, 0x9173, 0x9172, 0x918b, 0x9189, 0x9182, 0x91a2, 0x91ab, 0x91af, 0x91aa, 0x91b5, 0x91b4, 0x91ba, 0x91c0, 0x91c1, 0x91c9, 0x91cb, 0x91d0, 0x91d6, 0x91df, 0x91e1, 0x91db, 0x91fc, 0x91f5, 0x91f6, 0x921e, 0x91ff, 0x9214, 0x922c, 0x9215, 0x9211, 0x925e, 0x9257, 0x9245, 0x9249, 0x9264, 0x9248, 0x9295, 0x923f, 0x924b, 0x9250, 0x929c, 0x9296, 0x9293, 0x929b, 0x925a, 0x92cf, 0x92b9, 0x92b7, 0x92e9, 0x930f, 0x92fa, 0x9344, 0x932e, /* 0xef: 0xa1 - 0xfe*/ 0x9319, 0x9322, 0x931a, 0x9323, 0x933a, 0x9335, 0x933b, 0x935c, 0x9360, 0x937c, 0x936e, 0x9356, 0x93b0, 0x93ac, 0x93ad, 0x9394, 0x93b9, 0x93d6, 0x93d7, 0x93e8, 0x93e5, 0x93d8, 0x93c3, 0x93dd, 0x93d0, 0x93c8, 0x93e4, 0x941a, 0x9414, 0x9413, 0x9403, 0x9407, 0x9410, 0x9436, 0x942b, 0x9435, 0x9421, 0x943a, 0x9441, 0x9452, 0x9444, 0x945b, 0x9460, 0x9462, 0x945e, 0x946a, 0x9229, 0x9470, 0x9475, 0x9477, 0x947d, 0x945a, 0x947c, 0x947e, 0x9481, 0x947f, 0x9582, 0x9587, 0x958a, 0x9594, 0x9596, 0x9598, 0x9599, 0x95a0, 0x95a8, 0x95a7, 0x95ad, 0x95bc, 0x95bb, 0x95b9, 0x95be, 0x95ca, 0x6ff6, 0x95c3, 0x95cd, 0x95cc, 0x95d5, 0x95d4, 0x95d6, 0x95dc, 0x95e1, 0x95e5, 0x95e2, 0x9621, 0x9628, 0x962e, 0x962f, 0x9642, 0x964c, 0x964f, 0x964b, 0x9677, 0x965c, 0x965e, /* 0xf0: 0xa1 - 0xfe*/ 0x965d, 0x965f, 0x9666, 0x9672, 0x966c, 0x968d, 0x9698, 0x9695, 0x9697, 0x96aa, 0x96a7, 0x96b1, 0x96b2, 0x96b0, 0x96b4, 0x96b6, 0x96b8, 0x96b9, 0x96ce, 0x96cb, 0x96c9, 0x96cd, 0x894d, 0x96dc, 0x970d, 0x96d5, 0x96f9, 0x9704, 0x9706, 0x9708, 0x9713, 0x970e, 0x9711, 0x970f, 0x9716, 0x9719, 0x9724, 0x972a, 0x9730, 0x9739, 0x973d, 0x973e, 0x9744, 0x9746, 0x9748, 0x9742, 0x9749, 0x975c, 0x9760, 0x9764, 0x9766, 0x9768, 0x52d2, 0x976b, 0x9771, 0x9779, 0x9785, 0x977c, 0x9781, 0x977a, 0x9786, 0x978b, 0x978f, 0x9790, 0x979c, 0x97a8, 0x97a6, 0x97a3, 0x97b3, 0x97b4, 0x97c3, 0x97c6, 0x97c8, 0x97cb, 0x97dc, 0x97ed, 0x9f4f, 0x97f2, 0x7adf, 0x97f6, 0x97f5, 0x980f, 0x980c, 0x9838, 0x9824, 0x9821, 0x9837, 0x983d, 0x9846, 0x984f, 0x984b, 0x986b, 0x986f, 0x9870, /* 0xf1: 0xa1 - 0xfe*/ 0x9871, 0x9874, 0x9873, 0x98aa, 0x98af, 0x98b1, 0x98b6, 0x98c4, 0x98c3, 0x98c6, 0x98e9, 0x98eb, 0x9903, 0x9909, 0x9912, 0x9914, 0x9918, 0x9921, 0x991d, 0x991e, 0x9924, 0x9920, 0x992c, 0x992e, 0x993d, 0x993e, 0x9942, 0x9949, 0x9945, 0x9950, 0x994b, 0x9951, 0x9952, 0x994c, 0x9955, 0x9997, 0x9998, 0x99a5, 0x99ad, 0x99ae, 0x99bc, 0x99df, 0x99db, 0x99dd, 0x99d8, 0x99d1, 0x99ed, 0x99ee, 0x99f1, 0x99f2, 0x99fb, 0x99f8, 0x9a01, 0x9a0f, 0x9a05, 0x99e2, 0x9a19, 0x9a2b, 0x9a37, 0x9a45, 0x9a42, 0x9a40, 0x9a43, 0x9a3e, 0x9a55, 0x9a4d, 0x9a5b, 0x9a57, 0x9a5f, 0x9a62, 0x9a65, 0x9a64, 0x9a69, 0x9a6b, 0x9a6a, 0x9aad, 0x9ab0, 0x9abc, 0x9ac0, 0x9acf, 0x9ad1, 0x9ad3, 0x9ad4, 0x9ade, 0x9adf, 0x9ae2, 0x9ae3, 0x9ae6, 0x9aef, 0x9aeb, 0x9aee, 0x9af4, 0x9af1, 0x9af7, /* 0xf2: 0xa1 - 0xfe*/ 0x9afb, 0x9b06, 0x9b18, 0x9b1a, 0x9b1f, 0x9b22, 0x9b23, 0x9b25, 0x9b27, 0x9b28, 0x9b29, 0x9b2a, 0x9b2e, 0x9b2f, 0x9b32, 0x9b44, 0x9b43, 0x9b4f, 0x9b4d, 0x9b4e, 0x9b51, 0x9b58, 0x9b74, 0x9b93, 0x9b83, 0x9b91, 0x9b96, 0x9b97, 0x9b9f, 0x9ba0, 0x9ba8, 0x9bb4, 0x9bc0, 0x9bca, 0x9bb9, 0x9bc6, 0x9bcf, 0x9bd1, 0x9bd2, 0x9be3, 0x9be2, 0x9be4, 0x9bd4, 0x9be1, 0x9c3a, 0x9bf2, 0x9bf1, 0x9bf0, 0x9c15, 0x9c14, 0x9c09, 0x9c13, 0x9c0c, 0x9c06, 0x9c08, 0x9c12, 0x9c0a, 0x9c04, 0x9c2e, 0x9c1b, 0x9c25, 0x9c24, 0x9c21, 0x9c30, 0x9c47, 0x9c32, 0x9c46, 0x9c3e, 0x9c5a, 0x9c60, 0x9c67, 0x9c76, 0x9c78, 0x9ce7, 0x9cec, 0x9cf0, 0x9d09, 0x9d08, 0x9ceb, 0x9d03, 0x9d06, 0x9d2a, 0x9d26, 0x9daf, 0x9d23, 0x9d1f, 0x9d44, 0x9d15, 0x9d12, 0x9d41, 0x9d3f, 0x9d3e, 0x9d46, 0x9d48, /* 0xf3: 0xa1 - 0xfe*/ 0x9d5d, 0x9d5e, 0x9d64, 0x9d51, 0x9d50, 0x9d59, 0x9d72, 0x9d89, 0x9d87, 0x9dab, 0x9d6f, 0x9d7a, 0x9d9a, 0x9da4, 0x9da9, 0x9db2, 0x9dc4, 0x9dc1, 0x9dbb, 0x9db8, 0x9dba, 0x9dc6, 0x9dcf, 0x9dc2, 0x9dd9, 0x9dd3, 0x9df8, 0x9de6, 0x9ded, 0x9def, 0x9dfd, 0x9e1a, 0x9e1b, 0x9e1e, 0x9e75, 0x9e79, 0x9e7d, 0x9e81, 0x9e88, 0x9e8b, 0x9e8c, 0x9e92, 0x9e95, 0x9e91, 0x9e9d, 0x9ea5, 0x9ea9, 0x9eb8, 0x9eaa, 0x9ead, 0x9761, 0x9ecc, 0x9ece, 0x9ecf, 0x9ed0, 0x9ed4, 0x9edc, 0x9ede, 0x9edd, 0x9ee0, 0x9ee5, 0x9ee8, 0x9eef, 0x9ef4, 0x9ef6, 0x9ef7, 0x9ef9, 0x9efb, 0x9efc, 0x9efd, 0x9f07, 0x9f08, 0x76b7, 0x9f15, 0x9f21, 0x9f2c, 0x9f3e, 0x9f4a, 0x9f52, 0x9f54, 0x9f63, 0x9f5f, 0x9f60, 0x9f61, 0x9f66, 0x9f67, 0x9f6c, 0x9f6a, 0x9f77, 0x9f72, 0x9f76, 0x9f95, 0x9f9c, 0x9fa0, /* 0xf4: 0xa1 - 0xa6*/ 0x582f, 0x69c7, 0x9059, 0x7464, 0x51dc, 0x7199, }; static const struct jis_charmap __euc_jp_jis_x0208_map[] = { { .first = 0xa1, .last = 0xdf, .offset = 0 }, /* 0x8e */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x8f */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x90 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x91 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x92 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x93 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x94 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x95 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x96 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x97 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x98 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x99 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x9a */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x9b */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x9c */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x9d */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x9e */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0x9f */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xa0 */ { .first = 0xa1, .last = 0xfe, .offset = 63 }, /* 0xa1 */ { .first = 0xa1, .last = 0xfe, .offset = 157 }, /* 0xa2 */ { .first = 0xb0, .last = 0xfa, .offset = 251 }, /* 0xa3 */ { .first = 0xa1, .last = 0xf3, .offset = 326 }, /* 0xa4 */ { .first = 0xa1, .last = 0xf6, .offset = 409 }, /* 0xa5 */ { .first = 0xa1, .last = 0xd8, .offset = 495 }, /* 0xa6 */ { .first = 0xa1, .last = 0xf1, .offset = 551 }, /* 0xa7 */ { .first = 0xa1, .last = 0xc0, .offset = 632 }, /* 0xa8 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xa9 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xaa */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xab */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xac */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xad */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xae */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xaf */ { .first = 0xa1, .last = 0xfe, .offset = 664 }, /* 0xb0 */ { .first = 0xa1, .last = 0xfe, .offset = 758 }, /* 0xb1 */ { .first = 0xa1, .last = 0xfe, .offset = 852 }, /* 0xb2 */ { .first = 0xa1, .last = 0xfe, .offset = 946 }, /* 0xb3 */ { .first = 0xa1, .last = 0xfe, .offset = 1040 }, /* 0xb4 */ { .first = 0xa1, .last = 0xfe, .offset = 1134 }, /* 0xb5 */ { .first = 0xa1, .last = 0xfe, .offset = 1228 }, /* 0xb6 */ { .first = 0xa1, .last = 0xfe, .offset = 1322 }, /* 0xb7 */ { .first = 0xa1, .last = 0xfe, .offset = 1416 }, /* 0xb8 */ { .first = 0xa1, .last = 0xfe, .offset = 1510 }, /* 0xb9 */ { .first = 0xa1, .last = 0xfe, .offset = 1604 }, /* 0xba */ { .first = 0xa1, .last = 0xfe, .offset = 1698 }, /* 0xbb */ { .first = 0xa1, .last = 0xfe, .offset = 1792 }, /* 0xbc */ { .first = 0xa1, .last = 0xfe, .offset = 1886 }, /* 0xbd */ { .first = 0xa1, .last = 0xfe, .offset = 1980 }, /* 0xbe */ { .first = 0xa1, .last = 0xfe, .offset = 2074 }, /* 0xbf */ { .first = 0xa1, .last = 0xfe, .offset = 2168 }, /* 0xc0 */ { .first = 0xa1, .last = 0xfe, .offset = 2262 }, /* 0xc1 */ { .first = 0xa1, .last = 0xfe, .offset = 2356 }, /* 0xc2 */ { .first = 0xa1, .last = 0xfe, .offset = 2450 }, /* 0xc3 */ { .first = 0xa1, .last = 0xfe, .offset = 2544 }, /* 0xc4 */ { .first = 0xa1, .last = 0xfe, .offset = 2638 }, /* 0xc5 */ { .first = 0xa1, .last = 0xfe, .offset = 2732 }, /* 0xc6 */ { .first = 0xa1, .last = 0xfe, .offset = 2826 }, /* 0xc7 */ { .first = 0xa1, .last = 0xfe, .offset = 2920 }, /* 0xc8 */ { .first = 0xa1, .last = 0xfe, .offset = 3014 }, /* 0xc9 */ { .first = 0xa1, .last = 0xfe, .offset = 3108 }, /* 0xca */ { .first = 0xa1, .last = 0xfe, .offset = 3202 }, /* 0xcb */ { .first = 0xa1, .last = 0xfe, .offset = 3296 }, /* 0xcc */ { .first = 0xa1, .last = 0xfe, .offset = 3390 }, /* 0xcd */ { .first = 0xa1, .last = 0xfe, .offset = 3484 }, /* 0xce */ { .first = 0xa1, .last = 0xd3, .offset = 3578 }, /* 0xcf */ { .first = 0xa1, .last = 0xfe, .offset = 3629 }, /* 0xd0 */ { .first = 0xa1, .last = 0xfe, .offset = 3723 }, /* 0xd1 */ { .first = 0xa1, .last = 0xfe, .offset = 3817 }, /* 0xd2 */ { .first = 0xa1, .last = 0xfe, .offset = 3911 }, /* 0xd3 */ { .first = 0xa1, .last = 0xfe, .offset = 4005 }, /* 0xd4 */ { .first = 0xa1, .last = 0xfe, .offset = 4099 }, /* 0xd5 */ { .first = 0xa1, .last = 0xfe, .offset = 4193 }, /* 0xd6 */ { .first = 0xa1, .last = 0xfe, .offset = 4287 }, /* 0xd7 */ { .first = 0xa1, .last = 0xfe, .offset = 4381 }, /* 0xd8 */ { .first = 0xa1, .last = 0xfe, .offset = 4475 }, /* 0xd9 */ { .first = 0xa1, .last = 0xfe, .offset = 4569 }, /* 0xda */ { .first = 0xa1, .last = 0xfe, .offset = 4663 }, /* 0xdb */ { .first = 0xa1, .last = 0xfe, .offset = 4757 }, /* 0xdc */ { .first = 0xa1, .last = 0xfe, .offset = 4851 }, /* 0xdd */ { .first = 0xa1, .last = 0xfe, .offset = 4945 }, /* 0xde */ { .first = 0xa1, .last = 0xfe, .offset = 5039 }, /* 0xdf */ { .first = 0xa1, .last = 0xfe, .offset = 5133 }, /* 0xe0 */ { .first = 0xa1, .last = 0xfe, .offset = 5227 }, /* 0xe1 */ { .first = 0xa1, .last = 0xfe, .offset = 5321 }, /* 0xe2 */ { .first = 0xa1, .last = 0xfe, .offset = 5415 }, /* 0xe3 */ { .first = 0xa1, .last = 0xfe, .offset = 5509 }, /* 0xe4 */ { .first = 0xa1, .last = 0xfe, .offset = 5603 }, /* 0xe5 */ { .first = 0xa1, .last = 0xfe, .offset = 5697 }, /* 0xe6 */ { .first = 0xa1, .last = 0xfe, .offset = 5791 }, /* 0xe7 */ { .first = 0xa1, .last = 0xfe, .offset = 5885 }, /* 0xe8 */ { .first = 0xa1, .last = 0xfe, .offset = 5979 }, /* 0xe9 */ { .first = 0xa1, .last = 0xfe, .offset = 6073 }, /* 0xea */ { .first = 0xa1, .last = 0xfe, .offset = 6167 }, /* 0xeb */ { .first = 0xa1, .last = 0xfe, .offset = 6261 }, /* 0xec */ { .first = 0xa1, .last = 0xfe, .offset = 6355 }, /* 0xed */ { .first = 0xa1, .last = 0xfe, .offset = 6449 }, /* 0xee */ { .first = 0xa1, .last = 0xfe, .offset = 6543 }, /* 0xef */ { .first = 0xa1, .last = 0xfe, .offset = 6637 }, /* 0xf0 */ { .first = 0xa1, .last = 0xfe, .offset = 6731 }, /* 0xf1 */ { .first = 0xa1, .last = 0xfe, .offset = 6825 }, /* 0xf2 */ { .first = 0xa1, .last = 0xfe, .offset = 6919 }, /* 0xf3 */ { .first = 0xa1, .last = 0xa6, .offset = 7013 }, /* 0xf4 */ }; #endif /* jis_x0208 */ /* jis_x0213 tables */ #ifdef define_jis_x0213 #define __euc_jp_jis_x0213_first_row 0xa2 #define __euc_jp_jis_x0213_last_row 0xed #ifndef split_jis_x0213 #define split_jis_x0213_offset 0 #endif static const uint16_t __euc_jp_jis_x0213_codes[] = { /* 0x8f 0xa2: 0xaf - 0xf1 */ 0x02d8, 0x02c7, 0x00b8, 0x02d9, 0x02dd, 0x00af, 0x02db, 0x02da, 0xff5e, 0x0384, 0x0385, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x00a1, 0x00a6, 0x00bf, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x00ba, 0x00aa, 0x00a9, 0x00ae, 0x2122, 0x00a4, 0x2116, /* 0x8f 0xa6: 0xe1 - 0xfc */ 0x0386, 0x0388, 0x0389, 0x038a, 0x03aa, 0xffff, 0x038c, 0xffff, 0x038e, 0x03ab, 0xffff, 0x038f, 0xffff, 0xffff, 0xffff, 0xffff, 0x03ac, 0x03ad, 0x03ae, 0x03af, 0x03ca, 0x0390, 0x03cc, 0x03c2, 0x03cd, 0x03cb, 0x03b0, 0x03ce, /* 0x8f 0xa7: 0xc2 - 0xfe */ 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x040e, 0x040f, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457, 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x045e, 0x045f, /* 0x8f 0xa9: 0xa1 - 0xd0 */ 0x00c6, 0x0110, 0xffff, 0x0126, 0xffff, 0x0132, 0xffff, 0x0141, 0x013f, 0xffff, 0x014a, 0x00d8, 0x0152, 0xffff, 0x0166, 0x00de, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x00e6, 0x0111, 0x00f0, 0x0127, 0x0131, 0x0133, 0x0138, 0x0142, 0x0140, 0x0149, 0x014b, 0x00f8, 0x0153, 0x00df, 0x0167, 0x00fe, /* 0x8f 0xaa: 0xa1 - 0xf7 */ 0x00c1, 0x00c0, 0x00c4, 0x00c2, 0x0102, 0x01cd, 0x0100, 0x0104, 0x00c5, 0x00c3, 0x0106, 0x0108, 0x010c, 0x00c7, 0x010a, 0x010e, 0x00c9, 0x00c8, 0x00cb, 0x00ca, 0x011a, 0x0116, 0x0112, 0x0118, 0xffff, 0x011c, 0x011e, 0x0122, 0x0120, 0x0124, 0x00cd, 0x00cc, 0x00cf, 0x00ce, 0x01cf, 0x0130, 0x012a, 0x012e, 0x0128, 0x0134, 0x0136, 0x0139, 0x013d, 0x013b, 0x0143, 0x0147, 0x0145, 0x00d1, 0x00d3, 0x00d2, 0x00d6, 0x00d4, 0x01d1, 0x0150, 0x014c, 0x00d5, 0x0154, 0x0158, 0x0156, 0x015a, 0x015c, 0x0160, 0x015e, 0x0164, 0x0162, 0x00da, 0x00d9, 0x00dc, 0x00db, 0x016c, 0x01d3, 0x0170, 0x016a, 0x0172, 0x016e, 0x0168, 0x01d7, 0x01db, 0x01d9, 0x01d5, 0x0174, 0x00dd, 0x0178, 0x0176, 0x0179, 0x017d, 0x017b, /* 0x8f 0xab: 0xa1 - 0xf7 */ 0x00e1, 0x00e0, 0x00e4, 0x00e2, 0x0103, 0x01ce, 0x0101, 0x0105, 0x00e5, 0x00e3, 0x0107, 0x0109, 0x010d, 0x00e7, 0x010b, 0x010f, 0x00e9, 0x00e8, 0x00eb, 0x00ea, 0x011b, 0x0117, 0x0113, 0x0119, 0x01f5, 0x011d, 0x011f, 0xffff, 0x0121, 0x0125, 0x00ed, 0x00ec, 0x00ef, 0x00ee, 0x01d0, 0xffff, 0x012b, 0x012f, 0x0129, 0x0135, 0x0137, 0x013a, 0x013e, 0x013c, 0x0144, 0x0148, 0x0146, 0x00f1, 0x00f3, 0x00f2, 0x00f6, 0x00f4, 0x01d2, 0x0151, 0x014d, 0x00f5, 0x0155, 0x0159, 0x0157, 0x015b, 0x015d, 0x0161, 0x015f, 0x0165, 0x0163, 0x00fa, 0x00f9, 0x00fc, 0x00fb, 0x016d, 0x01d4, 0x0171, 0x016b, 0x0173, 0x016f, 0x0169, 0x01d8, 0x01dc, 0x01da, 0x01d6, 0x0175, 0x00fd, 0x00ff, 0x0177, 0x017a, 0x017e, 0x017c, /* 0x8f 0xb0: 0xa1 - 0xfe */ 0x4e02, 0x4e04, 0x4e05, 0x4e0c, 0x4e12, 0x4e1f, 0x4e23, 0x4e24, 0x4e28, 0x4e2b, 0x4e2e, 0x4e2f, 0x4e30, 0x4e35, 0x4e40, 0x4e41, 0x4e44, 0x4e47, 0x4e51, 0x4e5a, 0x4e5c, 0x4e63, 0x4e68, 0x4e69, 0x4e74, 0x4e75, 0x4e79, 0x4e7f, 0x4e8d, 0x4e96, 0x4e97, 0x4e9d, 0x4eaf, 0x4eb9, 0x4ec3, 0x4ed0, 0x4eda, 0x4edb, 0x4ee0, 0x4ee1, 0x4ee2, 0x4ee8, 0x4eef, 0x4ef1, 0x4ef3, 0x4ef5, 0x4efd, 0x4efe, 0x4eff, 0x4f00, 0x4f02, 0x4f03, 0x4f08, 0x4f0b, 0x4f0c, 0x4f12, 0x4f15, 0x4f16, 0x4f17, 0x4f19, 0x4f2e, 0x4f31, 0x4f60, 0x4f33, 0x4f35, 0x4f37, 0x4f39, 0x4f3b, 0x4f3e, 0x4f40, 0x4f42, 0x4f48, 0x4f49, 0x4f4b, 0x4f4c, 0x4f52, 0x4f54, 0x4f56, 0x4f58, 0x4f5f, 0x4f63, 0x4f6a, 0x4f6c, 0x4f6e, 0x4f71, 0x4f77, 0x4f78, 0x4f79, 0x4f7a, 0x4f7d, 0x4f7e, 0x4f81, 0x4f82, 0x4f84, /* 0x8f 0xb1: 0xa1 - 0xfe */ 0x4f85, 0x4f89, 0x4f8a, 0x4f8c, 0x4f8e, 0x4f90, 0x4f92, 0x4f93, 0x4f94, 0x4f97, 0x4f99, 0x4f9a, 0x4f9e, 0x4f9f, 0x4fb2, 0x4fb7, 0x4fb9, 0x4fbb, 0x4fbc, 0x4fbd, 0x4fbe, 0x4fc0, 0x4fc1, 0x4fc5, 0x4fc6, 0x4fc8, 0x4fc9, 0x4fcb, 0x4fcc, 0x4fcd, 0x4fcf, 0x4fd2, 0x4fdc, 0x4fe0, 0x4fe2, 0x4ff0, 0x4ff2, 0x4ffc, 0x4ffd, 0x4fff, 0x5000, 0x5001, 0x5004, 0x5007, 0x500a, 0x500c, 0x500e, 0x5010, 0x5013, 0x5017, 0x5018, 0x501b, 0x501c, 0x501d, 0x501e, 0x5022, 0x5027, 0x502e, 0x5030, 0x5032, 0x5033, 0x5035, 0x5040, 0x5041, 0x5042, 0x5045, 0x5046, 0x504a, 0x504c, 0x504e, 0x5051, 0x5052, 0x5053, 0x5057, 0x5059, 0x505f, 0x5060, 0x5062, 0x5063, 0x5066, 0x5067, 0x506a, 0x506d, 0x5070, 0x5071, 0x503b, 0x5081, 0x5083, 0x5084, 0x5086, 0x508a, 0x508e, 0x508f, 0x5090, /* 0x8f 0xb2: 0xa1 - 0xfe */ 0x5092, 0x5093, 0x5094, 0x5096, 0x509b, 0x509c, 0x509e, 0x509f, 0x50a0, 0x50a1, 0x50a2, 0x50aa, 0x50af, 0x50b0, 0x50b9, 0x50ba, 0x50bd, 0x50c0, 0x50c3, 0x50c4, 0x50c7, 0x50cc, 0x50ce, 0x50d0, 0x50d3, 0x50d4, 0x50d8, 0x50dc, 0x50dd, 0x50df, 0x50e2, 0x50e4, 0x50e6, 0x50e8, 0x50e9, 0x50ef, 0x50f1, 0x50f6, 0x50fa, 0x50fe, 0x5103, 0x5106, 0x5107, 0x5108, 0x510b, 0x510c, 0x510d, 0x510e, 0x50f2, 0x5110, 0x5117, 0x5119, 0x511b, 0x511c, 0x511d, 0x511e, 0x5123, 0x5127, 0x5128, 0x512c, 0x512d, 0x512f, 0x5131, 0x5133, 0x5134, 0x5135, 0x5138, 0x5139, 0x5142, 0x514a, 0x514f, 0x5153, 0x5155, 0x5157, 0x5158, 0x515f, 0x5164, 0x5166, 0x517e, 0x5183, 0x5184, 0x518b, 0x518e, 0x5198, 0x519d, 0x51a1, 0x51a3, 0x51ad, 0x51b8, 0x51ba, 0x51bc, 0x51be, 0x51bf, 0x51c2, /* 0x8f 0xb3: 0xa1 - 0xfe */ 0x51c8, 0x51cf, 0x51d1, 0x51d2, 0x51d3, 0x51d5, 0x51d8, 0x51de, 0x51e2, 0x51e5, 0x51ee, 0x51f2, 0x51f3, 0x51f4, 0x51f7, 0x5201, 0x5202, 0x5205, 0x5212, 0x5213, 0x5215, 0x5216, 0x5218, 0x5222, 0x5228, 0x5231, 0x5232, 0x5235, 0x523c, 0x5245, 0x5249, 0x5255, 0x5257, 0x5258, 0x525a, 0x525c, 0x525f, 0x5260, 0x5261, 0x5266, 0x526e, 0x5277, 0x5278, 0x5279, 0x5280, 0x5282, 0x5285, 0x528a, 0x528c, 0x5293, 0x5295, 0x5296, 0x5297, 0x5298, 0x529a, 0x529c, 0x52a4, 0x52a5, 0x52a6, 0x52a7, 0x52af, 0x52b0, 0x52b6, 0x52b7, 0x52b8, 0x52ba, 0x52bb, 0x52bd, 0x52c0, 0x52c4, 0x52c6, 0x52c8, 0x52cc, 0x52cf, 0x52d1, 0x52d4, 0x52d6, 0x52db, 0x52dc, 0x52e1, 0x52e5, 0x52e8, 0x52e9, 0x52ea, 0x52ec, 0x52f0, 0x52f1, 0x52f4, 0x52f6, 0x52f7, 0x5300, 0x5303, 0x530a, 0x530b, /* 0x8f 0xb4: 0xa1 - 0xfe */ 0x530c, 0x5311, 0x5313, 0x5318, 0x531b, 0x531c, 0x531e, 0x531f, 0x5325, 0x5327, 0x5328, 0x5329, 0x532b, 0x532c, 0x532d, 0x5330, 0x5332, 0x5335, 0x533c, 0x533d, 0x533e, 0x5342, 0x534c, 0x534b, 0x5359, 0x535b, 0x5361, 0x5363, 0x5365, 0x536c, 0x536d, 0x5372, 0x5379, 0x537e, 0x5383, 0x5387, 0x5388, 0x538e, 0x5393, 0x5394, 0x5399, 0x539d, 0x53a1, 0x53a4, 0x53aa, 0x53ab, 0x53af, 0x53b2, 0x53b4, 0x53b5, 0x53b7, 0x53b8, 0x53ba, 0x53bd, 0x53c0, 0x53c5, 0x53cf, 0x53d2, 0x53d3, 0x53d5, 0x53da, 0x53dd, 0x53de, 0x53e0, 0x53e6, 0x53e7, 0x53f5, 0x5402, 0x5413, 0x541a, 0x5421, 0x5427, 0x5428, 0x542a, 0x542f, 0x5431, 0x5434, 0x5435, 0x5443, 0x5444, 0x5447, 0x544d, 0x544f, 0x545e, 0x5462, 0x5464, 0x5466, 0x5467, 0x5469, 0x546b, 0x546d, 0x546e, 0x5474, 0x547f, /* 0x8f 0xb5: 0xa1 - 0xfe */ 0x5481, 0x5483, 0x5485, 0x5488, 0x5489, 0x548d, 0x5491, 0x5495, 0x5496, 0x549c, 0x549f, 0x54a1, 0x54a6, 0x54a7, 0x54a9, 0x54aa, 0x54ad, 0x54ae, 0x54b1, 0x54b7, 0x54b9, 0x54ba, 0x54bb, 0x54bf, 0x54c6, 0x54ca, 0x54cd, 0x54ce, 0x54e0, 0x54ea, 0x54ec, 0x54ef, 0x54f6, 0x54fc, 0x54fe, 0x54ff, 0x5500, 0x5501, 0x5505, 0x5508, 0x5509, 0x550c, 0x550d, 0x550e, 0x5515, 0x552a, 0x552b, 0x5532, 0x5535, 0x5536, 0x553b, 0x553c, 0x553d, 0x5541, 0x5547, 0x5549, 0x554a, 0x554d, 0x5550, 0x5551, 0x5558, 0x555a, 0x555b, 0x555e, 0x5560, 0x5561, 0x5564, 0x5566, 0x557f, 0x5581, 0x5582, 0x5586, 0x5588, 0x558e, 0x558f, 0x5591, 0x5592, 0x5593, 0x5594, 0x5597, 0x55a3, 0x55a4, 0x55ad, 0x55b2, 0x55bf, 0x55c1, 0x55c3, 0x55c6, 0x55c9, 0x55cb, 0x55cc, 0x55ce, 0x55d1, 0x55d2, /* 0x8f 0xb6: 0xa1 - 0xfe */ 0x55d3, 0x55d7, 0x55d8, 0x55db, 0x55de, 0x55e2, 0x55e9, 0x55f6, 0x55ff, 0x5605, 0x5608, 0x560a, 0x560d, 0x560e, 0x560f, 0x5610, 0x5611, 0x5612, 0x5619, 0x562c, 0x5630, 0x5633, 0x5635, 0x5637, 0x5639, 0x563b, 0x563c, 0x563d, 0x563f, 0x5640, 0x5641, 0x5643, 0x5644, 0x5646, 0x5649, 0x564b, 0x564d, 0x564f, 0x5654, 0x565e, 0x5660, 0x5661, 0x5662, 0x5663, 0x5666, 0x5669, 0x566d, 0x566f, 0x5671, 0x5672, 0x5675, 0x5684, 0x5685, 0x5688, 0x568b, 0x568c, 0x5695, 0x5699, 0x569a, 0x569d, 0x569e, 0x569f, 0x56a6, 0x56a7, 0x56a8, 0x56a9, 0x56ab, 0x56ac, 0x56ad, 0x56b1, 0x56b3, 0x56b7, 0x56be, 0x56c5, 0x56c9, 0x56ca, 0x56cb, 0x56cf, 0x56d0, 0x56cc, 0x56cd, 0x56d9, 0x56dc, 0x56dd, 0x56df, 0x56e1, 0x56e4, 0x56e5, 0x56e6, 0x56e7, 0x56e8, 0x56f1, 0x56eb, 0x56ed, /* 0x8f 0xb7: 0xa1 - 0xfe */ 0x56f6, 0x56f7, 0x5701, 0x5702, 0x5707, 0x570a, 0x570c, 0x5711, 0x5715, 0x571a, 0x571b, 0x571d, 0x5720, 0x5722, 0x5723, 0x5724, 0x5725, 0x5729, 0x572a, 0x572c, 0x572e, 0x572f, 0x5733, 0x5734, 0x573d, 0x573e, 0x573f, 0x5745, 0x5746, 0x574c, 0x574d, 0x5752, 0x5762, 0x5765, 0x5767, 0x5768, 0x576b, 0x576d, 0x576e, 0x576f, 0x5770, 0x5771, 0x5773, 0x5774, 0x5775, 0x5777, 0x5779, 0x577a, 0x577b, 0x577c, 0x577e, 0x5781, 0x5783, 0x578c, 0x5794, 0x5797, 0x5799, 0x579a, 0x579c, 0x579d, 0x579e, 0x579f, 0x57a1, 0x5795, 0x57a7, 0x57a8, 0x57a9, 0x57ac, 0x57b8, 0x57bd, 0x57c7, 0x57c8, 0x57cc, 0x57cf, 0x57d5, 0x57dd, 0x57de, 0x57e4, 0x57e6, 0x57e7, 0x57e9, 0x57ed, 0x57f0, 0x57f5, 0x57f6, 0x57f8, 0x57fd, 0x57fe, 0x57ff, 0x5803, 0x5804, 0x5808, 0x5809, 0x57e1, /* 0x8f 0xb8: 0xa1 - 0xfe */ 0x580c, 0x580d, 0x581b, 0x581e, 0x581f, 0x5820, 0x5826, 0x5827, 0x582d, 0x5832, 0x5839, 0x583f, 0x5849, 0x584c, 0x584d, 0x584f, 0x5850, 0x5855, 0x585f, 0x5861, 0x5864, 0x5867, 0x5868, 0x5878, 0x587c, 0x587f, 0x5880, 0x5881, 0x5887, 0x5888, 0x5889, 0x588a, 0x588c, 0x588d, 0x588f, 0x5890, 0x5894, 0x5896, 0x589d, 0x58a0, 0x58a1, 0x58a2, 0x58a6, 0x58a9, 0x58b1, 0x58b2, 0x58c4, 0x58bc, 0x58c2, 0x58c8, 0x58cd, 0x58ce, 0x58d0, 0x58d2, 0x58d4, 0x58d6, 0x58da, 0x58dd, 0x58e1, 0x58e2, 0x58e9, 0x58f3, 0x5905, 0x5906, 0x590b, 0x590c, 0x5912, 0x5913, 0x5914, 0x8641, 0x591d, 0x5921, 0x5923, 0x5924, 0x5928, 0x592f, 0x5930, 0x5933, 0x5935, 0x5936, 0x593f, 0x5943, 0x5946, 0x5952, 0x5953, 0x5959, 0x595b, 0x595d, 0x595e, 0x595f, 0x5961, 0x5963, 0x596b, 0x596d, /* 0x8f 0xb9: 0xa1 - 0xfe */ 0x596f, 0x5972, 0x5975, 0x5976, 0x5979, 0x597b, 0x597c, 0x598b, 0x598c, 0x598e, 0x5992, 0x5995, 0x5997, 0x599f, 0x59a4, 0x59a7, 0x59ad, 0x59ae, 0x59af, 0x59b0, 0x59b3, 0x59b7, 0x59ba, 0x59bc, 0x59c1, 0x59c3, 0x59c4, 0x59c8, 0x59ca, 0x59cd, 0x59d2, 0x59dd, 0x59de, 0x59df, 0x59e3, 0x59e4, 0x59e7, 0x59ee, 0x59ef, 0x59f1, 0x59f2, 0x59f4, 0x59f7, 0x5a00, 0x5a04, 0x5a0c, 0x5a0d, 0x5a0e, 0x5a12, 0x5a13, 0x5a1e, 0x5a23, 0x5a24, 0x5a27, 0x5a28, 0x5a2a, 0x5a2d, 0x5a30, 0x5a44, 0x5a45, 0x5a47, 0x5a48, 0x5a4c, 0x5a50, 0x5a55, 0x5a5e, 0x5a63, 0x5a65, 0x5a67, 0x5a6d, 0x5a77, 0x5a7a, 0x5a7b, 0x5a7e, 0x5a8b, 0x5a90, 0x5a93, 0x5a96, 0x5a99, 0x5a9c, 0x5a9e, 0x5a9f, 0x5aa0, 0x5aa2, 0x5aa7, 0x5aac, 0x5ab1, 0x5ab2, 0x5ab3, 0x5ab5, 0x5ab8, 0x5aba, 0x5abb, 0x5abf, /* 0x8f 0xba: 0xa1 - 0xfe */ 0x5ac4, 0x5ac6, 0x5ac8, 0x5acf, 0x5ada, 0x5adc, 0x5ae0, 0x5ae5, 0x5aea, 0x5aee, 0x5af5, 0x5af6, 0x5afd, 0x5b00, 0x5b01, 0x5b08, 0x5b17, 0x5b34, 0x5b19, 0x5b1b, 0x5b1d, 0x5b21, 0x5b25, 0x5b2d, 0x5b38, 0x5b41, 0x5b4b, 0x5b4c, 0x5b52, 0x5b56, 0x5b5e, 0x5b68, 0x5b6e, 0x5b6f, 0x5b7c, 0x5b7d, 0x5b7e, 0x5b7f, 0x5b81, 0x5b84, 0x5b86, 0x5b8a, 0x5b8e, 0x5b90, 0x5b91, 0x5b93, 0x5b94, 0x5b96, 0x5ba8, 0x5ba9, 0x5bac, 0x5bad, 0x5baf, 0x5bb1, 0x5bb2, 0x5bb7, 0x5bba, 0x5bbc, 0x5bc0, 0x5bc1, 0x5bcd, 0x5bcf, 0x5bd6, 0x5bd7, 0x5bd8, 0x5bd9, 0x5bda, 0x5be0, 0x5bef, 0x5bf1, 0x5bf4, 0x5bfd, 0x5c0c, 0x5c17, 0x5c1e, 0x5c1f, 0x5c23, 0x5c26, 0x5c29, 0x5c2b, 0x5c2c, 0x5c2e, 0x5c30, 0x5c32, 0x5c35, 0x5c36, 0x5c59, 0x5c5a, 0x5c5c, 0x5c62, 0x5c63, 0x5c67, 0x5c68, 0x5c69, /* 0x8f 0xbb: 0xa1 - 0xfe */ 0x5c6d, 0x5c70, 0x5c74, 0x5c75, 0x5c7a, 0x5c7b, 0x5c7c, 0x5c7d, 0x5c87, 0x5c88, 0x5c8a, 0x5c8f, 0x5c92, 0x5c9d, 0x5c9f, 0x5ca0, 0x5ca2, 0x5ca3, 0x5ca6, 0x5caa, 0x5cb2, 0x5cb4, 0x5cb5, 0x5cba, 0x5cc9, 0x5ccb, 0x5cd2, 0x5cdd, 0x5cd7, 0x5cee, 0x5cf1, 0x5cf2, 0x5cf4, 0x5d01, 0x5d06, 0x5d0d, 0x5d12, 0x5d2b, 0x5d23, 0x5d24, 0x5d26, 0x5d27, 0x5d31, 0x5d34, 0x5d39, 0x5d3d, 0x5d3f, 0x5d42, 0x5d43, 0x5d46, 0x5d48, 0x5d55, 0x5d51, 0x5d59, 0x5d4a, 0x5d5f, 0x5d60, 0x5d61, 0x5d62, 0x5d64, 0x5d6a, 0x5d6d, 0x5d70, 0x5d79, 0x5d7a, 0x5d7e, 0x5d7f, 0x5d81, 0x5d83, 0x5d88, 0x5d8a, 0x5d92, 0x5d93, 0x5d94, 0x5d95, 0x5d99, 0x5d9b, 0x5d9f, 0x5da0, 0x5da7, 0x5dab, 0x5db0, 0x5db4, 0x5db8, 0x5db9, 0x5dc3, 0x5dc7, 0x5dcb, 0x5dd0, 0x5dce, 0x5dd8, 0x5dd9, 0x5de0, 0x5de4, /* 0x8f 0xbc: 0xa1 - 0xfe */ 0x5de9, 0x5df8, 0x5df9, 0x5e00, 0x5e07, 0x5e0d, 0x5e12, 0x5e14, 0x5e15, 0x5e18, 0x5e1f, 0x5e20, 0x5e2e, 0x5e28, 0x5e32, 0x5e35, 0x5e3e, 0x5e4b, 0x5e50, 0x5e49, 0x5e51, 0x5e56, 0x5e58, 0x5e5b, 0x5e5c, 0x5e5e, 0x5e68, 0x5e6a, 0x5e6b, 0x5e6c, 0x5e6d, 0x5e6e, 0x5e70, 0x5e80, 0x5e8b, 0x5e8e, 0x5ea2, 0x5ea4, 0x5ea5, 0x5ea8, 0x5eaa, 0x5eac, 0x5eb1, 0x5eb3, 0x5ebd, 0x5ebe, 0x5ebf, 0x5ec6, 0x5ecc, 0x5ecb, 0x5ece, 0x5ed1, 0x5ed2, 0x5ed4, 0x5ed5, 0x5edc, 0x5ede, 0x5ee5, 0x5eeb, 0x5f02, 0x5f06, 0x5f07, 0x5f08, 0x5f0e, 0x5f19, 0x5f1c, 0x5f1d, 0x5f21, 0x5f22, 0x5f23, 0x5f24, 0x5f28, 0x5f2b, 0x5f2c, 0x5f2e, 0x5f30, 0x5f34, 0x5f36, 0x5f3b, 0x5f3d, 0x5f3f, 0x5f40, 0x5f44, 0x5f45, 0x5f47, 0x5f4d, 0x5f50, 0x5f54, 0x5f58, 0x5f5b, 0x5f60, 0x5f63, 0x5f64, 0x5f67, /* 0x8f 0xbd: 0xa1 - 0xfe */ 0x5f6f, 0x5f72, 0x5f74, 0x5f75, 0x5f78, 0x5f7a, 0x5f7d, 0x5f7e, 0x5f89, 0x5f8d, 0x5f8f, 0x5f96, 0x5f9c, 0x5f9d, 0x5fa2, 0x5fa7, 0x5fab, 0x5fa4, 0x5fac, 0x5faf, 0x5fb0, 0x5fb1, 0x5fb8, 0x5fc4, 0x5fc7, 0x5fc8, 0x5fc9, 0x5fcb, 0x5fd0, 0x5fd1, 0x5fd2, 0x5fd3, 0x5fd4, 0x5fde, 0x5fe1, 0x5fe2, 0x5fe8, 0x5fe9, 0x5fea, 0x5fec, 0x5fed, 0x5fee, 0x5fef, 0x5ff2, 0x5ff3, 0x5ff6, 0x5ffa, 0x5ffc, 0x6007, 0x600a, 0x600d, 0x6013, 0x6014, 0x6017, 0x6018, 0x601a, 0x601f, 0x6024, 0x602d, 0x6033, 0x6035, 0x6040, 0x6047, 0x6048, 0x6049, 0x604c, 0x6051, 0x6054, 0x6056, 0x6057, 0x605d, 0x6061, 0x6067, 0x6071, 0x607e, 0x607f, 0x6082, 0x6086, 0x6088, 0x608a, 0x608e, 0x6091, 0x6093, 0x6095, 0x6098, 0x609d, 0x609e, 0x60a2, 0x60a4, 0x60a5, 0x60a8, 0x60b0, 0x60b1, 0x60b7, /* 0x8f 0xbe: 0xa1 - 0xfe */ 0x60bb, 0x60be, 0x60c2, 0x60c4, 0x60c8, 0x60c9, 0x60ca, 0x60cb, 0x60ce, 0x60cf, 0x60d4, 0x60d5, 0x60d9, 0x60db, 0x60dd, 0x60de, 0x60e2, 0x60e5, 0x60f2, 0x60f5, 0x60f8, 0x60fc, 0x60fd, 0x6102, 0x6107, 0x610a, 0x610c, 0x6110, 0x6111, 0x6112, 0x6113, 0x6114, 0x6116, 0x6117, 0x6119, 0x611c, 0x611e, 0x6122, 0x612a, 0x612b, 0x6130, 0x6131, 0x6135, 0x6136, 0x6137, 0x6139, 0x6141, 0x6145, 0x6146, 0x6149, 0x615e, 0x6160, 0x616c, 0x6172, 0x6178, 0x617b, 0x617c, 0x617f, 0x6180, 0x6181, 0x6183, 0x6184, 0x618b, 0x618d, 0x6192, 0x6193, 0x6197, 0x6198, 0x619c, 0x619d, 0x619f, 0x61a0, 0x61a5, 0x61a8, 0x61aa, 0x61ad, 0x61b8, 0x61b9, 0x61bc, 0x61c0, 0x61c1, 0x61c2, 0x61ce, 0x61cf, 0x61d5, 0x61dc, 0x61dd, 0x61de, 0x61df, 0x61e1, 0x61e2, 0x61e7, 0x61e9, 0x61e5, /* 0x8f 0xbf: 0xa1 - 0xfe */ 0x61ec, 0x61ed, 0x61ef, 0x6201, 0x6203, 0x6204, 0x6207, 0x6213, 0x6215, 0x621c, 0x6220, 0x6222, 0x6223, 0x6227, 0x6229, 0x622b, 0x6239, 0x623d, 0x6242, 0x6243, 0x6244, 0x6246, 0x624c, 0x6250, 0x6251, 0x6252, 0x6254, 0x6256, 0x625a, 0x625c, 0x6264, 0x626d, 0x626f, 0x6273, 0x627a, 0x627d, 0x628d, 0x628e, 0x628f, 0x6290, 0x62a6, 0x62a8, 0x62b3, 0x62b6, 0x62b7, 0x62ba, 0x62be, 0x62bf, 0x62c4, 0x62ce, 0x62d5, 0x62d6, 0x62da, 0x62ea, 0x62f2, 0x62f4, 0x62fc, 0x62fd, 0x6303, 0x6304, 0x630a, 0x630b, 0x630d, 0x6310, 0x6313, 0x6316, 0x6318, 0x6329, 0x632a, 0x632d, 0x6335, 0x6336, 0x6339, 0x633c, 0x6341, 0x6342, 0x6343, 0x6344, 0x6346, 0x634a, 0x634b, 0x634e, 0x6352, 0x6353, 0x6354, 0x6358, 0x635b, 0x6365, 0x6366, 0x636c, 0x636d, 0x6371, 0x6374, 0x6375, /* 0x8f 0xc0: 0xa1 - 0xfe */ 0x6378, 0x637c, 0x637d, 0x637f, 0x6382, 0x6384, 0x6387, 0x638a, 0x6390, 0x6394, 0x6395, 0x6399, 0x639a, 0x639e, 0x63a4, 0x63a6, 0x63ad, 0x63ae, 0x63af, 0x63bd, 0x63c1, 0x63c5, 0x63c8, 0x63ce, 0x63d1, 0x63d3, 0x63d4, 0x63d5, 0x63dc, 0x63e0, 0x63e5, 0x63ea, 0x63ec, 0x63f2, 0x63f3, 0x63f5, 0x63f8, 0x63f9, 0x6409, 0x640a, 0x6410, 0x6412, 0x6414, 0x6418, 0x641e, 0x6420, 0x6422, 0x6424, 0x6425, 0x6429, 0x642a, 0x642f, 0x6430, 0x6435, 0x643d, 0x643f, 0x644b, 0x644f, 0x6451, 0x6452, 0x6453, 0x6454, 0x645a, 0x645b, 0x645c, 0x645d, 0x645f, 0x6460, 0x6461, 0x6463, 0x646d, 0x6473, 0x6474, 0x647b, 0x647d, 0x6485, 0x6487, 0x648f, 0x6490, 0x6491, 0x6498, 0x6499, 0x649b, 0x649d, 0x649f, 0x64a1, 0x64a3, 0x64a6, 0x64a8, 0x64ac, 0x64b3, 0x64bd, 0x64be, 0x64bf, /* 0x8f 0xc1: 0xa1 - 0xfe */ 0x64c4, 0x64c9, 0x64ca, 0x64cb, 0x64cc, 0x64ce, 0x64d0, 0x64d1, 0x64d5, 0x64d7, 0x64e4, 0x64e5, 0x64e9, 0x64ea, 0x64ed, 0x64f0, 0x64f5, 0x64f7, 0x64fb, 0x64ff, 0x6501, 0x6504, 0x6508, 0x6509, 0x650a, 0x650f, 0x6513, 0x6514, 0x6516, 0x6519, 0x651b, 0x651e, 0x651f, 0x6522, 0x6526, 0x6529, 0x652e, 0x6531, 0x653a, 0x653c, 0x653d, 0x6543, 0x6547, 0x6549, 0x6550, 0x6552, 0x6554, 0x655f, 0x6560, 0x6567, 0x656b, 0x657a, 0x657d, 0x6581, 0x6585, 0x658a, 0x6592, 0x6595, 0x6598, 0x659d, 0x65a0, 0x65a3, 0x65a6, 0x65ae, 0x65b2, 0x65b3, 0x65b4, 0x65bf, 0x65c2, 0x65c8, 0x65c9, 0x65ce, 0x65d0, 0x65d4, 0x65d6, 0x65d8, 0x65df, 0x65f0, 0x65f2, 0x65f4, 0x65f5, 0x65f9, 0x65fe, 0x65ff, 0x6600, 0x6604, 0x6608, 0x6609, 0x660d, 0x6611, 0x6612, 0x6615, 0x6616, 0x661d, /* 0x8f 0xc2: 0xa1 - 0xfe */ 0x661e, 0x6621, 0x6622, 0x6623, 0x6624, 0x6626, 0x6629, 0x662a, 0x662b, 0x662c, 0x662e, 0x6630, 0x6631, 0x6633, 0x6639, 0x6637, 0x6640, 0x6645, 0x6646, 0x664a, 0x664c, 0x6651, 0x664e, 0x6657, 0x6658, 0x6659, 0x665b, 0x665c, 0x6660, 0x6661, 0x66fb, 0x666a, 0x666b, 0x666c, 0x667e, 0x6673, 0x6675, 0x667f, 0x6677, 0x6678, 0x6679, 0x667b, 0x6680, 0x667c, 0x668b, 0x668c, 0x668d, 0x6690, 0x6692, 0x6699, 0x669a, 0x669b, 0x669c, 0x669f, 0x66a0, 0x66a4, 0x66ad, 0x66b1, 0x66b2, 0x66b5, 0x66bb, 0x66bf, 0x66c0, 0x66c2, 0x66c3, 0x66c8, 0x66cc, 0x66ce, 0x66cf, 0x66d4, 0x66db, 0x66df, 0x66e8, 0x66eb, 0x66ec, 0x66ee, 0x66fa, 0x6705, 0x6707, 0x670e, 0x6713, 0x6719, 0x671c, 0x6720, 0x6722, 0x6733, 0x673e, 0x6745, 0x6747, 0x6748, 0x674c, 0x6754, 0x6755, 0x675d, /* 0x8f 0xc3: 0xa1 - 0xfe */ 0x6766, 0x676c, 0x676e, 0x6774, 0x6776, 0x677b, 0x6781, 0x6784, 0x678e, 0x678f, 0x6791, 0x6793, 0x6796, 0x6798, 0x6799, 0x679b, 0x67b0, 0x67b1, 0x67b2, 0x67b5, 0x67bb, 0x67bc, 0x67bd, 0x67f9, 0x67c0, 0x67c2, 0x67c3, 0x67c5, 0x67c8, 0x67c9, 0x67d2, 0x67d7, 0x67d9, 0x67dc, 0x67e1, 0x67e6, 0x67f0, 0x67f2, 0x67f6, 0x67f7, 0x6852, 0x6814, 0x6819, 0x681d, 0x681f, 0x6828, 0x6827, 0x682c, 0x682d, 0x682f, 0x6830, 0x6831, 0x6833, 0x683b, 0x683f, 0x6844, 0x6845, 0x684a, 0x684c, 0x6855, 0x6857, 0x6858, 0x685b, 0x686b, 0x686e, 0x686f, 0x6870, 0x6871, 0x6872, 0x6875, 0x6879, 0x687a, 0x687b, 0x687c, 0x6882, 0x6884, 0x6886, 0x6888, 0x6896, 0x6898, 0x689a, 0x689c, 0x68a1, 0x68a3, 0x68a5, 0x68a9, 0x68aa, 0x68ae, 0x68b2, 0x68bb, 0x68c5, 0x68c8, 0x68cc, 0x68cf, /* 0x8f 0xc4: 0xa1 - 0xfe */ 0x68d0, 0x68d1, 0x68d3, 0x68d6, 0x68d9, 0x68dc, 0x68dd, 0x68e5, 0x68e8, 0x68ea, 0x68eb, 0x68ec, 0x68ed, 0x68f0, 0x68f1, 0x68f5, 0x68f6, 0x68fb, 0x68fc, 0x68fd, 0x6906, 0x6909, 0x690a, 0x6910, 0x6911, 0x6913, 0x6916, 0x6917, 0x6931, 0x6933, 0x6935, 0x6938, 0x693b, 0x6942, 0x6945, 0x6949, 0x694e, 0x6957, 0x695b, 0x6963, 0x6964, 0x6965, 0x6966, 0x6968, 0x6969, 0x696c, 0x6970, 0x6971, 0x6972, 0x697a, 0x697b, 0x697f, 0x6980, 0x698d, 0x6992, 0x6996, 0x6998, 0x69a1, 0x69a5, 0x69a6, 0x69a8, 0x69ab, 0x69ad, 0x69af, 0x69b7, 0x69b8, 0x69ba, 0x69bc, 0x69c5, 0x69c8, 0x69d1, 0x69d6, 0x69d7, 0x69e2, 0x69e5, 0x69ee, 0x69ef, 0x69f1, 0x69f3, 0x69f5, 0x69fe, 0x6a00, 0x6a01, 0x6a03, 0x6a0f, 0x6a11, 0x6a15, 0x6a1a, 0x6a1d, 0x6a20, 0x6a24, 0x6a28, 0x6a30, 0x6a32, /* 0x8f 0xc5: 0xa1 - 0xfe */ 0x6a34, 0x6a37, 0x6a3b, 0x6a3e, 0x6a3f, 0x6a45, 0x6a46, 0x6a49, 0x6a4a, 0x6a4e, 0x6a50, 0x6a51, 0x6a52, 0x6a55, 0x6a56, 0x6a5b, 0x6a64, 0x6a67, 0x6a6a, 0x6a71, 0x6a73, 0x6a7e, 0x6a81, 0x6a83, 0x6a86, 0x6a87, 0x6a89, 0x6a8b, 0x6a91, 0x6a9b, 0x6a9d, 0x6a9e, 0x6a9f, 0x6aa5, 0x6aab, 0x6aaf, 0x6ab0, 0x6ab1, 0x6ab4, 0x6abd, 0x6abe, 0x6abf, 0x6ac6, 0x6ac9, 0x6ac8, 0x6acc, 0x6ad0, 0x6ad4, 0x6ad5, 0x6ad6, 0x6adc, 0x6add, 0x6ae4, 0x6ae7, 0x6aec, 0x6af0, 0x6af1, 0x6af2, 0x6afc, 0x6afd, 0x6b02, 0x6b03, 0x6b06, 0x6b07, 0x6b09, 0x6b0f, 0x6b10, 0x6b11, 0x6b17, 0x6b1b, 0x6b1e, 0x6b24, 0x6b28, 0x6b2b, 0x6b2c, 0x6b2f, 0x6b35, 0x6b36, 0x6b3b, 0x6b3f, 0x6b46, 0x6b4a, 0x6b4d, 0x6b52, 0x6b56, 0x6b58, 0x6b5d, 0x6b60, 0x6b67, 0x6b6b, 0x6b6e, 0x6b70, 0x6b75, 0x6b7d, /* 0x8f 0xc6: 0xa1 - 0xfe */ 0x6b7e, 0x6b82, 0x6b85, 0x6b97, 0x6b9b, 0x6b9f, 0x6ba0, 0x6ba2, 0x6ba3, 0x6ba8, 0x6ba9, 0x6bac, 0x6bad, 0x6bae, 0x6bb0, 0x6bb8, 0x6bb9, 0x6bbd, 0x6bbe, 0x6bc3, 0x6bc4, 0x6bc9, 0x6bcc, 0x6bd6, 0x6bda, 0x6be1, 0x6be3, 0x6be6, 0x6be7, 0x6bee, 0x6bf1, 0x6bf7, 0x6bf9, 0x6bff, 0x6c02, 0x6c04, 0x6c05, 0x6c09, 0x6c0d, 0x6c0e, 0x6c10, 0x6c12, 0x6c19, 0x6c1f, 0x6c26, 0x6c27, 0x6c28, 0x6c2c, 0x6c2e, 0x6c33, 0x6c35, 0x6c36, 0x6c3a, 0x6c3b, 0x6c3f, 0x6c4a, 0x6c4b, 0x6c4d, 0x6c4f, 0x6c52, 0x6c54, 0x6c59, 0x6c5b, 0x6c5c, 0x6c6b, 0x6c6d, 0x6c6f, 0x6c74, 0x6c76, 0x6c78, 0x6c79, 0x6c7b, 0x6c85, 0x6c86, 0x6c87, 0x6c89, 0x6c94, 0x6c95, 0x6c97, 0x6c98, 0x6c9c, 0x6c9f, 0x6cb0, 0x6cb2, 0x6cb4, 0x6cc2, 0x6cc6, 0x6ccd, 0x6ccf, 0x6cd0, 0x6cd1, 0x6cd2, 0x6cd4, 0x6cd6, /* 0x8f 0xc7: 0xa1 - 0xfe */ 0x6cda, 0x6cdc, 0x6ce0, 0x6ce7, 0x6ce9, 0x6ceb, 0x6cec, 0x6cee, 0x6cf2, 0x6cf4, 0x6d04, 0x6d07, 0x6d0a, 0x6d0e, 0x6d0f, 0x6d11, 0x6d13, 0x6d1a, 0x6d26, 0x6d27, 0x6d28, 0x6c67, 0x6d2e, 0x6d2f, 0x6d31, 0x6d39, 0x6d3c, 0x6d3f, 0x6d57, 0x6d5e, 0x6d5f, 0x6d61, 0x6d65, 0x6d67, 0x6d6f, 0x6d70, 0x6d7c, 0x6d82, 0x6d87, 0x6d91, 0x6d92, 0x6d94, 0x6d96, 0x6d97, 0x6d98, 0x6daa, 0x6dac, 0x6db4, 0x6db7, 0x6db9, 0x6dbd, 0x6dbf, 0x6dc4, 0x6dc8, 0x6dca, 0x6dce, 0x6dcf, 0x6dd6, 0x6ddb, 0x6ddd, 0x6ddf, 0x6de0, 0x6de2, 0x6de5, 0x6de9, 0x6def, 0x6df0, 0x6df4, 0x6df6, 0x6dfc, 0x6e00, 0x6e04, 0x6e1e, 0x6e22, 0x6e27, 0x6e32, 0x6e36, 0x6e39, 0x6e3b, 0x6e3c, 0x6e44, 0x6e45, 0x6e48, 0x6e49, 0x6e4b, 0x6e4f, 0x6e51, 0x6e52, 0x6e53, 0x6e54, 0x6e57, 0x6e5c, 0x6e5d, 0x6e5e, /* 0x8f 0xc8: 0xa1 - 0xfe */ 0x6e62, 0x6e63, 0x6e68, 0x6e73, 0x6e7b, 0x6e7d, 0x6e8d, 0x6e93, 0x6e99, 0x6ea0, 0x6ea7, 0x6ead, 0x6eae, 0x6eb1, 0x6eb3, 0x6ebb, 0x6ebf, 0x6ec0, 0x6ec1, 0x6ec3, 0x6ec7, 0x6ec8, 0x6eca, 0x6ecd, 0x6ece, 0x6ecf, 0x6eeb, 0x6eed, 0x6eee, 0x6ef9, 0x6efb, 0x6efd, 0x6f04, 0x6f08, 0x6f0a, 0x6f0c, 0x6f0d, 0x6f16, 0x6f18, 0x6f1a, 0x6f1b, 0x6f26, 0x6f29, 0x6f2a, 0x6f2f, 0x6f30, 0x6f33, 0x6f36, 0x6f3b, 0x6f3c, 0x6f2d, 0x6f4f, 0x6f51, 0x6f52, 0x6f53, 0x6f57, 0x6f59, 0x6f5a, 0x6f5d, 0x6f5e, 0x6f61, 0x6f62, 0x6f68, 0x6f6c, 0x6f7d, 0x6f7e, 0x6f83, 0x6f87, 0x6f88, 0x6f8b, 0x6f8c, 0x6f8d, 0x6f90, 0x6f92, 0x6f93, 0x6f94, 0x6f96, 0x6f9a, 0x6f9f, 0x6fa0, 0x6fa5, 0x6fa6, 0x6fa7, 0x6fa8, 0x6fae, 0x6faf, 0x6fb0, 0x6fb5, 0x6fb6, 0x6fbc, 0x6fc5, 0x6fc7, 0x6fc8, 0x6fca, /* 0x8f 0xc9: 0xa1 - 0xfe */ 0x6fda, 0x6fde, 0x6fe8, 0x6fe9, 0x6ff0, 0x6ff5, 0x6ff9, 0x6ffc, 0x6ffd, 0x7000, 0x7005, 0x7006, 0x7007, 0x700d, 0x7017, 0x7020, 0x7023, 0x702f, 0x7034, 0x7037, 0x7039, 0x703c, 0x7043, 0x7044, 0x7048, 0x7049, 0x704a, 0x704b, 0x7054, 0x7055, 0x705d, 0x705e, 0x704e, 0x7064, 0x7065, 0x706c, 0x706e, 0x7075, 0x7076, 0x707e, 0x7081, 0x7085, 0x7086, 0x7094, 0x7095, 0x7096, 0x7097, 0x7098, 0x709b, 0x70a4, 0x70ab, 0x70b0, 0x70b1, 0x70b4, 0x70b7, 0x70ca, 0x70d1, 0x70d3, 0x70d4, 0x70d5, 0x70d6, 0x70d8, 0x70dc, 0x70e4, 0x70fa, 0x7103, 0x7104, 0x7105, 0x7106, 0x7107, 0x710b, 0x710c, 0x710f, 0x711e, 0x7120, 0x712b, 0x712d, 0x712f, 0x7130, 0x7131, 0x7138, 0x7141, 0x7145, 0x7146, 0x7147, 0x714a, 0x714b, 0x7150, 0x7152, 0x7157, 0x715a, 0x715c, 0x715e, 0x7160, /* 0x8f 0xca: 0xa1 - 0xfe */ 0x7168, 0x7179, 0x7180, 0x7185, 0x7187, 0x718c, 0x7192, 0x719a, 0x719b, 0x71a0, 0x71a2, 0x71af, 0x71b0, 0x71b2, 0x71b3, 0x71ba, 0x71bf, 0x71c0, 0x71c1, 0x71c4, 0x71cb, 0x71cc, 0x71d3, 0x71d6, 0x71d9, 0x71da, 0x71dc, 0x71f8, 0x71fe, 0x7200, 0x7207, 0x7208, 0x7209, 0x7213, 0x7217, 0x721a, 0x721d, 0x721f, 0x7224, 0x722b, 0x722f, 0x7234, 0x7238, 0x7239, 0x7241, 0x7242, 0x7243, 0x7245, 0x724e, 0x724f, 0x7250, 0x7253, 0x7255, 0x7256, 0x725a, 0x725c, 0x725e, 0x7260, 0x7263, 0x7268, 0x726b, 0x726e, 0x726f, 0x7271, 0x7277, 0x7278, 0x727b, 0x727c, 0x727f, 0x7284, 0x7289, 0x728d, 0x728e, 0x7293, 0x729b, 0x72a8, 0x72ad, 0x72ae, 0x72b1, 0x72b4, 0x72be, 0x72c1, 0x72c7, 0x72c9, 0x72cc, 0x72d5, 0x72d6, 0x72d8, 0x72df, 0x72e5, 0x72f3, 0x72f4, 0x72fa, 0x72fb, /* 0x8f 0xcb: 0xa1 - 0xfe */ 0x72fe, 0x7302, 0x7304, 0x7305, 0x7307, 0x730b, 0x730d, 0x7312, 0x7313, 0x7318, 0x7319, 0x731e, 0x7322, 0x7324, 0x7327, 0x7328, 0x732c, 0x7331, 0x7332, 0x7335, 0x733a, 0x733b, 0x733d, 0x7343, 0x734d, 0x7350, 0x7352, 0x7356, 0x7358, 0x735d, 0x735e, 0x735f, 0x7360, 0x7366, 0x7367, 0x7369, 0x736b, 0x736c, 0x736e, 0x736f, 0x7371, 0x7377, 0x7379, 0x737c, 0x7380, 0x7381, 0x7383, 0x7385, 0x7386, 0x738e, 0x7390, 0x7393, 0x7395, 0x7397, 0x7398, 0x739c, 0x739e, 0x739f, 0x73a0, 0x73a2, 0x73a5, 0x73a6, 0x73aa, 0x73ab, 0x73ad, 0x73b5, 0x73b7, 0x73b9, 0x73bc, 0x73bd, 0x73bf, 0x73c5, 0x73c6, 0x73c9, 0x73cb, 0x73cc, 0x73cf, 0x73d2, 0x73d3, 0x73d6, 0x73d9, 0x73dd, 0x73e1, 0x73e3, 0x73e6, 0x73e7, 0x73e9, 0x73f4, 0x73f5, 0x73f7, 0x73f9, 0x73fa, 0x73fb, 0x73fd, /* 0x8f 0xcc: 0xa1 - 0xfe */ 0x73ff, 0x7400, 0x7401, 0x7404, 0x7407, 0x740a, 0x7411, 0x741a, 0x741b, 0x7424, 0x7426, 0x7428, 0x7429, 0x742a, 0x742b, 0x742c, 0x742d, 0x742e, 0x742f, 0x7430, 0x7431, 0x7439, 0x7440, 0x7443, 0x7444, 0x7446, 0x7447, 0x744b, 0x744d, 0x7451, 0x7452, 0x7457, 0x745d, 0x7462, 0x7466, 0x7467, 0x7468, 0x746b, 0x746d, 0x746e, 0x7471, 0x7472, 0x7480, 0x7481, 0x7485, 0x7486, 0x7487, 0x7489, 0x748f, 0x7490, 0x7491, 0x7492, 0x7498, 0x7499, 0x749a, 0x749c, 0x749f, 0x74a0, 0x74a1, 0x74a3, 0x74a6, 0x74a8, 0x74a9, 0x74aa, 0x74ab, 0x74ae, 0x74af, 0x74b1, 0x74b2, 0x74b5, 0x74b9, 0x74bb, 0x74bf, 0x74c8, 0x74c9, 0x74cc, 0x74d0, 0x74d3, 0x74d8, 0x74da, 0x74db, 0x74de, 0x74df, 0x74e4, 0x74e8, 0x74ea, 0x74eb, 0x74ef, 0x74f4, 0x74fa, 0x74fb, 0x74fc, 0x74ff, 0x7506, /* 0x8f 0xcd: 0xa1 - 0xfe */ 0x7512, 0x7516, 0x7517, 0x7520, 0x7521, 0x7524, 0x7527, 0x7529, 0x752a, 0x752f, 0x7536, 0x7539, 0x753d, 0x753e, 0x753f, 0x7540, 0x7543, 0x7547, 0x7548, 0x754e, 0x7550, 0x7552, 0x7557, 0x755e, 0x755f, 0x7561, 0x756f, 0x7571, 0x7579, 0x757a, 0x757b, 0x757c, 0x757d, 0x757e, 0x7581, 0x7585, 0x7590, 0x7592, 0x7593, 0x7595, 0x7599, 0x759c, 0x75a2, 0x75a4, 0x75b4, 0x75ba, 0x75bf, 0x75c0, 0x75c1, 0x75c4, 0x75c6, 0x75cc, 0x75ce, 0x75cf, 0x75d7, 0x75dc, 0x75df, 0x75e0, 0x75e1, 0x75e4, 0x75e7, 0x75ec, 0x75ee, 0x75ef, 0x75f1, 0x75f9, 0x7600, 0x7602, 0x7603, 0x7604, 0x7607, 0x7608, 0x760a, 0x760c, 0x760f, 0x7612, 0x7613, 0x7615, 0x7616, 0x7619, 0x761b, 0x761c, 0x761d, 0x761e, 0x7623, 0x7625, 0x7626, 0x7629, 0x762d, 0x7632, 0x7633, 0x7635, 0x7638, 0x7639, /* 0x8f 0xce: 0xa1 - 0xfe */ 0x763a, 0x763c, 0x764a, 0x7640, 0x7641, 0x7643, 0x7644, 0x7645, 0x7649, 0x764b, 0x7655, 0x7659, 0x765f, 0x7664, 0x7665, 0x766d, 0x766e, 0x766f, 0x7671, 0x7674, 0x7681, 0x7685, 0x768c, 0x768d, 0x7695, 0x769b, 0x769c, 0x769d, 0x769f, 0x76a0, 0x76a2, 0x76a3, 0x76a4, 0x76a5, 0x76a6, 0x76a7, 0x76a8, 0x76aa, 0x76ad, 0x76bd, 0x76c1, 0x76c5, 0x76c9, 0x76cb, 0x76cc, 0x76ce, 0x76d4, 0x76d9, 0x76e0, 0x76e6, 0x76e8, 0x76ec, 0x76f0, 0x76f1, 0x76f6, 0x76f9, 0x76fc, 0x7700, 0x7706, 0x770a, 0x770e, 0x7712, 0x7714, 0x7715, 0x7717, 0x7719, 0x771a, 0x771c, 0x7722, 0x7728, 0x772d, 0x772e, 0x772f, 0x7734, 0x7735, 0x7736, 0x7739, 0x773d, 0x773e, 0x7742, 0x7745, 0x7746, 0x774a, 0x774d, 0x774e, 0x774f, 0x7752, 0x7756, 0x7757, 0x775c, 0x775e, 0x775f, 0x7760, 0x7762, /* 0x8f 0xcf: 0xa1 - 0xfe */ 0x7764, 0x7767, 0x776a, 0x776c, 0x7770, 0x7772, 0x7773, 0x7774, 0x777a, 0x777d, 0x7780, 0x7784, 0x778c, 0x778d, 0x7794, 0x7795, 0x7796, 0x779a, 0x779f, 0x77a2, 0x77a7, 0x77aa, 0x77ae, 0x77af, 0x77b1, 0x77b5, 0x77be, 0x77c3, 0x77c9, 0x77d1, 0x77d2, 0x77d5, 0x77d9, 0x77de, 0x77df, 0x77e0, 0x77e4, 0x77e6, 0x77ea, 0x77ec, 0x77f0, 0x77f1, 0x77f4, 0x77f8, 0x77fb, 0x7805, 0x7806, 0x7809, 0x780d, 0x780e, 0x7811, 0x781d, 0x7821, 0x7822, 0x7823, 0x782d, 0x782e, 0x7830, 0x7835, 0x7837, 0x7843, 0x7844, 0x7847, 0x7848, 0x784c, 0x784e, 0x7852, 0x785c, 0x785e, 0x7860, 0x7861, 0x7863, 0x7864, 0x7868, 0x786a, 0x786e, 0x787a, 0x787e, 0x788a, 0x788f, 0x7894, 0x7898, 0x78a1, 0x789d, 0x789e, 0x789f, 0x78a4, 0x78a8, 0x78ac, 0x78ad, 0x78b0, 0x78b1, 0x78b2, 0x78b3, /* 0x8f 0xd0: 0xa1 - 0xfe */ 0x78bb, 0x78bd, 0x78bf, 0x78c7, 0x78c8, 0x78c9, 0x78cc, 0x78ce, 0x78d2, 0x78d3, 0x78d5, 0x78d6, 0x78e4, 0x78db, 0x78df, 0x78e0, 0x78e1, 0x78e6, 0x78ea, 0x78f2, 0x78f3, 0x7900, 0x78f6, 0x78f7, 0x78fa, 0x78fb, 0x78ff, 0x7906, 0x790c, 0x7910, 0x791a, 0x791c, 0x791e, 0x791f, 0x7920, 0x7925, 0x7927, 0x7929, 0x792d, 0x7931, 0x7934, 0x7935, 0x793b, 0x793d, 0x793f, 0x7944, 0x7945, 0x7946, 0x794a, 0x794b, 0x794f, 0x7951, 0x7954, 0x7958, 0x795b, 0x795c, 0x7967, 0x7969, 0x796b, 0x7972, 0x7979, 0x797b, 0x797c, 0x797e, 0x798b, 0x798c, 0x7991, 0x7993, 0x7994, 0x7995, 0x7996, 0x7998, 0x799b, 0x799c, 0x79a1, 0x79a8, 0x79a9, 0x79ab, 0x79af, 0x79b1, 0x79b4, 0x79b8, 0x79bb, 0x79c2, 0x79c4, 0x79c7, 0x79c8, 0x79ca, 0x79cf, 0x79d4, 0x79d6, 0x79da, 0x79dd, 0x79de, /* 0x8f 0xd1: 0xa1 - 0xfe */ 0x79e0, 0x79e2, 0x79e5, 0x79ea, 0x79eb, 0x79ed, 0x79f1, 0x79f8, 0x79fc, 0x7a02, 0x7a03, 0x7a07, 0x7a09, 0x7a0a, 0x7a0c, 0x7a11, 0x7a15, 0x7a1b, 0x7a1e, 0x7a21, 0x7a27, 0x7a2b, 0x7a2d, 0x7a2f, 0x7a30, 0x7a34, 0x7a35, 0x7a38, 0x7a39, 0x7a3a, 0x7a44, 0x7a45, 0x7a47, 0x7a48, 0x7a4c, 0x7a55, 0x7a56, 0x7a59, 0x7a5c, 0x7a5d, 0x7a5f, 0x7a60, 0x7a65, 0x7a67, 0x7a6a, 0x7a6d, 0x7a75, 0x7a78, 0x7a7e, 0x7a80, 0x7a82, 0x7a85, 0x7a86, 0x7a8a, 0x7a8b, 0x7a90, 0x7a91, 0x7a94, 0x7a9e, 0x7aa0, 0x7aa3, 0x7aac, 0x7ab3, 0x7ab5, 0x7ab9, 0x7abb, 0x7abc, 0x7ac6, 0x7ac9, 0x7acc, 0x7ace, 0x7ad1, 0x7adb, 0x7ae8, 0x7ae9, 0x7aeb, 0x7aec, 0x7af1, 0x7af4, 0x7afb, 0x7afd, 0x7afe, 0x7b07, 0x7b14, 0x7b1f, 0x7b23, 0x7b27, 0x7b29, 0x7b2a, 0x7b2b, 0x7b2d, 0x7b2e, 0x7b2f, 0x7b30, /* 0x8f 0xd2: 0xa1 - 0xfe */ 0x7b31, 0x7b34, 0x7b3d, 0x7b3f, 0x7b40, 0x7b41, 0x7b47, 0x7b4e, 0x7b55, 0x7b60, 0x7b64, 0x7b66, 0x7b69, 0x7b6a, 0x7b6d, 0x7b6f, 0x7b72, 0x7b73, 0x7b77, 0x7b84, 0x7b89, 0x7b8e, 0x7b90, 0x7b91, 0x7b96, 0x7b9b, 0x7b9e, 0x7ba0, 0x7ba5, 0x7bac, 0x7baf, 0x7bb0, 0x7bb2, 0x7bb5, 0x7bb6, 0x7bba, 0x7bbb, 0x7bbc, 0x7bbd, 0x7bc2, 0x7bc5, 0x7bc8, 0x7bca, 0x7bd4, 0x7bd6, 0x7bd7, 0x7bd9, 0x7bda, 0x7bdb, 0x7be8, 0x7bea, 0x7bf2, 0x7bf4, 0x7bf5, 0x7bf8, 0x7bf9, 0x7bfa, 0x7bfc, 0x7bfe, 0x7c01, 0x7c02, 0x7c03, 0x7c04, 0x7c06, 0x7c09, 0x7c0b, 0x7c0c, 0x7c0e, 0x7c0f, 0x7c19, 0x7c1b, 0x7c20, 0x7c25, 0x7c26, 0x7c28, 0x7c2c, 0x7c31, 0x7c33, 0x7c34, 0x7c36, 0x7c39, 0x7c3a, 0x7c46, 0x7c4a, 0x7c55, 0x7c51, 0x7c52, 0x7c53, 0x7c59, 0x7c5a, 0x7c5b, 0x7c5c, 0x7c5d, 0x7c5e, /* 0x8f 0xd3: 0xa1 - 0xfe */ 0x7c61, 0x7c63, 0x7c67, 0x7c69, 0x7c6d, 0x7c6e, 0x7c70, 0x7c72, 0x7c79, 0x7c7c, 0x7c7d, 0x7c86, 0x7c87, 0x7c8f, 0x7c94, 0x7c9e, 0x7ca0, 0x7ca6, 0x7cb0, 0x7cb6, 0x7cb7, 0x7cba, 0x7cbb, 0x7cbc, 0x7cbf, 0x7cc4, 0x7cc7, 0x7cc8, 0x7cc9, 0x7ccd, 0x7ccf, 0x7cd3, 0x7cd4, 0x7cd5, 0x7cd7, 0x7cd9, 0x7cda, 0x7cdd, 0x7ce6, 0x7ce9, 0x7ceb, 0x7cf5, 0x7d03, 0x7d07, 0x7d08, 0x7d09, 0x7d0f, 0x7d11, 0x7d12, 0x7d13, 0x7d16, 0x7d1d, 0x7d1e, 0x7d23, 0x7d26, 0x7d2a, 0x7d2d, 0x7d31, 0x7d3c, 0x7d3d, 0x7d3e, 0x7d40, 0x7d41, 0x7d47, 0x7d48, 0x7d4d, 0x7d51, 0x7d53, 0x7d57, 0x7d59, 0x7d5a, 0x7d5c, 0x7d5d, 0x7d65, 0x7d67, 0x7d6a, 0x7d70, 0x7d78, 0x7d7a, 0x7d7b, 0x7d7f, 0x7d81, 0x7d82, 0x7d83, 0x7d85, 0x7d86, 0x7d88, 0x7d8b, 0x7d8c, 0x7d8d, 0x7d91, 0x7d96, 0x7d97, 0x7d9d, /* 0x8f 0xd4: 0xa1 - 0xfe */ 0x7d9e, 0x7da6, 0x7da7, 0x7daa, 0x7db3, 0x7db6, 0x7db7, 0x7db9, 0x7dc2, 0x7dc3, 0x7dc4, 0x7dc5, 0x7dc6, 0x7dcc, 0x7dcd, 0x7dce, 0x7dd7, 0x7dd9, 0x7e00, 0x7de2, 0x7de5, 0x7de6, 0x7dea, 0x7deb, 0x7ded, 0x7df1, 0x7df5, 0x7df6, 0x7df9, 0x7dfa, 0x7e08, 0x7e10, 0x7e11, 0x7e15, 0x7e17, 0x7e1c, 0x7e1d, 0x7e20, 0x7e27, 0x7e28, 0x7e2c, 0x7e2d, 0x7e2f, 0x7e33, 0x7e36, 0x7e3f, 0x7e44, 0x7e45, 0x7e47, 0x7e4e, 0x7e50, 0x7e52, 0x7e58, 0x7e5f, 0x7e61, 0x7e62, 0x7e65, 0x7e6b, 0x7e6e, 0x7e6f, 0x7e73, 0x7e78, 0x7e7e, 0x7e81, 0x7e86, 0x7e87, 0x7e8a, 0x7e8d, 0x7e91, 0x7e95, 0x7e98, 0x7e9a, 0x7e9d, 0x7e9e, 0x7f3c, 0x7f3b, 0x7f3d, 0x7f3e, 0x7f3f, 0x7f43, 0x7f44, 0x7f47, 0x7f4f, 0x7f52, 0x7f53, 0x7f5b, 0x7f5c, 0x7f5d, 0x7f61, 0x7f63, 0x7f64, 0x7f65, 0x7f66, 0x7f6d, /* 0x8f 0xd5: 0xa1 - 0xfe */ 0x7f71, 0x7f7d, 0x7f7e, 0x7f7f, 0x7f80, 0x7f8b, 0x7f8d, 0x7f8f, 0x7f90, 0x7f91, 0x7f96, 0x7f97, 0x7f9c, 0x7fa1, 0x7fa2, 0x7fa6, 0x7faa, 0x7fad, 0x7fb4, 0x7fbc, 0x7fbf, 0x7fc0, 0x7fc3, 0x7fc8, 0x7fce, 0x7fcf, 0x7fdb, 0x7fdf, 0x7fe3, 0x7fe5, 0x7fe8, 0x7fec, 0x7fee, 0x7fef, 0x7ff2, 0x7ffa, 0x7ffd, 0x7ffe, 0x7fff, 0x8007, 0x8008, 0x800a, 0x800d, 0x800e, 0x800f, 0x8011, 0x8013, 0x8014, 0x8016, 0x801d, 0x801e, 0x801f, 0x8020, 0x8024, 0x8026, 0x802c, 0x802e, 0x8030, 0x8034, 0x8035, 0x8037, 0x8039, 0x803a, 0x803c, 0x803e, 0x8040, 0x8044, 0x8060, 0x8064, 0x8066, 0x806d, 0x8071, 0x8075, 0x8081, 0x8088, 0x808e, 0x809c, 0x809e, 0x80a6, 0x80a7, 0x80ab, 0x80b8, 0x80b9, 0x80c8, 0x80cd, 0x80cf, 0x80d2, 0x80d4, 0x80d5, 0x80d7, 0x80d8, 0x80e0, 0x80ed, 0x80ee, /* 0x8f 0xd6: 0xa1 - 0xfe */ 0x80f0, 0x80f2, 0x80f3, 0x80f6, 0x80f9, 0x80fa, 0x80fe, 0x8103, 0x810b, 0x8116, 0x8117, 0x8118, 0x811c, 0x811e, 0x8120, 0x8124, 0x8127, 0x812c, 0x8130, 0x8135, 0x813a, 0x813c, 0x8145, 0x8147, 0x814a, 0x814c, 0x8152, 0x8157, 0x8160, 0x8161, 0x8167, 0x8168, 0x8169, 0x816d, 0x816f, 0x8177, 0x8181, 0x8190, 0x8184, 0x8185, 0x8186, 0x818b, 0x818e, 0x8196, 0x8198, 0x819b, 0x819e, 0x81a2, 0x81ae, 0x81b2, 0x81b4, 0x81bb, 0x81cb, 0x81c3, 0x81c5, 0x81ca, 0x81ce, 0x81cf, 0x81d5, 0x81d7, 0x81db, 0x81dd, 0x81de, 0x81e1, 0x81e4, 0x81eb, 0x81ec, 0x81f0, 0x81f1, 0x81f2, 0x81f5, 0x81f6, 0x81f8, 0x81f9, 0x81fd, 0x81ff, 0x8200, 0x8203, 0x820f, 0x8213, 0x8214, 0x8219, 0x821a, 0x821d, 0x8221, 0x8222, 0x8228, 0x8232, 0x8234, 0x823a, 0x8243, 0x8244, 0x8245, 0x8246, /* 0x8f 0xd7: 0xa1 - 0xfe */ 0x824b, 0x824e, 0x824f, 0x8251, 0x8256, 0x825c, 0x8260, 0x8263, 0x8267, 0x826d, 0x8274, 0x827b, 0x827d, 0x827f, 0x8280, 0x8281, 0x8283, 0x8284, 0x8287, 0x8289, 0x828a, 0x828e, 0x8291, 0x8294, 0x8296, 0x8298, 0x829a, 0x829b, 0x82a0, 0x82a1, 0x82a3, 0x82a4, 0x82a7, 0x82a8, 0x82a9, 0x82aa, 0x82ae, 0x82b0, 0x82b2, 0x82b4, 0x82b7, 0x82ba, 0x82bc, 0x82be, 0x82bf, 0x82c6, 0x82d0, 0x82d5, 0x82da, 0x82e0, 0x82e2, 0x82e4, 0x82e8, 0x82ea, 0x82ed, 0x82ef, 0x82f6, 0x82f7, 0x82fd, 0x82fe, 0x8300, 0x8301, 0x8307, 0x8308, 0x830a, 0x830b, 0x8354, 0x831b, 0x831d, 0x831e, 0x831f, 0x8321, 0x8322, 0x832c, 0x832d, 0x832e, 0x8330, 0x8333, 0x8337, 0x833a, 0x833c, 0x833d, 0x8342, 0x8343, 0x8344, 0x8347, 0x834d, 0x834e, 0x8351, 0x8355, 0x8356, 0x8357, 0x8370, 0x8378, /* 0x8f 0xd8: 0xa1 - 0xfe */ 0x837d, 0x837f, 0x8380, 0x8382, 0x8384, 0x8386, 0x838d, 0x8392, 0x8394, 0x8395, 0x8398, 0x8399, 0x839b, 0x839c, 0x839d, 0x83a6, 0x83a7, 0x83a9, 0x83ac, 0x83be, 0x83bf, 0x83c0, 0x83c7, 0x83c9, 0x83cf, 0x83d0, 0x83d1, 0x83d4, 0x83dd, 0x8353, 0x83e8, 0x83ea, 0x83f6, 0x83f8, 0x83f9, 0x83fc, 0x8401, 0x8406, 0x840a, 0x840f, 0x8411, 0x8415, 0x8419, 0x83ad, 0x842f, 0x8439, 0x8445, 0x8447, 0x8448, 0x844a, 0x844d, 0x844f, 0x8451, 0x8452, 0x8456, 0x8458, 0x8459, 0x845a, 0x845c, 0x8460, 0x8464, 0x8465, 0x8467, 0x846a, 0x8470, 0x8473, 0x8474, 0x8476, 0x8478, 0x847c, 0x847d, 0x8481, 0x8485, 0x8492, 0x8493, 0x8495, 0x849e, 0x84a6, 0x84a8, 0x84a9, 0x84aa, 0x84af, 0x84b1, 0x84b4, 0x84ba, 0x84bd, 0x84be, 0x84c0, 0x84c2, 0x84c7, 0x84c8, 0x84cc, 0x84cf, 0x84d3, /* 0x8f 0xd9: 0xa1 - 0xfe */ 0x84dc, 0x84e7, 0x84ea, 0x84ef, 0x84f0, 0x84f1, 0x84f2, 0x84f7, 0x8532, 0x84fa, 0x84fb, 0x84fd, 0x8502, 0x8503, 0x8507, 0x850c, 0x850e, 0x8510, 0x851c, 0x851e, 0x8522, 0x8523, 0x8524, 0x8525, 0x8527, 0x852a, 0x852b, 0x852f, 0x8533, 0x8534, 0x8536, 0x853f, 0x8546, 0x854f, 0x8550, 0x8551, 0x8552, 0x8553, 0x8556, 0x8559, 0x855c, 0x855d, 0x855e, 0x855f, 0x8560, 0x8561, 0x8562, 0x8564, 0x856b, 0x856f, 0x8579, 0x857a, 0x857b, 0x857d, 0x857f, 0x8581, 0x8585, 0x8586, 0x8589, 0x858b, 0x858c, 0x858f, 0x8593, 0x8598, 0x859d, 0x859f, 0x85a0, 0x85a2, 0x85a5, 0x85a7, 0x85b4, 0x85b6, 0x85b7, 0x85b8, 0x85bc, 0x85bd, 0x85be, 0x85bf, 0x85c2, 0x85c7, 0x85ca, 0x85cb, 0x85ce, 0x85ad, 0x85d8, 0x85da, 0x85df, 0x85e0, 0x85e6, 0x85e8, 0x85ed, 0x85f3, 0x85f6, 0x85fc, /* 0x8f 0xda: 0xa1 - 0xfe */ 0x85ff, 0x8600, 0x8604, 0x8605, 0x860d, 0x860e, 0x8610, 0x8611, 0x8612, 0x8618, 0x8619, 0x861b, 0x861e, 0x8621, 0x8627, 0x8629, 0x8636, 0x8638, 0x863a, 0x863c, 0x863d, 0x8640, 0x8642, 0x8646, 0x8652, 0x8653, 0x8656, 0x8657, 0x8658, 0x8659, 0x865d, 0x8660, 0x8661, 0x8662, 0x8663, 0x8664, 0x8669, 0x866c, 0x866f, 0x8675, 0x8676, 0x8677, 0x867a, 0x868d, 0x8691, 0x8696, 0x8698, 0x869a, 0x869c, 0x86a1, 0x86a6, 0x86a7, 0x86a8, 0x86ad, 0x86b1, 0x86b3, 0x86b4, 0x86b5, 0x86b7, 0x86b8, 0x86b9, 0x86bf, 0x86c0, 0x86c1, 0x86c3, 0x86c5, 0x86d1, 0x86d2, 0x86d5, 0x86d7, 0x86da, 0x86dc, 0x86e0, 0x86e3, 0x86e5, 0x86e7, 0x8688, 0x86fa, 0x86fc, 0x86fd, 0x8704, 0x8705, 0x8707, 0x870b, 0x870e, 0x870f, 0x8710, 0x8713, 0x8714, 0x8719, 0x871e, 0x871f, 0x8721, 0x8723, /* 0x8f 0xdb: 0xa1 - 0xfe */ 0x8728, 0x872e, 0x872f, 0x8731, 0x8732, 0x8739, 0x873a, 0x873c, 0x873d, 0x873e, 0x8740, 0x8743, 0x8745, 0x874d, 0x8758, 0x875d, 0x8761, 0x8764, 0x8765, 0x876f, 0x8771, 0x8772, 0x877b, 0x8783, 0x8784, 0x8785, 0x8786, 0x8787, 0x8788, 0x8789, 0x878b, 0x878c, 0x8790, 0x8793, 0x8795, 0x8797, 0x8798, 0x8799, 0x879e, 0x87a0, 0x87a3, 0x87a7, 0x87ac, 0x87ad, 0x87ae, 0x87b1, 0x87b5, 0x87be, 0x87bf, 0x87c1, 0x87c8, 0x87c9, 0x87ca, 0x87ce, 0x87d5, 0x87d6, 0x87d9, 0x87da, 0x87dc, 0x87df, 0x87e2, 0x87e3, 0x87e4, 0x87ea, 0x87eb, 0x87ed, 0x87f1, 0x87f3, 0x87f8, 0x87fa, 0x87ff, 0x8801, 0x8803, 0x8806, 0x8809, 0x880a, 0x880b, 0x8810, 0x8819, 0x8812, 0x8813, 0x8814, 0x8818, 0x881a, 0x881b, 0x881c, 0x881e, 0x881f, 0x8828, 0x882d, 0x882e, 0x8830, 0x8832, 0x8835, /* 0x8f 0xdc: 0xa1 - 0xfe */ 0x883a, 0x883c, 0x8841, 0x8843, 0x8845, 0x8848, 0x8849, 0x884a, 0x884b, 0x884e, 0x8851, 0x8855, 0x8856, 0x8858, 0x885a, 0x885c, 0x885f, 0x8860, 0x8864, 0x8869, 0x8871, 0x8879, 0x887b, 0x8880, 0x8898, 0x889a, 0x889b, 0x889c, 0x889f, 0x88a0, 0x88a8, 0x88aa, 0x88ba, 0x88bd, 0x88be, 0x88c0, 0x88ca, 0x88cb, 0x88cc, 0x88cd, 0x88ce, 0x88d1, 0x88d2, 0x88d3, 0x88db, 0x88de, 0x88e7, 0x88ef, 0x88f0, 0x88f1, 0x88f5, 0x88f7, 0x8901, 0x8906, 0x890d, 0x890e, 0x890f, 0x8915, 0x8916, 0x8918, 0x8919, 0x891a, 0x891c, 0x8920, 0x8926, 0x8927, 0x8928, 0x8930, 0x8931, 0x8932, 0x8935, 0x8939, 0x893a, 0x893e, 0x8940, 0x8942, 0x8945, 0x8946, 0x8949, 0x894f, 0x8952, 0x8957, 0x895a, 0x895b, 0x895c, 0x8961, 0x8962, 0x8963, 0x896b, 0x896e, 0x8970, 0x8973, 0x8975, 0x897a, /* 0x8f 0xdd: 0xa1 - 0xfe */ 0x897b, 0x897c, 0x897d, 0x8989, 0x898d, 0x8990, 0x8994, 0x8995, 0x899b, 0x899c, 0x899f, 0x89a0, 0x89a5, 0x89b0, 0x89b4, 0x89b5, 0x89b6, 0x89b7, 0x89bc, 0x89d4, 0x89d5, 0x89d6, 0x89d7, 0x89d8, 0x89e5, 0x89e9, 0x89eb, 0x89ed, 0x89f1, 0x89f3, 0x89f6, 0x89f9, 0x89fd, 0x89ff, 0x8a04, 0x8a05, 0x8a07, 0x8a0f, 0x8a11, 0x8a12, 0x8a14, 0x8a15, 0x8a1e, 0x8a20, 0x8a22, 0x8a24, 0x8a26, 0x8a2b, 0x8a2c, 0x8a2f, 0x8a35, 0x8a37, 0x8a3d, 0x8a3e, 0x8a40, 0x8a43, 0x8a45, 0x8a47, 0x8a49, 0x8a4d, 0x8a4e, 0x8a53, 0x8a56, 0x8a57, 0x8a58, 0x8a5c, 0x8a5d, 0x8a61, 0x8a65, 0x8a67, 0x8a75, 0x8a76, 0x8a77, 0x8a79, 0x8a7a, 0x8a7b, 0x8a7e, 0x8a7f, 0x8a80, 0x8a83, 0x8a86, 0x8a8b, 0x8a8f, 0x8a90, 0x8a92, 0x8a96, 0x8a97, 0x8a99, 0x8a9f, 0x8aa7, 0x8aa9, 0x8aae, 0x8aaf, 0x8ab3, /* 0x8f 0xde: 0xa1 - 0xfe */ 0x8ab6, 0x8ab7, 0x8abb, 0x8abe, 0x8ac3, 0x8ac6, 0x8ac8, 0x8ac9, 0x8aca, 0x8ad1, 0x8ad3, 0x8ad4, 0x8ad5, 0x8ad7, 0x8add, 0x8adf, 0x8aec, 0x8af0, 0x8af4, 0x8af5, 0x8af6, 0x8afc, 0x8aff, 0x8b05, 0x8b06, 0x8b0b, 0x8b11, 0x8b1c, 0x8b1e, 0x8b1f, 0x8b0a, 0x8b2d, 0x8b30, 0x8b37, 0x8b3c, 0x8b42, 0x8b43, 0x8b44, 0x8b45, 0x8b46, 0x8b48, 0x8b52, 0x8b53, 0x8b54, 0x8b59, 0x8b4d, 0x8b5e, 0x8b63, 0x8b6d, 0x8b76, 0x8b78, 0x8b79, 0x8b7c, 0x8b7e, 0x8b81, 0x8b84, 0x8b85, 0x8b8b, 0x8b8d, 0x8b8f, 0x8b94, 0x8b95, 0x8b9c, 0x8b9e, 0x8b9f, 0x8c38, 0x8c39, 0x8c3d, 0x8c3e, 0x8c45, 0x8c47, 0x8c49, 0x8c4b, 0x8c4f, 0x8c51, 0x8c53, 0x8c54, 0x8c57, 0x8c58, 0x8c5b, 0x8c5d, 0x8c59, 0x8c63, 0x8c64, 0x8c66, 0x8c68, 0x8c69, 0x8c6d, 0x8c73, 0x8c75, 0x8c76, 0x8c7b, 0x8c7e, 0x8c86, /* 0x8f 0xdf: 0xa1 - 0xfe */ 0x8c87, 0x8c8b, 0x8c90, 0x8c92, 0x8c93, 0x8c99, 0x8c9b, 0x8c9c, 0x8ca4, 0x8cb9, 0x8cba, 0x8cc5, 0x8cc6, 0x8cc9, 0x8ccb, 0x8ccf, 0x8cd6, 0x8cd5, 0x8cd9, 0x8cdd, 0x8ce1, 0x8ce8, 0x8cec, 0x8cef, 0x8cf0, 0x8cf2, 0x8cf5, 0x8cf7, 0x8cf8, 0x8cfe, 0x8cff, 0x8d01, 0x8d03, 0x8d09, 0x8d12, 0x8d17, 0x8d1b, 0x8d65, 0x8d69, 0x8d6c, 0x8d6e, 0x8d7f, 0x8d82, 0x8d84, 0x8d88, 0x8d8d, 0x8d90, 0x8d91, 0x8d95, 0x8d9e, 0x8d9f, 0x8da0, 0x8da6, 0x8dab, 0x8dac, 0x8daf, 0x8db2, 0x8db5, 0x8db7, 0x8db9, 0x8dbb, 0x8dc0, 0x8dc5, 0x8dc6, 0x8dc7, 0x8dc8, 0x8dca, 0x8dce, 0x8dd1, 0x8dd4, 0x8dd5, 0x8dd7, 0x8dd9, 0x8de4, 0x8de5, 0x8de7, 0x8dec, 0x8df0, 0x8dbc, 0x8df1, 0x8df2, 0x8df4, 0x8dfd, 0x8e01, 0x8e04, 0x8e05, 0x8e06, 0x8e0b, 0x8e11, 0x8e14, 0x8e16, 0x8e20, 0x8e21, 0x8e22, /* 0x8f 0xe0: 0xa1 - 0xfe */ 0x8e23, 0x8e26, 0x8e27, 0x8e31, 0x8e33, 0x8e36, 0x8e37, 0x8e38, 0x8e39, 0x8e3d, 0x8e40, 0x8e41, 0x8e4b, 0x8e4d, 0x8e4e, 0x8e4f, 0x8e54, 0x8e5b, 0x8e5c, 0x8e5d, 0x8e5e, 0x8e61, 0x8e62, 0x8e69, 0x8e6c, 0x8e6d, 0x8e6f, 0x8e70, 0x8e71, 0x8e79, 0x8e7a, 0x8e7b, 0x8e82, 0x8e83, 0x8e89, 0x8e90, 0x8e92, 0x8e95, 0x8e9a, 0x8e9b, 0x8e9d, 0x8e9e, 0x8ea2, 0x8ea7, 0x8ea9, 0x8ead, 0x8eae, 0x8eb3, 0x8eb5, 0x8eba, 0x8ebb, 0x8ec0, 0x8ec1, 0x8ec3, 0x8ec4, 0x8ec7, 0x8ecf, 0x8ed1, 0x8ed4, 0x8edc, 0x8ee8, 0x8eee, 0x8ef0, 0x8ef1, 0x8ef7, 0x8ef9, 0x8efa, 0x8eed, 0x8f00, 0x8f02, 0x8f07, 0x8f08, 0x8f0f, 0x8f10, 0x8f16, 0x8f17, 0x8f18, 0x8f1e, 0x8f20, 0x8f21, 0x8f23, 0x8f25, 0x8f27, 0x8f28, 0x8f2c, 0x8f2d, 0x8f2e, 0x8f34, 0x8f35, 0x8f36, 0x8f37, 0x8f3a, 0x8f40, 0x8f41, /* 0x8f 0xe1: 0xa1 - 0xfe */ 0x8f43, 0x8f47, 0x8f4f, 0x8f51, 0x8f52, 0x8f53, 0x8f54, 0x8f55, 0x8f58, 0x8f5d, 0x8f5e, 0x8f65, 0x8f9d, 0x8fa0, 0x8fa1, 0x8fa4, 0x8fa5, 0x8fa6, 0x8fb5, 0x8fb6, 0x8fb8, 0x8fbe, 0x8fc0, 0x8fc1, 0x8fc6, 0x8fca, 0x8fcb, 0x8fcd, 0x8fd0, 0x8fd2, 0x8fd3, 0x8fd5, 0x8fe0, 0x8fe3, 0x8fe4, 0x8fe8, 0x8fee, 0x8ff1, 0x8ff5, 0x8ff6, 0x8ffb, 0x8ffe, 0x9002, 0x9004, 0x9008, 0x900c, 0x9018, 0x901b, 0x9028, 0x9029, 0x902f, 0x902a, 0x902c, 0x902d, 0x9033, 0x9034, 0x9037, 0x903f, 0x9043, 0x9044, 0x904c, 0x905b, 0x905d, 0x9062, 0x9066, 0x9067, 0x906c, 0x9070, 0x9074, 0x9079, 0x9085, 0x9088, 0x908b, 0x908c, 0x908e, 0x9090, 0x9095, 0x9097, 0x9098, 0x9099, 0x909b, 0x90a0, 0x90a1, 0x90a2, 0x90a5, 0x90b0, 0x90b2, 0x90b3, 0x90b4, 0x90b6, 0x90bd, 0x90cc, 0x90be, 0x90c3, /* 0x8f 0xe2: 0xa1 - 0xfe */ 0x90c4, 0x90c5, 0x90c7, 0x90c8, 0x90d5, 0x90d7, 0x90d8, 0x90d9, 0x90dc, 0x90dd, 0x90df, 0x90e5, 0x90d2, 0x90f6, 0x90eb, 0x90ef, 0x90f0, 0x90f4, 0x90fe, 0x90ff, 0x9100, 0x9104, 0x9105, 0x9106, 0x9108, 0x910d, 0x9110, 0x9114, 0x9116, 0x9117, 0x9118, 0x911a, 0x911c, 0x911e, 0x9120, 0x9125, 0x9122, 0x9123, 0x9127, 0x9129, 0x912e, 0x912f, 0x9131, 0x9134, 0x9136, 0x9137, 0x9139, 0x913a, 0x913c, 0x913d, 0x9143, 0x9147, 0x9148, 0x914f, 0x9153, 0x9157, 0x9159, 0x915a, 0x915b, 0x9161, 0x9164, 0x9167, 0x916d, 0x9174, 0x9179, 0x917a, 0x917b, 0x9181, 0x9183, 0x9185, 0x9186, 0x918a, 0x918e, 0x9191, 0x9193, 0x9194, 0x9195, 0x9198, 0x919e, 0x91a1, 0x91a6, 0x91a8, 0x91ac, 0x91ad, 0x91ae, 0x91b0, 0x91b1, 0x91b2, 0x91b3, 0x91b6, 0x91bb, 0x91bc, 0x91bd, 0x91bf, /* 0x8f 0xe3: 0xa1 - 0xfe */ 0x91c2, 0x91c3, 0x91c5, 0x91d3, 0x91d4, 0x91d7, 0x91d9, 0x91da, 0x91de, 0x91e4, 0x91e5, 0x91e9, 0x91ea, 0x91ec, 0x91ed, 0x91ee, 0x91ef, 0x91f0, 0x91f1, 0x91f7, 0x91f9, 0x91fb, 0x91fd, 0x9200, 0x9201, 0x9204, 0x9205, 0x9206, 0x9207, 0x9209, 0x920a, 0x920c, 0x9210, 0x9212, 0x9213, 0x9216, 0x9218, 0x921c, 0x921d, 0x9223, 0x9224, 0x9225, 0x9226, 0x9228, 0x922e, 0x922f, 0x9230, 0x9233, 0x9235, 0x9236, 0x9238, 0x9239, 0x923a, 0x923c, 0x923e, 0x9240, 0x9242, 0x9243, 0x9246, 0x9247, 0x924a, 0x924d, 0x924e, 0x924f, 0x9251, 0x9258, 0x9259, 0x925c, 0x925d, 0x9260, 0x9261, 0x9265, 0x9267, 0x9268, 0x9269, 0x926e, 0x926f, 0x9270, 0x9275, 0x9276, 0x9277, 0x9278, 0x9279, 0x927b, 0x927c, 0x927d, 0x927f, 0x9288, 0x9289, 0x928a, 0x928d, 0x928e, 0x9292, 0x9297, /* 0x8f 0xe4: 0xa1 - 0xfe */ 0x9299, 0x929f, 0x92a0, 0x92a4, 0x92a5, 0x92a7, 0x92a8, 0x92ab, 0x92af, 0x92b2, 0x92b6, 0x92b8, 0x92ba, 0x92bb, 0x92bc, 0x92bd, 0x92bf, 0x92c0, 0x92c1, 0x92c2, 0x92c3, 0x92c5, 0x92c6, 0x92c7, 0x92c8, 0x92cb, 0x92cc, 0x92cd, 0x92ce, 0x92d0, 0x92d3, 0x92d5, 0x92d7, 0x92d8, 0x92d9, 0x92dc, 0x92dd, 0x92df, 0x92e0, 0x92e1, 0x92e3, 0x92e5, 0x92e7, 0x92e8, 0x92ec, 0x92ee, 0x92f0, 0x92f9, 0x92fb, 0x92ff, 0x9300, 0x9302, 0x9308, 0x930d, 0x9311, 0x9314, 0x9315, 0x931c, 0x931d, 0x931e, 0x931f, 0x9321, 0x9324, 0x9325, 0x9327, 0x9329, 0x932a, 0x9333, 0x9334, 0x9336, 0x9337, 0x9347, 0x9348, 0x9349, 0x9350, 0x9351, 0x9352, 0x9355, 0x9357, 0x9358, 0x935a, 0x935e, 0x9364, 0x9365, 0x9367, 0x9369, 0x936a, 0x936d, 0x936f, 0x9370, 0x9371, 0x9373, 0x9374, 0x9376, /* 0x8f 0xe5: 0xa1 - 0xfe */ 0x937a, 0x937d, 0x937f, 0x9380, 0x9381, 0x9382, 0x9388, 0x938a, 0x938b, 0x938d, 0x938f, 0x9392, 0x9395, 0x9398, 0x939b, 0x939e, 0x93a1, 0x93a3, 0x93a4, 0x93a6, 0x93a8, 0x93ab, 0x93b4, 0x93b5, 0x93b6, 0x93ba, 0x93a9, 0x93c1, 0x93c4, 0x93c5, 0x93c6, 0x93c7, 0x93c9, 0x93ca, 0x93cb, 0x93cc, 0x93cd, 0x93d3, 0x93d9, 0x93dc, 0x93de, 0x93df, 0x93e2, 0x93e6, 0x93e7, 0x93f9, 0x93f7, 0x93f8, 0x93fa, 0x93fb, 0x93fd, 0x9401, 0x9402, 0x9404, 0x9408, 0x9409, 0x940d, 0x940e, 0x940f, 0x9415, 0x9416, 0x9417, 0x941f, 0x942e, 0x942f, 0x9431, 0x9432, 0x9433, 0x9434, 0x943b, 0x943f, 0x943d, 0x9443, 0x9445, 0x9448, 0x944a, 0x944c, 0x9455, 0x9459, 0x945c, 0x945f, 0x9461, 0x9463, 0x9468, 0x946b, 0x946d, 0x946e, 0x946f, 0x9471, 0x9472, 0x9484, 0x9483, 0x9578, 0x9579, /* 0x8f 0xe6: 0xa1 - 0xfe */ 0x957e, 0x9584, 0x9588, 0x958c, 0x958d, 0x958e, 0x959d, 0x959e, 0x959f, 0x95a1, 0x95a6, 0x95a9, 0x95ab, 0x95ac, 0x95b4, 0x95b6, 0x95ba, 0x95bd, 0x95bf, 0x95c6, 0x95c8, 0x95c9, 0x95cb, 0x95d0, 0x95d1, 0x95d2, 0x95d3, 0x95d9, 0x95da, 0x95dd, 0x95de, 0x95df, 0x95e0, 0x95e4, 0x95e6, 0x961d, 0x961e, 0x9622, 0x9624, 0x9625, 0x9626, 0x962c, 0x9631, 0x9633, 0x9637, 0x9638, 0x9639, 0x963a, 0x963c, 0x963d, 0x9641, 0x9652, 0x9654, 0x9656, 0x9657, 0x9658, 0x9661, 0x966e, 0x9674, 0x967b, 0x967c, 0x967e, 0x967f, 0x9681, 0x9682, 0x9683, 0x9684, 0x9689, 0x9691, 0x9696, 0x969a, 0x969d, 0x969f, 0x96a4, 0x96a5, 0x96a6, 0x96a9, 0x96ae, 0x96af, 0x96b3, 0x96ba, 0x96ca, 0x96d2, 0x5db2, 0x96d8, 0x96da, 0x96dd, 0x96de, 0x96df, 0x96e9, 0x96ef, 0x96f1, 0x96fa, 0x9702, /* 0x8f 0xe7: 0xa1 - 0xfe */ 0x9703, 0x9705, 0x9709, 0x971a, 0x971b, 0x971d, 0x9721, 0x9722, 0x9723, 0x9728, 0x9731, 0x9733, 0x9741, 0x9743, 0x974a, 0x974e, 0x974f, 0x9755, 0x9757, 0x9758, 0x975a, 0x975b, 0x9763, 0x9767, 0x976a, 0x976e, 0x9773, 0x9776, 0x9777, 0x9778, 0x977b, 0x977d, 0x977f, 0x9780, 0x9789, 0x9795, 0x9796, 0x9797, 0x9799, 0x979a, 0x979e, 0x979f, 0x97a2, 0x97ac, 0x97ae, 0x97b1, 0x97b2, 0x97b5, 0x97b6, 0x97b8, 0x97b9, 0x97ba, 0x97bc, 0x97be, 0x97bf, 0x97c1, 0x97c4, 0x97c5, 0x97c7, 0x97c9, 0x97ca, 0x97cc, 0x97cd, 0x97ce, 0x97d0, 0x97d1, 0x97d4, 0x97d7, 0x97d8, 0x97d9, 0x97dd, 0x97de, 0x97e0, 0x97db, 0x97e1, 0x97e4, 0x97ef, 0x97f1, 0x97f4, 0x97f7, 0x97f8, 0x97fa, 0x9807, 0x980a, 0x9819, 0x980d, 0x980e, 0x9814, 0x9816, 0x981c, 0x981e, 0x9820, 0x9823, 0x9826, /* 0x8f 0xe8: 0xa1 - 0xfe */ 0x982b, 0x982e, 0x982f, 0x9830, 0x9832, 0x9833, 0x9835, 0x9825, 0x983e, 0x9844, 0x9847, 0x984a, 0x9851, 0x9852, 0x9853, 0x9856, 0x9857, 0x9859, 0x985a, 0x9862, 0x9863, 0x9865, 0x9866, 0x986a, 0x986c, 0x98ab, 0x98ad, 0x98ae, 0x98b0, 0x98b4, 0x98b7, 0x98b8, 0x98ba, 0x98bb, 0x98bf, 0x98c2, 0x98c5, 0x98c8, 0x98cc, 0x98e1, 0x98e3, 0x98e5, 0x98e6, 0x98e7, 0x98ea, 0x98f3, 0x98f6, 0x9902, 0x9907, 0x9908, 0x9911, 0x9915, 0x9916, 0x9917, 0x991a, 0x991b, 0x991c, 0x991f, 0x9922, 0x9926, 0x9927, 0x992b, 0x9931, 0x9932, 0x9933, 0x9934, 0x9935, 0x9939, 0x993a, 0x993b, 0x993c, 0x9940, 0x9941, 0x9946, 0x9947, 0x9948, 0x994d, 0x994e, 0x9954, 0x9958, 0x9959, 0x995b, 0x995c, 0x995e, 0x995f, 0x9960, 0x999b, 0x999d, 0x999f, 0x99a6, 0x99b0, 0x99b1, 0x99b2, 0x99b5, /* 0x8f 0xe9: 0xa1 - 0xfe */ 0x99b9, 0x99ba, 0x99bd, 0x99bf, 0x99c3, 0x99c9, 0x99d3, 0x99d4, 0x99d9, 0x99da, 0x99dc, 0x99de, 0x99e7, 0x99ea, 0x99eb, 0x99ec, 0x99f0, 0x99f4, 0x99f5, 0x99f9, 0x99fd, 0x99fe, 0x9a02, 0x9a03, 0x9a04, 0x9a0b, 0x9a0c, 0x9a10, 0x9a11, 0x9a16, 0x9a1e, 0x9a20, 0x9a22, 0x9a23, 0x9a24, 0x9a27, 0x9a2d, 0x9a2e, 0x9a33, 0x9a35, 0x9a36, 0x9a38, 0x9a47, 0x9a41, 0x9a44, 0x9a4a, 0x9a4b, 0x9a4c, 0x9a4e, 0x9a51, 0x9a54, 0x9a56, 0x9a5d, 0x9aaa, 0x9aac, 0x9aae, 0x9aaf, 0x9ab2, 0x9ab4, 0x9ab5, 0x9ab6, 0x9ab9, 0x9abb, 0x9abe, 0x9abf, 0x9ac1, 0x9ac3, 0x9ac6, 0x9ac8, 0x9ace, 0x9ad0, 0x9ad2, 0x9ad5, 0x9ad6, 0x9ad7, 0x9adb, 0x9adc, 0x9ae0, 0x9ae4, 0x9ae5, 0x9ae7, 0x9ae9, 0x9aec, 0x9af2, 0x9af3, 0x9af5, 0x9af9, 0x9afa, 0x9afd, 0x9aff, 0x9b00, 0x9b01, 0x9b02, 0x9b03, /* 0x8f 0xea: 0xa1 - 0xfe */ 0x9b04, 0x9b05, 0x9b08, 0x9b09, 0x9b0b, 0x9b0c, 0x9b0d, 0x9b0e, 0x9b10, 0x9b12, 0x9b16, 0x9b19, 0x9b1b, 0x9b1c, 0x9b20, 0x9b26, 0x9b2b, 0x9b2d, 0x9b33, 0x9b34, 0x9b35, 0x9b37, 0x9b39, 0x9b3a, 0x9b3d, 0x9b48, 0x9b4b, 0x9b4c, 0x9b55, 0x9b56, 0x9b57, 0x9b5b, 0x9b5e, 0x9b61, 0x9b63, 0x9b65, 0x9b66, 0x9b68, 0x9b6a, 0x9b6b, 0x9b6c, 0x9b6d, 0x9b6e, 0x9b73, 0x9b75, 0x9b77, 0x9b78, 0x9b79, 0x9b7f, 0x9b80, 0x9b84, 0x9b85, 0x9b86, 0x9b87, 0x9b89, 0x9b8a, 0x9b8b, 0x9b8d, 0x9b8f, 0x9b90, 0x9b94, 0x9b9a, 0x9b9d, 0x9b9e, 0x9ba6, 0x9ba7, 0x9ba9, 0x9bac, 0x9bb0, 0x9bb1, 0x9bb2, 0x9bb7, 0x9bb8, 0x9bbb, 0x9bbc, 0x9bbe, 0x9bbf, 0x9bc1, 0x9bc7, 0x9bc8, 0x9bce, 0x9bd0, 0x9bd7, 0x9bd8, 0x9bdd, 0x9bdf, 0x9be5, 0x9be7, 0x9bea, 0x9beb, 0x9bef, 0x9bf3, 0x9bf7, 0x9bf8, /* 0x8f 0xeb: 0xa1 - 0xfe */ 0x9bf9, 0x9bfa, 0x9bfd, 0x9bff, 0x9c00, 0x9c02, 0x9c0b, 0x9c0f, 0x9c11, 0x9c16, 0x9c18, 0x9c19, 0x9c1a, 0x9c1c, 0x9c1e, 0x9c22, 0x9c23, 0x9c26, 0x9c27, 0x9c28, 0x9c29, 0x9c2a, 0x9c31, 0x9c35, 0x9c36, 0x9c37, 0x9c3d, 0x9c41, 0x9c43, 0x9c44, 0x9c45, 0x9c49, 0x9c4a, 0x9c4e, 0x9c4f, 0x9c50, 0x9c53, 0x9c54, 0x9c56, 0x9c58, 0x9c5b, 0x9c5d, 0x9c5e, 0x9c5f, 0x9c63, 0x9c69, 0x9c6a, 0x9c5c, 0x9c6b, 0x9c68, 0x9c6e, 0x9c70, 0x9c72, 0x9c75, 0x9c77, 0x9c7b, 0x9ce6, 0x9cf2, 0x9cf7, 0x9cf9, 0x9d0b, 0x9d02, 0x9d11, 0x9d17, 0x9d18, 0x9d1c, 0x9d1d, 0x9d1e, 0x9d2f, 0x9d30, 0x9d32, 0x9d33, 0x9d34, 0x9d3a, 0x9d3c, 0x9d45, 0x9d3d, 0x9d42, 0x9d43, 0x9d47, 0x9d4a, 0x9d53, 0x9d54, 0x9d5f, 0x9d63, 0x9d62, 0x9d65, 0x9d69, 0x9d6a, 0x9d6b, 0x9d70, 0x9d76, 0x9d77, 0x9d7b, /* 0x8f 0xec: 0xa1 - 0xfe */ 0x9d7c, 0x9d7e, 0x9d83, 0x9d84, 0x9d86, 0x9d8a, 0x9d8d, 0x9d8e, 0x9d92, 0x9d93, 0x9d95, 0x9d96, 0x9d97, 0x9d98, 0x9da1, 0x9daa, 0x9dac, 0x9dae, 0x9db1, 0x9db5, 0x9db9, 0x9dbc, 0x9dbf, 0x9dc3, 0x9dc7, 0x9dc9, 0x9dca, 0x9dd4, 0x9dd5, 0x9dd6, 0x9dd7, 0x9dda, 0x9dde, 0x9ddf, 0x9de0, 0x9de5, 0x9de7, 0x9de9, 0x9deb, 0x9dee, 0x9df0, 0x9df3, 0x9df4, 0x9dfe, 0x9e0a, 0x9e02, 0x9e07, 0x9e0e, 0x9e10, 0x9e11, 0x9e12, 0x9e15, 0x9e16, 0x9e19, 0x9e1c, 0x9e1d, 0x9e7a, 0x9e7b, 0x9e7c, 0x9e80, 0x9e82, 0x9e83, 0x9e84, 0x9e85, 0x9e87, 0x9e8e, 0x9e8f, 0x9e96, 0x9e98, 0x9e9b, 0x9e9e, 0x9ea4, 0x9ea8, 0x9eac, 0x9eae, 0x9eaf, 0x9eb0, 0x9eb3, 0x9eb4, 0x9eb5, 0x9ec6, 0x9ec8, 0x9ecb, 0x9ed5, 0x9edf, 0x9ee4, 0x9ee7, 0x9eec, 0x9eed, 0x9eee, 0x9ef0, 0x9ef1, 0x9ef2, 0x9ef5, /* 0x8f 0xed: 0xa1 - 0xe3 */ 0x9ef8, 0x9eff, 0x9f02, 0x9f03, 0x9f09, 0x9f0f, 0x9f10, 0x9f11, 0x9f12, 0x9f14, 0x9f16, 0x9f17, 0x9f19, 0x9f1a, 0x9f1b, 0x9f1f, 0x9f22, 0x9f26, 0x9f2a, 0x9f2b, 0x9f2f, 0x9f31, 0x9f32, 0x9f34, 0x9f37, 0x9f39, 0x9f3a, 0x9f3c, 0x9f3d, 0x9f3f, 0x9f41, 0x9f43, 0x9f44, 0x9f45, 0x9f46, 0x9f47, 0x9f53, 0x9f55, 0x9f56, 0x9f57, 0x9f58, 0x9f5a, 0x9f5d, 0x9f5e, 0x9f68, 0x9f69, 0x9f6d, 0x9f6e, 0x9f6f, 0x9f70, 0x9f71, 0x9f73, 0x9f75, 0x9f7a, 0x9f7d, 0x9f8f, 0x9f90, 0x9f91, 0x9f92, 0x9f94, 0x9f96, 0x9f97, 0x9f9e, 0x9fa1, 0x9fa2, 0x9fa3, 0x9fa5, }; static const struct jis_charmap __euc_jp_jis_x0213_map[] = { { .first = 0xaf, .last = 0xf1, .offset = 0 }, /* 0xa2 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xa3 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xa4 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xa5 */ { .first = 0xe1, .last = 0xfc, .offset = 67 }, /* 0xa6 */ { .first = 0xc2, .last = 0xfe, .offset = 95 }, /* 0xa7 */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xa8 */ { .first = 0xa1, .last = 0xd0, .offset = 156 }, /* 0xa9 */ { .first = 0xa1, .last = 0xf7, .offset = 204 }, /* 0xaa */ { .first = 0xa1, .last = 0xf7, .offset = 291 }, /* 0xab */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xac */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xad */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xae */ { .first = 0x01, .last = 0x00, .offset = 0xffff }, /* 0xaf */ { .first = 0xa1, .last = 0xfe, .offset = 378 }, /* 0xb0 */ { .first = 0xa1, .last = 0xfe, .offset = 472 }, /* 0xb1 */ { .first = 0xa1, .last = 0xfe, .offset = 566 }, /* 0xb2 */ { .first = 0xa1, .last = 0xfe, .offset = 660 }, /* 0xb3 */ { .first = 0xa1, .last = 0xfe, .offset = 754 }, /* 0xb4 */ { .first = 0xa1, .last = 0xfe, .offset = 848 }, /* 0xb5 */ { .first = 0xa1, .last = 0xfe, .offset = 942 }, /* 0xb6 */ { .first = 0xa1, .last = 0xfe, .offset = 1036 }, /* 0xb7 */ { .first = 0xa1, .last = 0xfe, .offset = 1130 }, /* 0xb8 */ { .first = 0xa1, .last = 0xfe, .offset = 1224 }, /* 0xb9 */ { .first = 0xa1, .last = 0xfe, .offset = 1318 }, /* 0xba */ { .first = 0xa1, .last = 0xfe, .offset = 1412 }, /* 0xbb */ { .first = 0xa1, .last = 0xfe, .offset = 1506 }, /* 0xbc */ { .first = 0xa1, .last = 0xfe, .offset = 1600 }, /* 0xbd */ { .first = 0xa1, .last = 0xfe, .offset = 1694 }, /* 0xbe */ { .first = 0xa1, .last = 0xfe, .offset = 1788 }, /* 0xbf */ { .first = 0xa1, .last = 0xfe, .offset = 1882 }, /* 0xc0 */ { .first = 0xa1, .last = 0xfe, .offset = 1976 }, /* 0xc1 */ { .first = 0xa1, .last = 0xfe, .offset = 2070 }, /* 0xc2 */ { .first = 0xa1, .last = 0xfe, .offset = 2164 }, /* 0xc3 */ { .first = 0xa1, .last = 0xfe, .offset = 2258 }, /* 0xc4 */ { .first = 0xa1, .last = 0xfe, .offset = 2352 }, /* 0xc5 */ { .first = 0xa1, .last = 0xfe, .offset = 2446 }, /* 0xc6 */ { .first = 0xa1, .last = 0xfe, .offset = 2540 }, /* 0xc7 */ { .first = 0xa1, .last = 0xfe, .offset = 2634 }, /* 0xc8 */ { .first = 0xa1, .last = 0xfe, .offset = 2728 }, /* 0xc9 */ { .first = 0xa1, .last = 0xfe, .offset = 2822 }, /* 0xca */ { .first = 0xa1, .last = 0xfe, .offset = 2916 }, /* 0xcb */ { .first = 0xa1, .last = 0xfe, .offset = 3010 }, /* 0xcc */ { .first = 0xa1, .last = 0xfe, .offset = 3104 }, /* 0xcd */ { .first = 0xa1, .last = 0xfe, .offset = 3198 }, /* 0xce */ { .first = 0xa1, .last = 0xfe, .offset = 3292 }, /* 0xcf */ { .first = 0xa1, .last = 0xfe, .offset = 3386 }, /* 0xd0 */ { .first = 0xa1, .last = 0xfe, .offset = 3480 }, /* 0xd1 */ { .first = 0xa1, .last = 0xfe, .offset = 3574 }, /* 0xd2 */ { .first = 0xa1, .last = 0xfe, .offset = 3668 }, /* 0xd3 */ { .first = 0xa1, .last = 0xfe, .offset = 3762 }, /* 0xd4 */ { .first = 0xa1, .last = 0xfe, .offset = 3856 }, /* 0xd5 */ { .first = 0xa1, .last = 0xfe, .offset = 3950 }, /* 0xd6 */ { .first = 0xa1, .last = 0xfe, .offset = 4044 }, /* 0xd7 */ { .first = 0xa1, .last = 0xfe, .offset = 4138 }, /* 0xd8 */ { .first = 0xa1, .last = 0xfe, .offset = 4232 }, /* 0xd9 */ { .first = 0xa1, .last = 0xfe, .offset = 4326 }, /* 0xda */ { .first = 0xa1, .last = 0xfe, .offset = 4420 }, /* 0xdb */ { .first = 0xa1, .last = 0xfe, .offset = 4514 }, /* 0xdc */ { .first = 0xa1, .last = 0xfe, .offset = 4608 }, /* 0xdd */ { .first = 0xa1, .last = 0xfe, .offset = 4702 }, /* 0xde */ { .first = 0xa1, .last = 0xfe, .offset = 4796 }, /* 0xdf */ { .first = 0xa1, .last = 0xfe, .offset = 4890 }, /* 0xe0 */ { .first = 0xa1, .last = 0xfe, .offset = 4984 }, /* 0xe1 */ { .first = 0xa1, .last = 0xfe, .offset = 5078 }, /* 0xe2 */ { .first = 0xa1, .last = 0xfe, .offset = 5172 }, /* 0xe3 */ { .first = 0xa1, .last = 0xfe, .offset = 5266 }, /* 0xe4 */ { .first = 0xa1, .last = 0xfe, .offset = 5360 }, /* 0xe5 */ { .first = 0xa1, .last = 0xfe, .offset = 5454 }, /* 0xe6 */ { .first = 0xa1, .last = 0xfe, .offset = 5548 }, /* 0xe7 */ { .first = 0xa1, .last = 0xfe, .offset = 5642 }, /* 0xe8 */ { .first = 0xa1, .last = 0xfe, .offset = 5736 }, /* 0xe9 */ { .first = 0xa1, .last = 0xfe, .offset = 5830 }, /* 0xea */ { .first = 0xa1, .last = 0xfe, .offset = 5924 }, /* 0xeb */ { .first = 0xa1, .last = 0xfe, .offset = 6018 }, /* 0xec */ { .first = 0xa1, .last = 0xe3, .offset = 6112 }, /* 0xed */ }; #endif /* jis_x0213 */ #endif /* _JIS_CHARSETS_H_ */ picolibc-1.8.11/libc/stdlib/jitouc.c000066400000000000000000000036451513574234600172430ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #ifdef __MB_EXTENDED_CHARSETS_JIS #include "jis.h" wint_t __jis_to_unicode(uint16_t jis) { /* Translate to euc_jp */ if ((jis & 0x8080) != 0) return WEOF; if (jis > 0xff) jis |= 0x8080; return __euc_jp_to_unicode(jis); } #endif /* __MB_EXTENDED_CHARSETS_JIS */ picolibc-1.8.11/libc/stdlib/jrand48.c000066400000000000000000000013361513574234600172130ustar00rootroot00000000000000/* * Copyright (c) 1993 Martin Birgmeier * All rights reserved. * * You may redistribute unmodified or modified versions of this source * code provided that the above copyright notice and this and the * following conditions are retained. * * This software is provided ``as is'', and comes with no warranties * of any kind. I shall in no event be liable for anything that happens * to anyone/anything when using this software. */ #include "rand48.h" long _jrand48_r(struct _rand48 *r, unsigned short xseed[3]) { int32_t i; __dorand48(r, xseed); i = (int32_t)((uint32_t)(xseed[2]) << 16 | (uint32_t)(xseed[1])); return i; } long jrand48(unsigned short xseed[3]) { return _jrand48_r(&_rand48, xseed); } picolibc-1.8.11/libc/stdlib/l64a.c000066400000000000000000000027251513574234600165120ustar00rootroot00000000000000/* Copyright (c) 2002 Jeff Johnston */ /* l64a - convert long to radix-64 ascii string * * Conversion is performed on at most 32-bits of input value starting * from least significant bits to the most significant bits. * * The routine splits the input value into groups of 6 bits for up to * 32 bits of input. This means that the last group may be 2 bits * (bits 30 and 31). * * Each group of 6 bits forms a value from 0-63 which is converted into * a character as follows: * 0 = '.' * 1 = '/' * 2-11 = '0' to '9' * 12-37 = 'A' to 'Z' * 38-63 = 'a' to 'z' * * When the remaining bits are zero or all 32 bits have been translated, * a nul terminator is appended to the resulting string. An input value of * 0 results in an empty string. */ #define _DEFAULT_SOURCE #include static const char R64_ARRAY[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; char * l64a(long value) { char *ptr; char *result; int i, index; unsigned long tmp = (unsigned long)value & 0xffffffff; static __THREAD_LOCAL char _l64a_buf[8]; result = _l64a_buf; ptr = result; for (i = 0; i < 6; ++i) { if (tmp == 0) { *ptr = '\0'; break; } index = tmp & (64 - 1); *ptr++ = R64_ARRAY[index]; tmp >>= 6; } return result; } picolibc-1.8.11/libc/stdlib/labs.c000066400000000000000000000014121513574234600166550ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* FUNCTION <>---long integer absolute value INDEX labs SYNOPSIS #include long labs(long <[i]>); DESCRIPTION <> returns @tex $|x|$, @end tex the absolute value of <[i]> (also called the magnitude of <[i]>). That is, if <[i]> is negative, the result is the opposite of <[i]>, but if <[i]> is nonnegative the result is <[i]>. The similar function <> uses and returns <> rather than <> values. RETURNS The result is a nonnegative long integer. PORTABILITY <> is ANSI. No supporting OS subroutine calls are required. */ #include long labs(long x) { if (x < 0) { x = -x; } return x; } picolibc-1.8.11/libc/stdlib/lcong48.c000066400000000000000000000013621513574234600172160ustar00rootroot00000000000000/* * Copyright (c) 1993 Martin Birgmeier * All rights reserved. * * You may redistribute unmodified or modified versions of this source * code provided that the above copyright notice and this and the * following conditions are retained. * * This software is provided ``as is'', and comes with no warranties * of any kind. I shall in no event be liable for anything that happens * to anyone/anything when using this software. */ #include "rand48.h" void _lcong48_r(struct _rand48 *r, unsigned short p[7]) { r->_seed[0] = p[0]; r->_seed[1] = p[1]; r->_seed[2] = p[2]; r->_mult[0] = p[3]; r->_mult[1] = p[4]; r->_mult[2] = p[5]; r->_add = p[6]; } void lcong48(unsigned short p[7]) { _lcong48_r(&_rand48, p); } picolibc-1.8.11/libc/stdlib/ldiv.c000066400000000000000000000053501513574234600166770ustar00rootroot00000000000000/* FUNCTION <>---divide two long integers INDEX ldiv SYNOPSIS #include ldiv_t ldiv(long <[n]>, long <[d]>); DESCRIPTION Divide @tex $n/d$, @end tex @ifnottex <[n]>/<[d]>, @end ifnottex returning quotient and remainder as two long integers in a structure <>. RETURNS The result is represented with the structure . typedef struct . { . long quot; . long rem; . } ldiv_t; where the <> field represents the quotient, and <> the remainder. For nonzero <[d]>, if `<<<[r]> = ldiv(<[n]>,<[d]>);>>' then <[n]> equals `<<<[r]>.rem + <[d]>*<[r]>.quot>>'. To divide <> rather than <> values, use the similar function <
>. PORTABILITY <> is ANSI. No supporting OS subroutines are required. */ /* * Copyright (c) 1990 Regents of the University of California. * All rights reserved. * * This code is derived from software contributed to Berkeley by * Chris Torek. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include /* ldiv_t */ ldiv_t ldiv(long num, long denom) { ldiv_t r; /* see div.c for comments */ r.quot = num / denom; r.rem = num % denom; if (num >= 0 && r.rem < 0) { ++r.quot; r.rem -= denom; } else if (num < 0 && r.rem > 0) { --r.quot; r.rem += denom; } return (r); } picolibc-1.8.11/libc/stdlib/llabs.c000066400000000000000000000037331513574234600170410ustar00rootroot00000000000000/* FUNCTION <>---compute the absolute value of an long long integer. INDEX llabs SYNOPSIS #include long long llabs(long long <[j]>); DESCRIPTION The <> function computes the absolute value of the long long integer argument <[j]> (also called the magnitude of <[j]>). The similar function <> uses and returns <> rather than <> values. RETURNS A nonnegative long long integer. PORTABILITY <> is ISO 9899 (C99) compatable. No supporting OS subroutines are required. */ /*- * Copyright (c) 2001 Mike Barcroft * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include long long llabs(long long j) { return (j < 0 ? -j : j); } picolibc-1.8.11/libc/stdlib/lldiv.c000066400000000000000000000064441513574234600170600ustar00rootroot00000000000000/* FUNCTION <>---divide two long long integers INDEX lldiv SYNOPSIS #include lldiv_t lldiv(long long <[n]>, long long <[d]>); DESCRIPTION Divide @tex $n/d$, @end tex @ifnottex <[n]>/<[d]>, @end ifnottex returning quotient and remainder as two long long integers in a structure <>. RETURNS The result is represented with the structure . typedef struct . { . long long quot; . long long rem; . } lldiv_t; where the <> field represents the quotient, and <> the remainder. For nonzero <[d]>, if `<<<[r]> = ldiv(<[n]>,<[d]>);>>' then <[n]> equals `<<<[r]>.rem + <[d]>*<[r]>.quot>>'. To divide <> rather than <> values, use the similar function <>. PORTABILITY <> is ISO 9899 (C99) compatable. No supporting OS subroutines are required. */ /*- * Copyright (c) 2001 Mike Barcroft * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include /* * The ANSI standard says that |r.quot| <= |n/d|, where * n/d is to be computed in infinite precision. In other * words, we should always truncate the quotient towards * 0, never -infinity. * * Machine division and remainer may work either way when * one or both of n or d is negative. If only one is * negative and r.quot has been truncated towards -inf, * r.rem will have the same sign as denom and the opposite * sign of num; if both are negative and r.quot has been * truncated towards -inf, r.rem will be positive (will * have the opposite sign of num). These are considered * `wrong'. * * If both are num and denom are positive, r will always * be positive. * * This all boils down to: * if num >= 0, but r.rem < 0, we got the wrong answer. * In that case, to get the right answer, add 1 to r.quot and * subtract denom from r.rem. */ lldiv_t lldiv(long long numer, long long denom) { lldiv_t retval; retval.quot = numer / denom; retval.rem = numer % denom; if (numer >= 0 && retval.rem < 0) { retval.quot++; retval.rem -= denom; } return (retval); } picolibc-1.8.11/libc/stdlib/local-malloc.h000066400000000000000000000147061513574234600203120ustar00rootroot00000000000000/* * Copyright (c) 2012, 2013 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Implementation of <> <> <> <> * * Interface documentation refer to malloc.c. */ #define _DEFAULT_SOURCE #include #include #include #include #include #include #include #include #include #include #include #if MALLOC_DEBUG void __malloc_validate(void); void __malloc_validate_block(chunk_t *r); #define MALLOC_LOCK \ do { \ __LIBC_LOCK(); \ __malloc_validate(); \ } while (0) #define MALLOC_UNLOCK \ do { \ __malloc_validate(); \ __LIBC_UNLOCK(); \ } while (0) #else #define __malloc_validate() #define __malloc_validate_block(r) #define MALLOC_LOCK __LIBC_LOCK() #define MALLOC_UNLOCK __LIBC_UNLOCK() #endif #if __STDC_VERSION__ >= 201112L typedef max_align_t align_chunk_t; #else typedef union { void *p; double d; long long ll; size_t s; long double ld; } align_chunk_t; #endif /* -------------------------------------- * | size | * chunk->| When allocated: data | * | When freed: pointer to next free | * | chunk | * -------------------------------------- * * mem_ptr is aligned to MALLOC_CHUNK_ALIGN. That means that the * address of 'size' may not be aligned to MALLOC_CHUNK_ALIGN. But it * will be aligned to MALLOC_HEAD_ALIGN. * * size is set so that a chunk starting at chunk+size will be * aligned correctly * * We can't use a single struct containing both size and next as that * may insert padding between the size and pointer fields when * pointers are larger than size_t. */ typedef struct malloc_head { size_t size; } head_t; typedef struct malloc_chunk { struct malloc_chunk *next; } chunk_t; /* Alignment of allocated chunk. Compute the alignment required from a * range of types */ #define MALLOC_CHUNK_ALIGN _Alignof(align_chunk_t) /* Alignment of the header. Never larger than MALLOC_CHUNK_ALIGN, but * may be smaller on some targets when size_t is smaller than * align_chunk_t. */ #define MALLOC_HEAD_ALIGN _Alignof(head_t) #define MALLOC_HEAD sizeof(head_t) /* nominal "page size" */ #define MALLOC_PAGE_ALIGN (0x1000) /* Minimum allocation size */ #define MALLOC_MINSIZE __align_up(MALLOC_HEAD + sizeof(chunk_t), MALLOC_HEAD_ALIGN) /* Maximum allocation size */ #define MALLOC_MAXSIZE (SIZE_MAX - (MALLOC_HEAD + 2 * MALLOC_CHUNK_ALIGN)) static inline size_t * _size_ref(chunk_t *chunk) { return (size_t *)((char *)chunk - MALLOC_HEAD); } static inline size_t _size(chunk_t *chunk) { return *_size_ref(chunk); } static inline void _set_size(chunk_t *chunk, size_t size) { *_size_ref(chunk) = size; } /* Forward data declarations */ extern chunk_t *__malloc_free_list; extern char *__malloc_sbrk_start; extern char *__malloc_sbrk_top; #if MALLOC_DEBUG #else #endif bool __malloc_grow_chunk(chunk_t *c, size_t new_size); /* Work around compiler optimizing away stores to 'size' field before * call to free. */ #ifdef __strong_reference void __malloc_free(void *); void *__malloc_malloc(size_t); #else #define __malloc_free(x) free(x) #define __malloc_malloc(x) malloc(x) #endif /* convert storage pointer to chunk */ static inline chunk_t * ptr_to_chunk(void *ptr) { return (chunk_t *)ptr; } /* convert chunk to storage pointer */ static inline void * chunk_to_ptr(chunk_t *c) { return c; } /* Convert address of chunk region to chunk pointer */ static inline chunk_t * blob_to_chunk(void *blob) { return (chunk_t *)((char *)blob + MALLOC_HEAD); } /* Convert chunk pointer to address of chunk region */ static inline void * chunk_to_blob(chunk_t *c) { return (void *)((char *)c - MALLOC_HEAD); } /* end of chunk -- address of first byte past chunk storage */ static inline void * chunk_end(chunk_t *c) { size_t *s = _size_ref(c); return (char *)s + *s; } /* next chunk in memory -- address of chunk header past this chunk */ static inline chunk_t * chunk_after(chunk_t *c) { return (chunk_t *)((char *)c + _size(c)); } /* chunk size needed to hold 'malloc_size' bytes */ static inline size_t chunk_size(size_t malloc_size) { /* Keep all blocks aligned */ malloc_size = __align_up(malloc_size, MALLOC_CHUNK_ALIGN); /* Add space for header */ malloc_size += MALLOC_HEAD; /* fill the gap between chunks */ malloc_size += (MALLOC_CHUNK_ALIGN - MALLOC_HEAD_ALIGN); /* Make sure the requested size is big enough to hold a free chunk */ malloc_size = MAX(MALLOC_MINSIZE, malloc_size); return malloc_size; } /* available storage in chunk */ static inline size_t chunk_usable(chunk_t *c) { return _size(c) - MALLOC_HEAD; } /* assign 'size' to the specified chunk and return it to the free * pool */ static inline void make_free_chunk(chunk_t *c, size_t size) { _set_size(c, size); __malloc_free(chunk_to_ptr(c)); } picolibc-1.8.11/libc/stdlib/local-onexit.h000066400000000000000000000044211513574234600203420ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2021 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _PICO_ONEXIT_H_ #define _PICO_ONEXIT_H_ #include #if !defined(__USE_SYSTEM_LIBC) || !defined(__ENABLE_PROFILING) #define ENABLE_PICOLIBC_EXIT enum pico_onexit_kind { PICO_ONEXIT_EMPTY, PICO_ONEXIT_ONEXIT, PICO_ONEXIT_ATEXIT, PICO_ONEXIT_CXA_ATEXIT }; union on_exit_func { void (*on_exit)(int, void *); void (*atexit)(void); void (*cxa_atexit)(void *); }; int _on_exit(enum pico_onexit_kind kind, union on_exit_func func, void *arg); int __cxa_atexit(void (*func)(void *), void *arg, void *d); void __libc_fini_array(void); #ifndef __INIT_FINI_ARRAY void __call_exitprocs(int code, void *param) __weak; #endif #endif #endif /* _PICO_ONEXIT_H_ */ picolibc-1.8.11/libc/stdlib/local.h000066400000000000000000000016031513574234600170350ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* Misc. local definitions for libc/stdlib */ #ifndef _LOCAL_H_ #define _LOCAL_H_ #include char *_gcvt(double, int, char *, char, int); #include "locale_private.h" #ifndef __machine_mbstate_t_defined #include #endif #ifdef __AVR__ typedef unsigned int uwchar_t; #else typedef wchar_t uwchar_t; #endif mbtowc_f __ascii_mbtowc; wctomb_f __ascii_wctomb; #ifdef __MB_CAPABLE mbtowc_f __utf8_mbtowc; wctomb_f __utf8_wctomb; #ifdef __MB_EXTENDED_CHARSETS_ISO extern const uint16_t __iso_8859_conv[14][0x60]; extern const uint16_t __iso_8859_max[14]; #endif #ifdef __MB_EXTENDED_CHARSETS_WINDOWS extern const uint16_t __cp_conv[27][0x80]; extern const uint16_t __cp_max[27]; #endif #endif size_t _wcsnrtombs_l(char *, const wchar_t **, size_t, size_t, mbstate_t *, locale_t); #endif picolibc-1.8.11/libc/stdlib/local_s.h000066400000000000000000000037011513574234600173600ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _LOCAL_S_H_ #define _LOCAL_S_H_ #if __STDC_WANT_LIB_EXT1__ == 1 #ifndef __STDC_LIB_EXT1__ #define __STDC_LIB_EXT1__ 1 #endif #include #include #if RSIZE_MAX == SIZE_MAX #define CHECK_RSIZE(s) 0 #else #define CHECK_RSIZE(s) (RSIZE_MAX == SIZE_MAX ? 0 : (s) > RSIZE_MAX) #endif extern constraint_handler_t __cur_handler; #endif #endif picolibc-1.8.11/libc/stdlib/lrand48.c000066400000000000000000000012441513574234600172130ustar00rootroot00000000000000/* * Copyright (c) 1993 Martin Birgmeier * All rights reserved. * * You may redistribute unmodified or modified versions of this source * code provided that the above copyright notice and this and the * following conditions are retained. * * This software is provided ``as is'', and comes with no warranties * of any kind. I shall in no event be liable for anything that happens * to anyone/anything when using this software. */ #include "rand48.h" long _lrand48_r(struct _rand48 *r) { __dorand48(r, r->_seed); return (long)((unsigned long)r->_seed[2] << 15) + ((unsigned long)r->_seed[1] >> 1); } long lrand48(void) { return _lrand48_r(&_rand48); } picolibc-1.8.11/libc/stdlib/mallinfo.c000066400000000000000000000045541513574234600175470ustar00rootroot00000000000000/* * Copyright (c) 2012, 2013 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "local-malloc.h" struct mallinfo mallinfo(void) { char *sbrk_now; chunk_t *pf; size_t free_size = 0; size_t total_size; size_t ordblks = 0; struct mallinfo current_mallinfo; memset(¤t_mallinfo, 0, sizeof(current_mallinfo)); MALLOC_LOCK; if (__malloc_sbrk_start == NULL) total_size = 0; else { sbrk_now = __malloc_sbrk_top; if (sbrk_now == NULL) total_size = (size_t)-1; else total_size = (size_t)(sbrk_now - __malloc_sbrk_start); } for (pf = __malloc_free_list; pf; pf = pf->next) { ordblks++; free_size += _size(pf); } current_mallinfo.ordblks = ordblks; current_mallinfo.arena = total_size; current_mallinfo.fordblks = free_size; current_mallinfo.uordblks = total_size - free_size; MALLOC_UNLOCK; return current_mallinfo; } picolibc-1.8.11/libc/stdlib/malloc-stats.c000066400000000000000000000036111513574234600203420ustar00rootroot00000000000000/* * Copyright (c) 2012, 2013 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "local-malloc.h" void malloc_stats(void) { struct mallinfo current_mallinfo; current_mallinfo = mallinfo(); fprintf(stderr, "max system bytes = %10lu\n", (long)current_mallinfo.arena); fprintf(stderr, "system bytes = %10lu\n", (long)current_mallinfo.arena); fprintf(stderr, "in use bytes = %10lu\n", (long)current_mallinfo.uordblks); fprintf(stderr, "free blocks = %10lu\n", (long)current_mallinfo.ordblks); } picolibc-1.8.11/libc/stdlib/malloc-usable-size.c000066400000000000000000000030571513574234600214330ustar00rootroot00000000000000/* * Copyright (c) 2012, 2013 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "local-malloc.h" size_t malloc_usable_size(void *ptr) { return chunk_usable(ptr_to_chunk(ptr)); } picolibc-1.8.11/libc/stdlib/malloc.c000066400000000000000000000151111513574234600172040ustar00rootroot00000000000000/* * Copyright (c) 2012, 2013 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "local-malloc.h" /* List list header of free blocks */ chunk_t *__malloc_free_list; /* Starting point of memory allocated from system */ char *__malloc_sbrk_start; char *__malloc_sbrk_top; /* * Algorithm: * Use sbrk() to obtain more memory and ensure the storage is * MALLOC_CHUNK_ALIGN aligned. Optimise for the case that it is * already aligned - only ask for extra padding after we know we * need it */ static void * __malloc_sbrk_aligned(size_t s) { char *p, *align_p; #ifdef __APPLE__ /* Mac OS X 'emulates' sbrk, but the * parameter is int, not intptr_t or ptrdiff_t, */ int d = (int)s; if (d < 0 || (size_t)d != s) return (void *)-1; #else intptr_t d = (intptr_t)s; if (d < 0) return (void *)-1; #endif p = sbrk(d); /* sbrk returns -1 if fail to allocate */ if (p == (void *)-1) return p; __malloc_sbrk_top = (char *)((uintptr_t)p + s); /* Adjust returned space so that the storage area * is MALLOC_CHUNK_ALIGN aligned and the head is * MALLOC_HEAD_ALIGN aligned. */ align_p = (char *)(__align_up((uintptr_t)p + MALLOC_HEAD, MALLOC_CHUNK_ALIGN) - MALLOC_HEAD); if (align_p != p) { /* p is not aligned, ask for a few more bytes so that we have * s bytes reserved from align_p. This should only occur for * the first sbrk in a chunk of memory as all others should be * aligned to the right value as chunk sizes are selected to * make them abut in memory */ intptr_t adjust = align_p - p; char *extra = sbrk(adjust); if (extra != (char *)((uintptr_t)p + s)) return (void *)-1; __malloc_sbrk_top = extra + adjust; } if (__malloc_sbrk_start == NULL) __malloc_sbrk_start = align_p; return align_p; } bool __malloc_grow_chunk(chunk_t *c, size_t new_size) { char *chunk_e = chunk_end(c); if (chunk_e != __malloc_sbrk_top) return false; size_t add_size = MAX(MALLOC_MINSIZE, new_size - _size(c)); /* Ask for the extra memory needed */ char *heap = __malloc_sbrk_aligned(add_size); /* Check if we got what we wanted */ if (heap == chunk_e) { /* Set size and return */ *_size_ref(c) += add_size; return true; } if (heap != (char *)-1) { /* sbrk returned unexpected memory, free it */ make_free_chunk((chunk_t *)(heap + MALLOC_HEAD), add_size); } return false; } /** Function malloc * Algorithm: * Walk through the free list to find the first match. If fails to find * one, call sbrk to allocate a new chunk_t. */ void * malloc(size_t s) { chunk_t **p, *r; char *ptr; size_t alloc_size; if (s > MALLOC_MAXSIZE) { errno = ENOMEM; return NULL; } alloc_size = chunk_size(s); MALLOC_LOCK; for (p = &__malloc_free_list; (r = *p) != NULL; p = &r->next) { if (_size(r) >= alloc_size) { size_t rem = _size(r) - alloc_size; if (rem >= MALLOC_MINSIZE) { /* Find a chunk_t that much larger than required size, break * it into two chunks and return the first one */ chunk_t *s = (chunk_t *)((char *)r + alloc_size); _set_size(s, rem); s->next = r->next; *p = s; _set_size(r, alloc_size); } else { /* Find a chunk_t that is exactly the size or slightly bigger * than requested size, just return this chunk_t */ *p = r->next; } break; } if (!r->next && __malloc_grow_chunk(r, alloc_size)) { /* Grow the last chunk in memory to the requested size, * just return it */ *p = r->next; break; } } /* Failed to find a appropriate chunk_t. Ask for more memory */ if (r == NULL) { void *blob = __malloc_sbrk_aligned(alloc_size); /* sbrk returns -1 if fail to allocate */ if (blob == (void *)-1) { errno = ENOMEM; MALLOC_UNLOCK; return NULL; } r = blob_to_chunk(blob); _set_size(r, alloc_size); } MALLOC_UNLOCK; ptr = chunk_to_ptr(r); memset(ptr, '\0', alloc_size - MALLOC_HEAD); return ptr; } #ifdef __strong_reference #if defined(__GNUCLIKE_PRAGMA_DIAGNOSTIC) && !defined(__clang__) #pragma GCC diagnostic ignored "-Wmissing-attributes" #endif __strong_reference(malloc, __malloc_malloc); #endif #if MALLOC_DEBUG #include void __malloc_validate_block(chunk_t *r) { assert(__align_up(chunk_to_ptr(r), MALLOC_CHUNK_ALIGN) == chunk_to_ptr(r)); assert(__align_up(r, MALLOC_HEAD_ALIGN) == r); assert(_size(r) >= MALLOC_MINSIZE); assert(_size(r) < 0x80000000UL); assert(__align_up(_size(r), MALLOC_HEAD_ALIGN) == _size(r)); } void __malloc_validate(void) { chunk_t *r; for (r = __malloc_free_list; r; r = r->next) { __malloc_validate_block(r); assert(r->next == NULL || (char *)r + _size(r) <= (char *)r->next); } } #endif picolibc-1.8.11/libc/stdlib/mallopt.c000066400000000000000000000031321513574234600174050ustar00rootroot00000000000000/* * Copyright (c) 2012, 2013 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "local-malloc.h" int mallopt(int parameter_number, int parameter_value) { (void)parameter_number; (void)parameter_value; return 0; } picolibc-1.8.11/libc/stdlib/mbctype.h000066400000000000000000000014461513574234600174130ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ #ifndef _MBCTYPE_H_ #define _MBCTYPE_H_ /* escape character used for JIS encoding */ #define ESC_CHAR 0x1b /* functions used to support SHIFT_JIS, EUC-JP, and JIS multibyte encodings */ int _issjis1(int c); int _issjis2(int c); int _iseucjp(int c); int _isjis(int c); #define _issjis1(c) (((c) >= 0x81 && (c) <= 0x9f) || ((c) >= 0xe0 && (c) <= 0xef)) #define _issjis2(c) (((c) >= 0x40 && (c) <= 0x7e) || ((c) >= 0x80 && (c) <= 0xfc)) #define _issjis1b(c) (((c) <= 0x7f) || ((c) >= 0xa1 && (c) <= 0xdf)) #define _iseucjp1(c) ((c) == 0x8e || (c) == 0x8f || ((c) >= 0xa1 && (c) <= 0xfe)) #define _iseucjp2(c) ((c) >= 0xa1 && (c) <= 0xfe) #define _isjis(c) ((c) >= 0x21 && (c) <= 0x7e) #endif /* _MBCTYPE_H_ */ picolibc-1.8.11/libc/stdlib/mblen.c000066400000000000000000000033731513574234600170410ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* FUNCTION <>---minimal multibyte length function INDEX mblen SYNOPSIS #include int mblen(const char *<[s]>, size_t <[n]>); DESCRIPTION When __MB_CAPABLE is not defined, this is a minimal ANSI-conforming implementation of <>. In this case, the only ``multi-byte character sequences'' recognized are single bytes, and thus <<1>> is returned unless <[s]> is the null pointer or has a length of 0 or is the empty string. When __MB_CAPABLE is defined, this routine calls <<__MBTOWC>> to perform the conversion, passing a state variable to allow state dependent decoding. The result is based on the locale setting which may be restricted to a defined set of locales. RETURNS This implementation of <> returns <<0>> if <[s]> is <> or the empty string; it returns <<1>> if not __MB_CAPABLE or the character is a single-byte character; it returns <<-1>> if the multi-byte character is invalid; otherwise it returns the number of bytes in the multibyte character. PORTABILITY <> is required in the ANSI C standard. However, the precise effects vary with the locale. <> requires no supporting OS subroutines. */ #include #include #include "local.h" int mblen(const char *s, size_t n) { #ifdef __MB_CAPABLE int retval = 0; static _mbstate_t _mblen_state; retval = __MBTOWC(NULL, s, n, &_mblen_state); if (retval < 0) { _mblen_state.__count = 0; return -1; } else return retval; #else /* not __MB_CAPABLE */ if (s == NULL || *s == '\0') return 0; if (n == 0) return -1; return 1; #endif /* not __MB_CAPABLE */ } picolibc-1.8.11/libc/stdlib/mbrlen.c000066400000000000000000000004061513574234600172150ustar00rootroot00000000000000/* Copyright (c) 2002 Thomas Fitzsimmons */ #include #include #include #include size_t mbrlen(const char * __restrict s, size_t n, mbstate_t * __restrict ps) { return mbrtowc(NULL, s, n, ps); } picolibc-1.8.11/libc/stdlib/mbrtowc.c000066400000000000000000000013261513574234600174150ustar00rootroot00000000000000/* Copyright (c) 2002 Thomas Fitzsimmons */ #include #include #include #include #include #include "local.h" size_t mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n, mbstate_t * __restrict ps) { int retval = 0; #ifdef __MB_CAPABLE if (ps == NULL) { static mbstate_t _mbrtowc_state; ps = &_mbrtowc_state; } #endif if (s == NULL) retval = __MBTOWC(NULL, "", 1, ps); else retval = __MBTOWC(pwc, s, n, ps); if (retval == -1) { #ifdef __MB_CAPABLE ps->__count = 0; #endif errno = EILSEQ; return (size_t)(-1); } else return (size_t)retval; } picolibc-1.8.11/libc/stdlib/mbsinit.c000066400000000000000000000004121513574234600174000ustar00rootroot00000000000000/* Copyright (c) 2002 Thomas Fitzsimmons */ #include #include #include #include int mbsinit(const mbstate_t *ps) { if (ps == NULL || ps->__count == 0) return 1; else return 0; } picolibc-1.8.11/libc/stdlib/mbsnrtowcs.c000066400000000000000000000062521513574234600201440ustar00rootroot00000000000000/* Copyright (c) 2009 Corinna Vinschen */ /* FUNCTION <>, <>---convert a character string to a wide-character string INDEX mbsrtowcs INDEX _mbsrtowcs_r INDEX mbsnrtowcs INDEX _mbsnrtowcs_r SYNOPSIS #include size_t mbsrtowcs(wchar_t *__restrict <[dst]>, const char **__restrict <[src]>, size_t <[len]>, mbstate_t *__restrict <[ps]>); #include size_t mbsnrtowcs(wchar_t *__ restrict <[dst]>, const char **__restrict <[src]>, size_t <[nms]>, size_t <[len]>, mbstate_t *__restrict <[ps]>); DESCRIPTION The <> function converts a sequence of multibyte characters pointed to indirectly by <[src]> into a sequence of corresponding wide characters and stores at most <[len]> of them in the wchar_t array pointed to by <[dst]>, until it encounters a terminating null character ('\0'). If <[dst]> is NULL, no characters are stored. If <[dst]> is not NULL, the pointer pointed to by <[src]> is updated to point to the character after the one that conversion stopped at. If conversion stops because a null character is encountered, *<[src]> is set to NULL. The mbstate_t argument, <[ps]>, is used to keep track of the shift state. If it is NULL, <> uses an internal, static mbstate_t object, which is initialized to the initial conversion state at program startup. The <> function behaves identically to <>, except that conversion stops after reading at most <[nms]> bytes from the buffer pointed to by <[src]>. RETURNS The <> and <> functions return the number of wide characters stored in the array pointed to by <[dst]> if successful, otherwise it returns (size_t)-1. PORTABILITY <> is defined by the C99 standard. <> is defined by the POSIX.1-2008 standard. */ #define _DEFAULT_SOURCE #include #include #include #include size_t mbsnrtowcs(wchar_t *dst, const char **src, size_t nms, size_t len, mbstate_t *ps) { wchar_t *ptr = dst; const char *tmp_src; size_t max; size_t count = 0; int bytes; #ifdef __MB_CAPABLE if (ps == NULL) { static mbstate_t _mbsrtowcs_state; ps = &_mbsrtowcs_state; } #endif if (dst == NULL) { /* Ignore original len value and do not alter src pointer if the dst pointer is NULL. */ len = (size_t)-1; tmp_src = *src; src = &tmp_src; } max = len; while (len > 0) { bytes = mbrtowc(ptr, *src, nms, ps); if (bytes > 0) { *src += bytes; nms -= bytes; ++count; ptr = (dst == NULL) ? NULL : ptr + 1; --len; } else if (bytes == -2) { *src += nms; return count; } else if (bytes == 0) { *src = NULL; return count; } else { ps->__count = 0; errno = EILSEQ; return (size_t)-1; } } return (size_t)max; } picolibc-1.8.11/libc/stdlib/mbsrtowcs.c000066400000000000000000000005671513574234600177710ustar00rootroot00000000000000/* Copyright (c) 2002 Thomas Fitzsimmons */ /* doc in mbsnrtowcs.c */ #define _DEFAULT_SOURCE #include #include #include #include size_t mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src, size_t len, mbstate_t * __restrict ps) { return mbsnrtowcs(dst, src, (size_t)-1, len, ps); } picolibc-1.8.11/libc/stdlib/mbstowcs.c000066400000000000000000000046161513574234600176060ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* FUNCTION <>---minimal multibyte string to wide char converter INDEX mbstowcs SYNOPSIS #include int mbstowcs(wchar_t *restrict <[pwc]>, const char *restrict <[s]>, size_t <[n]>); DESCRIPTION When __MB_CAPABLE is not defined, this is a minimal ANSI-conforming implementation of <>. In this case, the only ``multi-byte character sequences'' recognized are single bytes, and they are ``converted'' to wide-char versions simply by byte extension. When __MB_CAPABLE is defined, this uses a state variable to allow state dependent decoding. The result is based on the locale setting which may be restricted to a defined set of locales. RETURNS This implementation of <> returns <<0>> if <[s]> is <> or is the empty string; it returns <<-1>> if __MB_CAPABLE and one of the multi-byte characters is invalid or incomplete; otherwise it returns the minimum of: <> or the number of multi-byte characters in <> plus 1 (to compensate for the nul character). If the return value is -1, the state of the <> string is indeterminate. If the input has a length of 0, the output string will be modified to contain a wchar_t nul terminator. PORTABILITY <> is required in the ANSI C standard. However, the precise effects vary with the locale. <> requires no supporting OS subroutines. */ #include #include #include "local.h" size_t mbstowcs(wchar_t * __restrict pwcs, const char * __restrict s, size_t n) { #ifdef __MB_CAPABLE mbstate_t state; state.__count = 0; size_t ret = 0; char *t = (char *)s; int bytes; if (!pwcs) n = (size_t)1; /* Value doesn't matter as long as it's not 0. */ while (n > 0) { bytes = __MBTOWC(pwcs, t, MB_CUR_MAX, &state); if (bytes < 0) { state.__count = 0; errno = EILSEQ; return -1; } else if (bytes == 0) break; t += bytes; ++ret; if (pwcs) { ++pwcs; --n; } } return ret; #else /* not __MB_CAPABLE */ int count = 0; if (n != 0) { do { if ((*pwcs++ = (wchar_t)*s++) == 0) break; count++; } while (--n != 0); } return count; #endif /* not __MB_CAPABLE */ } picolibc-1.8.11/libc/stdlib/mbtowc.c000066400000000000000000000040401513574234600172270ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* FUNCTION <>---minimal multibyte to wide char converter INDEX mbtowc SYNOPSIS #include int mbtowc(wchar_t *restrict <[pwc]>, const char *restrict <[s]>, size_t <[n]>); DESCRIPTION When __MB_CAPABLE is not defined, this is a minimal ANSI-conforming implementation of <>. In this case, only ``multi-byte character sequences'' recognized are single bytes, and they are ``converted'' to themselves. Each call to <> copies one character from <<*<[s]>>> to <<*<[pwc]>>>, unless <[s]> is a null pointer. The argument n is ignored. When __MB_CAPABLE is defined, this routine uses a state variable to allow state dependent decoding. The result is based on the locale setting which may be restricted to a defined set of locales. RETURNS This implementation of <> returns <<0>> if <[s]> is <> or is the empty string; it returns <<1>> if not __MB_CAPABLE or the character is a single-byte character; it returns <<-1>> if n is <<0>> or the multi-byte character is invalid; otherwise it returns the number of bytes in the multibyte character. If the return value is -1, no changes are made to the <> output string. If the input is the empty string, a wchar_t nul is placed in the output string and 0 is returned. If the input has a length of 0, no changes are made to the <> output string. PORTABILITY <> is required in the ANSI C standard. However, the precise effects vary with the locale. <> requires no supporting OS subroutines. */ #include #include #include "local.h" #ifdef __MB_CAPABLE static mbstate_t _mbtowc_state; #define ps &_mbtowc_state #else #define ps NULL #endif int mbtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n) { int retval; retval = __MBTOWC(pwc, s, n, ps); if (retval < 0) { #ifdef __MB_CAPABLE _mbtowc_state.__count = 0; #endif errno = EILSEQ; retval = -1; } return retval; } picolibc-1.8.11/libc/stdlib/mbtowc_r.c000066400000000000000000000632601513574234600175610ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ #include #include #include "mbctype.h" #include #include #include #include #include "local.h" #include "../ctype/local.h" int __ascii_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { wchar_t dummy; unsigned char *t = (unsigned char *)s; unsigned char c; (void)state; if (pwc == NULL) pwc = &dummy; if (s == NULL) return 0; if (n == 0) return -2; c = *t; if (c >= 0x80) return -1; *pwc = (wchar_t)c; if (*t == '\0') return 0; return 1; } #ifdef __MB_CAPABLE /* we override the mbstate_t __count field for more complex encodings and use it store a state value */ #define __state __count int __utf8_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { wchar_t dummy; unsigned char *t = (unsigned char *)s; int ch; int i = 0; if (pwc == NULL) pwc = &dummy; if (s == NULL) return 0; if (n == 0) return -2; if (state->__count == 0) ch = t[i++]; else ch = state->__value.__wchb[0]; if (ch == '\0') { *pwc = 0; state->__count = 0; return 0; /* s points to the null character */ } if (ch <= 0x7f) { /* single-byte sequence */ state->__count = 0; *pwc = ch; return 1; } if (ch >= 0xc0 && ch <= 0xdf) { if (ch == 0xc0) return -1; /* two-byte sequence */ state->__value.__wchb[0] = ch; if (state->__count == 0) state->__count = 1; else if (n < (size_t)-1) ++n; if (n < 2) return -2; ch = t[i++]; if (ch < 0x80 || ch > 0xbf) return -1; if (state->__value.__wchb[0] < 0xc2) { /* overlong UTF-8 sequence */ return -1; } state->__count = 0; *pwc = ((wchar_t)(state->__value.__wchb[0] & 0x1f) << 6) | (wchar_t)(ch & 0x3f); return i; } if (ch >= 0xe0 && ch <= 0xef) { /* three-byte sequence */ wchar_t tmp; state->__value.__wchb[0] = ch; if (state->__count == 0) state->__count = 1; else if (n < (size_t)-1) ++n; if (n < 2) return -2; ch = (state->__count == 1) ? t[i++] : state->__value.__wchb[1]; if (state->__value.__wchb[0] == 0xe0 && ch < 0xa0) { /* overlong UTF-8 sequence */ return -1; } if (ch < 0x80 || ch > 0xbf) { return -1; } state->__value.__wchb[1] = ch; if (state->__count == 1) state->__count = 2; else if (n < (size_t)-1) ++n; if (n < 3) return -2; ch = t[i++]; if (ch < 0x80 || ch > 0xbf) { return -1; } state->__count = 0; tmp = ((wchar_t)(state->__value.__wchb[0] & 0x0f) << 12) | ((wchar_t)(state->__value.__wchb[1] & 0x3f) << 6) | (wchar_t)(ch & 0x3f); /* Check for surrogates */ if (0xd800 <= (uwchar_t)tmp && (uwchar_t)tmp <= 0xdfff) { return -1; } *pwc = tmp; return i; } if (ch >= 0xf0 && ch <= 0xf4) { /* four-byte sequence */ uint32_t tmp; state->__value.__wchb[0] = ch; if (state->__count == 0) state->__count = 1; else if (n < (size_t)-1) ++n; if (n < 2) return -2; ch = (state->__count == 1) ? t[i++] : state->__value.__wchb[1]; if ((state->__value.__wchb[0] == 0xf0 && ch < 0x90) || (state->__value.__wchb[0] == 0xf4 && ch >= 0x90)) { /* overlong UTF-8 sequence or result is > 0x10ffff */ return -1; } if (ch < 0x80 || ch > 0xbf) { return -1; } state->__value.__wchb[1] = ch; if (state->__count == 1) state->__count = 2; else if (n < (size_t)-1) ++n; if (n < 3) return -2; ch = (state->__count == 2) ? t[i++] : state->__value.__wchb[2]; if (ch < 0x80 || ch > 0xbf) { return -1; } state->__value.__wchb[2] = ch; if (state->__count == 2) state->__count = 3; else if (n < (size_t)-1) ++n; #if __SIZEOF_WCHAR_T__ == 2 if (state->__count == 3) { /* On systems which have wchar_t being UTF-16 values, the value doesn't fit into a single wchar_t in this case. So what we do here is to store the state with a special value of __count and return the first half of a surrogate pair. The first three bytes of a UTF-8 sequence are enough to generate the first half of a UTF-16 surrogate pair. As return value we choose to return the number of bytes actually read up to here. The second half of the surrogate pair is returned in case we recognize the special __count value of four, and the next byte is actually a valid value. See below. */ tmp = (uint32_t)((state->__value.__wchb[0] & (uint32_t)0x07) << 18) | (uint32_t)((state->__value.__wchb[1] & (uint32_t)0x3f) << 12) | (uint32_t)((state->__value.__wchb[2] & (uint32_t)0x3f) << 6); state->__count = 4; *pwc = 0xd800 | ((tmp - 0x10000) >> 10); return i; } #endif if (n < 4) return -2; ch = t[i++]; if (ch < 0x80 || ch > 0xbf) { return -1; } tmp = (((uint32_t)state->__value.__wchb[0] & 0x07) << 18) | (((uint32_t)state->__value.__wchb[1] & 0x3f) << 12) | (((uint32_t)state->__value.__wchb[2] & 0x3f) << 6) | ((uint32_t)ch & 0x3f); #if __SIZEOF_WCHAR_T__ == 2 if (state->__count == 4) /* Create the second half of the surrogate pair for systems with wchar_t == UTF-16 . */ *pwc = 0xdc00 | (tmp & 0x3ff); else #endif *pwc = tmp; state->__count = 0; return i; } return -1; } #ifdef __MB_EXTENDED_CHARSETS_UCS #if _BYTE_ORDER == _LITTLE_ENDIAN #define __ucs2le_mbtowc __ucs2_mbtowc #define __ucs2be_mbtowc __ucs2swap_mbtowc #define __ucs4le_mbtowc __ucs4_mbtowc #define __ucs4be_mbtowc __ucs4swap_mbtowc #else #define __ucs2le_mbtowc __ucs2swap_mbtowc #define __ucs2be_mbtowc __ucs2_mbtowc #define __ucs4le_mbtowc __ucs4swap_mbtowc #define __ucs4be_mbtowc __ucs4_mbtowc #endif static int __ucs2_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { uint16_t uchar; (void)state; if (n < 2) return -1; memcpy(&uchar, s, 2); *pwc = uchar; return 2; } static int __ucs2swap_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { uint16_t uchar; (void)state; if (n < 2) return -1; memcpy(&uchar, s, 2); *pwc = __bswap16(uchar); return 2; } static int __ucs4_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { uint32_t uchar; (void)state; if (n < 4) return -1; memcpy(&uchar, s, 4); *pwc = uchar; return 4; } static int __ucs4swap_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { uint32_t uchar; (void)state; if (n < 4) return -1; memcpy(&uchar, s, 4); *pwc = __bswap32(uchar); return 4; } #endif /* __MB_EXTENDED_CHARSETS_UCS */ #ifdef __MB_EXTENDED_CHARSETS_ISO static int ___iso_mbtowc(wchar_t *pwc, const char *s, size_t n, enum locale_id id, mbstate_t *state) { wchar_t dummy; unsigned char *t = (unsigned char *)s; (void)state; if (pwc == NULL) pwc = &dummy; if (s == NULL) return 0; if (n == 0) return -2; if (*t >= 0xa0) { if (id > locale_ISO_8859_1) { *pwc = __iso_8859_conv[id - locale_ISO_8859_2][*t - 0xa0]; if (*pwc == 0) /* Invalid character */ { return -1; } return 1; } } *pwc = (wchar_t)*t; if (*t == '\0') return 0; return 1; } static int __iso_8859_1_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___iso_mbtowc(pwc, s, n, locale_ISO_8859_1, state); } static int __iso_8859_2_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___iso_mbtowc(pwc, s, n, locale_ISO_8859_2, state); } static int __iso_8859_3_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___iso_mbtowc(pwc, s, n, locale_ISO_8859_3, state); } static int __iso_8859_4_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___iso_mbtowc(pwc, s, n, locale_ISO_8859_4, state); } static int __iso_8859_5_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___iso_mbtowc(pwc, s, n, locale_ISO_8859_5, state); } static int __iso_8859_6_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___iso_mbtowc(pwc, s, n, locale_ISO_8859_6, state); } static int __iso_8859_7_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___iso_mbtowc(pwc, s, n, locale_ISO_8859_7, state); } static int __iso_8859_8_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___iso_mbtowc(pwc, s, n, locale_ISO_8859_8, state); } static int __iso_8859_9_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___iso_mbtowc(pwc, s, n, locale_ISO_8859_9, state); } static int __iso_8859_10_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___iso_mbtowc(pwc, s, n, locale_ISO_8859_10, state); } static int __iso_8859_11_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___iso_mbtowc(pwc, s, n, locale_ISO_8859_11, state); } static int __iso_8859_13_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___iso_mbtowc(pwc, s, n, locale_ISO_8859_13, state); } static int __iso_8859_14_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___iso_mbtowc(pwc, s, n, locale_ISO_8859_14, state); } static int __iso_8859_15_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___iso_mbtowc(pwc, s, n, locale_ISO_8859_15, state); } static int __iso_8859_16_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___iso_mbtowc(pwc, s, n, locale_ISO_8859_16, state); } #endif /* __MB_EXTENDED_CHARSETS_ISO */ #ifdef __MB_EXTENDED_CHARSETS_WINDOWS static int ___cp_mbtowc(wchar_t *pwc, const char *s, size_t n, enum locale_id id, mbstate_t *state) { wchar_t dummy; unsigned char *t = (unsigned char *)s; (void)state; if (pwc == NULL) pwc = &dummy; if (s == NULL) return 0; if (n == 0) return -2; if (*t >= 0x80) { *pwc = __cp_conv[id - locale_WINDOWS_BASE][*t - 0x80]; if (*pwc == 0) /* Invalid character */ return -1; return 1; } *pwc = (wchar_t)*t; if (*t == '\0') return 0; return 1; } static int __cp_437_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP437, state); } static int __cp_720_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP720, state); } static int __cp_737_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP737, state); } static int __cp_775_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP775, state); } static int __cp_850_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP850, state); } static int __cp_852_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP852, state); } static int __cp_855_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP855, state); } static int __cp_857_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP857, state); } static int __cp_858_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP858, state); } static int __cp_862_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP862, state); } static int __cp_866_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP866, state); } static int __cp_874_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP874, state); } static int __cp_1125_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP1125, state); } static int __cp_1250_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP1250, state); } static int __cp_1251_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP1251, state); } static int __cp_1252_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP1252, state); } static int __cp_1253_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP1253, state); } static int __cp_1254_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP1254, state); } static int __cp_1255_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP1255, state); } static int __cp_1256_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP1256, state); } static int __cp_1257_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP1257, state); } static int __cp_1258_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_CP1258, state); } static int __cp_20866_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_KOI8_R, state); } static int __cp_21866_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_KOI8_U, state); } static int __cp_101_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_GEORGIAN_PS, state); } static int __cp_102_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_PT154, state); } static int __cp_103_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { return ___cp_mbtowc(pwc, s, n, locale_KOI8_T, state); } #endif /* __MB_EXTENDED_CHARSETS_WINDOWS */ #ifdef __MB_EXTENDED_CHARSETS_JIS #include "jis.h" /* clang-format off */ typedef enum __packed { ESCAPE, DOLLAR, BRACKET, AT, B, J, NUL, JIS_CHAR, OTHER, JIS_C_NUM } JIS_CHAR_TYPE; typedef enum __packed { ASCII, JIS, A_ESC, A_ESC_DL, JIS_1, J_ESC, J_ESC_BR, INV, JIS_S_NUM } JIS_STATE; typedef enum __packed { COPY_A, COPY_J1, COPY_J2, MAKE_A, NOOP, EMPTY, ERROR } JIS_ACTION; /************************************************************************************** * state/action tables for processing JIS encoding * Where possible, switches to JIS are grouped with proceding JIS characters and switches * to ASCII are grouped with preceding JIS characters. Thus, maximum returned length * is 2 (switch to JIS) + 2 (JIS characters) + 2 (switch back to ASCII) = 6. *************************************************************************************/ static const JIS_STATE JIS_state_table[JIS_S_NUM][JIS_C_NUM] = { /* ESCAPE DOLLAR BRACKET AT B J NUL JIS_CHAR OTHER */ /* ASCII */ { A_ESC, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII }, /* JIS */ { J_ESC, JIS_1, JIS_1, JIS_1, JIS_1, JIS_1, INV, JIS_1, INV }, /* A_ESC */ { ASCII, A_ESC_DL, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII }, /* A_ESC_DL */{ ASCII, ASCII, ASCII, JIS, JIS, ASCII, ASCII, ASCII, ASCII }, /* JIS_1 */ { INV, JIS, JIS, JIS, JIS, JIS, INV, JIS, INV }, /* J_ESC */ { INV, INV, J_ESC_BR, INV, INV, INV, INV, INV, INV }, /* J_ESC_BR */{ INV, INV, INV, INV, ASCII, ASCII, INV, INV, INV }, }; static const JIS_ACTION JIS_action_table[JIS_S_NUM][JIS_C_NUM] = { /* ESCAPE DOLLAR BRACKET AT B J NUL JIS_CHAR OTHER */ /* ASCII */ { NOOP, COPY_A, COPY_A, COPY_A, COPY_A, COPY_A, EMPTY, COPY_A, COPY_A}, /* JIS */ { NOOP, COPY_J1, COPY_J1, COPY_J1, COPY_J1, COPY_J1, ERROR, COPY_J1, ERROR }, /* A_ESC */ { COPY_A, NOOP, COPY_A, COPY_A, COPY_A, COPY_A, COPY_A, COPY_A, COPY_A}, /* A_ESC_DL */{ COPY_A, COPY_A, COPY_A, NOOP, NOOP, COPY_A, COPY_A, COPY_A, COPY_A}, /* JIS_1 */ { ERROR, COPY_J2, COPY_J2, COPY_J2, COPY_J2, COPY_J2, ERROR, COPY_J2, ERROR }, /* J_ESC */ { ERROR, ERROR, NOOP, ERROR, ERROR, ERROR, ERROR, ERROR, ERROR }, /* J_ESC_BR */{ ERROR, ERROR, ERROR, ERROR, MAKE_A, MAKE_A, ERROR, ERROR, ERROR }, }; /* clang-format on */ static int __sjis_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { wchar_t dummy; wint_t jischar = 0, uchar; uint8_t *t = (uint8_t *)s; uint8_t *wchb; uint8_t ch; int i = 0; if (pwc == NULL) pwc = &dummy; if (s == NULL) return 0; /* not state-dependent */ if (n == 0) return -2; wchb = state->__value.__wchb; ch = t[i++]; if (state->__count == 0) { if (_issjis1(ch)) { wchb[0] = ch; state->__count = 1; if (n <= 1) return -2; ch = t[i++]; } else { if (!_issjis1b(ch)) return -1; if (ch == '\0') { *pwc = L'\0'; return 0; } jischar = ch; } } if (state->__count == 1) { if (!_issjis2(ch)) return -1; jischar = ((uint16_t)wchb[0] << 8) | ch; } uchar = __shift_jis_to_unicode(jischar); state->__count = 0; if (uchar == WEOF) return -1; *pwc = (wchar_t)uchar; return i; } static int __eucjp_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { wchar_t dummy; uint32_t jischar = 0; wint_t uchar; const uint8_t *t = (const uint8_t *)s; uint8_t ch; uint8_t *wchb; int i = 0; if (pwc == NULL) pwc = &dummy; if (s == NULL) return 0; /* not state-dependent */ if (n == 0) return -2; wchb = state->__value.__wchb; ch = t[i++]; if (state->__count == 0) { if (_iseucjp1(ch)) { wchb[0] = ch; state->__count = 1; if (n <= (size_t)i) return -2; ch = t[i++]; } else { if (ch == '\0') { *pwc = L'\0'; return 0; } jischar = ch; } } if (state->__count == 1) { if (_iseucjp2(ch)) { if (wchb[0] == 0x8f) { wchb[1] = ch; state->__count = 2; if (n <= (size_t)i) return -2; ch = t[i++]; } else { jischar = ((uint32_t)wchb[0] << 8) | ch; } } else { return -1; } } if (state->__count == 2) { if (_iseucjp2(ch)) { jischar = ((uint32_t)wchb[0] << 16) | ((uint32_t)wchb[1] << 8) | ch; } else { return -1; } } uchar = __euc_jp_to_unicode(jischar); state->__count = 0; if (uchar == WEOF) return -1; *pwc = (wchar_t)uchar; return i; } static int __jis_mbtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *state) { wchar_t dummy; wint_t jischar, uchar; const uint8_t *t = (const uint8_t *)s; JIS_STATE curr_state; JIS_ACTION action; JIS_CHAR_TYPE ch; const uint8_t *ptr; size_t i; uint8_t *wchb; uint8_t curr_ch; if (pwc == NULL) pwc = &dummy; if (s == NULL) { state->__state = ASCII; return 1; /* state-dependent */ } if (n == 0) return -2; wchb = state->__value.__wchb; curr_state = state->__state; ptr = t; for (i = 0; i < n; ++i) { curr_ch = t[i]; switch (curr_ch) { case ESC_CHAR: ch = ESCAPE; break; case '$': ch = DOLLAR; break; case '@': ch = AT; break; case '(': ch = BRACKET; break; case 'B': ch = B; break; case 'J': ch = J; break; case '\0': ch = NUL; break; default: if (_isjis(curr_ch)) ch = JIS_CHAR; else ch = OTHER; } action = JIS_action_table[curr_state][ch]; curr_state = JIS_state_table[curr_state][ch]; switch (action) { case NOOP: break; case EMPTY: state->__state = ASCII; *pwc = L'\0'; return 0; case COPY_A: state->__state = ASCII; *pwc = (wchar_t)*ptr; return i + 1; case COPY_J1: wchb[0] = t[i]; break; case COPY_J2: state->__state = JIS; jischar = ((uint16_t)wchb[0] << 8) | t[i]; uchar = __jis_to_unicode(jischar); if (uchar == WEOF) return -1; *pwc = uchar; return i + 1; case MAKE_A: ptr = (uint8_t *)(t + i + 1); break; case ERROR: default: return -1; } } state->__state = curr_state; return -2; /* n < bytes needed */ } #endif /* __MB_EXTENDED_CHARSETS_JIS */ const mbtowc_p __mbtowc[locale_END - locale_BASE] = { [locale_C - locale_BASE] = __ascii_mbtowc, [locale_UTF_8 - locale_BASE] = __utf8_mbtowc, #ifdef __MB_EXTENDED_CHARSETS_UCS [locale_UCS_2 - locale_BASE] = __ucs2_mbtowc, [locale_UCS_2LE - locale_BASE] = __ucs2le_mbtowc, [locale_UCS_2BE - locale_BASE] = __ucs2be_mbtowc, [locale_UCS_4 - locale_BASE] = __ucs4_mbtowc, [locale_UCS_4LE - locale_BASE] = __ucs4le_mbtowc, [locale_UCS_4BE - locale_BASE] = __ucs4be_mbtowc, #endif #ifdef __MB_EXTENDED_CHARSETS_ISO [locale_ISO_8859_1 - locale_BASE] = __iso_8859_1_mbtowc, [locale_ISO_8859_2 - locale_BASE] = __iso_8859_2_mbtowc, [locale_ISO_8859_3 - locale_BASE] = __iso_8859_3_mbtowc, [locale_ISO_8859_4 - locale_BASE] = __iso_8859_4_mbtowc, [locale_ISO_8859_5 - locale_BASE] = __iso_8859_5_mbtowc, [locale_ISO_8859_6 - locale_BASE] = __iso_8859_6_mbtowc, [locale_ISO_8859_7 - locale_BASE] = __iso_8859_7_mbtowc, [locale_ISO_8859_8 - locale_BASE] = __iso_8859_8_mbtowc, [locale_ISO_8859_9 - locale_BASE] = __iso_8859_9_mbtowc, [locale_ISO_8859_10 - locale_BASE] = __iso_8859_10_mbtowc, [locale_ISO_8859_11 - locale_BASE] = __iso_8859_11_mbtowc, [locale_ISO_8859_13 - locale_BASE] = __iso_8859_13_mbtowc, [locale_ISO_8859_14 - locale_BASE] = __iso_8859_14_mbtowc, [locale_ISO_8859_15 - locale_BASE] = __iso_8859_15_mbtowc, [locale_ISO_8859_16 - locale_BASE] = __iso_8859_16_mbtowc, #endif #ifdef __MB_EXTENDED_CHARSETS_WINDOWS [locale_CP437 - locale_BASE] = __cp_437_mbtowc, [locale_CP720 - locale_BASE] = __cp_720_mbtowc, [locale_CP737 - locale_BASE] = __cp_737_mbtowc, [locale_CP775 - locale_BASE] = __cp_775_mbtowc, [locale_CP850 - locale_BASE] = __cp_850_mbtowc, [locale_CP852 - locale_BASE] = __cp_852_mbtowc, [locale_CP855 - locale_BASE] = __cp_855_mbtowc, [locale_CP857 - locale_BASE] = __cp_857_mbtowc, [locale_CP858 - locale_BASE] = __cp_858_mbtowc, [locale_CP862 - locale_BASE] = __cp_862_mbtowc, [locale_CP866 - locale_BASE] = __cp_866_mbtowc, [locale_CP874 - locale_BASE] = __cp_874_mbtowc, [locale_CP1125 - locale_BASE] = __cp_1125_mbtowc, [locale_CP1250 - locale_BASE] = __cp_1250_mbtowc, [locale_CP1251 - locale_BASE] = __cp_1251_mbtowc, [locale_CP1252 - locale_BASE] = __cp_1252_mbtowc, [locale_CP1253 - locale_BASE] = __cp_1253_mbtowc, [locale_CP1254 - locale_BASE] = __cp_1254_mbtowc, [locale_CP1255 - locale_BASE] = __cp_1255_mbtowc, [locale_CP1256 - locale_BASE] = __cp_1256_mbtowc, [locale_CP1257 - locale_BASE] = __cp_1257_mbtowc, [locale_CP1258 - locale_BASE] = __cp_1258_mbtowc, [locale_KOI8_R - locale_BASE] = __cp_20866_mbtowc, [locale_KOI8_U - locale_BASE] = __cp_21866_mbtowc, [locale_GEORGIAN_PS - locale_BASE] = __cp_101_mbtowc, [locale_PT154 - locale_BASE] = __cp_102_mbtowc, [locale_KOI8_T - locale_BASE] = __cp_103_mbtowc, #endif #ifdef __MB_EXTENDED_CHARSETS_JIS [locale_JIS - locale_BASE] = __jis_mbtowc, [locale_EUCJP - locale_BASE] = __eucjp_mbtowc, [locale_SJIS - locale_BASE] = __sjis_mbtowc, #endif }; #endif /* __MB_CAPABLE */ picolibc-1.8.11/libc/stdlib/memalign.c000066400000000000000000000070521513574234600175330ustar00rootroot00000000000000/* * Copyright (c) 2012, 2013 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _GNU_SOURCE #include "local-malloc.h" /* * Allocate memory block aligned at specific boundary. * align: required alignment. Must be power of 2. Return NULL * if not power of 2. Undefined behavior is bigger than * pointer value range. * s: required size. * Return: allocated memory pointer aligned to align * Algorithm: Malloc a big enough block, padding pointer to aligned * address, then truncate and free the tail if too big. * Record the offset of align pointer and original pointer * in the padding area. */ void * memalign(size_t align, size_t s) { chunk_t *chunk_p; size_t offset, size_with_padding; char *allocated, *aligned_p; /* Return NULL if align isn't power of 2 */ if ((align & (align - 1)) != 0) { errno = EINVAL; return NULL; } align = MAX(align, MALLOC_MINSIZE); if (s > MALLOC_MAXSIZE - align) { errno = ENOMEM; return NULL; } s = __align_up(MAX(s, 1), MALLOC_CHUNK_ALIGN); /* Make sure there's space to align the allocation and split * off chunk_t from the front */ size_with_padding = s + align + MALLOC_MINSIZE; allocated = __malloc_malloc(size_with_padding); if (allocated == NULL) return NULL; chunk_p = ptr_to_chunk(allocated); aligned_p = __align_up(allocated, align); offset = (size_t)(aligned_p - allocated); /* Split off the front piece if necessary */ if (offset) { if (offset < MALLOC_MINSIZE) { aligned_p += align; offset += align; } chunk_t *new_chunk_p = ptr_to_chunk(aligned_p); _set_size(new_chunk_p, _size(chunk_p) - offset); make_free_chunk(chunk_p, offset); chunk_p = new_chunk_p; } offset = _size(chunk_p) - chunk_size(s); /* Split off the back piece if large enough */ if (offset >= MALLOC_MINSIZE) { *_size_ref(chunk_p) -= offset; make_free_chunk(chunk_after(chunk_p), offset); } return aligned_p; } #ifdef __strong_reference __strong_reference(memalign, aligned_alloc); #endif picolibc-1.8.11/libc/stdlib/meson.build000066400000000000000000000071541513574234600177430ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # malloc_srcs_stdlib = [ 'calloc.c', 'free.c', 'getpagesize.c', 'mallinfo.c', 'malloc.c', 'malloc-stats.c', 'malloc-usable-size.c', 'mallopt.c', 'memalign.c', 'posix-memalign.c', 'pvalloc.c', 'realloc.c', 'valloc.c', ] srcs_stdlib = [ 'a64l.c', 'abort.c', 'abs.c', 'aligned_alloc.c', 'arc4random.c', 'arc4random_uniform.c', 'assert.c', 'assert_func.c', 'assert_no_arg.c', 'atexit.c', 'atof.c', 'atoff.c', 'atoi.c', 'atol.c', 'atoll.c', 'btowc.c', 'cxa-atexit.c', 'div.c', 'drand48.c', 'ejtouc.c', 'environ.c', 'eprintf.c', 'erand48.c', 'exit.c', 'exitprocs.c', '_Exit.c', 'getenv.c', 'getenv_r.c', 'getopt.c', 'getsubopt.c', 'imaxabs.c', 'imaxdiv.c', 'itoa.c', 'jitouc.c', 'jrand48.c', 'l64a.c', 'labs.c', 'lcong48.c', 'ldiv.c', 'llabs.c', 'lldiv.c', 'lrand48.c', 'mblen.c', 'mbrlen.c', 'mbrtowc.c', 'mbsinit.c', 'mbsnrtowcs.c', 'mbsrtowcs.c', 'mbstowcs.c', 'mbtowc.c', 'mbtowc_r.c', 'mrand48.c', 'nrand48.c', 'onexit.c', 'putenv.c', 'rand48.c', 'rand.c', 'random.c', 'rand_r.c', 'reallocarray.c', 'reallocf.c', 'rpmatch.c', 'sb_charsets.c', 'seed48.c', 'setenv.c', 'sjtouc.c', 'srand.c', 'srand48.c', 'srandom.c', 'system.c', 'uctoji.c', 'uctoej.c', 'uctosj.c', 'utoa.c', 'wcrtomb.c', 'wcsnrtombs.c', 'wcsrtombs.c', 'wcstombs.c', 'wctob.c', 'wctomb.c', 'wctomb_r.c', 'set_constraint_handler_s.c', 'ignore_handler_s.c', ] if enable_malloc srcs_stdlib += malloc_srcs_stdlib endif srcs_stdlib_use = [] foreach file : srcs_stdlib s_file = fs.replace_suffix(file, '.S') if file in srcs_machine message('libc/stdlib/' + file + ': machine overrides generic') elif s_file in srcs_machine message('libc/stdlib/' + s_file + ': machine overrides generic') else srcs_stdlib_use += file endif endforeach src_stdlib = files(srcs_stdlib_use) picolibc-1.8.11/libc/stdlib/mk-jis-charsets.py000066400000000000000000000277351513574234600211660ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2025 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # ''' Generate multi-byte translation table for EUC-JP ''' import copy import re import sys invalid_unicode = 0xffff invalid_jis = 0xffff split_codes = 0x4000 struct_name = 'jis_charmap' head = '__euc_jp_' def to_code(byte0, byte1, byte2): if byte0 is not None: code = (byte0, byte1, byte2) elif byte1 is not None: code = (byte1, byte2) else: code = (byte2, ) return code def to_ucode(byte0, byte1, byte2): try: # Missing from python map if (byte0, byte1, byte2) == (0x8f, 0xa2, 0xb7): return 0xff5e ucode = ord(bytes(to_code(byte0, byte1, byte2)).decode('EUC_JP')) # ignore JIS x803 encodings for ASCII range if ucode < 0x80 and (byte0 is not none or byte1 is not none): ucode = invalid_ucode except: ucode = invalid_unicode return ucode def from_ucode(ucode): # leave identity ascii map out of this table if ucode <= 0x7f: return invalid_jis # Missing from python map if ucode == 0xff5e: return bytes((0x8f, 0xa2, 0xb7)) try: return chr(ucode).encode('EUC_JP') except: return invalid_jis class Row: def __init__(self, byte0 = None, byte1 = None, map = None): self.row=[invalid_unicode]*256 self.byte0 = byte0 self.byte1 = byte1 self.first = 256 self.last = 0 for byte2 in range(0x0, 0x100): ucode = to_ucode(byte0, byte1, byte2) self.row[byte2] = ucode if ucode != invalid_unicode: if byte2 < self.first: self.first = byte2 if byte2 > self.last: self.last = byte2 if self.first > self.last: self.first = 1 self.last = 0 if map is not None: self.add_to_map(map) def dump(self): if self.byte0 is not None: print(f' /* {self.byte0:#04x} {self.byte1:#04x}: {self.first:#04x} - {self.last:#04x} */') else: print(f' /* {self.byte1:#04x}: {self.first:#04x} - {self.last:#04x}*/') start=' ' for byte2 in range(self.first//16*16, self.last+1): if byte2 % 16 == 15: end='\n' else: end='' if byte2 < self.first: print(f'{start:s} ', end=end) else: print(f'{start:s}{self.row[byte2]:#06x},', end='') if byte2 % 16 == 15: start='\n ' else: start=' ' print('') def add_to_map(self, map): for byte2 in range(self.first, self.last+1): if self.row[byte2] != invalid_unicode and self.row[byte2] not in map: map[self.row[byte2]] = to_code(self.byte0, self.byte1, byte2) class URow: def __init__(self, byte1, map): self.byte1 = byte1 self.first = 256 self.last = 0 self.row = [invalid_jis]*256 for byte2 in range(0x0, 0x100): ucode = self.byte1 * 256 + byte2 jis = from_ucode(ucode) bytes=b'' if jis != invalid_jis: bytes = jis if byte2 < self.first: self.first = byte2 if byte2 > self.last: self.last = byte2 self.row[byte2] = bytes if self.first > self.last: self.first = 1 self.last = 0 def value(self, byte2): v = self.row[byte2] if len(v) == 0: ret = invalid_jis elif len(v) == 1: ret = v[0] elif len(v) == 2: ret = v[0] * 256 + v[1] if ret and ret < 0x8000: print(f'weird return {ret:#06x}', file=sys.stderr) sys.exit(1) else: ret = v[1] * 256 + v[2] if ret and ret < 0x8000: print(f'weird return {ret:#06x}', file=sys.stderr) sys.exit(1) ret -= 0x8000 return ret def dump(self): print(f' /* {self.byte1:#04x}: {self.first:#04x} - {self.last:#04x} */') start=' ' for byte2 in range(self.first//16*16, self.last+1): if byte2 % 16 == 15: end='\n' else: end='' if byte2 < self.first: print(f'{start:s} ', end=end) else: value = self.row[byte2] print(f'{start:s}{self.value(byte2):#06x},', end='') if byte2 % 16 == 15: start='\n ' else: start=' ' print('') def rows(byte0 = None, map = None): rows = [None]*256 for byte1 in range(0x80, 0x100): rows[byte1] = Row(byte0 = byte0, byte1 = byte1, map=map) return rows def u_rows(map): rows = [None]*256 for byte1 in range(0x0, 0x100): rows[byte1] = URow(byte1, map) return rows unicode_to_jis = {} # These are easy to compute, so don't place them in the map #row_1byte = Row() #row_8e = Row(byte1 = 0x8e) # Add rows_2byte = rows(map = unicode_to_jis) rows_3byte = rows(byte0=0x8f, map=unicode_to_jis) rows_unicode = u_rows(unicode_to_jis) min_unicode = min(unicode_to_jis.keys()) max_unicode = max(unicode_to_jis.keys()) # Dump out 2 byte table def dump_2byte(name, rows, first = None, last = None, do_map=True): print('') print(f'/* {name} tables */') if first is None: for byte1 in range(0, 0x100): row = rows[byte1] if row and row.last >= row.first: first = byte1 break if last is None: for byte1 in range(0xff, -1, -1): row = rows[byte1] if row and row.last >= row.first: last = byte1 break print(f'#ifdef define_{name}') print('') if do_map: print(f'#define {head}{name}_first_row {first:#04x}') print(f'#define {head}{name}_last_row {last:#04x}') else: row = rows[first] print(f'#define {head}{name}_first_col {row.first:#04x}') print(f'#define {head}{name}_last_col {row.last:#04x}') print('') print(f'#ifndef split_{name}') print(f'#define split_{name}_offset 0') print(f'#endif') print('') print(f'static const uint16_t {head}{name}_codes[] = {{') offset = 0 first_col = 1 last_col = 0 dumped = False split = False for byte1 in range(first, last + 1): row = rows[byte1] if row: row.offset = offset row.split = split if row.last >= row.first: if not dumped: if byte1 != first: print(f'Table for {name} starts at {byte1:#04x} not {first:#04x}', file=sys.stderr) sys.exit(1) dumped = True else: print('') if not split and offset + (row.last + 1 - row.first) > split_codes: print(f'#ifdef split_{name}') print(f'}};') print('') print(f'#define split_{name}_offset {split_codes - offset} /* {split_codes:#06x} - {offset} */') print('') print(f'static const uint16_t {head}{name}_codes_second[] = {{') print(f'#endif') print('') row.split = True split = True row.dump() offset += (row.last + 1 - row.first) print(f'}};') if do_map: print(f'static const struct {struct_name} {head}{name}_map[] = {{') for byte1 in range(first, last + 1): row = rows[byte1] if row: offset = row.offset if row.first > row.last: offset=f'0xffff' elif row.split: offset=f'{row.offset:5d} + split_{name}_offset' else: offset=f'{row.offset:5d}' print(f' {{ .first = {row.first:#04x}, .last = {row.last:#04x}, .offset = {offset} }}, /* {byte1:#02x} */') else: print(f' {{ .first = 1, .last = 0, .offset = 0xffff }}') print(f'}};') print(f'#endif /* {name} */') print(f'''\ /* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This file is auto-generated from mk-jis-charsets.py */ /* clang-format off */ #ifndef _JIS_CHARSETS_H_ #define _JIS_CHARSETS_H_ struct {struct_name} {{ uint8_t first; uint8_t last; uint16_t offset; }}; #define {head}invalid_jis {invalid_jis:#06x} #define {head}invalid_unicode {invalid_unicode:#06x} #define {head}split_codes {split_codes:#06x}''') dump_2byte('unicode', rows_unicode, last=0x9f) dump_2byte('unicode_ff', rows_unicode, first=0xff, last=0xff, do_map=False) dump_2byte('jis_x0208', rows_2byte) dump_2byte('jis_x0213', rows_3byte) print('') print('#endif /* _JIS_CHARSETS_H_ */') picolibc-1.8.11/libc/stdlib/mk-sb-charsets.py000066400000000000000000000263421513574234600207760ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2025 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # ''' Generate single-byte translation tables ''' import copy import re georgian_ps = { 0x00: 0x0000, 0x01: 0x0001, 0x02: 0x0002, 0x03: 0x0003, 0x04: 0x0004, 0x05: 0x0005, 0x06: 0x0006, 0x07: 0x0007, 0x08: 0x0008, 0x09: 0x0009, 0x0a: 0x000A, 0x0b: 0x000B, 0x0c: 0x000C, 0x0d: 0x000D, 0x0e: 0x000E, 0x0f: 0x000F, 0x10: 0x0010, 0x11: 0x0011, 0x12: 0x0012, 0x13: 0x0013, 0x14: 0x0014, 0x15: 0x0015, 0x16: 0x0016, 0x17: 0x0017, 0x18: 0x0018, 0x19: 0x0019, 0x1a: 0x001A, 0x1b: 0x001B, 0x1c: 0x001C, 0x1d: 0x001D, 0x1e: 0x001E, 0x1f: 0x001F, 0x20: 0x0020, 0x21: 0x0021, 0x22: 0x0022, 0x23: 0x0023, 0x24: 0x0024, 0x25: 0x0025, 0x26: 0x0026, 0x27: 0x0027, 0x28: 0x0028, 0x29: 0x0029, 0x2a: 0x002A, 0x2b: 0x002B, 0x2c: 0x002C, 0x2d: 0x002D, 0x2e: 0x002E, 0x2f: 0x002F, 0x30: 0x0030, 0x31: 0x0031, 0x32: 0x0032, 0x33: 0x0033, 0x34: 0x0034, 0x35: 0x0035, 0x36: 0x0036, 0x37: 0x0037, 0x38: 0x0038, 0x39: 0x0039, 0x3a: 0x003A, 0x3b: 0x003B, 0x3c: 0x003C, 0x3d: 0x003D, 0x3e: 0x003E, 0x3f: 0x003F, 0x40: 0x0040, 0x41: 0x0041, 0x42: 0x0042, 0x43: 0x0043, 0x44: 0x0044, 0x45: 0x0045, 0x46: 0x0046, 0x47: 0x0047, 0x48: 0x0048, 0x49: 0x0049, 0x4a: 0x004A, 0x4b: 0x004B, 0x4c: 0x004C, 0x4d: 0x004D, 0x4e: 0x004E, 0x4f: 0x004F, 0x50: 0x0050, 0x51: 0x0051, 0x52: 0x0052, 0x53: 0x0053, 0x54: 0x0054, 0x55: 0x0055, 0x56: 0x0056, 0x57: 0x0057, 0x58: 0x0058, 0x59: 0x0059, 0x5a: 0x005A, 0x5b: 0x005B, 0x5c: 0x005C, 0x5d: 0x005D, 0x5e: 0x005E, 0x5f: 0x005F, 0x60: 0x0060, 0x61: 0x0061, 0x62: 0x0062, 0x63: 0x0063, 0x64: 0x0064, 0x65: 0x0065, 0x66: 0x0066, 0x67: 0x0067, 0x68: 0x0068, 0x69: 0x0069, 0x6a: 0x006A, 0x6b: 0x006B, 0x6c: 0x006C, 0x6d: 0x006D, 0x6e: 0x006E, 0x6f: 0x006F, 0x70: 0x0070, 0x71: 0x0071, 0x72: 0x0072, 0x73: 0x0073, 0x74: 0x0074, 0x75: 0x0075, 0x76: 0x0076, 0x77: 0x0077, 0x78: 0x0078, 0x79: 0x0079, 0x7a: 0x007A, 0x7b: 0x007B, 0x7c: 0x007C, 0x7d: 0x007D, 0x7e: 0x007E, 0x7f: 0x007F, 0x80: 0x0080, 0x81: 0x0081, 0x82: 0x201A, 0x83: 0x0192, 0x84: 0x201E, 0x85: 0x2026, 0x86: 0x2020, 0x87: 0x2021, 0x88: 0x02C6, 0x89: 0x2030, 0x8a: 0x0160, 0x8b: 0x2039, 0x8c: 0x0152, 0x8d: 0x008D, 0x8e: 0x008E, 0x8f: 0x008F, 0x90: 0x0090, 0x91: 0x2018, 0x92: 0x2019, 0x93: 0x201C, 0x94: 0x201D, 0x95: 0x2022, 0x96: 0x2013, 0x97: 0x2014, 0x98: 0x02DC, 0x99: 0x2122, 0x9a: 0x0161, 0x9b: 0x203A, 0x9c: 0x0153, 0x9d: 0x009D, 0x9e: 0x009E, 0x9f: 0x0178, 0xa0: 0x00A0, 0xa1: 0x00A1, 0xa2: 0x00A2, 0xa3: 0x00A3, 0xa4: 0x00A4, 0xa5: 0x00A5, 0xa6: 0x00A6, 0xa7: 0x00A7, 0xa8: 0x00A8, 0xa9: 0x00A9, 0xaa: 0x00AA, 0xab: 0x00AB, 0xac: 0x00AC, 0xad: 0x00AD, 0xae: 0x00AE, 0xaf: 0x00AF, 0xb0: 0x00B0, 0xb1: 0x00B1, 0xb2: 0x00B2, 0xb3: 0x00B3, 0xb4: 0x00B4, 0xb5: 0x00B5, 0xb6: 0x00B6, 0xb7: 0x00B7, 0xb8: 0x00B8, 0xb9: 0x00B9, 0xba: 0x00BA, 0xbb: 0x00BB, 0xbc: 0x00BC, 0xbd: 0x00BD, 0xbe: 0x00BE, 0xbf: 0x00BF, 0xc0: 0x10D0, 0xc1: 0x10D1, 0xc2: 0x10D2, 0xc3: 0x10D3, 0xc4: 0x10D4, 0xc5: 0x10D5, 0xc6: 0x10D6, 0xc7: 0x10F1, 0xc8: 0x10D7, 0xc9: 0x10D8, 0xca: 0x10D9, 0xcb: 0x10DA, 0xcc: 0x10DB, 0xcd: 0x10DC, 0xce: 0x10F2, 0xcf: 0x10DD, 0xd0: 0x10DE, 0xd1: 0x10DF, 0xd2: 0x10E0, 0xd3: 0x10E1, 0xd4: 0x10E2, 0xd5: 0x10F3, 0xd6: 0x10E3, 0xd7: 0x10E4, 0xd8: 0x10E5, 0xd9: 0x10E6, 0xda: 0x10E7, 0xdb: 0x10E8, 0xdc: 0x10E9, 0xdd: 0x10EA, 0xde: 0x10EB, 0xdf: 0x10EC, 0xe0: 0x10ED, 0xe1: 0x10EE, 0xe2: 0x10F4, 0xe3: 0x10EF, 0xe4: 0x10F0, 0xe5: 0x10F5, 0xe6: 0x00E6, 0xe7: 0x00E7, 0xe8: 0x00E8, 0xe9: 0x00E9, 0xea: 0x00EA, 0xeb: 0x00EB, 0xec: 0x00EC, 0xed: 0x00ED, 0xee: 0x00EE, 0xef: 0x00EF, 0xf0: 0x00F0, 0xf1: 0x00F1, 0xf2: 0x00F2, 0xf3: 0x00F3, 0xf4: 0x00F4, 0xf5: 0x00F5, 0xf6: 0x00F6, 0xf7: 0x00F7, 0xf8: 0x00F8, 0xf9: 0x00F9, 0xfa: 0x00FA, 0xfb: 0x00FB, 0xfc: 0x00FC, 0xfd: 0x00FD, 0xfe: 0x00FE, 0xff: 0x00FF, } def translate(code, encoding): try: if encoding == 'GEORGIAN-PS': ucode = georgian_ps[code] else: ucode = ord(bytes([code]).decode(encoding)) except: ucode = 0 return ucode def dump_range(encoding, base, start, end): name = encoding.replace('-', '_') print(" [ locale_%s - locale_%s ] = " % (name, base.replace('-', '_'))) print(" { ", end="") max_ucode = 0 for code in range(start, end + 1): if code == end: e = ' },\n' elif (code - start) % 8 == 7: e = ',\n ' else: e = ', ' ucode = translate(code, encoding) if ucode == 0: print("%d" % ucode, end = e) else: print("%#x" % ucode, end = e) if ucode > max_ucode: max_ucode = ucode return max_ucode def dump_table(): print('''/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This file is auto-generated from mk-sb-charsets.py */ /* clang-format off */ ''') max_ucode_iso = {} print('''#ifdef __MB_EXTENDED_CHARSETS_ISO /* Tables for the ISO-8859-x to UTF conversion. The first index into the table is a value computed from locale id - locale_ISO_8859-2 (ISO-8859-1 is not included as it doesn't require translation). The second index is the value of the incoming character - 0xa0. Values < 0xa0 don't have to be converted anyway. */ const uint16_t __iso_8859_conv[14][0x60] = {''') for val in (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16): encoding = 'ISO-8859-%d' % val max = dump_range(encoding, 'ISO_8859_2', 0xa0, 0xff) max_ucode_iso['locale_%s - locale_%s' % (encoding.replace('-','_'), 'ISO_8859_2')] = max print('};') print('const uint16_t __iso_8859_max[14] = {') for max in max_ucode_iso: print(" [%s] = %#x," % (max, max_ucode_iso[max])) print('};') print('#endif /* __MB_EXTENDED_CHARSETS_ISO */') print('') max_ucode_cp = {} print('''#ifdef __MB_EXTENDED_CHARSETS_WINDOWS /* Tables for the Windows default singlebyte ANSI codepage conversion. The first index into the table is a value computed from locale id minus locale_WINDOWS_BASE, the second index is the value of the incoming character - 0x80. Values < 0x80 don't have to be converted anyway. */ const uint16_t __cp_conv[27][0x80] = {''') for cp in ('CP437', 'CP720', 'CP737', 'CP775', 'CP850', 'CP852', 'CP855', 'CP857', 'CP858', 'CP862', 'CP866', 'CP874', 'CP1125', 'CP1250', 'CP1251', 'CP1252', 'CP1253', 'CP1254', 'CP1255', 'CP1256', 'CP1257', 'CP1258', 'CP20866', 'CP21866', 'CP101', 'CP102', 'CP103'): if cp == 'CP101': encoding = 'GEORGIAN-PS' elif cp == 'CP102': encoding = 'PT154' elif cp == 'CP103': encoding = 'KOI8-T' elif cp == 'CP20866': encoding = 'KOI8-R' elif cp == 'CP21866': encoding = 'KOI8-U' else: encoding = cp if cp == 'CP101': name = 'GEORGIAN_PS' elif cp == 'CP102': name = 'PT154' else: name = cp max = dump_range(encoding, 'WINDOWS_BASE', 0x80, 0xff) max_ucode_cp['locale_%s - locale_%s' % (encoding.replace('-','_'), 'WINDOWS_BASE')] = max print('};') print('const uint16_t __cp_max[27] = {') for max in max_ucode_cp: print(" [%s] = %#x," % (max, max_ucode_cp[max])) print('};') print('#endif /* __MB_EXTENDED_CHARSETS_WINDOWS */') print('') dump_table() picolibc-1.8.11/libc/stdlib/mprec.h000066400000000000000000000270601513574234600170560ustar00rootroot00000000000000/**************************************************************** * * The author of this software is David M. Gay. * * Copyright (c) 1991 by AT&T. * * Permission to use, copy, modify, and distribute this software for any * purpose without fee is hereby granted, provided that this entire notice * is included in all copies of any software which is or includes a copy * or modification of this software and in all copies of the supporting * documentation for such software. * * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. * ***************************************************************/ /* Please send bug reports to David M. Gay AT&T Bell Laboratories, Room 2C-463 600 Mountain Avenue Murray Hill, NJ 07974-2070 U.S.A. dmg@research.att.com or research!dmg */ #include #include #include #include #include #include #include "local.h" #ifdef __IEEE_LITTLE_ENDIAN #define IEEE_8087 #endif #ifdef __IEEE_BIG_ENDIAN #define IEEE_MC68k #endif #ifdef __Z8000__ #define Just_16 #endif #ifdef DEBUG #include "stdio.h" #define Bug(x) \ { \ fprintf(stderr, "%s\n", x); \ exit(1); \ } #endif #ifdef Unsigned_Shifts #define Sign_Extend(a, b) \ if (b < 0) \ a |= (__uint32_t)0xffff0000; #else #define Sign_Extend(a, b) /*no-op*/ #endif #if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1 Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined. #endif /* If we are going to examine or modify specific bits in a double using the word0 and/or word1 macros, then we must wrap the double inside a union. This is necessary to avoid undefined behavior according to the ANSI C spec. */ union double_union { double d; __uint32_t i[2]; }; #ifdef IEEE_8087 #define word0(x) (x.i[1]) #define word1(x) (x.i[0]) #else #define word0(x) (x.i[0]) #define word1(x) (x.i[1]) #endif /* The following is taken from gdtoaimp.h for use with new strtod, but adjusted to avoid invalid type-punning. */ typedef __int32_t Long; /* Unfortunately, because __ULong might be a different type than __uint32_t, we can't re-use union double_union as-is without further edits in strtod.c. */ typedef union { double d; __ULong i[2]; } U; #define dword0(x) word0(x) #define dword1(x) word1(x) #define dval(x) (x.d) #undef SI #ifdef Sudden_Underflow #define SI 1 #else #define SI 0 #endif #define Storeinc(a, b, c) (*(a)++ = ((b) << 16) | ((c) & 0xffff)) /* #define P DBL_MANT_DIG */ /* Ten_pmax = floor(P*log(2)/log(5)) */ /* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */ /* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */ /* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */ #if defined(IEEE_8087) + defined(IEEE_MC68k) #if defined(_DOUBLE_IS_32BITS) #define Exp_shift 23 #define Exp_shift1 23 #define Exp_msk1 ((__uint32_t)0x00800000L) #define Exp_msk11 ((__uint32_t)0x00800000L) #define Exp_mask ((__uint32_t)0x7f800000L) #define P 24 #define Bias 127 #define NO_HEX_FP /* not supported in this case */ #define IEEE_Arith #define Emin (-126) #define Exp_1 ((__uint32_t)0x3f800000L) #define Exp_11 ((__uint32_t)0x3f800000L) #define Ebits 8 #define Frac_mask ((__uint32_t)0x007fffffL) #define Frac_mask1 ((__uint32_t)0x007fffffL) #define Ten_pmax 10 #define Sign_bit ((__uint32_t)0x80000000L) #define Ten_pmax 10 #define Bletch 2 #define Bndry_mask ((__uint32_t)0x007fffffL) #define Bndry_mask1 ((__uint32_t)0x007fffffL) #define LSB 1 #define Sign_bit ((__uint32_t)0x80000000L) #define Log2P 1 #define Tiny0 0 #define Tiny1 1 #define Quick_max 5 #define Int_max 6 #define Infinite(x) (word0(x) == ((__uint32_t)0x7f800000L)) #undef word0 #undef word1 #undef dword0 #undef dword1 #define word0(x) (x.i[0]) #define word1(x) 0 #define dword0(x) word0(x) #define dword1(x) 0 #else #define Exp_shift 20 #define Exp_shift1 20 #define Exp_msk1 ((__uint32_t)0x100000L) #define Exp_msk11 ((__uint32_t)0x100000L) #define Exp_mask ((__uint32_t)0x7ff00000L) #define P 53 #define Bias 1023 #define IEEE_Arith #define Emin (-1022) #define Exp_1 ((__uint32_t)0x3ff00000L) #define Exp_11 ((__uint32_t)0x3ff00000L) #define Ebits 11 #define Frac_mask ((__uint32_t)0xfffffL) #define Frac_mask1 ((__uint32_t)0xfffffL) #define Ten_pmax 22 #define Bletch 0x10 #define Bndry_mask ((__uint32_t)0xfffffL) #define Bndry_mask1 ((__uint32_t)0xfffffL) #define LSB 1 #define Sign_bit ((__uint32_t)0x80000000L) #define Log2P 1 #define Tiny0 0 #define Tiny1 1 #define Quick_max 14 #define Int_max 14 #define Infinite(x) (word0(x) == ((__uint32_t)0x7ff00000L)) /* sufficient test for here */ #endif /* !_DOUBLE_IS_32BITS */ #ifndef Flt_Rounds #ifdef FLT_ROUNDS #define Flt_Rounds FLT_ROUNDS #else #define Flt_Rounds 1 #endif #endif /*Flt_Rounds*/ #else /* !IEEE_8087 && !IEEE_MC68k */ #undef Sudden_Underflow #define Sudden_Underflow #ifdef IBM #define Flt_Rounds 0 #define Exp_shift 24 #define Exp_shift1 24 #define Exp_msk1 ((__uint32_t)0x1000000L) #define Exp_msk11 ((__uint32_t)0x1000000L) #define Exp_mask ((__uint32_t)0x7f000000L) #define P 14 #define Bias 65 #define Exp_1 ((__uint32_t)0x41000000L) #define Exp_11 ((__uint32_t)0x41000000L) #define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */ #define Frac_mask ((__uint32_t)0xffffffL) #define Frac_mask1 ((__uint32_t)0xffffffL) #define Bletch 4 #define Ten_pmax 22 #define Bndry_mask ((__uint32_t)0xefffffL) #define Bndry_mask1 ((__uint32_t)0xffffffL) #define LSB 1 #define Sign_bit ((__uint32_t)0x80000000L) #define Log2P 4 #define Tiny0 ((__uint32_t)0x100000L) #define Tiny1 0 #define Quick_max 14 #define Int_max 15 #else /* VAX */ #define Flt_Rounds 1 #define Exp_shift 23 #define Exp_shift1 7 #define Exp_msk1 0x80 #define Exp_msk11 ((__uint32_t)0x800000L) #define Exp_mask ((__uint32_t)0x7f80L) #define P 56 #define Bias 129 #define Exp_1 ((__uint32_t)0x40800000L) #define Exp_11 ((__uint32_t)0x4080L) #define Ebits 8 #define Frac_mask ((__uint32_t)0x7fffffL) #define Frac_mask1 ((__uint32_t)0xffff007fL) #define Ten_pmax 24 #define Bletch 2 #define Bndry_mask ((__uint32_t)0xffff007fL) #define Bndry_mask1 ((__uint32_t)0xffff007fL) #define LSB ((__uint32_t)0x10000L) #define Sign_bit ((__uint32_t)0x8000L) #define Log2P 1 #define Tiny0 0x80 #define Tiny1 0 #define Quick_max 15 #define Int_max 15 #endif #endif #ifndef IEEE_Arith #define ROUND_BIASED #else #define Scale_Bit 0x10 #if defined(_DOUBLE_IS_32BITS) && defined(__v800) #define n_bigtens 2 #else #define n_bigtens 5 #endif #endif #ifdef IBM #define n_bigtens 3 #endif #ifdef VAX #define n_bigtens 2 #endif #ifndef __NO_INFNAN_CHECK #define INFNAN_CHECK #endif #ifdef RND_PRODQUOT #define rounded_product(a, b) a = rnd_prod(a, b) #define rounded_quotient(a, b) a = rnd_quot(a, b) #ifdef KR_headers extern double rnd_prod(), rnd_quot(); #else extern double rnd_prod(double, double), rnd_quot(double, double); #endif #else #define rounded_product(a, b) a *= b #define rounded_quotient(a, b) a /= b #endif #define Big0 (Frac_mask1 | Exp_msk1 * (DBL_MAX_EXP + Bias - 1)) #define Big1 ((__uint32_t)0xffffffffL) #ifndef Just_16 /* When Pack_32 is not defined, we store 16 bits per 32-bit long. * This makes some inner loops simpler and sometimes saves work * during multiplications, but it often seems to make things slightly * slower. Hence the default is now to store 32 bits per long. */ #ifndef Pack_32 #define Pack_32 #endif #else /* Just_16 */ #ifndef Pack_16 #define Pack_16 #endif #endif /* Just_16 */ #ifdef Pack_32 #define ULbits 32 #define kshift 5 #define kmask 31 #define ALL_ON 0xffffffff #else #define ULbits 16 #define kshift 4 #define kmask 15 #define ALL_ON 0xffff #endif typedef struct _Bigint _Bigint; #define Balloc _Balloc #define Bfree _Bfree #define multadd __multadd #define s2b __s2b #define lo0bits __lo0bits #define hi0bits __hi0bits #define i2b __i2b #define mult __multiply #define pow5mult __pow5mult #define lshift __lshift #define match __match #define cmp __mcmp #define diff __mdiff #define ulp __ulp #define b2d __b2d #define d2b __d2b #define ratio __ratio #define any_on __any_on #define gethex __gethex #define copybits __copybits #define hexnan __hexnan #if !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) #define __get_hexdig(x) __hexdig[x] /* NOTE: must evaluate arg only once */ #else /* !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && \ !defined(_SMALL_HEXDIG) */ #define __get_hexdig(x) __hexdig_fun(x) #endif /* !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && \ !defined(_SMALL_HEXDIG) */ #define tens __mprec_tens #define bigtens __mprec_bigtens #define tinytens __mprec_tinytens char *__alloc_dtoa_result(int len); int __mprec_register_exit(void); struct _Bigint { int _k, _maxwds, _sign, _wds; uint32_t _x[]; }; struct FPI; double ulp(double x); double b2d(_Bigint *a, int *e); _Bigint *Balloc(int k); void Bfree(_Bigint *v); _Bigint *multadd(_Bigint *, int, int); _Bigint *s2b(const char *, int, int, __ULong); _Bigint *i2b(int); _Bigint *mult(_Bigint *, _Bigint *); _Bigint *pow5mult(_Bigint *, int k); int hi0bits(__ULong); int lo0bits(__ULong *); _Bigint *d2b(double d, int *e, int *bits); _Bigint *lshift(_Bigint *b, int k); int match(const char **, char *); _Bigint *diff(_Bigint *a, _Bigint *b); int cmp(_Bigint *a, _Bigint *b); int gethex(const char **sp, const struct FPI *fpi, Long *exp, _Bigint **bp, int sign, locale_t loc); double ratio(_Bigint *a, _Bigint *b); __ULong any_on(_Bigint *b, int k); void copybits(__ULong *c, int n, _Bigint *b); double _strtod_l(const char *__restrict s00, char **__restrict se, locale_t loc); #if defined(__HAVE_LONG_DOUBLE) && !defined(_LDBL_EQ_DBL) || 1 int _strtorx_l(const char *, char **, int, void *, locale_t); int _strtodg_l(const char *s00, char **se, struct FPI *fpi, Long *exp, __ULong *bits, locale_t); #endif /* __HAVE_LONG_DOUBLE && !_LDBL_EQ_DBL */ #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) || defined(_SMALL_HEXDIG) unsigned char __hexdig_fun(unsigned char); #endif /* !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && \ !defined(_SMALL_HEXDIG) */ #ifdef INFNAN_CHECK int hexnan(const char **sp, const struct FPI *fpi, __ULong *x0); #endif #define Bcopy(x, y) \ memcpy((char *)&x->_sign, (char *)&y->_sign, y->_wds * sizeof(__Long) + 2 * sizeof(int)) extern const double tinytens[]; extern const double bigtens[]; extern const double tens[]; #if !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) extern const unsigned char __hexdig[]; #endif /* !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && \ !defined(_SMALL_HEXDIG) */ double _mprec_log10(int); picolibc-1.8.11/libc/stdlib/mrand48.c000066400000000000000000000012721513574234600172150ustar00rootroot00000000000000/* * Copyright (c) 1993 Martin Birgmeier * All rights reserved. * * You may redistribute unmodified or modified versions of this source * code provided that the above copyright notice and this and the * following conditions are retained. * * This software is provided ``as is'', and comes with no warranties * of any kind. I shall in no event be liable for anything that happens * to anyone/anything when using this software. */ #include "rand48.h" long _mrand48_r(struct _rand48 *r) { int32_t i; __dorand48(r, r->_seed); i = (int32_t)((uint32_t)(r->_seed[2]) << 16 | (uint32_t)(r->_seed[1])); return (long)i; } long mrand48(void) { return _mrand48_r(&_rand48); } picolibc-1.8.11/libc/stdlib/mul_overflow.h000066400000000000000000000020661513574234600204670ustar00rootroot00000000000000#if __HAVE_BUILTIN_MUL_OVERFLOW && !defined(__MSP430__) // gcc should use the correct one here #define mul_overflow __builtin_mul_overflow #else /** * Since __builtin_mul_overflow doesn't seem to exist, * use a (slower) software implementation instead. * This is only implemented for size_t, so in case mallocr.c's INTERNAL_SIZE_T * is non default, mallocr.c throws an #error. */ static int mul_overflow_size_t(size_t a, size_t b, size_t *res) { // always fill the result (gcc doesn't define what happens here) if (res) *res = a * b; // multiply with 0 can not overflow (and avoid div-by-zero): if (a == 0 || b == 0) return 0; #ifdef __MSP430__ volatile uint32_t ia = (uint32_t)a; volatile uint32_t ib = (uint32_t)b; // check if overflow would happen: if ((ia > SIZE_MAX / ib) || (ib > SIZE_MAX / ia)) { return 1; } #else // check if overflow would happen: if ((a > SIZE_MAX / b) || (b > SIZE_MAX / a)) { return 1; } #endif return 0; } #define mul_overflow mul_overflow_size_t #endif picolibc-1.8.11/libc/stdlib/nrand48.c000066400000000000000000000013161513574234600172150ustar00rootroot00000000000000/* * Copyright (c) 1993 Martin Birgmeier * All rights reserved. * * You may redistribute unmodified or modified versions of this source * code provided that the above copyright notice and this and the * following conditions are retained. * * This software is provided ``as is'', and comes with no warranties * of any kind. I shall in no event be liable for anything that happens * to anyone/anything when using this software. */ #include "rand48.h" long _nrand48_r(struct _rand48 *r, unsigned short xseed[3]) { __dorand48(r, xseed); return (long)((unsigned long)xseed[2] << 15) + ((unsigned long)xseed[1] >> 1); } long nrand48(unsigned short xseed[3]) { return _nrand48_r(&_rand48, xseed); } picolibc-1.8.11/libc/stdlib/onexit.c000066400000000000000000000035351513574234600172520ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2021 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include #include "local-onexit.h" #ifdef ENABLE_PICOLIBC_EXIT int on_exit(void (*func)(int, void *), void *arg) { union on_exit_func func_u = { .on_exit = func }; return _on_exit(PICO_ONEXIT_ONEXIT, func_u, arg); } #endif picolibc-1.8.11/libc/stdlib/posix-memalign.c000066400000000000000000000035111513574234600206670ustar00rootroot00000000000000/* * Copyright (c) 2012, 2013 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "local-malloc.h" int posix_memalign(void **memptr, size_t align, size_t size) { /* Return EINVAL if align isn't power of 2 or not a multiple of a pointer size */ if ((align & (align - 1)) != 0 || align % sizeof(void *) != 0 || align == 0) return EINVAL; void *mem = memalign(align, size); if (!mem) return ENOMEM; *memptr = mem; return 0; } picolibc-1.8.11/libc/stdlib/putenv.c000066400000000000000000000024321513574234600172600ustar00rootroot00000000000000/*- * Copyright (c) 1988 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that: (1) source distributions retain this entire copyright * notice and comment, and (2) distributions including binaries display * the following acknowledgement: ``This product includes software * developed by the University of California, Berkeley and its contributors'' * in the documentation or other materials provided with the distribution. * Neither the name of the University nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #define _DEFAULT_SOURCE #include #include int putenv(char *str) { register char *p, *equal; int rval; p = strdup(str); if (!p) return 1; if (!(equal = strchr(p, '='))) { (void)free(p); return 1; } *equal = '\0'; rval = setenv(p, equal + 1, 1); (void)free(p); return rval; } picolibc-1.8.11/libc/stdlib/pvalloc.c000066400000000000000000000032221513574234600173750ustar00rootroot00000000000000/* * Copyright (c) 2012, 2013 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "local-malloc.h" void * pvalloc(size_t s) { if (s > MALLOC_MAXSIZE - MALLOC_PAGE_ALIGN) { errno = ENOMEM; return NULL; } return valloc(__align_up(s, MALLOC_PAGE_ALIGN)); } picolibc-1.8.11/libc/stdlib/rand.c000066400000000000000000000037501513574234600166670ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* FUNCTION <>, <>---pseudo-random numbers INDEX rand INDEX srand INDEX rand_r SYNOPSIS #include int rand(void); void srand(unsigned int <[seed]>); int rand_r(unsigned int *<[seed]>); DESCRIPTION <> returns a different integer each time it is called; each integer is chosen by an algorithm designed to be unpredictable, so that you can use <> when you require a random number. The algorithm depends on a static variable called the ``random seed''; starting with a given value of the random seed always produces the same sequence of numbers in successive calls to <>. You can set the random seed using <>; it does nothing beyond storing its argument in the static variable used by <>. You can exploit this to make the pseudo-random sequence less predictable, if you wish, by using some other unpredictable value (often the least significant parts of a time-varying value) as the random seed before beginning a sequence of calls to <>; or, if you wish to ensure (for example, while debugging) that successive runs of your program use the same ``random'' numbers, you can use <> to set the same random seed at the outset. RETURNS <> returns the next pseudo-random integer in sequence; it is a number between <<0>> and <> (inclusive). <> does not return a result. NOTES <> and <> are unsafe for multi-threaded applications. <> is thread-safe and should be used instead. PORTABILITY <> is required by ANSI, but the algorithm for pseudo-random number generation is not specified; therefore, even if you use the same random seed, you cannot expect the same sequence of results on two different systems. <> requires no supporting OS subroutines. */ #define _DEFAULT_SOURCE #include int rand(void) { return (int)(random() & RAND_MAX); } picolibc-1.8.11/libc/stdlib/rand48.c000066400000000000000000000125641513574234600170460ustar00rootroot00000000000000/* * Copyright (c) 1993 Martin Birgmeier * All rights reserved. * * You may redistribute unmodified or modified versions of this source * code provided that the above copyright notice and this and the * following conditions are retained. * * This software is provided ``as is'', and comes with no warranties * of any kind. I shall in no event be liable for anything that happens * to anyone/anything when using this software. */ /* FUNCTION <>, <>, <>, <>, <>, <>, <>, <>, <>, <>---pseudo-random number generators and initialization routines INDEX rand48 INDEX drand48 INDEX erand48 INDEX lrand48 INDEX nrand48 INDEX mrand48 INDEX jrand48 INDEX srand48 INDEX seed48 INDEX lcong48 SYNOPSIS #include double drand48(void); double erand48(unsigned short <[xseed]>[3]); long lrand48(void); long nrand48(unsigned short <[xseed]>[3]); long mrand48(void); long jrand48(unsigned short <[xseed]>[3]); void srand48(long <[seed]>); unsigned short *seed48(unsigned short <[xseed]>[3]); void lcong48(unsigned short <[p]>[7]); DESCRIPTION The <> family of functions generates pseudo-random numbers using a linear congruential algorithm working on integers 48 bits in size. The particular formula employed is r(n+1) = (a * r(n) + c) mod m where the default values are for the multiplicand a = 0xfdeece66d = 25214903917 and the addend c = 0xb = 11. The modulo is always fixed at m = 2 ** 48. r(n) is called the seed of the random number generator. For all the six generator routines described next, the first computational step is to perform a single iteration of the algorithm. <> and <> return values of type double. The full 48 bits of r(n+1) are loaded into the mantissa of the returned value, with the exponent set such that the values produced lie in the interval [0.0, 1.0]. <> and <> return values of type long in the range [0, 2**31-1]. The high-order (31) bits of r(n+1) are loaded into the lower bits of the returned value, with the topmost (sign) bit set to zero. <> and <> return values of type long in the range [-2**31, 2**31-1]. The high-order (32) bits of r(n+1) are loaded into the returned value. <>, <>, and <> use an internal buffer to store r(n). For these functions the initial value of r(0) = 0x1234abcd330e = 20017429951246. On the other hand, <>, <>, and <> use a user-supplied buffer to store the seed r(n), which consists of an array of 3 shorts, where the zeroth member holds the least significant bits. All functions share the same multiplicand and addend. <> is used to initialize the internal buffer r(n) of <>, <>, and <> such that the 32 bits of the seed value are copied into the upper 32 bits of r(n), with the lower 16 bits of r(n) arbitrarily being set to 0x330e. Additionally, the constant multiplicand and addend of the algorithm are reset to the default values given above. <> also initializes the internal buffer r(n) of <>, <>, and <>, but here all 48 bits of the seed can be specified in an array of 3 shorts, where the zeroth member specifies the lowest bits. Again, the constant multiplicand and addend of the algorithm are reset to the default values given above. <> returns a pointer to an array of 3 shorts which contains the old seed. This array is statically allocated, thus its contents are lost after each new call to <>. Finally, <> allows full control over the multiplicand and addend used in <>, <>, <>, <>, <>, and <>, and the seed used in <>, <>, and <>. An array of 7 shorts is passed as parameter; the first three shorts are used to initialize the seed; the second three are used to initialize the multiplicand; and the last short is used to initialize the addend. It is thus not possible to use values greater than 0xffff as the addend. Note that all three methods of seeding the random number generator always also set the multiplicand and addend for any of the six generator calls. For a more powerful random number generator, see <>. PORTABILITY SUS requires these functions. No supporting OS subroutines are required. */ #include "rand48.h" __THREAD_LOCAL struct _rand48 _rand48 = { ._seed = { _RAND48_SEED_0, _RAND48_SEED_1, _RAND48_SEED_2 }, ._mult = { _RAND48_MULT_0, _RAND48_MULT_1, _RAND48_MULT_2 }, ._add = _RAND48_ADD, }; void __dorand48(struct _rand48 *r, unsigned short xseed[3]) { uint32_t accu; unsigned short temp[2]; accu = (uint32_t)r->_mult[0] * (uint32_t)xseed[0] + (uint32_t)r->_add; temp[0] = (unsigned short)accu; /* lower 16 bits */ accu >>= sizeof(unsigned short) * 8; accu += (uint32_t)r->_mult[0] * (uint32_t)xseed[1] + (uint32_t)r->_mult[1] * (uint32_t)xseed[0]; temp[1] = (unsigned short)accu; /* middle 16 bits */ accu >>= sizeof(unsigned short) * 8; accu += (uint32_t)r->_mult[0] * (uint32_t)xseed[2] + (uint32_t)r->_mult[1] * (uint32_t)xseed[1] + (uint32_t)r->_mult[2] * (uint32_t)xseed[0]; xseed[0] = temp[0]; xseed[1] = temp[1]; xseed[2] = (unsigned short)accu; } picolibc-1.8.11/libc/stdlib/rand48.h000066400000000000000000000027601513574234600170500ustar00rootroot00000000000000/* * Copyright (c) 1993 Martin Birgmeier * All rights reserved. * * You may redistribute unmodified or modified versions of this source * code provided that the above copyright notice and this and the * following conditions are retained. * * This software is provided ``as is'', and comes with no warranties * of any kind. I shall in no event be liable for anything that happens * to anyone/anything when using this software. */ #ifndef _RAND48_H_ #define _RAND48_H_ #define _DEFAULT_SOURCE #include #include #include /* * rand48 family support * * Copyright (c) 1993 Martin Birgmeier * All rights reserved. * * You may redistribute unmodified or modified versions of this source * code provided that the above copyright notice and this and the * following conditions are retained. * * This software is provided ``as is'', and comes with no warranties * of any kind. I shall in no event be liable for anything that happens * to anyone/anything when using this software. */ #define _RAND48_SEED_0 (0x330e) #define _RAND48_SEED_1 (0xabcd) #define _RAND48_SEED_2 (0x1234) #define _RAND48_MULT_0 (0xe66d) #define _RAND48_MULT_1 (0xdeec) #define _RAND48_MULT_2 (0x0005) #define _RAND48_ADD (0x000b) struct _rand48 { unsigned short _seed[3]; unsigned short _mult[3]; unsigned short _add; }; extern __THREAD_LOCAL struct _rand48 _rand48; extern void __dorand48(struct _rand48 *r, unsigned short[3]); #endif /* _RAND48_H_ */ picolibc-1.8.11/libc/stdlib/rand_r.c000066400000000000000000000016611513574234600172070ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ #define _DEFAULT_SOURCE #include /* Pseudo-random generator based on Minimal Standard by Lewis, Goodman, and Miller in 1969. I[j+1] = a*I[j] (mod m) where a = 16807 m = 2147483647 Using Schrage's algorithm, a*I[j] (mod m) can be rewritten as: a*(I[j] mod q) - r*{I[j]/q} if >= 0 a*(I[j] mod q) - r*{I[j]/q} + m otherwise where: {} denotes integer division q = {m/a} = 127773 r = m (mod a) = 2836 note that the seed value of 0 cannot be used in the calculation as it results in 0 itself */ int rand_r(unsigned int *seed) { long k; long s = (long)(*seed); if (s == 0) s = 0x12345987; k = s / 127773; s = 16807 * (s - k * 127773) - 2836 * k; if (s < 0) s += 2147483647; (*seed) = (unsigned int)s; return (int)(s & RAND_MAX); } picolibc-1.8.11/libc/stdlib/random.c000066400000000000000000000042241513574234600172200ustar00rootroot00000000000000/* Copyright (c) 2016 Joel Sherrill */ /* FUNCTION <>, <>---pseudo-random numbers INDEX random INDEX srandom SYNOPSIS #define _XOPEN_SOURCE 500 #include long int random(void); void srandom(unsigned int <[seed]>); DESCRIPTION <> returns a different integer each time it is called; each integer is chosen by an algorithm designed to be unpredictable, so that you can use <> when you require a random number. The algorithm depends on a static variable called the ``random seed''; starting with a given value of the random seed always produces the same sequence of numbers in successive calls to <>. You can set the random seed using <>; it does nothing beyond storing its argument in the static variable used by <>. You can exploit this to make the pseudo-random sequence less predictable, if you wish, by using some other unpredictable value (often the least significant parts of a time-varying value) as the random seed before beginning a sequence of calls to <>; or, if you wish to ensure (for example, while debugging) that successive runs of your program use the same ``random'' numbers, you can use <> to set the same random seed at the outset. RETURNS <> returns the next pseudo-random integer in sequence; it is a number between <<0>> and <<2**31 - 1>> (inclusive). <> does not return a result. NOTES <> and <> are unsafe for multi-threaded applications. _XOPEN_SOURCE may be any value >= 500. PORTABILITY <> is required by XSI. This implementation uses the same algorithm as <>. <> requires no supporting OS subroutines. */ #define _DEFAULT_SOURCE #include #include __THREAD_LOCAL uint64_t _rand_next = 1; long int random(void) { /* This multiplier was obtained from Knuth, D.E., "The Art of Computer Programming," Vol 2, Seminumerical Algorithms, Third Edition, Addison-Wesley, 1998, p. 106 (line 26) & p. 108 */ _rand_next = _rand_next * 6364136223846793005ULL + 1; return (long int)((_rand_next >> 32) & 0x7fffffffL); } picolibc-1.8.11/libc/stdlib/realloc.c000066400000000000000000000076551513574234600173740ustar00rootroot00000000000000/* * Copyright (c) 2012, 2013 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "local-malloc.h" /* * Implement either by merging adjacent free memory * or by calling malloc/memcpy */ void * realloc(void *ptr, size_t size) { void *mem; if (ptr == NULL) return malloc(size); if (size == 0) { free(ptr); return NULL; } if (size > MALLOC_MAXSIZE) { errno = ENOMEM; return NULL; } size_t new_size = chunk_size(size); chunk_t *p_to_realloc = ptr_to_chunk(ptr); #if MALLOC_DEBUG __malloc_validate_block(p_to_realloc); #endif size_t old_size = _size(p_to_realloc); /* See if we can avoid allocating new memory * when increasing the size */ if (new_size > old_size) { void *chunk_e = chunk_end(p_to_realloc); MALLOC_LOCK; if (__malloc_grow_chunk(p_to_realloc, new_size)) { /* clear new memory */ memset(chunk_e, '\0', new_size - old_size); /* adjust chunk_t size */ old_size = new_size; } else { chunk_t **p, *r; /* Check to see if there's a chunk_t of free space just past * the current block, merge it in in case that's useful */ for (p = &__malloc_free_list; (r = *p) != NULL; p = &r->next) { if (r == chunk_e) { size_t r_size = _size(r); /* remove R from the free list */ *p = r->next; /* clear the memory from r */ memset(r, '\0', r_size); /* add it's size to our block */ old_size += r_size; _set_size(p_to_realloc, old_size); break; } if (p_to_realloc < r) break; } } MALLOC_UNLOCK; } if (new_size <= old_size) { size_t extra = old_size - new_size; #ifdef __MALLOC_CLEAR_FREED if (extra > MALLOC_HEAD) memset((char *)ptr + new_size, 0, extra - MALLOC_HEAD); #endif /* If there's enough space left over, split it out * and free it */ if (extra >= MALLOC_MINSIZE) { _set_size(p_to_realloc, new_size); make_free_chunk(chunk_after(p_to_realloc), extra); } return ptr; } /* No short cuts, allocate new memory and copy */ mem = malloc(size); if (!mem) return NULL; memcpy(mem, ptr, old_size - MALLOC_HEAD); free(ptr); return mem; } picolibc-1.8.11/libc/stdlib/reallocarray.c000066400000000000000000000022631513574234600204210ustar00rootroot00000000000000/* $OpenBSD: reallocarray.c,v 1.2 2014/12/08 03:45:00 bcook Exp $ */ /* * Copyright (c) 2008 Otto Moerbeek * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #define _DEFAULT_SOURCE #include #include #include #include #include "mul_overflow.h" void * reallocarray(void *optr, size_t nmemb, size_t size) { size_t bytes; if (mul_overflow(nmemb, size, &bytes)) { errno = ENOMEM; return NULL; } return realloc(optr, bytes); } picolibc-1.8.11/libc/stdlib/reallocf.c000066400000000000000000000031051513574234600175240ustar00rootroot00000000000000/*- * Copyright (c) 1998, M. Warner Losh * 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. */ /* Documented in malloc.c. */ #define _DEFAULT_SOURCE #include void * reallocf(void *ptr, size_t size) { void *nptr; nptr = realloc(ptr, size); if (!nptr && ptr) free(ptr); return (nptr); } picolibc-1.8.11/libc/stdlib/rpmatch.c000066400000000000000000000051071513574234600173770ustar00rootroot00000000000000/* FUNCTION <>---determine whether response to question is affirmative or negative INDEX rpmatch SYNOPSIS #include int rpmatch(const char *<[response]>); DESCRIPTION The <> function determines whether <[response]> is an affirmative or negative response to a question according to the current locale. RETURNS <> returns 1 if <[response]> is affirmative, 0 if negative, or -1 if not recognized as either. PORTABILITY <> is a BSD extension also found in glibc. NOTES No supporting OS subroutines are required. */ /* This code is originally taken from FreeBSD. */ /*- * Copyright (c) 2004-2005 Tim J. Robbins. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include #include #include #include int rpmatch(const char *response) { regex_t yes, no; int ret; if (regcomp(&yes, nl_langinfo(YESEXPR), REG_EXTENDED | REG_NOSUB) != 0) return (-1); if (regcomp(&no, nl_langinfo(NOEXPR), REG_EXTENDED | REG_NOSUB) != 0) { regfree(&yes); return (-1); } if (regexec(&yes, response, 0, NULL, 0) == 0) ret = 1; else if (regexec(&no, response, 0, NULL, 0) == 0) ret = 0; else ret = -1; regfree(&yes); regfree(&no); return (ret); } picolibc-1.8.11/libc/stdlib/sb_charsets.c000066400000000000000000000002561513574234600202410ustar00rootroot00000000000000/* Copyright (c) 2009 Corinna Vinschen */ #include #include "local.h" #ifdef __MB_CAPABLE #include "sb_charsets.h" #endif /* __MB_CAPABLE */ picolibc-1.8.11/libc/stdlib/sb_charsets.h000066400000000000000000001201621513574234600202450ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* This file is auto-generated from mk-sb-charsets.py */ /* clang-format off */ #ifdef __MB_EXTENDED_CHARSETS_ISO /* Tables for the ISO-8859-x to UTF conversion. The first index into the table is a value computed from locale id - locale_ISO_8859-2 (ISO-8859-1 is not included as it doesn't require translation). The second index is the value of the incoming character - 0xa0. Values < 0xa0 don't have to be converted anyway. */ const uint16_t __iso_8859_conv[14][0x60] = { [ locale_ISO_8859_2 - locale_ISO_8859_2 ] = { 0xa0, 0x104, 0x2d8, 0x141, 0xa4, 0x13d, 0x15a, 0xa7, 0xa8, 0x160, 0x15e, 0x164, 0x179, 0xad, 0x17d, 0x17b, 0xb0, 0x105, 0x2db, 0x142, 0xb4, 0x13e, 0x15b, 0x2c7, 0xb8, 0x161, 0x15f, 0x165, 0x17a, 0x2dd, 0x17e, 0x17c, 0x154, 0xc1, 0xc2, 0x102, 0xc4, 0x139, 0x106, 0xc7, 0x10c, 0xc9, 0x118, 0xcb, 0x11a, 0xcd, 0xce, 0x10e, 0x110, 0x143, 0x147, 0xd3, 0xd4, 0x150, 0xd6, 0xd7, 0x158, 0x16e, 0xda, 0x170, 0xdc, 0xdd, 0x162, 0xdf, 0x155, 0xe1, 0xe2, 0x103, 0xe4, 0x13a, 0x107, 0xe7, 0x10d, 0xe9, 0x119, 0xeb, 0x11b, 0xed, 0xee, 0x10f, 0x111, 0x144, 0x148, 0xf3, 0xf4, 0x151, 0xf6, 0xf7, 0x159, 0x16f, 0xfa, 0x171, 0xfc, 0xfd, 0x163, 0x2d9 }, [ locale_ISO_8859_3 - locale_ISO_8859_2 ] = { 0xa0, 0x126, 0x2d8, 0xa3, 0xa4, 0, 0x124, 0xa7, 0xa8, 0x130, 0x15e, 0x11e, 0x134, 0xad, 0, 0x17b, 0xb0, 0x127, 0xb2, 0xb3, 0xb4, 0xb5, 0x125, 0xb7, 0xb8, 0x131, 0x15f, 0x11f, 0x135, 0xbd, 0, 0x17c, 0xc0, 0xc1, 0xc2, 0, 0xc4, 0x10a, 0x108, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0, 0xd1, 0xd2, 0xd3, 0xd4, 0x120, 0xd6, 0xd7, 0x11c, 0xd9, 0xda, 0xdb, 0xdc, 0x16c, 0x15c, 0xdf, 0xe0, 0xe1, 0xe2, 0, 0xe4, 0x10b, 0x109, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0, 0xf1, 0xf2, 0xf3, 0xf4, 0x121, 0xf6, 0xf7, 0x11d, 0xf9, 0xfa, 0xfb, 0xfc, 0x16d, 0x15d, 0x2d9 }, [ locale_ISO_8859_4 - locale_ISO_8859_2 ] = { 0xa0, 0x104, 0x138, 0x156, 0xa4, 0x128, 0x13b, 0xa7, 0xa8, 0x160, 0x112, 0x122, 0x166, 0xad, 0x17d, 0xaf, 0xb0, 0x105, 0x2db, 0x157, 0xb4, 0x129, 0x13c, 0x2c7, 0xb8, 0x161, 0x113, 0x123, 0x167, 0x14a, 0x17e, 0x14b, 0x100, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0x12e, 0x10c, 0xc9, 0x118, 0xcb, 0x116, 0xcd, 0xce, 0x12a, 0x110, 0x145, 0x14c, 0x136, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0x172, 0xda, 0xdb, 0xdc, 0x168, 0x16a, 0xdf, 0x101, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0x12f, 0x10d, 0xe9, 0x119, 0xeb, 0x117, 0xed, 0xee, 0x12b, 0x111, 0x146, 0x14d, 0x137, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0x173, 0xfa, 0xfb, 0xfc, 0x169, 0x16b, 0x2d9 }, [ locale_ISO_8859_5 - locale_ISO_8859_2 ] = { 0xa0, 0x401, 0x402, 0x403, 0x404, 0x405, 0x406, 0x407, 0x408, 0x409, 0x40a, 0x40b, 0x40c, 0xad, 0x40e, 0x40f, 0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417, 0x418, 0x419, 0x41a, 0x41b, 0x41c, 0x41d, 0x41e, 0x41f, 0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427, 0x428, 0x429, 0x42a, 0x42b, 0x42c, 0x42d, 0x42e, 0x42f, 0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437, 0x438, 0x439, 0x43a, 0x43b, 0x43c, 0x43d, 0x43e, 0x43f, 0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447, 0x448, 0x449, 0x44a, 0x44b, 0x44c, 0x44d, 0x44e, 0x44f, 0x2116, 0x451, 0x452, 0x453, 0x454, 0x455, 0x456, 0x457, 0x458, 0x459, 0x45a, 0x45b, 0x45c, 0xa7, 0x45e, 0x45f }, [ locale_ISO_8859_6 - locale_ISO_8859_2 ] = { 0xa0, 0, 0, 0, 0xa4, 0, 0, 0, 0, 0, 0, 0, 0x60c, 0xad, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x61b, 0, 0, 0, 0x61f, 0, 0x621, 0x622, 0x623, 0x624, 0x625, 0x626, 0x627, 0x628, 0x629, 0x62a, 0x62b, 0x62c, 0x62d, 0x62e, 0x62f, 0x630, 0x631, 0x632, 0x633, 0x634, 0x635, 0x636, 0x637, 0x638, 0x639, 0x63a, 0, 0, 0, 0, 0, 0x640, 0x641, 0x642, 0x643, 0x644, 0x645, 0x646, 0x647, 0x648, 0x649, 0x64a, 0x64b, 0x64c, 0x64d, 0x64e, 0x64f, 0x650, 0x651, 0x652, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, [ locale_ISO_8859_7 - locale_ISO_8859_2 ] = { 0xa0, 0x2018, 0x2019, 0xa3, 0x20ac, 0x20af, 0xa6, 0xa7, 0xa8, 0xa9, 0x37a, 0xab, 0xac, 0xad, 0, 0x2015, 0xb0, 0xb1, 0xb2, 0xb3, 0x384, 0x385, 0x386, 0xb7, 0x388, 0x389, 0x38a, 0xbb, 0x38c, 0xbd, 0x38e, 0x38f, 0x390, 0x391, 0x392, 0x393, 0x394, 0x395, 0x396, 0x397, 0x398, 0x399, 0x39a, 0x39b, 0x39c, 0x39d, 0x39e, 0x39f, 0x3a0, 0x3a1, 0, 0x3a3, 0x3a4, 0x3a5, 0x3a6, 0x3a7, 0x3a8, 0x3a9, 0x3aa, 0x3ab, 0x3ac, 0x3ad, 0x3ae, 0x3af, 0x3b0, 0x3b1, 0x3b2, 0x3b3, 0x3b4, 0x3b5, 0x3b6, 0x3b7, 0x3b8, 0x3b9, 0x3ba, 0x3bb, 0x3bc, 0x3bd, 0x3be, 0x3bf, 0x3c0, 0x3c1, 0x3c2, 0x3c3, 0x3c4, 0x3c5, 0x3c6, 0x3c7, 0x3c8, 0x3c9, 0x3ca, 0x3cb, 0x3cc, 0x3cd, 0x3ce, 0 }, [ locale_ISO_8859_8 - locale_ISO_8859_2 ] = { 0xa0, 0, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xd7, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xf7, 0xbb, 0xbc, 0xbd, 0xbe, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2017, 0x5d0, 0x5d1, 0x5d2, 0x5d3, 0x5d4, 0x5d5, 0x5d6, 0x5d7, 0x5d8, 0x5d9, 0x5da, 0x5db, 0x5dc, 0x5dd, 0x5de, 0x5df, 0x5e0, 0x5e1, 0x5e2, 0x5e3, 0x5e4, 0x5e5, 0x5e6, 0x5e7, 0x5e8, 0x5e9, 0x5ea, 0, 0, 0x200e, 0x200f, 0 }, [ locale_ISO_8859_9 - locale_ISO_8859_2 ] = { 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0x11e, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0x130, 0x15e, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0x11f, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0x131, 0x15f, 0xff }, [ locale_ISO_8859_10 - locale_ISO_8859_2 ] = { 0xa0, 0x104, 0x112, 0x122, 0x12a, 0x128, 0x136, 0xa7, 0x13b, 0x110, 0x160, 0x166, 0x17d, 0xad, 0x16a, 0x14a, 0xb0, 0x105, 0x113, 0x123, 0x12b, 0x129, 0x137, 0xb7, 0x13c, 0x111, 0x161, 0x167, 0x17e, 0x2015, 0x16b, 0x14b, 0x100, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0x12e, 0x10c, 0xc9, 0x118, 0xcb, 0x116, 0xcd, 0xce, 0xcf, 0xd0, 0x145, 0x14c, 0xd3, 0xd4, 0xd5, 0xd6, 0x168, 0xd8, 0x172, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0x101, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0x12f, 0x10d, 0xe9, 0x119, 0xeb, 0x117, 0xed, 0xee, 0xef, 0xf0, 0x146, 0x14d, 0xf3, 0xf4, 0xf5, 0xf6, 0x169, 0xf8, 0x173, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0x138 }, [ locale_ISO_8859_11 - locale_ISO_8859_2 ] = { 0xa0, 0xe01, 0xe02, 0xe03, 0xe04, 0xe05, 0xe06, 0xe07, 0xe08, 0xe09, 0xe0a, 0xe0b, 0xe0c, 0xe0d, 0xe0e, 0xe0f, 0xe10, 0xe11, 0xe12, 0xe13, 0xe14, 0xe15, 0xe16, 0xe17, 0xe18, 0xe19, 0xe1a, 0xe1b, 0xe1c, 0xe1d, 0xe1e, 0xe1f, 0xe20, 0xe21, 0xe22, 0xe23, 0xe24, 0xe25, 0xe26, 0xe27, 0xe28, 0xe29, 0xe2a, 0xe2b, 0xe2c, 0xe2d, 0xe2e, 0xe2f, 0xe30, 0xe31, 0xe32, 0xe33, 0xe34, 0xe35, 0xe36, 0xe37, 0xe38, 0xe39, 0xe3a, 0, 0, 0, 0, 0xe3f, 0xe40, 0xe41, 0xe42, 0xe43, 0xe44, 0xe45, 0xe46, 0xe47, 0xe48, 0xe49, 0xe4a, 0xe4b, 0xe4c, 0xe4d, 0xe4e, 0xe4f, 0xe50, 0xe51, 0xe52, 0xe53, 0xe54, 0xe55, 0xe56, 0xe57, 0xe58, 0xe59, 0xe5a, 0xe5b, 0, 0, 0, 0 }, [ locale_ISO_8859_13 - locale_ISO_8859_2 ] = { 0xa0, 0x201d, 0xa2, 0xa3, 0xa4, 0x201e, 0xa6, 0xa7, 0xd8, 0xa9, 0x156, 0xab, 0xac, 0xad, 0xae, 0xc6, 0xb0, 0xb1, 0xb2, 0xb3, 0x201c, 0xb5, 0xb6, 0xb7, 0xf8, 0xb9, 0x157, 0xbb, 0xbc, 0xbd, 0xbe, 0xe6, 0x104, 0x12e, 0x100, 0x106, 0xc4, 0xc5, 0x118, 0x112, 0x10c, 0xc9, 0x179, 0x116, 0x122, 0x136, 0x12a, 0x13b, 0x160, 0x143, 0x145, 0xd3, 0x14c, 0xd5, 0xd6, 0xd7, 0x172, 0x141, 0x15a, 0x16a, 0xdc, 0x17b, 0x17d, 0xdf, 0x105, 0x12f, 0x101, 0x107, 0xe4, 0xe5, 0x119, 0x113, 0x10d, 0xe9, 0x17a, 0x117, 0x123, 0x137, 0x12b, 0x13c, 0x161, 0x144, 0x146, 0xf3, 0x14d, 0xf5, 0xf6, 0xf7, 0x173, 0x142, 0x15b, 0x16b, 0xfc, 0x17c, 0x17e, 0x2019 }, [ locale_ISO_8859_14 - locale_ISO_8859_2 ] = { 0xa0, 0x1e02, 0x1e03, 0xa3, 0x10a, 0x10b, 0x1e0a, 0xa7, 0x1e80, 0xa9, 0x1e82, 0x1e0b, 0x1ef2, 0xad, 0xae, 0x178, 0x1e1e, 0x1e1f, 0x120, 0x121, 0x1e40, 0x1e41, 0xb6, 0x1e56, 0x1e81, 0x1e57, 0x1e83, 0x1e60, 0x1ef3, 0x1e84, 0x1e85, 0x1e61, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0x174, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0x1e6a, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0x176, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0x175, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0x1e6b, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0x177, 0xff }, [ locale_ISO_8859_15 - locale_ISO_8859_2 ] = { 0xa0, 0xa1, 0xa2, 0xa3, 0x20ac, 0xa5, 0x160, 0xa7, 0x161, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0x17d, 0xb5, 0xb6, 0xb7, 0x17e, 0xb9, 0xba, 0xbb, 0x152, 0x153, 0x178, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }, [ locale_ISO_8859_16 - locale_ISO_8859_2 ] = { 0xa0, 0x104, 0x105, 0x141, 0x20ac, 0x201e, 0x160, 0xa7, 0x161, 0xa9, 0x218, 0xab, 0x179, 0xad, 0x17a, 0x17b, 0xb0, 0xb1, 0x10c, 0x142, 0x17d, 0x201d, 0xb6, 0xb7, 0x17e, 0x10d, 0x219, 0xbb, 0x152, 0x153, 0x178, 0x17c, 0xc0, 0xc1, 0xc2, 0x102, 0xc4, 0x106, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0x110, 0x143, 0xd2, 0xd3, 0xd4, 0x150, 0xd6, 0x15a, 0x170, 0xd9, 0xda, 0xdb, 0xdc, 0x118, 0x21a, 0xdf, 0xe0, 0xe1, 0xe2, 0x103, 0xe4, 0x107, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0x111, 0x144, 0xf2, 0xf3, 0xf4, 0x151, 0xf6, 0x15b, 0x171, 0xf9, 0xfa, 0xfb, 0xfc, 0x119, 0x21b, 0xff }, }; const uint16_t __iso_8859_max[14] = { [locale_ISO_8859_2 - locale_ISO_8859_2] = 0x2dd, [locale_ISO_8859_3 - locale_ISO_8859_2] = 0x2d9, [locale_ISO_8859_4 - locale_ISO_8859_2] = 0x2db, [locale_ISO_8859_5 - locale_ISO_8859_2] = 0x2116, [locale_ISO_8859_6 - locale_ISO_8859_2] = 0x652, [locale_ISO_8859_7 - locale_ISO_8859_2] = 0x20af, [locale_ISO_8859_8 - locale_ISO_8859_2] = 0x2017, [locale_ISO_8859_9 - locale_ISO_8859_2] = 0x15f, [locale_ISO_8859_10 - locale_ISO_8859_2] = 0x2015, [locale_ISO_8859_11 - locale_ISO_8859_2] = 0xe5b, [locale_ISO_8859_13 - locale_ISO_8859_2] = 0x201e, [locale_ISO_8859_14 - locale_ISO_8859_2] = 0x1ef3, [locale_ISO_8859_15 - locale_ISO_8859_2] = 0x20ac, [locale_ISO_8859_16 - locale_ISO_8859_2] = 0x20ac, }; #endif /* __MB_EXTENDED_CHARSETS_ISO */ #ifdef __MB_EXTENDED_CHARSETS_WINDOWS /* Tables for the Windows default singlebyte ANSI codepage conversion. The first index into the table is a value computed from locale id minus locale_WINDOWS_BASE, the second index is the value of the incoming character - 0x80. Values < 0x80 don't have to be converted anyway. */ const uint16_t __cp_conv[27][0x80] = { [ locale_CP437 - locale_WINDOWS_BASE ] = { 0xc7, 0xfc, 0xe9, 0xe2, 0xe4, 0xe0, 0xe5, 0xe7, 0xea, 0xeb, 0xe8, 0xef, 0xee, 0xec, 0xc4, 0xc5, 0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9, 0xff, 0xd6, 0xdc, 0xa2, 0xa3, 0xa5, 0x20a7, 0x192, 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba, 0xbf, 0x2310, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, 0x3b1, 0xdf, 0x393, 0x3c0, 0x3a3, 0x3c3, 0xb5, 0x3c4, 0x3a6, 0x398, 0x3a9, 0x3b4, 0x221e, 0x3c6, 0x3b5, 0x2229, 0x2261, 0xb1, 0x2265, 0x2264, 0x2320, 0x2321, 0xf7, 0x2248, 0xb0, 0x2219, 0xb7, 0x221a, 0x207f, 0xb2, 0x25a0, 0xa0 }, [ locale_CP720 - locale_WINDOWS_BASE ] = { 0x80, 0x81, 0xe9, 0xe2, 0x84, 0xe0, 0x86, 0xe7, 0xea, 0xeb, 0xe8, 0xef, 0xee, 0x8d, 0x8e, 0x8f, 0x90, 0x651, 0x652, 0xf4, 0xa4, 0x640, 0xfb, 0xf9, 0x621, 0x622, 0x623, 0x624, 0xa3, 0x625, 0x626, 0x627, 0x628, 0x629, 0x62a, 0x62b, 0x62c, 0x62d, 0x62e, 0x62f, 0x630, 0x631, 0x632, 0x633, 0x634, 0x635, 0xab, 0xbb, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, 0x636, 0x637, 0x638, 0x639, 0x63a, 0x641, 0xb5, 0x642, 0x643, 0x644, 0x645, 0x646, 0x647, 0x648, 0x649, 0x64a, 0x2261, 0x64b, 0x64c, 0x64d, 0x64e, 0x64f, 0x650, 0x2248, 0xb0, 0x2219, 0xb7, 0x221a, 0x207f, 0xb2, 0x25a0, 0xa0 }, [ locale_CP737 - locale_WINDOWS_BASE ] = { 0x391, 0x392, 0x393, 0x394, 0x395, 0x396, 0x397, 0x398, 0x399, 0x39a, 0x39b, 0x39c, 0x39d, 0x39e, 0x39f, 0x3a0, 0x3a1, 0x3a3, 0x3a4, 0x3a5, 0x3a6, 0x3a7, 0x3a8, 0x3a9, 0x3b1, 0x3b2, 0x3b3, 0x3b4, 0x3b5, 0x3b6, 0x3b7, 0x3b8, 0x3b9, 0x3ba, 0x3bb, 0x3bc, 0x3bd, 0x3be, 0x3bf, 0x3c0, 0x3c1, 0x3c3, 0x3c2, 0x3c4, 0x3c5, 0x3c6, 0x3c7, 0x3c8, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, 0x3c9, 0x3ac, 0x3ad, 0x3ae, 0x3ca, 0x3af, 0x3cc, 0x3cd, 0x3cb, 0x3ce, 0x386, 0x388, 0x389, 0x38a, 0x38c, 0x38e, 0x38f, 0xb1, 0x2265, 0x2264, 0x3aa, 0x3ab, 0xf7, 0x2248, 0xb0, 0x2219, 0xb7, 0x221a, 0x207f, 0xb2, 0x25a0, 0xa0 }, [ locale_CP775 - locale_WINDOWS_BASE ] = { 0x106, 0xfc, 0xe9, 0x101, 0xe4, 0x123, 0xe5, 0x107, 0x142, 0x113, 0x156, 0x157, 0x12b, 0x179, 0xc4, 0xc5, 0xc9, 0xe6, 0xc6, 0x14d, 0xf6, 0x122, 0xa2, 0x15a, 0x15b, 0xd6, 0xdc, 0xf8, 0xa3, 0xd8, 0xd7, 0xa4, 0x100, 0x12a, 0xf3, 0x17b, 0x17c, 0x17a, 0x201d, 0xa6, 0xa9, 0xae, 0xac, 0xbd, 0xbc, 0x141, 0xab, 0xbb, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x104, 0x10c, 0x118, 0x116, 0x2563, 0x2551, 0x2557, 0x255d, 0x12e, 0x160, 0x2510, 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x172, 0x16a, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x17d, 0x105, 0x10d, 0x119, 0x117, 0x12f, 0x161, 0x173, 0x16b, 0x17e, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, 0xd3, 0xdf, 0x14c, 0x143, 0xf5, 0xd5, 0xb5, 0x144, 0x136, 0x137, 0x13b, 0x13c, 0x146, 0x112, 0x145, 0x2019, 0xad, 0xb1, 0x201c, 0xbe, 0xb6, 0xa7, 0xf7, 0x201e, 0xb0, 0x2219, 0xb7, 0xb9, 0xb3, 0xb2, 0x25a0, 0xa0 }, [ locale_CP850 - locale_WINDOWS_BASE ] = { 0xc7, 0xfc, 0xe9, 0xe2, 0xe4, 0xe0, 0xe5, 0xe7, 0xea, 0xeb, 0xe8, 0xef, 0xee, 0xec, 0xc4, 0xc5, 0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9, 0xff, 0xd6, 0xdc, 0xf8, 0xa3, 0xd8, 0xd7, 0x192, 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba, 0xbf, 0xae, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0xc1, 0xc2, 0xc0, 0xa9, 0x2563, 0x2551, 0x2557, 0x255d, 0xa2, 0xa5, 0x2510, 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0xe3, 0xc3, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0xa4, 0xf0, 0xd0, 0xca, 0xcb, 0xc8, 0x131, 0xcd, 0xce, 0xcf, 0x2518, 0x250c, 0x2588, 0x2584, 0xa6, 0xcc, 0x2580, 0xd3, 0xdf, 0xd4, 0xd2, 0xf5, 0xd5, 0xb5, 0xfe, 0xde, 0xda, 0xdb, 0xd9, 0xfd, 0xdd, 0xaf, 0xb4, 0xad, 0xb1, 0x2017, 0xbe, 0xb6, 0xa7, 0xf7, 0xb8, 0xb0, 0xa8, 0xb7, 0xb9, 0xb3, 0xb2, 0x25a0, 0xa0 }, [ locale_CP852 - locale_WINDOWS_BASE ] = { 0xc7, 0xfc, 0xe9, 0xe2, 0xe4, 0x16f, 0x107, 0xe7, 0x142, 0xeb, 0x150, 0x151, 0xee, 0x179, 0xc4, 0x106, 0xc9, 0x139, 0x13a, 0xf4, 0xf6, 0x13d, 0x13e, 0x15a, 0x15b, 0xd6, 0xdc, 0x164, 0x165, 0x141, 0xd7, 0x10d, 0xe1, 0xed, 0xf3, 0xfa, 0x104, 0x105, 0x17d, 0x17e, 0x118, 0x119, 0xac, 0x17a, 0x10c, 0x15f, 0xab, 0xbb, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0xc1, 0xc2, 0x11a, 0x15e, 0x2563, 0x2551, 0x2557, 0x255d, 0x17b, 0x17c, 0x2510, 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x102, 0x103, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0xa4, 0x111, 0x110, 0x10e, 0xcb, 0x10f, 0x147, 0xcd, 0xce, 0x11b, 0x2518, 0x250c, 0x2588, 0x2584, 0x162, 0x16e, 0x2580, 0xd3, 0xdf, 0xd4, 0x143, 0x144, 0x148, 0x160, 0x161, 0x154, 0xda, 0x155, 0x170, 0xfd, 0xdd, 0x163, 0xb4, 0xad, 0x2dd, 0x2db, 0x2c7, 0x2d8, 0xa7, 0xf7, 0xb8, 0xb0, 0xa8, 0x2d9, 0x171, 0x158, 0x159, 0x25a0, 0xa0 }, [ locale_CP855 - locale_WINDOWS_BASE ] = { 0x452, 0x402, 0x453, 0x403, 0x451, 0x401, 0x454, 0x404, 0x455, 0x405, 0x456, 0x406, 0x457, 0x407, 0x458, 0x408, 0x459, 0x409, 0x45a, 0x40a, 0x45b, 0x40b, 0x45c, 0x40c, 0x45e, 0x40e, 0x45f, 0x40f, 0x44e, 0x42e, 0x44a, 0x42a, 0x430, 0x410, 0x431, 0x411, 0x446, 0x426, 0x434, 0x414, 0x435, 0x415, 0x444, 0x424, 0x433, 0x413, 0xab, 0xbb, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x445, 0x425, 0x438, 0x418, 0x2563, 0x2551, 0x2557, 0x255d, 0x439, 0x419, 0x2510, 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x43a, 0x41a, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0xa4, 0x43b, 0x41b, 0x43c, 0x41c, 0x43d, 0x41d, 0x43e, 0x41e, 0x43f, 0x2518, 0x250c, 0x2588, 0x2584, 0x41f, 0x44f, 0x2580, 0x42f, 0x440, 0x420, 0x441, 0x421, 0x442, 0x422, 0x443, 0x423, 0x436, 0x416, 0x432, 0x412, 0x44c, 0x42c, 0x2116, 0xad, 0x44b, 0x42b, 0x437, 0x417, 0x448, 0x428, 0x44d, 0x42d, 0x449, 0x429, 0x447, 0x427, 0xa7, 0x25a0, 0xa0 }, [ locale_CP857 - locale_WINDOWS_BASE ] = { 0xc7, 0xfc, 0xe9, 0xe2, 0xe4, 0xe0, 0xe5, 0xe7, 0xea, 0xeb, 0xe8, 0xef, 0xee, 0x131, 0xc4, 0xc5, 0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9, 0x130, 0xd6, 0xdc, 0xf8, 0xa3, 0xd8, 0x15e, 0x15f, 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0x11e, 0x11f, 0xbf, 0xae, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0xc1, 0xc2, 0xc0, 0xa9, 0x2563, 0x2551, 0x2557, 0x255d, 0xa2, 0xa5, 0x2510, 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0xe3, 0xc3, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0xa4, 0xba, 0xaa, 0xca, 0xcb, 0xc8, 0, 0xcd, 0xce, 0xcf, 0x2518, 0x250c, 0x2588, 0x2584, 0xa6, 0xcc, 0x2580, 0xd3, 0xdf, 0xd4, 0xd2, 0xf5, 0xd5, 0xb5, 0, 0xd7, 0xda, 0xdb, 0xd9, 0xec, 0xff, 0xaf, 0xb4, 0xad, 0xb1, 0, 0xbe, 0xb6, 0xa7, 0xf7, 0xb8, 0xb0, 0xa8, 0xb7, 0xb9, 0xb3, 0xb2, 0x25a0, 0xa0 }, [ locale_CP858 - locale_WINDOWS_BASE ] = { 0xc7, 0xfc, 0xe9, 0xe2, 0xe4, 0xe0, 0xe5, 0xe7, 0xea, 0xeb, 0xe8, 0xef, 0xee, 0xec, 0xc4, 0xc5, 0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9, 0xff, 0xd6, 0xdc, 0xf8, 0xa3, 0xd8, 0xd7, 0x192, 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba, 0xbf, 0xae, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0xc1, 0xc2, 0xc0, 0xa9, 0x2563, 0x2551, 0x2557, 0x255d, 0xa2, 0xa5, 0x2510, 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0xe3, 0xc3, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0xa4, 0xf0, 0xd0, 0xca, 0xcb, 0xc8, 0x20ac, 0xcd, 0xce, 0xcf, 0x2518, 0x250c, 0x2588, 0x2584, 0xa6, 0xcc, 0x2580, 0xd3, 0xdf, 0xd4, 0xd2, 0xf5, 0xd5, 0xb5, 0xfe, 0xde, 0xda, 0xdb, 0xd9, 0xfd, 0xdd, 0xaf, 0xb4, 0xad, 0xb1, 0x2017, 0xbe, 0xb6, 0xa7, 0xf7, 0xb8, 0xb0, 0xa8, 0xb7, 0xb9, 0xb3, 0xb2, 0x25a0, 0xa0 }, [ locale_CP862 - locale_WINDOWS_BASE ] = { 0x5d0, 0x5d1, 0x5d2, 0x5d3, 0x5d4, 0x5d5, 0x5d6, 0x5d7, 0x5d8, 0x5d9, 0x5da, 0x5db, 0x5dc, 0x5dd, 0x5de, 0x5df, 0x5e0, 0x5e1, 0x5e2, 0x5e3, 0x5e4, 0x5e5, 0x5e6, 0x5e7, 0x5e8, 0x5e9, 0x5ea, 0xa2, 0xa3, 0xa5, 0x20a7, 0x192, 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba, 0xbf, 0x2310, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, 0x3b1, 0xdf, 0x393, 0x3c0, 0x3a3, 0x3c3, 0xb5, 0x3c4, 0x3a6, 0x398, 0x3a9, 0x3b4, 0x221e, 0x3c6, 0x3b5, 0x2229, 0x2261, 0xb1, 0x2265, 0x2264, 0x2320, 0x2321, 0xf7, 0x2248, 0xb0, 0x2219, 0xb7, 0x221a, 0x207f, 0xb2, 0x25a0, 0xa0 }, [ locale_CP866 - locale_WINDOWS_BASE ] = { 0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417, 0x418, 0x419, 0x41a, 0x41b, 0x41c, 0x41d, 0x41e, 0x41f, 0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427, 0x428, 0x429, 0x42a, 0x42b, 0x42c, 0x42d, 0x42e, 0x42f, 0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437, 0x438, 0x439, 0x43a, 0x43b, 0x43c, 0x43d, 0x43e, 0x43f, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, 0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447, 0x448, 0x449, 0x44a, 0x44b, 0x44c, 0x44d, 0x44e, 0x44f, 0x401, 0x451, 0x404, 0x454, 0x407, 0x457, 0x40e, 0x45e, 0xb0, 0x2219, 0xb7, 0x221a, 0x2116, 0xa4, 0x25a0, 0xa0 }, [ locale_CP874 - locale_WINDOWS_BASE ] = { 0x20ac, 0, 0, 0, 0, 0x2026, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0, 0, 0, 0, 0, 0, 0, 0, 0xa0, 0xe01, 0xe02, 0xe03, 0xe04, 0xe05, 0xe06, 0xe07, 0xe08, 0xe09, 0xe0a, 0xe0b, 0xe0c, 0xe0d, 0xe0e, 0xe0f, 0xe10, 0xe11, 0xe12, 0xe13, 0xe14, 0xe15, 0xe16, 0xe17, 0xe18, 0xe19, 0xe1a, 0xe1b, 0xe1c, 0xe1d, 0xe1e, 0xe1f, 0xe20, 0xe21, 0xe22, 0xe23, 0xe24, 0xe25, 0xe26, 0xe27, 0xe28, 0xe29, 0xe2a, 0xe2b, 0xe2c, 0xe2d, 0xe2e, 0xe2f, 0xe30, 0xe31, 0xe32, 0xe33, 0xe34, 0xe35, 0xe36, 0xe37, 0xe38, 0xe39, 0xe3a, 0, 0, 0, 0, 0xe3f, 0xe40, 0xe41, 0xe42, 0xe43, 0xe44, 0xe45, 0xe46, 0xe47, 0xe48, 0xe49, 0xe4a, 0xe4b, 0xe4c, 0xe4d, 0xe4e, 0xe4f, 0xe50, 0xe51, 0xe52, 0xe53, 0xe54, 0xe55, 0xe56, 0xe57, 0xe58, 0xe59, 0xe5a, 0xe5b, 0, 0, 0, 0 }, [ locale_CP1125 - locale_WINDOWS_BASE ] = { 0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417, 0x418, 0x419, 0x41a, 0x41b, 0x41c, 0x41d, 0x41e, 0x41f, 0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427, 0x428, 0x429, 0x42a, 0x42b, 0x42c, 0x42d, 0x42e, 0x42f, 0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437, 0x438, 0x439, 0x43a, 0x43b, 0x43c, 0x43d, 0x43e, 0x43f, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, 0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447, 0x448, 0x449, 0x44a, 0x44b, 0x44c, 0x44d, 0x44e, 0x44f, 0x401, 0x451, 0x490, 0x491, 0x404, 0x454, 0x406, 0x456, 0x407, 0x457, 0xb7, 0x221a, 0x2116, 0xa4, 0x25a0, 0xa0 }, [ locale_CP1250 - locale_WINDOWS_BASE ] = { 0x20ac, 0, 0x201a, 0, 0x201e, 0x2026, 0x2020, 0x2021, 0, 0x2030, 0x160, 0x2039, 0x15a, 0x164, 0x17d, 0x179, 0, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0, 0x2122, 0x161, 0x203a, 0x15b, 0x165, 0x17e, 0x17a, 0xa0, 0x2c7, 0x2d8, 0x141, 0xa4, 0x104, 0xa6, 0xa7, 0xa8, 0xa9, 0x15e, 0xab, 0xac, 0xad, 0xae, 0x17b, 0xb0, 0xb1, 0x2db, 0x142, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0x105, 0x15f, 0xbb, 0x13d, 0x2dd, 0x13e, 0x17c, 0x154, 0xc1, 0xc2, 0x102, 0xc4, 0x139, 0x106, 0xc7, 0x10c, 0xc9, 0x118, 0xcb, 0x11a, 0xcd, 0xce, 0x10e, 0x110, 0x143, 0x147, 0xd3, 0xd4, 0x150, 0xd6, 0xd7, 0x158, 0x16e, 0xda, 0x170, 0xdc, 0xdd, 0x162, 0xdf, 0x155, 0xe1, 0xe2, 0x103, 0xe4, 0x13a, 0x107, 0xe7, 0x10d, 0xe9, 0x119, 0xeb, 0x11b, 0xed, 0xee, 0x10f, 0x111, 0x144, 0x148, 0xf3, 0xf4, 0x151, 0xf6, 0xf7, 0x159, 0x16f, 0xfa, 0x171, 0xfc, 0xfd, 0x163, 0x2d9 }, [ locale_CP1251 - locale_WINDOWS_BASE ] = { 0x402, 0x403, 0x201a, 0x453, 0x201e, 0x2026, 0x2020, 0x2021, 0x20ac, 0x2030, 0x409, 0x2039, 0x40a, 0x40c, 0x40b, 0x40f, 0x452, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0, 0x2122, 0x459, 0x203a, 0x45a, 0x45c, 0x45b, 0x45f, 0xa0, 0x40e, 0x45e, 0x408, 0xa4, 0x490, 0xa6, 0xa7, 0x401, 0xa9, 0x404, 0xab, 0xac, 0xad, 0xae, 0x407, 0xb0, 0xb1, 0x406, 0x456, 0x491, 0xb5, 0xb6, 0xb7, 0x451, 0x2116, 0x454, 0xbb, 0x458, 0x405, 0x455, 0x457, 0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417, 0x418, 0x419, 0x41a, 0x41b, 0x41c, 0x41d, 0x41e, 0x41f, 0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427, 0x428, 0x429, 0x42a, 0x42b, 0x42c, 0x42d, 0x42e, 0x42f, 0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437, 0x438, 0x439, 0x43a, 0x43b, 0x43c, 0x43d, 0x43e, 0x43f, 0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447, 0x448, 0x449, 0x44a, 0x44b, 0x44c, 0x44d, 0x44e, 0x44f }, [ locale_CP1252 - locale_WINDOWS_BASE ] = { 0x20ac, 0, 0x201a, 0x192, 0x201e, 0x2026, 0x2020, 0x2021, 0x2c6, 0x2030, 0x160, 0x2039, 0x152, 0, 0x17d, 0, 0, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x2dc, 0x2122, 0x161, 0x203a, 0x153, 0, 0x17e, 0x178, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }, [ locale_CP1253 - locale_WINDOWS_BASE ] = { 0x20ac, 0, 0x201a, 0x192, 0x201e, 0x2026, 0x2020, 0x2021, 0, 0x2030, 0, 0x2039, 0, 0, 0, 0, 0, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0, 0x2122, 0, 0x203a, 0, 0, 0, 0, 0xa0, 0x385, 0x386, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0, 0xab, 0xac, 0xad, 0xae, 0x2015, 0xb0, 0xb1, 0xb2, 0xb3, 0x384, 0xb5, 0xb6, 0xb7, 0x388, 0x389, 0x38a, 0xbb, 0x38c, 0xbd, 0x38e, 0x38f, 0x390, 0x391, 0x392, 0x393, 0x394, 0x395, 0x396, 0x397, 0x398, 0x399, 0x39a, 0x39b, 0x39c, 0x39d, 0x39e, 0x39f, 0x3a0, 0x3a1, 0, 0x3a3, 0x3a4, 0x3a5, 0x3a6, 0x3a7, 0x3a8, 0x3a9, 0x3aa, 0x3ab, 0x3ac, 0x3ad, 0x3ae, 0x3af, 0x3b0, 0x3b1, 0x3b2, 0x3b3, 0x3b4, 0x3b5, 0x3b6, 0x3b7, 0x3b8, 0x3b9, 0x3ba, 0x3bb, 0x3bc, 0x3bd, 0x3be, 0x3bf, 0x3c0, 0x3c1, 0x3c2, 0x3c3, 0x3c4, 0x3c5, 0x3c6, 0x3c7, 0x3c8, 0x3c9, 0x3ca, 0x3cb, 0x3cc, 0x3cd, 0x3ce, 0 }, [ locale_CP1254 - locale_WINDOWS_BASE ] = { 0x20ac, 0, 0x201a, 0x192, 0x201e, 0x2026, 0x2020, 0x2021, 0x2c6, 0x2030, 0x160, 0x2039, 0x152, 0, 0, 0, 0, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x2dc, 0x2122, 0x161, 0x203a, 0x153, 0, 0, 0x178, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0x11e, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0x130, 0x15e, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0x11f, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0x131, 0x15f, 0xff }, [ locale_CP1255 - locale_WINDOWS_BASE ] = { 0x20ac, 0, 0x201a, 0x192, 0x201e, 0x2026, 0x2020, 0x2021, 0x2c6, 0x2030, 0, 0x2039, 0, 0, 0, 0, 0, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x2dc, 0x2122, 0, 0x203a, 0, 0, 0, 0, 0xa0, 0xa1, 0xa2, 0xa3, 0x20aa, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xd7, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xf7, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0x5b0, 0x5b1, 0x5b2, 0x5b3, 0x5b4, 0x5b5, 0x5b6, 0x5b7, 0x5b8, 0x5b9, 0, 0x5bb, 0x5bc, 0x5bd, 0x5be, 0x5bf, 0x5c0, 0x5c1, 0x5c2, 0x5c3, 0x5f0, 0x5f1, 0x5f2, 0x5f3, 0x5f4, 0, 0, 0, 0, 0, 0, 0, 0x5d0, 0x5d1, 0x5d2, 0x5d3, 0x5d4, 0x5d5, 0x5d6, 0x5d7, 0x5d8, 0x5d9, 0x5da, 0x5db, 0x5dc, 0x5dd, 0x5de, 0x5df, 0x5e0, 0x5e1, 0x5e2, 0x5e3, 0x5e4, 0x5e5, 0x5e6, 0x5e7, 0x5e8, 0x5e9, 0x5ea, 0, 0, 0x200e, 0x200f, 0 }, [ locale_CP1256 - locale_WINDOWS_BASE ] = { 0x20ac, 0x67e, 0x201a, 0x192, 0x201e, 0x2026, 0x2020, 0x2021, 0x2c6, 0x2030, 0x679, 0x2039, 0x152, 0x686, 0x698, 0x688, 0x6af, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x6a9, 0x2122, 0x691, 0x203a, 0x153, 0x200c, 0x200d, 0x6ba, 0xa0, 0x60c, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0x6be, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0x61b, 0xbb, 0xbc, 0xbd, 0xbe, 0x61f, 0x6c1, 0x621, 0x622, 0x623, 0x624, 0x625, 0x626, 0x627, 0x628, 0x629, 0x62a, 0x62b, 0x62c, 0x62d, 0x62e, 0x62f, 0x630, 0x631, 0x632, 0x633, 0x634, 0x635, 0x636, 0xd7, 0x637, 0x638, 0x639, 0x63a, 0x640, 0x641, 0x642, 0x643, 0xe0, 0x644, 0xe2, 0x645, 0x646, 0x647, 0x648, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0x649, 0x64a, 0xee, 0xef, 0x64b, 0x64c, 0x64d, 0x64e, 0xf4, 0x64f, 0x650, 0xf7, 0x651, 0xf9, 0x652, 0xfb, 0xfc, 0x200e, 0x200f, 0x6d2 }, [ locale_CP1257 - locale_WINDOWS_BASE ] = { 0x20ac, 0, 0x201a, 0, 0x201e, 0x2026, 0x2020, 0x2021, 0, 0x2030, 0, 0x2039, 0, 0xa8, 0x2c7, 0xb8, 0, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0, 0x2122, 0, 0x203a, 0, 0xaf, 0x2db, 0, 0xa0, 0, 0xa2, 0xa3, 0xa4, 0, 0xa6, 0xa7, 0xd8, 0xa9, 0x156, 0xab, 0xac, 0xad, 0xae, 0xc6, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xf8, 0xb9, 0x157, 0xbb, 0xbc, 0xbd, 0xbe, 0xe6, 0x104, 0x12e, 0x100, 0x106, 0xc4, 0xc5, 0x118, 0x112, 0x10c, 0xc9, 0x179, 0x116, 0x122, 0x136, 0x12a, 0x13b, 0x160, 0x143, 0x145, 0xd3, 0x14c, 0xd5, 0xd6, 0xd7, 0x172, 0x141, 0x15a, 0x16a, 0xdc, 0x17b, 0x17d, 0xdf, 0x105, 0x12f, 0x101, 0x107, 0xe4, 0xe5, 0x119, 0x113, 0x10d, 0xe9, 0x17a, 0x117, 0x123, 0x137, 0x12b, 0x13c, 0x161, 0x144, 0x146, 0xf3, 0x14d, 0xf5, 0xf6, 0xf7, 0x173, 0x142, 0x15b, 0x16b, 0xfc, 0x17c, 0x17e, 0x2d9 }, [ locale_CP1258 - locale_WINDOWS_BASE ] = { 0x20ac, 0, 0x201a, 0x192, 0x201e, 0x2026, 0x2020, 0x2021, 0x2c6, 0x2030, 0, 0x2039, 0x152, 0, 0, 0, 0, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x2dc, 0x2122, 0, 0x203a, 0x153, 0, 0, 0x178, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0x102, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0x300, 0xcd, 0xce, 0xcf, 0x110, 0xd1, 0x309, 0xd3, 0xd4, 0x1a0, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0x1af, 0x303, 0xdf, 0xe0, 0xe1, 0xe2, 0x103, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0x301, 0xed, 0xee, 0xef, 0x111, 0xf1, 0x323, 0xf3, 0xf4, 0x1a1, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0x1b0, 0x20ab, 0xff }, [ locale_KOI8_R - locale_WINDOWS_BASE ] = { 0x2500, 0x2502, 0x250c, 0x2510, 0x2514, 0x2518, 0x251c, 0x2524, 0x252c, 0x2534, 0x253c, 0x2580, 0x2584, 0x2588, 0x258c, 0x2590, 0x2591, 0x2592, 0x2593, 0x2320, 0x25a0, 0x2219, 0x221a, 0x2248, 0x2264, 0x2265, 0xa0, 0x2321, 0xb0, 0xb2, 0xb7, 0xf7, 0x2550, 0x2551, 0x2552, 0x451, 0x2553, 0x2554, 0x2555, 0x2556, 0x2557, 0x2558, 0x2559, 0x255a, 0x255b, 0x255c, 0x255d, 0x255e, 0x255f, 0x2560, 0x2561, 0x401, 0x2562, 0x2563, 0x2564, 0x2565, 0x2566, 0x2567, 0x2568, 0x2569, 0x256a, 0x256b, 0x256c, 0xa9, 0x44e, 0x430, 0x431, 0x446, 0x434, 0x435, 0x444, 0x433, 0x445, 0x438, 0x439, 0x43a, 0x43b, 0x43c, 0x43d, 0x43e, 0x43f, 0x44f, 0x440, 0x441, 0x442, 0x443, 0x436, 0x432, 0x44c, 0x44b, 0x437, 0x448, 0x44d, 0x449, 0x447, 0x44a, 0x42e, 0x410, 0x411, 0x426, 0x414, 0x415, 0x424, 0x413, 0x425, 0x418, 0x419, 0x41a, 0x41b, 0x41c, 0x41d, 0x41e, 0x41f, 0x42f, 0x420, 0x421, 0x422, 0x423, 0x416, 0x412, 0x42c, 0x42b, 0x417, 0x428, 0x42d, 0x429, 0x427, 0x42a }, [ locale_KOI8_U - locale_WINDOWS_BASE ] = { 0x2500, 0x2502, 0x250c, 0x2510, 0x2514, 0x2518, 0x251c, 0x2524, 0x252c, 0x2534, 0x253c, 0x2580, 0x2584, 0x2588, 0x258c, 0x2590, 0x2591, 0x2592, 0x2593, 0x2320, 0x25a0, 0x2219, 0x221a, 0x2248, 0x2264, 0x2265, 0xa0, 0x2321, 0xb0, 0xb2, 0xb7, 0xf7, 0x2550, 0x2551, 0x2552, 0x451, 0x454, 0x2554, 0x456, 0x457, 0x2557, 0x2558, 0x2559, 0x255a, 0x255b, 0x491, 0x255d, 0x255e, 0x255f, 0x2560, 0x2561, 0x401, 0x404, 0x2563, 0x406, 0x407, 0x2566, 0x2567, 0x2568, 0x2569, 0x256a, 0x490, 0x256c, 0xa9, 0x44e, 0x430, 0x431, 0x446, 0x434, 0x435, 0x444, 0x433, 0x445, 0x438, 0x439, 0x43a, 0x43b, 0x43c, 0x43d, 0x43e, 0x43f, 0x44f, 0x440, 0x441, 0x442, 0x443, 0x436, 0x432, 0x44c, 0x44b, 0x437, 0x448, 0x44d, 0x449, 0x447, 0x44a, 0x42e, 0x410, 0x411, 0x426, 0x414, 0x415, 0x424, 0x413, 0x425, 0x418, 0x419, 0x41a, 0x41b, 0x41c, 0x41d, 0x41e, 0x41f, 0x42f, 0x420, 0x421, 0x422, 0x423, 0x416, 0x412, 0x42c, 0x42b, 0x417, 0x428, 0x42d, 0x429, 0x427, 0x42a }, [ locale_GEORGIAN_PS - locale_WINDOWS_BASE ] = { 0x80, 0x81, 0x201a, 0x192, 0x201e, 0x2026, 0x2020, 0x2021, 0x2c6, 0x2030, 0x160, 0x2039, 0x152, 0x8d, 0x8e, 0x8f, 0x90, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x2dc, 0x2122, 0x161, 0x203a, 0x153, 0x9d, 0x9e, 0x178, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0x10d0, 0x10d1, 0x10d2, 0x10d3, 0x10d4, 0x10d5, 0x10d6, 0x10f1, 0x10d7, 0x10d8, 0x10d9, 0x10da, 0x10db, 0x10dc, 0x10f2, 0x10dd, 0x10de, 0x10df, 0x10e0, 0x10e1, 0x10e2, 0x10f3, 0x10e3, 0x10e4, 0x10e5, 0x10e6, 0x10e7, 0x10e8, 0x10e9, 0x10ea, 0x10eb, 0x10ec, 0x10ed, 0x10ee, 0x10f4, 0x10ef, 0x10f0, 0x10f5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }, [ locale_PT154 - locale_WINDOWS_BASE ] = { 0x496, 0x492, 0x4ee, 0x493, 0x201e, 0x2026, 0x4b6, 0x4ae, 0x4b2, 0x4af, 0x4a0, 0x4e2, 0x4a2, 0x49a, 0x4ba, 0x4b8, 0x497, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x4b3, 0x4b7, 0x4a1, 0x4e3, 0x4a3, 0x49b, 0x4bb, 0x4b9, 0xa0, 0x40e, 0x45e, 0x408, 0x4e8, 0x498, 0x4b0, 0xa7, 0x401, 0xa9, 0x4d8, 0xab, 0xac, 0x4ef, 0xae, 0x49c, 0xb0, 0x4b1, 0x406, 0x456, 0x499, 0x4e9, 0xb6, 0xb7, 0x451, 0x2116, 0x4d9, 0xbb, 0x458, 0x4aa, 0x4ab, 0x49d, 0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417, 0x418, 0x419, 0x41a, 0x41b, 0x41c, 0x41d, 0x41e, 0x41f, 0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427, 0x428, 0x429, 0x42a, 0x42b, 0x42c, 0x42d, 0x42e, 0x42f, 0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437, 0x438, 0x439, 0x43a, 0x43b, 0x43c, 0x43d, 0x43e, 0x43f, 0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447, 0x448, 0x449, 0x44a, 0x44b, 0x44c, 0x44d, 0x44e, 0x44f }, [ locale_KOI8_T - locale_WINDOWS_BASE ] = { 0x49b, 0x493, 0x201a, 0x492, 0x201e, 0x2026, 0x2020, 0x2021, 0, 0x2030, 0x4b3, 0x2039, 0x4b2, 0x4b7, 0x4b6, 0, 0x49a, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0, 0x2122, 0, 0x203a, 0, 0, 0, 0, 0, 0x4ef, 0x4ee, 0x451, 0xa4, 0x4e3, 0xa6, 0xa7, 0, 0, 0, 0xab, 0xac, 0xad, 0xae, 0, 0xb0, 0xb1, 0xb2, 0x401, 0, 0x4e2, 0xb6, 0xb7, 0, 0x2116, 0, 0xbb, 0, 0, 0, 0xa9, 0x44e, 0x430, 0x431, 0x446, 0x434, 0x435, 0x444, 0x433, 0x445, 0x438, 0x439, 0x43a, 0x43b, 0x43c, 0x43d, 0x43e, 0x43f, 0x44f, 0x440, 0x441, 0x442, 0x443, 0x436, 0x432, 0x44c, 0x44b, 0x437, 0x448, 0x44d, 0x449, 0x447, 0x44a, 0x42e, 0x410, 0x411, 0x426, 0x414, 0x415, 0x424, 0x413, 0x425, 0x418, 0x419, 0x41a, 0x41b, 0x41c, 0x41d, 0x41e, 0x41f, 0x42f, 0x420, 0x421, 0x422, 0x423, 0x416, 0x412, 0x42c, 0x42b, 0x417, 0x428, 0x42d, 0x429, 0x427, 0x42a }, }; const uint16_t __cp_max[27] = { [locale_CP437 - locale_WINDOWS_BASE] = 0x25a0, [locale_CP720 - locale_WINDOWS_BASE] = 0x25a0, [locale_CP737 - locale_WINDOWS_BASE] = 0x25a0, [locale_CP775 - locale_WINDOWS_BASE] = 0x25a0, [locale_CP850 - locale_WINDOWS_BASE] = 0x25a0, [locale_CP852 - locale_WINDOWS_BASE] = 0x25a0, [locale_CP855 - locale_WINDOWS_BASE] = 0x25a0, [locale_CP857 - locale_WINDOWS_BASE] = 0x25a0, [locale_CP858 - locale_WINDOWS_BASE] = 0x25a0, [locale_CP862 - locale_WINDOWS_BASE] = 0x25a0, [locale_CP866 - locale_WINDOWS_BASE] = 0x25a0, [locale_CP874 - locale_WINDOWS_BASE] = 0x20ac, [locale_CP1125 - locale_WINDOWS_BASE] = 0x25a0, [locale_CP1250 - locale_WINDOWS_BASE] = 0x2122, [locale_CP1251 - locale_WINDOWS_BASE] = 0x2122, [locale_CP1252 - locale_WINDOWS_BASE] = 0x2122, [locale_CP1253 - locale_WINDOWS_BASE] = 0x2122, [locale_CP1254 - locale_WINDOWS_BASE] = 0x2122, [locale_CP1255 - locale_WINDOWS_BASE] = 0x2122, [locale_CP1256 - locale_WINDOWS_BASE] = 0x2122, [locale_CP1257 - locale_WINDOWS_BASE] = 0x2122, [locale_CP1258 - locale_WINDOWS_BASE] = 0x2122, [locale_KOI8_R - locale_WINDOWS_BASE] = 0x25a0, [locale_KOI8_U - locale_WINDOWS_BASE] = 0x25a0, [locale_GEORGIAN_PS - locale_WINDOWS_BASE] = 0x2122, [locale_PT154 - locale_WINDOWS_BASE] = 0x2116, [locale_KOI8_T - locale_WINDOWS_BASE] = 0x2122, }; #endif /* __MB_EXTENDED_CHARSETS_WINDOWS */ picolibc-1.8.11/libc/stdlib/seed48.c000066400000000000000000000017451513574234600170410ustar00rootroot00000000000000/* * Copyright (c) 1993 Martin Birgmeier * All rights reserved. * * You may redistribute unmodified or modified versions of this source * code provided that the above copyright notice and this and the * following conditions are retained. * * This software is provided ``as is'', and comes with no warranties * of any kind. I shall in no event be liable for anything that happens * to anyone/anything when using this software. */ #include "rand48.h" unsigned short * _seed48_r(struct _rand48 *r, unsigned short xseed[3]) { static __THREAD_LOCAL unsigned short sseed[3]; sseed[0] = r->_seed[0]; sseed[1] = r->_seed[1]; sseed[2] = r->_seed[2]; r->_seed[0] = xseed[0]; r->_seed[1] = xseed[1]; r->_seed[2] = xseed[2]; r->_mult[0] = _RAND48_MULT_0; r->_mult[1] = _RAND48_MULT_1; r->_mult[2] = _RAND48_MULT_2; r->_add = _RAND48_ADD; return sseed; } unsigned short * seed48(unsigned short xseed[3]) { return _seed48_r(&_rand48, xseed); } picolibc-1.8.11/libc/stdlib/set_constraint_handler_s.c000066400000000000000000000042271513574234600230210ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define __STDC_WANT_LIB_EXT1__ 1 #include "local_s.h" constraint_handler_t __cur_handler = abort_handler_s; void abort_handler_s(const char * __restrict msg, void * __restrict ptr, __errno_t error) { (void)msg; (void)ptr; (void)error; abort(); } constraint_handler_t set_constraint_handler_s(constraint_handler_t handler) { constraint_handler_t h = __cur_handler; if (handler == (constraint_handler_t)NULL) { __cur_handler = abort_handler_s; // null restores to default handler } else { __cur_handler = handler; } return h; } picolibc-1.8.11/libc/stdlib/setenv.c000066400000000000000000000075371513574234600172560ustar00rootroot00000000000000/* * Copyright (c) 1987 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that: (1) source distributions retain this entire copyright * notice and comment, and (2) distributions including binaries display * the following acknowledgement: ``This product includes software * developed by the University of California, Berkeley and its contributors'' * in the documentation or other materials provided with the distribution. * Neither the name of the University nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #define _DEFAULT_SOURCE #include #include #include #include #include /* * setenv -- * Set the value of the environmental variable "name" to be * "value". If rewrite is set, replace any current value. */ extern char **environ; /* Only deal with a pointer to environ, to work around subtle bugs with shared libraries and/or small data systems where the user declares his own 'environ'. */ static char ***p_environ = &environ; int setenv(const char *name, const char *value, int rewrite) { static int alloced; /* if allocated space before */ register char *C; size_t l_value; int offset; /* Name cannot be NULL, empty, or contain an equal sign. */ if (name == NULL || name[0] == '\0' || strchr(name, '=')) { errno = EINVAL; return -1; } ENV_LOCK; l_value = strlen(value); if ((C = _findenv(name, &offset))) { /* find if already exists */ if (!rewrite) { ENV_UNLOCK; return 0; } if (strlen(C) >= l_value) { /* old larger; copy over */ strcpy(C, value); ENV_UNLOCK; return 0; } } else { /* create new slot */ register int cnt; register char **P; for (P = *p_environ, cnt = 0; *P; ++P, ++cnt) ; if (alloced) { /* just increase size */ *p_environ = (char **)realloc((char *)environ, (size_t)(sizeof(char *) * (cnt + 2))); if (!*p_environ) { ENV_UNLOCK; return -1; } } else { /* get new space */ alloced = 1; /* copy old entries into it */ P = (char **)malloc((size_t)(sizeof(char *) * (cnt + 2))); if (!P) { ENV_UNLOCK; return (-1); } memcpy((char *)P, (char *)*p_environ, cnt * sizeof(char *)); *p_environ = P; } (*p_environ)[cnt + 1] = NULL; offset = cnt; } for (C = (char *)name; *C && *C != '='; ++C) ; /* no `=' in name */ char *E = malloc((size_t)((int)(C - name) + l_value + 2)); if (!E) { ENV_UNLOCK; return -1; } (*p_environ)[offset] = E; for (C = E; (*C = *name++) && *C != '='; ++C) ; for (*C++ = '='; (*C++ = *value++) != 0;) ; ENV_UNLOCK; return 0; } /* * unsetenv(name) -- * Delete environmental variable "name". */ int unsetenv(const char *name) { register char **P; int offset; /* Name cannot be NULL, empty, or contain an equal sign. */ if (name == NULL || name[0] == '\0' || strchr(name, '=')) { errno = EINVAL; return -1; } ENV_LOCK; while (_findenv(name, &offset)) /* if set multiple times */ { for (P = &(*p_environ)[offset];; ++P) if (!(*P = *(P + 1))) break; } ENV_UNLOCK; return 0; } picolibc-1.8.11/libc/stdlib/sjtouc.c000066400000000000000000000054671513574234600172610ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #ifdef __MB_EXTENDED_CHARSETS_JIS #include "jis.h" wint_t __shift_jis_to_unicode(uint16_t shift_jis) { uint8_t byte1, byte2, sjis1, sjis2; sjis1 = shift_jis >> 8; sjis2 = shift_jis & 0xff; switch (sjis1) { case 0: /* ASCII */ switch (sjis2) { case 0x5c: return 0xa5; /* ¥ */ case 0x7e: return 0x203e; /* ‾ */ default: if (sjis2 < 0x80) return sjis2; if (0xa1 <= sjis2 && sjis2 <= 0xdf) return sjis2 + (0xff61 - 0xa1); return WEOF; } break; } if (0x81 <= sjis1 && sjis1 <= 0x9f) byte1 = (sjis1 - 112 + 64) << 1; else if (0xe0 <= sjis1 && sjis1 <= 0xef) byte1 = (sjis1 - 176 + 64) << 1; else return WEOF; if (0x40 <= sjis2 && sjis2 <= 0x9e && sjis2 != 0x7f) { byte1 -= 1; byte2 = sjis2 - 31 + 128; if (sjis2 >= 0x7f) byte2--; } else if (0x9f <= sjis2 && sjis2 <= 0xfc) { byte2 = sjis2 - 126 + 128; } else { return WEOF; } return __euc_jp_to_unicode(((uint16_t)byte1 << 8) | byte2); } #endif /* __MB_EXTENDED_CHARSETS_JIS */ picolibc-1.8.11/libc/stdlib/srand.c000066400000000000000000000037431513574234600170540ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* FUNCTION <>, <>---pseudo-random numbers INDEX rand INDEX srand INDEX rand_r SYNOPSIS #include int rand(void); void srand(unsigned int <[seed]>); int rand_r(unsigned int *<[seed]>); DESCRIPTION <> returns a different integer each time it is called; each integer is chosen by an algorithm designed to be unpredictable, so that you can use <> when you require a random number. The algorithm depends on a static variable called the ``random seed''; starting with a given value of the random seed always produces the same sequence of numbers in successive calls to <>. You can set the random seed using <>; it does nothing beyond storing its argument in the static variable used by <>. You can exploit this to make the pseudo-random sequence less predictable, if you wish, by using some other unpredictable value (often the least significant parts of a time-varying value) as the random seed before beginning a sequence of calls to <>; or, if you wish to ensure (for example, while debugging) that successive runs of your program use the same ``random'' numbers, you can use <> to set the same random seed at the outset. RETURNS <> returns the next pseudo-random integer in sequence; it is a number between <<0>> and <> (inclusive). <> does not return a result. NOTES <> and <> are unsafe for multi-threaded applications. <> is thread-safe and should be used instead. PORTABILITY <> is required by ANSI, but the algorithm for pseudo-random number generation is not specified; therefore, even if you use the same random seed, you cannot expect the same sequence of results on two different systems. <> requires no supporting OS subroutines. */ #define _DEFAULT_SOURCE #include void srand(unsigned int seed) { srandom(seed); } picolibc-1.8.11/libc/stdlib/srand48.c000066400000000000000000000015071513574234600172240ustar00rootroot00000000000000/* * Copyright (c) 1993 Martin Birgmeier * All rights reserved. * * You may redistribute unmodified or modified versions of this source * code provided that the above copyright notice and this and the * following conditions are retained. * * This software is provided ``as is'', and comes with no warranties * of any kind. I shall in no event be liable for anything that happens * to anyone/anything when using this software. */ #include "rand48.h" void _srand48_r(struct _rand48 *r, long seed) { r->_seed[0] = _RAND48_SEED_0; r->_seed[1] = (unsigned short)seed; r->_seed[2] = (unsigned short)((unsigned long)seed >> 16); r->_mult[0] = _RAND48_MULT_0; r->_mult[1] = _RAND48_MULT_1; r->_mult[2] = _RAND48_MULT_2; r->_add = _RAND48_ADD; } void srand48(long seed) { _srand48_r(&_rand48, seed); } picolibc-1.8.11/libc/stdlib/srandom.c000066400000000000000000000035471513574234600174120ustar00rootroot00000000000000/* Copyright (c) 2016 Joel Sherrill */ /* FUNCTION <>, <>---pseudo-random numbers INDEX random INDEX srandom SYNOPSIS #define _XOPEN_SOURCE 500 #include long int random(void); void srandom(unsigned int <[seed]>); DESCRIPTION <> returns a different integer each time it is called; each integer is chosen by an algorithm designed to be unpredictable, so that you can use <> when you require a random number. The algorithm depends on a static variable called the ``random seed''; starting with a given value of the random seed always produces the same sequence of numbers in successive calls to <>. You can set the random seed using <>; it does nothing beyond storing its argument in the static variable used by <>. You can exploit this to make the pseudo-random sequence less predictable, if you wish, by using some other unpredictable value (often the least significant parts of a time-varying value) as the random seed before beginning a sequence of calls to <>; or, if you wish to ensure (for example, while debugging) that successive runs of your program use the same ``random'' numbers, you can use <> to set the same random seed at the outset. RETURNS <> returns the next pseudo-random integer in sequence; it is a number between <<0>> and <> (inclusive). <> does not return a result. NOTES <> and <> are unsafe for multi-threaded applications. _XOPEN_SOURCE may be any value >= 500. PORTABILITY <> is required by XSI. This implementation uses the same algorithm as <>. <> requires no supporting OS subroutines. */ #define _DEFAULT_SOURCE #include extern __THREAD_LOCAL long long _rand_next; void srandom(unsigned int seed) { _rand_next = seed; } picolibc-1.8.11/libc/stdlib/stdlib.tex000066400000000000000000000115251513574234600176010ustar00rootroot00000000000000# #Copyright (c) 1990 Regents of the University of California. #All rights reserved. # @node Stdlib @chapter Standard Utility Functions (@file{stdlib.h}) This chapter groups utility functions useful in a variety of programs. The corresponding declarations are in the header file @file{stdlib.h}. @menu * Function _Exit:: End program execution without cleaning up * Function a64l:: String to long long * Function abort:: Abnormal termination of a program * Function abs:: Integer absolute value (magnitude) * Function assert:: Macro for Debugging Diagnostics * Function atexit:: Request execution of functions at program exit * Function atof:: String to double or float * Function atoi:: String to integer * Function atoll:: String to long long * Function bsearch:: Binary search * Function calloc:: Allocate space for arrays * Function div:: Divide two integers * Function ecvtbuf:: Double or float to string of digits * Function ecvt:: Double or float to string of digits (malloc result) * Function __env_lock:: Lock environment list for getenv and setenv * Function gcvt:: Format double or float as string * Function exit:: End program execution * Function getenv:: Look up environment variable * Function itoa:: Integer to string * Function labs:: Long integer absolute value (magnitude) * Function ldiv:: Divide two long integers * Function llabs:: Long long integer absolute value (magnitude) * Function lldiv:: Divide two long long integers * Function malloc:: Allocate and manage memory (malloc, realloc, free) * Function mallinfo:: Get information about allocated memory * Function __malloc_lock:: Lock memory pool for malloc and free * Function mbsrtowcs:: Convert a character string to a wide-character string * Function mbstowcs:: Minimal multibyte string to wide string converter * Function mblen:: Minimal multibyte length * Function mbtowc:: Minimal multibyte to wide character converter * Function on_exit:: Request execution of functions at program exit * Function qsort:: Array sort * Function rand:: Pseudo-random numbers * Function random:: Pseudo-random numbers * Function rand48:: Uniformly distributed pseudo-random numbers * Function rpmatch:: Determine whether response is affirmative or negative * Function strtod:: String to double or float * Function strtol:: String to long * Function strtoll:: String to long long * Function strtoul:: String to unsigned long * Function strtoull:: String to unsigned long long * Function wcsrtombs:: Convert a wide-character string to a character string * Function wcstod:: Wide string to double or float * Function wcstol:: Wide string to long * Function wcstoll:: Wide string to long long * Function wcstoul:: Wide string to unsigned long * Function wcstoull:: Wide string to unsigned long long * Function system:: Execute command string * Function utoa:: Unsigned integer to string * Function wcstombs:: Minimal wide string to multibyte string converter * Function wctomb:: Minimal wide character to multibyte converter @end menu @page @include stdlib/_Exit.def @page @include stdlib/a64l.def @page @include stdlib/abort.def @page @include stdlib/abs.def @page @include stdlib/assert.def @page @include stdlib/atexit.def @page @include stdlib/atof.def @page @include stdlib/atoi.def @page @include stdlib/atoll.def @page @include search/bsearch.def @page @include stdlib/calloc.def @page @include stdlib/div.def @page @include stdlib/efgcvt.def @page @include stdlib/ecvtbuf.def @page @include stdlib/envlock.def @page @include stdlib/exit.def @page @include stdlib/getenv.def @page @include stdlib/itoa.def @page @include stdlib/labs.def @page @include stdlib/ldiv.def @page @include stdlib/llabs.def @page @include stdlib/lldiv.def @page @include stdlib/malloc.def @page @include stdlib/mstats.def @page @include stdlib/mlock.def @page @include stdlib/mblen.def @page @include stdlib/mbsnrtowcs.def @page @include stdlib/mbstowcs.def @page @include stdlib/mbtowc.def @page @include stdlib/on_exit.def @page @include search/qsort.def @page @include stdlib/rand.def @page @include stdlib/random.def @page @include stdlib/rand48.def @page @include stdlib/rpmatch.def @page @include stdlib/strtod.def @page @include stdlib/strtol.def @page @include stdlib/strtoll.def @page @include stdlib/strtoul.def @page @include stdlib/strtoull.def @page @include stdlib/wcsnrtombs.def @page @include stdlib/wcstod.def @page @include stdlib/wcstol.def @page @include stdlib/wcstoll.def @page @include stdlib/wcstoul.def @page @include stdlib/wcstoull.def @page @include stdlib/system.def @page @include stdlib/utoa.def @page @include stdlib/wcstombs.def @page @include stdlib/wctomb.def picolibc-1.8.11/libc/stdlib/system.c000066400000000000000000000055401513574234600172660ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* FUNCTION <>---execute command string INDEX system INDEX _system_r SYNOPSIS #include int system(char *<[s]>); int _system_r(void *<[reent]>, char *<[s]>); DESCRIPTION Use <> to pass a command string <<*<[s]>>> to <> on your system, and wait for it to finish executing. Use ``<>'' to test whether your system has <> available. The alternate function <<_system_r>> is a reentrant version. The extra argument <[reent]> is a pointer to a reentrancy structure. RETURNS <> returns a non-zero value if <> is available, and <<0>> if it is not. With a command argument, the result of <> is the exit status returned by <>. PORTABILITY ANSI C requires <>, but leaves the nature and effects of a command processor undefined. ANSI C does, however, specify that <> return zero or nonzero to report on the existence of a command processor. POSIX.2 requires <>, and requires that it invoke a <>. Where <> is found is left unspecified. Supporting OS subroutines required: <<_exit>>, <<_execve>>, <<_fork_r>>, <<_wait_r>>. */ #include #include #include #include #include #if defined(unix) || defined(__CYGWIN__) static int do_system(const char *s); #endif int system(const char *s) { #if defined(HAVE_SYSTEM) return _system(s); #elif defined(NO_EXEC) if (s == NULL) return 0; errno = ENOSYS; return -1; #else /* ??? How to handle (s == NULL) here is not exactly clear. If _fork_r fails, that's not really a justification for returning 0. For now we always return 0 and leave it to each target to explicitly handle otherwise (this can always be relaxed in the future). */ #if defined(unix) || defined(__CYGWIN__) if (s == NULL) return 1; return do_system(s); #else if (s == NULL) return 0; errno = ENOSYS; return -1; #endif #endif } #if defined(unix) && !defined(__CYGWIN__) && !defined(__rtems__) extern char **environ; /* Only deal with a pointer to environ, to work around subtle bugs with shared libraries and/or small data systems where the user declares his own 'environ'. */ static char ***p_environ = &environ; static int do_system(const char *s) { char *argv[4]; int pid, status; argv[0] = "sh"; argv[1] = "-c"; argv[2] = (char *)s; argv[3] = NULL; if ((pid = fork()) == 0) { execve("/bin/sh", argv, *p_environ); exit(100); } else if (pid == -1) return -1; else { int rc = wait(&status); if (rc == -1) return -1; status = (status >> 8) & 0xff; return status; } } #endif picolibc-1.8.11/libc/stdlib/uctoej.c000066400000000000000000000067051513574234600172370ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #ifdef __MB_EXTENDED_CHARSETS_JIS #ifdef __AVR__ #define split_unicode #endif #define define_unicode #define define_unicode_ff #include "jis.h" uint32_t __unicode_to_euc_jp(wchar_t unicode) { #if __SIZEOF_WCHAR_T__ > 2 if (unicode > 0xffff) return INVALID_JIS; #endif uint8_t row = unicode >> 8; uint8_t col = unicode; uint8_t first_col, last_col; const uint16_t *codes; uint16_t jis; const struct jis_charmap *map; /* ASCII */ if (row == 0) if (col < 0xa0 && col != 0x8f && col != 0x8e) return unicode; if (row == 0xff) { codes = __euc_jp_unicode_ff_codes; first_col = __euc_jp_unicode_ff_first_col; last_col = __euc_jp_unicode_ff_last_col; } else { #if __euc_jp_unicode_first_row != 0 if (row < __euc_jp_unicode_first_row) return INVALID_JIS; #endif if (row > __euc_jp_unicode_last_row) return INVALID_JIS; map = &__euc_jp_unicode_map[row - __euc_jp_unicode_first_row]; if (map->offset == 0xffff) return INVALID_JIS; #ifdef split_unicode if (map->offset >= __euc_jp_split_codes) { codes = __euc_jp_unicode_codes_second + (map->offset - __euc_jp_split_codes); } else #endif { codes = __euc_jp_unicode_codes + map->offset; } first_col = map->first; last_col = map->last; } if (col < first_col || last_col < col) return INVALID_JIS; jis = codes[col - first_col]; if (jis == __euc_jp_invalid_jis) return INVALID_JIS; /* Map JIS X213 values */ if ((jis & 0x8000) == 0 && (jis & 0x80) != 0) return (uint32_t)jis | (uint32_t)0x8f8000U; return jis; } #endif /* __MB_EXTENDED_CHARSETS_JIS */ picolibc-1.8.11/libc/stdlib/uctoji.c000066400000000000000000000040471513574234600172400ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #ifdef __MB_EXTENDED_CHARSETS_JIS #include "jis.h" uint16_t __unicode_to_jis(wchar_t jis) { uint32_t euc_jp = __unicode_to_euc_jp((uint16_t)jis); /* JIS encoding doesn't support JIS X0213 yet */ if (euc_jp > 0xffff) return INVALID_JIS; /* Translate from EUC-JP */ if (euc_jp != INVALID_JIS && euc_jp > 0xff) euc_jp &= 0x7f7f; return euc_jp; } #endif /* __MB_EXTENDED_CHARSETS_JIS */ picolibc-1.8.11/libc/stdlib/uctosj.c000066400000000000000000000057571513574234600172630ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2025 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #ifdef __MB_EXTENDED_CHARSETS_JIS #include "jis.h" uint16_t __unicode_to_shift_jis(wchar_t unicode) { /* Deviations from EUC-JP */ switch (unicode) { case 0xa5: /* ¥ */ return 0x5c; case 0x203e: /* ‾ */ return 0x7e; case 0xffe0: /* ¢ -> ¢ */ return 0x8191; case 0xffe1: /* £ -> £ */ return 0x8192; case 0xffe2: /* ¬ -> ¬ */ return 0x81ca; default: break; } /* ASCII */ if (unicode <= 0x7f) return unicode; /* Shift-JIS doesn't include these control chars */ if (unicode <= 0x9f) return INVALID_JIS; uint32_t euc_jp = __unicode_to_euc_jp(unicode); if (euc_jp == INVALID_JIS) return euc_jp; /* shift-jis doesn't handle 3-byte euc-jp values */ if (euc_jp > 0xffff) return INVALID_JIS; /* Katakana */ if (0x8ea1 <= euc_jp && euc_jp <= 0x8efe) { return euc_jp - 0x8e00; } /* Convert to JIS X 0208 values */ uint8_t j1 = (euc_jp >> 8) & 0x7f; uint8_t j2 = euc_jp & 0x7f; uint8_t s1, s2; /* Compute Shift-JIS bytes */ if (33 <= j1 && j1 <= 94) s1 = ((j1 + 1) >> 1) + 112; else s1 = ((j1 + 1) >> 1) + 176; if (j1 & 1) s2 = j2 + 31 + (j2 / 96); else s2 = j2 + 126; return ((uint16_t)s1 << 8) | s2; } #endif /* __MB_EXTENDED_CHARSETS_JIS */ picolibc-1.8.11/libc/stdlib/utoa.c000066400000000000000000000030571513574234600167130ustar00rootroot00000000000000/* Copyright (c) 2014 Corinna Vinschen */ /* FUNCTION <>---unsigned integer to string INDEX utoa SYNOPSIS #include char *utoa(unsigned <[value]>, char *<[str]>, int <[base]>); char *__utoa(unsigned <[value]>, char *<[str]>, int <[base]>); DESCRIPTION <> converts the unsigned integer [] to a null-terminated string using the specified base, which must be between 2 and 36, inclusive. <[str]> should be an array long enough to contain the converted value, which in the worst case is sizeof(int)*8+1 bytes. RETURNS A pointer to the string, <[str]>, or NULL if <[base]> is invalid. PORTABILITY <> is non-ANSI. No supporting OS subroutine calls are required. */ #define _DEFAULT_SOURCE #include char * __utoa(unsigned value, char *str, int base) { const char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; int i, j; unsigned remainder; char c; /* Check base is supported. */ if ((base < 2) || (base > 36)) { str[0] = '\0'; return NULL; } /* Convert to string. Digits are in reverse order. */ i = 0; do { remainder = value % base; str[i++] = digits[remainder]; value = value / base; } while (value != 0); str[i] = '\0'; /* Reverse string. */ for (j = 0, i--; j < i; j++, i--) { c = str[j]; str[j] = str[i]; str[i] = c; } return str; } char * utoa(unsigned value, char *str, int base) { return __utoa(value, str, base); } picolibc-1.8.11/libc/stdlib/valloc.c000066400000000000000000000030411513574234600172140ustar00rootroot00000000000000/* * Copyright (c) 2012, 2013 ARM Ltd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the company may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "local-malloc.h" void * valloc(size_t s) { return memalign(MALLOC_PAGE_ALIGN, s); } picolibc-1.8.11/libc/stdlib/wcrtomb.c000066400000000000000000000012621513574234600174140ustar00rootroot00000000000000/* Copyright (c) 2002 Thomas Fitzsimmons */ #include #include #include #include #include "local.h" size_t wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps) { int retval = 0; char buf[10]; #ifdef __MB_CAPABLE if (ps == NULL) { static mbstate_t _wcrtomb_state; ps = &_wcrtomb_state; } #endif if (s == NULL) retval = __WCTOMB(buf, L'\0', ps); else retval = __WCTOMB(s, wc, ps); if (retval == -1) { #ifdef __MB_CAPABLE ps->__count = 0; #endif errno = EILSEQ; return (size_t)(-1); } else return (size_t)retval; } picolibc-1.8.11/libc/stdlib/wcsnrtombs.c000066400000000000000000000101111513574234600201310ustar00rootroot00000000000000/* Copyright (c) 2009 Corinna Vinschen */ /* FUNCTION <>, <>---convert a wide-character string to a character string INDEX wcsrtombs INDEX _wcsrtombs_r INDEX wcsnrtombs INDEX _wcsnrtombs_r SYNOPSIS #include size_t wcsrtombs(char *__restrict <[dst]>, const wchar_t **__restrict <[src]>, size_t <[len]>, mbstate_t *__restrict <[ps]>); #include size_t _wcsrtombs_r(struct _reent *<[ptr]>, char *<[dst]>, const wchar_t **<[src]>, size_t <[len]>, mbstate_t *<[ps]>); #include size_t wcsnrtombs(char *__restrict <[dst]>, const wchar_t **__restrict <[src]>, size_t <[nwc]>, size_t <[len]>, mbstate_t *__restrict <[ps]>); #include size_t _wcsnrtombs_r(struct _reent *<[ptr]>, char *<[dst]>, const wchar_t **<[src]>, size_t <[nwc]>, size_t <[len]>, mbstate_t *<[ps]>); DESCRIPTION The <> function converts a string of wide characters indirectly pointed to by <[src]> to a corresponding multibyte character string stored in the array pointed to by <[dst]>. No more than <[len]> bytes are written to <[dst]>. If <[dst]> is NULL, no characters are stored. If <[dst]> is not NULL, the pointer pointed to by <[src]> is updated to point to the character after the one that conversion stopped at. If conversion stops because a null character is encountered, *<[src]> is set to NULL. The mbstate_t argument, <[ps]>, is used to keep track of the shift state. If it is NULL, <> uses an internal, static mbstate_t object, which is initialized to the initial conversion state at program startup. The <> function behaves identically to <>, except that conversion stops after reading at most <[nwc]> characters from the buffer pointed to by <[src]>. RETURNS The <> and <> functions return the number of bytes stored in the array pointed to by <[dst]> (not including any terminating null), if successful, otherwise it returns (size_t)-1. PORTABILITY <> is defined by C99 standard. <> is defined by the POSIX.1-2008 standard. */ #define _DEFAULT_SOURCE #include #include #include #include #include "local.h" #include "local.h" size_t _wcsnrtombs_l(char *dst, const wchar_t **src, size_t nwc, size_t len, mbstate_t *ps, locale_t loc) { char *ptr = dst; char buff[10]; wchar_t *pwcs; size_t n; int i; #ifdef __MB_CAPABLE if (ps == NULL) { static mbstate_t _wcsrtombs_state; ps = &_wcsrtombs_state; } #endif /* If no dst pointer, treat len as maximum possible value. */ if (dst == NULL) len = (size_t)-1; n = 0; pwcs = (wchar_t *)(*src); while (n < len && nwc-- > 0) { int count = ps->__count; wint_t wch = ps->__value.__wch; int bytes = __WCTOMB_L(loc)(buff, *pwcs, ps); if (bytes == -1) { errno = EILSEQ; ps->__count = 0; return (size_t)-1; } if (n + bytes <= len) { n += bytes; if (dst) { for (i = 0; i < bytes; ++i) *ptr++ = buff[i]; ++(*src); } if (*pwcs++ == 0x00) { if (dst) *src = NULL; ps->__count = 0; return n - 1; } } else { /* not enough room, we must back up state to before __WCTOMB call */ ps->__count = count; ps->__value.__wch = wch; len = 0; } } return n; } size_t wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t nwc, size_t len, mbstate_t * __restrict ps) { return _wcsnrtombs_l(dst, src, nwc, len, ps, __get_current_locale()); } picolibc-1.8.11/libc/stdlib/wcsrtombs.c000066400000000000000000000004751513574234600177670ustar00rootroot00000000000000/* Copyright (c) 2002 Thomas Fitzsimmons */ /* Doc in wcsnrtombs.c */ #define _DEFAULT_SOURCE #include size_t wcsrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t len, mbstate_t * __restrict ps) { return wcsnrtombs(dst, src, (size_t)-1, len, ps); } picolibc-1.8.11/libc/stdlib/wcstombs.c000066400000000000000000000053011513574234600175760ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* FUNCTION <>---minimal wide char string to multibyte string converter INDEX wcstombs SYNOPSIS #include size_t wcstombs(char *restrict <[s]>, const wchar_t *restrict <[pwc]>, size_t <[n]>); DESCRIPTION When __MB_CAPABLE is not defined, this is a minimal ANSI-conforming implementation of <>. In this case, all wide-characters are expected to represent single bytes and so are converted simply by casting to char. When __MB_CAPABLE is defined, this routine uses a state variable to allow state dependent decoding. The result is based on the locale setting which may be restricted to a defined set of locales. RETURNS This implementation of <> returns <<0>> if <[s]> is <> or is the empty string; it returns <<-1>> if __MB_CAPABLE and one of the wide-char characters does not represent a valid multi-byte character; otherwise it returns the minimum of: <> or the number of bytes that are transferred to <>, not including the nul terminator. If the return value is -1, the state of the <> string is indeterminate. If the input has a length of 0, the output string will be modified to contain a wchar_t nul terminator if <> > 0. PORTABILITY <> is required in the ANSI C standard. However, the precise effects vary with the locale. <> requires no supporting OS subroutines. */ #include #include #include "local.h" size_t wcstombs(char * __restrict s, const wchar_t * __restrict pwcs, size_t n) { #ifdef __MB_CAPABLE mbstate_t state; state.__count = 0; char *ptr = s; size_t max = n; char buff[8]; int i, bytes, num_to_copy; if (s == NULL) { size_t num_bytes = 0; while (*pwcs != 0) { bytes = __WCTOMB(buff, *pwcs++, &state); if (bytes == -1) return -1; num_bytes += bytes; } return num_bytes; } else { while (n > 0) { bytes = __WCTOMB(buff, *pwcs, &state); if (bytes == -1) return -1; num_to_copy = (n > (size_t)bytes ? bytes : (int)n); for (i = 0; i < num_to_copy; ++i) *ptr++ = buff[i]; if (*pwcs == 0x00) return ptr - s - (n >= (size_t)bytes); ++pwcs; n -= num_to_copy; } return max; } #else /* not __MB_CAPABLE */ int count = 0; if (n != 0) { do { if ((*s++ = (char)*pwcs++) == 0) break; count++; } while (--n != 0); } return count; #endif /* not __MB_CAPABLE */ } picolibc-1.8.11/libc/stdlib/wctob.c000066400000000000000000000006601513574234600170560ustar00rootroot00000000000000/* Copyright (c) 2002 Thomas Fitzsimmons */ #include #include #include #include #include "local.h" int wctob(wint_t wc) { mbstate_t mbs; unsigned char pmb[MB_LEN_MAX]; if (wc == WEOF) return EOF; /* Put mbs in initial state. */ memset(&mbs, '\0', sizeof(mbs)); return __WCTOMB((char *)pmb, wc, &mbs) == 1 ? (int)pmb[0] : EOF; } picolibc-1.8.11/libc/stdlib/wctomb.c000066400000000000000000000033411513574234600172320ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ /* FUNCTION <>---minimal wide char to multibyte converter INDEX wctomb SYNOPSIS #include int wctomb(char *<[s]>, wchar_t <[wchar]>); DESCRIPTION When __MB_CAPABLE is not defined, this is a minimal ANSI-conforming implementation of <>. The only ``wide characters'' recognized are single bytes, and they are ``converted'' to themselves. When __MB_CAPABLE is defined, this routine calls <<_wctomb_r>> to perform the conversion, passing a state variable to allow state dependent decoding. The result is based on the locale setting which may be restricted to a defined set of locales. Each call to <> modifies <<*<[s]>>> unless <[s]> is a null pointer or __MB_CAPABLE is defined and <[wchar]> is invalid. RETURNS This implementation of <> returns <<0>> if <[s]> is <>; it returns <<-1>> if __MB_CAPABLE is enabled and the wchar is not a valid multi-byte character, it returns <<1>> if __MB_CAPABLE is not defined or the wchar is in reality a single byte character, otherwise it returns the number of bytes in the multi-byte character. PORTABILITY <> is required in the ANSI C standard. However, the precise effects vary with the locale. <> requires no supporting OS subroutines. */ #include #include #include "local.h" #ifdef __MB_CAPABLE static mbstate_t _mbtowc_state; #define ps &_mbtowc_state #else #define ps NULL #endif int wctomb(char *s, wchar_t wchar) { int retval; retval = __WCTOMB(s, wchar, ps); if (retval == -1) { #ifdef __MB_CAPABLE _mbtowc_state.__count = 0; #endif errno = EILSEQ; } return retval; } picolibc-1.8.11/libc/stdlib/wctomb_r.c000066400000000000000000000420311513574234600175520ustar00rootroot00000000000000/* Copyright (c) 1990 Regents of the University of California. All rights reserved. */ #include #include #include #include #include #include #include #include "mbctype.h" #include "local.h" #include "../ctype/local.h" int __ascii_wctomb(char *s, wchar_t wchar, mbstate_t *state) { (void)state; if (s == NULL) return 0; if (wchar >= 0x80) return -1; *s = (char)wchar; return 1; } #ifdef __MB_CAPABLE /* for some conversions, we use the __count field as a place to store a state value */ #define __state __count int __utf8_wctomb(char *s, wchar_t wchar, mbstate_t *state) { (void)state; /* unused when wchar_t is 32-bits */ if (s == NULL) { #if __SIZEOF_WCHAR_T__ == 2 state->__count = 0; /* UTF-16 encoding is state-dependent */ #endif return 0; } #if __SIZEOF_WCHAR_T__ == 2 if (state->__count == -4) { state->__count = 0; /* Check for low surrogate */ if (0xdc00 <= (uwchar_t)wchar && (uwchar_t)wchar <= 0xdfff) { uint32_t tmp; /* Second half of a surrogate pair. Reconstruct the full Unicode value and return the trailing three bytes of the UTF-8 character. */ tmp = state->__value.__ucs | (wchar & 0x3ff); *s++ = 0xf0 | ((tmp & 0x1c0000) >> 18); *s++ = 0x80 | ((tmp & 0x3f000) >> 12); *s++ = 0x80 | ((tmp & 0xfc0) >> 6); *s = 0x80 | (tmp & 0x3f); return 4; } /* Not a low surrogate */ return -1; } #endif if (wchar <= 0x7f) { *s = wchar; return 1; } if (wchar >= 0x80 && wchar <= 0x7ff) { *s++ = 0xc0 | ((wchar & 0x7c0) >> 6); *s = 0x80 | (wchar & 0x3f); return 2; } if (wchar >= 0x800 #if __SIZEOF_WCHAR_T__ > 2 && (uwchar_t)wchar <= 0xffff #endif ) { if ((uwchar_t)wchar >= 0xd800 && (uwchar_t)wchar <= 0xdfff) { #if __SIZEOF_WCHAR_T__ == 2 if ((uwchar_t)wchar <= 0xdbff) { /* First half of a surrogate pair. Store the state and return 0. */ state->__value.__ucs = ((uint32_t)(wchar & 0x3ff) << 10) + 0x10000; state->__count = -4; return 0; } #endif /* Unexpected surrogate */ return -1; } *s++ = 0xe0 | ((wchar & 0xf000) >> 12); *s++ = 0x80 | ((wchar & 0xfc0) >> 6); *s = 0x80 | (wchar & 0x3f); return 3; } #if __SIZEOF_WCHAR_T__ == 4 if ((uwchar_t)wchar >= (uwchar_t)0x10000 && (uwchar_t)wchar <= (uwchar_t)0x10ffff) { *s++ = 0xf0 | ((wchar & 0x1c0000) >> 18); *s++ = 0x80 | ((wchar & 0x3f000) >> 12); *s++ = 0x80 | ((wchar & 0xfc0) >> 6); *s = 0x80 | (wchar & 0x3f); return 4; } #endif return -1; } #ifdef __MB_EXTENDED_CHARSETS_UCS #if _BYTE_ORDER == _LITTLE_ENDIAN #define __ucs2le_wctomb __ucs2_wctomb #define __ucs2be_wctomb __ucs2swap_wctomb #define __ucs4le_wctomb __ucs4_wctomb #define __ucs4be_wctomb __ucs4swap_wctomb #else #define __ucs2le_wctomb __ucs2swap_wctomb #define __ucs2be_wctomb __ucs2_wctomb #define __ucs4le_wctomb __ucs4swap_wctomb #define __ucs4be_wctomb __ucs4_wctomb #endif static int __ucs2_wctomb(char *s, wchar_t wchar, mbstate_t *state) { uint16_t uchar = (uint16_t)wchar; (void)state; /* Surrogates are invalid in UCS-2 */ if ((uwchar_t)wchar >= 0xd800 && (uwchar_t)wchar <= 0xdfff) return -1; memcpy((void *)s, &uchar, 2); return 2; } static int __ucs2swap_wctomb(char *s, wchar_t wchar, mbstate_t *state) { uint16_t uchar = __bswap16((uint16_t)wchar); (void)state; /* Surrogates are invalid in UCS-2 */ if ((uwchar_t)wchar >= 0xd800 && (uwchar_t)wchar <= 0xdfff) return -1; memcpy((void *)s, &uchar, 2); return 2; } static int __ucs4_wctomb(char *s, wchar_t wchar, mbstate_t *state) { uint32_t uchar = (uint32_t)wchar; (void)state; /* Surrogates are invalid in UCS-4 */ if ((uwchar_t)wchar >= 0xd800 && (uwchar_t)wchar <= 0xdfff) return -1; memcpy((void *)s, &uchar, 4); return 4; } static int __ucs4swap_wctomb(char *s, wchar_t wchar, mbstate_t *state) { uint32_t uchar = __bswap32((uint32_t)wchar); (void)state; /* Surrogates are invalid in UCS-4 */ if ((uwchar_t)wchar >= 0xd800 && (uwchar_t)wchar <= 0xdfff) return -1; memcpy((void *)s, &uchar, 4); return 4; } #endif /* __MB_EXTENDED_CHARSETS_UCS */ #ifdef __MB_EXTENDED_CHARSETS_JIS #include "jis.h" static int __sjis_wctomb(char *s, wchar_t wchar, mbstate_t *state) { (void)state; if (s == NULL) return 0; /* not state-dependent */ uint16_t jischar = __unicode_to_shift_jis(wchar); if (jischar == INVALID_JIS) return -1; uint8_t char2 = (uint8_t)jischar; uint8_t char1 = (uint8_t)(jischar >> 8); if (char1 != 0x00) { s[0] = (char)char1; s[1] = (char)char2; return 2; } else { s[0] = (char)char2; return 1; } } static int __eucjp_wctomb(char *s, wchar_t wchar, mbstate_t *state) { (void)state; if (s == NULL) return 0; /* not state-dependent */ uint32_t jischar = __unicode_to_euc_jp(wchar); if (jischar == INVALID_JIS) return -1; uint8_t char2 = (uint8_t)jischar; uint8_t char1 = (uint8_t)(jischar >> 8); uint8_t char0 = (uint8_t)(jischar >> 16); if (char0 != 0x00) { s[0] = (char)char0; s[1] = (char)char1; s[2] = (char)char2; return 3; } else if (char1 != 0x00) { s[0] = (char)char1; s[1] = (char)char2; return 2; } else { s[0] = (char)char2; return 1; } } static int __jis_wctomb(char *s, wchar_t wchar, mbstate_t *state) { if (s == NULL) return 1; /* state-dependent */ uint16_t jischar = __unicode_to_jis(wchar); if (jischar == INVALID_JIS) return -1; uint8_t char2 = (uint8_t)jischar; uint8_t char1 = (uint8_t)(jischar >> 8); int cnt = 0; if (char1 != 0x00) { /* first byte is non-zero; multi-byte char */ if (state->__state == 0) { /* must switch from ASCII to JIS state */ state->__state = 1; *s++ = ESC_CHAR; *s++ = '$'; *s++ = 'B'; cnt = 3; } s[0] = (char)char1; s[1] = (char)char2; return cnt + 2; } else { /* first byte zero; single-byte char */ if (state->__state != 0) { /* must switch from JIS to ASCII state */ state->__state = 0; *s++ = ESC_CHAR; *s++ = '('; *s++ = 'B'; cnt = 3; } s[0] = (char)char2; return cnt + 1; } } #endif /* __MB_EXTENDED_CHARSETS_JIS */ #ifdef __MB_EXTENDED_CHARSETS_ISO static int ___iso_wctomb(char *s, wchar_t wchar, enum locale_id id, mbstate_t *state) { (void)state; if (s == NULL) return 0; /* wchars <= 0x9f translate to all ISO charsets directly. */ if (wchar >= 0xa0) { unsigned char mb; if ((uwchar_t)wchar > __iso_8859_max[id - locale_ISO_8859_2]) return -1; for (mb = 0; mb < 0x60; ++mb) if (__iso_8859_conv[id - locale_ISO_8859_2][mb] == (uwchar_t)wchar) { *s = (char)(mb + 0xa0); return 1; } return -1; } if (wchar >= 0x100) { return -1; } *s = (char)wchar; return 1; } static int __iso_8859_1_wctomb(char *s, wchar_t wchar, mbstate_t *state) { (void)state; if (s == NULL) return 0; if (wchar >= 0x100) { return -1; } *s = (char)wchar; return 1; } static int __iso_8859_2_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___iso_wctomb(s, _wchar, locale_ISO_8859_2, state); } static int __iso_8859_3_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___iso_wctomb(s, _wchar, locale_ISO_8859_3, state); } static int __iso_8859_4_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___iso_wctomb(s, _wchar, locale_ISO_8859_4, state); } static int __iso_8859_5_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___iso_wctomb(s, _wchar, locale_ISO_8859_5, state); } static int __iso_8859_6_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___iso_wctomb(s, _wchar, locale_ISO_8859_6, state); } static int __iso_8859_7_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___iso_wctomb(s, _wchar, locale_ISO_8859_7, state); } static int __iso_8859_8_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___iso_wctomb(s, _wchar, locale_ISO_8859_8, state); } static int __iso_8859_9_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___iso_wctomb(s, _wchar, locale_ISO_8859_9, state); } static int __iso_8859_10_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___iso_wctomb(s, _wchar, locale_ISO_8859_10, state); } static int __iso_8859_11_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___iso_wctomb(s, _wchar, locale_ISO_8859_11, state); } static int __iso_8859_13_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___iso_wctomb(s, _wchar, locale_ISO_8859_13, state); } static int __iso_8859_14_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___iso_wctomb(s, _wchar, locale_ISO_8859_14, state); } static int __iso_8859_15_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___iso_wctomb(s, _wchar, locale_ISO_8859_15, state); } static int __iso_8859_16_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___iso_wctomb(s, _wchar, locale_ISO_8859_16, state); } #endif /* __MB_EXTENDED_CHARSETS_ISO */ #ifdef __MB_EXTENDED_CHARSETS_WINDOWS #ifdef __AVR__ /* The avr compiler gets confused by the use of __cp_conv below */ #ifdef __GNUCLIKE_PRAGMA_DIAGNOSTIC #pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wunknown-warning-option" #pragma GCC diagnostic ignored "-Wanalyzer-out-of-bounds" #endif #endif static int ___cp_wctomb(char *s, wchar_t wchar, int cp_idx, mbstate_t *state) { (void)state; if (s == NULL) return 0; if (wchar >= 0x80) { if (cp_idx >= 0) { unsigned char mb; if ((uwchar_t)wchar > __cp_max[cp_idx]) return -1; for (mb = 0; mb < 0x80; ++mb) if (__cp_conv[cp_idx][mb] == (uwchar_t)wchar) { *s = (char)(mb + 0x80); return 1; } return -1; } } if (wchar >= 0x100) { return -1; } *s = (char)wchar; return 1; } static int __cp_437_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 0, state); } static int __cp_720_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 1, state); } static int __cp_737_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 2, state); } static int __cp_775_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 3, state); } static int __cp_850_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 4, state); } static int __cp_852_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 5, state); } static int __cp_855_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 6, state); } static int __cp_857_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 7, state); } static int __cp_858_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 8, state); } static int __cp_862_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 9, state); } static int __cp_866_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 10, state); } static int __cp_874_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 11, state); } static int __cp_1125_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 12, state); } static int __cp_1250_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 13, state); } static int __cp_1251_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 14, state); } static int __cp_1252_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 15, state); } static int __cp_1253_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 16, state); } static int __cp_1254_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 17, state); } static int __cp_1255_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 18, state); } static int __cp_1256_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 19, state); } static int __cp_1257_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 20, state); } static int __cp_1258_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 21, state); } static int __cp_20866_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 22, state); } static int __cp_21866_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 23, state); } static int __cp_101_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 24, state); } static int __cp_102_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 25, state); } static int __cp_103_wctomb(char *s, wchar_t _wchar, mbstate_t *state) { return ___cp_wctomb(s, _wchar, 26, state); } #endif /* __MB_EXTENDED_CHARSETS_WINDOWS */ const wctomb_p __wctomb[locale_END - locale_BASE] = { [locale_C - locale_BASE] = __ascii_wctomb, [locale_UTF_8 - locale_BASE] = __utf8_wctomb, #ifdef __MB_EXTENDED_CHARSETS_UCS [locale_UCS_2 - locale_BASE] = __ucs2_wctomb, [locale_UCS_2LE - locale_BASE] = __ucs2le_wctomb, [locale_UCS_2BE - locale_BASE] = __ucs2be_wctomb, [locale_UCS_4 - locale_BASE] = __ucs4_wctomb, [locale_UCS_4LE - locale_BASE] = __ucs4le_wctomb, [locale_UCS_4BE - locale_BASE] = __ucs4be_wctomb, #endif #ifdef __MB_EXTENDED_CHARSETS_ISO [locale_ISO_8859_1 - locale_BASE] = __iso_8859_1_wctomb, [locale_ISO_8859_2 - locale_BASE] = __iso_8859_2_wctomb, [locale_ISO_8859_3 - locale_BASE] = __iso_8859_3_wctomb, [locale_ISO_8859_4 - locale_BASE] = __iso_8859_4_wctomb, [locale_ISO_8859_5 - locale_BASE] = __iso_8859_5_wctomb, [locale_ISO_8859_6 - locale_BASE] = __iso_8859_6_wctomb, [locale_ISO_8859_7 - locale_BASE] = __iso_8859_7_wctomb, [locale_ISO_8859_8 - locale_BASE] = __iso_8859_8_wctomb, [locale_ISO_8859_9 - locale_BASE] = __iso_8859_9_wctomb, [locale_ISO_8859_10 - locale_BASE] = __iso_8859_10_wctomb, [locale_ISO_8859_11 - locale_BASE] = __iso_8859_11_wctomb, [locale_ISO_8859_13 - locale_BASE] = __iso_8859_13_wctomb, [locale_ISO_8859_14 - locale_BASE] = __iso_8859_14_wctomb, [locale_ISO_8859_15 - locale_BASE] = __iso_8859_15_wctomb, [locale_ISO_8859_16 - locale_BASE] = __iso_8859_16_wctomb, #endif #ifdef __MB_EXTENDED_CHARSETS_WINDOWS [locale_CP437 - locale_BASE] = __cp_437_wctomb, [locale_CP720 - locale_BASE] = __cp_720_wctomb, [locale_CP737 - locale_BASE] = __cp_737_wctomb, [locale_CP775 - locale_BASE] = __cp_775_wctomb, [locale_CP850 - locale_BASE] = __cp_850_wctomb, [locale_CP852 - locale_BASE] = __cp_852_wctomb, [locale_CP855 - locale_BASE] = __cp_855_wctomb, [locale_CP857 - locale_BASE] = __cp_857_wctomb, [locale_CP858 - locale_BASE] = __cp_858_wctomb, [locale_CP862 - locale_BASE] = __cp_862_wctomb, [locale_CP866 - locale_BASE] = __cp_866_wctomb, [locale_CP874 - locale_BASE] = __cp_874_wctomb, [locale_CP1125 - locale_BASE] = __cp_1125_wctomb, [locale_CP1250 - locale_BASE] = __cp_1250_wctomb, [locale_CP1251 - locale_BASE] = __cp_1251_wctomb, [locale_CP1252 - locale_BASE] = __cp_1252_wctomb, [locale_CP1253 - locale_BASE] = __cp_1253_wctomb, [locale_CP1254 - locale_BASE] = __cp_1254_wctomb, [locale_CP1255 - locale_BASE] = __cp_1255_wctomb, [locale_CP1256 - locale_BASE] = __cp_1256_wctomb, [locale_CP1257 - locale_BASE] = __cp_1257_wctomb, [locale_CP1258 - locale_BASE] = __cp_1258_wctomb, [locale_KOI8_R - locale_BASE] = __cp_20866_wctomb, [locale_KOI8_U - locale_BASE] = __cp_21866_wctomb, [locale_GEORGIAN_PS - locale_BASE] = __cp_101_wctomb, [locale_PT154 - locale_BASE] = __cp_102_wctomb, [locale_KOI8_T - locale_BASE] = __cp_103_wctomb, #endif #ifdef __MB_EXTENDED_CHARSETS_JIS [locale_JIS - locale_BASE] = __jis_wctomb, [locale_EUCJP - locale_BASE] = __eucjp_wctomb, [locale_SJIS - locale_BASE] = __sjis_wctomb, #endif }; #endif /* __MB_CAPABLE */ picolibc-1.8.11/libc/string/000077500000000000000000000000001513574234600156175ustar00rootroot00000000000000picolibc-1.8.11/libc/string/CMakeLists.txt000066400000000000000000000057311513574234600203650ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2022 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # picolibc_sources( bcmp.c bcopy.c bzero.c explicit_bzero.c ffsl.c ffsll.c fls.c flsl.c flsll.c gnu_basename.c index.c memccpy.c memchr.c memcmp.c memcpy.c memmem.c memmove.c mempcpy.c memrchr.c memset.c memset_explicit.c rawmemchr.c rindex.c stpcpy.c stpncpy.c strcasecmp.c strcasecmp_l.c strcasestr.c strcat.c strchr.c strchrnul.c strcoll.c strcoll_l.c strcmp.c strcpy.c strcspn.c strdup.c strerror.c strerror_r.c strlcat.c strlcpy.c strlen.c strlwr.c strncasecmp.c strncasecmp_l.c strncat.c strncmp.c strncpy.c strndup.c strnlen.c strnstr.c strpbrk.c strrchr.c strsep.c strsignal.c strspn.c strstr.c strtok.c strtok_r.c strupr.c strverscmp.c strxfrm.c strxfrm_l.c swab.c timingsafe_bcmp.c timingsafe_memcmp.c wcpcpy.c wcpncpy.c wcscasecmp.c wcscasecmp_l.c wcscat.c wcschr.c wcscmp.c wcscoll.c wcscoll_l.c wcscpy.c wcscspn.c wcsdup.c wcslcat.c wcslcpy.c wcslen.c wcsncasecmp.c wcsncasecmp_l.c wcsncat.c wcsncmp.c wcsncpy.c wcsnlen.c wcspbrk.c wcsrchr.c wcsspn.c wcsstr.c wcstok.c wcswidth.c wcsxfrm.c wcsxfrm_l.c wcwidth.c wmemchr.c wmemcmp.c wmemcpy.c wmemmove.c wmempcpy.c wmemset.c xpg_strerror_r.c memcpy_s.c memmove_s.c memset_s.c strcat_s.c strcpy_s.c strerror_s.c strerrorlen_s.c strncat_s.c strncpy_s.c strnlen_s.c ) picolibc-1.8.11/libc/string/WIDTH-A000066400000000000000000000170541513574234600166060ustar00rootroot00000000000000# This file is automatically generated # UAX #11: East Asian Ambiguous # Plane 00 # Rows Positions (Cells) 00 A1 A4 A7-A8 AA AD-AE B0-B4 B6-BA BC-BF C6 D0 D7-D8 DE-E1 E6 E8-EA 00 EC-ED F0 F2-F3 F7-FA FC FE 01 01 11 13 1B 26-27 2B 31-33 38 3F-42 44 48-4B 4D 52-53 66-67 6B 01 CE D0 D2 D4 D6 D8 DA DC 02 51 61 C4 C7 C9-CB CD D0 D8-DB DD DF 03 00-6F 91-A1 A3-A9 B1-C1 C3-C9 04 01 10-4F 51 20 10 13-16 18-19 1C-1D 20-22 24-27 30 32-33 35 3B 3E 74 7F 81-84 20 AC 21 03 05 09 13 16 21-22 26 2B 53-54 5B-5E 60-6B 70-79 89 90-99 B8-B9 21 D2 D4 E7 22 00 02-03 07-08 0B 0F 11 15 1A 1D-20 23 25 27-2C 2E 34-37 3C-3D 22 48 4C 52 60-61 64-67 6A-6B 6E-6F 82-83 86-87 95 99 A5 BF 23 12 24 60-E9 EB-FF 25 00-4B 50-73 80-8F 92-95 A0-A1 A3-A9 B2-B3 B6-B7 BC-BD C0-C1 C6-C8 25 CB CE-D1 E2-E5 EF 26 05-06 09 0E-0F 1C 1E 40 42 60-61 63-65 67-6A 6C-6D 6F 9E-9F BF 26 C6-CD CF-D3 D5-E1 E3 E8-E9 EB-F1 F4 F6-F9 FB-FC FE-FF 27 3D 76-7F 2B 56-59 32 48-4F E0 00-FF E1 00-FF E2 00-FF E3 00-FF E4 00-FF E5 00-FF E6 00-FF E7 00-FF E8 00-FF E9 00-FF EA 00-FF EB 00-FF EC 00-FF ED 00-FF EE 00-FF EF 00-FF F0 00-FF F1 00-FF F2 00-FF F3 00-FF F4 00-FF F5 00-FF F6 00-FF F7 00-FF F8 00-FF FE 00-0F FF FD 1F1 00-0A 10-2D 30-69 70-8D 8F-90 9B-AC E01 00-EF F00 00-FF F01 00-FF F02 00-FF F03 00-FF F04 00-FF F05 00-FF F06 00-FF F07 00-FF F08 00-FF F09 00-FF F0A 00-FF F0B 00-FF F0C 00-FF F0D 00-FF F0E 00-FF F0F 00-FF F10 00-FF F11 00-FF F12 00-FF F13 00-FF F14 00-FF F15 00-FF F16 00-FF F17 00-FF F18 00-FF F19 00-FF F1A 00-FF F1B 00-FF F1C 00-FF F1D 00-FF F1E 00-FF F1F 00-FF F20 00-FF F21 00-FF F22 00-FF F23 00-FF F24 00-FF F25 00-FF F26 00-FF F27 00-FF F28 00-FF F29 00-FF F2A 00-FF F2B 00-FF F2C 00-FF F2D 00-FF F2E 00-FF F2F 00-FF F30 00-FF F31 00-FF F32 00-FF F33 00-FF F34 00-FF F35 00-FF F36 00-FF F37 00-FF F38 00-FF F39 00-FF F3A 00-FF F3B 00-FF F3C 00-FF F3D 00-FF F3E 00-FF F3F 00-FF F40 00-FF F41 00-FF F42 00-FF F43 00-FF F44 00-FF F45 00-FF F46 00-FF F47 00-FF F48 00-FF F49 00-FF F4A 00-FF F4B 00-FF F4C 00-FF F4D 00-FF F4E 00-FF F4F 00-FF F50 00-FF F51 00-FF F52 00-FF F53 00-FF F54 00-FF F55 00-FF F56 00-FF F57 00-FF F58 00-FF F59 00-FF F5A 00-FF F5B 00-FF F5C 00-FF F5D 00-FF F5E 00-FF F5F 00-FF F60 00-FF F61 00-FF F62 00-FF F63 00-FF F64 00-FF F65 00-FF F66 00-FF F67 00-FF F68 00-FF F69 00-FF F6A 00-FF F6B 00-FF F6C 00-FF F6D 00-FF F6E 00-FF F6F 00-FF F70 00-FF F71 00-FF F72 00-FF F73 00-FF F74 00-FF F75 00-FF F76 00-FF F77 00-FF F78 00-FF F79 00-FF F7A 00-FF F7B 00-FF F7C 00-FF F7D 00-FF F7E 00-FF F7F 00-FF F80 00-FF F81 00-FF F82 00-FF F83 00-FF F84 00-FF F85 00-FF F86 00-FF F87 00-FF F88 00-FF F89 00-FF F8A 00-FF F8B 00-FF F8C 00-FF F8D 00-FF F8E 00-FF F8F 00-FF F90 00-FF F91 00-FF F92 00-FF F93 00-FF F94 00-FF F95 00-FF F96 00-FF F97 00-FF F98 00-FF F99 00-FF F9A 00-FF F9B 00-FF F9C 00-FF F9D 00-FF F9E 00-FF F9F 00-FF FA0 00-FF FA1 00-FF FA2 00-FF FA3 00-FF FA4 00-FF FA5 00-FF FA6 00-FF FA7 00-FF FA8 00-FF FA9 00-FF FAA 00-FF FAB 00-FF FAC 00-FF FAD 00-FF FAE 00-FF FAF 00-FF FB0 00-FF FB1 00-FF FB2 00-FF FB3 00-FF FB4 00-FF FB5 00-FF FB6 00-FF FB7 00-FF FB8 00-FF FB9 00-FF FBA 00-FF FBB 00-FF FBC 00-FF FBD 00-FF FBE 00-FF FBF 00-FF FC0 00-FF FC1 00-FF FC2 00-FF FC3 00-FF FC4 00-FF FC5 00-FF FC6 00-FF FC7 00-FF FC8 00-FF FC9 00-FF FCA 00-FF FCB 00-FF FCC 00-FF FCD 00-FF FCE 00-FF FCF 00-FF FD0 00-FF FD1 00-FF FD2 00-FF FD3 00-FF FD4 00-FF FD5 00-FF FD6 00-FF FD7 00-FF FD8 00-FF FD9 00-FF FDA 00-FF FDB 00-FF FDC 00-FF FDD 00-FF FDE 00-FF FDF 00-FF FE0 00-FF FE1 00-FF FE2 00-FF FE3 00-FF FE4 00-FF FE5 00-FF FE6 00-FF FE7 00-FF FE8 00-FF FE9 00-FF FEA 00-FF FEB 00-FF FEC 00-FF FED 00-FF FEE 00-FF FEF 00-FF FF0 00-FF FF1 00-FF FF2 00-FF FF3 00-FF FF4 00-FF FF5 00-FF FF6 00-FF FF7 00-FF FF8 00-FF FF9 00-FF FFA 00-FF FFB 00-FF FFC 00-FF FFD 00-FF FFE 00-FF FFF 00-FD 1000 00-FF 1001 00-FF 1002 00-FF 1003 00-FF 1004 00-FF 1005 00-FF 1006 00-FF 1007 00-FF 1008 00-FF 1009 00-FF 100A 00-FF 100B 00-FF 100C 00-FF 100D 00-FF 100E 00-FF 100F 00-FF 1010 00-FF 1011 00-FF 1012 00-FF 1013 00-FF 1014 00-FF 1015 00-FF 1016 00-FF 1017 00-FF 1018 00-FF 1019 00-FF 101A 00-FF 101B 00-FF 101C 00-FF 101D 00-FF 101E 00-FF 101F 00-FF 1020 00-FF 1021 00-FF 1022 00-FF 1023 00-FF 1024 00-FF 1025 00-FF 1026 00-FF 1027 00-FF 1028 00-FF 1029 00-FF 102A 00-FF 102B 00-FF 102C 00-FF 102D 00-FF 102E 00-FF 102F 00-FF 1030 00-FF 1031 00-FF 1032 00-FF 1033 00-FF 1034 00-FF 1035 00-FF 1036 00-FF 1037 00-FF 1038 00-FF 1039 00-FF 103A 00-FF 103B 00-FF 103C 00-FF 103D 00-FF 103E 00-FF 103F 00-FF 1040 00-FF 1041 00-FF 1042 00-FF 1043 00-FF 1044 00-FF 1045 00-FF 1046 00-FF 1047 00-FF 1048 00-FF 1049 00-FF 104A 00-FF 104B 00-FF 104C 00-FF 104D 00-FF 104E 00-FF 104F 00-FF 1050 00-FF 1051 00-FF 1052 00-FF 1053 00-FF 1054 00-FF 1055 00-FF 1056 00-FF 1057 00-FF 1058 00-FF 1059 00-FF 105A 00-FF 105B 00-FF 105C 00-FF 105D 00-FF 105E 00-FF 105F 00-FF 1060 00-FF 1061 00-FF 1062 00-FF 1063 00-FF 1064 00-FF 1065 00-FF 1066 00-FF 1067 00-FF 1068 00-FF 1069 00-FF 106A 00-FF 106B 00-FF 106C 00-FF 106D 00-FF 106E 00-FF 106F 00-FF 1070 00-FF 1071 00-FF 1072 00-FF 1073 00-FF 1074 00-FF 1075 00-FF 1076 00-FF 1077 00-FF 1078 00-FF 1079 00-FF 107A 00-FF 107B 00-FF 107C 00-FF 107D 00-FF 107E 00-FF 107F 00-FF 1080 00-FF 1081 00-FF 1082 00-FF 1083 00-FF 1084 00-FF 1085 00-FF 1086 00-FF 1087 00-FF 1088 00-FF 1089 00-FF 108A 00-FF 108B 00-FF 108C 00-FF 108D 00-FF 108E 00-FF 108F 00-FF 1090 00-FF 1091 00-FF 1092 00-FF 1093 00-FF 1094 00-FF 1095 00-FF 1096 00-FF 1097 00-FF 1098 00-FF 1099 00-FF 109A 00-FF 109B 00-FF 109C 00-FF 109D 00-FF 109E 00-FF 109F 00-FF 10A0 00-FF 10A1 00-FF 10A2 00-FF 10A3 00-FF 10A4 00-FF 10A5 00-FF 10A6 00-FF 10A7 00-FF 10A8 00-FF 10A9 00-FF 10AA 00-FF 10AB 00-FF 10AC 00-FF 10AD 00-FF 10AE 00-FF 10AF 00-FF 10B0 00-FF 10B1 00-FF 10B2 00-FF 10B3 00-FF 10B4 00-FF 10B5 00-FF 10B6 00-FF 10B7 00-FF 10B8 00-FF 10B9 00-FF 10BA 00-FF 10BB 00-FF 10BC 00-FF 10BD 00-FF 10BE 00-FF 10BF 00-FF 10C0 00-FF 10C1 00-FF 10C2 00-FF 10C3 00-FF 10C4 00-FF 10C5 00-FF 10C6 00-FF 10C7 00-FF 10C8 00-FF 10C9 00-FF 10CA 00-FF 10CB 00-FF 10CC 00-FF 10CD 00-FF 10CE 00-FF 10CF 00-FF 10D0 00-FF 10D1 00-FF 10D2 00-FF 10D3 00-FF 10D4 00-FF 10D5 00-FF 10D6 00-FF 10D7 00-FF 10D8 00-FF 10D9 00-FF 10DA 00-FF 10DB 00-FF 10DC 00-FF 10DD 00-FF 10DE 00-FF 10DF 00-FF 10E0 00-FF 10E1 00-FF 10E2 00-FF 10E3 00-FF 10E4 00-FF 10E5 00-FF 10E6 00-FF 10E7 00-FF 10E8 00-FF 10E9 00-FF 10EA 00-FF 10EB 00-FF 10EC 00-FF 10ED 00-FF 10EE 00-FF 10EF 00-FF 10F0 00-FF 10F1 00-FF 10F2 00-FF 10F3 00-FF 10F4 00-FF 10F5 00-FF 10F6 00-FF 10F7 00-FF 10F8 00-FF 10F9 00-FF 10FA 00-FF 10FB 00-FF 10FC 00-FF 10FD 00-FF 10FE 00-FF 10FF 00-FD picolibc-1.8.11/libc/string/ambiguous.t000066400000000000000000000071671513574234600200120ustar00rootroot00000000000000/* This file is automatically generated */ { { 0x00A1, 0x00A1 }, { 0x00A4, 0x00A4 }, { 0x00A7, 0x00A8 }, { 0x00AA, 0x00AA }, { 0x00AE, 0x00AE }, { 0x00B0, 0x00B4 }, { 0x00B6, 0x00BA }, { 0x00BC, 0x00BF }, { 0x00C6, 0x00C6 }, { 0x00D0, 0x00D0 }, { 0x00D7, 0x00D8 }, { 0x00DE, 0x00E1 }, { 0x00E6, 0x00E6 }, { 0x00E8, 0x00EA }, { 0x00EC, 0x00ED }, { 0x00F0, 0x00F0 }, { 0x00F2, 0x00F3 }, { 0x00F7, 0x00FA }, { 0x00FC, 0x00FC }, { 0x00FE, 0x00FE }, { 0x0101, 0x0101 }, { 0x0111, 0x0111 }, { 0x0113, 0x0113 }, { 0x011B, 0x011B }, { 0x0126, 0x0127 }, { 0x012B, 0x012B }, { 0x0131, 0x0133 }, { 0x0138, 0x0138 }, { 0x013F, 0x0142 }, { 0x0144, 0x0144 }, { 0x0148, 0x014B }, { 0x014D, 0x014D }, { 0x0152, 0x0153 }, { 0x0166, 0x0167 }, { 0x016B, 0x016B }, { 0x01CE, 0x01CE }, { 0x01D0, 0x01D0 }, { 0x01D2, 0x01D2 }, { 0x01D4, 0x01D4 }, { 0x01D6, 0x01D6 }, { 0x01D8, 0x01D8 }, { 0x01DA, 0x01DA }, { 0x01DC, 0x01DC }, { 0x0251, 0x0251 }, { 0x0261, 0x0261 }, { 0x02C4, 0x02C4 }, { 0x02C7, 0x02C7 }, { 0x02C9, 0x02CB }, { 0x02CD, 0x02CD }, { 0x02D0, 0x02D0 }, { 0x02D8, 0x02DB }, { 0x02DD, 0x02DD }, { 0x02DF, 0x02DF }, { 0x0391, 0x03A1 }, { 0x03A3, 0x03A9 }, { 0x03B1, 0x03C1 }, { 0x03C3, 0x03C9 }, { 0x0401, 0x0401 }, { 0x0410, 0x044F }, { 0x0451, 0x0451 }, { 0x2010, 0x2010 }, { 0x2013, 0x2016 }, { 0x2018, 0x2019 }, { 0x201C, 0x201D }, { 0x2020, 0x2022 }, { 0x2024, 0x2027 }, { 0x2030, 0x2030 }, { 0x2032, 0x2033 }, { 0x2035, 0x2035 }, { 0x203B, 0x203B }, { 0x203E, 0x203E }, { 0x2074, 0x2074 }, { 0x207F, 0x207F }, { 0x2081, 0x2084 }, { 0x20AC, 0x20AC }, { 0x2103, 0x2103 }, { 0x2105, 0x2105 }, { 0x2109, 0x2109 }, { 0x2113, 0x2113 }, { 0x2116, 0x2116 }, { 0x2121, 0x2122 }, { 0x2126, 0x2126 }, { 0x212B, 0x212B }, { 0x2153, 0x2154 }, { 0x215B, 0x215E }, { 0x2160, 0x216B }, { 0x2170, 0x2179 }, { 0x2189, 0x2189 }, { 0x2190, 0x2199 }, { 0x21B8, 0x21B9 }, { 0x21D2, 0x21D2 }, { 0x21D4, 0x21D4 }, { 0x21E7, 0x21E7 }, { 0x2200, 0x2200 }, { 0x2202, 0x2203 }, { 0x2207, 0x2208 }, { 0x220B, 0x220B }, { 0x220F, 0x220F }, { 0x2211, 0x2211 }, { 0x2215, 0x2215 }, { 0x221A, 0x221A }, { 0x221D, 0x2220 }, { 0x2223, 0x2223 }, { 0x2225, 0x2225 }, { 0x2227, 0x222C }, { 0x222E, 0x222E }, { 0x2234, 0x2237 }, { 0x223C, 0x223D }, { 0x2248, 0x2248 }, { 0x224C, 0x224C }, { 0x2252, 0x2252 }, { 0x2260, 0x2261 }, { 0x2264, 0x2267 }, { 0x226A, 0x226B }, { 0x226E, 0x226F }, { 0x2282, 0x2283 }, { 0x2286, 0x2287 }, { 0x2295, 0x2295 }, { 0x2299, 0x2299 }, { 0x22A5, 0x22A5 }, { 0x22BF, 0x22BF }, { 0x2312, 0x2312 }, { 0x2460, 0x24E9 }, { 0x24EB, 0x254B }, { 0x2550, 0x2573 }, { 0x2580, 0x258F }, { 0x2592, 0x2595 }, { 0x25A0, 0x25A1 }, { 0x25A3, 0x25A9 }, { 0x25B2, 0x25B3 }, { 0x25B6, 0x25B7 }, { 0x25BC, 0x25BD }, { 0x25C0, 0x25C1 }, { 0x25C6, 0x25C8 }, { 0x25CB, 0x25CB }, { 0x25CE, 0x25D1 }, { 0x25E2, 0x25E5 }, { 0x25EF, 0x25EF }, { 0x2605, 0x2606 }, { 0x2609, 0x2609 }, { 0x260E, 0x260F }, { 0x261C, 0x261C }, { 0x261E, 0x261E }, { 0x2640, 0x2640 }, { 0x2642, 0x2642 }, { 0x2660, 0x2661 }, { 0x2663, 0x2665 }, { 0x2667, 0x266A }, { 0x266C, 0x266D }, { 0x266F, 0x266F }, { 0x269E, 0x269F }, { 0x26BF, 0x26BF }, { 0x26C6, 0x26CD }, { 0x26CF, 0x26D3 }, { 0x26D5, 0x26E1 }, { 0x26E3, 0x26E3 }, { 0x26E8, 0x26E9 }, { 0x26EB, 0x26F1 }, { 0x26F4, 0x26F4 }, { 0x26F6, 0x26F9 }, { 0x26FB, 0x26FC }, { 0x26FE, 0x26FF }, { 0x273D, 0x273D }, { 0x2776, 0x277F }, { 0x2B56, 0x2B59 }, { 0x3248, 0x324F }, { 0xE000, 0xF8FF }, { 0xFFFD, 0xFFFD }, { 0x1F100, 0x1F10A }, { 0x1F110, 0x1F12D }, { 0x1F130, 0x1F169 }, { 0x1F170, 0x1F18D }, { 0x1F18F, 0x1F190 }, { 0x1F19B, 0x1F1AC }, { 0xF0000, 0xFFFFD }, { 0x100000, 0x10FFFD } }; picolibc-1.8.11/libc/string/bcmp.c000066400000000000000000000030351513574234600167050ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---compare two memory areas INDEX bcmp SYNOPSIS #include int bcmp(const void *<[s1]>, const void *<[s2]>, size_t <[n]>); DESCRIPTION This function compares not more than <[n]> bytes of the object pointed to by <[s1]> with the object pointed to by <[s2]>. This function is identical to <>. RETURNS The function returns an integer greater than, equal to or less than zero according to whether the object pointed to by <[s1]> is greater than, equal to or less than the object pointed to by <[s2]>. PORTABILITY <> requires no supporting OS subroutines. QUICKREF bcmp ansi pure */ #include #include int bcmp(const void *m1, const void *m2, size_t n) { return memcmp(m1, m2, n); } picolibc-1.8.11/libc/string/bcopy.c000066400000000000000000000024571513574234600171070ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---copy memory regions SYNOPSIS #include void bcopy(const void *<[in]>, void *<[out]>, size_t <[n]>); DESCRIPTION This function copies <[n]> bytes from the memory region pointed to by <[in]> to the memory region pointed to by <[out]>. This function is implemented in term of <>. PORTABILITY <> requires no supporting OS subroutines. QUICKREF bcopy - pure */ #include #include #undef bcopy void bcopy(const void *b1, void *b2, size_t length) { memmove(b2, b1, length); } picolibc-1.8.11/libc/string/bzero.c000066400000000000000000000024731513574234600171120ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---initialize memory to zero INDEX bzero SYNOPSIS #include void bzero(void *<[b]>, size_t <[length]>); DESCRIPTION <> initializes <[length]> bytes of memory, starting at address <[b]>, to zero. RETURNS <> does not return a result. PORTABILITY <> is in the Berkeley Software Distribution. Neither ANSI C nor the System V Interface Definition (Issue 2) require <>. <> requires no supporting OS subroutines. */ #include #include #undef memset void bzero(void *b, size_t length) { memset(b, 0, length); } picolibc-1.8.11/libc/string/combining.t000066400000000000000000000171011513574234600177510ustar00rootroot00000000000000/* This file is automatically generated */ { { 0x0300, 0x036F }, { 0x0483, 0x0489 }, { 0x0591, 0x05BD }, { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 }, { 0x05C4, 0x05C5 }, { 0x05C7, 0x05C7 }, { 0x0600, 0x0605 }, { 0x0610, 0x061A }, { 0x061C, 0x061C }, { 0x064B, 0x065F }, { 0x0670, 0x0670 }, { 0x06D6, 0x06DD }, { 0x06DF, 0x06E4 }, { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED }, { 0x070F, 0x070F }, { 0x0711, 0x0711 }, { 0x0730, 0x074A }, { 0x07A6, 0x07B0 }, { 0x07EB, 0x07F3 }, { 0x07FD, 0x07FD }, { 0x0816, 0x0819 }, { 0x081B, 0x0823 }, { 0x0825, 0x0827 }, { 0x0829, 0x082D }, { 0x0859, 0x085B }, { 0x0890, 0x0891 }, { 0x0898, 0x089F }, { 0x08CA, 0x0902 }, { 0x093A, 0x093A }, { 0x093C, 0x093C }, { 0x0941, 0x0948 }, { 0x094D, 0x094D }, { 0x0951, 0x0957 }, { 0x0962, 0x0963 }, { 0x0981, 0x0981 }, { 0x09BC, 0x09BC }, { 0x09C1, 0x09C4 }, { 0x09CD, 0x09CD }, { 0x09E2, 0x09E3 }, { 0x09FE, 0x09FE }, { 0x0A01, 0x0A02 }, { 0x0A3C, 0x0A3C }, { 0x0A41, 0x0A42 }, { 0x0A47, 0x0A48 }, { 0x0A4B, 0x0A4D }, { 0x0A51, 0x0A51 }, { 0x0A70, 0x0A71 }, { 0x0A75, 0x0A75 }, { 0x0A81, 0x0A82 }, { 0x0ABC, 0x0ABC }, { 0x0AC1, 0x0AC5 }, { 0x0AC7, 0x0AC8 }, { 0x0ACD, 0x0ACD }, { 0x0AE2, 0x0AE3 }, { 0x0AFA, 0x0AFF }, { 0x0B01, 0x0B01 }, { 0x0B3C, 0x0B3C }, { 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B44 }, { 0x0B4D, 0x0B4D }, { 0x0B55, 0x0B56 }, { 0x0B62, 0x0B63 }, { 0x0B82, 0x0B82 }, { 0x0BC0, 0x0BC0 }, { 0x0BCD, 0x0BCD }, { 0x0C00, 0x0C00 }, { 0x0C04, 0x0C04 }, { 0x0C3C, 0x0C3C }, { 0x0C3E, 0x0C40 }, { 0x0C46, 0x0C48 }, { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 }, { 0x0C62, 0x0C63 }, { 0x0C81, 0x0C81 }, { 0x0CBC, 0x0CBC }, { 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 }, { 0x0CCC, 0x0CCD }, { 0x0CE2, 0x0CE3 }, { 0x0D00, 0x0D01 }, { 0x0D3B, 0x0D3C }, { 0x0D41, 0x0D44 }, { 0x0D4D, 0x0D4D }, { 0x0D62, 0x0D63 }, { 0x0D81, 0x0D81 }, { 0x0DCA, 0x0DCA }, { 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 }, { 0x0E31, 0x0E31 }, { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E }, { 0x0EB1, 0x0EB1 }, { 0x0EB4, 0x0EBC }, { 0x0EC8, 0x0ECE }, { 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 }, { 0x0F37, 0x0F37 }, { 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E }, { 0x0F80, 0x0F84 }, { 0x0F86, 0x0F87 }, { 0x0F8D, 0x0F97 }, { 0x0F99, 0x0FBC }, { 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 }, { 0x1032, 0x1037 }, { 0x1039, 0x103A }, { 0x103D, 0x103E }, { 0x1058, 0x1059 }, { 0x105E, 0x1060 }, { 0x1071, 0x1074 }, { 0x1082, 0x1082 }, { 0x1085, 0x1086 }, { 0x108D, 0x108D }, { 0x109D, 0x109D }, { 0x1160, 0x11FF }, { 0x135D, 0x135F }, { 0x1712, 0x1714 }, { 0x1732, 0x1733 }, { 0x1752, 0x1753 }, { 0x1772, 0x1773 }, { 0x17B4, 0x17B5 }, { 0x17B7, 0x17BD }, { 0x17C6, 0x17C6 }, { 0x17C9, 0x17D3 }, { 0x17DD, 0x17DD }, { 0x180B, 0x180F }, { 0x1885, 0x1886 }, { 0x18A9, 0x18A9 }, { 0x1920, 0x1922 }, { 0x1927, 0x1928 }, { 0x1932, 0x1932 }, { 0x1939, 0x193B }, { 0x1A17, 0x1A18 }, { 0x1A1B, 0x1A1B }, { 0x1A56, 0x1A56 }, { 0x1A58, 0x1A5E }, { 0x1A60, 0x1A60 }, { 0x1A62, 0x1A62 }, { 0x1A65, 0x1A6C }, { 0x1A73, 0x1A7C }, { 0x1A7F, 0x1A7F }, { 0x1AB0, 0x1ACE }, { 0x1B00, 0x1B03 }, { 0x1B34, 0x1B34 }, { 0x1B36, 0x1B3A }, { 0x1B3C, 0x1B3C }, { 0x1B42, 0x1B42 }, { 0x1B6B, 0x1B73 }, { 0x1B80, 0x1B81 }, { 0x1BA2, 0x1BA5 }, { 0x1BA8, 0x1BA9 }, { 0x1BAB, 0x1BAD }, { 0x1BE6, 0x1BE6 }, { 0x1BE8, 0x1BE9 }, { 0x1BED, 0x1BED }, { 0x1BEF, 0x1BF1 }, { 0x1C2C, 0x1C33 }, { 0x1C36, 0x1C37 }, { 0x1CD0, 0x1CD2 }, { 0x1CD4, 0x1CE0 }, { 0x1CE2, 0x1CE8 }, { 0x1CED, 0x1CED }, { 0x1CF4, 0x1CF4 }, { 0x1CF8, 0x1CF9 }, { 0x1DC0, 0x1DFF }, { 0x200B, 0x200F }, { 0x202A, 0x202E }, { 0x2060, 0x2064 }, { 0x2066, 0x206F }, { 0x20D0, 0x20F0 }, { 0x2CEF, 0x2CF1 }, { 0x2D7F, 0x2D7F }, { 0x2DE0, 0x2DFF }, { 0x302A, 0x302D }, { 0x3099, 0x309A }, { 0xA66F, 0xA672 }, { 0xA674, 0xA67D }, { 0xA69E, 0xA69F }, { 0xA6F0, 0xA6F1 }, { 0xA802, 0xA802 }, { 0xA806, 0xA806 }, { 0xA80B, 0xA80B }, { 0xA825, 0xA826 }, { 0xA82C, 0xA82C }, { 0xA8C4, 0xA8C5 }, { 0xA8E0, 0xA8F1 }, { 0xA8FF, 0xA8FF }, { 0xA926, 0xA92D }, { 0xA947, 0xA951 }, { 0xA980, 0xA982 }, { 0xA9B3, 0xA9B3 }, { 0xA9B6, 0xA9B9 }, { 0xA9BC, 0xA9BD }, { 0xA9E5, 0xA9E5 }, { 0xAA29, 0xAA2E }, { 0xAA31, 0xAA32 }, { 0xAA35, 0xAA36 }, { 0xAA43, 0xAA43 }, { 0xAA4C, 0xAA4C }, { 0xAA7C, 0xAA7C }, { 0xAAB0, 0xAAB0 }, { 0xAAB2, 0xAAB4 }, { 0xAAB7, 0xAAB8 }, { 0xAABE, 0xAABF }, { 0xAAC1, 0xAAC1 }, { 0xAAEC, 0xAAED }, { 0xAAF6, 0xAAF6 }, { 0xABE5, 0xABE5 }, { 0xABE8, 0xABE8 }, { 0xABED, 0xABED }, { 0xD7B0, 0xD7C6 }, { 0xD7CB, 0xD7FB }, { 0xFB1E, 0xFB1E }, { 0xFE00, 0xFE0F }, { 0xFE20, 0xFE2F }, { 0xFEFF, 0xFEFF }, { 0xFFF9, 0xFFFB }, { 0x101FD, 0x101FD }, { 0x102E0, 0x102E0 }, { 0x10376, 0x1037A }, { 0x10A01, 0x10A03 }, { 0x10A05, 0x10A06 }, { 0x10A0C, 0x10A0F }, { 0x10A38, 0x10A3A }, { 0x10A3F, 0x10A3F }, { 0x10AE5, 0x10AE6 }, { 0x10D24, 0x10D27 }, { 0x10EAB, 0x10EAC }, { 0x10EFD, 0x10EFF }, { 0x10F46, 0x10F50 }, { 0x10F82, 0x10F85 }, { 0x11001, 0x11001 }, { 0x11038, 0x11046 }, { 0x11070, 0x11070 }, { 0x11073, 0x11074 }, { 0x1107F, 0x11081 }, { 0x110B3, 0x110B6 }, { 0x110B9, 0x110BA }, { 0x110BD, 0x110BD }, { 0x110C2, 0x110C2 }, { 0x110CD, 0x110CD }, { 0x11100, 0x11102 }, { 0x11127, 0x1112B }, { 0x1112D, 0x11134 }, { 0x11173, 0x11173 }, { 0x11180, 0x11181 }, { 0x111B6, 0x111BE }, { 0x111C9, 0x111CC }, { 0x111CF, 0x111CF }, { 0x1122F, 0x11231 }, { 0x11234, 0x11234 }, { 0x11236, 0x11237 }, { 0x1123E, 0x1123E }, { 0x11241, 0x11241 }, { 0x112DF, 0x112DF }, { 0x112E3, 0x112EA }, { 0x11300, 0x11301 }, { 0x1133B, 0x1133C }, { 0x11340, 0x11340 }, { 0x11366, 0x1136C }, { 0x11370, 0x11374 }, { 0x11438, 0x1143F }, { 0x11442, 0x11444 }, { 0x11446, 0x11446 }, { 0x1145E, 0x1145E }, { 0x114B3, 0x114B8 }, { 0x114BA, 0x114BA }, { 0x114BF, 0x114C0 }, { 0x114C2, 0x114C3 }, { 0x115B2, 0x115B5 }, { 0x115BC, 0x115BD }, { 0x115BF, 0x115C0 }, { 0x115DC, 0x115DD }, { 0x11633, 0x1163A }, { 0x1163D, 0x1163D }, { 0x1163F, 0x11640 }, { 0x116AB, 0x116AB }, { 0x116AD, 0x116AD }, { 0x116B0, 0x116B5 }, { 0x116B7, 0x116B7 }, { 0x1171D, 0x1171F }, { 0x11722, 0x11725 }, { 0x11727, 0x1172B }, { 0x1182F, 0x11837 }, { 0x11839, 0x1183A }, { 0x1193B, 0x1193C }, { 0x1193E, 0x1193E }, { 0x11943, 0x11943 }, { 0x119D4, 0x119D7 }, { 0x119DA, 0x119DB }, { 0x119E0, 0x119E0 }, { 0x11A01, 0x11A0A }, { 0x11A33, 0x11A38 }, { 0x11A3B, 0x11A3E }, { 0x11A47, 0x11A47 }, { 0x11A51, 0x11A56 }, { 0x11A59, 0x11A5B }, { 0x11A8A, 0x11A96 }, { 0x11A98, 0x11A99 }, { 0x11C30, 0x11C36 }, { 0x11C38, 0x11C3D }, { 0x11C3F, 0x11C3F }, { 0x11C92, 0x11CA7 }, { 0x11CAA, 0x11CB0 }, { 0x11CB2, 0x11CB3 }, { 0x11CB5, 0x11CB6 }, { 0x11D31, 0x11D36 }, { 0x11D3A, 0x11D3A }, { 0x11D3C, 0x11D3D }, { 0x11D3F, 0x11D45 }, { 0x11D47, 0x11D47 }, { 0x11D90, 0x11D91 }, { 0x11D95, 0x11D95 }, { 0x11D97, 0x11D97 }, { 0x11EF3, 0x11EF4 }, { 0x11F00, 0x11F01 }, { 0x11F36, 0x11F3A }, { 0x11F40, 0x11F40 }, { 0x11F42, 0x11F42 }, { 0x13430, 0x13440 }, { 0x13447, 0x13455 }, { 0x16AF0, 0x16AF4 }, { 0x16B30, 0x16B36 }, { 0x16F4F, 0x16F4F }, { 0x16F8F, 0x16F92 }, { 0x16FE4, 0x16FE4 }, { 0x1BC9D, 0x1BC9E }, { 0x1BCA0, 0x1BCA3 }, { 0x1CF00, 0x1CF2D }, { 0x1CF30, 0x1CF46 }, { 0x1D167, 0x1D169 }, { 0x1D173, 0x1D182 }, { 0x1D185, 0x1D18B }, { 0x1D1AA, 0x1D1AD }, { 0x1D242, 0x1D244 }, { 0x1DA00, 0x1DA36 }, { 0x1DA3B, 0x1DA6C }, { 0x1DA75, 0x1DA75 }, { 0x1DA84, 0x1DA84 }, { 0x1DA9B, 0x1DA9F }, { 0x1DAA1, 0x1DAAF }, { 0x1E000, 0x1E006 }, { 0x1E008, 0x1E018 }, { 0x1E01B, 0x1E021 }, { 0x1E023, 0x1E024 }, { 0x1E026, 0x1E02A }, { 0x1E08F, 0x1E08F }, { 0x1E130, 0x1E136 }, { 0x1E2AE, 0x1E2AE }, { 0x1E2EC, 0x1E2EF }, { 0x1E4EC, 0x1E4EF }, { 0x1E8D0, 0x1E8D6 }, { 0x1E944, 0x1E94A }, { 0xE0001, 0xE0001 }, { 0xE0020, 0xE007F }, { 0xE0100, 0xE01EF } }; picolibc-1.8.11/libc/string/explicit_bzero.c000066400000000000000000000004641513574234600210110ustar00rootroot00000000000000/* $OpenBSD: explicit_bzero.c,v 1.2 2014/06/10 04:17:37 deraadt Exp $ */ /* * Copyright (c) 2014 Ted Unangst * Public domain. */ #define _DEFAULT_SOURCE #include /* * explicit_bzero - don't let the compiler optimize away bzero */ void explicit_bzero(void *p, size_t n) { bzero(p, n); } picolibc-1.8.11/libc/string/ffsl.c000066400000000000000000000033331513574234600167170ustar00rootroot00000000000000/*- * Copyright (c) 2017 embedded brains GmbH * 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. */ #define _DEFAULT_SOURCE #include int ffsl(long i) { #if __HAVE_BUILTIN_FFSL return (__builtin_ffsl(i)); #elif __HAVE_BUILTIN_CTZL if (i == 0) return 0; return __builtin_ctzl((unsigned long)i) + 1; #else int r; if (!i) return 0; r = 0; for (;;) { if (((1L << r++) & i) != 0) return r; } return 0; #endif } picolibc-1.8.11/libc/string/ffsll.c000066400000000000000000000033531513574234600170750ustar00rootroot00000000000000/*- * Copyright (c) 2017 embedded brains GmbH * 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. */ #define _DEFAULT_SOURCE #include int ffsll(long long i) { #if __HAVE_BUILTIN_FFSLL return (__builtin_ffsll(i)); #elif __HAVE_BUILTIN_CTZLL if (i == 0) return 0; return __builtin_ctzll((unsigned long long)i) + 1; #else int r; if (!i) return 0; r = 0; for (;;) { if (((1LL << r++) & i) != 0) return r; } return 0; #endif } picolibc-1.8.11/libc/string/fls.c000066400000000000000000000030021513574234600165420ustar00rootroot00000000000000/*- * Copyright (c) 2017 embedded brains GmbH * 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. */ #define _DEFAULT_SOURCE #include #include int fls(int i) { if (i == 0) return 0; return (sizeof(i) * CHAR_BIT - __builtin_clz(i)); } picolibc-1.8.11/libc/string/flsl.c000066400000000000000000000030051513574234600167210ustar00rootroot00000000000000/*- * Copyright (c) 2017 embedded brains GmbH * 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. */ #define _DEFAULT_SOURCE #include #include int flsl(long i) { if (i == 0) return 0; return (sizeof(i) * CHAR_BIT - __builtin_clzl(i)); } picolibc-1.8.11/libc/string/flsll.c000066400000000000000000000030141513574234600170750ustar00rootroot00000000000000/*- * Copyright (c) 2017 embedded brains GmbH * 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. */ #define _DEFAULT_SOURCE #include #include int flsll(long long i) { if (i == 0) return 0; return (sizeof(i) * CHAR_BIT - __builtin_clzll(i)); } picolibc-1.8.11/libc/string/gnu_basename.c000066400000000000000000000013171513574234600204110ustar00rootroot00000000000000#ifndef _NO_BASENAME /* Copyright 2015 Red Hat, Inc. * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ /* The differences with the POSIX version (unix/basename.c): * - declared in (instead of ); * - the argument is never modified, and therefore is marked const; * - the empty string is returned if path is an empty string, "/", or ends * with a trailing slash. */ #define _GNU_SOURCE #include __typeof(basename) __gnu_basename; char * __gnu_basename(const char *path) { char *p; if ((p = strrchr(path, '/'))) return p + 1; return (char *)path; } #endif /* !_NO_BASENAME */ picolibc-1.8.11/libc/string/index.c000066400000000000000000000026651513574234600171030ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---search for character in string INDEX index SYNOPSIS #include char * index(const char *<[string]>, int <[c]>); DESCRIPTION This function finds the first occurence of <[c]> (converted to a char) in the string pointed to by <[string]> (including the terminating null character). This function is identical to <>. RETURNS Returns a pointer to the located character, or a null pointer if <[c]> does not occur in <[string]>. PORTABILITY <> requires no supporting OS subroutines. QUICKREF index - pure */ #include #include char * index(const char *s, int c) { return strchr(s, c); } picolibc-1.8.11/libc/string/local.h000066400000000000000000000034701513574234600170660ustar00rootroot00000000000000/* Copyright (c) 2009 Corinna Vinschen */ #include "../ctype/local.h" /* internal function to compute width of wide char. */ int __wcwidth(wint_t); /* Reentrant version of strerror. */ char *_strerror_r(int, int, int *); /* Nonzero if X is not aligned on a "long" boundary. * This macro is used to skip a few bytes to find an aligned pointer. * It's better to keep it as is even if _HAVE_HW_MISALIGNED_ACCESS is enabled, * to avoid small performance penalties (if they are not zero). */ #define UNALIGNED_X(X) ((uintptr_t)(X) & (sizeof(unsigned long) - 1)) /* Nonzero if either X or Y is not aligned on a "long" boundary. */ #define UNALIGNED_X_Y(X, Y) \ (((uintptr_t)(X) & (sizeof(unsigned long) - 1)) \ | ((uintptr_t)(Y) & (sizeof(unsigned long) - 1))) /* How many bytes are copied each iteration of the word copy loop. */ #define LITTLE_BLOCK_SIZE (sizeof(unsigned long)) /* How many bytes are copied each iteration of the 4X unrolled loop. */ #define BIG_BLOCK_SIZE (sizeof(unsigned long) << 2) /* Threshhold for punting to the little block byte copier. */ #define TOO_SMALL_LITTLE_BLOCK(LEN) ((LEN) < LITTLE_BLOCK_SIZE) /* Threshhold for punting to the big block byte copier. */ #define TOO_SMALL_BIG_BLOCK(LEN) ((LEN) < BIG_BLOCK_SIZE) /* Macros for detecting endchar. */ #if ULONG_MAX == 4294967295UL #define DETECT_NULL(X) (((X) - 0x01010101UL) & ~(X) & 0x80808080UL) #elif ULONG_MAX == 18446744073709551615UL /* Nonzero if X (a long int) contains a NULL byte. */ #define DETECT_NULL(X) (((X) - 0x0101010101010101UL) & ~(X) & 0x8080808080808080UL) #else #error long int is not a 32bit or 64bit type. #endif /* Returns nonzero if (unsigned long)X contains the byte used to fill (unsigned long)MASK. */ #define DETECT_CHAR(X, MASK) (DETECT_NULL(X ^ MASK)) picolibc-1.8.11/libc/string/memccpy.c000066400000000000000000000064531513574234600174300ustar00rootroot00000000000000/* Copyright (c) 2002 Jeff Johnston */ /* FUNCTION <>---copy memory regions with end-token check SYNOPSIS #include void* memccpy(void *restrict <[out]>, const void *restrict <[in]>, int <[endchar]>, size_t <[n]>); DESCRIPTION This function copies up to <[n]> bytes from the memory region pointed to by <[in]> to the memory region pointed to by <[out]>. If a byte matching the <[endchar]> is encountered, the byte is copied and copying stops. If the regions overlap, the behavior is undefined. RETURNS <> returns a pointer to the first byte following the <[endchar]> in the <[out]> region. If no byte matching <[endchar]> was copied, then <> is returned. PORTABILITY <> is a GNU extension. <> requires no supporting OS subroutines. */ #define _DEFAULT_SOURCE #include #include #include #include "local.h" void * memccpy(void * __restrict dst0, const void * __restrict src0, int endchar0, size_t len0) { #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) \ || defined(_PICOLIBC_NO_OUT_OF_BOUNDS_READS) void *ptr = NULL; char *dst = (char *)dst0; char *src = (char *)src0; char endchar = endchar0 & 0xff; while (len0--) { if ((*dst++ = *src++) == endchar) { ptr = dst; break; } } return ptr; #else void *ptr = NULL; unsigned char *dst = dst0; const unsigned char *src = src0; long *aligned_dst; const long *aligned_src; unsigned char endchar = endchar0 & 0xff; /* If the size is small, or either SRC or DST is unaligned, then punt into the byte copy loop. This should be rare. */ if (!TOO_SMALL_LITTLE_BLOCK(len0) && !UNALIGNED_X_Y(src, dst)) { unsigned int i; unsigned long mask; aligned_dst = (long *)dst; aligned_src = (long *)src; /* The fast code reads the ASCII one word at a time and only performs the bytewise search on word-sized segments if they contain the search character, which is detected by XORing the word-sized segment with a word-sized block of the search character and then detecting for the presence of NULL in the result. */ mask = endchar << 8 | endchar; mask = mask << 16 | mask; for (i = 32; i < sizeof(mask) * 8; i <<= 1) mask = (mask << i) | mask; /* Copy one long word at a time if possible. */ while (!TOO_SMALL_LITTLE_BLOCK(len0)) { unsigned long buffer = (unsigned long)(*aligned_src); buffer ^= mask; if (DETECT_NULL(buffer)) break; /* endchar is found, go byte by byte from here */ *aligned_dst++ = *aligned_src++; len0 -= LITTLE_BLOCK_SIZE; } /* Pick up any residual with a byte copier. */ dst = (unsigned char *)aligned_dst; src = (unsigned char *)aligned_src; } while (len0--) { if ((*dst++ = *src++) == endchar) { ptr = dst; break; } } return ptr; #endif /* not __PREFER_SIZE_OVER_SPEED */ } picolibc-1.8.11/libc/string/memchr.c000066400000000000000000000063661513574234600172510ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---find character in memory INDEX memchr SYNOPSIS #include void *memchr(const void *<[src]>, int <[c]>, size_t <[length]>); DESCRIPTION This function searches memory starting at <<*<[src]>>> for the character <[c]>. The search only ends with the first occurrence of <[c]>, or after <[length]> characters; in particular, <> does not terminate the search. RETURNS If the character <[c]> is found within <[length]> characters of <<*<[src]>>>, a pointer to the character is returned. If <[c]> is not found, then <> is returned. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF memchr ansi pure */ #include #include #include "local.h" void * memchr(const void *src_void, int c, size_t length) { const unsigned char *src = (const unsigned char *)src_void; unsigned char d = c; #if !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) \ && !defined(_PICOLIBC_NO_OUT_OF_BOUNDS_READS) unsigned long *asrc; unsigned long mask; unsigned int i; while (UNALIGNED_X(src)) { if (!length--) return NULL; if (*src == d) return (void *)src; src++; } if (!TOO_SMALL_LITTLE_BLOCK(length)) { /* If we get this far, we know that length is large and src is word-aligned. */ /* The fast code reads the source one word at a time and only performs the bytewise search on word-sized segments if they contain the search character, which is detected by XORing the word-sized segment with a word-sized block of the search character and then detecting for the presence of NUL in the result. */ asrc = (unsigned long *)src; mask = (unsigned long)d << 8 | (unsigned long)d; mask = mask << 16 | mask; for (i = 32; i < sizeof(mask) * 8; i <<= 1) mask = (mask << i) | mask; while (!TOO_SMALL_LITTLE_BLOCK(length)) { if (DETECT_CHAR(*asrc, mask)) break; length -= LITTLE_BLOCK_SIZE; asrc++; } /* If there are fewer than LITTLE_BLOCK_SIZE characters left, then we resort to the bytewise loop. */ src = (unsigned char *)asrc; } #endif /* not __PREFER_SIZE_OVER_SPEED */ while (length--) { if (*src == d) return (void *)src; src++; } return NULL; } picolibc-1.8.11/libc/string/memcmp.c000066400000000000000000000054241513574234600172460ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---compare two memory areas INDEX memcmp SYNOPSIS #include int memcmp(const void *<[s1]>, const void *<[s2]>, size_t <[n]>); DESCRIPTION This function compares not more than <[n]> characters of the object pointed to by <[s1]> with the object pointed to by <[s2]>. RETURNS The function returns an integer greater than, equal to or less than zero according to whether the object pointed to by <[s1]> is greater than, equal to or less than the object pointed to by <[s2]>. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF memcmp ansi pure */ #include #include "local.h" int memcmp(const void *m1, const void *m2, size_t n) { #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) unsigned char *s1 = (unsigned char *)m1; unsigned char *s2 = (unsigned char *)m2; while (n--) { if (*s1 != *s2) { return *s1 - *s2; } s1++; s2++; } return 0; #else unsigned char *s1 = (unsigned char *)m1; unsigned char *s2 = (unsigned char *)m2; unsigned long *a1; unsigned long *a2; /* If the size is too small, or either pointer is unaligned, then we punt to the byte compare loop. Hopefully this will not turn up in inner loops. */ if (!TOO_SMALL_LITTLE_BLOCK(n) && !UNALIGNED_X_Y(s1, s2)) { /* Otherwise, load and compare the blocks of memory one word at a time. */ a1 = (unsigned long *)s1; a2 = (unsigned long *)s2; while (!TOO_SMALL_LITTLE_BLOCK(n)) { if (*a1 != *a2) break; a1++; a2++; n -= LITTLE_BLOCK_SIZE; } /* check m mod LITTLE_BLOCK_SIZE remaining characters */ s1 = (unsigned char *)a1; s2 = (unsigned char *)a2; } while (n--) { if (*s1 != *s2) return *s1 - *s2; s1++; s2++; } return 0; #endif /* not __PREFER_SIZE_OVER_SPEED */ } picolibc-1.8.11/libc/string/memcpy.c000066400000000000000000000104321513574234600172550ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---copy memory regions SYNOPSIS #include void* memcpy(void *restrict <[out]>, const void *restrict <[in]>, size_t <[n]>); DESCRIPTION This function copies <[n]> bytes from the memory region pointed to by <[in]> to the memory region pointed to by <[out]>. If the regions overlap, the behavior is undefined. RETURNS <> returns a pointer to the first byte of the <[out]> region. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF memcpy ansi pure */ #include #include "local.h" #include #undef memcpy void * __no_builtin memcpy(void * __restrict dst0, const void * __restrict src0, size_t len0) { char *dst = dst0; const char *src = src0; #if !(defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)) unsigned long *aligned_dst; const unsigned long *aligned_src; /* If the size is small, or either SRC or DST is unaligned, then punt into the byte copy loop. This should be rare. */ if (!TOO_SMALL_BIG_BLOCK(len0)) { /* * Align dst and make sure * we won't fetch anything before src */ unsigned start = LITTLE_BLOCK_SIZE * 2 - UNALIGNED_X(dst); while (start--) { *dst++ = *src++; len0--; } aligned_dst = (unsigned long *)dst; int byte_shift = UNALIGNED_X(src); if (!byte_shift) { aligned_src = (unsigned long *)src; /* Copy 4X long words at a time if possible. */ while (len0 >= BIG_BLOCK_SIZE) { *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; len0 -= BIG_BLOCK_SIZE; } /* Copy one long word at a time if possible. */ while (len0 >= LITTLE_BLOCK_SIZE) { *aligned_dst++ = *aligned_src++; len0 -= LITTLE_BLOCK_SIZE; } src = (char *)aligned_src; } else { /* * Fetch source words and then merge two of them for each * dest word: * * byte_shift remain * | | | * xxxxxxxL RRRRRRRy * D DDDDDDD * * We don't want to fetch past the source at all, so stop * when we have fewer than 'remain' bytes left */ /* bytes used from the left word */ int remain = LITTLE_BLOCK_SIZE - byte_shift; /* bit shifts for the left and right words */ int left_shift = byte_shift << 3; int right_shift = remain << 3; aligned_src = (unsigned long *)(src - byte_shift); unsigned long left = *aligned_src++, right; while (len0 >= LITTLE_BLOCK_SIZE + remain) { right = *aligned_src++; #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ *aligned_dst++ = (left >> left_shift) | (right << right_shift); #else *aligned_dst++ = (left << left_shift) | (right >> right_shift); #endif left = right; len0 -= LITTLE_BLOCK_SIZE; } src = (char *)aligned_src - remain; } /* Pick up any residual with a byte copier. */ dst = (char *)aligned_dst; } #endif while (len0--) *dst++ = *src++; return dst0; } picolibc-1.8.11/libc/string/memcpy_s.c000066400000000000000000000056051513574234600176050ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define __STDC_WANT_LIB_EXT1__ 1 #include #include #include "string_private.h" __errno_t memcpy_s(void * __restrict s1, rsize_t s1max, const void * __restrict s2, rsize_t n) { const char *msg = ""; if (s1 == NULL) { msg = "memcpy_s: dest is NULL"; goto handle_error; } if (CHECK_RSIZE(s1max)) { msg = "memcpy_s: buffer size exceeds RSIZE_MAX"; goto handle_error; } if (s2 == NULL) { msg = "memcpy_s: source is NULL"; goto handle_error; } if (CHECK_RSIZE(n)) { msg = "memcpy_s: copy count exceeds RSIZE_MAX"; goto handle_error; } if (n > s1max) { msg = "memcpy_s: copy count exceeds buffer size"; goto handle_error; } const char *s1cp = (const char *)s1; const char *s2cp = (const char *)s2; const char *s1cp_limit = &s1cp[n]; const char *s2cp_limit = &s2cp[n]; if (((s1cp_limit <= s2cp) || (s2cp_limit <= s1cp)) == false) { msg = "memcpy_s: overlapping copy"; goto handle_error; } // Normal return path (void)memcpy(s1, s2, n); return 0; handle_error: if (s1 != NULL) { (void)memset(s1, (int32_t)'\0', s1max); } if (__cur_handler != NULL) { __cur_handler(msg, NULL, -1); } return -1; } picolibc-1.8.11/libc/string/memmem.c000066400000000000000000000142761513574234600172520ustar00rootroot00000000000000/* Optimized memmem function. Copyright (c) 2018 Arm Ltd. All rights reserved. SPDX-License-Identifier: BSD-3-Clause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the company may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* FUNCTION <>---find memory segment INDEX memmem SYNOPSIS #include void *memmem(const void *<[s1]>, size_t <[l1]>, const void *<[s2]>, size_t <[l2]>); DESCRIPTION Locates the first occurrence in the memory region pointed to by <[s1]> with length <[l1]> of the sequence of bytes pointed to by <[s2]> of length <[l2]>. If you already know the lengths of your haystack and needle, <> is much faster than <>. RETURNS Returns a pointer to the located segment, or a null pointer if <[s2]> is not found. If <[l2]> is 0, <[s1]> is returned. PORTABILITY <> is a newlib extension. <> requires no supporting OS subroutines. QUICKREF memmem pure */ #define _GNU_SOURCE #include #include #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) /* Small and efficient memmem implementation (quadratic worst-case). */ void * memmem(const void *haystack, size_t hs_len, const void *needle, size_t ne_len) { const char *hs = haystack; const char *ne = needle; if (ne_len == 0) return (void *)hs; int i; int c = ne[0]; const char *end = hs + hs_len - ne_len; for (; hs <= end; hs++) { if (hs[0] != c) continue; for (i = ne_len - 1; i != 0; i--) if (hs[i] != ne[i]) break; if (i == 0) return (void *)hs; } return NULL; } #else #define RETURN_TYPE void * #define AVAILABLE(h, h_l, j, n_l) ((j) <= (h_l) - (n_l)) #include "str-two-way.h" #define hash2(p) (((size_t)(p)[0] - ((size_t)(p)[-1] << 3)) % sizeof(shift)) /* Fast memmem algorithm with guaranteed linear-time performance. Small needles up to size 2 use a dedicated linear search. Longer needles up to size 256 use a novel modified Horspool algorithm. It hashes pairs of characters to quickly skip past mismatches. The main search loop only exits if the last 2 characters match, avoiding unnecessary calls to memcmp and allowing for a larger skip if there is no match. A self-adapting filtering check is used to quickly detect mismatches in long needles. By limiting the needle length to 256, the shift table can be reduced to 8 bits per entry, lowering preprocessing overhead and minimizing cache effects. The limit also implies worst-case performance is linear. Needles larger than 256 characters use the linear-time Two-Way algorithm. */ void * memmem(const void *haystack, size_t hs_len, const void *needle, size_t ne_len) { const unsigned char *hs = haystack; const unsigned char *ne = needle; if (ne_len == 0) return (void *)hs; if (ne_len == 1) return (void *)memchr(hs, ne[0], hs_len); /* Ensure haystack length is >= needle length. */ if (hs_len < ne_len) return NULL; const unsigned char *end = hs + hs_len - ne_len; if (ne_len == 2) { uint32_t nw = ((uint32_t)ne[0] << 16) | ne[1], hw = ((uint32_t)hs[0] << 16) | hs[1]; for (hs++; hs <= end && hw != nw;) hw = hw << 16 | *++hs; return hw == nw ? (void *)(hs - 1) : NULL; } /* Use Two-Way algorithm for very long needles. */ if (__builtin_expect(ne_len > 256, 0)) return two_way_long_needle(hs, hs_len, ne, ne_len); uint8_t shift[256]; size_t tmp, shift1; size_t m1 = ne_len - 1; size_t offset = 0; size_t i; /* Initialize bad character shift hash table. */ memset(shift, 0, sizeof(shift)); for (i = 1; i < m1; i++) shift[hash2(ne + i)] = i; shift1 = m1 - shift[hash2(ne + m1)]; shift[hash2(ne + m1)] = m1; for (; hs <= end;) { /* Skip past character pairs not in the needle. */ do { hs += m1; tmp = shift[hash2(hs)]; } while (hs <= end && tmp == 0); /* If the match is not at the end of the needle, shift to the end and continue until we match the last 2 characters. */ hs -= tmp; if (tmp < m1) continue; /* The last 2 characters match. If the needle is long, check a fixed number of characters first to quickly filter out mismatches. */ if (m1 <= 15 || memcmp(hs + offset, ne + offset, sizeof(long)) == 0) { if (memcmp(hs, ne, m1) == 0) return (void *)hs; /* Adjust filter offset when it doesn't find the mismatch. */ offset = (offset >= sizeof(long) ? offset : m1) - sizeof(long); } /* Skip based on matching the last 2 characters. */ hs += shift1; } return NULL; } #endif /* Compilation for speed. */ picolibc-1.8.11/libc/string/memmove.c000066400000000000000000000101021513574234600174220ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---move possibly overlapping memory INDEX memmove SYNOPSIS #include void *memmove(void *<[dst]>, const void *<[src]>, size_t <[length]>); DESCRIPTION This function moves <[length]> characters from the block of memory starting at <<*<[src]>>> to the memory starting at <<*<[dst]>>>. <> reproduces the characters correctly at <<*<[dst]>>> even if the two areas overlap. RETURNS The function returns <[dst]> as passed. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF memmove ansi pure */ #include #include #include #include #include "local.h" #undef memmove /*SUPPRESS 20*/ void * __no_builtin memmove(void *dst_void, const void *src_void, size_t length) { #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) char *dst = dst_void; const char *src = src_void; if (src < dst && dst < src + length) { /* Have to copy backwards */ src += length; dst += length; while (length--) { *--dst = *--src; } } else { while (length--) { *dst++ = *src++; } } return dst_void; #else char *dst = dst_void; const char *src = src_void; long *aligned_dst; const long *aligned_src; if (src < dst && dst < src + length) { /* Destructive overlap...have to copy backwards */ src += length; dst += length; if (!TOO_SMALL_LITTLE_BLOCK(length) && !UNALIGNED_X_Y(src, dst)) { aligned_dst = (long *)dst; aligned_src = (long *)src; /* Copy one long word at a time if possible. */ while (!TOO_SMALL_LITTLE_BLOCK(length)) { *--aligned_dst = *--aligned_src; length -= LITTLE_BLOCK_SIZE; } /* Pick up any residual with a byte copier. */ dst = (char *)aligned_dst; src = (char *)aligned_src; } while (length--) { *--dst = *--src; } } else { /* Use optimizing algorithm for a non-destructive copy to closely match memcpy. If the size is small or either SRC or DST is unaligned, then punt into the byte copy loop. This should be rare. */ if (!TOO_SMALL_LITTLE_BLOCK(length) && !UNALIGNED_X_Y(src, dst)) { aligned_dst = (long *)dst; aligned_src = (long *)src; /* Copy 4X long words at a time if possible. */ while (!TOO_SMALL_BIG_BLOCK(length)) { *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; length -= BIG_BLOCK_SIZE; } /* Copy one long word at a time if possible. */ while (!TOO_SMALL_LITTLE_BLOCK(length)) { *aligned_dst++ = *aligned_src++; length -= LITTLE_BLOCK_SIZE; } /* Pick up any residual with a byte copier. */ dst = (char *)aligned_dst; src = (char *)aligned_src; } while (length--) { *dst++ = *src++; } } return dst_void; #endif /* not __PREFER_SIZE_OVER_SPEED */ } picolibc-1.8.11/libc/string/memmove_s.c000066400000000000000000000052171513574234600177570ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define __STDC_WANT_LIB_EXT1__ 1 #include #include #include "string_private.h" __errno_t memmove_s(void *s1, rsize_t s1max, const void *s2, rsize_t n) { const char *msg = ""; if (s1 == NULL) { msg = "memmove_s: dest is NULL"; goto handle_error; } if (CHECK_RSIZE(s1max)) { msg = "memmove_s: buffer size exceeds RSIZE_MAX"; goto handle_error; } if (s2 == NULL) { msg = "memmove_s: source is NULL"; goto handle_error; } if (CHECK_RSIZE(n)) { msg = "memmove_s: copy count exceeds RSIZE_MAX"; goto handle_error; } if (n > s1max) { msg = "memmove_s: copy count exceeds buffer size"; goto handle_error; } /* overlapping memory is allowed for memmove_s so no checks for that */ // Normal return path (void)memmove(s1, s2, n); return 0; handle_error: if (s1 != NULL) { (void)memset(s1, (int32_t)'\0', s1max); } if (__cur_handler != NULL) { __cur_handler(msg, NULL, -1); } return -1; } picolibc-1.8.11/libc/string/mempcpy.c000066400000000000000000000042501513574234600174360ustar00rootroot00000000000000/* Copyright (c) 2002 Jeff Johnston */ /* FUNCTION <>---copy memory regions and return end pointer SYNOPSIS #include void* mempcpy(void *<[out]>, const void *<[in]>, size_t <[n]>); DESCRIPTION This function copies <[n]> bytes from the memory region pointed to by <[in]> to the memory region pointed to by <[out]>. If the regions overlap, the behavior is undefined. RETURNS <> returns a pointer to the byte following the last byte copied to the <[out]> region. PORTABILITY <> is a GNU extension. <> requires no supporting OS subroutines. */ #define _GNU_SOURCE #include #include #include #include "local.h" void * mempcpy(void *dst0, const void *src0, size_t len0) { #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) char *dst = (char *)dst0; char *src = (char *)src0; while (len0--) { *dst++ = *src++; } return dst; #else char *dst = dst0; const char *src = src0; long *aligned_dst; const long *aligned_src; /* If the size is small, or either SRC or DST is unaligned, then punt into the byte copy loop. This should be rare. */ if (!TOO_SMALL_LITTLE_BLOCK(len0) && !UNALIGNED_X_Y(src, dst)) { aligned_dst = (long *)dst; aligned_src = (long *)src; /* Copy 4X long words at a time if possible. */ while (!TOO_SMALL_BIG_BLOCK(len0)) { *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; len0 -= BIG_BLOCK_SIZE; } /* Copy one long word at a time if possible. */ while (!TOO_SMALL_LITTLE_BLOCK(len0)) { *aligned_dst++ = *aligned_src++; len0 -= LITTLE_BLOCK_SIZE; } /* Pick up any residual with a byte copier. */ dst = (char *)aligned_dst; src = (char *)aligned_src; } while (len0--) *dst++ = *src++; return dst; #endif /* not __PREFER_SIZE_OVER_SPEED */ } picolibc-1.8.11/libc/string/memrchr.c000066400000000000000000000052501513574234600174220ustar00rootroot00000000000000/* Copyright (c) 2012 Corinna Vinschen */ /* FUNCTION <>---reverse search for character in memory INDEX memrchr SYNOPSIS #include void *memrchr(const void *<[src]>, int <[c]>, size_t <[length]>); DESCRIPTION This function searches memory starting at <[length]> bytes beyond <<*<[src]>>> backwards for the character <[c]>. The search only ends with the first occurrence of <[c]>; in particular, <> does not terminate the search. RETURNS If the character <[c]> is found within <[length]> characters of <<*<[src]>>>, a pointer to the character is returned. If <[c]> is not found, then <> is returned. PORTABILITY <> is a GNU extension. <> requires no supporting OS subroutines. QUICKREF memrchr */ #define _GNU_SOURCE #include #include #include "local.h" void * memrchr(const void *src_void, int c, size_t length) { const unsigned char *src = (const unsigned char *)src_void + length - 1; unsigned char d = c; #if !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) unsigned long *asrc; unsigned long mask; unsigned int i; while (UNALIGNED_X(src + 1)) { if (!length--) return NULL; if (*src == d) return (void *)src; src--; } if (!TOO_SMALL_LITTLE_BLOCK(length)) { /* If we get this far, we know that length is large and src is word-aligned. */ /* The fast code reads the source one word at a time and only performs the bytewise search on word-sized segments if they contain the search character, which is detected by XORing the word-sized segment with a word-sized block of the search character and then detecting for the presence of NUL in the result. */ asrc = (unsigned long *)(src - LITTLE_BLOCK_SIZE + 1); mask = (unsigned long)d << 8 | (unsigned long)d; mask = mask << 16 | mask; for (i = 32; i < sizeof(mask) * 8; i <<= 1) mask = (mask << i) | mask; while (!TOO_SMALL_LITTLE_BLOCK(length)) { if (DETECT_CHAR(*asrc, mask)) break; length -= LITTLE_BLOCK_SIZE; asrc--; } /* If there are fewer than LITTLE_BLOCK_SIZE characters left, then we resort to the bytewise loop. */ src = (unsigned char *)asrc + LITTLE_BLOCK_SIZE - 1; } #endif /* not __PREFER_SIZE_OVER_SPEED */ while (length--) { if (*src == d) return (void *)src; src--; } return NULL; } picolibc-1.8.11/libc/string/memset.c000066400000000000000000000054671513574234600172710ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---set an area of memory INDEX memset SYNOPSIS #include void *memset(void *<[dst]>, int <[c]>, size_t <[length]>); DESCRIPTION This function converts the argument <[c]> into an unsigned char and fills the first <[length]> characters of the array pointed to by <[dst]> to the value. RETURNS <> returns the value of <[dst]>. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF memset ansi pure */ #include #include #include "local.h" #undef memset void * __no_builtin memset(void *m, int c, size_t n) { char *s = (char *)m; #if !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) unsigned int i; unsigned long buffer; unsigned long *aligned_addr; unsigned int d = c & 0xff; /* To avoid sign extension, copy C to an unsigned variable. */ while (UNALIGNED_X(s)) { if (n--) *s++ = (char)c; else return m; } if (!TOO_SMALL_LITTLE_BLOCK(n)) { /* If we get this far, we know that n is large and s is word-aligned. */ aligned_addr = (unsigned long *)s; /* Store D into each char sized location in BUFFER so that we can set large blocks quickly. */ buffer = (d << 8) | d; buffer |= (buffer << 16); for (i = 32; i < sizeof(buffer) * 8; i <<= 1) buffer = (buffer << i) | buffer; /* Unroll the loop. */ while (!TOO_SMALL_BIG_BLOCK(n)) { *aligned_addr++ = buffer; *aligned_addr++ = buffer; *aligned_addr++ = buffer; *aligned_addr++ = buffer; n -= BIG_BLOCK_SIZE; } while (!TOO_SMALL_LITTLE_BLOCK(n)) { *aligned_addr++ = buffer; n -= LITTLE_BLOCK_SIZE; } /* Pick up the remainder with a bytewise loop. */ s = (char *)aligned_addr; } #endif /* not __PREFER_SIZE_OVER_SPEED */ while (n--) *s++ = (char)c; return m; } picolibc-1.8.11/libc/string/memset_explicit.c000066400000000000000000000034711513574234600211630ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024 Keith Packard * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _ISOC23_SOURCE #include void * memset_explicit(void *dest, int ch, size_t count) { memset(dest, ch, count); /* Compiler barrier. */ __asm__ __volatile__("" ::"r"(dest) : "memory"); return dest; } picolibc-1.8.11/libc/string/memset_s.c000066400000000000000000000051261513574234600176030ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define __STDC_WANT_LIB_EXT1__ 1 #include #include #include "string_private.h" __errno_t memset_s(void *s, rsize_t smax, int c, rsize_t n) { const char *msg = ""; if (s == NULL) { msg = "memset_s: dest is NULL"; goto handle_error; } if (CHECK_RSIZE(smax)) { msg = "memset_s: buffer size exceeds RSIZE_MAX"; goto handle_error; } if (CHECK_RSIZE(n)) { msg = "memset_s: count exceeds RSIZE_MAX"; goto handle_error; } if (n > smax) { msg = "memset_s: count exceeds buffer size"; goto handle_error; } // Normal return path (void)memset(s, c, n); /* Compiler barrier. */ __asm__ __volatile__("" ::"r"(s) : "memory"); return 0; handle_error: if (s != NULL) { (void)memset(s, c, smax); /* Compiler barrier. */ __asm__ __volatile__("" ::"r"(s) : "memory"); } if (__cur_handler != NULL) { __cur_handler(msg, NULL, -1); } return -1; } picolibc-1.8.11/libc/string/meson.build000066400000000000000000000114311513574234600177610ustar00rootroot00000000000000# # SPDX-License-Identifier: BSD-3-Clause # # Copyright © 2019 Keith Packard # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # srcs_string = [ 'bcmp.c', 'bcopy.c', 'bzero.c', 'explicit_bzero.c', 'ffsl.c', 'ffsll.c', 'fls.c', 'flsl.c', 'flsll.c', 'gnu_basename.c', 'index.c', 'memccpy.c', 'memchr.c', 'memcmp.c', 'memcpy.c', 'memmem.c', 'memmove.c', 'mempcpy.c', 'memrchr.c', 'memset.c', 'memset_explicit.c', 'rawmemchr.c', 'rindex.c', 'stpcpy.c', 'stpncpy.c', 'strcasecmp.c', 'strcasecmp_l.c', 'strcasestr.c', 'strcat.c', 'strchr.c', 'strchrnul.c', 'strcoll.c', 'strcoll_l.c', 'strcpy.c', 'strcspn.c', 'strdup.c', 'strerror.c', 'strerror_r.c', 'strlcat.c', 'strlcpy.c', 'strlen.c', 'strlwr.c', 'strncasecmp.c', 'strncasecmp_l.c', 'strncat.c', 'strncmp.c', 'strncpy.c', 'strndup.c', 'strnlen.c', 'strnstr.c', 'strpbrk.c', 'strrchr.c', 'strsep.c', 'strsignal.c', 'strspn.c', 'strstr.c', 'strtok.c', 'strtok_r.c', 'strupr.c', 'strverscmp.c', 'strxfrm.c', 'strxfrm_l.c', 'swab.c', 'timingsafe_bcmp.c', 'timingsafe_memcmp.c', 'wcpcpy.c', 'wcpncpy.c', 'wcscasecmp.c', 'wcscasecmp_l.c', 'wcscat.c', 'wcschr.c', 'wcscmp.c', 'wcscoll.c', 'wcscoll_l.c', 'wcscpy.c', 'wcscspn.c', 'wcsdup.c', 'wcslcat.c', 'wcslcpy.c', 'wcslen.c', 'wcsncasecmp.c', 'wcsncasecmp_l.c', 'wcsncat.c', 'wcsncmp.c', 'wcsncpy.c', 'wcsnlen.c', 'wcspbrk.c', 'wcsrchr.c', 'wcsspn.c', 'wcsstr.c', 'wcstok.c', 'wcswidth.c', 'wcsxfrm.c', 'wcsxfrm_l.c', 'wcwidth.c', 'wmemchr.c', 'wmemcmp.c', 'wmemcpy.c', 'wmemmove.c', 'wmempcpy.c', 'wmemset.c', 'xpg_strerror_r.c', 'memcpy_s.c', 'memmove_s.c', 'memset_s.c', 'strcat_s.c', 'strcpy_s.c', 'strerror_s.c', 'strerrorlen_s.c', 'strncat_s.c', 'strncpy_s.c', 'strnlen_s.c', ] hdrs_string = [ 'local.h', 'str-two-way.h', 'string_private.h', ] srcs_strcmp = [ 'strcmp.c' ] srcs_string_use = [] foreach file : srcs_string s_file = fs.replace_suffix(file, '.S') if file in srcs_machine message('libc/string/' + file + ': machine overrides generic') elif s_file in srcs_machine message('libc/string/' + s_file + ': machine overrides generic') else srcs_string_use += file endif endforeach srcs_strcmp_use = [] foreach file : srcs_strcmp s_file = fs.replace_suffix(file, '.S') if file in srcs_machine message('libc/string/' + file + ': machine overrides generic') elif s_file in srcs_machine message('libc/string/' + s_file + ': machine overrides generic') else srcs_strcmp_use += file endif endforeach if fast_strcmp cargs_strcmp = ['-O3'] else cargs_strcmp = [] endif src_string = files(srcs_string_use) # Need a sub-library to pass custom cflags to strcmp if srcs_strcmp_use != [] foreach params : targets target = params['name'] target_dir = params['dir'] target_c_args = params['c_args'] set_variable('lib_string' + target, static_library('strcmp' + target, srcs_strcmp_use, pic: false, c_args: target_c_args + c_args + cargs_strcmp, include_directories: inc)) endforeach endif picolibc-1.8.11/libc/string/mkunidata000077500000000000000000000040771513574234600175320ustar00rootroot00000000000000#! /bin/sh # Copyright(c) 2018 Thomas Wolff echo Generating Unicode width data for libc/string/wcwidth.c cd `dirname $0` PATH="$PATH":. # ensure access to uniset tool ############################################################################# # checks and (with option -u) downloads case "$1" in -h) echo "Usage: $0 [-h|-u|-i]" echo "Generate width data tables ambiguous.t, combining.t, wide.t" echo "from local Unicode files UnicodeData.txt, Blocks.txt, EastAsianWidth.txt." echo "" echo "Options:" echo " -u download files from unicode.org first, download uniset tool" echo " -i copy files from /usr/share/unicode/ucd first" echo " -h show this" exit ;; -u) wget () { ref=`basename $1` ref=`ls "$ref" 2> /dev/null || echo 01-Jan-1970` curl -R -O --connect-timeout 55 -z "$ref" "$1" } echo downloading uniset tool wget https://www.cl.cam.ac.uk/~mgk25/download/uniset.tar.gz gzip -dc uniset.tar.gz | tar xvf - uniset echo downloading data from unicode.org for data in UnicodeData.txt Blocks.txt EastAsianWidth.txt do wget http://unicode.org/Public/UNIDATA/$data done ;; -i) echo copying data from /usr/share/unicode/ucd for data in UnicodeData.txt Blocks.txt EastAsianWidth.txt do cp /usr/share/unicode/ucd/$data . done ;; esac echo checking uniset tool type uniset || exit 9 echo checking Unicode data files for data in UnicodeData.txt Blocks.txt EastAsianWidth.txt do if [ -r $data ] then true else echo $data not available, skipping table generation exit fi done echo generating from Unicode version `sed -e 's,[^.0-9],,g' -e 1q Blocks.txt` ############################################################################# # table generation echo generating combining characters table uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B +D7B0-D7C6 +D7CB-D7FB c > combining.t echo generating ambiguous width characters table sh ./mkwidthA && uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c > ambiguous.t echo generating wide characters table sh ./mkwide ############################################################################# # end picolibc-1.8.11/libc/string/mkwide000077500000000000000000000024301513574234600170240ustar00rootroot00000000000000#! /bin/sh # Copyright(c) 2018 Thomas Wolff # generate list of wide characters, with convex closure skipcheck=false if [ ! -r EastAsianWidth.txt ] then ln -s /usr/share/unicode/ucd/EastAsianWidth.txt . || exit 1 fi if [ ! -r UnicodeData.txt ] then ln -s /usr/share/unicode/ucd/UnicodeData.txt . || exit 1 fi if [ ! -r Blocks.txt ] then ln -s /usr/share/unicode/ucd/Blocks.txt . || exit 1 fi sed -e "s,^\([^;]*\);[NAH],\1," -e t -e d EastAsianWidth.txt > wide.na sed -e "s,^\([^;]*\);[WF],\1," -e t -e d EastAsianWidth.txt > wide.fw PATH="$PATH:." # for uniset nrfw=`uniset +wide.fw nr | sed -e 's,.*:,,'` echo FW $nrfw nrna=`uniset +wide.na nr | sed -e 's,.*:,,'` echo NAH $nrna extrablocks="2E80-303E" # check all blocks includes () { nr=`uniset +wide.$2 -$1 nr | sed -e 's,.*:,,'` test $nr != $3 } echo "adding compact closure of wide ranges, this may take ~10min" for b in $extrablocks `sed -e 's,^\([0-9A-F]*\)\.\.\([0-9A-F]*\).*,\1-\2,' -e t -e d Blocks.txt` do range=$b echo checking $range $* >&2 if includes $range fw $nrfw && ! includes $range na $nrna then echo $range fi done > wide.blocks ( sed -e "s,^,//," -e 1q EastAsianWidth.txt sed -e "s,^,//," -e 1q Blocks.txt uniset `sed -e 's,^,+,' wide.blocks` +wide.fw c ) > wide.t rm -f wide.na wide.fw wide.blocks picolibc-1.8.11/libc/string/mkwidthA000077500000000000000000000012151513574234600173140ustar00rootroot00000000000000#! /bin/sh # Copyright(c) 2018 Thomas Wolff # generate WIDTH-A file, listing Unicode characters with width property # Ambiguous, from EastAsianWidth.txt if [ ! -r EastAsianWidth.txt ] then ln -s /usr/share/unicode/ucd/EastAsianWidth.txt . || exit 1 fi if [ ! -r UnicodeData.txt ] then ln -s /usr/share/unicode/ucd/UnicodeData.txt . || exit 1 fi if [ ! -r Blocks.txt ] then ln -s /usr/share/unicode/ucd/Blocks.txt . || exit 1 fi sed -e "s,^\([^;]*\);A,\1," -e t -e d EastAsianWidth.txt > width-a-new rm -f WIDTH-A echo "# UAX #11: East Asian Ambiguous" > WIDTH-A PATH="$PATH:." uniset +width-a-new compact >> WIDTH-A rm -f width-a-new picolibc-1.8.11/libc/string/rawmemchr.c000066400000000000000000000043661513574234600177610ustar00rootroot00000000000000/* Copyright (c) 2013 Yaakov Selkowitz */ /* FUNCTION <>---find character in memory INDEX rawmemchr SYNOPSIS #include void *rawmemchr(const void *<[src]>, int <[c]>); DESCRIPTION This function searches memory starting at <<*<[src]>>> for the character <[c]>. The search only ends with the first occurrence of <[c]>; in particular, <> does not terminate the search. No bounds checking is performed, so this function should only be used when it is certain that the character <[c]> will be found. RETURNS A pointer to the first occurance of character <[c]>. PORTABILITY <> is a GNU extension. <> requires no supporting OS subroutines. QUICKREF rawmemchr */ #define _GNU_SOURCE #include #include #include "local.h" void * rawmemchr(const void *src_void, int c) { const unsigned char *src = (const unsigned char *)src_void; unsigned char d = c; #if !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) \ && !defined(_PICOLIBC_NO_OUT_OF_BOUNDS_READS) unsigned long *asrc; unsigned long mask; unsigned int i; while (UNALIGNED_X(src)) { if (*src == d) return (void *)src; src++; } /* If we get this far, we know that src is word-aligned. */ /* The fast code reads the source one word at a time and only performs the bytewise search on word-sized segments if they contain the search character, which is detected by XORing the word-sized segment with a word-sized block of the search character and then detecting for the presence of NUL in the result. */ asrc = (unsigned long *)src; mask = d << 8 | d; mask = mask << 16 | mask; for (i = 32; i < sizeof(mask) * 8; i <<= 1) mask = (mask << i) | mask; while (1) { if (DETECT_CHAR(*asrc, mask)) break; asrc++; } /* We have the matching word, now we resort to a bytewise loop. */ src = (unsigned char *)asrc; #endif /* !__PREFER_SIZE_OVER_SPEED && !__OPTIMIZE_SIZE__ */ while (1) { if (*src == d) return (void *)src; src++; } } picolibc-1.8.11/libc/string/rindex.c000066400000000000000000000027031513574234600172560ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---reverse search for character in string INDEX rindex SYNOPSIS #include char * rindex(const char *<[string]>, int <[c]>); DESCRIPTION This function finds the last occurence of <[c]> (converted to a char) in the string pointed to by <[string]> (including the terminating null character). This function is identical to <>. RETURNS Returns a pointer to the located character, or a null pointer if <[c]> does not occur in <[string]>. PORTABILITY <> requires no supporting OS subroutines. QUICKREF rindex - pure */ #include #include char * rindex(const char *s, int c) { return strrchr(s, c); } picolibc-1.8.11/libc/string/stpcpy.c000066400000000000000000000032111513574234600173020ustar00rootroot00000000000000/* Copyright (c) 2007 Corinna Vinschen */ /* FUNCTION <>---copy string returning a pointer to its end INDEX stpcpy SYNOPSIS #include char *stpcpy(char *restrict <[dst]>, const char *restrict <[src]>); DESCRIPTION <> copies the string pointed to by <[src]> (including the terminating null character) to the array pointed to by <[dst]>. RETURNS This function returns a pointer to the end of the destination string, thus pointing to the trailing '\0'. PORTABILITY <> is a GNU extension, candidate for inclusion into POSIX/SUSv4. <> requires no supporting OS subroutines. QUICKREF stpcpy gnu */ #define IN_STPCPY #define _GNU_SOURCE #include #include #include "local.h" /*SUPPRESS 560*/ /*SUPPRESS 530*/ char * stpcpy(char * __restrict dst, const char * __restrict src) { #if !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) \ && !defined(_PICOLIBC_NO_OUT_OF_BOUNDS_READS) long *aligned_dst; const long *aligned_src; /* If SRC or DEST is unaligned, then copy bytes. */ if (!UNALIGNED_X_Y(src, dst)) { aligned_dst = (long *)dst; aligned_src = (long *)src; /* SRC and DEST are both "long int" aligned, try to do "long int" sized copies. */ while (!DETECT_NULL(*aligned_src)) { *aligned_dst++ = *aligned_src++; } dst = (char *)aligned_dst; src = (char *)aligned_src; } #endif /* not __PREFER_SIZE_OVER_SPEED */ while ((*dst++ = *src++)) ; return --dst; } picolibc-1.8.11/libc/string/stpncpy.c000066400000000000000000000045511513574234600174700ustar00rootroot00000000000000/* Copyright (c) 2007 Corinna Vinschen */ /* FUNCTION <>---counted copy string returning a pointer to its end INDEX stpncpy SYNOPSIS #include char *stpncpy(char *restrict <[dst]>, const char *restrict <[src]>, size_t <[length]>); DESCRIPTION <> copies not more than <[length]> characters from the the string pointed to by <[src]> (including the terminating null character) to the array pointed to by <[dst]>. If the string pointed to by <[src]> is shorter than <[length]> characters, null characters are appended to the destination array until a total of <[length]> characters have been written. RETURNS This function returns a pointer to the end of the destination string, thus pointing to the trailing '\0', or, if the destination string is not null-terminated, pointing to dst + n. PORTABILITY <> is a GNU extension, candidate for inclusion into POSIX/SUSv4. <> requires no supporting OS subroutines. QUICKREF stpncpy gnu */ #define _DEFAULT_SOURCE #include #include #include "local.h" /*SUPPRESS 560*/ /*SUPPRESS 530*/ char * stpncpy(char * __restrict dst, const char * __restrict src, size_t count) { char *ret = NULL; #if !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) \ && !defined(_PICOLIBC_NO_OUT_OF_BOUNDS_READS) long *aligned_dst; const long *aligned_src; /* If SRC and DEST is aligned and count large enough, then copy words. */ if (!UNALIGNED_X_Y(src, dst) && !TOO_SMALL_LITTLE_BLOCK(count)) { aligned_dst = (long *)dst; aligned_src = (long *)src; /* SRC and DEST are both LITTLE_BLOCK_SIZE aligned, try to do LITTLE_BLOCK_SIZE sized copies. */ while (!TOO_SMALL_LITTLE_BLOCK(count) && !DETECT_NULL(*aligned_src)) { count -= LITTLE_BLOCK_SIZE; *aligned_dst++ = *aligned_src++; } dst = (char *)aligned_dst; src = (char *)aligned_src; } #endif /* not __PREFER_SIZE_OVER_SPEED */ while (count > 0) { --count; if ((*dst++ = *src++) == '\0') { ret = dst - 1; break; } } while (count-- > 0) *dst++ = '\0'; return ret ? ret : dst; } picolibc-1.8.11/libc/string/str-two-way.h000066400000000000000000000365151513574234600202170ustar00rootroot00000000000000/* Byte-wise substring search, using the Two-Way algorithm. * Copyright (C) 2008, 2010 Eric Blake * Permission to use, copy, modify, and distribute this software * is freely granted, provided that this notice is preserved. */ /* Before including this file, you need to include , and define: RESULT_TYPE A macro that expands to the return type. AVAILABLE(h, h_l, j, n_l) A macro that returns nonzero if there are at least N_L bytes left starting at H[J]. H is 'unsigned char *', H_L, J, and N_L are 'size_t'; H_L is an lvalue. For NUL-terminated searches, H_L can be modified each iteration to avoid having to compute the end of H up front. For case-insensitivity, you may optionally define: CMP_FUNC(p1, p2, l) A macro that returns 0 iff the first L characters of P1 and P2 are equal. CANON_ELEMENT(c) A macro that canonicalizes an element right after it has been fetched from one of the two strings. The argument is an 'unsigned char'; the result must be an 'unsigned char' as well. This file undefines the macros documented above, and defines LONG_NEEDLE_THRESHOLD. */ #include #include /* We use the Two-Way string matching algorithm, which guarantees linear complexity with constant space. Additionally, for long needles, we also use a bad character shift table similar to the Boyer-Moore algorithm to achieve improved (potentially sub-linear) performance. See http://www-igm.univ-mlv.fr/~lecroq/string/node26.html#SECTION00260 and http://en.wikipedia.org/wiki/Boyer-Moore_string_search_algorithm */ /* Point at which computing a bad-byte shift table is likely to be worthwhile. Small needles should not compute a table, since it adds (1 << CHAR_BIT) + NEEDLE_LEN computations of preparation for a speedup no greater than a factor of NEEDLE_LEN. The larger the needle, the better the potential performance gain. On the other hand, on non-POSIX systems with CHAR_BIT larger than eight, the memory required for the table is prohibitive. */ #if CHAR_BIT < 10 #define LONG_NEEDLE_THRESHOLD 32U #else #define LONG_NEEDLE_THRESHOLD SIZE_MAX #endif #define MAX(a, b) ((a < b) ? (b) : (a)) #ifndef CANON_ELEMENT #define CANON_ELEMENT(c) c #endif #ifndef CMP_FUNC #define CMP_FUNC memcmp #endif /* Perform a critical factorization of NEEDLE, of length NEEDLE_LEN. Return the index of the first byte in the right half, and set *PERIOD to the global period of the right half. The global period of a string is the smallest index (possibly its length) at which all remaining bytes in the string are repetitions of the prefix (the last repetition may be a subset of the prefix). When NEEDLE is factored into two halves, a local period is the length of the smallest word that shares a suffix with the left half and shares a prefix with the right half. All factorizations of a non-empty NEEDLE have a local period of at least 1 and no greater than NEEDLE_LEN. A critical factorization has the property that the local period equals the global period. All strings have at least one critical factorization with the left half smaller than the global period. Given an ordered alphabet, a critical factorization can be computed in linear time, with 2 * NEEDLE_LEN comparisons, by computing the larger of two ordered maximal suffixes. The ordered maximal suffixes are determined by lexicographic comparison of periodicity. */ static size_t critical_factorization(const unsigned char *needle, size_t needle_len, size_t *period) { /* Index of last byte of left half, or SIZE_MAX. */ size_t max_suffix, max_suffix_rev; size_t j; /* Index into NEEDLE for current candidate suffix. */ size_t k; /* Offset into current period. */ size_t p; /* Intermediate period. */ unsigned char a, b; /* Current comparison bytes. */ /* Invariants: 0 <= j < NEEDLE_LEN - 1 -1 <= max_suffix{,_rev} < j (treating SIZE_MAX as if it were signed) min(max_suffix, max_suffix_rev) < global period of NEEDLE 1 <= p <= global period of NEEDLE p == global period of the substring NEEDLE[max_suffix{,_rev}+1...j] 1 <= k <= p */ /* Perform lexicographic search. */ max_suffix = SIZE_MAX; j = 0; k = p = 1; while (j + k < needle_len) { a = CANON_ELEMENT(needle[j + k]); b = CANON_ELEMENT(needle[(size_t)(max_suffix + k)]); if (a < b) { /* Suffix is smaller, period is entire prefix so far. */ j += k; k = 1; p = j - max_suffix; } else if (a == b) { /* Advance through repetition of the current period. */ if (k != p) ++k; else { j += p; k = 1; } } else /* b < a */ { /* Suffix is larger, start over from current location. */ max_suffix = j++; k = p = 1; } } *period = p; /* Perform reverse lexicographic search. */ max_suffix_rev = SIZE_MAX; j = 0; k = p = 1; while (j + k < needle_len) { a = CANON_ELEMENT(needle[j + k]); b = CANON_ELEMENT(needle[max_suffix_rev + k]); if (b < a) { /* Suffix is smaller, period is entire prefix so far. */ j += k; k = 1; p = j - max_suffix_rev; } else if (a == b) { /* Advance through repetition of the current period. */ if (k != p) ++k; else { j += p; k = 1; } } else /* a < b */ { /* Suffix is larger, start over from current location. */ max_suffix_rev = j++; k = p = 1; } } /* Choose the longer suffix. Return the first byte of the right half, rather than the last byte of the left half. */ if (max_suffix_rev + 1 < max_suffix + 1) return max_suffix + 1; *period = p; return max_suffix_rev + 1; } /* Return the first location of non-empty NEEDLE within HAYSTACK, or NULL. HAYSTACK_LEN is the minimum known length of HAYSTACK. This method is optimized for NEEDLE_LEN < LONG_NEEDLE_THRESHOLD. Performance is guaranteed to be linear, with an initialization cost of 2 * NEEDLE_LEN comparisons. If AVAILABLE does not modify HAYSTACK_LEN (as in memmem), then at most 2 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching. If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching. */ static inline RETURN_TYPE two_way_short_needle(const unsigned char *haystack, size_t haystack_len, const unsigned char *needle, size_t needle_len) { size_t i; /* Index into current byte of NEEDLE. */ size_t j; /* Index into current window of HAYSTACK. */ size_t period; /* The period of the right half of needle. */ size_t suffix; /* The index of the right half of needle. */ /* Factor the needle into two halves, such that the left half is smaller than the global period, and the right half is periodic (with a period as large as NEEDLE_LEN - suffix). */ suffix = critical_factorization(needle, needle_len, &period); /* Perform the search. Each iteration compares the right half first. */ if (CMP_FUNC(needle, needle + period, suffix) == 0) { /* Entire needle is periodic; a mismatch can only advance by the period, so use memory to avoid rescanning known occurrences of the period. */ size_t memory = 0; j = 0; while (AVAILABLE(haystack, haystack_len, j, needle_len)) { /* Scan for matches in right half. */ i = MAX(suffix, memory); while (i < needle_len && (CANON_ELEMENT(needle[i]) == CANON_ELEMENT(haystack[i + j]))) ++i; if (needle_len <= i) { /* Scan for matches in left half. */ i = suffix - 1; while (memory < i + 1 && (CANON_ELEMENT(needle[i]) == CANON_ELEMENT(haystack[i + j]))) --i; if (i + 1 < memory + 1) return (RETURN_TYPE)(haystack + j); /* No match, so remember how many repetitions of period on the right half were scanned. */ j += period; memory = needle_len - period; } else { j += i - suffix + 1; memory = 0; } } } else { /* The two halves of needle are distinct; no extra memory is required, and any mismatch results in a maximal shift. */ period = MAX(suffix, needle_len - suffix) + 1; j = 0; while (AVAILABLE(haystack, haystack_len, j, needle_len)) { /* Scan for matches in right half. */ i = suffix; while (i < needle_len && (CANON_ELEMENT(needle[i]) == CANON_ELEMENT(haystack[i + j]))) ++i; if (needle_len <= i) { /* Scan for matches in left half. */ i = suffix - 1; while (i != SIZE_MAX && (CANON_ELEMENT(needle[i]) == CANON_ELEMENT(haystack[i + j]))) --i; if (i == SIZE_MAX) return (RETURN_TYPE)(haystack + j); j += period; } else j += i - suffix + 1; } } return NULL; } /* Return the first location of non-empty NEEDLE within HAYSTACK, or NULL. HAYSTACK_LEN is the minimum known length of HAYSTACK. This method is optimized for LONG_NEEDLE_THRESHOLD <= NEEDLE_LEN. Performance is guaranteed to be linear, with an initialization cost of 3 * NEEDLE_LEN + (1 << CHAR_BIT) operations. If AVAILABLE does not modify HAYSTACK_LEN (as in memmem), then at most 2 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching, and sublinear performance O(HAYSTACK_LEN / NEEDLE_LEN) is possible. If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching, and sublinear performance is not possible. */ __noinline static RETURN_TYPE __used two_way_long_needle(const unsigned char *haystack, size_t haystack_len, const unsigned char *needle, size_t needle_len) { size_t i; /* Index into current byte of NEEDLE. */ size_t j; /* Index into current window of HAYSTACK. */ size_t period; /* The period of the right half of needle. */ size_t suffix; /* The index of the right half of needle. */ size_t shift_table[1U << CHAR_BIT]; /* See below. */ /* Factor the needle into two halves, such that the left half is smaller than the global period, and the right half is periodic (with a period as large as NEEDLE_LEN - suffix). */ suffix = critical_factorization(needle, needle_len, &period); /* Populate shift_table. For each possible byte value c, shift_table[c] is the distance from the last occurrence of c to the end of NEEDLE, or NEEDLE_LEN if c is absent from the NEEDLE. shift_table[NEEDLE[NEEDLE_LEN - 1]] contains the only 0. */ for (i = 0; i < 1U << CHAR_BIT; i++) shift_table[i] = needle_len; for (i = 0; i < needle_len; i++) shift_table[CANON_ELEMENT(needle[i])] = needle_len - i - 1; /* Perform the search. Each iteration compares the right half first. */ if (CMP_FUNC(needle, needle + period, suffix) == 0) { /* Entire needle is periodic; a mismatch can only advance by the period, so use memory to avoid rescanning known occurrences of the period. */ size_t memory = 0; size_t shift; j = 0; while (AVAILABLE(haystack, haystack_len, j, needle_len)) { /* Check the last byte first; if it does not match, then shift to the next possible match location. */ shift = shift_table[CANON_ELEMENT(haystack[j + needle_len - 1])]; if (0 < shift) { if (memory && shift < period) { /* Since needle is periodic, but the last period has a byte out of place, there can be no match until after the mismatch. */ shift = needle_len - period; } memory = 0; j += shift; continue; } /* Scan for matches in right half. The last byte has already been matched, by virtue of the shift table. */ i = MAX(suffix, memory); while (i < needle_len - 1 && (CANON_ELEMENT(needle[i]) == CANON_ELEMENT(haystack[i + j]))) ++i; if (needle_len - 1 <= i) { /* Scan for matches in left half. */ i = suffix - 1; while (memory < i + 1 && (CANON_ELEMENT(needle[i]) == CANON_ELEMENT(haystack[i + j]))) --i; if (i + 1 < memory + 1) return (RETURN_TYPE)(haystack + j); /* No match, so remember how many repetitions of period on the right half were scanned. */ j += period; memory = needle_len - period; } else { j += i - suffix + 1; memory = 0; } } } else { /* The two halves of needle are distinct; no extra memory is required, and any mismatch results in a maximal shift. */ size_t shift; period = MAX(suffix, needle_len - suffix) + 1; j = 0; while (AVAILABLE(haystack, haystack_len, j, needle_len)) { /* Check the last byte first; if it does not match, then shift to the next possible match location. */ shift = shift_table[CANON_ELEMENT(haystack[j + needle_len - 1])]; if (0 < shift) { j += shift; continue; } /* Scan for matches in right half. The last byte has already been matched, by virtue of the shift table. */ i = suffix; while (i < needle_len - 1 && (CANON_ELEMENT(needle[i]) == CANON_ELEMENT(haystack[i + j]))) ++i; if (needle_len - 1 <= i) { /* Scan for matches in left half. */ i = suffix - 1; while (i != SIZE_MAX && (CANON_ELEMENT(needle[i]) == CANON_ELEMENT(haystack[i + j]))) --i; if (i == SIZE_MAX) return (RETURN_TYPE)(haystack + j); j += period; } else j += i - suffix + 1; } } return NULL; } #undef AVAILABLE #undef CANON_ELEMENT #undef CMP_FUNC #undef MAX #undef RETURN_TYPE picolibc-1.8.11/libc/string/strcasecmp.c000066400000000000000000000036241513574234600201340ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---case-insensitive character string compare INDEX strcasecmp SYNOPSIS #include int strcasecmp(const char *<[a]>, const char *<[b]>); DESCRIPTION <> compares the string at <[a]> to the string at <[b]> in a case-insensitive manner. RETURNS If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after both are converted to lowercase), <> returns a number greater than zero. If the two strings match, <> returns zero. If <<*<[a]>>> sorts lexicographically before <<*<[b]>>>, <> returns a number less than zero. PORTABILITY <> is in the Berkeley Software Distribution. <> requires no supporting OS subroutines. It uses tolower() from elsewhere in this library. QUICKREF strcasecmp */ #include #include int strcasecmp(const char *s1, const char *s2) { int d = 0; for (;;) { const int c1 = tolower(*(unsigned char *)s1++); const int c2 = tolower(*(unsigned char *)s2++); if (((d = c1 - c2) != 0) || (c2 == '\0')) break; } return d; } picolibc-1.8.11/libc/string/strcasecmp_l.c000066400000000000000000000027451513574234600204520ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen */ /* FUNCTION <>---case-insensitive character string compare INDEX strcasecmp_l SYNOPSIS #include int strcasecmp_l(const char *<[a]>, const char *<[b]>, locale_t <[locale]>); DESCRIPTION <> compares the string at <[a]> to the string at <[b]> in a case-insensitive manner. if <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after both are converted to lowercase), <> returns a number greater than zero. If the two strings match, <> returns zero. If <<*<[a]>>> sorts lexicographically before <<*<[b]>>>, <> returns a number less than zero. PORTABILITY <> is POSIX-1.2008. <> requires no supporting OS subroutines. It uses tolower_l() from elsewhere in this library. QUICKREF strcasecmp_l */ #define _DEFAULT_SOURCE #include #include int strcasecmp_l(const char *s1, const char *s2, locale_t locale) { int d = 0; for (;;) { const int c1 = tolower_l(*(unsigned char *)s1++, locale); const int c2 = tolower_l(*(unsigned char *)s2++, locale); if (((d = c1 - c2) != 0) || (c2 == '\0')) break; } return d; } picolibc-1.8.11/libc/string/strcasestr.c000066400000000000000000000120621513574234600201610ustar00rootroot00000000000000/* FUNCTION <>---case-insensitive character string search INDEX strcasestr SYNOPSIS #include char *strcasestr(const char *<[s]>, const char *<[find]>); DESCRIPTION <> searchs the string <[s]> for the first occurrence of the sequence <[find]>. <> is identical to <> except the search is case-insensitive. RETURNS A pointer to the first case-insensitive occurrence of the sequence <[find]> or <> if no match was found. PORTABILITY <> is in the Berkeley Software Distribution. <> requires no supporting OS subroutines. It uses tolower() from elsewhere in this library. QUICKREF strcasestr */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * The quadratic code is derived from software contributed to Berkeley by * Chris Torek. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* Linear algorithm Copyright (C) 2008 Eric Blake * Permission to use, copy, modify, and distribute the linear portion of * software is freely granted, provided that this notice is preserved. */ #define _GNU_SOURCE #include #include #include #if !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) #define RETURN_TYPE char * #define AVAILABLE(h, h_l, j, n_l) \ (!memchr((h) + (h_l), '\0', (j) + (n_l) - (h_l)) && ((h_l) = (j) + (n_l))) #define CANON_ELEMENT(c) tolower(c) #ifdef __GNUCLIKE_PRAGMA_DIAGNOSTIC /* strncasecmp uses signed char, CMP_FUNC is expected to use unsigned char. */ #pragma GCC diagnostic ignored "-Wpointer-sign" #endif #define CMP_FUNC strncasecmp #include "str-two-way.h" #endif /* * Find the first occurrence of find in s, ignore case. */ char * strcasestr(const char *s, const char *find) { #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) /* Less code size, but quadratic performance in the worst case. */ char c, sc; size_t len; if ((c = *find++) != 0) { c = tolower((unsigned char)c); len = strlen(find); do { do { if ((sc = *s++) == 0) return (NULL); } while ((char)tolower((unsigned char)sc) != c); } while (strncasecmp(s, find, len) != 0); s--; } return ((char *)s); #else /* compilation for speed */ /* Larger code size, but guaranteed linear performance. */ const char *haystack = s; const char *needle = find; size_t needle_len; /* Length of NEEDLE. */ size_t haystack_len; /* Known minimum length of HAYSTACK. */ int ok = 1; /* True if NEEDLE is prefix of HAYSTACK. */ /* Determine length of NEEDLE, and in the process, make sure HAYSTACK is at least as long (no point processing all of a long NEEDLE if HAYSTACK is too short). */ while (*haystack && *needle) ok &= (tolower((unsigned char)*haystack++) == tolower((unsigned char)*needle++)); if (*needle) return NULL; if (ok) return (char *)s; needle_len = needle - find; haystack = s + 1; haystack_len = needle_len - 1; /* Perform the search. */ if (needle_len < LONG_NEEDLE_THRESHOLD) return two_way_short_needle((const unsigned char *)haystack, haystack_len, (const unsigned char *)find, needle_len); return two_way_long_needle((const unsigned char *)haystack, haystack_len, (const unsigned char *)find, needle_len); #endif /* compilation for speed */ } picolibc-1.8.11/libc/string/strcat.c000066400000000000000000000051441513574234600172670ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---concatenate strings INDEX strcat SYNOPSIS #include char *strcat(char *restrict <[dst]>, const char *restrict <[src]>); DESCRIPTION <> appends a copy of the string pointed to by <[src]> (including the terminating null character) to the end of the string pointed to by <[dst]>. The initial character of <[src]> overwrites the null character at the end of <[dst]>. RETURNS This function returns the initial value of <[dst]> PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF strcat ansi pure */ #include #include #include "local.h" /*SUPPRESS 560*/ /*SUPPRESS 530*/ #undef strcat char * strcat(char * __restrict s1, const char * __restrict s2) { #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) \ || defined(_PICOLIBC_NO_OUT_OF_BOUNDS_READS) char *s = s1; while (*s1) s1++; while ((*s1++ = *s2++)) ; return s; #else char *s = s1; /* Skip unaligned memory in s1. */ while (UNALIGNED_X(s1) && *s1) s1++; if (*s1) { /* Skip over the aligned data in s1 as quickly as possible. */ unsigned long *aligned_s1 = (unsigned long *)s1; while (!DETECT_NULL(*aligned_s1)) aligned_s1++; s1 = (char *)aligned_s1; /* Find string terminator. */ while (*s1) s1++; } /* s1 now points to the its trailing null character, we can just use strcpy to do the work for us now. ?!? We might want to just include strcpy here. Also, this will cause many more unaligned string copies because s1 is much less likely to be aligned. I don't know if its worth tweaking strcpy to handle this better. */ strcpy(s1, s2); return s; #endif /* not __PREFER_SIZE_OVER_SPEED */ } picolibc-1.8.11/libc/string/strcat_s.c000066400000000000000000000111171513574234600176060ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define __STDC_WANT_LIB_EXT1__ 1 #include #include #include "string_private.h" __errno_t strcat_s(char * __restrict s1, rsize_t s1max, const char * __restrict s2) { const char *msg = ""; size_t s1_len = 0; bool write_null = true; if (s1 == NULL) { msg = "strcat_s: dest is NULL"; write_null = false; goto handle_error; } if ((s1max == 0) || (CHECK_RSIZE(s1max))) { msg = "strcat_s: dest buffer size is 0 or exceeds RSIZE_MAX"; write_null = false; goto handle_error; } if (s2 == NULL) { msg = "strcat_s: source is NULL"; goto handle_error; } /* It is a constraint violation if s1max is not large enough to contain * the concatenation s2: no truncation permitted. * It is also a constraint violation if the string pointed to by s2 * overlaps s1 in any way. * The C11 Rationale says we are permitted to proceed with the copy and * detect dest buffer overrun and overlapping memory blocks as a byproduct * of performing the copy operation. This is to avoid calling strlen on * s2 to detect these violations prior to attempting the copy. */ // compute chars available in s1 s1_len = strnlen_s(s1, s1max); if (s1_len == s1max) { msg = "strcat_s: string 1 length exceeds buffer size"; goto handle_error; } const char *overlap_point; bool check_s1_for_overlap; unsigned m = s1max - s1_len; char *s1cp = s1 + s1_len; const char *s2cp = s2; if (s1 <= s2) { // if we ever reach s2 when storing to s1 we have overlap overlap_point = s2; check_s1_for_overlap = true; // make sure source does not lie within initial dest string. if (s2 <= s1cp) { msg = "strcat_s: overlapping copy"; goto handle_error; } } else { // if we ever reach s1 when reading from s2 we have overlap overlap_point = s1; check_s1_for_overlap = false; // issue with checking initial dest string does not apply in this // case, overlap will be detected only by hitting overlap_point. } unsigned written = 0; char c = '.'; while (written < m) { if (check_s1_for_overlap) { if (s1cp == overlap_point) { msg = "strcat_s: overlapping copy"; goto handle_error; } } else if (s2cp == overlap_point) { msg = "strcat_s: overlapping copy"; goto handle_error; } c = *s2cp++; *s1cp++ = c; written++; if (c == '\0') { break; } } if (c != '\0') { msg = "strcat_s: dest buffer size insufficent to append string"; goto handle_error; } // Normal return path return 0; handle_error: if (write_null && s1 != NULL) { *s1 = '\0'; } if (__cur_handler != NULL) { __cur_handler(msg, NULL, -1); } return -1; } picolibc-1.8.11/libc/string/strchr.c000066400000000000000000000056741513574234600173040ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---search for character in string INDEX strchr SYNOPSIS #include char * strchr(const char *<[string]>, int <[c]>); DESCRIPTION This function finds the first occurence of <[c]> (converted to a char) in the string pointed to by <[string]> (including the terminating null character). RETURNS Returns a pointer to the located character, or a null pointer if <[c]> does not occur in <[string]>. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF strchr ansi pure */ #include #include #include "local.h" char * strchr(const char *s1, int i) { const unsigned char *s = (const unsigned char *)s1; unsigned char c = i; #if !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) \ && !defined(_PICOLIBC_NO_OUT_OF_BOUNDS_READS) unsigned long mask, j; unsigned long *aligned_addr; /* Special case for finding 0. */ if (!c) { while (UNALIGNED_X(s)) { if (!*s) return (char *)s; s++; } /* Operate a word at a time. */ aligned_addr = (unsigned long *)s; while (!DETECT_NULL(*aligned_addr)) aligned_addr++; /* Found the end of string. */ s = (const unsigned char *)aligned_addr; while (*s) s++; return (char *)s; } /* All other bytes. Align the pointer, then search a long at a time. */ while (UNALIGNED_X(s)) { if (!*s) return NULL; if (*s == c) return (char *)s; s++; } mask = c; for (j = 8; j < sizeof(mask) * 8; j <<= 1) mask = (mask << j) | mask; aligned_addr = (unsigned long *)s; while (!DETECT_NULL(*aligned_addr) && !DETECT_CHAR(*aligned_addr, mask)) aligned_addr++; /* The block of bytes currently pointed to by aligned_addr contains either a null or the target char, or both. We catch it using the bytewise search. */ s = (unsigned char *)aligned_addr; #endif /* not __PREFER_SIZE_OVER_SPEED */ while (*s && *s != c) s++; if (*s == c) return (char *)s; return NULL; } picolibc-1.8.11/libc/string/strchrnul.c000066400000000000000000000016661513574234600200200ustar00rootroot00000000000000/* Copyright (c) 2011 Corinna Vinschen */ /* FUNCTION <>---search for character in string INDEX strchrnul SYNOPSIS #include char * strchrnul(const char *<[string]>, int <[c]>); DESCRIPTION This function finds the first occurence of <[c]> (converted to a char) in the string pointed to by <[string]> (including the terminating null character). RETURNS Returns a pointer to the located character, or a pointer to the concluding null byte if <[c]> does not occur in <[string]>. PORTABILITY <> is a GNU extension. <> requires no supporting OS subroutines. It uses strchr() and strlen() from elsewhere in this library. QUICKREF strchrnul */ #define _GNU_SOURCE #include char * strchrnul(const char *s1, int i) { char *s = strchr(s1, i); return s ? s : (char *)s1 + strlen(s1); } picolibc-1.8.11/libc/string/strcmp.c000066400000000000000000000051721513574234600173000ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---character string compare INDEX strcmp SYNOPSIS #include int strcmp(const char *<[a]>, const char *<[b]>); DESCRIPTION <> compares the string at <[a]> to the string at <[b]>. RETURNS If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>, <> returns a number greater than zero. If the two strings match, <> returns zero. If <<*<[a]>>> sorts lexicographically before <<*<[b]>>>, <> returns a number less than zero. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF strcmp ansi pure */ #include #include #include "local.h" int strcmp(const char *s1, const char *s2) { #if ((defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)) && !defined(__FAST_STRCMP)) \ || defined(_PICOLIBC_NO_OUT_OF_BOUNDS_READS) while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; } return (*(unsigned char *)s1) - (*(unsigned char *)s2); #else unsigned long *a1; unsigned long *a2; /* If s1 or s2 are unaligned, then compare bytes. */ if (!UNALIGNED_X_Y(s1, s2)) { /* If s1 and s2 are word-aligned, compare them a word at a time. */ a1 = (unsigned long *)s1; a2 = (unsigned long *)s2; while (*a1 == *a2) { /* To get here, *a1 == *a2, thus if we find a null in *a1, then the strings must be equal, so return zero. */ if (DETECT_NULL(*a1)) return 0; a1++; a2++; } /* A difference was detected in last few bytes of s1, so search bytewise */ s1 = (char *)a1; s2 = (char *)a2; } while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; } return (*(unsigned char *)s1) - (*(unsigned char *)s2); #endif /* not __PREFER_SIZE_OVER_SPEED */ } picolibc-1.8.11/libc/string/strcoll.c000066400000000000000000000034041513574234600174460ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---locale-specific character string compare INDEX strcoll SYNOPSIS #include int strcoll(const char *<[stra]>, const char * <[strb]>); DESCRIPTION <> compares the string pointed to by <[stra]> to the string pointed to by <[strb]>, using an interpretation appropriate to the current <> state. (NOT Cygwin:) The current implementation of <> simply uses <> and does not support any language-specific sorting. RETURNS If the first string is greater than the second string, <> returns a number greater than zero. If the two strings are equivalent, <> returns zero. If the first string is less than the second string, <> returns a number less than zero. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF strcoll ansi pure */ #include int strcoll(const char *a, const char *b) { return strcmp(a, b); } picolibc-1.8.11/libc/string/strcoll_l.c000066400000000000000000000025571513574234600177710ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen */ /* FUNCTION <>---locale-specific character string compare INDEX strcoll_l SYNOPSIS #include int strcoll_l(const char *<[stra]>, const char * <[strb]>, locale_t <[locale]>); DESCRIPTION <> compares the string pointed to by <[stra]> to the string pointed to by <[strb]>, using an interpretation appropriate to the current <> state. (NOT Cygwin:) The current implementation of <> simply uses <> and does not support any language-specific sorting. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS If the first string is greater than the second string, <> returns a number greater than zero. If the two strings are equivalent, <> returns zero. If the first string is less than the second string, <> returns a number less than zero. PORTABILITY <> is POSIX-1.2008. <> requires no supporting OS subroutines. QUICKREF strcoll_l ansi pure */ #define _DEFAULT_SOURCE #include int strcoll_l(const char *a, const char *b, locale_t locale) { (void)locale; return strcmp(a, b); } picolibc-1.8.11/libc/string/strcpy.c000066400000000000000000000043161513574234600173130ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---copy string INDEX strcpy SYNOPSIS #include char *strcpy(char *<[dst]>, const char *<[src]>); DESCRIPTION <> copies the string pointed to by <[src]> (including the terminating null character) to the array pointed to by <[dst]>. RETURNS This function returns the initial value of <[dst]>. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF strcpy ansi pure */ #include #include #include "local.h" /*SUPPRESS 560*/ /*SUPPRESS 530*/ #undef strcpy char * strcpy(char *dst0, const char *src0) { #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) \ || defined(_PICOLIBC_NO_OUT_OF_BOUNDS_READS) char *s = dst0; while ((*dst0++ = *src0++)) ; return s; #else char *dst = dst0; const char *src = src0; long *aligned_dst; const long *aligned_src; /* If SRC or DEST is unaligned, then copy bytes. */ if (!UNALIGNED_X_Y(src, dst)) { aligned_dst = (long *)dst; aligned_src = (long *)src; /* SRC and DEST are both "long int" aligned, try to do "long int" sized copies. */ while (!DETECT_NULL(*aligned_src)) { *aligned_dst++ = *aligned_src++; } dst = (char *)aligned_dst; src = (char *)aligned_src; } while ((*dst++ = *src++)) ; return dst0; #endif /* not __PREFER_SIZE_OVER_SPEED */ } picolibc-1.8.11/libc/string/strcpy_s.c000066400000000000000000000077451513574234600176460ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define __STDC_WANT_LIB_EXT1__ 1 #include #include #include "string_private.h" __errno_t strcpy_s(char * __restrict s1, rsize_t s1max, const char * __restrict s2) { const char *msg = ""; bool write_null = true; if (s1 == NULL) { msg = "strcpy_s: dest is NULL"; write_null = false; goto handle_error; } if ((s1max == 0) || (CHECK_RSIZE(s1max))) { msg = "strcpy_s: dest buffer size is 0 or exceeds RSIZE_MAX"; write_null = false; goto handle_error; } if (s2 == NULL) { msg = "strcpy_s: source is NULL"; goto handle_error; } /* It is a constraint violation if s1max is not large enough to contain * s2: no truncation permitted. * It is also a constraint violation if the string pointed to by s2 * overlaps s1 in any way. * The C11 Rationale says we are permitted to proceed with the copy and * detect dest buffer overrun and overlapping memory blocks as a byproduct * of performing the copy operation. This is to avoid calling strlen on * s2 to detect these violations prior to attempting the copy. */ const char *overlap_point; bool check_s1_for_overlap; char *s1cp = s1; const char *s2cp = s2; if (s1 < s2) { // if we ever reach s2 when storing to s1 we have overlap overlap_point = s2; check_s1_for_overlap = true; } else { // if we ever reach s1 when reading from s2 we have overlap overlap_point = s1; check_s1_for_overlap = false; } unsigned written = 0; char c = '.'; while (written < s1max) { if (check_s1_for_overlap) { if (s1cp == overlap_point) { msg = "strcpy_s: overlapping copy"; goto handle_error; } } else if (s2cp == overlap_point) { msg = "strcpy_s: overlapping copy"; goto handle_error; } c = *s2cp++; *s1cp++ = c; written++; if (c == '\0') { break; } } if (c != '\0') { msg = "strcpy_s: dest buffer size insufficent to copy string"; goto handle_error; } // Normal return path return 0; handle_error: if (write_null && s1 != NULL) { *s1 = '\0'; } if (__cur_handler != NULL) { __cur_handler(msg, NULL, -1); } return -1; } picolibc-1.8.11/libc/string/strcspn.c000066400000000000000000000030431513574234600174570ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---count characters not in string INDEX strcspn SYNOPSIS size_t strcspn(const char *<[s1]>, const char *<[s2]>); DESCRIPTION This function computes the length of the initial part of the string pointed to by <[s1]> which consists entirely of characters <[NOT]> from the string pointed to by <[s2]> (excluding the terminating null character). RETURNS <> returns the length of the substring found. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. */ #include size_t strcspn(const char *s1, const char *s2) { const char *s = s1; const char *c; while (*s1) { for (c = s2; *c; c++) { if (*s1 == *c) goto end; } s1++; } end: return s1 - s; } picolibc-1.8.11/libc/string/strdup.c000066400000000000000000000004531513574234600173060ustar00rootroot00000000000000/* Copyright (c) 2002 Jeff Johnston */ #define _DEFAULT_SOURCE #include #include char * strdup(const char *str) { size_t len = strlen(str) + 1; char *copy = malloc(len); if (copy) { memcpy(copy, str, len); } return copy; } picolibc-1.8.11/libc/string/strerror.c000066400000000000000000000433531513574234600176550ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /*** **** CAUTION!!! KEEP DOC CONSISTENT---if you change text of a message **** here, change two places: **** 1) the leading doc section (alphabetized by macro) **** 2) the real text inside switch(errnum) ***/ /* FUNCTION <>, <>---convert error number to string INDEX strerror INDEX strerror_l SYNOPSIS #include char *strerror(int <[errnum]>); char *strerror_l(int <[errnum]>, locale_t <[locale]>); char *_strerror_r(struct _reent <[ptr]>, int <[errnum]>, int <[internal]>, int *<[error]>); DESCRIPTION <> converts the error number <[errnum]> into a string. The value of <[errnum]> is usually a copy of <>. If <> is not a known error number, the result points to an empty string. <> is like <> but creates a string in a format as expected in locale <[locale]>. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. This implementation of <> prints out the following strings for each of the values defined in `<>': o+ o 0 Success o E2BIG Arg list too long o EACCES Permission denied o EADDRINUSE Address already in use o EADDRNOTAVAIL Address not available o EADV Advertise error o EAFNOSUPPORT Address family not supported by protocol family o EAGAIN No more processes o EALREADY Socket already connected o EBADF Bad file number o EBADMSG Bad message o EBUSY Device or resource busy o ECANCELED Operation canceled o ECHILD No children o ECOMM Communication error o ECONNABORTED Software caused connection abort o ECONNREFUSED Connection refused o ECONNRESET Connection reset by peer o EDEADLK Deadlock o EDESTADDRREQ Destination address required o EEXIST File exists o EDOM Mathematics argument out of domain of function o EFAULT Bad address o EFBIG File too large o EHOSTDOWN Host is down o EHOSTUNREACH Host is unreachable o EIDRM Identifier removed o EILSEQ Illegal byte sequence o EINPROGRESS Connection already in progress o EINTR Interrupted system call o EINVAL Invalid argument o EIO I/O error o EISCONN Socket is already connected o EISDIR Is a directory o ELIBACC Cannot access a needed shared library o ELIBBAD Accessing a corrupted shared library o ELIBEXEC Cannot exec a shared library directly o ELIBMAX Attempting to link in more shared libraries than system limit o ELIBSCN <<.lib>> section in a.out corrupted o EMFILE File descriptor value too large o EMLINK Too many links o EMSGSIZE Message too long o EMULTIHOP Multihop attempted o ENAMETOOLONG File or path name too long o ENETDOWN Network interface is not configured o ENETRESET Connection aborted by network o ENETUNREACH Network is unreachable o ENFILE Too many open files in system o ENOBUFS No buffer space available o ENODATA No data o ENODEV No such device o ENOENT No such file or directory o ENOEXEC Exec format error o ENOLCK No lock o ENOLINK Virtual circuit is gone o ENOMEM Not enough space o ENOMSG No message of desired type o ENONET Machine is not on the network o ENOPKG No package o ENOPROTOOPT Protocol not available o ENOSPC No space left on device o ENOSR No stream resources o ENOSTR Not a stream o ENOSYS Function not implemented o ENOTBLK Block device required o ENOTCONN Socket is not connected o ENOTDIR Not a directory o ENOTEMPTY Directory not empty o ENOTRECOVERABLE State not recoverable o ENOTSOCK Socket operation on non-socket o ENOTSUP Not supported o ENOTTY Not a character device o ENXIO No such device or address o EOPNOTSUPP Operation not supported on socket o EOVERFLOW Value too large for defined data type o EOWNERDEAD Previous owner died o EPERM Not owner o EPIPE Broken pipe o EPROTO Protocol error o EPROTOTYPE Protocol wrong type for socket o EPROTONOSUPPORT Unknown protocol o ERANGE Result too large o EREMOTE Resource is remote o EROFS Read-only file system o ESHUTDOWN Can't send after socket shutdown o ESOCKTNOSUPPORT Socket type not supported o ESPIPE Illegal seek o ESRCH No such process o ESRMNT Srmount error o ESTRPIPE Strings pipe error o ETIME Stream ioctl timeout o ETIMEDOUT Connection timed out o ETXTBSY Text file busy o EWOULDBLOCK Operation would block (usually same as EAGAIN) o EXDEV Cross-device link o- <<_strerror_r>> is a reentrant version of the above. RETURNS This function returns a pointer to a string. Your application must not modify that string. PORTABILITY ANSI C requires <>, but does not specify the strings used for each error number. <> is POSIX-1.2008. Although this implementation of <> is reentrant (depending on <<_user_strerror>>), ANSI C declares that subsequent calls to <> may overwrite the result string; therefore portable code cannot depend on the reentrancy of this subroutine. Although this implementation of <> guarantees a non-null result with a NUL-terminator, some implementations return <> on failure. Although POSIX allows <> to set <> to EINVAL on failure, this implementation does not do so (unless you provide <<_user_strerror>>). POSIX recommends that unknown <[errnum]> result in a message including that value, however it is not a requirement and this implementation does not provide that information (unless you provide <<_user_strerror>>). This implementation of <> provides for user-defined extensibility. <> defines <[__ELASTERROR]>, which can be used as a base for user-defined error values. If the user supplies a routine named <<_user_strerror>>, and <[errnum]> passed to <> does not match any of the supported values, <<_user_strerror>> is called with three arguments. The first is of type <[int]>, and is the <[errnum]> value unknown to <>. The second is of type <[int]>, and matches the <[internal]> argument of <<_strerror_r>>; this should be zero if called from <> and non-zero if called from any other function; <<_user_strerror>> can use this information to satisfy the POSIX rule that no other standardized function can overwrite a static buffer reused by <>. The third is of type <[int *]>, and matches the <[error]> argument of <<_strerror_r>>; if a non-zero value is stored into that location (usually <[EINVAL]>), then <> will set <> to that value, and the XPG variant of <> will return that value instead of zero or <[ERANGE]>. <<_user_strerror>> returns a <[char *]> value; returning <[NULL]> implies that the user function did not choose to handle <[errnum]>. The default <<_user_strerror>> returns <[NULL]> for all input values. Note that <<_user_sterror>> must be thread-safe, and only denote errors via the third argument rather than modifying <>, if <> and <> are are to comply with POSIX. <> requires no supporting OS subroutines. QUICKREF strerror ansi pure */ #define _DEFAULT_SOURCE #include #include #include "string_private.h" #include "local.h" extern char *_user_strerror(int, int, int *) __weak; char * _strerror_r(int errnum, int internal, int *errptr) { char *error; switch (errnum) { case 0: error = "Success"; break; /* go32 defines EPERM as EACCES */ #if defined(EPERM) && (!defined(EACCES) || (EPERM != EACCES)) case EPERM: error = "Not owner"; break; #endif #ifdef ENOENT case ENOENT: error = "No such file or directory"; break; #endif #ifdef ESRCH case ESRCH: error = "No such process"; break; #endif #ifdef EINTR case EINTR: error = "Interrupted system call"; break; #endif #ifdef EIO case EIO: error = "I/O error"; break; #endif /* go32 defines ENXIO as ENODEV */ #if defined(ENXIO) && (!defined(ENODEV) || (ENXIO != ENODEV)) case ENXIO: error = "No such device or address"; break; #endif #ifdef E2BIG case E2BIG: error = "Arg list too long"; break; #endif #ifdef ENOEXEC case ENOEXEC: error = "Exec format error"; break; #endif #ifdef EALREADY case EALREADY: error = "Socket already connected"; break; #endif #ifdef EBADF case EBADF: error = "Bad file number"; break; #endif #ifdef ECHILD case ECHILD: error = "No children"; break; #endif #ifdef EDESTADDRREQ case EDESTADDRREQ: error = "Destination address required"; break; #endif #ifdef EAGAIN case EAGAIN: error = "No more processes"; break; #endif #ifdef ENOMEM case ENOMEM: error = "Not enough space"; break; #endif #ifdef EACCES case EACCES: error = "Permission denied"; break; #endif #ifdef EFAULT case EFAULT: error = "Bad address"; break; #endif #ifdef ENOTBLK case ENOTBLK: error = "Block device required"; break; #endif #ifdef EBUSY case EBUSY: error = "Device or resource busy"; break; #endif #ifdef EEXIST case EEXIST: error = "File exists"; break; #endif #ifdef EXDEV case EXDEV: error = "Cross-device link"; break; #endif #ifdef ENODEV case ENODEV: error = "No such device"; break; #endif #ifdef ENOTDIR case ENOTDIR: error = "Not a directory"; break; #endif #ifdef EHOSTDOWN case EHOSTDOWN: error = "Host is down"; break; #endif #ifdef EINPROGRESS case EINPROGRESS: error = "Connection already in progress"; break; #endif #ifdef EISDIR case EISDIR: error = "Is a directory"; break; #endif #ifdef EINVAL case EINVAL: error = "Invalid argument"; break; #endif #ifdef ENETDOWN case ENETDOWN: error = "Network interface is not configured"; break; #endif #ifdef ENETRESET case ENETRESET: error = "Connection aborted by network"; break; #endif #ifdef ENFILE case ENFILE: error = "Too many open files in system"; break; #endif #ifdef EMFILE case EMFILE: error = "File descriptor value too large"; break; #endif #ifdef ENOTTY case ENOTTY: error = "Not a character device"; break; #endif #ifdef ETXTBSY case ETXTBSY: error = "Text file busy"; break; #endif #ifdef EFBIG case EFBIG: error = "File too large"; break; #endif #ifdef EHOSTUNREACH case EHOSTUNREACH: error = "Host is unreachable"; break; #endif #ifdef ENOSPC case ENOSPC: error = "No space left on device"; break; #endif #ifdef ENOTSUP case ENOTSUP: error = "Not supported"; break; #endif #ifdef ESPIPE case ESPIPE: error = "Illegal seek"; break; #endif #ifdef EROFS case EROFS: error = "Read-only file system"; break; #endif #ifdef EMLINK case EMLINK: error = "Too many links"; break; #endif #ifdef EPIPE case EPIPE: error = "Broken pipe"; break; #endif #ifdef EDOM case EDOM: error = "Mathematics argument out of domain of function"; break; #endif #ifdef ERANGE case ERANGE: error = "Result too large"; break; #endif #ifdef ENOMSG case ENOMSG: error = "No message of desired type"; break; #endif #ifdef EIDRM case EIDRM: error = "Identifier removed"; break; #endif #ifdef EILSEQ case EILSEQ: error = "Illegal byte sequence"; break; #endif #ifdef EDEADLK case EDEADLK: error = "Deadlock"; break; #endif #ifdef ENETUNREACH case ENETUNREACH: error = "Network is unreachable"; break; #endif #ifdef ENOLCK case ENOLCK: error = "No lock"; break; #endif #ifdef ENOSTR case ENOSTR: error = "Not a stream"; break; #endif #ifdef ETIME case ETIME: error = "Stream ioctl timeout"; break; #endif #ifdef ENOSR case ENOSR: error = "No stream resources"; break; #endif #ifdef ENONET case ENONET: error = "Machine is not on the network"; break; #endif #ifdef ENOPKG case ENOPKG: error = "No package"; break; #endif #ifdef EREMOTE case EREMOTE: error = "Resource is remote"; break; #endif #ifdef ENOLINK case ENOLINK: error = "Virtual circuit is gone"; break; #endif #ifdef EADV case EADV: error = "Advertise error"; break; #endif #ifdef ESRMNT case ESRMNT: error = "Srmount error"; break; #endif #ifdef ECOMM case ECOMM: error = "Communication error"; break; #endif #ifdef EPROTO case EPROTO: error = "Protocol error"; break; #endif #ifdef EPROTONOSUPPORT case EPROTONOSUPPORT: error = "Unknown protocol"; break; #endif #ifdef EMULTIHOP case EMULTIHOP: error = "Multihop attempted"; break; #endif #ifdef EBADMSG case EBADMSG: error = "Bad message"; break; #endif #ifdef ELIBACC case ELIBACC: error = "Cannot access a needed shared library"; break; #endif #ifdef ELIBBAD case ELIBBAD: error = "Accessing a corrupted shared library"; break; #endif #ifdef ELIBSCN case ELIBSCN: error = ".lib section in a.out corrupted"; break; #endif #ifdef ELIBMAX case ELIBMAX: error = "Attempting to link in more shared libraries than system limit"; break; #endif #ifdef ELIBEXEC case ELIBEXEC: error = "Cannot exec a shared library directly"; break; #endif #ifdef ENOSYS case ENOSYS: error = "Function not implemented"; break; #endif #ifdef ENMFILE case ENMFILE: error = "No more files"; break; #endif #ifdef ENOTEMPTY case ENOTEMPTY: error = "Directory not empty"; break; #endif #ifdef ENAMETOOLONG case ENAMETOOLONG: error = "File or path name too long"; break; #endif #ifdef ELOOP case ELOOP: error = "Too many symbolic links"; break; #endif #ifdef ENOBUFS case ENOBUFS: error = "No buffer space available"; break; #endif #ifdef ENODATA case ENODATA: error = "No data"; break; #endif #ifdef EAFNOSUPPORT case EAFNOSUPPORT: error = "Address family not supported by protocol family"; break; #endif #ifdef EPROTOTYPE case EPROTOTYPE: error = "Protocol wrong type for socket"; break; #endif #ifdef ENOTSOCK case ENOTSOCK: error = "Socket operation on non-socket"; break; #endif #ifdef ENOPROTOOPT case ENOPROTOOPT: error = "Protocol not available"; break; #endif #ifdef ESHUTDOWN case ESHUTDOWN: error = "Can't send after socket shutdown"; break; #endif #ifdef ECONNREFUSED case ECONNREFUSED: error = "Connection refused"; break; #endif #ifdef ECONNRESET case ECONNRESET: error = "Connection reset by peer"; break; #endif #ifdef EADDRINUSE case EADDRINUSE: error = "Address already in use"; break; #endif #ifdef EADDRNOTAVAIL case EADDRNOTAVAIL: error = "Address not available"; break; #endif #ifdef ECONNABORTED case ECONNABORTED: error = "Software caused connection abort"; break; #endif #if (defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))) case EWOULDBLOCK: error = "Operation would block"; break; #endif #ifdef ENOTCONN case ENOTCONN: error = "Socket is not connected"; break; #endif #ifdef ESOCKTNOSUPPORT case ESOCKTNOSUPPORT: error = "Socket type not supported"; break; #endif #ifdef EISCONN case EISCONN: error = "Socket is already connected"; break; #endif #ifdef ECANCELED case ECANCELED: error = "Operation canceled"; break; #endif #ifdef ENOTRECOVERABLE case ENOTRECOVERABLE: error = "State not recoverable"; break; #endif #ifdef EOWNERDEAD case EOWNERDEAD: error = "Previous owner died"; break; #endif #ifdef ESTRPIPE case ESTRPIPE: error = "Streams pipe error"; break; #endif #if defined(EOPNOTSUPP) && (!defined(ENOTSUP) || (ENOTSUP != EOPNOTSUPP)) case EOPNOTSUPP: error = "Operation not supported on socket"; break; #endif #ifdef EOVERFLOW case EOVERFLOW: error = "Value too large for defined data type"; break; #endif #ifdef EMSGSIZE case EMSGSIZE: error = "Message too long"; break; #endif #ifdef ETIMEDOUT case ETIMEDOUT: error = "Connection timed out"; break; #endif default: if (!errptr) errptr = &errno; if (&_user_strerror == NULL || (error = _user_strerror(errnum, internal, errptr)) == 0) error = ""; break; } return error; } char * strerror(int errnum) { return _strerror_r(errnum, 0, NULL); } char * strerror_l(int errnum, locale_t locale) { (void)locale; /* We don't support per-locale error messages. */ return _strerror_r(errnum, 0, NULL); } picolibc-1.8.11/libc/string/strerror_r.c000066400000000000000000000054731513574234600201770ustar00rootroot00000000000000/* Copyright (c) 2002 Jeff Johnston */ /* GNU variant of strerror_r. */ /* FUNCTION <>---convert error number to string and copy to buffer INDEX strerror_r SYNOPSIS #include #ifdef _GNU_SOURCE char *strerror_r(int <[errnum]>, char *<[buffer]>, size_t <[n]>); #else int strerror_r(int <[errnum]>, char *<[buffer]>, size_t <[n]>); #endif DESCRIPTION <> converts the error number <[errnum]> into a string and copies the result into the supplied <[buffer]> for a length up to <[n]>, including the NUL terminator. The value of <[errnum]> is usually a copy of <>. If <> is not a known error number, the result is the empty string. See <> for how strings are mapped to <>. RETURNS There are two variants: the GNU version always returns a NUL-terminated string, which is <[buffer]> if all went well, but which is another pointer if <[n]> was too small (leaving <[buffer]> untouched). If the return is not <[buffer]>, your application must not modify that string. The POSIX version returns 0 on success, <[EINVAL]> if <> was not recognized, and <[ERANGE]> if <[n]> was too small. The variant chosen depends on macros that you define before inclusion of <>. PORTABILITY <> with a <[char *]> result is a GNU extension. <> with an <[int]> result is required by POSIX 2001. This function is compliant only if <<_user_strerror>> is not provided, or if it is thread-safe and uses separate storage according to whether the second argument of that function is non-zero. For more details on <<_user_strerror>>, see the <> documentation. POSIX states that the contents of <[buf]> are unspecified on error, although this implementation guarantees a NUL-terminated string for all except <[n]> of 0. POSIX recommends that unknown <[errnum]> result in a message including that value, however it is not a requirement and this implementation provides only an empty string (unless you provide <<_user_strerror>>). POSIX also recommends that unknown <[errnum]> fail with EINVAL even when providing such a message, however it is not a requirement and this implementation will return success if <<_user_strerror>> provided a non-empty alternate string without assigning into its third argument. <> requires no supporting OS subroutines. */ #undef __STRICT_ANSI__ #define _GNU_SOURCE #include #include #include "local.h" #undef strerror_r /* For backwards-compatible linking, this must be the GNU signature; see xpg_strerror_r.c for the POSIX version. */ char * strerror_r(int errnum, char *buffer, size_t n) { char *error = _strerror_r(errnum, 1, NULL); if (strlen(error) >= n) return error; return strcpy(buffer, error); } picolibc-1.8.11/libc/string/strerror_s.c000066400000000000000000000054141513574234600201730ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define __STDC_WANT_LIB_EXT1__ 1 #include #include #include #include "string_private.h" /* C11 version; required by LLVM's C++11 library */ __errno_t strerror_s(char *buf, rsize_t buflen, __errno_t errnum) { int32_t result = 0; const char *msg = ""; if (buf == NULL) { msg = "strerror_s: dest is NULL"; goto handle_error; } if ((buflen == 0u) || (CHECK_RSIZE(buflen))) { msg = "strerror_s: dest buffer size is 0 or exceeds RSIZE_MAX"; goto handle_error; } const char *cp = _strerror_r(errnum, 0, NULL); uint32_t len = strnlen_s(cp, MAX_ERROR_MSG); if (len < buflen) { (void)strncpy(buf, cp, MAX_ERROR_MSG); } else { /* Standard allows truncation of error message with '...' to indicate truncation. */ (void)memcpy(buf, cp, (buflen - 1u)); buf[(buflen - 1u)] = '\0'; if (buflen > 3u) { (void)strncpy(&buf[(buflen - 4u)], "...", 4u); } result = ERANGE; } // Normal return path return result; handle_error: if (__cur_handler != NULL) { __cur_handler(msg, NULL, -1); } return -1; } picolibc-1.8.11/libc/string/strerrorlen_s.c000066400000000000000000000034201513574234600206650ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define __STDC_WANT_LIB_EXT1__ 1 #include #include "string_private.h" size_t strerrorlen_s(__errno_t errnum) { return strnlen_s(_strerror_r(errnum, 0, NULL), MAX_ERROR_MSG); } picolibc-1.8.11/libc/string/string_private.h000066400000000000000000000034271513574234600210360ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef STRING_PRIVATE_H_ #define STRING_PRIVATE_H_ #include "../stdlib/local_s.h" #define MAX_ERROR_MSG 100 char *_strerror_r(int errnum, int internal, int *errptr); #endif // STRING_PRIVATE_H_ picolibc-1.8.11/libc/string/strings.tex000066400000000000000000000122621513574234600200350ustar00rootroot00000000000000# #Copyright (c) 1994 Cygnus Support. #All rights reserved. # #Redistribution and use in source and binary forms are permitted #provided that the above copyright notice and this paragraph are #duplicated in all such forms and that any documentation, #and/or other materials related to such #distribution and use acknowledge that the software was developed #at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to #endorse or promote products derived from this software without #specific prior written permission. #THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR #IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED #WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # @node Strings @chapter Strings and Memory (@file{string.h}) This chapter describes string-handling functions and functions for managing areas of memory. The corresponding declarations are in @file{string.h}. @menu * Function bcmp:: Compare two memory areas * Function bcopy:: Copy memory regions * Function bzero:: Initialize memory to zero * Function index:: Search for character in string * Function memccpy:: Copy memory regions up to end-token * Function memchr:: Find character in memory * Function memcmp:: Compare two memory areas * Function memcpy:: Copy memory regions * Function memmem:: Find memory segment * Function memmove:: Move possibly overlapping memory * Function mempcpy:: Copy memory regions and locate end * Function memrchr:: Reverse search for character in memory * Function memset:: Set an area of memory * Function rawmemchr:: Find character in memory * Function rindex:: Reverse search for character in string * Function stpcpy:: Copy string returning a pointer to its end * Function stpncpy:: Counted copy string returning a pointer to its end * Function strcasecmp:: Compare strings ignoring case * Function strcasestr:: Find string segment ignoring case * Function strcat:: Concatenate strings * Function strchr:: Search for character in string * Function strchrnul:: Search for character in string * Function strcmp:: Character string compare * Function strcoll:: Locale-specific character string compare * Function strcpy:: Copy string * Function strcspn:: Count chars not in string * Function strerror:: Convert error number to string (strerror, strerror_l) * Function strerror_r:: Convert error number to string * Function strlen:: Character string length * Function strlwr:: Convert string to lowercase * Function strncasecmp:: Compare strings ignoring case * Function strncat:: Concatenate strings * Function strncmp:: Character string compare * Function strncpy:: Counted copy string * Function strnstr:: Find string segment * Function strnlen:: Character string length * Function strpbrk:: Find chars in string * Function strrchr:: Reverse search for character in string * Function strsignal:: Return signal message string * Function strspn:: Find initial match * Function strstr:: Find string segment * Function strtok:: Get next token from a string * Function strupr:: Convert string to upper case * Function strverscmp:: Compare version strings * Function strxfrm:: Transform string * Function swab:: Swap adjacent bytes * Function wcscasecmp:: Compare wide character strings ignoring case * Function wcsdup:: Wide character string duplicate * Function wcsncasecmp:: Compare wide character strings ignoring case @end menu @page @include string/bcmp.def @page @include string/bcopy.def @page @include string/bzero.def @page @include string/index.def @page @include string/memccpy.def @page @include string/memchr.def @page @include string/memcmp.def @page @include string/memcpy.def @page @include string/memmem.def @page @include string/memmove.def @page @include string/mempcpy.def @page @include string/memrchr.def @page @include string/memset.def @page @include string/rawmemchr.def @page @include string/rindex.def @page @include string/stpcpy.def @page @include string/stpncpy.def @page @include string/strcasecmp.def @page @include string/strcasestr.def @page @include string/strcat.def @page @include string/strchr.def @page @include string/strchrnul.def @page @include string/strcmp.def @page @include string/strcoll.def @page @include string/strcpy.def @page @include string/strcspn.def @page @include string/strerror.def @page @include string/strerror_r.def @page @include string/strlen.def @page @include string/strlwr.def @page @include string/strncasecmp.def @page @include string/strncat.def @page @include string/strncmp.def @page @include string/strncpy.def @page @include string/strnstr.def @page @include string/strnlen.def @page @include string/strpbrk.def @page @include string/strrchr.def @page @include string/strsignal.def @page @include string/strspn.def @page @include string/strstr.def @page @include string/strtok.def @page @include string/strupr.def @page @include string/strverscmp.def @page @include string/strxfrm.def @page @include string/swab.def @page @include string/wcscasecmp.def @page @include string/wcsdup.def @page @include string/wcsncasecmp.def picolibc-1.8.11/libc/string/strlcat.c000066400000000000000000000035171513574234600174450ustar00rootroot00000000000000/* $OpenBSD: strlcat.c,v 1.19 2019/01/25 00:19:25 millert Exp $ */ /* * Copyright (c) 1998, 2015 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #define _DEFAULT_SOURCE #include #include /* * Appends src to string dst of size dsize (unlike strncat, dsize is the * full size of dst, not space left). At most dsize-1 characters * will be copied. Always NUL terminates (unless dsize <= strlen(dst)). * Returns strlen(src) + MIN(dsize, strlen(initial dst)). * If retval >= dsize, truncation occurred. */ size_t strlcat(char *dst, const char *src, size_t dsize) { const char *odst = dst; const char *osrc = src; size_t n = dsize; size_t dlen; /* Find the end of dst and adjust bytes left but don't go past end. */ while (n-- != 0 && *dst != '\0') dst++; dlen = dst - odst; n = dsize - dlen; if (n-- == 0) return (dlen + strlen(src)); while (*src != '\0') { if (n != 0) { *dst++ = *src; n--; } src++; } *dst = '\0'; return (dlen + (src - osrc)); /* count does not include NUL */ } picolibc-1.8.11/libc/string/strlcpy.c000066400000000000000000000032701513574234600174650ustar00rootroot00000000000000/* $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $ */ /* * Copyright (c) 1998, 2015 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #define _DEFAULT_SOURCE #include #include /* * Copy string src to buffer dst of size dsize. At most dsize-1 * chars will be copied. Always NUL terminates (unless dsize == 0). * Returns strlen(src); if retval >= dsize, truncation occurred. */ size_t strlcpy(char *dst, const char *src, size_t dsize) { const char *osrc = src; size_t nleft = dsize; /* Copy as many bytes as will fit. */ if (nleft != 0) { while (--nleft != 0) { if ((*dst++ = *src++) == '\0') break; } } /* Not enough room in dst, add NUL and traverse rest of src. */ if (nleft == 0) { if (dsize != 0) *dst = '\0'; /* NUL-terminate dst */ while (*src++) ; } return (src - osrc - 1); /* count does not include NUL */ } picolibc-1.8.11/libc/string/strlen.c000066400000000000000000000041511513574234600172730ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---character string length INDEX strlen SYNOPSIS #include size_t strlen(const char *<[str]>); DESCRIPTION The <> function works out the length of the string starting at <<*<[str]>>> by counting chararacters until it reaches a <> character. RETURNS <> returns the character count. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF strlen ansi pure */ #include #include #include "local.h" size_t strlen(const char *str) { const char *start = str; #if !defined(__PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) \ && !defined(_PICOLIBC_NO_OUT_OF_BOUNDS_READS) unsigned long *aligned_addr; /* Align the pointer, so we can search a word at a time. */ while (UNALIGNED_X(str)) { if (!*str) return str - start; str++; } /* If the string is word-aligned, we can check for the presence of a null in each word-sized block. */ aligned_addr = (unsigned long *)str; while (!DETECT_NULL(*aligned_addr)) aligned_addr++; /* Once a null is detected, we check each byte in that block for a precise position of the null. */ str = (char *)aligned_addr; #endif /* not __PREFER_SIZE_OVER_SPEED */ while (*str) str++; return str - start; } picolibc-1.8.11/libc/string/strlwr.c000066400000000000000000000025321513574234600173220ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---force string to lowercase INDEX strlwr SYNOPSIS #include char *strlwr(char *<[a]>); DESCRIPTION <> converts each character in the string at <[a]> to lowercase. RETURNS <> returns its argument, <[a]>. PORTABILITY <> is not widely portable. <> requires no supporting OS subroutines. QUICKREF strlwr */ #define _DEFAULT_SOURCE #include #include char * strlwr(char *s) { unsigned char *ucs = (unsigned char *)s; for (; *ucs != '\0'; ucs++) { *ucs = tolower(*ucs); } return s; } picolibc-1.8.11/libc/string/strncasecmp.c000066400000000000000000000037721513574234600203160ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---case-insensitive character string compare INDEX strncasecmp SYNOPSIS #include int strncasecmp(const char *<[a]>, const char * <[b]>, size_t <[length]>); DESCRIPTION <> compares up to <[length]> characters from the string at <[a]> to the string at <[b]> in a case-insensitive manner. RETURNS If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after both are converted to lowercase), <> returns a number greater than zero. If the two strings are equivalent, <> returns zero. If <<*<[a]>>> sorts lexicographically before <<*<[b]>>>, <> returns a number less than zero. PORTABILITY <> is in the Berkeley Software Distribution. <> requires no supporting OS subroutines. It uses tolower() from elsewhere in this library. QUICKREF strncasecmp */ #include #include int strncasecmp(const char *s1, const char *s2, size_t n) { int d = 0; for (; n != 0; n--) { const int c1 = tolower(*(unsigned char *)s1++); const int c2 = tolower(*(unsigned char *)s2++); if (((d = c1 - c2) != 0) || (c2 == '\0')) break; } return d; } picolibc-1.8.11/libc/string/strncasecmp_l.c000066400000000000000000000031151513574234600206200ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen */ /* FUNCTION <>---case-insensitive character string compare INDEX strncasecmp_l SYNOPSIS #include int strncasecmp_l(const char *<[a]>, const char * <[b]>, size_t <[length]>, locale_t <[locale]>); DESCRIPTION <> compares up to <[length]> characters from the string at <[a]> to the string at <[b]> in a case-insensitive manner. if <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after both are converted to lowercase), <> returns a number greater than zero. If the two strings are equivalent, <> returns zero. If <<*<[a]>>> sorts lexicographically before <<*<[b]>>>, <> returns a number less than zero. PORTABILITY <> is POSIX-1.2008. <> requires no supporting OS subroutines. It uses tolower_l() from elsewhere in this library. QUICKREF strncasecmp_l */ #define _DEFAULT_SOURCE #include #include int strncasecmp_l(const char *s1, const char *s2, size_t n, locale_t locale) { int d = 0; for (; n != 0; n--) { const int c1 = tolower_l(*(unsigned char *)s1++, locale); const int c2 = tolower_l(*(unsigned char *)s2++, locale); if (((d = c1 - c2) != 0) || (c2 == '\0')) break; } return d; } picolibc-1.8.11/libc/string/strncat.c000066400000000000000000000057121513574234600174460ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---concatenate strings INDEX strncat SYNOPSIS #include char *strncat(char *restrict <[dst]>, const char *restrict <[src]>, size_t <[length]>); DESCRIPTION <> appends not more than <[length]> characters from the string pointed to by <[src]> (including the terminating null character) to the end of the string pointed to by <[dst]>. The initial character of <[src]> overwrites the null character at the end of <[dst]>. A terminating null character is always appended to the result WARNINGS Note that a null is always appended, so that if the copy is limited by the <[length]> argument, the number of characters appended to <[dst]> is <>. RETURNS This function returns the initial value of <[dst]> PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF strncat ansi pure */ #include #include #include "local.h" #undef strncat char * strncat(char * __restrict s1, const char * __restrict s2, size_t n) { #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) \ || defined(_PICOLIBC_NO_OUT_OF_BOUNDS_READS) char *s = s1; while (*s1) s1++; while (n-- != 0 && (*s1++ = *s2++)) { if (n == 0) *s1 = '\0'; } return s; #else char *s = s1; /* Skip unaligned memory in s1. */ while (UNALIGNED_X(s1) && *s1) s1++; if (*s1) { /* Skip over the aligned data in s1 as quickly as possible. */ unsigned long *aligned_s1 = (unsigned long *)s1; while (!DETECT_NULL(*aligned_s1)) aligned_s1++; s1 = (char *)aligned_s1; /* Find string terminator. */ while (*s1) s1++; } /* s1 now points to the its trailing null character, now copy up to N bytes from S2 into S1 stopping if a NULL is encountered in S2. It is not safe to use strncpy here since it copies EXACTLY N characters, NULL padding if necessary. */ while (n-- != 0 && (*s1++ = *s2++)) { if (n == 0) *s1 = '\0'; } return s; #endif /* not __PREFER_SIZE_OVER_SPEED */ } picolibc-1.8.11/libc/string/strncat_s.c000066400000000000000000000130441513574234600177650ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define __STDC_WANT_LIB_EXT1__ 1 #include #include #include "string_private.h" __errno_t strncat_s(char * __restrict s1, rsize_t s1max, const char * __restrict s2, rsize_t n) { const char *msg = ""; size_t s1_len = 0; bool write_null = true; s1_len = strnlen_s(s1, s1max); if (s1 == NULL) { msg = "strncat_s: dest is NULL"; write_null = false; goto handle_error; } else if ((s1max == 0u) || (CHECK_RSIZE(s1max))) { msg = "strncat_s: dest buffer size is 0 or exceeds RSIZE_MAX"; write_null = false; goto handle_error; } else if (s2 == NULL) { msg = "strncat_s: source is NULL"; goto handle_error; } else if (CHECK_RSIZE(n)) { msg = "strncat_s: copy count exceeds RSIZE_MAX"; goto handle_error; } /* It is a constraint violation if s1max is not large enough to contain * the concatenation of s2. * It is also a constraint violation if the string pointed to by s2 * overlaps s1 in any way. * The C11 Rationale says we are permitted to proceed with the copy and * detect dest buffer overrun and overlapping memory blocks as a byproduct * of performing the copy operation. This is to avoid calling strlen on * s2 to detect these violations prior to attempting the copy. */ // compute chars available in s1 else if (s1_len == s1max) { msg = "strncat_s: string 1 length exceeds buffer size"; goto handle_error; } else { // compute chars available in s1 uint32_t m = (s1max - s1_len); uint32_t i = 0; char *s1cp = s1; for (i = 0u; i < s1_len; i++) { s1cp++; } // Question; at this point should we just return // strncpy_s(s1cp, m, s2, n) ? // perhaps not since overlap check needs to be over entire s1 vs. s2? const char *overlap_point; bool check_s1_for_overlap; const char *s2cp = s2; if (s1 <= s2) { // if we ever reach s2 when storing to s1 we have overlap overlap_point = s2; check_s1_for_overlap = true; // make sure source does not lie within initial dest string. if (s2 <= s1cp) { msg = "strncat_s: overlapping copy"; goto handle_error; } } else { // if we ever reach s1 when reading from s2 we have overlap overlap_point = s1; check_s1_for_overlap = false; } uint32_t written = 0; char c = '.'; while ((written < m) && (written < n)) { if (check_s1_for_overlap == true) { if (s1cp == overlap_point) { msg = "strncat_s: overlapping copy"; goto handle_error; } } else if (s2cp == overlap_point) { msg = "strncat_s: overlapping copy"; goto handle_error; } else { /* Normal case*/ } c = *s2cp; s2cp++; *s1cp = c; s1cp++; written++; if (c == '\0') { break; } } if ((c != '\0') && (written == n) && (written < m)) { // we copied n chars from s2 and there is room for null char in s1 if ((check_s1_for_overlap == true) && (s1cp == overlap_point)) { msg = "strncat_s: overlapping copy"; goto handle_error; } else { c = '\0'; *s1cp = '\0'; } } if (c != '\0') { msg = "strncat_s: dest buffer size insufficent to copy string"; goto handle_error; } } // Normal return path return 0; handle_error: if (write_null && s1 != NULL) { *s1 = '\0'; } if (__cur_handler != NULL) { __cur_handler(msg, NULL, -1); } return -1; } picolibc-1.8.11/libc/string/strncmp.c000066400000000000000000000057731513574234600174650ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---character string compare INDEX strncmp SYNOPSIS #include int strncmp(const char *<[a]>, const char * <[b]>, size_t <[length]>); DESCRIPTION <> compares up to <[length]> characters from the string at <[a]> to the string at <[b]>. RETURNS If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>, <> returns a number greater than zero. If the two strings are equivalent, <> returns zero. If <<*<[a]>>> sorts lexicographically before <<*<[b]>>>, <> returns a number less than zero. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF strncmp ansi pure */ #include #include #include "local.h" int strncmp(const char *s1, const char *s2, size_t n) { #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) \ || defined(_PICOLIBC_NO_OUT_OF_BOUNDS_READS) if (n == 0) return 0; while (n-- != 0 && *s1 == *s2) { if (n == 0 || *s1 == '\0') break; s1++; s2++; } return (*(unsigned char *)s1) - (*(unsigned char *)s2); #else unsigned long *a1; unsigned long *a2; if (n == 0) return 0; /* If s1 or s2 are unaligned, then compare bytes. */ if (!UNALIGNED_X_Y(s1, s2)) { /* If s1 and s2 are word-aligned, compare them a word at a time. */ a1 = (unsigned long *)s1; a2 = (unsigned long *)s2; while (n >= sizeof(long) && *a1 == *a2) { n -= sizeof(long); /* If we've run out of bytes or hit a null, return zero since we already know *a1 == *a2. */ if (n == 0 || DETECT_NULL(*a1)) return 0; a1++; a2++; } /* A difference was detected in last few bytes of s1, so search bytewise */ s1 = (char *)a1; s2 = (char *)a2; } while (n-- > 0 && *s1 == *s2) { /* If we've run out of bytes or hit a null, return zero since we already know *s1 == *s2. */ if (n == 0 || *s1 == '\0') return 0; s1++; s2++; } return (*(unsigned char *)s1) - (*(unsigned char *)s2); #endif /* not __PREFER_SIZE_OVER_SPEED */ } picolibc-1.8.11/libc/string/strncpy.c000066400000000000000000000057551513574234600175010ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---counted copy string INDEX strncpy SYNOPSIS #include char *strncpy(char *restrict <[dst]>, const char *restrict <[src]>, size_t <[length]>); DESCRIPTION <> copies not more than <[length]> characters from the string pointed to by <[src]> (including the terminating null character) to the array pointed to by <[dst]>. If the string pointed to by <[src]> is shorter than <[length]> characters, null characters are appended to the destination array until a total of <[length]> characters have been written. RETURNS This function returns the initial value of <[dst]>. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF strncpy ansi pure */ #include #include #include "local.h" /*SUPPRESS 560*/ /*SUPPRESS 530*/ #undef strncpy char * strncpy(char * __restrict dst0, const char * __restrict src0, size_t count) { #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) \ || defined(_PICOLIBC_NO_OUT_OF_BOUNDS_READS) char *dscan; const char *sscan; dscan = dst0; sscan = src0; while (count > 0) { --count; if ((*dscan++ = *sscan++) == '\0') break; } while (count-- > 0) *dscan++ = '\0'; return dst0; #else char *dst = dst0; const char *src = src0; long *aligned_dst; const long *aligned_src; /* If SRC and DEST is aligned and count large enough, then copy words. */ if (!UNALIGNED_X_Y(src, dst) && !TOO_SMALL_LITTLE_BLOCK(count)) { aligned_dst = (long *)dst; aligned_src = (long *)src; /* SRC and DEST are both "long int" aligned, try to do "long int" sized copies. */ while (!TOO_SMALL_LITTLE_BLOCK(count) && !DETECT_NULL(*aligned_src)) { count -= sizeof(long int); *aligned_dst++ = *aligned_src++; } dst = (char *)aligned_dst; src = (char *)aligned_src; } while (count > 0) { --count; if ((*dst++ = *src++) == '\0') break; } while (count-- > 0) *dst++ = '\0'; return dst0; #endif /* not __PREFER_SIZE_OVER_SPEED */ } picolibc-1.8.11/libc/string/strncpy_s.c000066400000000000000000000115011513574234600200050ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define __STDC_WANT_LIB_EXT1__ 1 #include #include #include "string_private.h" __errno_t strncpy_s(char * __restrict s1, rsize_t s1max, const char * __restrict s2, rsize_t n) { const char *msg = ""; bool write_null = true; if (s1 == NULL) { msg = "strncpy_s: dest is NULL"; write_null = false; goto handle_error; } else if ((s1max == 0u) || (CHECK_RSIZE(s1max))) { msg = "strncpy_s: dest buffer size is 0 or exceeds RSIZE_MAX"; write_null = false; goto handle_error; } else if (s2 == NULL) { msg = "strncpy_s: source is NULL"; goto handle_error; } else if (CHECK_RSIZE(n)) { msg = "strncpy_s: copy count exceeds RSIZE_MAX"; goto handle_error; } /* It is a constraint violation if s1max is not large enough to contain * a copy of s2 (with n as upper bound on chars copied). * It is also a constraint violation if the string pointed to by s2 * overlaps s1 in any way. * The C11 Rationale says we are permitted to proceed with the copy and * detect dest buffer overrun and overlapping memory blocks as a byproduct * of performing the copy operation. This is to avoid calling strlen on * s2 to detect these violations prior to attempting the copy. */ else { const char *overlap_point; bool check_s1_for_overlap; char *s1cp = s1; const char *s2cp = s2; if (s1 < s2) { // if we ever reach s2 when storing to s1 we have overlap overlap_point = s2; check_s1_for_overlap = true; } else { // if we ever reach s1 when reading from s2 we have overlap overlap_point = s1; check_s1_for_overlap = false; } uint32_t written = 0; char c = '.'; while ((written < s1max) && (written < n)) { if (check_s1_for_overlap == true) { if (s1cp == overlap_point) { msg = "strncpy_s: overlapping copy"; goto handle_error; } } else if (s2cp == overlap_point) { msg = "strncpy_s: overlapping copy"; goto handle_error; } else { /* Normal case*/ } c = *s2cp; s2cp++; *s1cp = c; s1cp++; written++; if (c == '\0') { break; } } if ((c != '\0') && (written == n) && (written < s1max)) { // we copied n chars from s2 and there is room for null char in s1 if ((check_s1_for_overlap == true) && (s1cp == overlap_point)) { msg = "strncpy_s: overlapping copy"; goto handle_error; } else { c = '\0'; *s1cp = '\0'; } } if (c != '\0') { msg = "strncpy_s: dest buffer size insufficent to copy string"; goto handle_error; } } // Normal return path return 0; handle_error: if (write_null && s1 != NULL) { *s1 = '\0'; } if (__cur_handler != NULL) { __cur_handler(msg, NULL, -1); } return -1; } picolibc-1.8.11/libc/string/strndup.c000066400000000000000000000006641513574234600174700ustar00rootroot00000000000000/* Copyright (c) 2002 Jeff Johnston */ #define _DEFAULT_SOURCE #include #include char * strndup(const char *str, size_t n) { const char *ptr = str; size_t len; char *copy; while (n-- > 0 && *ptr) ptr++; len = ptr - str; copy = malloc(len + 1); if (copy) { memcpy(copy, str, len); copy[len] = '\0'; } return copy; } picolibc-1.8.11/libc/string/strnlen.c000066400000000000000000000015201513574234600174460ustar00rootroot00000000000000/* Copyright (c) 2002 Jeff Johnston */ /* FUNCTION <>---character string length INDEX strnlen SYNOPSIS #include size_t strnlen(const char *<[str]>, size_t <[n]>); DESCRIPTION The <> function works out the length of the string starting at <<*<[str]>>> by counting chararacters until it reaches a NUL character or the maximum: <[n]> number of characters have been inspected. RETURNS <> returns the character count or <[n]>. PORTABILITY <> is a GNU extension. <> requires no supporting OS subroutines. */ #undef __STRICT_ANSI__ #include size_t strnlen(const char *str, size_t n) { const char *start = str; while (n-- > 0 && *str) str++; return str - start; } picolibc-1.8.11/libc/string/strnlen_s.c000066400000000000000000000041441513574234600177750ustar00rootroot00000000000000/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright © 2024, Synopsys Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #define __STDC_WANT_LIB_EXT1__ 1 #include #include #include "string_private.h" size_t strnlen_s(const char *s, size_t maxsize) { const void *s_end; size_t rtn = 0; if (s == NULL) { rtn = 0; } else { s_end = memchr((const void *)s, (int)'\0', maxsize); if (s_end == NULL) { rtn = maxsize; } else { ptrdiff_t s_size; s_size = (const char *)s_end - s; rtn = (size_t)s_size; } } return rtn; } picolibc-1.8.11/libc/string/strnstr.c000066400000000000000000000024201513574234600175000ustar00rootroot00000000000000/* Copyright (c) 2017 Sichen Zhao <1473996754@qq.com> */ /* FUNCTION <>---find string segment INDEX strnstr SYNOPSIS #include size_t strnstr(const char *<[s1]>, const char *<[s2]>, size_t <[n]>); DESCRIPTION Locates the first occurrence in the string pointed to by <[s1]> of the sequence of limited to the <[n]> characters in the string pointed to by <[s2]> RETURNS Returns a pointer to the located string segment, or a null pointer if the string <[s2]> is not found. If <[s2]> points to a string with zero length, <[s1]> is returned. PORTABILITY <> is a BSD extension. <> requires no supporting OS subroutines. QUICKREF strnstr pure */ #define _GNU_SOURCE #include /* * Find the first occurrence of find in s, where the search is limited to the * first slen characters of s. */ char * strnstr(const char *haystack, const char *needle, size_t haystack_len) { size_t needle_len = strnlen(needle, haystack_len); if (needle_len < haystack_len || !needle[needle_len]) { char *x = memmem(haystack, haystack_len, needle, needle_len); if (x && !memchr(haystack, 0, x - haystack)) return x; } return NULL; } picolibc-1.8.11/libc/string/strpbrk.c000066400000000000000000000030621513574234600174530ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---find characters in string INDEX strpbrk SYNOPSIS #include char *strpbrk(const char *<[s1]>, const char *<[s2]>); DESCRIPTION This function locates the first occurence in the string pointed to by <[s1]> of any character in string pointed to by <[s2]> (excluding the terminating null character). RETURNS <> returns a pointer to the character found in <[s1]>, or a null pointer if no character from <[s2]> occurs in <[s1]>. PORTABILITY <> requires no supporting OS subroutines. */ #include char * strpbrk(const char *s1, const char *s2) { const char *c = s2; while (*s1) { for (c = s2; *c; c++) { if (*s1 == *c) return (char *)s1; } s1++; } return (char *)NULL; } picolibc-1.8.11/libc/string/strrchr.c000066400000000000000000000031431513574234600174530ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---reverse search for character in string INDEX strrchr SYNOPSIS #include char * strrchr(const char *<[string]>, int <[c]>); DESCRIPTION This function finds the last occurence of <[c]> (converted to a char) in the string pointed to by <[string]> (including the terminating null character). RETURNS Returns a pointer to the located character, or a null pointer if <[c]> does not occur in <[string]>. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF strrchr ansi pure */ #include char * strrchr(const char *s, int i) { const char *last = NULL; char c = i; if (c) { while ((s = strchr(s, c))) { last = s; s++; } } else { last = strchr(s, c); } return (char *)last; } picolibc-1.8.11/libc/string/strsep.c000066400000000000000000000004061513574234600173030ustar00rootroot00000000000000/* BSD strsep function */ /* Copyright 2002, Red Hat Inc. */ #define _DEFAULT_SOURCE #include #include "strtok_r.h" char * strsep(register char **source_ptr, register const char *delim) { return __strtok_r(*source_ptr, delim, source_ptr, 0); } picolibc-1.8.11/libc/string/strsignal.c000066400000000000000000000117351513574234600200000ustar00rootroot00000000000000/* FUNCTION <>---convert signal number to string INDEX strsignal SYNOPSIS #include char *strsignal(int <[signal]>); DESCRIPTION <> converts the signal number <[signal]> into a string. If <[signal]> is not a known signal number, the result will be of the form "Unknown signal NN" where NN is the <[signal]> is a decimal number. RETURNS This function returns a pointer to a string. Your application must not modify that string. PORTABILITY POSIX.1-2008 C requires <>, but does not specify the strings used for each signal number. <> requires no supporting OS subroutines. QUICKREF strsignal pure */ /* * Written by Joel Sherrill . * * COPYRIGHT (c) 2010, 2017. * On-Line Applications Research Corporation (OAR). * * Permission to use, copy, modify, and distribute this software for any * purpose without fee is hereby granted, provided that this entire notice * is included in all copies of any software which is or includes a copy * or modification of this software. * * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED * WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION * OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS * SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. */ #define _DEFAULT_SOURCE #include #include #include #include char * strsignal(int signal) { char *buffer; static __THREAD_LOCAL char _signal_buf[24]; buffer = _signal_buf; #if defined(SIGRTMIN) && defined(SIGRTMAX) if ((signal >= SIGRTMIN) && (signal <= SIGRTMAX)) { sprintf(buffer, "Real-time signal %d", signal - SIGRTMIN); return buffer; } #endif switch (signal) { #ifdef SIGHUP case SIGHUP: buffer = "Hangup"; break; #endif #ifdef SIGINT case SIGINT: buffer = "Interrupt"; break; #endif #ifdef SIGQUIT case SIGQUIT: buffer = "Quit"; break; #endif #ifdef SIGILL case SIGILL: buffer = "Illegal instruction"; break; #endif #ifdef SIGTRAP case SIGTRAP: buffer = "Trace/breakpoint trap"; break; #endif #ifdef SIGIOT #if defined(SIGABRT) && (SIGIOT != SIGABRT) case SIGABRT: #endif case SIGIOT: buffer = "IOT trap"; break; #endif #ifdef SIGEMT case SIGEMT: buffer = "EMT trap"; break; #endif #ifdef SIGFPE case SIGFPE: buffer = "Floating point exception"; break; #endif #ifdef SIGKILL case SIGKILL: buffer = "Killed"; break; #endif #ifdef SIGBUS case SIGBUS: buffer = "Bus error"; break; #endif #ifdef SIGSEGV case SIGSEGV: buffer = "Segmentation fault"; break; #endif #ifdef SIGSYS case SIGSYS: buffer = "Bad system call"; break; #endif #ifdef SIGPIPE case SIGPIPE: buffer = "Broken pipe"; break; #endif #ifdef SIGALRM case SIGALRM: buffer = "Alarm clock"; break; #endif #ifdef SIGTERM case SIGTERM: buffer = "Terminated"; break; #endif #ifdef SIGURG case SIGURG: buffer = "Urgent I/O condition"; break; #endif #ifdef SIGSTOP case SIGSTOP: buffer = "Stopped (signal)"; break; #endif #ifdef SIGTSTP case SIGTSTP: buffer = "Stopped"; break; #endif #ifdef SIGCONT case SIGCONT: buffer = "Continued"; break; #endif #ifdef SIGCHLD #if defined(SIGCLD) && (SIGCHLD != SIGCLD) case SIGCLD: #endif case SIGCHLD: buffer = "Child exited"; break; #endif #ifdef SIGTTIN case SIGTTIN: buffer = "Stopped (tty input)"; break; #endif #ifdef SIGTTOUT case SIGTTOUT: buffer = "Stopped (tty output)"; break; #endif #ifdef SIGIO #if defined(SIGPOLL) && (SIGIO != SIGPOLL) case SIGPOLL: #endif case SIGIO: buffer = "I/O possible"; break; #endif #ifdef SIGWINCH case SIGWINCH: buffer = "Window changed"; break; #endif #ifdef SIGUSR1 case SIGUSR1: buffer = "User defined signal 1"; break; #endif #ifdef SIGUSR2 case SIGUSR2: buffer = "User defined signal 2"; break; #endif #ifdef SIGPWR case SIGPWR: buffer = "Power Failure"; break; #endif #ifdef SIGXCPU case SIGXCPU: buffer = "CPU time limit exceeded"; break; #endif #ifdef SIGXFSZ case SIGXFSZ: buffer = "File size limit exceeded"; break; #endif #ifdef SIGVTALRM case SIGVTALRM: buffer = "Virtual timer expired"; break; #endif #ifdef SIGPROF case SIGPROF: buffer = "Profiling timer expired"; break; #endif #if defined(SIGLOST) && SIGLOST != SIGPWR case SIGLOST: buffer = "Resource lost"; break; #endif default: sprintf(buffer, "Unknown signal %d", signal); break; } return buffer; } picolibc-1.8.11/libc/string/strspn.c000066400000000000000000000031731513574234600173200ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---find initial match INDEX strspn SYNOPSIS #include size_t strspn(const char *<[s1]>, const char *<[s2]>); DESCRIPTION This function computes the length of the initial segment of the string pointed to by <[s1]> which consists entirely of characters from the string pointed to by <[s2]> (excluding the terminating null character). RETURNS <> returns the length of the segment found. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF strspn ansi pure */ #include size_t strspn(const char *s1, const char *s2) { const char *s = s1; const char *c; while (*s1) { for (c = s2; *c; c++) { if (*s1 == *c) goto found; } if (*c == '\0') break; found: s1++; } return s1 - s; } picolibc-1.8.11/libc/string/strstr.c000066400000000000000000000166241513574234600173350ustar00rootroot00000000000000/* Optimized strstr function. Copyright (c) 2018 Arm Ltd. All rights reserved. SPDX-License-Identifier: BSD-3-Clause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the company may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---find string segment INDEX strstr SYNOPSIS #include char *strstr(const char *<[s1]>, const char *<[s2]>); DESCRIPTION Locates the first occurrence in the string pointed to by <[s1]> of the sequence of characters in the string pointed to by <[s2]> (excluding the terminating null character). RETURNS Returns a pointer to the located string segment, or a null pointer if the string <[s2]> is not found. If <[s2]> points to a string with zero length, <[s1]> is returned. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF strstr ansi pure */ #define _DEFAULT_SOURCE #include #include #if defined(__PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) || CHAR_BIT > 8 /* Small and efficient strstr implementation. */ char * strstr(const char *hs, const char *ne) { size_t i; int c = ne[0]; if (c == 0) return (char *)hs; for (; hs[0] != '\0'; hs++) { if (hs[0] != c) continue; for (i = 1; ne[i] != 0; i++) if (hs[i] != ne[i]) break; if (ne[i] == '\0') return (char *)hs; } return NULL; } #else /* compilation for speed */ #define RETURN_TYPE char * #define AVAILABLE(h, h_l, j, n_l) \ (((j) <= (h_l) - (n_l)) \ || ((h_l) += strnlen((const char *)(h) + (h_l), (n_l) | 2048), ((j) <= (h_l) - (n_l)))) #include "str-two-way.h" /* Number of bits used to index shift table. */ #define SHIFT_TABLE_BITS 6 static inline char * strstr2(const unsigned char *hs, const unsigned char *ne) { uint32_t h1 = ((uint32_t)ne[0] << 16) | ne[1]; uint32_t h2 = 0; int c; for (c = hs[0]; h1 != h2 && c != 0; c = *++hs) h2 = (h2 << 16) | c; return h1 == h2 ? (char *)hs - 2 : NULL; } static inline char * strstr3(const unsigned char *hs, const unsigned char *ne) { uint32_t h1 = ((uint32_t)ne[0] << 24) | ((uint32_t)ne[1] << 16) | ((uint32_t)ne[2] << 8); uint32_t h2 = 0; int c; for (c = hs[0]; h1 != h2 && c != 0; c = *++hs) h2 = (h2 | c) << 8; return h1 == h2 ? (char *)hs - 3 : NULL; } static inline char * strstr4(const unsigned char *hs, const unsigned char *ne) { uint32_t h1 = ((uint32_t)ne[0] << 24) | ((uint32_t)ne[1] << 16) | ((uint32_t)ne[2] << 8) | ne[3]; uint32_t h2 = 0; int c; for (c = hs[0]; c != 0 && h1 != h2; c = *++hs) h2 = (h2 << 8) | c; return h1 == h2 ? (char *)hs - 4 : NULL; } /* Extremely fast strstr algorithm with guaranteed linear-time performance. Small needles up to size 4 use a dedicated linear search. Longer needles up to size 254 use Sunday's Quick-Search algorithm. Due to its simplicity it has the best average performance of string matching algorithms on almost all inputs. It uses a bad-character shift table to skip past mismatches. By limiting the needle length to 254, the shift table can be reduced to 8 bits per entry, lowering preprocessing overhead and minimizing cache effects. The limit also implies the worst-case performance is linear. Even larger needles are processed by the linear-time Two-Way algorithm. */ char * strstr(const char *haystack, const char *needle) { const unsigned char *hs = (const unsigned char *)haystack; const unsigned char *ne = (const unsigned char *)needle; size_t i; /* Handle short needle special cases first. */ if (ne[0] == '\0') return (char *)hs; if (ne[1] == '\0') return (char *)strchr((const char *)hs, (char)ne[0]); if (ne[2] == '\0') return strstr2(hs, ne); if (ne[3] == '\0') return strstr3(hs, ne); if (ne[4] == '\0') return strstr4(hs, ne); size_t ne_len = strlen((const char *)ne); size_t hs_len = strnlen((const char *)hs, ne_len | 512); /* Ensure haystack length is >= needle length. */ if (hs_len < ne_len) return NULL; /* Use the Quick-Search algorithm for needle lengths less than 255. */ if (__builtin_expect(ne_len < 255, 1)) { uint8_t shift[1 << SHIFT_TABLE_BITS]; const unsigned char *end = hs + hs_len - ne_len; /* Initialize bad character shift hash table. */ memset(shift, ne_len + 1, sizeof(shift)); for (i = 0; i < ne_len; i++) shift[ne[i] % sizeof(shift)] = ne_len - i; do { hs--; /* Search by skipping past bad characters. */ size_t tmp = shift[hs[ne_len] % sizeof(shift)]; for (hs += tmp; hs <= end; hs += tmp) { tmp = shift[hs[ne_len] % sizeof(shift)]; if (memcmp(hs, ne, ne_len) == 0) return (char *)hs; } if (end[ne_len] == 0) return NULL; end += strnlen((const char *)(end + ne_len), 2048); } while (hs <= end); return NULL; } /* Use Two-Way algorithm for very long needles. */ return two_way_long_needle(hs, hs_len, ne, ne_len); } #endif /* compilation for speed */ picolibc-1.8.11/libc/string/strtok.c000066400000000000000000000072501513574234600173150ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>, <>, <>---get next token from a string INDEX strtok INDEX strtok_r INDEX strsep SYNOPSIS #include char *strtok(char *restrict <[source]>, const char *restrict <[delimiters]>); char *strtok_r(char *restrict <[source]>, const char *restrict <[delimiters]>, char **<[lasts]>); char *strsep(char **<[source_ptr]>, const char *<[delimiters]>); DESCRIPTION The <> function is used to isolate sequential tokens in a null-terminated string, <<*<[source]>>>. These tokens are delimited in the string by at least one of the characters in <<*<[delimiters]>>>. The first time that <> is called, <<*<[source]>>> should be specified; subsequent calls, wishing to obtain further tokens from the same string, should pass a null pointer instead. The separator string, <<*<[delimiters]>>>, must be supplied each time and may change between calls. The <> function returns a pointer to the beginning of each subsequent token in the string, after replacing the separator character itself with a null character. When no more tokens remain, a null pointer is returned. The <> function has the same behavior as <>, except a pointer to placeholder <<*<[lasts]>>> must be supplied by the caller. The <> function is similar in behavior to <>, except a pointer to the string pointer must be supplied <<<[source_ptr]>>> and the function does not skip leading delimiters. When the string starts with a delimiter, the delimiter is changed to the null character and the empty string is returned. Like <> and <>, the <<*<[source_ptr]>>> is updated to the next character following the last delimiter found or NULL if the end of string is reached with no more delimiters. RETURNS <>, <>, and <> all return a pointer to the next token, or <> if no more tokens can be found. For <>, a token may be the empty string. NOTES <> is unsafe for multi-threaded applications. <> and <> are thread-safe and should be used instead. PORTABILITY <> is ANSI C. <> is POSIX. <> is a BSD extension. <>, <>, and <> require no supporting OS subroutines. QUICKREF strtok ansi impure */ /* undef STRICT_ANSI so that strtok_r prototype will be defined */ #undef __STRICT_ANSI__ #include #include static __THREAD_LOCAL char *_strtok_last; extern char *__strtok_r(char *, const char *, char **, int); char * strtok(register char * __restrict s, register const char * __restrict delim) { return __strtok_r(s, delim, &_strtok_last, 1); } picolibc-1.8.11/libc/string/strtok_r.c000066400000000000000000000060301513574234600176310ustar00rootroot00000000000000/* * Copyright (c) 1988 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #define _DEFAULT_SOURCE #include #include "strtok_r.h" char * __strtok_r(register char *s, register const char *delim, char **lasts, int skip_leading_delim) { register char *spanp; register int c, sc; char *tok; if (s == NULL && (s = *lasts) == NULL) return (NULL); /* * Skip (span) leading delimiters (s += strspn(s, delim), sort of). */ cont: c = *s++; for (spanp = (char *)delim; (sc = *spanp++) != 0;) { if (c == sc) { if (skip_leading_delim) { goto cont; } else { *lasts = s; s[-1] = 0; return (s - 1); } } } if (c == 0) { /* no non-delimiter characters */ *lasts = NULL; return (NULL); } tok = s - 1; /* * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). * Note that delim must have one NUL; we stop if we see that, too. */ for (;;) { c = *s++; spanp = (char *)delim; do { if ((sc = *spanp++) == c) { if (c == 0) s = NULL; else s[-1] = 0; *lasts = s; return (tok); } } while (sc != 0); } /* NOTREACHED */ } char * strtok_r(register char * __restrict s, register const char * __restrict delim, char ** __restrict lasts) { return __strtok_r(s, delim, lasts, 1); } picolibc-1.8.11/libc/string/strtok_r.h000066400000000000000000000033551513574234600176450ustar00rootroot00000000000000/* * Copyright (c) 1988 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef _STRTOK_R_H_ #define _STRTOK_R_H_ char *__strtok_r(register char *s, register const char *delim, char **lasts, int skip_leading_delim); #endif /* _STRTOK_R_H_ */ picolibc-1.8.11/libc/string/strupr.c000066400000000000000000000025321513574234600173240ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---force string to uppercase INDEX strupr SYNOPSIS #include char *strupr(char *<[a]>); DESCRIPTION <> converts each character in the string at <[a]> to uppercase. RETURNS <> returns its argument, <[a]>. PORTABILITY <> is not widely portable. <> requires no supporting OS subroutines. QUICKREF strupr */ #define _DEFAULT_SOURCE #include #include char * strupr(char *s) { unsigned char *ucs = (unsigned char *)s; for (; *ucs != '\0'; ucs++) { *ucs = toupper(*ucs); } return s; } picolibc-1.8.11/libc/string/strverscmp.c000066400000000000000000000061231513574234600201750ustar00rootroot00000000000000/* FUNCTION <>---version string compare INDEX strverscmp SYNOPSIS #define _GNU_SOURCE #include int strverscmp(const char *<[a]>, const char *<[b]>); DESCRIPTION <> compares the string at <[a]> to the string at <[b]> in a version-logical order. RETURNS If <<*<[a]>>> version-sorts after <<*<[b]>>>, <> returns a number greater than zero. If the two strings match, <> returns zero. If <<*<[a]>>> version-sorts before <<*<[b]>>>, <> returns a number less than zero. PORTABILITY <> is a GNU extension. <> requires no supporting OS subroutines. It uses isdigit() from elsewhere in this library. QUICKREF strverscmp */ /* From musl src/string/strverscmp.c Copyright © 2005-2014 Rich Felker, et al. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #define _GNU_SOURCE #include #include int strverscmp(const char *l0, const char *r0) { const unsigned char *l = (const void *)l0; const unsigned char *r = (const void *)r0; size_t i, dp, j; int z = 1; /* Find maximal matching prefix and track its maximal digit * suffix and whether those digits are all zeros. */ for (dp = i = 0; l[i] == r[i]; i++) { int c = l[i]; if (!c) return 0; if (!isdigit(c)) dp = i + 1, z = 1; else if (c != '0') z = 0; } if (l[dp] < '1' + 9U && r[dp] < '1' + 9U) { /* If we're looking at non-degenerate digit sequences starting * with nonzero digits, longest digit string is greater. */ for (j = i; isdigit(l[j]); j++) if (!isdigit(r[j])) return 1; if (isdigit(r[j])) return -1; } else if (z && dp < i && (isdigit(l[i]) || isdigit(r[i]))) { /* Otherwise, if common prefix of digit sequence is * all zeros, digits order less than non-digits. */ return (unsigned char)(l[i] - '0') - (unsigned char)(r[i] - '0'); } return l[i] - r[i]; } picolibc-1.8.11/libc/string/strxfrm.c000066400000000000000000000050001513574234600174630ustar00rootroot00000000000000/* Copyright (c) 1994 Cygnus Support. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, and/or other materials related to such distribution and use acknowledge that the software was developed at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* FUNCTION <>---transform string INDEX strxfrm SYNOPSIS #include size_t strxfrm(char *restrict <[s1]>, const char *restrict <[s2]>, size_t <[n]>); DESCRIPTION This function transforms the string pointed to by <[s2]> and places the resulting string into the array pointed to by <[s1]>. The transformation is such that if the <> function is applied to the two transformed strings, it returns a value greater than, equal to, or less than zero, correspoinding to the result of a <> function applied to the same two original strings. No more than <[n]> characters are placed into the resulting array pointed to by <[s1]>, including the terminating null character. If <[n]> is zero, <[s1]> may be a null pointer. If copying takes place between objects that overlap, the behavior is undefined. (NOT Cygwin:) The current implementation of <> simply copies the input and does not support any language-specific transformations. RETURNS The <> function returns the length of the transformed string (not including the terminating null character). If the value returned is <[n]> or more, the contents of the array pointed to by <[s1]> are indeterminate. PORTABILITY <> is ANSI C. <> requires no supporting OS subroutines. QUICKREF strxfrm ansi pure */ #include size_t strxfrm(char * __restrict s1, const char * __restrict s2, size_t n) { size_t res; res = 0; while (n-- > 0) { if ((*s1++ = *s2++) != '\0') ++res; else return res; } while (*s2) { ++s2; ++res; } return res; } picolibc-1.8.11/libc/string/strxfrm_l.c000066400000000000000000000041201513574234600200000ustar00rootroot00000000000000/* Copyright (c) 2016 Corinna Vinschen */ /* FUNCTION <>---transform string INDEX strxfrm_l SYNOPSIS #include size_t strxfrm_l(char *restrict <[s1]>, const char *restrict <[s2]>, size_t <[n]>, locale_t <[locale]>); DESCRIPTION This function transforms the string pointed to by <[s2]> and places the resulting string into the array pointed to by <[s1]>. The transformation is such that if the <> function is applied to the two transformed strings, it returns a value greater than, equal to, or less than zero, correspoinding to the result of a <> function applied to the same two original strings. No more than <[n]> characters are placed into the resulting array pointed to by <[s1]>, including the terminating null character. If <[n]> is zero, <[s1]> may be a null pointer. If copying takes place between objects that overlap, the behavior is undefined. (NOT Cygwin:) The current implementation of <> simply copies the input and does not support any language-specific transformations. If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. RETURNS The <> function returns the length of the transformed string (not including the terminating null character). If the value returned is <[n]> or more, the contents of the array pointed to by <[s1]> are indeterminate. PORTABILITY <> is POSIX-1.2008. <> requires no supporting OS subroutines. QUICKREF strxfrm_l ansi pure */ #define _DEFAULT_SOURCE #include size_t strxfrm_l(char * __restrict s1, const char * __restrict s2, size_t n, locale_t locale) { size_t res; (void)locale; res = 0; while (n-- > 0) { if ((*s1++ = *s2++) != '\0') ++res; else return res; } while (*s2) { ++s2; ++res; } return res; } picolibc-1.8.11/libc/string/swab.c000066400000000000000000000016251513574234600167230ustar00rootroot00000000000000/* Copyright (c) 2000 Alexandre Oliva */ /* FUNCTION <>---swap adjacent bytes SYNOPSIS #include void swab(const void *<[in]>, void *<[out]>, ssize_t <[n]>); DESCRIPTION This function copies <[n]> bytes from the memory region pointed to by <[in]> to the memory region pointed to by <[out]>, exchanging adjacent even and odd bytes. PORTABILITY <> requires no supporting OS subroutines. */ #define _XOPEN_SOURCE #include void swab(const void *b1, void *b2, ssize_t length) { const char *from = b1; char *to = b2; ssize_t ptr; for (ptr = 1; ptr < length; ptr += 2) { char p = from[ptr]; char q = from[ptr - 1]; to[ptr - 1] = p; to[ptr] = q; } if (ptr == length) /* I.e., if length is odd, */ to[ptr - 1] = 0; /* then pad with a NUL. */ } picolibc-1.8.11/libc/string/timingsafe_bcmp.c000066400000000000000000000021601513574234600211110ustar00rootroot00000000000000/* $OpenBSD: timingsafe_bcmp.c,v 1.2 2014/06/10 04:17:37 deraadt Exp $ */ /* * Copyright (c) 2010 Damien Miller. All rights reserved. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #define _DEFAULT_SOURCE #include int timingsafe_bcmp(const void *b1, const void *b2, size_t n) { const unsigned char *p1 = b1, *p2 = b2; int ret = 0; for (; n > 0; n--) ret |= *p1++ ^ *p2++; return (ret != 0); } picolibc-1.8.11/libc/string/timingsafe_memcmp.c000066400000000000000000000030541513574234600214510ustar00rootroot00000000000000/* $OpenBSD: timingsafe_memcmp.c,v 1.1 2014/06/13 02:12:17 matthew Exp $ */ /* * Copyright (c) 2014 Google Inc. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #define _DEFAULT_SOURCE #include #include int timingsafe_memcmp(const void *b1, const void *b2, size_t len) { const unsigned char *p1 = b1, *p2 = b2; size_t i; int res = 0, done = 0; for (i = 0; i < len; i++) { /* lt is -1 if p1[i] < p2[i]; else 0. */ int lt = (p1[i] - p2[i]) >> CHAR_BIT; /* gt is -1 if p1[i] > p2[i]; else 0. */ int gt = (p2[i] - p1[i]) >> CHAR_BIT; /* cmp is 1 if p1[i] > p2[i]; -1 if p1[i] < p2[i]; else 0. */ int cmp = lt - gt; /* set res = cmp if !done. */ res |= cmp & ~done; /* set done if p1[i] != p2[i]. */ done |= lt | gt; } return (res); } picolibc-1.8.11/libc/string/uniset000077500000000000000000000523441513574234600170640ustar00rootroot00000000000000#!/usr/bin/perl # Copyright (c) 2018 Markus Kuhn # Uniset -- Unicode subset manager -- Markus Kuhn # http://www.cl.cam.ac.uk/~mgk25/download/uniset.tar.gz require 5.014; use open ':utf8'; use FindBin qw($RealBin); # to find directory where this file is located binmode(STDOUT, ":utf8"); binmode(STDIN, ":utf8"); my (%name, %invname, %category, %comment); print <. yyyy yyyy (optionally prefixed with 0x) is a Unicode character belonging to the specified subset. yyyy-yyyy a range of Unicode characters belonging to yyyy..yyyy the specified subset. xx yy yy yy-yy yy xx denotes a row (high-byte) and the yy specify corresponding low bytes or with a hyphen also ranges of low bytes in the Unicode values that belong to this subset. This is also the format that is generated by the compact command. End exit 1 if $#ARGV < 0; # Subroutine to identify whether the ISO 10646/Unicode character code # ucs belongs into the East Asian Wide (W) or East Asian FullWidth # (F) category as defined in Unicode Technical Report #11. sub iswide ($) { my $ucs = shift(@_); return ($ucs >= 0x1100 && ($ucs <= 0x115f || # Hangul Jamo $ucs == 0x2329 || $ucs == 0x232a || ($ucs >= 0x2e80 && $ucs <= 0xa4cf && $ucs != 0x303f) || # CJK .. Yi ($ucs >= 0xac00 && $ucs <= 0xd7a3) || # Hangul Syllables ($ucs >= 0xf900 && $ucs <= 0xfaff) || # CJK Comp. Ideographs ($ucs >= 0xfe30 && $ucs <= 0xfe6f) || # CJK Comp. Forms ($ucs >= 0xff00 && $ucs <= 0xff60) || # Fullwidth Forms ($ucs >= 0xffe0 && $ucs <= 0xffe6) || ($ucs >= 0x20000 && $ucs <= 0x2fffd) || ($ucs >= 0x30000 && $ucs <= 0x3fffd))); } # Return the Unicode name that belongs to a given character code # Jamo short names, see Unicode 3.0, table 4-4, page 86 my @lname = ('G', 'GG', 'N', 'D', 'DD', 'R', 'M', 'B', 'BB', 'S', 'SS', '', 'J', 'JJ', 'C', 'K', 'T', 'P', 'H'); # 1100..1112 my @vname = ('A', 'AE', 'YA', 'YAE', 'EO', 'E', 'YEO', 'YE', 'O', 'WA', 'WAE', 'OE', 'YO', 'U', 'WEO', 'WE', 'WI', 'YU', 'EU', 'YI', 'I'); # 1161..1175 my @tname = ('G', 'GG', 'GS', 'N', 'NJ', 'NH', 'D', 'L', 'LG', 'LM', 'LB', 'LS', 'LT', 'LP', 'LH', 'M', 'B', 'BS', 'S', 'SS', 'NG', 'J', 'C', 'K', 'T', 'P', 'H'); # 11a8..11c2 sub name { my $ucs = shift(@_); # The intervals used here reflect Unicode Version 3.2 if (($ucs >= 0x3400 && $ucs <= 0x4db5) || ($ucs >= 0x4e00 && $ucs <= 0x9fa5) || ($ucs >= 0x20000 && $ucs <= 0x2a6d6)) { return "CJK UNIFIED IDEOGRAPH-" . sprintf("%04X", $ucs); } if ($ucs >= 0xac00 && $ucs <= 0xd7a3) { my $s = $ucs - 0xac00; my $l = 0x1100 + int($s / (21 * 28)); my $v = 0x1161 + int(($s % (21 * 28)) / 28); my $t = 0x11a7 + $s % 28; return "HANGUL SYLLABLE " . ($lname[int($s / (21 * 28))] . $vname[int(($s % (21 * 28)) / 28)] . $tname[$s % 28 - 1]); } return $name{$ucs}; } sub is_unicode { my $ucs = shift(@_); # The intervals used here reflect Unicode Version 3.2 if (($ucs >= 0x3400 && $ucs <= 0x4db5) || ($ucs >= 0x4e00 && $ucs <= 0x9fa5) || ($ucs >= 0xac00 && $ucs <= 0xd7a3) || ($ucs >= 0x20000 && $ucs <= 0x2a6d6)) { return 1; } return exists $name{$ucs}; } my @search_path = (); if ($RealBin =~ m|^(.*)/bin\z| && -d "$1/share/uniset") { push @search_path, "$1/share/uniset"; } else { push @search_path, $RealBin; } sub search_open { my ($mode, $fn) = @_; my $file; return $file if open($file, $mode, $fn); return undef if $fn =~ m|/|; for my $path (@search_path) { return $file if open($file, $mode, "$path/$fn"); } return undef; } my $html = 0; my $image = 0; my $adducs = 0; my $unicodedata = "UnicodeData.txt"; my $blockdata = "Blocks.txt"; # read list of all Unicode names my $data = search_open('<', $unicodedata); unless ($data) { die ("Can't open Unicode database '$unicodedata':\n$!\n\n" . "Please make sure that you have downloaded the file\n" . "http://www.unicode.org/Public/UNIDATA/UnicodeData.txt\n"); } while (<$data>) { if (/^([0-9,A-F]{4,8});([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*)$/) { next if $2 ne '' && substr($2, 0, 1) eq '<'; $ucs = hex($1); $name{$ucs} = $2; $invname{$2} = $ucs; $category{$ucs} = $3; $comment{$ucs} = $12; } else { die("Syntax error in line '$_' in file '$unicodedata'\n"); } } close($data); # read list of all Unicode blocks $data = search_open('<', $blockdata); unless ($data) { die ("Can't open Unicode blockname list '$blockdata':\n$!\n\n" . "Please make sure that you have downloaded the file\n" . "http://www.unicode.org/Public/UNIDATA/Blocks.txt\n"); } my $blocks = 0; my (@blockstart, @blockend, @blockname); while (<$data>) { if (/^\s*([0-9,A-F]{4,8})\s*\.\.\s*([0-9,A-F]{4,8})\s*;\s*(.*)$/) { $blockstart[$blocks] = hex($1); $blockend [$blocks] = hex($2); $blockname [$blocks] = $3; $blocks++; } elsif (/^\s*\#/ || /^\s*$/) { # ignore comments and empty lines } else { die("Syntax error in line '$_' in file '$blockdata'\n"); } } close($data); if ($blockend[$blocks-1] < 0x110000) { $blockstart[$blocks] = 0x110000; $blockend [$blocks] = 0x7FFFFFFF; $blockname [$blocks] = "Beyond Plane 16"; $blocks++; } # process command line arguments while ($_ = shift(@ARGV)) { if (/^html$/) { $html = 1; } elsif (/^ucs$/) { $adducs = 1; } elsif (/^img$/) { $html = 1; $image = 1; } elsif (/^template$/) { $template = shift(@ARGV); open(TEMPLATE, $template) || die("Can't open template file '$template': $!\n"); while (