diff options
Diffstat (limited to 'src/boost/libs/context')
137 files changed, 14532 insertions, 0 deletions
diff --git a/src/boost/libs/context/README.md b/src/boost/libs/context/README.md new file mode 100644 index 000000000..44aeff04f --- /dev/null +++ b/src/boost/libs/context/README.md @@ -0,0 +1,21 @@ +boost.context +============= + +boost.context is a foundational library that provides a sort of cooperative multitasking on a single thread. +By providing an abstraction of the current execution state in the current thread, including the stack (with +local variables) and stack pointer, all registers and CPU flags, and the instruction pointer, a execution_context +instance represents a specific point in the application's execution path. This is useful for building +higher-level abstractions, like coroutines, cooperative threads (userland threads) or an equivalent to +C# keyword yield in C++. + +A fiber provides the means to suspend the current execution path and to transfer execution control, +thereby permitting another fiber to run on the current thread. This state full transfer mechanism +enables a fiber to suspend execution from within nested functions and, later, to resume from where it +was suspended. While the execution path represented by a fiber only runs on a single thread, it can be +migrated to another thread at any given time. + +A context switch between threads requires system calls (involving the OS kernel), which can cost more than +thousand CPU cycles on x86 CPUs. By contrast, transferring control among fibers requires only fewer than +hundred CPU cycles because it does not involve system calls as it is done within a single thread. + +boost.context requires C++11! diff --git a/src/boost/libs/context/build/Jamfile.v2 b/src/boost/libs/context/build/Jamfile.v2 new file mode 100644 index 000000000..580aca664 --- /dev/null +++ b/src/boost/libs/context/build/Jamfile.v2 @@ -0,0 +1,828 @@ + +# Boost.Context Library Build Jamfile + +# Copyright Oliver Kowalke 2009. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import common ; +import feature ; +import indirect ; +import modules ; +import os ; +import toolset ; + import ../../config/checks/config : requires ; + +feature.feature segmented-stacks : on : optional propagated composite ; +feature.compose <segmented-stacks>on : <define>BOOST_USE_SEGMENTED_STACKS ; + +feature.feature htm : tsx : optional propagated composite ; +feature.compose <htm>tsx : <define>BOOST_USE_TSX ; + +feature.feature valgrind : on : optional propagated composite ; +feature.compose <valgrind>on : <define>BOOST_USE_VALGRIND ; + +project boost/context + : requirements + <target-os>windows:<define>_WIN32_WINNT=0x0601 + <toolset>gcc,<segmented-stacks>on:<cxxflags>-fsplit-stack + <toolset>gcc,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS + <toolset>gcc,<segmented-stacks>on:<linkflags>"-static-libgcc" + <toolset>clang,<segmented-stacks>on:<cxxflags>-fsplit-stack + <toolset>clang,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS + <toolset>clang,<segmented-stacks>on:<linkflags>"-static-libgcc" + <toolset>intel,<link>shared:<define>BOOST_CONTEXT_EXPORT=EXPORT + <toolset>intel,<link>static:<define>BOOST_CONTEXT_EXPORT= + <toolset>msvc,<link>shared:<define>BOOST_CONTEXT_EXPORT=EXPORT + <toolset>msvc,<link>static:<define>BOOST_CONTEXT_EXPORT= + <toolset>clang-win,<link>shared:<define>BOOST_CONTEXT_EXPORT=EXPORT + <toolset>clang-win,<link>static:<define>BOOST_CONTEXT_EXPORT= + <link>shared:<define>BOOST_CONTEXT_DYN_LINK=1 + <define>BOOST_CONTEXT_SOURCE + <threading>multi + : usage-requirements + <link>shared:<define>BOOST_CONTEXT_DYN_LINK=1 + <optimization>speed:<define>BOOST_DISABLE_ASSERTS + <variant>release:<define>BOOST_DISABLE_ASSERTS + : source-location ../src + ; + + +local rule default_binary_format ( ) +{ + local tmp = elf ; + if [ os.name ] = "NT" { tmp = pe ; } + else if [ os.name ] = "CYGWIN" { tmp = pe ; } + else if [ os.name ] = "AIX" { tmp = xcoff ; } + else if [ os.name ] = "MACOSX" { tmp = mach-o ; } + return $(tmp) ; +} + +feature.feature binary-format + : elf + mach-o + pe + xcoff + : propagated + ; +feature.set-default binary-format : [ default_binary_format ] ; + + +local rule default_abi ( ) +{ + local tmp = sysv ; + if [ os.name ] = "NT" { tmp = ms ; } + else if [ os.name ] = "CYGWIN" { tmp = ms ; } + else if [ os.platform ] = "ARM" { tmp = aapcs ; } + else if [ os.platform ] = "MIPS32" { tmp = o32 ; } + else if [ os.platform ] = "MIPS64" { tmp = n64 ; } + return $(tmp) ; +} + +feature.feature abi + : aapcs + eabi + ms + n32 + n64 + o32 + o64 + sysv + x32 + : propagated + ; +feature.set-default abi : [ default_abi ] ; + + +feature.feature context-impl + : fcontext + ucontext + winfib + : propagated + composite + ; +feature.set-default context-impl : fcontext ; +feature.compose <context-impl>ucontext : <define>BOOST_USE_UCONTEXT ; +feature.compose <context-impl>winfib : <define>BOOST_USE_WINFIB ; + +# ARM +# ARM/AAPCS/ELF +alias asm_sources + : asm/make_arm_aapcs_elf_gas.S + asm/jump_arm_aapcs_elf_gas.S + asm/ontop_arm_aapcs_elf_gas.S + : <abi>aapcs + <address-model>32 + <architecture>arm + <binary-format>elf + <toolset>clang + ; + +alias asm_sources + : asm/make_arm_aapcs_elf_gas.S + asm/jump_arm_aapcs_elf_gas.S + asm/ontop_arm_aapcs_elf_gas.S + : <abi>aapcs + <address-model>32 + <architecture>arm + <binary-format>elf + <toolset>gcc + ; + +alias asm_sources + : asm/make_arm_aapcs_elf_gas.S + asm/jump_arm_aapcs_elf_gas.S + asm/ontop_arm_aapcs_elf_gas.S + : <abi>aapcs + <address-model>32 + <architecture>arm + <binary-format>elf + <toolset>qcc + ; + +# ARM/AAPCS/MACH-O +alias asm_sources + : asm/make_arm_aapcs_macho_gas.S + asm/jump_arm_aapcs_macho_gas.S + asm/ontop_arm_aapcs_macho_gas.S + : <abi>aapcs + <address-model>32 + <architecture>arm + <binary-format>mach-o + <toolset>clang + ; + +alias asm_sources + : asm/make_arm_aapcs_macho_gas.S + asm/jump_arm_aapcs_macho_gas.S + asm/ontop_arm_aapcs_macho_gas.S + : <abi>aapcs + <address-model>32 + <architecture>arm + <binary-format>mach-o + <toolset>darwin + ; + +# ARM/AAPCS/PE +alias asm_sources + : asm/make_arm_aapcs_pe_armasm.asm + asm/jump_arm_aapcs_pe_armasm.asm + asm/ontop_arm_aapcs_pe_armasm.asm + untested.cpp + : <abi>aapcs + <address-model>32 + <architecture>arm + <binary-format>pe + <toolset>msvc + ; + +# ARM64 +# ARM64/AAPCS/ELF +alias asm_sources + : asm/make_arm64_aapcs_elf_gas.S + asm/jump_arm64_aapcs_elf_gas.S + asm/ontop_arm64_aapcs_elf_gas.S + : <abi>aapcs + <address-model>64 + <architecture>arm + <binary-format>elf + <toolset>clang + ; + +alias asm_sources + : asm/make_arm64_aapcs_elf_gas.S + asm/jump_arm64_aapcs_elf_gas.S + asm/ontop_arm64_aapcs_elf_gas.S + : <abi>aapcs + <address-model>64 + <architecture>arm + <binary-format>elf + <toolset>gcc + ; + +# ARM64/AAPCS/MACH-O +alias asm_sources + : asm/make_arm64_aapcs_macho_gas.S + asm/jump_arm64_aapcs_macho_gas.S + asm/ontop_arm64_aapcs_macho_gas.S + : <abi>aapcs + <address-model>64 + <architecture>arm + <binary-format>mach-o + <toolset>clang + ; + +alias asm_sources + : asm/make_arm64_aapcs_macho_gas.S + asm/jump_arm64_aapcs_macho_gas.S + asm/ontop_arm64_aapcs_macho_gas.S + : <abi>aapcs + <address-model>64 + <architecture>arm + <binary-format>mach-o + <toolset>darwin + ; + +# MIPS +# MIPS32/O32/ELF +alias asm_sources + : asm/make_mips32_o32_elf_gas.S + asm/jump_mips32_o32_elf_gas.S + asm/ontop_mips32_o32_elf_gas.S + : <abi>o32 + <address-model>32 + <architecture>mips1 + <binary-format>elf + <toolset>clang + ; + +alias asm_sources + : asm/make_mips32_o32_elf_gas.S + asm/jump_mips32_o32_elf_gas.S + asm/ontop_mips32_o32_elf_gas.S + : <abi>o32 + <address-model>32 + <architecture>mips1 + <binary-format>elf + <toolset>gcc + ; + +# MIPS64/N64/ELF +alias asm_sources + : asm/make_mips64_n64_elf_gas.S + asm/jump_mips64_n64_elf_gas.S + asm/ontop_mips64_n64_elf_gas.S + : <abi>n64 + <address-model>64 + <architecture>mips1 + <binary-format>elf + <toolset>clang + ; + +alias asm_sources + : asm/make_mips64_n64_elf_gas.S + asm/jump_mips64_n64_elf_gas.S + asm/ontop_mips64_n64_elf_gas.S + : <abi>n64 + <address-model>64 + <architecture>mips1 + <binary-format>elf + <toolset>gcc + ; + +# POWERPC_32 +# POWERPC_32/SYSV/ELF +alias asm_sources + : asm/make_ppc32_sysv_elf_gas.S + asm/jump_ppc32_sysv_elf_gas.S + asm/ontop_ppc32_sysv_elf_gas.S + asm/tail_ppc32_sysv_elf_gas.cpp + : <abi>sysv + <address-model>32 + <architecture>power + <binary-format>elf + <toolset>clang + ; + +alias asm_sources + : asm/make_ppc32_sysv_elf_gas.S + asm/jump_ppc32_sysv_elf_gas.S + asm/ontop_ppc32_sysv_elf_gas.S + asm/tail_ppc32_sysv_elf_gas.cpp + : <abi>sysv + <address-model>32 + <architecture>power + <binary-format>elf + <toolset>gcc + ; + +alias asm_sources + : asm/make_ppc32_sysv_macho_gas.S + asm/jump_ppc32_sysv_macho_gas.S + asm/ontop_ppc32_sysv_macho_gas.S + : <abi>sysv + <address-model>32 + <architecture>power + <binary-format>mach-o + <toolset>darwin + ; + +#POWERPC_32/SYSV/XCOFF +alias asm_sources + : asm/make_ppc32_sysv_xcoff_gas.S + asm/jump_ppc32_sysv_xcoff_gas.S + asm/ontop_ppc32_sysv_xcoff_gas.S + : <abi>sysv + <address-model>32 + <architecture>power + <binary-format>xcoff + <toolset>clang + ; + +alias asm_sources + : asm/make_ppc32_sysv_xcoff_gas.S + asm/jump_ppc32_sysv_xcoff_gas.S + asm/ontop_ppc32_sysv_xcoff_gas.S + : <abi>sysv + <address-model>32 + <architecture>power + <binary-format>xcoff + <toolset>gcc + ; + +# POWERPC_64 +# POWERPC_64/SYSV/ELF +alias asm_sources + : asm/make_ppc64_sysv_elf_gas.S + asm/jump_ppc64_sysv_elf_gas.S + asm/ontop_ppc64_sysv_elf_gas.S + : <abi>sysv + <address-model>64 + <architecture>power + <binary-format>elf + <toolset>clang + ; + +alias asm_sources + : asm/make_ppc64_sysv_elf_gas.S + asm/jump_ppc64_sysv_elf_gas.S + asm/ontop_ppc64_sysv_elf_gas.S + : <abi>sysv + <address-model>64 + <architecture>power + <binary-format>elf + <toolset>gcc + ; + +# POWERPC_64/SYSV/MACH-O +alias asm_sources + : asm/make_ppc64_sysv_macho_gas.S + asm/jump_ppc64_sysv_macho_gas.S + asm/ontop_ppc64_sysv_macho_gas.S + untested.cpp + : <abi>sysv + <address-model>64 + <architecture>power + <binary-format>mach-o + <toolset>clang + ; + +alias asm_sources + : asm/make_ppc64_sysv_macho_gas.S + asm/jump_ppc64_sysv_macho_gas.S + asm/ontop_ppc64_sysv_macho_gas.S + untested.cpp + : <abi>sysv + <address-model>64 + <architecture>power + <binary-format>mach-o + <toolset>darwin + ; + +# POWERPC_64/SYSV/XCOFF +alias asm_sources + : asm/make_ppc64_sysv_xcoff_gas.S + asm/jump_ppc64_sysv_xcoff_gas.S + asm/ontop_ppc64_sysv_xcoff_gas.S + : <abi>sysv + <address-model>64 + <architecture>power + <binary-format>xcoff + <toolset>clang + ; + +alias asm_sources + : asm/make_ppc64_sysv_xcoff_gas.S + asm/jump_ppc64_sysv_xcoff_gas.S + asm/ontop_ppc64_sysv_xcoff_gas.S + : <abi>sysv + <address-model>64 + <architecture>power + <binary-format>xcoff + <toolset>gcc + ; + +# POWERPC universal +# POWERPC_32_64/SYSV/MACH-O +alias asm_sources + : asm/make_ppc32_ppc64_sysv_macho_gas.S + asm/jump_ppc32_ppc64_sysv_macho_gas.S + asm/ontop_ppc32_ppc64_sysv_macho_gas.S + : <abi>sysv + <address-model>32_64 + <architecture>power + <binary-format>mach-o + ; + +# RISCV64 +# RISCV64/SYSV/ELF +alias asm_sources + : asm/make_riscv64_sysv_elf_gas.S + asm/jump_riscv64_sysv_elf_gas.S + asm/ontop_riscv64_sysv_elf_gas.S + : <abi>sysv + <address-model>64 + <architecture>riscv + <binary-format>elf + <toolset>gcc + ; + +# S390X +# S390X/SYSV/ELF +alias asm_sources + : asm/make_s390x_sysv_elf_gas.S + asm/jump_s390x_sysv_elf_gas.S + asm/ontop_s390x_sysv_elf_gas.S + : <abi>sysv + <address-model>64 + <architecture>s390x + <binary-format>elf + <toolset>gcc + ; + +# X86 +# X86/SYSV/ELF +alias asm_sources + : asm/make_i386_sysv_elf_gas.S + asm/jump_i386_sysv_elf_gas.S + asm/ontop_i386_sysv_elf_gas.S + : <abi>sysv + <address-model>32 + <architecture>x86 + <binary-format>elf + <toolset>clang + ; + +alias asm_sources + : asm/make_i386_sysv_elf_gas.S + asm/jump_i386_sysv_elf_gas.S + asm/ontop_i386_sysv_elf_gas.S + : <abi>sysv + <address-model>32 + <architecture>x86 + <binary-format>elf + <toolset>gcc + ; + +alias asm_sources + : asm/make_i386_sysv_elf_gas.S + asm/jump_i386_sysv_elf_gas.S + asm/ontop_i386_sysv_elf_gas.S + : <abi>sysv + <address-model>32 + <architecture>x86 + <binary-format>elf + <toolset>intel + ; + +# X86/SYSV/MACH-O +alias asm_sources + : asm/make_i386_sysv_macho_gas.S + asm/jump_i386_sysv_macho_gas.S + asm/ontop_i386_sysv_macho_gas.S + : <abi>sysv + <address-model>32 + <architecture>x86 + <binary-format>mach-o + <toolset>clang + ; + +alias asm_sources + : asm/make_i386_sysv_macho_gas.S + asm/jump_i386_sysv_macho_gas.S + asm/ontop_i386_sysv_macho_gas.S + : <abi>sysv + <address-model>32 + <architecture>x86 + <binary-format>mach-o + <toolset>darwin + ; + +# X86/MS/PE +alias asm_sources + : asm/make_i386_ms_pe_gas.asm + asm/jump_i386_ms_pe_gas.asm + asm/ontop_i386_ms_pe_gas.asm + dummy.cpp + : <abi>ms + <address-model>32 + <architecture>x86 + <binary-format>pe + <toolset>clang + ; + +alias asm_sources + : asm/make_i386_ms_pe_masm.asm + asm/jump_i386_ms_pe_masm.asm + asm/ontop_i386_ms_pe_masm.asm + dummy.cpp + : <abi>ms + <address-model>32 + <architecture>x86 + <binary-format>pe + <toolset>clang-win + ; + +alias asm_sources + : asm/make_i386_ms_pe_gas.asm + asm/jump_i386_ms_pe_gas.asm + asm/ontop_i386_ms_pe_gas.asm + dummy.cpp + : <abi>ms + <address-model>32 + <architecture>x86 + <binary-format>pe + <toolset>gcc + ; + +alias asm_sources + : asm/make_i386_ms_pe_masm.asm + asm/jump_i386_ms_pe_masm.asm + asm/ontop_i386_ms_pe_masm.asm + dummy.cpp + : <abi>ms + <address-model>32 + <architecture>x86 + <binary-format>pe + <toolset>intel + ; + +alias asm_sources + : asm/make_i386_ms_pe_masm.asm + asm/jump_i386_ms_pe_masm.asm + asm/ontop_i386_ms_pe_masm.asm + dummy.cpp + : <abi>ms + <address-model>32 + <architecture>x86 + <binary-format>pe + <toolset>msvc + ; + +# X86_64 +# X86_64/SYSV/ELF +alias asm_sources + : asm/make_x86_64_sysv_elf_gas.S + asm/jump_x86_64_sysv_elf_gas.S + asm/ontop_x86_64_sysv_elf_gas.S + : <abi>sysv + <address-model>64 + <architecture>x86 + <binary-format>elf + <toolset>clang + ; + +alias asm_sources + : asm/make_x86_64_sysv_elf_gas.S + asm/jump_x86_64_sysv_elf_gas.S + asm/ontop_x86_64_sysv_elf_gas.S + : <abi>sysv + <address-model>64 + <architecture>x86 + <binary-format>elf + <toolset>gcc + ; + +alias asm_sources + : asm/make_x86_64_sysv_elf_gas.S + asm/jump_x86_64_sysv_elf_gas.S + asm/ontop_x86_64_sysv_elf_gas.S + : <abi>sysv + <address-model>64 + <architecture>x86 + <binary-format>elf + <toolset>intel + ; + +# X86_64/SYSV/MACH-O +alias asm_sources + : asm/make_x86_64_sysv_macho_gas.S + asm/jump_x86_64_sysv_macho_gas.S + asm/ontop_x86_64_sysv_macho_gas.S + : <abi>sysv + <address-model>64 + <architecture>x86 + <binary-format>mach-o + <toolset>clang + ; + +alias asm_sources + : asm/make_x86_64_sysv_macho_gas.S + asm/jump_x86_64_sysv_macho_gas.S + asm/ontop_x86_64_sysv_macho_gas.S + : <abi>sysv + <address-model>64 + <architecture>x86 + <binary-format>mach-o + <toolset>darwin + ; + +alias asm_sources + : asm/make_x86_64_sysv_macho_gas.S + asm/jump_x86_64_sysv_macho_gas.S + asm/ontop_x86_64_sysv_macho_gas.S + : <abi>sysv + <address-model>64 + <architecture>x86 + <binary-format>mach-o + <toolset>intel + ; + +# X86_64/MS/PE +alias asm_sources + : asm/make_x86_64_ms_pe_gas.asm + asm/jump_x86_64_ms_pe_gas.asm + asm/ontop_x86_64_ms_pe_gas.asm + dummy.cpp + : <abi>ms + <address-model>64 + <architecture>x86 + <binary-format>pe + <toolset>clang + ; + +alias asm_sources + : asm/make_x86_64_ms_pe_masm.asm + asm/jump_x86_64_ms_pe_masm.asm + asm/ontop_x86_64_ms_pe_masm.asm + dummy.cpp + : <abi>ms + <address-model>64 + <architecture>x86 + <binary-format>pe + <toolset>clang-win + ; + +alias asm_sources + : asm/make_x86_64_ms_pe_gas.asm + asm/jump_x86_64_ms_pe_gas.asm + asm/ontop_x86_64_ms_pe_gas.asm + dummy.cpp + : <abi>ms + <address-model>64 + <architecture>x86 + <binary-format>pe + <toolset>gcc + ; + +alias asm_sources + : asm/make_x86_64_ms_pe_masm.asm + asm/jump_x86_64_ms_pe_masm.asm + asm/ontop_x86_64_ms_pe_masm.asm + dummy.cpp + : <abi>ms + <address-model>64 + <architecture>x86 + <binary-format>pe + <toolset>intel + ; + +alias asm_sources + : asm/make_x86_64_ms_pe_masm.asm + asm/jump_x86_64_ms_pe_masm.asm + asm/ontop_x86_64_ms_pe_masm.asm + dummy.cpp + : <abi>ms + <address-model>64 + <architecture>x86 + <binary-format>pe + <toolset>msvc + ; + +# X86_64/SYSV/X32 +alias asm_sources + : asm/make_x86_64_sysv_elf_gas.S + asm/jump_x86_64_sysv_elf_gas.S + asm/ontop_x86_64_sysv_elf_gas.S + : <abi>x32 + <address-model>64 + <architecture>x86 + <binary-format>elf + <toolset>clang + ; + +alias asm_sources + : asm/make_x86_64_sysv_elf_gas.S + asm/jump_x86_64_sysv_elf_gas.S + asm/ontop_x86_64_sysv_elf_gas.S + : <abi>x32 + <address-model>64 + <architecture>x86 + <binary-format>elf + <toolset>gcc + ; + +alias asm_sources + : asm/make_x86_64_sysv_elf_gas.S + asm/jump_x86_64_sysv_elf_gas.S + asm/ontop_x86_64_sysv_elf_gas.S + : <abi>x32 + <address-model>64 + <architecture>x86 + <binary-format>elf + <toolset>intel + ; + +#X86 universal +alias asm_sources + : asm/make_i386_x86_64_sysv_macho_gas.S + asm/jump_i386_x86_64_sysv_macho_gas.S + asm/ontop_i386_x86_64_sysv_macho_gas.S + : <abi>sysv + <address-model>32_64 + <architecture>x86 + <binary-format>mach-o + ; + +# COMBINED +alias asm_sources + : asm/make_combined_sysv_macho_gas.S + asm/jump_combined_sysv_macho_gas.S + asm/ontop_combined_sysv_macho_gas.S + : <abi>sysv + <architecture>combined + <binary-format>mach-o + ; + +explicit asm_sources ; + + +# fcontext_t +alias impl_sources + : asm_sources + : <context-impl>fcontext + ; + +# ucontext_t +alias impl_sources + : continuation.cpp + fiber.cpp + : <context-impl>ucontext + [ requires cxx11_auto_declarations + cxx11_constexpr + cxx11_defaulted_functions + cxx11_final + cxx11_hdr_thread + cxx11_hdr_tuple + cxx11_lambdas + cxx11_noexcept + cxx11_nullptr + cxx11_rvalue_references + cxx11_template_aliases + cxx11_thread_local + cxx11_variadic_templates ] + ; + +# WinFiber +alias impl_sources + : continuation.cpp + fiber.cpp + : <context-impl>winfib + [ requires cxx11_auto_declarations + cxx11_constexpr + cxx11_defaulted_functions + cxx11_final + cxx11_hdr_thread + cxx11_hdr_tuple + cxx11_lambdas + cxx11_noexcept + cxx11_nullptr + cxx11_rvalue_references + cxx11_template_aliases + cxx11_thread_local + cxx11_variadic_templates ] + ; + +explicit impl_sources ; + +obj cxx11_hdr_mutex_check : ../build/cxx11_hdr_mutex.cpp ; +explicit cxx11_hdr_mutex_check ; +local cxx11_mutex = [ check-target-builds + cxx11_hdr_mutex_check "C++11 mutex" + : + : <library>/boost/thread//boost_thread + ] ; + +alias stack_traits_sources + : windows/stack_traits.cpp + : <target-os>windows + : + : $(cxx11_mutex) + ; + +alias stack_traits_sources + : posix/stack_traits.cpp + : + : + : $(cxx11_mutex) + ; + +explicit stack_traits_sources ; + +lib boost_context + : impl_sources + stack_traits_sources + ; + +boost-install boost_context ; diff --git a/src/boost/libs/context/build/architecture.jam b/src/boost/libs/context/build/architecture.jam new file mode 100644 index 000000000..e00e61e57 --- /dev/null +++ b/src/boost/libs/context/build/architecture.jam @@ -0,0 +1,92 @@ +# architecture.jam +# +# Copyright 2012 Steven Watanabe +# +# Distributed under the Boost Software License Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import configure ; +import project ; +import path ; +import property ; + +local here = [ modules.binding $(__name__) ] ; + +project.push-current [ project.current ] ; +project.load [ path.join [ path.make $(here:D) ] ../config ] ; +project.pop-current ; + +rule deduce-address-model ( properties * ) +{ + local result = [ property.select <address-model> : $(properties) ] ; + if $(result) + { + return $(result) ; + } + else + { + if [ configure.builds /boost/architecture//32 : $(properties) : 32-bit ] + { + return <address-model>32 ; + } + else if [ configure.builds /boost/architecture//64 : $(properties) : 64-bit ] + { + return <address-model>64 ; + } + } +} + +rule address-model ( ) +{ + return <conditional>@architecture.deduce-address-model ; +} + +rule deduce-architecture ( properties * ) +{ + local result = [ property.select <architecture> : $(properties) ] ; + if $(result) + { + return $(result) ; + } + else + { + if [ configure.builds /boost/architecture//arm : $(properties) : arm ] + { + return <architecture>arm ; + } + else if [ configure.builds /boost/architecture//mips1 : $(properties) : mips1 ] + { + return <architecture>mips1 ; + } + else if [ configure.builds /boost/architecture//power : $(properties) : power ] + { + return <architecture>power ; + } + else if [ configure.builds /boost/architecture//riscv : $(properties) : riscv ] + { + return <architecture>riscv ; + } + else if [ configure.builds /boost/architecture//s390x : $(properties) : s390x ] + { + return <architecture>s390x ; + } + else if [ configure.builds /boost/architecture//sparc : $(properties) : sparc ] + { + return <architecture>sparc ; + } + else if [ configure.builds /boost/architecture//x86 : $(properties) : x86 ] + { + return <architecture>x86 ; + } + else if [ configure.builds /boost/architecture//combined : $(properties) : combined ] + { + return <architecture>combined ; + } + } +} + +rule architecture ( ) +{ + return <conditional>@architecture.deduce-architecture ; +} diff --git a/src/boost/libs/context/build/cxx11_hdr_mutex.cpp b/src/boost/libs/context/build/cxx11_hdr_mutex.cpp new file mode 100644 index 000000000..d16a7a152 --- /dev/null +++ b/src/boost/libs/context/build/cxx11_hdr_mutex.cpp @@ -0,0 +1,10 @@ +// Copyright Kohei Takahashi 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/config.hpp> + +#ifdef BOOST_NO_CXX11_HDR_MUTEX +#error "C++11 <mutex> is not available." +#endif diff --git a/src/boost/libs/context/example/callcc/Jamfile.v2 b/src/boost/libs/context/example/callcc/Jamfile.v2 new file mode 100644 index 000000000..f6bf50443 --- /dev/null +++ b/src/boost/libs/context/example/callcc/Jamfile.v2 @@ -0,0 +1,79 @@ +# Boost.Context Library Examples Jamfile + +# Copyright Oliver Kowalke 2014. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# For more information, see http://www.boost.org/ + +import common ; +import feature ; +import indirect ; +import modules ; +import os ; +import toolset ; +import architecture ; + +project boost/context/example/callcc + : requirements + <library>/boost/context//boost_context + <toolset>gcc,<segmented-stacks>on:<cxxflags>-fsplit-stack + <toolset>gcc,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS + <toolset>clang,<segmented-stacks>on:<cxxflags>-fsplit-stack + <toolset>clang,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS + <link>static + <threading>multi + ; + +exe stack + : stack.cpp + ; + +exe jump_void + : jump_void.cpp + ; + +exe jump + : jump.cpp + ; + +exe jump_mov + : jump_mov.cpp + ; + +exe ontop_void + : ontop_void.cpp + ; + +exe throw + : throw.cpp + ; + +exe fibonacci + : fibonacci.cpp + ; + +exe parser + : parser.cpp + ; + +exe ontop + : ontop.cpp + ; + +exe endless_loop + : endless_loop.cpp + ; + +exe segmented + : segmented.cpp + ; + +#exe backtrace +# : backtrace.cpp +# ; + +#exe echosse +# : echosse.cpp +# ; diff --git a/src/boost/libs/context/example/callcc/backtrace.cpp b/src/boost/libs/context/example/callcc/backtrace.cpp new file mode 100644 index 000000000..43acc5730 --- /dev/null +++ b/src/boost/libs/context/example/callcc/backtrace.cpp @@ -0,0 +1,57 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#define UNW_LOCAL_ONLY + +#include <cstdlib> +#include <iostream> + +#include <libunwind.h> + +#include <boost/context/continuation.hpp> + +namespace ctx = boost::context; + +void backtrace() { + unw_cursor_t cursor; + unw_context_t context; + unw_getcontext( & context); + unw_init_local( & cursor, & context); + while ( 0 < unw_step( & cursor) ) { + unw_word_t offset, pc; + unw_get_reg( & cursor, UNW_REG_IP, & pc); + if ( 0 == pc) { + break; + } + std::cout << "0x" << pc << ":"; + + char sym[256]; + if ( 0 == unw_get_proc_name( & cursor, sym, sizeof( sym), & offset) ) { + std::cout << " (" << sym << "+0x" << offset << ")" << std::endl; + } else { + std::cout << " -- error: unable to obtain symbol name for this frame" << std::endl; + } + } +} + +void bar() { + backtrace(); +} + +void foo() { + bar(); +} + +ctx::continuation f1( ctx::continuation && c) { + foo(); + return std::move( c); +} + +int main() { + ctx::callcc( f1); + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/callcc/circle.cpp b/src/boost/libs/context/example/callcc/circle.cpp new file mode 100644 index 000000000..4dd403614 --- /dev/null +++ b/src/boost/libs/context/example/callcc/circle.cpp @@ -0,0 +1,44 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> +#include <list> + +#include <boost/context/fiber.hpp> + +namespace ctx = boost::context; + +int main() { + ctx::fiber f1, f2, f3; + f3 = ctx::fiber{[&](ctx::fiber && f)->ctx::fiber{ + f2 = std::move( f); + for (;;) { + std::cout << "f3\n"; + f2 = f1.resume(); + } + return {}; + }}; + f2 = ctx::fiber{[&](ctx::fiber && f)->ctx::fiber{ + f1 = std::move( f); + for (;;) { + std::cout << "f2\n"; + f1 = f3.resume(); + } + return {}; + }}; + f1 = ctx::fiber{[&](ctx::fiber && /*main*/)->ctx::fiber{ + for (;;) { + std::cout << "f1\n"; + f3 = f2.resume(); + } + return {}; + }}; + f1.resume(); + + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/callcc/echosse.cpp b/src/boost/libs/context/example/callcc/echosse.cpp new file mode 100644 index 000000000..4b76ffc5d --- /dev/null +++ b/src/boost/libs/context/example/callcc/echosse.cpp @@ -0,0 +1,46 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstddef> +#include <cstdlib> +#include <cstring> +#include <iostream> +#include <emmintrin.h> + +#include <boost/context/continuation.hpp> + +namespace ctx = boost::context; + +void echoSSE( int i) { + __m128i xmm; + xmm = _mm_set_epi32( i, i + 1, i + 2, i + 3); + uint32_t v32[4]; + memcpy( & v32, & xmm, 16); + std::cout << v32[0]; + std::cout << v32[1]; + std::cout << v32[2]; + std::cout << v32[3]; +} + + +int main( int argc, char * argv[]) { + int i = 0; + ctx::continuation c = ctx::callcc( + [&i](ctx::continuation && c) { + for (;;) { + std::cout << i; + echoSSE( i); + std::cout << " "; + c = c.resume(); + } + return std::move( c); + }); + for (; i < 10; ++i) { + c = c.resume(); + } + std::cout << "\nmain: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/callcc/endless_loop.cpp b/src/boost/libs/context/example/callcc/endless_loop.cpp new file mode 100644 index 000000000..318bb88db --- /dev/null +++ b/src/boost/libs/context/example/callcc/endless_loop.cpp @@ -0,0 +1,28 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> + +#include <boost/context/continuation.hpp> + +namespace ctx = boost::context; + +ctx::continuation foo( ctx::continuation && c) { + do { + std::cout << "foo\n"; + } while ( ( c = c.resume() ) ); + return std::move( c); +} + +int main() { + ctx::continuation c = ctx::callcc( foo); + do { + std::cout << "bar\n"; + } while ( ( c = c.resume() ) ); + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/callcc/fibonacci.cpp b/src/boost/libs/context/example/callcc/fibonacci.cpp new file mode 100644 index 000000000..170b9f274 --- /dev/null +++ b/src/boost/libs/context/example/callcc/fibonacci.cpp @@ -0,0 +1,36 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> +#include <memory> + +#include <boost/context/continuation.hpp> + +namespace ctx = boost::context; + +int main() { + int a; + ctx::continuation c=ctx::callcc( + [&a](ctx::continuation && c){ + a=0; + int b=1; + for(;;){ + c=c.resume(); + int next=a+b; + a=b; + b=next; + } + return std::move( c); + }); + for ( int j = 0; j < 10; ++j) { + std::cout << a << " "; + c=c.resume(); + } + std::cout << std::endl; + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/callcc/jump.cpp b/src/boost/libs/context/example/callcc/jump.cpp new file mode 100644 index 000000000..ab5d6b739 --- /dev/null +++ b/src/boost/libs/context/example/callcc/jump.cpp @@ -0,0 +1,35 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> + +#include <boost/context/continuation.hpp> + +namespace ctx = boost::context; + +int main() { + ctx::continuation c; + int data = 1; + c = ctx::callcc( + [&data](ctx::continuation && c){ + std::cout << "entered first time: " << data << std::endl; + data += 2; + c = c.resume(); + std::cout << "entered second time: " << data << std::endl; + return std::move( c); + }); + std::cout << "returned first time: " << data << std::endl; + data += 2; + c = c.resume(); + if ( c) { + std::cout << "returned second time: " << data << std::endl; + } else { + std::cout << "returned second time: execution context terminated" << std::endl; + } + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/callcc/jump_mov.cpp b/src/boost/libs/context/example/callcc/jump_mov.cpp new file mode 100644 index 000000000..1f522eff6 --- /dev/null +++ b/src/boost/libs/context/example/callcc/jump_mov.cpp @@ -0,0 +1,59 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> + +#include <boost/context/continuation.hpp> + +namespace ctx = boost::context; + +class moveable { +public: + int value; + + moveable() : + value( -1) { + } + + moveable( int v) : + value( v) { + } + + moveable( moveable && other) { + std::swap( value, other.value); + } + + moveable & operator=( moveable && other) { + if ( this == & other) return * this; + value = other.value; + other.value = -1; + return * this; + } + + moveable( moveable const& other) = delete; + moveable & operator=( moveable const& other) = delete; +}; + +int main() { + ctx::continuation c; + moveable data{ 1 }; + c = ctx::callcc( std::allocator_arg, ctx::fixedsize_stack{}, + [&data](ctx::continuation && c){ + std::cout << "entered first time: " << data.value << std::endl; + data = std::move( moveable{ 3 }); + c = c.resume(); + std::cout << "entered second time: " << data.value << std::endl; + data = std::move( moveable{}); + return std::move( c); + }); + std::cout << "returned first time: " << data.value << std::endl; + data.value = 5; + c = c.resume(); + std::cout << "returned second time: " << data.value << std::endl; + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/callcc/jump_void.cpp b/src/boost/libs/context/example/callcc/jump_void.cpp new file mode 100644 index 000000000..7cb5d41e0 --- /dev/null +++ b/src/boost/libs/context/example/callcc/jump_void.cpp @@ -0,0 +1,28 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> + +#include <boost/context/continuation.hpp> + +namespace ctx = boost::context; + +ctx::continuation f1( ctx::continuation && c) { + std::cout << "f1: entered first time" << std::endl; + c = c.resume(); + std::cout << "f1: entered second time" << std::endl; + return std::move( c); +} + +int main() { + ctx::continuation c = ctx::callcc( f1); + std::cout << "f1: returned first time" << std::endl; + c = c.resume(); + std::cout << "f1: returned second time" << std::endl; + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/callcc/ontop.cpp b/src/boost/libs/context/example/callcc/ontop.cpp new file mode 100644 index 000000000..d59fde8a4 --- /dev/null +++ b/src/boost/libs/context/example/callcc/ontop.cpp @@ -0,0 +1,40 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> +#include <tuple> + +#include <boost/context/continuation.hpp> + +namespace ctx = boost::context; + +int main() { + int data = 0; + ctx::continuation c = ctx::callcc( [&data](ctx::continuation && c) { + std::cout << "f1: entered first time: " << data << std::endl; + data += 1; + c = c.resume(); + std::cout << "f1: entered second time: " << data << std::endl; + data += 1; + c = c.resume(); + std::cout << "f1: entered third time: " << data << std::endl; + return std::move( c); + }); + std::cout << "f1: returned first time: " << data << std::endl; + data += 1; + c = c.resume(); + std::cout << "f1: returned second time: " << data << std::endl; + data += 1; + c = c.resume_with( [&data](ctx::continuation && c){ + std::cout << "f2: entered: " << data << std::endl; + data = -1; + return std::move( c); + }); + std::cout << "f1: returned third time" << std::endl; + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/callcc/ontop_void.cpp b/src/boost/libs/context/example/callcc/ontop_void.cpp new file mode 100644 index 000000000..fdc9827b2 --- /dev/null +++ b/src/boost/libs/context/example/callcc/ontop_void.cpp @@ -0,0 +1,40 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> +#include <tuple> + +#include <boost/context/continuation.hpp> + +namespace ctx = boost::context; + +ctx::continuation f1( ctx::continuation && c) { + std::cout << "f1: entered first time" << std::endl; + c = c.resume(); + std::cout << "f1: entered second time" << std::endl; + c = c.resume(); + std::cout << "f1: entered third time" << std::endl; + return std::move( c); +} + +ctx::continuation f2( ctx::continuation && c) { + std::cout << "f2: entered" << std::endl; + return std::move( c); +} + +int main() { + ctx::continuation c = ctx::callcc( f1); + std::cout << "f1: returned first time" << std::endl; + c = c.resume(); + std::cout << "f1: returned second time" << std::endl; + c = c.resume_with( f2); + std::cout << "f1: returned third time" << std::endl; + + std::cout << "main: done" << std::endl; + + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/callcc/parser.cpp b/src/boost/libs/context/example/callcc/parser.cpp new file mode 100644 index 000000000..b1744f02c --- /dev/null +++ b/src/boost/libs/context/example/callcc/parser.cpp @@ -0,0 +1,128 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdio> +#include <cstdlib> +#include <exception> +#include <functional> +#include <iostream> +#include <memory> +#include <sstream> + +#include <boost/context/continuation.hpp> + +namespace ctx = boost::context; + +/* + * grammar: + * P ---> E '\0' + * E ---> T {('+'|'-') T} + * T ---> S {('*'|'/') S} + * S ---> digit | '(' E ')' + */ +class Parser{ + char next; + std::istream& is; + std::function<void(char)> cb; + + char pull(){ + return std::char_traits<char>::to_char_type(is.get()); + } + + void scan(){ + do{ + next=pull(); + } + while(isspace(next)); + } + +public: + Parser(std::istream& is_,std::function<void(char)> cb_) : + next(), is(is_), cb(cb_) + {} + + void run() { + scan(); + E(); + } + +private: + void E(){ + T(); + while (next=='+'||next=='-'){ + cb(next); + scan(); + T(); + } + } + + void T(){ + S(); + while (next=='*'||next=='/'){ + cb(next); + scan(); + S(); + } + } + + void S(){ + if (isdigit(next)){ + cb(next); + scan(); + } + else if(next=='('){ + cb(next); + scan(); + E(); + if (next==')'){ + cb(next); + scan(); + }else{ + throw std::runtime_error("parsing failed"); + } + } + else{ + throw std::runtime_error("parsing failed"); + } + } +}; + +int main() { + try { + std::istringstream is("1+1"); + // execute parser in new execution context + ctx::continuation source; + // user-code pulls parsed data from parser + // invert control flow + char c; + bool done = false; + source=ctx::callcc( + [&is,&c,&done](ctx::continuation && sink){ + // create parser with callback function + Parser p( is, + [&sink,&c](char c_){ + // resume main execution context + c = c_; + sink=sink.resume(); + }); + // start recursive parsing + p.run(); + // signal termination + done = true; + // resume main execution context + return std::move(sink); + }); + while(!done){ + printf("Parsed: %c\n",c); + source=source.resume(); + } + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; + } catch (std::exception const& e) { + std::cerr << "exception: " << e.what() << std::endl; + } + return EXIT_FAILURE; +} diff --git a/src/boost/libs/context/example/callcc/segmented.cpp b/src/boost/libs/context/example/callcc/segmented.cpp new file mode 100644 index 000000000..c70de99c3 --- /dev/null +++ b/src/boost/libs/context/example/callcc/segmented.cpp @@ -0,0 +1,51 @@ + +// Copyright Oliver Kowalke 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> +#include <memory> + +#include <boost/context/continuation.hpp> + +namespace ctx = boost::context; + +#ifdef BOOST_MSVC //MS VisualStudio +__declspec(noinline) void access( char *buf); +#else // GCC +void access( char *buf) __attribute__ ((noinline)); +#endif +void access( char *buf) { + buf[0] = '\0'; +} + +void bar( int i) { + char buf[4 * 1024]; + if ( i > 0) { + access( buf); + std::cout << i << ". iteration" << std::endl; + bar( i - 1); + } +} + +int main() { + int count = 100*1024; +#if defined(BOOST_USE_SEGMENTED_STACKS) + std::cout << "using segmented_stack stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, "; + std::cout << "initial stack size = " << ctx::segmented_stack::traits_type::default_size() / 1024 << "kB" << std::endl; + std::cout << "application should not fail" << std::endl; +#else + std::cout << "using standard stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, "; + std::cout << "initial stack size = " << ctx::fixedsize_stack::traits_type::default_size() / 1024 << "kB" << std::endl; + std::cout << "application might fail" << std::endl; +#endif + ctx::continuation c = ctx::callcc( + [count](ctx::continuation && c){ + bar( count); + return std::move( c); + }); + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/callcc/stack.cpp b/src/boost/libs/context/example/callcc/stack.cpp new file mode 100644 index 000000000..887932650 --- /dev/null +++ b/src/boost/libs/context/example/callcc/stack.cpp @@ -0,0 +1,25 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> + +#include <boost/context/continuation.hpp> + +namespace ctx = boost::context; + +int main() { + std::cout << "minimum stack size: " << ctx::stack_traits::minimum_size() << " byte\n"; + std::cout << "default stack size: " << ctx::stack_traits::default_size() << " byte\n"; + std::cout << "maximum stack size: "; + if ( ctx::stack_traits::is_unbounded() ) { + std::cout << "unlimited\n"; + } else { + std::cout << ctx::stack_traits::maximum_size() << " byte\n"; + } + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/callcc/throw.cpp b/src/boost/libs/context/example/callcc/throw.cpp new file mode 100644 index 000000000..723a956b6 --- /dev/null +++ b/src/boost/libs/context/example/callcc/throw.cpp @@ -0,0 +1,47 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <exception> +#include <iostream> +#include <stdexcept> +#include <string> + +#include <boost/context/continuation.hpp> + +namespace ctx = boost::context; + +struct my_exception : public std::runtime_error { + ctx::continuation c; + my_exception( ctx::continuation && c_, std::string const& what) : + std::runtime_error{ what }, + c{ std::move( c_) } { + } +}; + +int main() { + ctx::continuation c = ctx::callcc([](ctx::continuation && c) { + for (;;) { + try { + std::cout << "entered" << std::endl; + c = c.resume(); + } catch ( my_exception & ex) { + std::cerr << "my_exception: " << ex.what() << std::endl; + return std::move( ex.c); + } + } + return std::move( c); + }); + c = c.resume_with( + [](ctx::continuation && c){ + throw my_exception(std::move( c), "abc"); + return std::move( c); + }); + + std::cout << "main: done" << std::endl; + + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/fiber/Jamfile.v2 b/src/boost/libs/context/example/fiber/Jamfile.v2 new file mode 100644 index 000000000..e827eff6b --- /dev/null +++ b/src/boost/libs/context/example/fiber/Jamfile.v2 @@ -0,0 +1,83 @@ +# Boost.Context Library Examples Jamfile + +# Copyright Oliver Kowalke 2014. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# For more information, see http://www.boost.org/ + +import common ; +import feature ; +import indirect ; +import modules ; +import os ; +import toolset ; +import architecture ; + +project boost/context/example/fiber + : requirements + <library>/boost/context//boost_context + <toolset>gcc,<segmented-stacks>on:<cxxflags>-fsplit-stack + <toolset>gcc,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS + <toolset>clang,<segmented-stacks>on:<cxxflags>-fsplit-stack + <toolset>clang,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS + <link>static + <threading>multi + ; + +exe stack + : stack.cpp + ; + +exe jump_void + : jump_void.cpp + ; + +exe jump + : jump.cpp + ; + +exe jump_mov + : jump_mov.cpp + ; + +exe ontop_void + : ontop_void.cpp + ; + +exe throw + : throw.cpp + ; + +exe fibonacci + : fibonacci.cpp + ; + +exe parser + : parser.cpp + ; + +exe ontop + : ontop.cpp + ; + +exe endless_loop + : endless_loop.cpp + ; + +exe segmented + : segmented.cpp + ; + +exe circle + : circle.cpp + ; + +#exe backtrace +# : backtrace.cpp +# ; + +#exe echosse +# : echosse.cpp +# ; diff --git a/src/boost/libs/context/example/fiber/backtrace.cpp b/src/boost/libs/context/example/fiber/backtrace.cpp new file mode 100644 index 000000000..42c739bba --- /dev/null +++ b/src/boost/libs/context/example/fiber/backtrace.cpp @@ -0,0 +1,57 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#define UNW_LOCAL_ONLY + +#include <cstdlib> +#include <iostream> + +#include <libunwind.h> + +#include <boost/context/fiber.hpp> + +namespace ctx = boost::context; + +void backtrace() { + unw_cursor_t cursor; + unw_context_t context; + unw_getcontext( & context); + unw_init_local( & cursor, & context); + while ( 0 < unw_step( & cursor) ) { + unw_word_t offset, pc; + unw_get_reg( & cursor, UNW_REG_IP, & pc); + if ( 0 == pc) { + break; + } + std::cout << "0x" << pc << ":"; + + char sym[256]; + if ( 0 == unw_get_proc_name( & cursor, sym, sizeof( sym), & offset) ) { + std::cout << " (" << sym << "+0x" << offset << ")" << std::endl; + } else { + std::cout << " -- error: unable to obtain symbol name for this frame" << std::endl; + } + } +} + +void bar() { + backtrace(); +} + +void foo() { + bar(); +} + +ctx::fiber f1( ctx::fiber && c) { + foo(); + return std::move( c); +} + +int main() { + ctx::fiber{ f1 }.resume(); + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/fiber/circle.cpp b/src/boost/libs/context/example/fiber/circle.cpp new file mode 100644 index 000000000..ed1cba63a --- /dev/null +++ b/src/boost/libs/context/example/fiber/circle.cpp @@ -0,0 +1,44 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> +#include <list> + +#include <boost/context/fiber.hpp> + +namespace ctx = boost::context; + +int main() { + ctx::fiber f1, f2, f3; + f3 = ctx::fiber{[&](ctx::fiber && f)->ctx::fiber{ + f2 = std::move( f); + for (;;) { + std::cout << "f3\n"; + f2 = std::move( f1).resume(); + } + return {}; + }}; + f2 = ctx::fiber{[&](ctx::fiber && f)->ctx::fiber{ + f1 = std::move( f); + for (;;) { + std::cout << "f2\n"; + f1 = std::move( f3).resume(); + } + return {}; + }}; + f1 = ctx::fiber{[&](ctx::fiber && /*main*/)->ctx::fiber{ + for (;;) { + std::cout << "f1\n"; + f3 = std::move( f2).resume(); + } + return {}; + }}; + std::move( f1).resume(); + + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/fiber/echosse.cpp b/src/boost/libs/context/example/fiber/echosse.cpp new file mode 100644 index 000000000..e4f6debae --- /dev/null +++ b/src/boost/libs/context/example/fiber/echosse.cpp @@ -0,0 +1,46 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstddef> +#include <cstdlib> +#include <cstring> +#include <iostream> +#include <emmintrin.h> + +#include <boost/context/fiber.hpp> + +namespace ctx = boost::context; + +void echoSSE( int i) { + __m128i xmm; + xmm = _mm_set_epi32( i, i + 1, i + 2, i + 3); + uint32_t v32[4]; + memcpy( & v32, & xmm, 16); + std::cout << v32[0]; + std::cout << v32[1]; + std::cout << v32[2]; + std::cout << v32[3]; +} + + +int main( int argc, char * argv[]) { + int i = 0; + ctx::fiber f{ + [&i](ctx::fiber && f) { + for (;;) { + std::cout << i; + echoSSE( i); + std::cout << " "; + f = std::move( f).resume(); + } + return std::move( f); + }}; + for (; i < 11; ++i) { + f = std::move( f).resume(); + } + std::cout << "\nmain: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/fiber/endless_loop.cpp b/src/boost/libs/context/example/fiber/endless_loop.cpp new file mode 100644 index 000000000..0ce434dd7 --- /dev/null +++ b/src/boost/libs/context/example/fiber/endless_loop.cpp @@ -0,0 +1,30 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> + +#include <boost/context/fiber.hpp> + +namespace ctx = boost::context; + +ctx::fiber bar( ctx::fiber && f) { + do { + std::cout << "bar\n"; + f = std::move( f).resume(); + } while ( f); + return std::move( f); +} + +int main() { + ctx::fiber f{ bar }; + do { + std::cout << "foo\n"; + f = std::move( f).resume(); + } while ( f); + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/fiber/fibonacci.cpp b/src/boost/libs/context/example/fiber/fibonacci.cpp new file mode 100644 index 000000000..a664c6f46 --- /dev/null +++ b/src/boost/libs/context/example/fiber/fibonacci.cpp @@ -0,0 +1,36 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> +#include <memory> + +#include <boost/context/fiber.hpp> + +namespace ctx = boost::context; + +int main() { + int a; + ctx::fiber f{ + [&a](ctx::fiber && f){ + a=0; + int b=1; + for(;;){ + f = std::move( f).resume(); + int next=a+b; + a=b; + b=next; + } + return std::move( f); + }}; + for ( int j = 0; j < 10; ++j) { + f = std::move( f).resume(); + std::cout << a << " "; + } + std::cout << std::endl; + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/fiber/jump.cpp b/src/boost/libs/context/example/fiber/jump.cpp new file mode 100644 index 000000000..59b592c15 --- /dev/null +++ b/src/boost/libs/context/example/fiber/jump.cpp @@ -0,0 +1,35 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> + +#include <boost/context/fiber.hpp> + +namespace ctx = boost::context; + +int main() { + int data = 1; + ctx::fiber f{ + [&data](ctx::fiber && f){ + std::cout << "entered first time: " << data << std::endl; + data += 2; + f = std::move( f).resume(); + std::cout << "entered second time: " << data << std::endl; + return std::move( f); + }}; + f = std::move( f).resume(); + std::cout << "returned first time: " << data << std::endl; + data += 2; + f = std::move( f).resume(); + if ( f) { + std::cout << "returned second time: " << data << std::endl; + } else { + std::cout << "returned second time: execution context terminated" << std::endl; + } + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/fiber/jump_mov.cpp b/src/boost/libs/context/example/fiber/jump_mov.cpp new file mode 100644 index 000000000..fc9bc4fe1 --- /dev/null +++ b/src/boost/libs/context/example/fiber/jump_mov.cpp @@ -0,0 +1,59 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> + +#include <boost/context/fiber.hpp> + +namespace ctx = boost::context; + +class moveable { +public: + int value; + + moveable() : + value( -1) { + } + + moveable( int v) : + value( v) { + } + + moveable( moveable && other) { + std::swap( value, other.value); + } + + moveable & operator=( moveable && other) { + if ( this == & other) return * this; + value = other.value; + other.value = -1; + return * this; + } + + moveable( moveable const& other) = delete; + moveable & operator=( moveable const& other) = delete; +}; + +int main() { + moveable data{ 1 }; + ctx::fiber f{ std::allocator_arg, ctx::fixedsize_stack{}, + [&data](ctx::fiber && f){ + std::cout << "entered first time: " << data.value << std::endl; + data = std::move( moveable{ 3 }); + f = std::move( f).resume(); + std::cout << "entered second time: " << data.value << std::endl; + data = std::move( moveable{}); + return std::move( f); + }}; + f = std::move( f).resume(); + std::cout << "returned first time: " << data.value << std::endl; + data.value = 5; + f = std::move( f).resume(); + std::cout << "returned second time: " << data.value << std::endl; + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/fiber/jump_void.cpp b/src/boost/libs/context/example/fiber/jump_void.cpp new file mode 100644 index 000000000..b4e9f39e8 --- /dev/null +++ b/src/boost/libs/context/example/fiber/jump_void.cpp @@ -0,0 +1,29 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> + +#include <boost/context/fiber.hpp> + +namespace ctx = boost::context; + +ctx::fiber f1( ctx::fiber && f) { + std::cout << "f1: entered first time" << std::endl; + f = std::move( f).resume(); + std::cout << "f1: entered second time" << std::endl; + return std::move( f); +} + +int main() { + ctx::fiber f{ f1 }; + f = std::move( f).resume(); + std::cout << "f1: returned first time" << std::endl; + f = std::move( f).resume(); + std::cout << "f1: returned second time" << std::endl; + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/fiber/ontop.cpp b/src/boost/libs/context/example/fiber/ontop.cpp new file mode 100644 index 000000000..9e4a1f40b --- /dev/null +++ b/src/boost/libs/context/example/fiber/ontop.cpp @@ -0,0 +1,41 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> +#include <tuple> + +#include <boost/context/fiber.hpp> + +namespace ctx = boost::context; + +int main() { + int data = 0; + ctx::fiber f{ [&data](ctx::fiber && f) { + std::cout << "f1: entered first time: " << data << std::endl; + data += 1; + f = std::move( f).resume(); + std::cout << "f1: entered second time: " << data << std::endl; + data += 1; + f = std::move( f).resume(); + std::cout << "f1: entered third time: " << data << std::endl; + return std::move( f); + }}; + f = std::move( f).resume(); + std::cout << "f1: returned first time: " << data << std::endl; + data += 1; + f = std::move( f).resume(); + std::cout << "f1: returned second time: " << data << std::endl; + data += 1; + f = std::move( f).resume_with([&data](ctx::fiber && f){ + std::cout << "f2: entered: " << data << std::endl; + data = -1; + return std::move( f); + }); + std::cout << "f1: returned third time" << std::endl; + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/fiber/ontop_void.cpp b/src/boost/libs/context/example/fiber/ontop_void.cpp new file mode 100644 index 000000000..b43cd2d78 --- /dev/null +++ b/src/boost/libs/context/example/fiber/ontop_void.cpp @@ -0,0 +1,41 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> +#include <tuple> + +#include <boost/context/fiber.hpp> + +namespace ctx = boost::context; + +ctx::fiber f1( ctx::fiber && f) { + std::cout << "f1: entered first time" << std::endl; + f = std::move( f).resume(); + std::cout << "f1: entered second time" << std::endl; + f = std::move( f).resume(); + std::cout << "f1: entered third time" << std::endl; + return std::move( f); +} + +ctx::fiber f2( ctx::fiber && f) { + std::cout << "f2: entered" << std::endl; + return std::move( f); +} + +int main() { + ctx::fiber f{ f1 }; + f = std::move( f).resume(); + std::cout << "f1: returned first time" << std::endl; + f = std::move( f).resume(); + std::cout << "f1: returned second time" << std::endl; + f = std::move( f).resume_with( f2); + std::cout << "f1: returned third time" << std::endl; + + std::cout << "main: done" << std::endl; + + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/fiber/parser.cpp b/src/boost/libs/context/example/fiber/parser.cpp new file mode 100644 index 000000000..fb1121b5c --- /dev/null +++ b/src/boost/libs/context/example/fiber/parser.cpp @@ -0,0 +1,127 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdio> +#include <cstdlib> +#include <exception> +#include <functional> +#include <iostream> +#include <memory> +#include <sstream> + +#include <boost/context/fiber.hpp> + +namespace ctx = boost::context; + +/* + * grammar: + * P ---> E '\0' + * E ---> T {('+'|'-') T} + * T ---> S {('*'|'/') S} + * S ---> digit | '(' E ')' + */ +class Parser{ + char next; + std::istream& is; + std::function<void(char)> cb; + + char pull(){ + return std::char_traits<char>::to_char_type(is.get()); + } + + void scan(){ + do{ + next=pull(); + } + while(isspace(next)); + } + +public: + Parser(std::istream& is_,std::function<void(char)> cb_) : + next(), is(is_), cb(cb_) + {} + + void run() { + scan(); + E(); + } + +private: + void E(){ + T(); + while (next=='+'||next=='-'){ + cb(next); + scan(); + T(); + } + } + + void T(){ + S(); + while (next=='*'||next=='/'){ + cb(next); + scan(); + S(); + } + } + + void S(){ + if (isdigit(next)){ + cb(next); + scan(); + } + else if(next=='('){ + cb(next); + scan(); + E(); + if (next==')'){ + cb(next); + scan(); + }else{ + throw std::runtime_error("parsing failed"); + } + } + else{ + throw std::runtime_error("parsing failed"); + } + } +}; + +int main() { + try { + std::istringstream is("1+1"); + // user-code pulls parsed data from parser + // invert control flow + char c; + bool done = false; + // execute parser in new execution context + ctx::fiber source{[&is,&c,&done](ctx::fiber && sink){ + // create parser with callback function + Parser p( is, + [&sink,&c](char c_){ + // resume main execution context + c = c_; + sink = std::move( sink).resume(); + }); + // start recursive parsing + p.run(); + // signal termination + done = true; + // resume main execution context + return std::move(sink); + }}; + source = std::move( source).resume(); + while(!done){ + printf("Parsed: %c\n",c); + source = std::move( source).resume(); + } + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; + } catch (std::exception const& e) { + std::cerr << "exception: " << e.what() << std::endl; + } + return EXIT_FAILURE; +} diff --git a/src/boost/libs/context/example/fiber/segmented.cpp b/src/boost/libs/context/example/fiber/segmented.cpp new file mode 100644 index 000000000..3d1a5c344 --- /dev/null +++ b/src/boost/libs/context/example/fiber/segmented.cpp @@ -0,0 +1,51 @@ + +// Copyright Oliver Kowalke 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> +#include <memory> + +#include <boost/context/fiber.hpp> + +namespace ctx = boost::context; + +#ifdef BOOST_MSVC //MS VisualStudio +__declspec(noinline) void access( char *buf); +#else // GCC +void access( char *buf) __attribute__ ((noinline)); +#endif +void access( char *buf) { + buf[0] = '\0'; +} + +void bar( int i) { + char buf[4 * 1024]; + if ( i > 0) { + access( buf); + std::cout << i << ". iteration" << std::endl; + bar( i - 1); + } +} + +int main() { + int count = 100*1024; +#if defined(BOOST_USE_SEGMENTED_STACKS) + std::cout << "using segmented_stack stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, "; + std::cout << "initial stack size = " << ctx::segmented_stack::traits_type::default_size() / 1024 << "kB" << std::endl; + std::cout << "application should not fail" << std::endl; +#else + std::cout << "using standard stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, "; + std::cout << "initial stack size = " << ctx::fixedsize_stack::traits_type::default_size() / 1024 << "kB" << std::endl; + std::cout << "application might fail" << std::endl; +#endif + ctx::fiber{ + [count](ctx::fiber && f){ + bar( count); + return std::move( f); + }}.resume(); + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/fiber/stack.cpp b/src/boost/libs/context/example/fiber/stack.cpp new file mode 100644 index 000000000..887932650 --- /dev/null +++ b/src/boost/libs/context/example/fiber/stack.cpp @@ -0,0 +1,25 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <iostream> + +#include <boost/context/continuation.hpp> + +namespace ctx = boost::context; + +int main() { + std::cout << "minimum stack size: " << ctx::stack_traits::minimum_size() << " byte\n"; + std::cout << "default stack size: " << ctx::stack_traits::default_size() << " byte\n"; + std::cout << "maximum stack size: "; + if ( ctx::stack_traits::is_unbounded() ) { + std::cout << "unlimited\n"; + } else { + std::cout << ctx::stack_traits::maximum_size() << " byte\n"; + } + std::cout << "main: done" << std::endl; + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/example/fiber/throw.cpp b/src/boost/libs/context/example/fiber/throw.cpp new file mode 100644 index 000000000..e5f1d6f65 --- /dev/null +++ b/src/boost/libs/context/example/fiber/throw.cpp @@ -0,0 +1,45 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstdlib> +#include <exception> +#include <iostream> +#include <stdexcept> +#include <string> + +#include <boost/context/fiber.hpp> + +namespace ctx = boost::context; + +struct my_exception : public std::runtime_error { + ctx::fiber f; + my_exception( ctx::fiber && f_, std::string const& what) : + std::runtime_error{ what }, + f{ std::move( f_) } { + } +}; + +int main() { + ctx::fiber f{[](ctx::fiber && f) ->ctx::fiber { + std::cout << "entered" << std::endl; + try { + f = std::move( f).resume(); + } catch ( my_exception & ex) { + std::cerr << "my_exception: " << ex.what() << std::endl; + return std::move( ex.f); + } + return {}; + }}; + f = std::move( f).resume(); + f = std::move( f).resume_with([](ctx::fiber && f) ->ctx::fiber { + throw my_exception(std::move( f), "abc"); + return {}; + }); + + std::cout << "main: done" << std::endl; + + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/context/index.html b/src/boost/libs/context/index.html new file mode 100644 index 000000000..0ade6cbd2 --- /dev/null +++ b/src/boost/libs/context/index.html @@ -0,0 +1,14 @@ +<html> +<head> +<meta http-equiv="refresh" content="0; URL=doc/html/index.html"> +</head> +<body> +Automatic redirection failed, please go to +<a href="doc/html/index.html">doc/html/index.html</a> +<hr> +<p>© Copyright Beman Dawes, 2001</p> +<p> Distributed under the Boost Software +License, Version 1.0. (See accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt"> +www.boost.org/LICENSE_1_0.txt</a>)</p> +</body> +</html> diff --git a/src/boost/libs/context/meta/libraries.json b/src/boost/libs/context/meta/libraries.json new file mode 100644 index 000000000..ca468790e --- /dev/null +++ b/src/boost/libs/context/meta/libraries.json @@ -0,0 +1,15 @@ +{ + "key": "context", + "name": "Context", + "authors": [ + "Oliver Kowalke" + ], + "description": "(C++11) Context switching library.", + "category": [ + "Concurrent", + "System" + ], + "maintainers": [ + "Oliver Kowalke <oliver.kowalke -at- gmail.com>" + ] +} diff --git a/src/boost/libs/context/performance/callcc/Jamfile.v2 b/src/boost/libs/context/performance/callcc/Jamfile.v2 new file mode 100644 index 000000000..5471cb0f6 --- /dev/null +++ b/src/boost/libs/context/performance/callcc/Jamfile.v2 @@ -0,0 +1,34 @@ + +# Copyright Oliver Kowalke 2009. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# For more information, see http://www.boost.org/ + +import common ; +import feature ; +import indirect ; +import modules ; +import os ; +import toolset ; + +project boost/context/performance/callcc + : requirements + <library>/boost/chrono//boost_chrono + <library>/boost/context//boost_context + <library>/boost/program_options//boost_program_options + <toolset>gcc,<segmented-stacks>on:<cxxflags>-fsplit-stack + <toolset>gcc,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS + <toolset>clang,<segmented-stacks>on:<cxxflags>-fsplit-stack + <toolset>clang,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS + <link>static + <optimization>speed + <threading>multi + <variant>release + <cxxflags>-DBOOST_DISABLE_ASSERTS + ; + +exe performance + : performance.cpp + ; diff --git a/src/boost/libs/context/performance/callcc/performance.cpp b/src/boost/libs/context/performance/callcc/performance.cpp new file mode 100644 index 000000000..21de3c735 --- /dev/null +++ b/src/boost/libs/context/performance/callcc/performance.cpp @@ -0,0 +1,102 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstddef> +#include <cstdlib> +#include <iostream> +#include <stdexcept> + +#include <boost/context/continuation.hpp> +#include <boost/cstdint.hpp> +#include <boost/program_options.hpp> + +#include "../clock.hpp" +#include "../cycle.hpp" + +boost::uint64_t jobs = 1000000; + +namespace ctx = boost::context; + +static ctx::continuation foo( ctx::continuation && c) { + while ( true) { + c = c.resume(); + } + return std::move( c); +} + +duration_type measure_time() { + // cache warum-up + ctx::continuation c = ctx::callcc( foo); + c = c.resume(); + + time_point_type start( clock_type::now() ); + for ( std::size_t i = 0; i < jobs; ++i) { + c = c.resume(); + } + duration_type total = clock_type::now() - start; + total -= overhead_clock(); // overhead of measurement + total /= jobs; // loops + total /= 2; // 2x jump_fcontext + + return total; +} + +#ifdef BOOST_CONTEXT_CYCLE +cycle_type measure_cycles() { + // cache warum-up + ctx::fixedsize_stack alloc; + ctx::continuation c = ctx::callcc( std::allocator_arg, alloc, foo); + c = c.resume(); + + cycle_type start( cycles() ); + for ( std::size_t i = 0; i < jobs; ++i) { + c = c.resume(); + } + cycle_type total = cycles() - start; + total -= overhead_cycle(); // overhead of measurement + total /= jobs; // loops + total /= 2; // 2x jump_fcontext + + return total; +} +#endif + +int main( int argc, char * argv[]) { + try { + boost::program_options::options_description desc("allowed options"); + desc.add_options() + ("help", "help message") + ("jobs,j", boost::program_options::value< boost::uint64_t >( & jobs), "jobs to run"); + + boost::program_options::variables_map vm; + boost::program_options::store( + boost::program_options::parse_command_line( + argc, + argv, + desc), + vm); + boost::program_options::notify( vm); + + if ( vm.count("help") ) { + std::cout << desc << std::endl; + return EXIT_SUCCESS; + } + + boost::uint64_t res = measure_time().count(); + std::cout << "continuation: average of " << res << " nano seconds" << std::endl; +#ifdef BOOST_CONTEXT_CYCLE + res = measure_cycles(); + std::cout << "continuation: average of " << res << " cpu cycles" << std::endl; +#endif + + return EXIT_SUCCESS; + } catch ( std::exception const& e) { + std::cerr << "exception: " << e.what() << std::endl; + } catch (...) { + std::cerr << "unhandled exception" << std::endl; + } + return EXIT_FAILURE; +} diff --git a/src/boost/libs/context/performance/clock.hpp b/src/boost/libs/context/performance/clock.hpp new file mode 100644 index 000000000..d8222bb8f --- /dev/null +++ b/src/boost/libs/context/performance/clock.hpp @@ -0,0 +1,45 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +#ifndef CLOCK_H +#define CLOCK_H + +#include <algorithm> +#include <cstddef> +#include <numeric> +#include <vector> + +#include <boost/assert.hpp> +#include <boost/chrono.hpp> +#include <boost/cstdint.hpp> + +typedef boost::chrono::high_resolution_clock clock_type; +typedef clock_type::duration duration_type; +typedef clock_type::time_point time_point_type; + +struct clock_overhead +{ + boost::uint64_t operator()() + { + time_point_type start( clock_type::now() ); + return ( clock_type::now() - start).count(); + } +}; + +inline +duration_type overhead_clock() +{ + std::size_t iterations( 10); + std::vector< boost::uint64_t > overhead( iterations, 0); + for ( std::size_t i = 0; i < iterations; ++i) + std::generate( + overhead.begin(), overhead.end(), + clock_overhead() ); + BOOST_ASSERT( overhead.begin() != overhead.end() ); + return duration_type( std::accumulate( overhead.begin(), overhead.end(), 0) / iterations); +} + +#endif // CLOCK_H diff --git a/src/boost/libs/context/performance/cycle.hpp b/src/boost/libs/context/performance/cycle.hpp new file mode 100644 index 000000000..c26c85983 --- /dev/null +++ b/src/boost/libs/context/performance/cycle.hpp @@ -0,0 +1,26 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef CYCLE_H +#define CYCLE_H + +// x86_64 +// test x86_64 before i386 because icc might +// define __i686__ for x86_64 too +#if defined(__x86_64__) || defined(__x86_64) \ + || defined(__amd64__) || defined(__amd64) \ + || defined(_M_X64) || defined(_M_AMD64) +# include "cycle_x86-64.hpp" +// i386 +#elif defined(i386) || defined(__i386__) || defined(__i386) \ + || defined(__i486__) || defined(__i586__) || defined(__i686__) \ + || defined(__X86__) || defined(_X86_) || defined(__THW_INTEL__) \ + || defined(__I86__) || defined(__INTEL__) || defined(__IA32__) \ + || defined(_M_IX86) || defined(_I86_) +# include "cycle_i386.hpp" +#endif + +#endif // CYCLE_H diff --git a/src/boost/libs/context/performance/cycle_i386.hpp b/src/boost/libs/context/performance/cycle_i386.hpp new file mode 100644 index 000000000..a3eb70398 --- /dev/null +++ b/src/boost/libs/context/performance/cycle_i386.hpp @@ -0,0 +1,83 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef CYCLE_I386_H +#define CYCLE_I386_H + +#include <algorithm> +#include <numeric> +#include <cstddef> +#include <vector> + +#include <boost/assert.hpp> +#include <boost/bind.hpp> +#include <boost/cstdint.hpp> + +#define BOOST_CONTEXT_CYCLE + +typedef boost::uint64_t cycle_type; + +#if _MSC_VER +inline +cycle_type cycles() +{ + cycle_type c; + __asm { + cpuid + rdtsc + mov dword ptr [c + 0], eax + mov dword ptr [c + 4], edx + } + return c; +} +#elif defined(__GNUC__) || \ + defined(__INTEL_COMPILER) || defined(__ICC) || defined(_ECC) || defined(__ICL) +inline +cycle_type cycles() +{ + boost::uint32_t lo, hi; + + __asm__ __volatile__ ( + "xorl %%eax, %%eax\n" + "cpuid\n" + ::: "%eax", "%ebx", "%ecx", "%edx" + ); + __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi) ); + __asm__ __volatile__ ( + "xorl %%eax, %%eax\n" + "cpuid\n" + ::: "%eax", "%ebx", "%ecx", "%edx" + ); + + return ( cycle_type)hi << 32 | lo; +} +#else +# error "this compiler is not supported" +#endif + +struct cycle_overhead +{ + cycle_type operator()() + { + cycle_type start( cycles() ); + return cycles() - start; + } +}; + +inline +cycle_type overhead_cycle() +{ + std::size_t iterations( 10); + std::vector< cycle_type > overhead( iterations, 0); + for ( std::size_t i( 0); i < iterations; ++i) + std::generate( + overhead.begin(), overhead.end(), + cycle_overhead() ); + BOOST_ASSERT( overhead.begin() != overhead.end() ); + return std::accumulate( overhead.begin(), overhead.end(), 0) / iterations; +} + +#endif // CYCLE_I386_H diff --git a/src/boost/libs/context/performance/cycle_x86-64.hpp b/src/boost/libs/context/performance/cycle_x86-64.hpp new file mode 100644 index 000000000..fae0226c9 --- /dev/null +++ b/src/boost/libs/context/performance/cycle_x86-64.hpp @@ -0,0 +1,79 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef CYCLE_X86_64_H +#define CYCLE_X86_64_H + +#include <algorithm> +#include <numeric> +#include <cstddef> +#include <vector> + +#include <boost/assert.hpp> +#include <boost/bind.hpp> +#include <boost/cstdint.hpp> + +#define BOOST_CONTEXT_CYCLE + +typedef boost::uint64_t cycle_type; + +#if _MSC_VER >= 1400 +# include <intrin.h> +# pragma intrinsic(__rdtsc) +inline +cycle_type cycles() +{ return __rdtsc(); } +#elif defined(__INTEL_COMPILER) || defined(__ICC) || defined(_ECC) || defined(__ICL) +inline +cycle_type cycles() +{ return __rdtsc(); } +#elif defined(__GNUC__) || defined(__SUNPRO_C) +inline +cycle_type cycles() +{ + boost::uint32_t lo, hi; + + __asm__ __volatile__ ( + "xorl %%eax, %%eax\n" + "cpuid\n" + ::: "%rax", "%rbx", "%rcx", "%rdx" + ); + __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi) ); + __asm__ __volatile__ ( + "xorl %%eax, %%eax\n" + "cpuid\n" + ::: "%rax", "%rbx", "%rcx", "%rdx" + ); + + return ( cycle_type)hi << 32 | lo; +} +#else +# error "this compiler is not supported" +#endif + +struct cycle_overhead +{ + cycle_type operator()() + { + cycle_type start( cycles() ); + return cycles() - start; + } +}; + +inline +cycle_type overhead_cycle() +{ + std::size_t iterations( 10); + std::vector< cycle_type > overhead( iterations, 0); + for ( std::size_t i( 0); i < iterations; ++i) + std::generate( + overhead.begin(), overhead.end(), + cycle_overhead() ); + BOOST_ASSERT( overhead.begin() != overhead.end() ); + return std::accumulate( overhead.begin(), overhead.end(), 0) / iterations; +} + +#endif // CYCLE_X86_64_H diff --git a/src/boost/libs/context/performance/fcontext/Jamfile.v2 b/src/boost/libs/context/performance/fcontext/Jamfile.v2 new file mode 100644 index 000000000..eeb2a5d23 --- /dev/null +++ b/src/boost/libs/context/performance/fcontext/Jamfile.v2 @@ -0,0 +1,34 @@ + +# Copyright Oliver Kowalke 2009. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# For more information, see http://www.boost.org/ + +import common ; +import feature ; +import indirect ; +import modules ; +import os ; +import toolset ; + +project boost/context/performance/fcontext + : requirements + <library>/boost/chrono//boost_chrono + <library>/boost/context//boost_context + <library>/boost/program_options//boost_program_options + <toolset>gcc,<segmented-stacks>on:<cxxflags>-fsplit-stack + <toolset>gcc,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS + <toolset>clang,<segmented-stacks>on:<cxxflags>-fsplit-stack + <toolset>clang,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS + <link>static + <optimization>speed + <threading>multi + <variant>release + <cxxflags>-DBOOST_DISABLE_ASSERTS + ; + +exe performance + : performance.cpp + ; diff --git a/src/boost/libs/context/performance/fcontext/performance.cpp b/src/boost/libs/context/performance/fcontext/performance.cpp new file mode 100644 index 000000000..ed271dccd --- /dev/null +++ b/src/boost/libs/context/performance/fcontext/performance.cpp @@ -0,0 +1,150 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstddef> +#include <cstdlib> +#include <iostream> +#include <stdexcept> + +#include <boost/context/detail/fcontext.hpp> +#include <boost/cstdint.hpp> +#include <boost/program_options.hpp> + +#include "../clock.hpp" +#include "../cycle.hpp" + +template< std::size_t Max, std::size_t Default, std::size_t Min > +class simple_stack_allocator +{ +public: + static std::size_t maximum_stacksize() + { return Max; } + + static std::size_t default_stacksize() + { return Default; } + + static std::size_t minimum_stacksize() + { return Min; } + + void * allocate( std::size_t size) const + { + BOOST_ASSERT( minimum_stacksize() <= size); + BOOST_ASSERT( maximum_stacksize() >= size); + + void * limit = std::malloc( size); + if ( ! limit) throw std::bad_alloc(); + + return static_cast< char * >( limit) + size; + } + + void deallocate( void * vp, std::size_t size) const + { + BOOST_ASSERT( vp); + BOOST_ASSERT( minimum_stacksize() <= size); + BOOST_ASSERT( maximum_stacksize() >= size); + + void * limit = static_cast< char * >( vp) - size; + std::free( limit); + } +}; + +typedef simple_stack_allocator< + 8 * 1024 * 1024, 64 * 1024, 8 * 1024 + > stack_allocator; + +boost::uint64_t jobs = 1000000; + +static void foo( boost::context::detail::transfer_t t_) { + boost::context::detail::transfer_t t = t_; + while ( true) { + t = boost::context::detail::jump_fcontext( t.fctx, 0); + } +} + +duration_type measure_time_fc() { + stack_allocator stack_alloc; + boost::context::detail::fcontext_t ctx = boost::context::detail::make_fcontext( + stack_alloc.allocate( stack_allocator::default_stacksize() ), + stack_allocator::default_stacksize(), + foo); + + // cache warum-up + boost::context::detail::transfer_t t = boost::context::detail::jump_fcontext( ctx, 0); + + time_point_type start( clock_type::now() ); + for ( std::size_t i = 0; i < jobs; ++i) { + t = boost::context::detail::jump_fcontext( t.fctx, 0); + } + duration_type total = clock_type::now() - start; + total -= overhead_clock(); // overhead of measurement + total /= jobs; // loops + total /= 2; // 2x jump_fcontext + + return total; +} + +#ifdef BOOST_CONTEXT_CYCLE +cycle_type measure_cycles_fc() { + stack_allocator stack_alloc; + boost::context::detail::fcontext_t ctx = boost::context::detail::make_fcontext( + stack_alloc.allocate( stack_allocator::default_stacksize() ), + stack_allocator::default_stacksize(), + foo); + + // cache warum-up + boost::context::detail::transfer_t t = boost::context::detail::jump_fcontext( ctx, 0); + + cycle_type start( cycles() ); + for ( std::size_t i = 0; i < jobs; ++i) { + t = boost::context::detail::jump_fcontext( t.fctx, 0); + } + cycle_type total = cycles() - start; + total -= overhead_cycle(); // overhead of measurement + total /= jobs; // loops + total /= 2; // 2x jump_fcontext + + return total; +} +#endif + +int main( int argc, char * argv[]) +{ + try + { + boost::program_options::options_description desc("allowed options"); + desc.add_options() + ("help", "help message") + ("jobs,j", boost::program_options::value< boost::uint64_t >( & jobs), "jobs to run"); + + boost::program_options::variables_map vm; + boost::program_options::store( + boost::program_options::parse_command_line( + argc, + argv, + desc), + vm); + boost::program_options::notify( vm); + + if ( vm.count("help") ) { + std::cout << desc << std::endl; + return EXIT_SUCCESS; + } + + boost::uint64_t res = measure_time_fc().count(); + std::cout << "fcontext_t: average of " << res << " nano seconds" << std::endl; +#ifdef BOOST_CONTEXT_CYCLE + res = measure_cycles_fc(); + std::cout << "fcontext_t: average of " << res << " cpu cycles" << std::endl; +#endif + + return EXIT_SUCCESS; + } + catch ( std::exception const& e) + { std::cerr << "exception: " << e.what() << std::endl; } + catch (...) + { std::cerr << "unhandled exception" << std::endl; } + return EXIT_FAILURE; +} diff --git a/src/boost/libs/context/performance/fiber/Jamfile.v2 b/src/boost/libs/context/performance/fiber/Jamfile.v2 new file mode 100644 index 000000000..5e9f54f3b --- /dev/null +++ b/src/boost/libs/context/performance/fiber/Jamfile.v2 @@ -0,0 +1,34 @@ + +# Copyright Oliver Kowalke 2009. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# For more information, see http://www.boost.org/ + +import common ; +import feature ; +import indirect ; +import modules ; +import os ; +import toolset ; + +project boost/context/performance/fiber + : requirements + <library>/boost/chrono//boost_chrono + <library>/boost/context//boost_context + <library>/boost/program_options//boost_program_options + <toolset>gcc,<segmented-stacks>on:<cxxflags>-fsplit-stack + <toolset>gcc,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS + <toolset>clang,<segmented-stacks>on:<cxxflags>-fsplit-stack + <toolset>clang,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS + <link>static + <optimization>speed + <threading>multi + <variant>release + <cxxflags>-DBOOST_DISABLE_ASSERTS + ; + +exe performance + : performance.cpp + ; diff --git a/src/boost/libs/context/performance/fiber/performance.cpp b/src/boost/libs/context/performance/fiber/performance.cpp new file mode 100644 index 000000000..e49deecd2 --- /dev/null +++ b/src/boost/libs/context/performance/fiber/performance.cpp @@ -0,0 +1,102 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cstddef> +#include <cstdlib> +#include <iostream> +#include <stdexcept> + +#include <boost/context/fiber.hpp> +#include <boost/cstdint.hpp> +#include <boost/program_options.hpp> + +#include "../clock.hpp" +#include "../cycle.hpp" + +boost::uint64_t jobs = 1000000; + +namespace ctx = boost::context; + +static ctx::fiber foo( ctx::fiber && f) { + while ( true) { + f = std::move( f).resume(); + } + return ctx::fiber{}; +} + +duration_type measure_time() { + // cache warum-up + ctx::fiber f{ foo }; + f = std::move( f).resume(); + + time_point_type start( clock_type::now() ); + for ( std::size_t i = 0; i < jobs; ++i) { + f = std::move( f).resume(); + } + duration_type total = clock_type::now() - start; + total -= overhead_clock(); // overhead of measurement + total /= jobs; // loops + total /= 2; // 2x jump_fcontext + + return total; +} + +#ifdef BOOST_CONTEXT_CYCLE +cycle_type measure_cycles() { + // cache warum-up + ctx::fixedsize_stack alloc; + ctx::fiber f{ std::allocator_arg, alloc, foo }; + f = std::move( f).resume(); + + cycle_type start( cycles() ); + for ( std::size_t i = 0; i < jobs; ++i) { + f = std::move( f).resume(); + } + cycle_type total = cycles() - start; + total -= overhead_cycle(); // overhead of measurement + total /= jobs; // loops + total /= 2; // 2x jump_fcontext + + return total; +} +#endif + +int main( int argc, char * argv[]) { + try { + boost::program_options::options_description desc("allowed options"); + desc.add_options() + ("help", "help message") + ("jobs,j", boost::program_options::value< boost::uint64_t >( & jobs), "jobs to run"); + + boost::program_options::variables_map vm; + boost::program_options::store( + boost::program_options::parse_command_line( + argc, + argv, + desc), + vm); + boost::program_options::notify( vm); + + if ( vm.count("help") ) { + std::cout << desc << std::endl; + return EXIT_SUCCESS; + } + + boost::uint64_t res = measure_time().count(); + std::cout << "fiber: average of " << res << " nano seconds" << std::endl; +#ifdef BOOST_CONTEXT_CYCLE + res = measure_cycles(); + std::cout << "fiber: average of " << res << " cpu cycles" << std::endl; +#endif + + return EXIT_SUCCESS; + } catch ( std::exception const& e) { + std::cerr << "exception: " << e.what() << std::endl; + } catch (...) { + std::cerr << "unhandled exception" << std::endl; + } + return EXIT_FAILURE; +} diff --git a/src/boost/libs/context/src/asm/jump_arm64_aapcs_elf_gas.S b/src/boost/libs/context/src/asm/jump_arm64_aapcs_elf_gas.S new file mode 100644 index 000000000..cefd1830d --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_arm64_aapcs_elf_gas.S @@ -0,0 +1,114 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | d8 | d9 | d10 | d11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | d12 | d13 | d14 | d15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | x19 | x20 | x21 | x22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | x23 | x24 | x25 | x26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | x27 | x28 | FP | LR | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | | | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| | | * + * ------------------------------------------------- * + * | PC | align | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "jump_arm64_aapcs_elf_gas.S" +.text +.align 2 +.global jump_fcontext +.type jump_fcontext, %function +jump_fcontext: + # prepare stack for GP + FPU + sub sp, sp, #0xb0 + + # save d8 - d15 + stp d8, d9, [sp, #0x00] + stp d10, d11, [sp, #0x10] + stp d12, d13, [sp, #0x20] + stp d14, d15, [sp, #0x30] + + # save x19-x30 + stp x19, x20, [sp, #0x40] + stp x21, x22, [sp, #0x50] + stp x23, x24, [sp, #0x60] + stp x25, x26, [sp, #0x70] + stp x27, x28, [sp, #0x80] + stp x29, x30, [sp, #0x90] + + # save LR as PC + str x30, [sp, #0xa0] + + # store RSP (pointing to context-data) in X0 + mov x4, sp + + # restore RSP (pointing to context-data) from X1 + mov sp, x0 + + # load d8 - d15 + ldp d8, d9, [sp, #0x00] + ldp d10, d11, [sp, #0x10] + ldp d12, d13, [sp, #0x20] + ldp d14, d15, [sp, #0x30] + + # load x19-x30 + ldp x19, x20, [sp, #0x40] + ldp x21, x22, [sp, #0x50] + ldp x23, x24, [sp, #0x60] + ldp x25, x26, [sp, #0x70] + ldp x27, x28, [sp, #0x80] + ldp x29, x30, [sp, #0x90] + + # return transfer_t from jump + # pass transfer_t as first arg in context function + # X0 == FCTX, X1 == DATA + mov x0, x4 + + # load pc + ldr x4, [sp, #0xa0] + + # restore stack from GP + FPU + add sp, sp, #0xb0 + + ret x4 +.size jump_fcontext,.-jump_fcontext +# Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/jump_arm64_aapcs_macho_gas.S b/src/boost/libs/context/src/asm/jump_arm64_aapcs_macho_gas.S new file mode 100644 index 000000000..31738f745 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_arm64_aapcs_macho_gas.S @@ -0,0 +1,109 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | d8 | d9 | d10 | d11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | d12 | d13 | d14 | d15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | x19 | x20 | x21 | x22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | x23 | x24 | x25 | x26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | x27 | x28 | FP | LR | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | | | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| | | * + * ------------------------------------------------- * + * | PC | align | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.globl _jump_fcontext +.balign 16 +_jump_fcontext: + ; prepare stack for GP + FPU + sub sp, sp, #0xb0 + + ; save d8 - d15 + stp d8, d9, [sp, #0x00] + stp d10, d11, [sp, #0x10] + stp d12, d13, [sp, #0x20] + stp d14, d15, [sp, #0x30] + + ; save x19-x30 + stp x19, x20, [sp, #0x40] + stp x21, x22, [sp, #0x50] + stp x23, x24, [sp, #0x60] + stp x25, x26, [sp, #0x70] + stp x27, x28, [sp, #0x80] + stp fp, lr, [sp, #0x90] + + ; save LR as PC + str lr, [sp, #0xa0] + + ; store RSP (pointing to context-data) in X0 + mov x4, sp + + ; restore RSP (pointing to context-data) from X1 + mov sp, x0 + + ; load d8 - d15 + ldp d8, d9, [sp, #0x00] + ldp d10, d11, [sp, #0x10] + ldp d12, d13, [sp, #0x20] + ldp d14, d15, [sp, #0x30] + + ; load x19-x30 + ldp x19, x20, [sp, #0x40] + ldp x21, x22, [sp, #0x50] + ldp x23, x24, [sp, #0x60] + ldp x25, x26, [sp, #0x70] + ldp x27, x28, [sp, #0x80] + ldp fp, lr, [sp, #0x90] + + ; return transfer_t from jump + ; pass transfer_t as first arg in context function + ; X0 == FCTX, X1 == DATA + mov x0, x4 + + ; load pc + ldr x4, [sp, #0xa0] + + ; restore stack from GP + FPU + add sp, sp, #0xb0 + + ret x4 diff --git a/src/boost/libs/context/src/asm/jump_arm_aapcs_elf_gas.S b/src/boost/libs/context/src/asm/jump_arm_aapcs_elf_gas.S new file mode 100644 index 000000000..86efe9d82 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_arm_aapcs_elf_gas.S @@ -0,0 +1,88 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * |hiddn| v1 | v2 | v3 | v4 | v5 | v6 | v7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | v8 | lr | pc | FCTX| DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "jump_arm_aapcs_elf_gas.S" +.text +.globl jump_fcontext +.align 2 +.type jump_fcontext,%function +.syntax unified +jump_fcontext: + @ save LR as PC + push {lr} + @ save hidden,V1-V8,LR + push {a1,v1-v8,lr} + + @ prepare stack for FPU + sub sp, sp, #64 +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) + @ save S16-S31 + vstmia sp, {d8-d15} +#endif + + @ store RSP (pointing to context-data) in A1 + mov a1, sp + + @ restore RSP (pointing to context-data) from A2 + mov sp, a2 + +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) + @ restore S16-S31 + vldmia sp, {d8-d15} +#endif + @ prepare stack for FPU + add sp, sp, #64 + + @ restore hidden,V1-V8,LR + pop {a4,v1-v8,lr} + + @ return transfer_t from jump + str a1, [a4, #0] + str a3, [a4, #4] + @ pass transfer_t as first arg in context function + @ A1 == FCTX, A2 == DATA + mov a2, a3 + + @ restore PC + pop {pc} +.size jump_fcontext,.-jump_fcontext + +@ Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/jump_arm_aapcs_macho_gas.S b/src/boost/libs/context/src/asm/jump_arm_aapcs_macho_gas.S new file mode 100644 index 000000000..8edd0d7de --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_arm_aapcs_macho_gas.S @@ -0,0 +1,95 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | sjlj|hiddn| v1 | v2 | v3 | v4 | v5 | v6 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | v7 | v8 | lr | pc | FCTX| DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.globl _jump_fcontext +.align 2 +_jump_fcontext: + @ save LR as PC + push {lr} + @ save hidden,V1-V8,LR + push {a1,v1-v8,lr} + + @ locate TLS to save/restore SjLj handler + mrc p15, 0, v2, c13, c0, #3 + bic v2, v2, #3 + + @ load TLS[__PTK_LIBC_DYLD_Unwind_SjLj_Key] + ldr v1, [v2, #8] + @ save SjLj handler + push {v1} + + @ prepare stack for FPU + sub sp, sp, #64 +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) + @ save S16-S31 + vstmia sp, {d8-d15} +#endif + + @ store RSP (pointing to context-data) in A1 + mov a1, sp + + @ restore RSP (pointing to context-data) from A2 + mov sp, a2 + +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) + @ restore S16-S31 + vldmia sp, {d8-d15} +#endif + @ prepare stack for FPU + add sp, sp, #64 + + @ r#estore SjLj handler + pop {v1} + @ store SjLj handler in TLS + str v1, [v2, #8] + + @ restore hidden,V1-V8,LR + pop {a4,v1-v8,lr} + + @ return transfer_t from jump + str a1, [a4, #0] + str a3, [a4, #4] + @ pass transfer_t as first arg in context function + @ A1 == FCTX, A2 == DATA + mov a2, a3 + + @ restore PC + pop {pc} diff --git a/src/boost/libs/context/src/asm/jump_arm_aapcs_pe_armasm.asm b/src/boost/libs/context/src/asm/jump_arm_aapcs_pe_armasm.asm new file mode 100644 index 000000000..bca923c6c --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_arm_aapcs_pe_armasm.asm @@ -0,0 +1,81 @@ +;/* +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) +;*/ + +; ******************************************************* +; * * +; * ------------------------------------------------- * +; * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +; * ------------------------------------------------- * +; * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * +; * ------------------------------------------------- * +; * |deall|limit| base|hiddn| v1 | v2 | v3 | v4 | * +; * ------------------------------------------------- * +; * ------------------------------------------------- * +; * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +; * ------------------------------------------------- * +; * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * +; * ------------------------------------------------- * +; * | v5 | v6 | v7 | v8 | lr | pc | FCTX| DATA| * +; * ------------------------------------------------- * +; * * +; ******************************************************* + + AREA |.text|, CODE + ALIGN 4 + EXPORT jump_fcontext + +jump_fcontext PROC + ; save LR as PC + push {lr} + ; save hidden,V1-V8,LR + push {a1,v1-v8,lr} + + ; load TIB to save/restore thread size and limit. + ; we do not need preserve CPU flag and can use it's arg register + mrc p15, #0, v1, c13, c0, #2 + + ; save current stack base + ldr a5, [v1, #0x04] + push {a5} + ; save current stack limit + ldr a5, [v1, #0x08] + push {a5} + ; save current deallocation stack + ldr a5, [v1, #0xe0c] + push {a5} + + ; store RSP (pointing to context-data) in A1 + mov a1, sp + + ; restore RSP (pointing to context-data) from A2 + mov sp, a2 + + ; restore deallocation stack + pop {a5} + str a5, [v1, #0xe0c] + ; restore stack limit + pop {a5} + str a5, [v1, #0x08] + ; restore stack base + pop {a5} + str a5, [v1, #0x04] + + ; restore hidden,V1-V8,LR + pop {a4,v1-v8,lr} + + ; return transfer_t from jump + str a1, [a4, #0] + str a3, [a4, #4] + ; pass transfer_t as first arg in context function + ; A1 == FCTX, A2 == DATA + mov a2, a3 + + ; restore PC + pop {pc} + + ENDP + END diff --git a/src/boost/libs/context/src/asm/jump_combined_sysv_macho_gas.S b/src/boost/libs/context/src/asm/jump_combined_sysv_macho_gas.S new file mode 100644 index 000000000..1d27afad1 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_combined_sysv_macho_gas.S @@ -0,0 +1,20 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__i386__) + #include "jump_i386_sysv_macho_gas.S" +#elif defined(__x86_64__) + #include "jump_x86_64_sysv_macho_gas.S" +#elif defined(__ppc__) + #include "jump_ppc32_sysv_macho_gas.S" +#elif defined(__ppc64__) + #include "jump_ppc64_sysv_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/src/boost/libs/context/src/asm/jump_i386_ms_pe_gas.asm b/src/boost/libs/context/src/asm/jump_i386_ms_pe_gas.asm new file mode 100644 index 000000000..bf5c75a49 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_i386_ms_pe_gas.asm @@ -0,0 +1,123 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* --------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* --------------------------------------------------------------------------------- * +* | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | * +* --------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | * +* --------------------------------------------------------------------------------- * +* --------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* --------------------------------------------------------------------------------- * +* | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | * +* --------------------------------------------------------------------------------- * +* | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| * +* --------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "jump_i386_ms_pe_gas.asm" +.text +.p2align 4,,15 + +/* mark as using no unregistered SEH handlers */ +.globl @feat.00 +.def @feat.00; .scl 3; .type 0; .endef +.set @feat.00, 1 + +.globl _jump_fcontext +.def _jump_fcontext; .scl 2; .type 32; .endef +_jump_fcontext: + /* prepare stack */ + leal -0x2c(%esp), %esp + +#if !defined(BOOST_USE_TSX) + /* save MMX control- and status-word */ + stmxcsr (%esp) + /* save x87 control-word */ + fnstcw 0x4(%esp) +#endif + + /* load NT_TIB */ + movl %fs:(0x18), %edx + /* load fiber local storage */ + movl 0x10(%edx), %eax + movl %eax, 0x8(%esp) + /* load current dealloction stack */ + movl 0xe0c(%edx), %eax + movl %eax, 0xc(%esp) + /* load current stack limit */ + movl 0x8(%edx), %eax + movl %eax, 0x10(%esp) + /* load current stack base */ + movl 0x4(%edx), %eax + movl %eax, 0x14(%esp) + /* load current SEH exception list */ + movl (%edx), %eax + movl %eax, 0x18(%esp) + + movl %edi, 0x1c(%esp) /* save EDI */ + movl %esi, 0x20(%esp) /* save ESI */ + movl %ebx, 0x24(%esp) /* save EBX */ + movl %ebp, 0x28(%esp) /* save EBP */ + + /* store ESP (pointing to context-data) in EAX */ + movl %esp, %eax + + /* firstarg of jump_fcontext() == fcontext to jump to */ + movl 0x30(%esp), %ecx + + /* restore ESP (pointing to context-data) from ECX */ + movl %ecx, %esp + +#if !defined(BOOST_USE_TSX) + /* restore MMX control- and status-word */ + ldmxcsr (%esp) + /* restore x87 control-word */ + fldcw 0x4(%esp) +#endif + + /* restore NT_TIB into EDX */ + movl %fs:(0x18), %edx + /* restore fiber local storage */ + movl 0x8(%esp), %ecx + movl %ecx, 0x10(%edx) + /* restore current deallocation stack */ + movl 0xc(%esp), %ecx + movl %ecx, 0xe0c(%edx) + /* restore current stack limit */ + movl 0x10(%esp), %ecx + movl %ecx, 0x8(%edx) + /* restore current stack base */ + movl 0x14(%esp), %ecx + movl %ecx, 0x4(%edx) + /* restore current SEH exception list */ + movl 0x18(%esp), %ecx + movl %ecx, (%edx) + + movl 0x2c(%esp), %ecx /* restore EIP */ + + movl 0x1c(%esp), %edi /* restore EDI */ + movl 0x20(%esp), %esi /* restore ESI */ + movl 0x24(%esp), %ebx /* restore EBX */ + movl 0x28(%esp), %ebp /* restore EBP */ + + /* prepare stack */ + leal 0x30(%esp), %esp + + /* return transfer_t */ + /* FCTX == EAX, DATA == EDX */ + movl 0x34(%eax), %edx + + /* jump to context */ + jmp *%ecx + +.section .drectve +.ascii " -export:\"_jump_fcontext\"" diff --git a/src/boost/libs/context/src/asm/jump_i386_ms_pe_masm.asm b/src/boost/libs/context/src/asm/jump_i386_ms_pe_masm.asm new file mode 100644 index 000000000..7a9e848f1 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_i386_ms_pe_masm.asm @@ -0,0 +1,116 @@ + +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) + +; --------------------------------------------------------------------------------- +; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +; --------------------------------------------------------------------------------- +; | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | +; --------------------------------------------------------------------------------- +; | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | +; --------------------------------------------------------------------------------- +; --------------------------------------------------------------------------------- +; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | +; --------------------------------------------------------------------------------- +; | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | +; --------------------------------------------------------------------------------- +; | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| +; --------------------------------------------------------------------------------- + +.386 +.XMM +.model flat, c +.code + +jump_fcontext PROC BOOST_CONTEXT_EXPORT + ; prepare stack + lea esp, [esp-02ch] + +IFNDEF BOOST_USE_TSX + ; save MMX control- and status-word + stmxcsr [esp] + ; save x87 control-word + fnstcw [esp+04h] +ENDIF + + assume fs:nothing + ; load NT_TIB into ECX + mov edx, fs:[018h] + assume fs:error + ; load fiber local storage + mov eax, [edx+010h] + mov [esp+08h], eax + ; load current deallocation stack + mov eax, [edx+0e0ch] + mov [esp+0ch], eax + ; load current stack limit + mov eax, [edx+08h] + mov [esp+010h], eax + ; load current stack base + mov eax, [edx+04h] + mov [esp+014h], eax + ; load current SEH exception list + mov eax, [edx] + mov [esp+018h], eax + + mov [esp+01ch], edi ; save EDI + mov [esp+020h], esi ; save ESI + mov [esp+024h], ebx ; save EBX + mov [esp+028h], ebp ; save EBP + + ; store ESP (pointing to context-data) in EAX + mov eax, esp + + ; firstarg of jump_fcontext() == fcontext to jump to + mov ecx, [esp+030h] + + ; restore ESP (pointing to context-data) from ECX + mov esp, ecx + +IFNDEF BOOST_USE_TSX + ; restore MMX control- and status-word + ldmxcsr [esp] + ; restore x87 control-word + fldcw [esp+04h] +ENDIF + + assume fs:nothing + ; load NT_TIB into EDX + mov edx, fs:[018h] + assume fs:error + ; restore fiber local storage + mov ecx, [esp+08h] + mov [edx+010h], ecx + ; restore current deallocation stack + mov ecx, [esp+0ch] + mov [edx+0e0ch], ecx + ; restore current stack limit + mov ecx, [esp+010h] + mov [edx+08h], ecx + ; restore current stack base + mov ecx, [esp+014h] + mov [edx+04h], ecx + ; restore current SEH exception list + mov ecx, [esp+018h] + mov [edx], ecx + + mov ecx, [esp+02ch] ; restore EIP + + mov edi, [esp+01ch] ; restore EDI + mov esi, [esp+020h] ; restore ESI + mov ebx, [esp+024h] ; restore EBX + mov ebp, [esp+028h] ; restore EBP + + ; prepare stack + lea esp, [esp+030h] + + ; return transfer_t + ; FCTX == EAX, DATA == EDX + mov edx, [eax+034h] + + ; jump to context + jmp ecx +jump_fcontext ENDP +END diff --git a/src/boost/libs/context/src/asm/jump_i386_sysv_elf_gas.S b/src/boost/libs/context/src/asm/jump_i386_sysv_elf_gas.S new file mode 100644 index 000000000..b96d4b5c0 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_i386_sysv_elf_gas.S @@ -0,0 +1,83 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | hidden | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | | * + * ---------------------------------------------------------------------------------- * + * | to | data | | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.file "jump_i386_sysv_elf_gas.S" +.text +.globl jump_fcontext +.align 2 +.type jump_fcontext,@function +jump_fcontext: + leal -0x18(%esp), %esp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + stmxcsr (%esp) /* save MMX control- and status-word */ + fnstcw 0x4(%esp) /* save x87 control-word */ +#endif + + movl %edi, 0x8(%esp) /* save EDI */ + movl %esi, 0xc(%esp) /* save ESI */ + movl %ebx, 0x10(%esp) /* save EBX */ + movl %ebp, 0x14(%esp) /* save EBP */ + + /* store ESP (pointing to context-data) in ECX */ + movl %esp, %ecx + + /* first arg of jump_fcontext() == fcontext to jump to */ + movl 0x20(%esp), %eax + + /* second arg of jump_fcontext() == data to be transferred */ + movl 0x24(%esp), %edx + + /* restore ESP (pointing to context-data) from EAX */ + movl %eax, %esp + + /* address of returned transport_t */ + movl 0x1c(%esp), %eax + /* return parent fcontext_t */ + movl %ecx, (%eax) + /* return data */ + movl %edx, 0x4(%eax) + + movl 0x18(%esp), %ecx /* restore EIP */ + +#if !defined(BOOST_USE_TSX) + ldmxcsr (%esp) /* restore MMX control- and status-word */ + fldcw 0x4(%esp) /* restore x87 control-word */ +#endif + + movl 0x8(%esp), %edi /* restore EDI */ + movl 0xc(%esp), %esi /* restore ESI */ + movl 0x10(%esp), %ebx /* restore EBX */ + movl 0x14(%esp), %ebp /* restore EBP */ + + leal 0x20(%esp), %esp /* prepare stack */ + + /* jump to context */ + jmp *%ecx +.size jump_fcontext,.-jump_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/jump_i386_sysv_macho_gas.S b/src/boost/libs/context/src/asm/jump_i386_sysv_macho_gas.S new file mode 100644 index 000000000..8ab7c6f29 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_i386_sysv_macho_gas.S @@ -0,0 +1,74 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | to | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | | * + * ---------------------------------------------------------------------------------- * + * | data | | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.text +.globl _jump_fcontext +.align 2 +_jump_fcontext: + leal -0x18(%esp), %esp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + stmxcsr (%esp) /* save MMX control- and status-word */ + fnstcw 0x4(%esp) /* save x87 control-word */ +#endif + + movl %edi, 0x8(%esp) /* save EDI */ + movl %esi, 0xc(%esp) /* save ESI */ + movl %ebx, 0x10(%esp) /* save EBX */ + movl %ebp, 0x14(%esp) /* save EBP */ + + /* store ESP (pointing to context-data) in ECX */ + movl %esp, %ecx + + /* first arg of jump_fcontext() == fcontext to jump to */ + movl 0x1c(%esp), %eax + + /* second arg of jump_fcontext() == data to be transferred */ + movl 0x20(%esp), %edx + + /* restore ESP (pointing to context-data) from EAX */ + movl %eax, %esp + + /* return parent fcontext_t */ + movl %ecx, %eax + /* returned data is stored in EDX */ + + movl 0x18(%esp), %ecx /* restore EIP */ + +#if !defined(BOOST_USE_TSX) + ldmxcsr (%esp) /* restore MMX control- and status-word */ + fldcw 0x4(%esp) /* restore x87 control-word */ +#endif + + movl 0x8(%esp), %edi /* restore EDI */ + movl 0xc(%esp), %esi /* restore ESI */ + movl 0x10(%esp), %ebx /* restore EBX */ + movl 0x14(%esp), %ebp /* restore EBP */ + + leal 0x1c(%esp), %esp /* prepare stack */ + + /* jump to context */ + jmp *%ecx diff --git a/src/boost/libs/context/src/asm/jump_i386_x86_64_sysv_macho_gas.S b/src/boost/libs/context/src/asm/jump_i386_x86_64_sysv_macho_gas.S new file mode 100644 index 000000000..959ddac16 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_i386_x86_64_sysv_macho_gas.S @@ -0,0 +1,16 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__i386__) + #include "jump_i386_sysv_macho_gas.S" +#elif defined(__x86_64__) + #include "jump_x86_64_sysv_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/src/boost/libs/context/src/asm/jump_mips32_o32_elf_gas.S b/src/boost/libs/context/src/asm/jump_mips32_o32_elf_gas.S new file mode 100644 index 000000000..f2b8034d8 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_mips32_o32_elf_gas.S @@ -0,0 +1,119 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | F20 | F22 | F24 | F26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | F28 | F30 | S0 | S1 | S2 | S3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | S4 | S5 | S6 | S7 | FP |hiddn| RA | PC | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | ABI ARGS | GP | FCTX| DATA| | * + * ------------------------------------------------- * + * * + * *****************************************************/ + +.file "jump_mips32_o32_elf_gas.S" +.text +.globl jump_fcontext +.align 2 +.type jump_fcontext,@function +.ent jump_fcontext +jump_fcontext: + # reserve space on stack + addiu $sp, $sp, -96 + + sw $s0, 48($sp) # save S0 + sw $s1, 52($sp) # save S1 + sw $s2, 56($sp) # save S2 + sw $s3, 60($sp) # save S3 + sw $s4, 64($sp) # save S4 + sw $s5, 68($sp) # save S5 + sw $s6, 72($sp) # save S6 + sw $s7, 76($sp) # save S7 + sw $fp, 80($sp) # save FP + sw $a0, 84($sp) # save hidden, address of returned transfer_t + sw $ra, 88($sp) # save RA + sw $ra, 92($sp) # save RA as PC + +#if defined(__mips_hard_float) + s.d $f20, ($sp) # save F20 + s.d $f22, 8($sp) # save F22 + s.d $f24, 16($sp) # save F24 + s.d $f26, 24($sp) # save F26 + s.d $f28, 32($sp) # save F28 + s.d $f30, 40($sp) # save F30 +#endif + + # store SP (pointing to context-data) in A0 + move $a0, $sp + + # restore SP (pointing to context-data) from A1 + move $sp, $a1 + +#if defined(__mips_hard_float) + l.d $f20, ($sp) # restore F20 + l.d $f22, 8($sp) # restore F22 + l.d $f24, 16($sp) # restore F24 + l.d $f26, 24($sp) # restore F26 + l.d $f28, 32($sp) # restore F28 + l.d $f30, 40($sp) # restore F30 +#endif + + lw $s0, 48($sp) # restore S0 + lw $s1, 52($sp) # restore S1 + lw $s2, 56($sp) # restore S2 + lw $s3, 60($sp) # restore S3 + lw $s4, 64($sp) # restore S4 + lw $s5, 68($sp) # restore S5 + lw $s6, 72($sp) # restore S6 + lw $s7, 76($sp) # restore S7 + lw $fp, 80($sp) # restore FP + lw $v0, 84($sp) # restore hidden, address of returned transfer_t + lw $ra, 88($sp) # restore RA + + # load PC + lw $t9, 92($sp) + + # adjust stack + addiu $sp, $sp, 96 + + # return transfer_t from jump + sw $a0, ($v0) # fctx of transfer_t + sw $a2, 4($v0) # data of transfer_t + # pass transfer_t as first arg in context function + # A0 == fctx, A1 == data + move $a1, $a2 + + # jump to context + jr $t9 +.end jump_fcontext +.size jump_fcontext, .-jump_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/jump_mips64_n64_elf_gas.S b/src/boost/libs/context/src/asm/jump_mips64_n64_elf_gas.S new file mode 100644 index 000000000..5423dd4c6 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_mips64_n64_elf_gas.S @@ -0,0 +1,121 @@ +/* + Copyright Jiaxun Yang 2018. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * + * | F24 | F25 | F26 | F27 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * + * | F28 | F29 | F30 | F31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 72 | 80 | 88 | * + * ------------------------------------------------- * + * | S0 | S1 | S2 | S3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | S4 | S5 | S6 | S7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | FP | GP | RA | PC | * + * ------------------------------------------------- * + * * + * *****************************************************/ + +.file "jump_mips64_n64_elf_gas.S" +.text +.globl jump_fcontext +.align 3 +.type jump_fcontext,@function +.ent jump_fcontext +jump_fcontext: + # reserve space on stack + daddiu $sp, $sp, -160 + + sd $s0, 64($sp) # save S0 + sd $s1, 72($sp) # save S1 + sd $s2, 80($sp) # save S2 + sd $s3, 88($sp) # save S3 + sd $s4, 96($sp) # save S4 + sd $s5, 104($sp) # save S5 + sd $s6, 112($sp) # save S6 + sd $s7, 120($sp) # save S7 + sd $fp, 128($sp) # save FP + sd $ra, 144($sp) # save RA + sd $ra, 152($sp) # save RA as PC + + + s.d $f24, 0($sp) # save F24 + s.d $f25, 8($sp) # save F25 + s.d $f26, 16($sp) # save F26 + s.d $f27, 24($sp) # save F27 + s.d $f28, 32($sp) # save F28 + s.d $f29, 40($sp) # save F29 + s.d $f30, 48($sp) # save F30 + s.d $f31, 56($sp) # save F31 + + # store SP (pointing to old context-data) in v0 as return + move $v0, $sp + + # get SP (pointing to new context-data) from a0 param + move $sp, $a0 + + l.d $f24, 0($sp) # restore F24 + l.d $f25, 8($sp) # restore F25 + l.d $f26, 16($sp) # restore F26 + l.d $f27, 24($sp) # restore F27 + l.d $f28, 32($sp) # restore F28 + l.d $f29, 40($sp) # restore F29 + l.d $f30, 48($sp) # restore F30 + l.d $f31, 56($sp) # restore F31 + + ld $s0, 64($sp) # restore S0 + ld $s1, 72($sp) # restore S1 + ld $s2, 80($sp) # restore S2 + ld $s3, 88($sp) # restore S3 + ld $s4, 96($sp) # restore S4 + ld $s5, 104($sp) # restore S5 + ld $s6, 112($sp) # restore S6 + ld $s7, 120($sp) # restore S7 + ld $fp, 128($sp) # restore FP + ld $ra, 144($sp) # restore RAa + + # load PC + ld $t9, 152($sp) + + # adjust stack + daddiu $sp, $sp, 160 + + move $a0, $v0 # move old sp from v0 to a0 as param + move $v1, $a1 # move *data from a1 to v1 as return + + # jump to context + jr $t9 +.end jump_fcontext +.size jump_fcontext, .-jump_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/jump_ppc32_ppc64_sysv_macho_gas.S b/src/boost/libs/context/src/asm/jump_ppc32_ppc64_sysv_macho_gas.S new file mode 100644 index 000000000..f175e3123 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_ppc32_ppc64_sysv_macho_gas.S @@ -0,0 +1,16 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__ppc__) + #include "jump_ppc32_sysv_macho_gas.S" +#elif defined(__ppc64__) + #include "jump_ppc64_sysv_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/src/boost/libs/context/src/asm/jump_ppc32_sysv_elf_gas.S b/src/boost/libs/context/src/asm/jump_ppc32_sysv_elf_gas.S new file mode 100644 index 000000000..48e09c935 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_ppc32_sysv_elf_gas.S @@ -0,0 +1,201 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * |bchai|hiddn| fpscr | PC | CR | R14 | R15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R16 | R17 | R18 | R19 | R20 | R21 | R22 | R23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R24 | R25 | R26 | R27 | R28 | R29 | R30 | R31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------|------------ * + * | 224 | 228 | 232 | 236 | 240 | 244 | * + * ------------------------|------------ * + * | F30 | F31 |bchai| LR | * + * ------------------------|------------ * + * * + *******************************************************/ + +.file "jump_ppc32_sysv_elf_gas.S" +.text +.globl jump_fcontext +.align 2 +.type jump_fcontext,@function +jump_fcontext: + # Linux: jump_fcontext( hidden transfer_t * R3, R4, R5) + # Other: transfer_t R3:R4 = jump_fcontext( R3, R4) + + mflr %r0 # return address from LR + mffs %f0 # FPSCR + mfcr %r8 # condition register + + stwu %r1, -240(%r1) # allocate stack space, R1 % 16 == 0 + stw %r0, 244(%r1) # save LR in caller's frame + +#ifdef __linux__ + stw %r3, 4(%r1) # hidden pointer +#endif + + stfd %f0, 8(%r1) # FPSCR + stw %r0, 16(%r1) # LR as PC + stw %r8, 20(%r1) # CR + + # Save registers R14 to R31. + # Don't change R2, the thread-local storage pointer. + # Don't change R13, the small data pointer. + stw %r14, 24(%r1) + stw %r15, 28(%r1) + stw %r16, 32(%r1) + stw %r17, 36(%r1) + stw %r18, 40(%r1) + stw %r19, 44(%r1) + stw %r20, 48(%r1) + stw %r21, 52(%r1) + stw %r22, 56(%r1) + stw %r23, 60(%r1) + stw %r24, 64(%r1) + stw %r25, 68(%r1) + stw %r26, 72(%r1) + stw %r27, 76(%r1) + stw %r28, 80(%r1) + stw %r29, 84(%r1) + stw %r30, 88(%r1) + stw %r31, 92(%r1) + + # Save registers F14 to F31 in slots with 8-byte alignment. + # 4-byte alignment may stall the pipeline of some processors. + # Less than 4 may cause alignment traps. + stfd %f14, 96(%r1) + stfd %f15, 104(%r1) + stfd %f16, 112(%r1) + stfd %f17, 120(%r1) + stfd %f18, 128(%r1) + stfd %f19, 136(%r1) + stfd %f20, 144(%r1) + stfd %f21, 152(%r1) + stfd %f22, 160(%r1) + stfd %f23, 168(%r1) + stfd %f24, 176(%r1) + stfd %f25, 184(%r1) + stfd %f26, 192(%r1) + stfd %f27, 200(%r1) + stfd %f28, 208(%r1) + stfd %f29, 216(%r1) + stfd %f30, 224(%r1) + stfd %f31, 232(%r1) + + # store RSP (pointing to context-data) in R7/R6 + # restore RSP (pointing to context-data) from R4/R3 +#ifdef __linux__ + mr %r7, %r1 + mr %r1, %r4 + lwz %r3, 4(%r1) # hidden pointer +#else + mr %r6, %r1 + mr %r1, %r3 +#endif + + lfd %f0, 8(%r1) # FPSCR + lwz %r0, 16(%r1) # PC + lwz %r8, 20(%r1) # CR + + mtfsf 0xff, %f0 # restore FPSCR + mtctr %r0 # load CTR with PC + mtcr %r8 # restore CR + + # restore R14 to R31 + lwz %r14, 24(%r1) + lwz %r15, 28(%r1) + lwz %r16, 32(%r1) + lwz %r17, 36(%r1) + lwz %r18, 40(%r1) + lwz %r19, 44(%r1) + lwz %r20, 48(%r1) + lwz %r21, 52(%r1) + lwz %r22, 56(%r1) + lwz %r23, 60(%r1) + lwz %r24, 64(%r1) + lwz %r25, 68(%r1) + lwz %r26, 72(%r1) + lwz %r27, 76(%r1) + lwz %r28, 80(%r1) + lwz %r29, 84(%r1) + lwz %r30, 88(%r1) + lwz %r31, 92(%r1) + + # restore F14 to F31 + lfd %f14, 96(%r1) + lfd %f15, 104(%r1) + lfd %f16, 112(%r1) + lfd %f17, 120(%r1) + lfd %f18, 128(%r1) + lfd %f19, 136(%r1) + lfd %f20, 144(%r1) + lfd %f21, 152(%r1) + lfd %f22, 160(%r1) + lfd %f23, 168(%r1) + lfd %f24, 176(%r1) + lfd %f25, 184(%r1) + lfd %f26, 192(%r1) + lfd %f27, 200(%r1) + lfd %f28, 208(%r1) + lfd %f29, 216(%r1) + lfd %f30, 224(%r1) + lfd %f31, 232(%r1) + + # restore LR from caller's frame + lwz %r0, 244(%r1) + mtlr %r0 + + # adjust stack + addi %r1, %r1, 240 + + # return transfer_t +#ifdef __linux__ + stw %r7, 0(%r3) + stw %r5, 4(%r3) +#else + mr %r3, %r6 + # %r4, %r4 +#endif + + # jump to context + bctr +.size jump_fcontext, .-jump_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/jump_ppc32_sysv_macho_gas.S b/src/boost/libs/context/src/asm/jump_ppc32_sysv_macho_gas.S new file mode 100644 index 000000000..c555237af --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_ppc32_sysv_macho_gas.S @@ -0,0 +1,201 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/****************************************************** + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F30 | F31 | fpscr | R13 | R14 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | R31 |hiddn| CR | LR | PC |bchai|linkr| FCTX| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | | * + * ------------------------------------------------- * + * | 256 | | * + * ------------------------------------------------- * + * | DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.globl _jump_fcontext +.align 2 +_jump_fcontext: + ; reserve space on stack + subi r1, r1, 244 + + stfd f14, 0(r1) # save F14 + stfd f15, 8(r1) # save F15 + stfd f16, 16(r1) # save F16 + stfd f17, 24(r1) # save F17 + stfd f18, 32(r1) # save F18 + stfd f19, 40(r1) # save F19 + stfd f20, 48(r1) # save F20 + stfd f21, 56(r1) # save F21 + stfd f22, 64(r1) # save F22 + stfd f23, 72(r1) # save F23 + stfd f24, 80(r1) # save F24 + stfd f25, 88(r1) # save F25 + stfd f26, 96(r1) # save F26 + stfd f27, 104(r1) # save F27 + stfd f28, 112(r1) # save F28 + stfd f29, 120(r1) # save F29 + stfd f30, 128(r1) # save F30 + stfd f31, 136(r1) # save F31 + mffs f0 # load FPSCR + stfd f0, 144(r1) # save FPSCR + + stw r13, 152(r1) # save R13 + stw r14, 156(r1) # save R14 + stw r15, 160(r1) # save R15 + stw r16, 164(r1) # save R16 + stw r17, 168(r1) # save R17 + stw r18, 172(r1) # save R18 + stw r19, 176(r1) # save R19 + stw r20, 180(r1) # save R20 + stw r21, 184(r1) # save R21 + stw r22, 188(r1) # save R22 + stw r23, 192(r1) # save R23 + stw r24, 196(r1) # save R24 + stw r25, 200(r1) # save R25 + stw r26, 204(r1) # save R26 + stw r27, 208(r1) # save R27 + stw r28, 212(r1) # save R28 + stw r29, 216(r1) # save R29 + stw r30, 220(r1) # save R30 + stw r31, 224(r1) # save R31 + stw r3, 228(r1) # save hidden + + # save CR + mfcr r0 + stw r0, 232(r1) + # save LR + mflr r0 + stw r0, 236(r1) + # save LR as PC + stw r0, 240(r1) + + # store RSP (pointing to context-data) in R6 + mr r6, r1 + + # restore RSP (pointing to context-data) from R4 + mr r1, r4 + + lfd f14, 0(r1) # restore F14 + lfd f15, 8(r1) # restore F15 + lfd f16, 16(r1) # restore F16 + lfd f17, 24(r1) # restore F17 + lfd f18, 32(r1) # restore F18 + lfd f19, 40(r1) # restore F19 + lfd f20, 48(r1) # restore F20 + lfd f21, 56(r1) # restore F21 + lfd f22, 64(r1) # restore F22 + lfd f23, 72(r1) # restore F23 + lfd f24, 80(r1) # restore F24 + lfd f25, 88(r1) # restore F25 + lfd f26, 96(r1) # restore F26 + lfd f27, 104(r1) # restore F27 + lfd f28, 112(r1) # restore F28 + lfd f29, 120(r1) # restore F29 + lfd f30, 128(r1) # restore F30 + lfd f31, 136(r1) # restore F31 + lfd f0, 144(r1) # load FPSCR + mtfsf 0xff, f0 # restore FPSCR + + lwz r13, 152(r1) # restore R13 + lwz r14, 156(r1) # restore R14 + lwz r15, 160(r1) # restore R15 + lwz r16, 164(r1) # restore R16 + lwz r17, 168(r1) # restore R17 + lwz r18, 172(r1) # restore R18 + lwz r19, 176(r1) # restore R19 + lwz r20, 180(r1) # restore R20 + lwz r21, 184(r1) # restore R21 + lwz r22, 188(r1) # restore R22 + lwz r23, 192(r1) # restore R23 + lwz r24, 196(r1) # restore R24 + lwz r25, 200(r1) # restore R25 + lwz r26, 204(r1) # restore R26 + lwz r27, 208(r1) # restore R27 + lwz r28, 212(r1) # restore R28 + lwz r29, 216(r1) # restore R29 + lwz r30, 220(r1) # restore R30 + lwz r31, 224(r1) # restore R31 + lwz r3, 228(r1) # restore hidden + + # restore CR + lwz r0, 232(r1) + mtcr r0 + # restore LR + lwz r0, 236(r1) + mtlr r0 + # load PC + lwz r0, 240(r1) + # restore CTR + mtctr r0 + + # adjust stack + addi r1, r1, 244 + + # return transfer_t + stw r6, 0(r3) + stw r5, 4(r3) + + # jump to context + bctr diff --git a/src/boost/libs/context/src/asm/jump_ppc32_sysv_xcoff_gas.S b/src/boost/libs/context/src/asm/jump_ppc32_sysv_xcoff_gas.S new file mode 100644 index 000000000..5a967726a --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_ppc32_sysv_xcoff_gas.S @@ -0,0 +1,203 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/****************************************************** + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F30 | F31 | fpscr | R13 | R14 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | R31 |hiddn| CR | LR | PC |bchai|linkr| FCTX| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | | * + * ------------------------------------------------- * + * | 256 | | * + * ------------------------------------------------- * + * | DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ +.globl .jump_fcontext +.globl jump_fcontext[DS] +.align 2 +.csect jump_fcontext[DS] +jump_fcontext: + .long .jump_fcontext +.jump_fcontext: + # reserve space on stack + subi r1, r1, 244 + + stfd f14, 0(r1) # save F14 + stfd f15, 8(r1) # save F15 + stfd f16, 16(r1) # save F16 + stfd f17, 24(r1) # save F17 + stfd f18, 32(r1) # save F18 + stfd f19, 40(r1) # save F19 + stfd f20, 48(r1) # save F20 + stfd f21, 56(r1) # save F21 + stfd f22, 64(r1) # save F22 + stfd f23, 72(r1) # save F23 + stfd f24, 80(r1) # save F24 + stfd f25, 88(r1) # save F25 + stfd f26, 96(r1) # save F26 + stfd f27, 104(r1) # save F27 + stfd f28, 112(r1) # save F28 + stfd f29, 120(r1) # save F29 + stfd f30, 128(r1) # save F30 + stfd f31, 136(r1) # save F31 + mffs f0 # load FPSCR + stfd f0, 144(r1) # save FPSCR + + stw r13, 152(r1) # save R13 + stw r14, 156(r1) # save R14 + stw r15, 160(r1) # save R15 + stw r16, 164(r1) # save R16 + stw r17, 168(r1) # save R17 + stw r18, 172(r1) # save R18 + stw r19, 176(r1) # save R19 + stw r20, 180(r1) # save R20 + stw r21, 184(r1) # save R21 + stw r22, 188(r1) # save R22 + stw r23, 192(r1) # save R23 + stw r24, 196(r1) # save R24 + stw r25, 200(r1) # save R25 + stw r26, 204(r1) # save R26 + stw r27, 208(r1) # save R27 + stw r28, 212(r1) # save R28 + stw r29, 216(r1) # save R29 + stw r30, 220(r1) # save R30 + stw r31, 224(r1) # save R31 + stw r3, 228(r1) # save hidden + + # save CR + mfcr r0 + stw r0, 232(r1) + # save LR + mflr r0 + stw r0, 236(r1) + # save LR as PC + stw r0, 240(r1) + + # store RSP (pointing to context-data) in R6 + mr r6, r1 + + # restore RSP (pointing to context-data) from R4 + mr r1, r4 + + lfd f14, 0(r1) # restore F14 + lfd f15, 8(r1) # restore F15 + lfd f16, 16(r1) # restore F16 + lfd f17, 24(r1) # restore F17 + lfd f18, 32(r1) # restore F18 + lfd f19, 40(r1) # restore F19 + lfd f20, 48(r1) # restore F20 + lfd f21, 56(r1) # restore F21 + lfd f22, 64(r1) # restore F22 + lfd f23, 72(r1) # restore F23 + lfd f24, 80(r1) # restore F24 + lfd f25, 88(r1) # restore F25 + lfd f26, 96(r1) # restore F26 + lfd f27, 104(r1) # restore F27 + lfd f28, 112(r1) # restore F28 + lfd f29, 120(r1) # restore F29 + lfd f30, 128(r1) # restore F30 + lfd f31, 136(r1) # restore F31 + lfd f0, 144(r1) # load FPSCR + mtfsf 0xff, f0 # restore FPSCR + + lwz r13, 152(r1) # restore R13 + lwz r14, 156(r1) # restore R14 + lwz r15, 160(r1) # restore R15 + lwz r16, 164(r1) # restore R16 + lwz r17, 168(r1) # restore R17 + lwz r18, 172(r1) # restore R18 + lwz r19, 176(r1) # restore R19 + lwz r20, 180(r1) # restore R20 + lwz r21, 184(r1) # restore R21 + lwz r22, 188(r1) # restore R22 + lwz r23, 192(r1) # restore R23 + lwz r24, 196(r1) # restore R24 + lwz r25, 200(r1) # restore R25 + lwz r26, 204(r1) # restore R26 + lwz r27, 208(r1) # restore R27 + lwz r28, 212(r1) # restore R28 + lwz r29, 216(r1) # restore R29 + lwz r30, 220(r1) # restore R30 + lwz r31, 224(r1) # restore R31 + lwz r3, 228(r1) # restore hidden + + # restore CR + lwz r0, 232(r1) + mtcr r0 + # restore LR + lwz r0, 236(r1) + mtlr r0 + # load PC + lwz r0, 240(r1) + # restore CTR + mtctr r0 + + # adjust stack + addi r1, r1, 244 + + # return transfer_t + stw r6, 0(r3) + stw r5, 4(r3) + + # jump to context + bctr diff --git a/src/boost/libs/context/src/asm/jump_ppc64_sysv_elf_gas.S b/src/boost/libs/context/src/asm/jump_ppc64_sysv_elf_gas.S new file mode 100644 index 000000000..28907db32 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_ppc64_sysv_elf_gas.S @@ -0,0 +1,221 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | TOC | R14 | R15 | R16 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R17 | R18 | R19 | R20 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R21 | R22 | R23 | R24 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | R25 | R26 | R27 | R28 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | R29 | R30 | R31 | hidden | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | CR | LR | PC | back-chain| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | cr saved | lr saved | compiler | linker | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | TOC saved | FCTX | DATA | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "jump_ppc64_sysv_elf_gas.S" +.globl jump_fcontext +#if _CALL_ELF == 2 + .text + .align 2 +jump_fcontext: + addis %r2, %r12, .TOC.-jump_fcontext@ha + addi %r2, %r2, .TOC.-jump_fcontext@l + .localentry jump_fcontext, . - jump_fcontext +#else + .section ".opd","aw" + .align 3 +jump_fcontext: +# ifdef _CALL_LINUX + .quad .L.jump_fcontext,.TOC.@tocbase,0 + .type jump_fcontext,@function + .text + .align 2 +.L.jump_fcontext: +# else + .hidden .jump_fcontext + .globl .jump_fcontext + .quad .jump_fcontext,.TOC.@tocbase,0 + .size jump_fcontext,24 + .type .jump_fcontext,@function + .text + .align 2 +.jump_fcontext: +# endif +#endif + # reserve space on stack + subi %r1, %r1, 184 + +#if _CALL_ELF != 2 + std %r2, 0(%r1) # save TOC +#endif + std %r14, 8(%r1) # save R14 + std %r15, 16(%r1) # save R15 + std %r16, 24(%r1) # save R16 + std %r17, 32(%r1) # save R17 + std %r18, 40(%r1) # save R18 + std %r19, 48(%r1) # save R19 + std %r20, 56(%r1) # save R20 + std %r21, 64(%r1) # save R21 + std %r22, 72(%r1) # save R22 + std %r23, 80(%r1) # save R23 + std %r24, 88(%r1) # save R24 + std %r25, 96(%r1) # save R25 + std %r26, 104(%r1) # save R26 + std %r27, 112(%r1) # save R27 + std %r28, 120(%r1) # save R28 + std %r29, 128(%r1) # save R29 + std %r30, 136(%r1) # save R30 + std %r31, 144(%r1) # save R31 +#if _CALL_ELF != 2 + std %r3, 152(%r1) # save hidden +#endif + + # save CR + mfcr %r0 + std %r0, 160(%r1) + # save LR + mflr %r0 + std %r0, 168(%r1) + # save LR as PC + std %r0, 176(%r1) + + # store RSP (pointing to context-data) in R6 + mr %r6, %r1 + +#if _CALL_ELF == 2 + # restore RSP (pointing to context-data) from R3 + mr %r1, %r3 +#else + # restore RSP (pointing to context-data) from R4 + mr %r1, %r4 + + ld %r2, 0(%r1) # restore TOC +#endif + ld %r14, 8(%r1) # restore R14 + ld %r15, 16(%r1) # restore R15 + ld %r16, 24(%r1) # restore R16 + ld %r17, 32(%r1) # restore R17 + ld %r18, 40(%r1) # restore R18 + ld %r19, 48(%r1) # restore R19 + ld %r20, 56(%r1) # restore R20 + ld %r21, 64(%r1) # restore R21 + ld %r22, 72(%r1) # restore R22 + ld %r23, 80(%r1) # restore R23 + ld %r24, 88(%r1) # restore R24 + ld %r25, 96(%r1) # restore R25 + ld %r26, 104(%r1) # restore R26 + ld %r27, 112(%r1) # restore R27 + ld %r28, 120(%r1) # restore R28 + ld %r29, 128(%r1) # restore R29 + ld %r30, 136(%r1) # restore R30 + ld %r31, 144(%r1) # restore R31 +#if _CALL_ELF != 2 + ld %r3, 152(%r1) # restore hidden +#endif + + # restore CR + ld %r0, 160(%r1) + mtcr %r0 + # restore LR + ld %r0, 168(%r1) + mtlr %r0 + + # load PC + ld %r12, 176(%r1) + # restore CTR + mtctr %r12 + + # adjust stack + addi %r1, %r1, 184 + +#if _CALL_ELF == 2 + # copy transfer_t into transfer_fn arg registers + mr %r3, %r6 + # arg pointer already in %r4 + + # jump to context + bctr + .size jump_fcontext, .-jump_fcontext +#else + # zero in r3 indicates first jump to context-function + cmpdi %r3, 0 + beq use_entry_arg + + # return transfer_t + std %r6, 0(%r3) + std %r5, 8(%r3) + + # jump to context + bctr + +use_entry_arg: + # copy transfer_t into transfer_fn arg registers + mr %r3, %r6 + mr %r4, %r5 + + # jump to context + bctr +# ifdef _CALL_LINUX + .size .jump_fcontext, .-.L.jump_fcontext +# else + .size .jump_fcontext, .-.jump_fcontext +# endif +#endif + + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/jump_ppc64_sysv_macho_gas.S b/src/boost/libs/context/src/asm/jump_ppc64_sysv_macho_gas.S new file mode 100644 index 000000000..74fcb2ab3 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_ppc64_sysv_macho_gas.S @@ -0,0 +1,164 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | TOC | R14 | R15 | R16 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R17 | R18 | R19 | R20 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R21 | R22 | R23 | R24 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | R25 | R26 | R27 | R28 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | R29 | R30 | R31 | hidden | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | CR | LR | PC | back-chain| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | cr saved | lr saved | compiler | linker | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | TOC saved | FCTX | DATA | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.align 2 +.globl _jump_fcontext + +_jump_fcontext: + ; reserve space on stack + subi r1, r1, 184 + + std r14, 8(r1) ; save R14 + std r15, 16(r1) ; save R15 + std r16, 24(r1) ; save R16 + std r17, 32(r1) ; save R17 + std r18, 40(r1) ; save R18 + std r19, 48(r1) ; save R19 + std r20, 56(r1) ; save R20 + std r21, 64(r1) ; save R21 + std r22, 72(r1) ; save R22 + std r23, 80(r1) ; save R23 + std r24, 88(r1) ; save R24 + std r25, 96(r1) ; save R25 + std r26, 104(r1) ; save R26 + std r27, 112(r1) ; save R27 + std r28, 120(r1) ; save R28 + std r29, 128(r1) ; save R29 + std r30, 136(r1) ; save R30 + std r31, 144(r1) ; save R31 + std r3, 152(r1) ; save hidden + + ; save CR + mfcr r0 + std r0, 160(r1) + ; save LR + mflr r0 + std r0, 168(r1) + ; save LR as PC + std r0, 176(r1) + + ; store RSP (pointing to context-data) in R6 + mr r6, r1 + + ; restore RSP (pointing to context-data) from R4 + mr r1, r4 + + ld r14, 8(r1) ; restore R14 + ld r15, 16(r1) ; restore R15 + ld r16, 24(r1) ; restore R16 + ld r17, 32(r1) ; restore R17 + ld r18, 40(r1) ; restore R18 + ld r19, 48(r1) ; restore R19 + ld r20, 56(r1) ; restore R20 + ld r21, 64(r1) ; restore R21 + ld r22, 72(r1) ; restore R22 + ld r23, 80(r1) ; restore R23 + ld r24, 88(r1) ; restore R24 + ld r25, 96(r1) ; restore R25 + ld r26, 104(r1) ; restore R26 + ld r27, 112(r1) ; restore R27 + ld r28, 120(r1) ; restore R28 + ld r29, 128(r1) ; restore R29 + ld r30, 136(r1) ; restore R30 + ld r31, 144(r1) ; restore R31 + ld r3, 152(r1) ; restore hidden + + ; restore CR + ld r0, 160(r1) + mtcr r0 + ; restore LR + ld r0, 168(r1) + mtlr r0 + + ; load PC + ld r12, 176(r1) + # restore CTR + mtctr r12 + + # adjust stack + addi r1, r1, 184 + + # zero in r3 indicates first jump to context-function + cmpdi r3, 0 + beq use_entry_arg + + # return transfer_t + std r6, 0(r3) + std r5, 8(r3) + + # jump to context + bctr + +use_entry_arg: + # copy transfer_t into transfer_fn arg registers + mr r3, r6 + mr r4, r5 + + # jump to context + bctr diff --git a/src/boost/libs/context/src/asm/jump_ppc64_sysv_xcoff_gas.S b/src/boost/libs/context/src/asm/jump_ppc64_sysv_xcoff_gas.S new file mode 100644 index 000000000..ff0e6eaa8 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_ppc64_sysv_xcoff_gas.S @@ -0,0 +1,92 @@ + +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +.align 2 +.globl .jump_fcontext +.jump_fcontext: + # reserve space on stack + subi 1, 1, 184 + + std 13, 0(1) # save R13 + std 14, 8(1) # save R14 + std 15, 16(1) # save R15 + std 16, 24(1) # save R16 + std 17, 32(1) # save R17 + std 18, 40(1) # save R18 + std 19, 48(1) # save R19 + std 20, 56(1) # save R20 + std 21, 64(1) # save R21 + std 22, 72(1) # save R22 + std 23, 80(1) # save R23 + std 24, 88(1) # save R24 + std 25, 96(1) # save R25 + std 26, 104(1) # save R26 + std 27, 112(1) # save R27 + std 29, 120(1) # save R28 + std 29, 128(1) # save R29 + std 30, 136(1) # save R30 + std 31, 144(1) # save R31 + std 3, 152(1) # save hidden + + # save CR + mfcr 0 + std 0, 160(1) + # save LR + mflr 0 + std 0, 168(1) + # save LR as PC + std 0, 176(1) + + # store RSP (pointing to context-data) in R6 + mr 6, 1 + + # restore RSP (pointing to context-data) from R4 + mr 1, 4 + + ld 13, 0(1) # restore R13 + ld 14, 8(1) # restore R14 + ld 15, 16(1) # restore R15 + ld 16, 24(1) # restore R16 + ld 17, 32(1) # restore R17 + ld 18, 40(1) # restore R18 + ld 19, 48(1) # restore R19 + ld 20, 56(1) # restore R20 + ld 21, 64(1) # restore R21 + ld 22, 72(1) # restore R22 + ld 23, 80(1) # restore R23 + ld 24, 88(1) # restore R24 + ld 25, 96(1) # restore R25 + ld 26, 104(1) # restore R26 + ld 27, 112(1) # restore R27 + ld 28, 120(1) # restore R28 + ld 29, 128(1) # restore R29 + ld 30, 136(1) # restore R30 + ld 31, 144(1) # restore R31 + ld 3, 152(1) # restore hidden + + # restore CR + ld 0, 160(1) + mtcr 0 + # restore LR + ld 0, 168(1) + mtlr 0 + + # load PC + ld 0, 176(1) + # restore CTR + mtctr 0 + + # adjust stack + addi 1, 1, 184 + + # return transfer_t + std 6, 0(3) + std 5, 8(3) + + # jump to context + bctr diff --git a/src/boost/libs/context/src/asm/jump_riscv64_sysv_elf_gas.S b/src/boost/libs/context/src/asm/jump_riscv64_sysv_elf_gas.S new file mode 100644 index 000000000..5417e5d5e --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_riscv64_sysv_elf_gas.S @@ -0,0 +1,150 @@ +/* + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | fs0 | fs1 | fs2 | fs3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | fs4 | fs5 | fs6 | fs7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | fs8 | fs9 | fs10 | fs11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | s0 | s1 | s2 | s3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | s4 | s5 | s6 | s7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * + * ------------------------------------------------- * + * | s8 | s9 | s10 | s11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | | | | | * + * ------------------------------------------------- * + * | 0xc0| 0xc4| 0xc8| 0xcc| | | | | * + * ------------------------------------------------- * + * | ra | pc | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "jump_riscv64_sysv_elf_gas.S" +.text +.align 1 +.global jump_fcontext +.type jump_fcontext, %function +jump_fcontext: + # prepare stack for GP + FPU + addi sp, sp, -0xd0 + + # save fs0 - fs11 + fsd fs0, 0x00(sp) + fsd fs1, 0x08(sp) + fsd fs2, 0x10(sp) + fsd fs3, 0x18(sp) + fsd fs4, 0x20(sp) + fsd fs5, 0x28(sp) + fsd fs6, 0x30(sp) + fsd fs7, 0x38(sp) + fsd fs8, 0x40(sp) + fsd fs9, 0x48(sp) + fsd fs10, 0x50(sp) + fsd fs11, 0x58(sp) + + # save s0-s11, ra + sd s0, 0x60(sp) + sd s1, 0x68(sp) + sd s2, 0x70(sp) + sd s3, 0x78(sp) + sd s4, 0x80(sp) + sd s5, 0x88(sp) + sd s6, 0x90(sp) + sd s7, 0x98(sp) + sd s8, 0xa0(sp) + sd s9, 0xa8(sp) + sd s10, 0xb0(sp) + sd s11, 0xb8(sp) + sd ra, 0xc0(sp) + + # save RA as PC + sd ra, 0xc8(sp) + + # store SP (pointing to context-data) in A2 + mv a2, sp + + # restore SP (pointing to context-data) from A0 + mv sp, a0 + + # load fs0 - fs11 + fld fs0, 0x00(sp) + fld fs1, 0x08(sp) + fld fs2, 0x10(sp) + fld fs3, 0x18(sp) + fld fs4, 0x20(sp) + fld fs5, 0x28(sp) + fld fs6, 0x30(sp) + fld fs7, 0x38(sp) + fld fs8, 0x40(sp) + fld fs9, 0x48(sp) + fld fs10, 0x50(sp) + fld fs11, 0x58(sp) + + # load s0-s11,ra + ld s0, 0x60(sp) + ld s1, 0x68(sp) + ld s2, 0x70(sp) + ld s3, 0x78(sp) + ld s4, 0x80(sp) + ld s5, 0x88(sp) + ld s6, 0x90(sp) + ld s7, 0x98(sp) + ld s8, 0xa0(sp) + ld s9, 0xa8(sp) + ld s10, 0xb0(sp) + ld s11, 0xb8(sp) + ld ra, 0xc0(sp) + + # return transfer_t from jump + # pass transfer_t as first arg in context function + # a0 == FCTX, a1 == DATA + mv a0, a2 + + # load pc + ld a2, 0xc8(sp) + + # restore stack from GP + FPU + addi sp, sp, 0xd0 + + jr a2 +.size jump_fcontext,.-jump_fcontext +# Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/jump_s390x_sysv_elf_gas.S b/src/boost/libs/context/src/asm/jump_s390x_sysv_elf_gas.S new file mode 100644 index 000000000..c2a578b26 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_s390x_sysv_elf_gas.S @@ -0,0 +1,156 @@ +/******************************************************* + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * + * | t.fctx | t.data | r2 | r6 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * + * | r7 | r8 | r9 | r10 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 72 | 80 | 88 | * + * ------------------------------------------------- * + * | r11 | r12 | r13 | r14 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 104 | 112 | 120 | * + * ------------------------------------------------- * + * | f8 | f9 | f10 | f11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 136 | 144 | 152 | * + * ------------------------------------------------- * + * | f12 | f13 | f14 | f15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 168 | 176 | | * + * ------------------------------------------------- * + * | fpc | pc | | | * + * ------------------------------------------------- * + *******************************************************/ + +.text +.align 8 +.global jump_fcontext +.type jump_fcontext, @function + +#define ARG_OFFSET 0 +#define GR_OFFSET 16 +#define FP_OFFSET 96 +#define FPC_OFFSET 160 +#define PC_OFFSET 168 +#define CONTEXT_SIZE 176 + +#define REG_SAVE_AREA_SIZE 160 + +/* + +typedef void* fcontext_t; + +struct transfer_t { + fcontext_t fctx; + void * data; +}; + +transfer_t jump_fcontext( fcontext_t const to, + void * data); + +Incoming args +r2 - Hidden argument to the location where the return transfer_t needs to be returned +r3 - Context we want to switch to +r4 - Data pointer + +*/ + +jump_fcontext: + .machine "z10" + /* Reserve stack space to store the current context. */ + aghi %r15,-CONTEXT_SIZE + + /* Save the argument register holding the location of the return value. */ + stg %r2,GR_OFFSET(%r15) + + /* Save the call-saved general purpose registers. */ + stmg %r6,%r14,GR_OFFSET+8(%r15) + + /* Save call-saved floating point registers. */ + std %f8,FP_OFFSET(%r15) + std %f9,FP_OFFSET+8(%r15) + std %f10,FP_OFFSET+16(%r15) + std %f11,FP_OFFSET+24(%r15) + std %f12,FP_OFFSET+32(%r15) + std %f13,FP_OFFSET+40(%r15) + std %f14,FP_OFFSET+48(%r15) + std %f15,FP_OFFSET+56(%r15) + + /* Save the return address as current pc. */ + stg %r14,PC_OFFSET(%r15) + + /* Save the floating point control register. */ + stfpc FPC_OFFSET(%r15) + + /* Backup the stack pointer pointing to the old context-data into r1. */ + lgr %r1,%r15 + + /* Load the new context pointer as stack pointer. */ + lgr %r15,%r3 + + /* Restore the call-saved GPRs from the new context. */ + lmg %r6,%r14,GR_OFFSET+8(%r15) + + /* Restore call-saved floating point registers. */ + ld %f8,FP_OFFSET(%r15) + ld %f9,FP_OFFSET+8(%r15) + ld %f10,FP_OFFSET+16(%r15) + ld %f11,FP_OFFSET+24(%r15) + ld %f12,FP_OFFSET+32(%r15) + ld %f13,FP_OFFSET+40(%r15) + ld %f14,FP_OFFSET+48(%r15) + ld %f15,FP_OFFSET+56(%r15) + + /* Load the floating point control register. */ + lfpc FPC_OFFSET(%r15) + + /* Restore PC - the location where we will jump to at the end. */ + lg %r5,PC_OFFSET(%r15) + + ltg %r2,GR_OFFSET(%r15) + jnz use_return_slot + + /* We restore a make_fcontext context. Use the function + argument slot in the context we just saved and allocate the + register save area for the target function. */ + la %r2,ARG_OFFSET(%r1) + aghi %r15,-REG_SAVE_AREA_SIZE + +use_return_slot: + /* Save the two fields in transfer_t. When calling a + make_fcontext function this becomes the function argument of + the target function, otherwise it will be the return value of + jump_fcontext. */ + stg %r1,0(%r2) + stg %r4,8(%r2) + + /* Free the restored context. */ + aghi %r15,CONTEXT_SIZE + + /* Jump to the PC loaded from the new context. */ + br %r5 + + +.size jump_fcontext,.-jump_fcontext +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/jump_x86_64_ms_pe_gas.asm b/src/boost/libs/context/src/asm/jump_x86_64_ms_pe_gas.asm new file mode 100644 index 000000000..ec4ecfe94 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_x86_64_ms_pe_gas.asm @@ -0,0 +1,209 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* ---------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* ---------------------------------------------------------------------------------- * +* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* ---------------------------------------------------------------------------------- * +* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +* ---------------------------------------------------------------------------------- * +* | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +* ---------------------------------------------------------------------------------- * +* | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | * +* ---------------------------------------------------------------------------------- * +* | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | * +* ---------------------------------------------------------------------------------- * +* | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | * +* ---------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | * +* ---------------------------------------------------------------------------------- * +* | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | * +* ---------------------------------------------------------------------------------- * +* | limit | base | R12 | R13 | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | * +* ---------------------------------------------------------------------------------- * +* | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | * +* ---------------------------------------------------------------------------------- * +* | R14 | R15 | RDI | RSI | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | * +* ---------------------------------------------------------------------------------- * +* | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | * +* ---------------------------------------------------------------------------------- * +* | RBX | RBP | hidden | RIP | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | * +* ---------------------------------------------------------------------------------- * +* | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | * +* ---------------------------------------------------------------------------------- * +* | parameter area | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | * +* ---------------------------------------------------------------------------------- * +* | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | * +* ---------------------------------------------------------------------------------- * +* | FCTX | DATA | | * +* ---------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "jump_x86_64_ms_pe_gas.asm" +.text +.p2align 4,,15 +.globl jump_fcontext +.def jump_fcontext; .scl 2; .type 32; .endef +.seh_proc jump_fcontext +jump_fcontext: +.seh_endprologue + + leaq -0x118(%rsp), %rsp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + /* save XMM storage */ + movaps %xmm6, 0x0(%rsp) + movaps %xmm7, 0x10(%rsp) + movaps %xmm8, 0x20(%rsp) + movaps %xmm9, 0x30(%rsp) + movaps %xmm10, 0x40(%rsp) + movaps %xmm11, 0x50(%rsp) + movaps %xmm12, 0x60(%rsp) + movaps %xmm13, 0x70(%rsp) + movaps %xmm14, 0x80(%rsp) + movaps %xmm15, 0x90(%rsp) + stmxcsr 0xa0(%rsp) /* save MMX control- and status-word */ + fnstcw 0xa4(%rsp) /* save x87 control-word */ +#endif + + /* load NT_TIB */ + movq %gs:(0x30), %r10 + /* save fiber local storage */ + movq 0x20(%r10), %rax + movq %rax, 0xb0(%rsp) + /* save current deallocation stack */ + movq 0x1478(%r10), %rax + movq %rax, 0xb8(%rsp) + /* save current stack limit */ + movq 0x10(%r10), %rax + movq %rax, 0xc0(%rsp) + /* save current stack base */ + movq 0x08(%r10), %rax + movq %rax, 0xc8(%rsp) + + movq %r12, 0xd0(%rsp) /* save R12 */ + movq %r13, 0xd8(%rsp) /* save R13 */ + movq %r14, 0xe0(%rsp) /* save R14 */ + movq %r15, 0xe8(%rsp) /* save R15 */ + movq %rdi, 0xf0(%rsp) /* save RDI */ + movq %rsi, 0xf8(%rsp) /* save RSI */ + movq %rbx, 0x100(%rsp) /* save RBX */ + movq %rbp, 0x108(%rsp) /* save RBP */ + + movq %rcx, 0x110(%rsp) /* save hidden address of transport_t */ + + /* preserve RSP (pointing to context-data) in R9 */ + movq %rsp, %r9 + + /* restore RSP (pointing to context-data) from RDX */ + movq %rdx, %rsp + +#if !defined(BOOST_USE_TSX) + /* restore XMM storage */ + movaps 0x0(%rsp), %xmm6 + movaps 0x10(%rsp), %xmm7 + movaps 0x20(%rsp), %xmm8 + movaps 0x30(%rsp), %xmm9 + movaps 0x40(%rsp), %xmm10 + movaps 0x50(%rsp), %xmm11 + movaps 0x60(%rsp), %xmm12 + movaps 0x70(%rsp), %xmm13 + movaps 0x80(%rsp), %xmm14 + movaps 0x90(%rsp), %xmm15 + ldmxcsr 0xa0(%rsp) /* restore MMX control- and status-word */ + fldcw 0xa4(%rsp) /* restore x87 control-word */ +#endif + + /* load NT_TIB */ + movq %gs:(0x30), %r10 + /* restore fiber local storage */ + movq 0xb0(%rsp), %rax + movq %rax, 0x20(%r10) + /* restore current deallocation stack */ + movq 0xb8(%rsp), %rax + movq %rax, 0x1478(%r10) + /* restore current stack limit */ + movq 0xc0(%rsp), %rax + movq %rax, 0x10(%r10) + /* restore current stack base */ + movq 0xc8(%rsp), %rax + movq %rax, 0x08(%r10) + + movq 0xd0(%rsp), %r12 /* restore R12 */ + movq 0xd8(%rsp), %r13 /* restore R13 */ + movq 0xe0(%rsp), %r14 /* restore R14 */ + movq 0xe8(%rsp), %r15 /* restore R15 */ + movq 0xf0(%rsp), %rdi /* restore RDI */ + movq 0xf8(%rsp), %rsi /* restore RSI */ + movq 0x100(%rsp), %rbx /* restore RBX */ + movq 0x108(%rsp), %rbp /* restore RBP */ + + movq 0x110(%rsp), %rax /* restore hidden address of transport_t */ + + leaq 0x118(%rsp), %rsp /* prepare stack */ + + /* restore return-address */ + popq %r10 + + /* transport_t returned in RAX */ + /* return parent fcontext_t */ + movq %r9, 0x0(%rax) + /* return data */ + movq %r8, 0x8(%rax) + + /* transport_t as 1.arg of context-function */ + movq %rax, %rcx + + /* indirect jump to context */ + jmp *%r10 +.seh_endproc + +.section .drectve +.ascii " -export:\"jump_fcontext\"" diff --git a/src/boost/libs/context/src/asm/jump_x86_64_ms_pe_masm.asm b/src/boost/libs/context/src/asm/jump_x86_64_ms_pe_masm.asm new file mode 100644 index 000000000..c8a28a558 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_x86_64_ms_pe_masm.asm @@ -0,0 +1,205 @@ + +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) + +; ---------------------------------------------------------------------------------- +; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +; ---------------------------------------------------------------------------------- +; | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | +; ---------------------------------------------------------------------------------- +; | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | +; ---------------------------------------------------------------------------------- +; | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | +; ---------------------------------------------------------------------------------- +; | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | +; ---------------------------------------------------------------------------------- +; | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | +; ---------------------------------------------------------------------------------- +; | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | +; ---------------------------------------------------------------------------------- +; | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | +; ---------------------------------------------------------------------------------- +; | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | +; ---------------------------------------------------------------------------------- +; | limit | base | R12 | R13 | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | +; ---------------------------------------------------------------------------------- +; | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | +; ---------------------------------------------------------------------------------- +; | R14 | R15 | RDI | RSI | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | +; ---------------------------------------------------------------------------------- +; | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | +; ---------------------------------------------------------------------------------- +; | RBX | RBP | hidden | RIP | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | +; ---------------------------------------------------------------------------------- +; | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | +; ---------------------------------------------------------------------------------- +; | parameter area | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | +; ---------------------------------------------------------------------------------- +; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | +; ---------------------------------------------------------------------------------- +; | FCTX | DATA | | +; ---------------------------------------------------------------------------------- + +.code + +jump_fcontext PROC BOOST_CONTEXT_EXPORT FRAME + .endprolog + + ; prepare stack + lea rsp, [rsp-0118h] + +IFNDEF BOOST_USE_TSX + ; save XMM storage + movaps [rsp], xmm6 + movaps [rsp+010h], xmm7 + movaps [rsp+020h], xmm8 + movaps [rsp+030h], xmm9 + movaps [rsp+040h], xmm10 + movaps [rsp+050h], xmm11 + movaps [rsp+060h], xmm12 + movaps [rsp+070h], xmm13 + movaps [rsp+080h], xmm14 + movaps [rsp+090h], xmm15 + ; save MMX control- and status-word + stmxcsr [rsp+0a0h] + ; save x87 control-word + fnstcw [rsp+0a4h] +ENDIF + + ; load NT_TIB + mov r10, gs:[030h] + ; save fiber local storage + mov rax, [r10+020h] + mov [rsp+0b0h], rax + ; save current deallocation stack + mov rax, [r10+01478h] + mov [rsp+0b8h], rax + ; save current stack limit + mov rax, [r10+010h] + mov [rsp+0c0h], rax + ; save current stack base + mov rax, [r10+08h] + mov [rsp+0c8h], rax + + mov [rsp+0d0h], r12 ; save R12 + mov [rsp+0d8h], r13 ; save R13 + mov [rsp+0e0h], r14 ; save R14 + mov [rsp+0e8h], r15 ; save R15 + mov [rsp+0f0h], rdi ; save RDI + mov [rsp+0f8h], rsi ; save RSI + mov [rsp+0100h], rbx ; save RBX + mov [rsp+0108h], rbp ; save RBP + + mov [rsp+0110h], rcx ; save hidden address of transport_t + + ; preserve RSP (pointing to context-data) in R9 + mov r9, rsp + + ; restore RSP (pointing to context-data) from RDX + mov rsp, rdx + +IFNDEF BOOST_USE_TSX + ; restore XMM storage + movaps xmm6, [rsp] + movaps xmm7, [rsp+010h] + movaps xmm8, [rsp+020h] + movaps xmm9, [rsp+030h] + movaps xmm10, [rsp+040h] + movaps xmm11, [rsp+050h] + movaps xmm12, [rsp+060h] + movaps xmm13, [rsp+070h] + movaps xmm14, [rsp+080h] + movaps xmm15, [rsp+090h] + ; restore MMX control- and status-word + ldmxcsr [rsp+0a0h] + ; save x87 control-word + fldcw [rsp+0a4h] +ENDIF + + ; load NT_TIB + mov r10, gs:[030h] + ; restore fiber local storage + mov rax, [rsp+0b0h] + mov [r10+020h], rax + ; restore current deallocation stack + mov rax, [rsp+0b8h] + mov [r10+01478h], rax + ; restore current stack limit + mov rax, [rsp+0c0h] + mov [r10+010h], rax + ; restore current stack base + mov rax, [rsp+0c8h] + mov [r10+08h], rax + + mov r12, [rsp+0d0h] ; restore R12 + mov r13, [rsp+0d8h] ; restore R13 + mov r14, [rsp+0e0h] ; restore R14 + mov r15, [rsp+0e8h] ; restore R15 + mov rdi, [rsp+0f0h] ; restore RDI + mov rsi, [rsp+0f8h] ; restore RSI + mov rbx, [rsp+0100h] ; restore RBX + mov rbp, [rsp+0108h] ; restore RBP + + mov rax, [rsp+0110h] ; restore hidden address of transport_t + + ; prepare stack + lea rsp, [rsp+0118h] + + ; load return-address + pop r10 + + ; transport_t returned in RAX + ; return parent fcontext_t + mov [rax], r9 + ; return data + mov [rax+08h], r8 + + ; transport_t as 1.arg of context-function + mov rcx, rax + + ; indirect jump to context + jmp r10 +jump_fcontext ENDP +END diff --git a/src/boost/libs/context/src/asm/jump_x86_64_sysv_elf_gas.S b/src/boost/libs/context/src/asm/jump_x86_64_sysv_elf_gas.S new file mode 100644 index 000000000..d0defc43e --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_x86_64_sysv_elf_gas.S @@ -0,0 +1,81 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * + * ---------------------------------------------------------------------------------- * + * | R15 | RBX | RBP | RIP | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.file "jump_x86_64_sysv_elf_gas.S" +.text +.globl jump_fcontext +.type jump_fcontext,@function +.align 16 +jump_fcontext: + leaq -0x38(%rsp), %rsp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + stmxcsr (%rsp) /* save MMX control- and status-word */ + fnstcw 0x4(%rsp) /* save x87 control-word */ +#endif + + movq %r12, 0x8(%rsp) /* save R12 */ + movq %r13, 0x10(%rsp) /* save R13 */ + movq %r14, 0x18(%rsp) /* save R14 */ + movq %r15, 0x20(%rsp) /* save R15 */ + movq %rbx, 0x28(%rsp) /* save RBX */ + movq %rbp, 0x30(%rsp) /* save RBP */ + + /* store RSP (pointing to context-data) in RAX */ + movq %rsp, %rax + + /* restore RSP (pointing to context-data) from RDI */ + movq %rdi, %rsp + + movq 0x38(%rsp), %r8 /* restore return-address */ + +#if !defined(BOOST_USE_TSX) + ldmxcsr (%rsp) /* restore MMX control- and status-word */ + fldcw 0x4(%rsp) /* restore x87 control-word */ +#endif + + movq 0x8(%rsp), %r12 /* restore R12 */ + movq 0x10(%rsp), %r13 /* restore R13 */ + movq 0x18(%rsp), %r14 /* restore R14 */ + movq 0x20(%rsp), %r15 /* restore R15 */ + movq 0x28(%rsp), %rbx /* restore RBX */ + movq 0x30(%rsp), %rbp /* restore RBP */ + + leaq 0x40(%rsp), %rsp /* prepare stack */ + + /* return transfer_t from jump */ + /* RAX == fctx, RDX == data */ + movq %rsi, %rdx + /* pass transfer_t as first arg in context function */ + /* RDI == fctx, RSI == data */ + movq %rax, %rdi + + /* indirect jump to context */ + jmp *%r8 +.size jump_fcontext,.-jump_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/jump_x86_64_sysv_macho_gas.S b/src/boost/libs/context/src/asm/jump_x86_64_sysv_macho_gas.S new file mode 100644 index 000000000..afc3e5c12 --- /dev/null +++ b/src/boost/libs/context/src/asm/jump_x86_64_sysv_macho_gas.S @@ -0,0 +1,75 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * + * ---------------------------------------------------------------------------------- * + * | R15 | RBX | RBP | RIP | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.text +.globl _jump_fcontext +.align 8 +_jump_fcontext: + leaq -0x38(%rsp), %rsp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + stmxcsr (%rsp) /* save MMX control- and status-word */ + fnstcw 0x4(%rsp) /* save x87 control-word */ +#endif + + movq %r12, 0x8(%rsp) /* save R12 */ + movq %r13, 0x10(%rsp) /* save R13 */ + movq %r14, 0x18(%rsp) /* save R14 */ + movq %r15, 0x20(%rsp) /* save R15 */ + movq %rbx, 0x28(%rsp) /* save RBX */ + movq %rbp, 0x30(%rsp) /* save RBP */ + + /* store RSP (pointing to context-data) in RAX */ + movq %rsp, %rax + + /* restore RSP (pointing to context-data) from RDI */ + movq %rdi, %rsp + + movq 0x38(%rsp), %r8 /* restore return-address */ + +#if !defined(BOOST_USE_TSX) + ldmxcsr (%rsp) /* restore MMX control- and status-word */ + fldcw 0x4(%rsp) /* restore x87 control-word */ +#endif + + movq 0x8(%rsp), %r12 /* restore R12 */ + movq 0x10(%rsp), %r13 /* restore R13 */ + movq 0x18(%rsp), %r14 /* restore R14 */ + movq 0x20(%rsp), %r15 /* restore R15 */ + movq 0x28(%rsp), %rbx /* restore RBX */ + movq 0x30(%rsp), %rbp /* restore RBP */ + + leaq 0x40(%rsp), %rsp /* prepare stack */ + + /* return transfer_t from jump */ + /* RAX == fctx, RDX == data */ + movq %rsi, %rdx + /* pass transfer_t as first arg in context function */ + /* RDI == fctx, RSI == data */ + movq %rax, %rdi + + /* indirect jump to context */ + jmp *%r8 diff --git a/src/boost/libs/context/src/asm/make_arm64_aapcs_elf_gas.S b/src/boost/libs/context/src/asm/make_arm64_aapcs_elf_gas.S new file mode 100644 index 000000000..66cfb2da1 --- /dev/null +++ b/src/boost/libs/context/src/asm/make_arm64_aapcs_elf_gas.S @@ -0,0 +1,85 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | d8 | d9 | d10 | d11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | d12 | d13 | d14 | d15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | x19 | x20 | x21 | x22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | x23 | x24 | x25 | x26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | x27 | x28 | FP | LR | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | | | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| | | * + * ------------------------------------------------- * + * | PC | align | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "make_arm64_aapcs_elf_gas.S" +.text +.align 2 +.global make_fcontext +.type make_fcontext, %function +make_fcontext: + # shift address in x0 (allocated stack) to lower 16 byte boundary + and x0, x0, ~0xF + + # reserve space for context-data on context-stack + sub x0, x0, #0xb0 + + # third arg of make_fcontext() == address of context-function + # store address as a PC to jump in + str x2, [x0, #0xa0] + + # save address of finish as return-address for context-function + # will be entered after context-function returns (LR register) + adr x1, finish + str x1, [x0, #0x98] + + ret x30 // return pointer to context-data (x0) + +finish: + # exit code is zero + mov x0, #0 + # exit application + bl _exit + +.size make_fcontext,.-make_fcontext +# Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/make_arm64_aapcs_macho_gas.S b/src/boost/libs/context/src/asm/make_arm64_aapcs_macho_gas.S new file mode 100644 index 000000000..a3716ff08 --- /dev/null +++ b/src/boost/libs/context/src/asm/make_arm64_aapcs_macho_gas.S @@ -0,0 +1,88 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | d8 | d9 | d10 | d11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | d12 | d13 | d14 | d15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | x19 | x20 | x21 | x22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | x23 | x24 | x25 | x26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | x27 | x28 | FP | LR | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | | | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| | | * + * ------------------------------------------------- * + * | PC | align | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.globl _make_fcontext +.balign 16 + +_make_fcontext: + ; shift address in x0 (allocated stack) to lower 16 byte boundary + and x0, x0, ~0xF + + ; reserve space for context-data on context-stack + sub x0, x0, #0xb0 + + ; third arg of make_fcontext() == address of context-function + ; store address as a PC to jump in + str x2, [x0, #0xa0] + + ; compute abs address of label finish + ; 0x0c = 3 instructions * size (4) before label 'finish' + + ; TODO: Numeric offset since llvm still does not support labels in ADR. Fix: + ; http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140407/212336.html + adr x1, 0x0c + + ; save address of finish as return-address for context-function + ; will be entered after context-function returns (LR register) + str x1, [x0, #0x98] + + ret lr ; return pointer to context-data (x0) + +finish: + ; exit code is zero + mov x0, #0 + ; exit application + bl __exit + + diff --git a/src/boost/libs/context/src/asm/make_arm_aapcs_elf_gas.S b/src/boost/libs/context/src/asm/make_arm_aapcs_elf_gas.S new file mode 100644 index 000000000..98ae64b43 --- /dev/null +++ b/src/boost/libs/context/src/asm/make_arm_aapcs_elf_gas.S @@ -0,0 +1,81 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * |hiddn| v1 | v2 | v3 | v4 | v5 | v6 | v7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | v8 | lr | pc | FCTX| DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "make_arm_aapcs_elf_gas.S" +.text +.globl make_fcontext +.align 2 +.type make_fcontext,%function +.syntax unified +make_fcontext: + @ shift address in A1 to lower 16 byte boundary + bic a1, a1, #15 + + @ reserve space for context-data on context-stack + sub a1, a1, #124 + + @ third arg of make_fcontext() == address of context-function + str a3, [a1, #104] + + @ compute address of returned transfer_t + add a2, a1, #108 + mov a3, a2 + str a3, [a1, #64] + + @ compute abs address of label finish + adr a2, finish + @ save address of finish as return-address for context-function + @ will be entered after context-function returns + str a2, [a1, #100] + +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) +#endif + + bx lr @ return pointer to context-data + +finish: + @ exit code is zero + mov a1, #0 + @ exit application + bl _exit@PLT +.size make_fcontext,.-make_fcontext + +@ Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/make_arm_aapcs_macho_gas.S b/src/boost/libs/context/src/asm/make_arm_aapcs_macho_gas.S new file mode 100644 index 000000000..c909ae9d4 --- /dev/null +++ b/src/boost/libs/context/src/asm/make_arm_aapcs_macho_gas.S @@ -0,0 +1,71 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | sjlj|hiddn| v1 | v2 | v3 | v4 | v5 | v6 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | v7 | v8 | lr | pc | FCTX| DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.globl _make_fcontext +.align 2 +_make_fcontext: + @ shift address in A1 to lower 16 byte boundary + bic a1, a1, #15 + + @ reserve space for context-data on context-stack + sub a1, a1, #124 + + @ third arg of make_fcontext() == address of context-function + str a3, [a1, #108] + + @ compute address of returned transfer_t + add a2, a1, #112 + mov a3, a2 + str a3, [a1, #68] + + @ compute abs address of label finish + adr a2, finish + @ save address of finish as return-address for context-function + @ will be entered after context-function returns + str a2, [a1, #104] + + bx lr @ return pointer to context-data + +finish: + @ exit code is zero + mov a1, #0 + @ exit application + bl __exit diff --git a/src/boost/libs/context/src/asm/make_arm_aapcs_pe_armasm.asm b/src/boost/libs/context/src/asm/make_arm_aapcs_pe_armasm.asm new file mode 100644 index 000000000..27cbfb082 --- /dev/null +++ b/src/boost/libs/context/src/asm/make_arm_aapcs_pe_armasm.asm @@ -0,0 +1,77 @@ +;/* +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) +;*/ + +; ******************************************************* +; * * +; * ------------------------------------------------- * +; * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +; * ------------------------------------------------- * +; * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * +; * ------------------------------------------------- * +; * |deall|limit| base|hiddn| v1 | v2 | v3 | v4 | * +; * ------------------------------------------------- * +; * ------------------------------------------------- * +; * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +; * ------------------------------------------------- * +; * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * +; * ------------------------------------------------- * +; * | v5 | v6 | v7 | v8 | lr | pc | FCTX| DATA| * +; * ------------------------------------------------- * +; * * +; ******************************************************* + + + AREA |.text|, CODE + ALIGN 4 + EXPORT make_fcontext + IMPORT _exit + +make_fcontext PROC + ; first arg of make_fcontext() == top of context-stack + ; save top of context-stack (base) A4 + mov a4, a1 + + ; shift address in A1 to lower 16 byte boundary + bic a1, a1, #0x0f + + ; reserve space for context-data on context-stack + sub a1, a1, #0x48 + + ; save top address of context_stack as 'base' + str a4, [a1, #0x8] + ; second arg of make_fcontext() == size of context-stack + ; compute bottom address of context-stack (limit) + sub a4, a4, a2 + ; save bottom address of context-stack as 'limit' + str a4, [a1, #0x4] + ; save bottom address of context-stack as 'dealloction stack' + str a4, [a1, #0x0] + + ; third arg of make_fcontext() == address of context-function + str a3, [a1, #0x34] + + ; compute address of returned transfer_t + add a2, a1, #0x38 + mov a3, a2 + str a3, [a1, #0xc] + + ; compute abs address of label finish + adr a2, finish + ; save address of finish as return-address for context-function + ; will be entered after context-function returns + str a2, [a1, #0x30] + + bx lr ; return pointer to context-data + +finish + ; exit code is zero + mov a1, #0 + ; exit application + bl _exit + + ENDP + END diff --git a/src/boost/libs/context/src/asm/make_combined_sysv_macho_gas.S b/src/boost/libs/context/src/asm/make_combined_sysv_macho_gas.S new file mode 100644 index 000000000..727e9045f --- /dev/null +++ b/src/boost/libs/context/src/asm/make_combined_sysv_macho_gas.S @@ -0,0 +1,20 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__i386__) + #include "make_i386_sysv_macho_gas.S" +#elif defined(__x86_64__) + #include "make_x86_64_sysv_macho_gas.S" +#elif defined(__ppc__) + #include "make_ppc32_sysv_macho_gas.S" +#elif defined(__ppc64__) + #include "make_ppc64_sysv_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/src/boost/libs/context/src/asm/make_i386_ms_pe_gas.asm b/src/boost/libs/context/src/asm/make_i386_ms_pe_gas.asm new file mode 100644 index 000000000..10277bb5f --- /dev/null +++ b/src/boost/libs/context/src/asm/make_i386_ms_pe_gas.asm @@ -0,0 +1,153 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* --------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* --------------------------------------------------------------------------------- * +* | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | * +* --------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | * +* --------------------------------------------------------------------------------- * +* --------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* --------------------------------------------------------------------------------- * +* | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | * +* --------------------------------------------------------------------------------- * +* | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| * +* --------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "make_i386_ms_pe_gas.asm" +.text +.p2align 4,,15 + +/* mark as using no unregistered SEH handlers */ +.globl @feat.00 +.def @feat.00; .scl 3; .type 0; .endef +.set @feat.00, 1 + +.globl _make_fcontext +.def _make_fcontext; .scl 2; .type 32; .endef +_make_fcontext: + /* first arg of make_fcontext() == top of context-stack */ + movl 0x04(%esp), %eax + + /* reserve space for first argument of context-function */ + /* EAX might already point to a 16byte border */ + leal -0x8(%eax), %eax + + /* shift address in EAX to lower 16 byte boundary */ + andl $-16, %eax + + /* reserve space for context-data on context-stack */ + /* size for fc_mxcsr .. EIP + return-address for context-function */ + /* on context-function entry: (ESP -0x4) % 8 == 0 */ + /* additional space is required for SEH */ + leal -0x40(%eax), %eax + + /* save MMX control- and status-word */ + stmxcsr (%eax) + /* save x87 control-word */ + fnstcw 0x4(%eax) + + /* first arg of make_fcontext() == top of context-stack */ + movl 0x4(%esp), %ecx + /* save top address of context stack as 'base' */ + movl %ecx, 0x14(%eax) + /* second arg of make_fcontext() == size of context-stack */ + movl 0x8(%esp), %edx + /* negate stack size for LEA instruction (== substraction) */ + negl %edx + /* compute bottom address of context stack (limit) */ + leal (%ecx,%edx), %ecx + /* save bottom address of context-stack as 'limit' */ + movl %ecx, 0x10(%eax) + /* save bottom address of context-stack as 'dealloction stack' */ + movl %ecx, 0xc(%eax) + /* set fiber-storage to zero */ + xorl %ecx, %ecx + movl %ecx, 0x8(%eax) + + /* third arg of make_fcontext() == address of context-function */ + /* stored in EBX */ + movl 0xc(%esp), %ecx + movl %ecx, 0x24(%eax) + + /* compute abs address of label trampoline */ + movl $trampoline, %ecx + /* save address of trampoline as return-address for context-function */ + /* will be entered after calling jump_fcontext() first time */ + movl %ecx, 0x2c(%eax) + + /* compute abs address of label finish */ + movl $finish, %ecx + /* save address of finish as return-address for context-function */ + /* will be entered after context-function returns */ + movl %ecx, 0x28(%eax) + + /* traverse current seh chain to get the last exception handler installed by Windows */ + /* note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default */ + /* the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler */ + /* at its end by RaiseException all seh andlers are disregarded if not present and the */ + /* program is aborted */ + /* load NT_TIB into ECX */ + movl %fs:(0x0), %ecx + +walk: + /* load 'next' member of current SEH into EDX */ + movl (%ecx), %edx + /* test if 'next' of current SEH is last (== 0xffffffff) */ + incl %edx + jz found + decl %edx + /* exchange content; ECX contains address of next SEH */ + xchgl %ecx, %edx + /* inspect next SEH */ + jmp walk + +found: + /* load 'handler' member of SEH == address of last SEH handler installed by Windows */ + movl 0x04(%ecx), %ecx + /* save address in ECX as SEH handler for context */ + movl %ecx, 0x3c(%eax) + /* set ECX to -1 */ + movl $0xffffffff, %ecx + /* save ECX as next SEH item */ + movl %ecx, 0x38(%eax) + /* load address of next SEH item */ + leal 0x38(%eax), %ecx + /* save next SEH */ + movl %ecx, 0x18(%eax) + + /* return pointer to context-data */ + ret + +trampoline: + /* move transport_t for entering context-function */ + /* FCTX == EAX, DATA == EDX */ + movl %eax, (%esp) + movl %edx, 0x4(%esp) + /* label finish as return-address */ + pushl %ebp + /* jump to context-function */ + jmp *%ebx + +finish: + /* ESP points to same address as ESP on entry of context function + 0x4 */ + xorl %eax, %eax + /* exit code is zero */ + movl %eax, (%esp) + /* exit application */ + call __exit + hlt + +.def __exit; .scl 2; .type 32; .endef /* standard C library function */ + +.section .drectve +.ascii " -export:\"_make_fcontext\"" diff --git a/src/boost/libs/context/src/asm/make_i386_ms_pe_masm.asm b/src/boost/libs/context/src/asm/make_i386_ms_pe_masm.asm new file mode 100644 index 000000000..5246465cb --- /dev/null +++ b/src/boost/libs/context/src/asm/make_i386_ms_pe_masm.asm @@ -0,0 +1,140 @@ + +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) + +; --------------------------------------------------------------------------------- +; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +; --------------------------------------------------------------------------------- +; | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | +; --------------------------------------------------------------------------------- +; | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | +; --------------------------------------------------------------------------------- +; --------------------------------------------------------------------------------- +; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | +; --------------------------------------------------------------------------------- +; | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | +; --------------------------------------------------------------------------------- +; | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| +; --------------------------------------------------------------------------------- + +.386 +.XMM +.model flat, c +; standard C library function +_exit PROTO, value:SDWORD +.code + +make_fcontext PROC BOOST_CONTEXT_EXPORT + ; first arg of make_fcontext() == top of context-stack + mov eax, [esp+04h] + + ; reserve space for first argument of context-function + ; EAX might already point to a 16byte border + lea eax, [eax-08h] + + ; shift address in EAX to lower 16 byte boundary + and eax, -16 + + ; reserve space for context-data on context-stack + ; on context-function entry: (ESP -0x4) % 8 == 0 + ; additional space is required for SEH + lea eax, [eax-040h] + + ; save MMX control- and status-word + stmxcsr [eax] + ; save x87 control-word + fnstcw [eax+04h] + + ; first arg of make_fcontext() == top of context-stack + mov ecx, [esp+04h] + ; save top address of context stack as 'base' + mov [eax+014h], ecx + ; second arg of make_fcontext() == size of context-stack + mov edx, [esp+08h] + ; negate stack size for LEA instruction (== substraction) + neg edx + ; compute bottom address of context stack (limit) + lea ecx, [ecx+edx] + ; save bottom address of context-stack as 'limit' + mov [eax+010h], ecx + ; save bottom address of context-stack as 'dealloction stack' + mov [eax+0ch], ecx + ; set fiber-storage to zero + xor ecx, ecx + mov [eax+08h], ecx + + ; third arg of make_fcontext() == address of context-function + ; stored in EBX + mov ecx, [esp+0ch] + mov [eax+024h], ecx + + ; compute abs address of label trampoline + mov ecx, trampoline + ; save address of trampoline as return-address for context-function + ; will be entered after calling jump_fcontext() first time + mov [eax+02ch], ecx + + ; compute abs address of label finish + mov ecx, finish + ; save address of finish as return-address for context-function in EBP + ; will be entered after context-function returns + mov [eax+028h], ecx + + ; traverse current seh chain to get the last exception handler installed by Windows + ; note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default + ; the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler + ; at its end by RaiseException all seh-handlers are disregarded if not present and the + ; program is aborted + assume fs:nothing + ; load NT_TIB into ECX + mov ecx, fs:[0h] + assume fs:error + +walk: + ; load 'next' member of current SEH into EDX + mov edx, [ecx] + ; test if 'next' of current SEH is last (== 0xffffffff) + inc edx + jz found + dec edx + ; exchange content; ECX contains address of next SEH + xchg edx, ecx + ; inspect next SEH + jmp walk + +found: + ; load 'handler' member of SEH == address of last SEH handler installed by Windows + mov ecx, [ecx+04h] + ; save address in ECX as SEH handler for context + mov [eax+03ch], ecx + ; set ECX to -1 + mov ecx, 0ffffffffh + ; save ECX as next SEH item + mov [eax+038h], ecx + ; load address of next SEH item + lea ecx, [eax+038h] + ; save next SEH + mov [eax+018h], ecx + + ret ; return pointer to context-data + +trampoline: + ; move transport_t for entering context-function + ; FCTX == EAX, DATA == EDX + mov [esp], eax + mov [esp+04h], edx + push ebp + ; jump to context-function + jmp ebx + +finish: + ; exit code is zero + xor eax, eax + mov [esp], eax + ; exit application + call _exit + hlt +make_fcontext ENDP +END diff --git a/src/boost/libs/context/src/asm/make_i386_sysv_elf_gas.S b/src/boost/libs/context/src/asm/make_i386_sysv_elf_gas.S new file mode 100644 index 000000000..b76de260d --- /dev/null +++ b/src/boost/libs/context/src/asm/make_i386_sysv_elf_gas.S @@ -0,0 +1,107 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | hidden | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | | * + * ---------------------------------------------------------------------------------- * + * | to | data | | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.file "make_i386_sysv_elf_gas.S" +.text +.globl make_fcontext +.align 2 +.type make_fcontext,@function +make_fcontext: + /* first arg of make_fcontext() == top of context-stack */ + movl 0x4(%esp), %eax + + /* reserve space for first argument of context-function + eax might already point to a 16byte border */ + leal -0x8(%eax), %eax + + /* shift address in EAX to lower 16 byte boundary */ + andl $-16, %eax + + /* reserve space for context-data on context-stack */ + leal -0x28(%eax), %eax + + /* third arg of make_fcontext() == address of context-function */ + /* stored in EBX */ + movl 0xc(%esp), %ecx + movl %ecx, 0x10(%eax) + + /* save MMX control- and status-word */ + stmxcsr (%eax) + /* save x87 control-word */ + fnstcw 0x4(%eax) + + /* return transport_t */ + /* FCTX == EDI, DATA == ESI */ + leal 0x8(%eax), %ecx + movl %ecx, 0x1c(%eax) + + /* compute abs address of label trampoline */ + call 1f + /* address of trampoline 1 */ +1: popl %ecx + /* compute abs address of label trampoline */ + addl $trampoline-1b, %ecx + /* save address of trampoline as return address */ + /* will be entered after calling jump_fcontext() first time */ + movl %ecx, 0x18(%eax) + + /* compute abs address of label finish */ + call 2f + /* address of label 2 */ +2: popl %ecx + /* compute abs address of label finish */ + addl $finish-2b, %ecx + /* save address of finish as return-address for context-function */ + /* will be entered after context-function returns */ + movl %ecx, 0x14(%eax) + + ret /* return pointer to context-data */ + +trampoline: + /* move transport_t for entering context-function */ + movl %edi, (%esp) + movl %esi, 0x4(%esp) + pushl %ebp + /* jump to context-function */ + jmp *%ebx + +finish: + call 3f + /* address of label 3 */ +3: popl %ebx + /* compute address of GOT and store it in EBX */ + addl $_GLOBAL_OFFSET_TABLE_+[.-3b], %ebx + + /* exit code is zero */ + xorl %eax, %eax + movl %eax, (%esp) + /* exit application */ + call _exit@PLT + hlt +.size make_fcontext,.-make_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/make_i386_sysv_macho_gas.S b/src/boost/libs/context/src/asm/make_i386_sysv_macho_gas.S new file mode 100644 index 000000000..fdcdb7c80 --- /dev/null +++ b/src/boost/libs/context/src/asm/make_i386_sysv_macho_gas.S @@ -0,0 +1,90 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | to | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | | * + * ---------------------------------------------------------------------------------- * + * | data | | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.text +.globl _make_fcontext +.align 2 +_make_fcontext: + /* first arg of make_fcontext() == top of context-stack */ + movl 0x4(%esp), %eax + + /* reserve space for first argument of context-function + eax might already point to a 16byte border */ + leal -0x8(%eax), %eax + + /* shift address in EAX to lower 16 byte boundary */ + andl $-16, %eax + + /* reserve space for context-data on context-stack */ + leal -0x2c(%eax), %eax + + /* third arg of make_fcontext() == address of context-function */ + /* stored in EBX */ + movl 0xc(%esp), %ecx + movl %ecx, 0x10(%eax) + + /* save MMX control- and status-word */ + stmxcsr (%eax) + /* save x87 control-word */ + fnstcw 0x4(%eax) + + /* compute abs address of label trampoline */ + call 1f + /* address of trampoline 1 */ +1: popl %ecx + /* compute abs address of label trampoline */ + addl $trampoline-1b, %ecx + /* save address of trampoline as return address */ + /* will be entered after calling jump_fcontext() first time */ + movl %ecx, 0x18(%eax) + + /* compute abs address of label finish */ + call 2f + /* address of label 2 */ +2: popl %ecx + /* compute abs address of label finish */ + addl $finish-2b, %ecx + /* save address of finish as return-address for context-function */ + /* will be entered after context-function returns */ + movl %ecx, 0x14(%eax) + + ret /* return pointer to context-data */ + +trampoline: + /* move transport_t for entering context-function */ + movl %eax, (%esp) + movl %edx, 0x4(%esp) + pushl %ebp + /* jump to context-function */ + jmp *%ebx + +finish: + /* exit code is zero */ + xorl %eax, %eax + movl %eax, (%esp) + /* exit application */ + call __exit + hlt diff --git a/src/boost/libs/context/src/asm/make_i386_x86_64_sysv_macho_gas.S b/src/boost/libs/context/src/asm/make_i386_x86_64_sysv_macho_gas.S new file mode 100644 index 000000000..e364b2db6 --- /dev/null +++ b/src/boost/libs/context/src/asm/make_i386_x86_64_sysv_macho_gas.S @@ -0,0 +1,16 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__i386__) + #include "make_i386_sysv_macho_gas.S" +#elif defined(__x86_64__) + #include "make_x86_64_sysv_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/src/boost/libs/context/src/asm/make_mips32_o32_elf_gas.S b/src/boost/libs/context/src/asm/make_mips32_o32_elf_gas.S new file mode 100644 index 000000000..4e11e3d05 --- /dev/null +++ b/src/boost/libs/context/src/asm/make_mips32_o32_elf_gas.S @@ -0,0 +1,97 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | F20 | F22 | F24 | F26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | F28 | F30 | S0 | S1 | S2 | S3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | S4 | S5 | S6 | S7 | FP |hiddn| RA | PC | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | ABI ARGS | GP | FCTX| DATA| | * + * ------------------------------------------------- * + * * + * *****************************************************/ + +.file "make_mips32_o32_elf_gas.S" +.text +.globl make_fcontext +.align 2 +.type make_fcontext,@function +.ent make_fcontext +make_fcontext: +#ifdef __PIC__ +.set noreorder +.cpload $t9 +.set reorder +#endif + # shift address in A0 to lower 16 byte boundary + li $v1, -16 # 0xfffffffffffffff0 + and $v0, $v1, $a0 + + # reserve space for context-data on context-stack + # includes an extra 32 bytes for: + # - 16-byte incoming argument area required by mips ABI used when + # jump_context calls the initial function + # - 4 bytes to save our GP register used in finish + # - 8 bytes to as space for transfer_t returned to finish + # - 4 bytes for alignment + addiu $v0, $v0, -128 + + # third arg of make_fcontext() == address of context-function + sw $a2, 92($v0) + # save global pointer in context-data + sw $gp, 112($v0) + + # compute address of returned transfer_t + addiu $t0, $v0, 116 + sw $t0, 84($v0) + + # compute abs address of label finish + la $t9, finish + # save address of finish as return-address for context-function + # will be entered after context-function returns + sw $t9, 88($v0) + + jr $ra # return pointer to context-data + +finish: + # reload our gp register (needed for la) + lw $gp, 16($sp) + + # call _exit(0) + # the previous function should have left the 16 bytes incoming argument + # area on the stack which we reuse for calling _exit + la $t9, _exit + move $a0, $zero + jr $t9 +.end make_fcontext +.size make_fcontext, .-make_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/make_mips64_n64_elf_gas.S b/src/boost/libs/context/src/asm/make_mips64_n64_elf_gas.S new file mode 100644 index 000000000..7bb30b14d --- /dev/null +++ b/src/boost/libs/context/src/asm/make_mips64_n64_elf_gas.S @@ -0,0 +1,96 @@ +/* + Copyright Jiaxun Yang 2018. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * + * | F24 | F25 | F26 | F27 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * + * | F28 | F29 | F30 | F31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 72 | 80 | 88 | * + * ------------------------------------------------- * + * | S0 | S1 | S2 | S3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | S4 | S5 | S6 | S7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | FP | GP | RA | PC | * + * ------------------------------------------------- * + * * + * *****************************************************/ + +.file "make_mips64_n64_elf_gas.S" +.text +.globl make_fcontext +.align 3 +.type make_fcontext,@function +.ent make_fcontext +make_fcontext: +#ifdef __PIC__ +.set noreorder +.cpload $t9 +.set reorder +#endif + # shift address in A0 to lower 16 byte boundary + li $v1, 0xfffffffffffffff0 + and $v0, $v1, $a0 + + # reserve space for context-data on context-stack + daddiu $v0, $v0, -160 + + # third arg of make_fcontext() == address of context-function + sd $a2, 152($v0) + # save global pointer in context-data + sd $gp, 136($v0) + + # psudo instruction compute abs address of label finish based on GP + dla $t9, finish + + # save address of finish as return-address for context-function + # will be entered after context-function returns + sd $t9, 144($v0) + + jr $ra # return pointer to context-data + +finish: + # reload our gp register (needed for la) + daddiu $t0, $sp, -160 + ld $gp, 136($t0) + + # call _exit(0) + # the previous function should have left the 16 bytes incoming argument + # area on the stack which we reuse for calling _exit + dla $t9, _exit + move $a0, $zero + jr $t9 +.end make_fcontext +.size make_fcontext, .-make_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/make_ppc32_ppc64_sysv_macho_gas.S b/src/boost/libs/context/src/asm/make_ppc32_ppc64_sysv_macho_gas.S new file mode 100644 index 000000000..52e722093 --- /dev/null +++ b/src/boost/libs/context/src/asm/make_ppc32_ppc64_sysv_macho_gas.S @@ -0,0 +1,16 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__ppc__) + #include "make_ppc32_sysv_macho_gas.S" +#elif defined(__ppc64__) + #include "make_ppc64_sysv_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/src/boost/libs/context/src/asm/make_ppc32_sysv_elf_gas.S b/src/boost/libs/context/src/asm/make_ppc32_sysv_elf_gas.S new file mode 100644 index 000000000..9616c4ca9 --- /dev/null +++ b/src/boost/libs/context/src/asm/make_ppc32_sysv_elf_gas.S @@ -0,0 +1,146 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * |bchai|hiddn| fpscr | PC | CR | R14 | R15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R16 | R17 | R18 | R19 | R20 | R21 | R22 | R23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R24 | R25 | R26 | R27 | R28 | R29 | R30 | R31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------|------------ * + * | 224 | 228 | 232 | 236 | 240 | 244 | * + * ------------------------|------------ * + * | F30 | F31 |bchai| LR | * + * ------------------------|------------ * + * * + *******************************************************/ + +.file "make_ppc32_sysv_elf_gas.S" +.text +.globl make_fcontext +.align 2 +.type make_fcontext,@function +make_fcontext: + # save return address into R6 + mflr %r6 + + # first arg of make_fcontext() == top address of context-function + # shift address in R3 to lower 16 byte boundary + clrrwi %r3, %r3, 4 + + # reserve space on context-stack, including 16 bytes of linkage + # and parameter area + 240 bytes of context-data (R1 % 16 == 0) + subi %r3, %r3, 16 + 240 + + # third arg of make_fcontext() == address of context-function +#ifdef __linux__ + # save context-function as PC + stw %r5, 16(%r3) +#else + # save context-function for trampoline + stw %r5, 248(%r3) +#endif + + # set back-chain to zero + li %r0, 0 + stw %r0, 240(%r3) + + # copy FPSCR to new context + mffs %f0 + stfd %f0, 8(%r3) + +#ifdef __linux__ + # set hidden pointer for returning transfer_t + la %r0, 248(%r3) + stw %r0, 4(%r3) +#endif + + # load address of label 1 into R4 + bl 1f +1: mflr %r4 +#ifndef __linux__ + # compute abs address of trampoline, use as PC + addi %r7, %r4, trampoline - 1b + stw %r7, 16(%r3) +#endif + # compute abs address of label finish + addi %r4, %r4, finish - 1b + # save address of finish as return-address for context-function + # will be entered after context-function returns + stw %r4, 244(%r3) + + # restore return address from R6 + mtlr %r6 + + blr # return pointer to context-data + +#ifndef __linux__ +trampoline: + # On systems other than Linux, jump_fcontext is returning the + # transfer_t in R3:R4, but we need to pass transfer_t * R3 to + # our context-function. + lwz %r0, 8(%r1) # address of context-function + mtctr %r0 + stw %r3, 8(%r1) + stw %r4, 12(%r1) + la %r3, 8(%r1) # address of transfer_t + bctr +#endif + +finish: + # Use the secure PLT for _exit(0). If we use the insecure BSS PLT + # here, then the linker may use the insecure BSS PLT even if the + # C++ compiler wanted the secure PLT. + + # set R30 for secure PLT, large model + bl 2f +2: mflr %r30 + addis %r30, %r30, .Ltoc - 2b@ha + addi %r30, %r30, .Ltoc - 2b@l + + # call _exit(0) with special addend 0x8000 for large model + li %r3, 0 + bl _exit + 0x8000@plt +.size make_fcontext, .-make_fcontext + +/* Provide the GOT pointer for secure PLT, large model. */ +.section .got2,"aw" +.Ltoc = . + 0x8000 + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/make_ppc32_sysv_macho_gas.S b/src/boost/libs/context/src/asm/make_ppc32_sysv_macho_gas.S new file mode 100644 index 000000000..8f35eff9a --- /dev/null +++ b/src/boost/libs/context/src/asm/make_ppc32_sysv_macho_gas.S @@ -0,0 +1,137 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/****************************************************** + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F30 | F31 | fpscr | R13 | R14 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | R31 |hiddn| CR | LR | PC |bchai|linkr| FCTX| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | | * + * ------------------------------------------------- * + * | 256 | | * + * ------------------------------------------------- * + * | DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.globl _make_fcontext +.align 2 +_make_fcontext: + # save return address into R6 + mflr r6 + + # first arg of make_fcontext() == top address of context-function + # shift address in R3 to lower 16 byte boundary + clrrwi r3, r3, 4 + + # reserve space for context-data on context-stack + # including 64 byte of linkage + parameter area (R1 16 == 0) + subi r3, r3, 336 + + # third arg of make_fcontext() == address of context-function + stw r5, 240(r3) + + # set back-chain to zero + li r0, 0 + stw r0, 244(r3) + + mffs f0 # load FPSCR + stfd f0, 144(r3) # save FPSCR + + # compute address of returned transfer_t + addi r0, r3, 252 + mr r4, r0 + stw r4, 228(r3) + + # load LR + mflr r0 + # jump to label 1 + bl 1f +1: + # load LR into R4 + mflr r4 + # compute abs address of label finish + addi r4, r4, finish - 1b + # restore LR + mtlr r0 + # save address of finish as return-address for context-function + # will be entered after context-function returns + stw r4, 236(r3) + + # restore return address from R6 + mtlr r6 + + blr # return pointer to context-data + +finish: + # save return address into R0 + mflr r0 + # save return address on stack, set up stack frame + stw r0, 4(r1) + # allocate stack space, R1 16 == 0 + stwu r1, -16(r1) + + # exit code is zero + li r3, 0 + # exit application + bl _exit@plt diff --git a/src/boost/libs/context/src/asm/make_ppc32_sysv_xcoff_gas.S b/src/boost/libs/context/src/asm/make_ppc32_sysv_xcoff_gas.S new file mode 100644 index 000000000..f25725806 --- /dev/null +++ b/src/boost/libs/context/src/asm/make_ppc32_sysv_xcoff_gas.S @@ -0,0 +1,138 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/****************************************************** + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F30 | F31 | fpscr | R13 | R14 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | R31 |hiddn| CR | LR | PC |bchai|linkr| FCTX| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | | * + * ------------------------------------------------- * + * | 256 | | * + * ------------------------------------------------- * + * | DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + .globl make_fcontext[DS] + .globl .make_fcontext[PR] + .align 2 + .csect make_fcontext[DS] +make_fcontext: + .long .make_fcontext[PR] + .csect .make_fcontext[PR], 3 +#.make_fcontext: + # save return address into R6 + mflr 6 + + # first arg of make_fcontext() == top address of context-function + # shift address in R3 to lower 16 byte boundary + clrrwi 3, 3, 4 + + # reserve space for context-data on context-stack + # including 64 byte of linkage + parameter area (R1 % 16 == 0) + subi 3, 3, 336 + + # third arg of make_fcontext() == address of context-function + stw 5, 240(3) + + # set back-chain to zero + li 0, 0 + stw 0, 244(3) + + # compute address of returned transfer_t + addi 0, 3, 252 + mr 4, 0 + stw 4, 228(3) + + # load LR + mflr 0 + # jump to label 1 + bl .Label +.Label: + # load LR into R4 + mflr 4 + # compute abs address of label .L_finish + addi 4, 4, .L_finish - .Label + # restore LR + mtlr 0 + # save address of finish as return-address for context-function + # will be entered after context-function returns + stw 4, 236(3) + + # restore return address from R6 + mtlr 6 + + blr # return pointer to context-data + +.L_finish: + # save return address into R0 + mflr 0 + # save return address on stack, set up stack frame + stw 0, 4(1) + # allocate stack space, R1 % 16 == 0 + stwu 1, -16(1) + + # exit code is zero + li 3, 0 + # exit application + bl ._exit + nop diff --git a/src/boost/libs/context/src/asm/make_ppc64_sysv_elf_gas.S b/src/boost/libs/context/src/asm/make_ppc64_sysv_elf_gas.S new file mode 100644 index 000000000..c4d7ee598 --- /dev/null +++ b/src/boost/libs/context/src/asm/make_ppc64_sysv_elf_gas.S @@ -0,0 +1,177 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | TOC | R14 | R15 | R16 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R17 | R18 | R19 | R20 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R21 | R22 | R23 | R24 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | R25 | R26 | R27 | R28 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | R29 | R30 | R31 | hidden | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | CR | LR | PC | back-chain| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | cr saved | lr saved | compiler | linker | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | TOC saved | FCTX | DATA | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "make_ppc64_sysv_elf_gas.S" +.globl make_fcontext +#if _CALL_ELF == 2 + .text + .align 2 +make_fcontext: + addis %r2, %r12, .TOC.-make_fcontext@ha + addi %r2, %r2, .TOC.-make_fcontext@l + .localentry make_fcontext, . - make_fcontext +#else + .section ".opd","aw" + .align 3 +make_fcontext: +# ifdef _CALL_LINUX + .quad .L.make_fcontext,.TOC.@tocbase,0 + .type make_fcontext,@function + .text + .align 2 +.L.make_fcontext: +# else + .hidden .make_fcontext + .globl .make_fcontext + .quad .make_fcontext,.TOC.@tocbase,0 + .size make_fcontext,24 + .type .make_fcontext,@function + .text + .align 2 +.make_fcontext: +# endif +#endif + # save return address into R6 + mflr %r6 + + # first arg of make_fcontext() == top address of context-stack + # shift address in R3 to lower 16 byte boundary + clrrdi %r3, %r3, 4 + + # reserve space for context-data on context-stack + # including 64 byte of linkage + parameter area (R1 % 16 == 0) + subi %r3, %r3, 248 + + # third arg of make_fcontext() == address of context-function + # entry point (ELFv2) or descriptor (ELFv1) +#if _CALL_ELF == 2 + # save address of context-function entry point + std %r5, 176(%r3) +#else + # save address of context-function entry point + ld %r4, 0(%r5) + std %r4, 176(%r3) + # save TOC of context-function + ld %r4, 8(%r5) + std %r4, 0(%r3) +#endif + + # set back-chain to zero + li %r0, 0 + std %r0, 184(%r3) + +#if _CALL_ELF != 2 + # zero in r3 indicates first jump to context-function + std %r0, 152(%r3) +#endif + + # load LR + mflr %r0 + # jump to label 1 + bl 1f +1: + # load LR into R4 + mflr %r4 + # compute abs address of label finish + addi %r4, %r4, finish - 1b + # restore LR + mtlr %r0 + # save address of finish as return-address for context-function + # will be entered after context-function returns + std %r4, 168(%r3) + + # restore return address from R6 + mtlr %r6 + + blr # return pointer to context-data + +finish: + # save return address into R0 + mflr %r0 + # save return address on stack, set up stack frame + std %r0, 8(%r1) + # allocate stack space, R1 % 16 == 0 + stdu %r1, -32(%r1) + + # exit code is zero + li %r3, 0 + # exit application + bl _exit + nop +#if _CALL_ELF == 2 + .size make_fcontext, .-make_fcontext +#else +# ifdef _CALL_LINUX + .size .make_fcontext, .-.L.make_fcontext +# else + .size .make_fcontext, .-.make_fcontext +# endif +#endif + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/make_ppc64_sysv_macho_gas.S b/src/boost/libs/context/src/asm/make_ppc64_sysv_macho_gas.S new file mode 100644 index 000000000..7b947bb6b --- /dev/null +++ b/src/boost/libs/context/src/asm/make_ppc64_sysv_macho_gas.S @@ -0,0 +1,126 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | TOC | R14 | R15 | R16 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R17 | R18 | R19 | R20 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R21 | R22 | R23 | R24 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | R25 | R26 | R27 | R28 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | R29 | R30 | R31 | hidden | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | CR | LR | PC | back-chain| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | cr saved | lr saved | compiler | linker | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | TOC saved | FCTX | DATA | | * + * ------------------------------------------------- * + * * + +.text +.globl _make_fcontext +_make_fcontext: + ; save return address into R6 + mflr r6 + + ; first arg of make_fcontext() == top address of context-function + ; shift address in R3 to lower 16 byte boundary + clrrwi r3, r3, 4 + + ; reserve space for context-data on context-stack + ; including 64 byte of linkage + parameter area (R1 16 == 0) + subi r3, r3, 248 + + ; third arg of make_fcontext() == address of context-function + stw r5, 176(r3) + + ; set back-chain to zero + li %r0, 0 + std %r0, 184(%r3) + + ; compute address of returned transfer_t + addi %r0, %r3, 232 + mr %r4, %r0 + std %r4, 152(%r3) + + ; load LR + mflr r0 + ; jump to label 1 + bl l1 +l1: + ; load LR into R4 + mflr r4 + ; compute abs address of label finish + addi r4, r4, lo16((finish - .) + 4) + ; restore LR + mtlr r0 + ; save address of finish as return-address for context-function + ; will be entered after context-function returns + std r4, 168(r3) + + ; restore return address from R6 + mtlr r6 + + blr ; return pointer to context-data + +finish: + ; save return address into R0 + mflr r0 + ; save return address on stack, set up stack frame + stw r0, 8(r1) + ; allocate stack space, R1 16 == 0 + stwu r1, -32(r1) + + ; set return value to zero + li r3, 0 + ; exit application + bl __exit + nop diff --git a/src/boost/libs/context/src/asm/make_ppc64_sysv_xcoff_gas.S b/src/boost/libs/context/src/asm/make_ppc64_sysv_xcoff_gas.S new file mode 100644 index 000000000..60ad6b6b2 --- /dev/null +++ b/src/boost/libs/context/src/asm/make_ppc64_sysv_xcoff_gas.S @@ -0,0 +1,68 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + .globl make_fcontext[DS] + .globl .make_fcontext[PR] + .align 2 + .csect .make_fcontext[PR], 3 + .globl _make_fcontext +#._make_fcontext: + # save return address into R6 + mflr 6 + + # first arg of make_fcontext() == top address of context-function + # shift address in R3 to lower 16 byte boundary + clrrwi 3, 3, 4 + + # reserve space for context-data on context-stack + # including 64 byte of linkage + parameter area (R1 % 16 == 0) + subi 3, 3, 248 + + # third arg of make_fcontext() == address of context-function + stw 5, 176(3) + + # set back-chain to zero + li 0, 0 + std 0, 184(3) + + # compute address of returned transfer_t + addi 0, 3, 232 + mr 4, 0 + std 4, 152(3) + + # load LR + mflr 0 + # jump to label 1 + bl .Label +.Label: + # load LR into R4 + mflr 4 + # compute abs address of label .L_finish + addi 4, 4, .L_finish - .Label + # restore LR + mtlr 0 + # save address of finish as return-address for context-function + # will be entered after context-function returns + stw 4, 168(3) + + # restore return address from R6 + mtlr 6 + + blr # return pointer to context-data + +.L_finish: + # save return address into R0 + mflr 0 + # save return address on stack, set up stack frame + stw 0, 8(1) + # allocate stack space, R1 % 16 == 0 + stwu 1, -32(1) + + # exit code is zero + li 3, 0 + # exit application + bl ._exit + nop diff --git a/src/boost/libs/context/src/asm/make_riscv64_sysv_elf_gas.S b/src/boost/libs/context/src/asm/make_riscv64_sysv_elf_gas.S new file mode 100644 index 000000000..5322e0fdb --- /dev/null +++ b/src/boost/libs/context/src/asm/make_riscv64_sysv_elf_gas.S @@ -0,0 +1,91 @@ +/* + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | fs0 | fs1 | fs2 | fs3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | fs4 | fs5 | fs6 | fs7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | fs8 | fs9 | fs10 | fs11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | s0 | s1 | s2 | s3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | s4 | s5 | s6 | s7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * + * ------------------------------------------------- * + * | s8 | s9 | s10 | s11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | | | | | * + * ------------------------------------------------- * + * | 0xc0| 0xc4| 0xc8| 0xcc| | | | | * + * ------------------------------------------------- * + * | ra | pc | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "make_riscv64_sysv_elf_gas.S" +.text +.align 1 +.global make_fcontext +.type make_fcontext, %function +make_fcontext: + # shift address in a0 (allocated stack) to lower 16 byte boundary + andi a0, a0, ~0xF + + # reserve space for context-data on context-stack + addi a0, a0, -0xd0 + + # third arg of make_fcontext() == address of context-function + # store address as a PC to jump in + sd a2, 0xc8(a0) + + # save address of finish as return-address for context-function + # will be entered after context-function returns (RA register) + lla a4, finish + sd a4, 0xc0(a0) + + ret // return pointer to context-data (a0) + +finish: + # exit code is zero + li a0, 0 + # exit application + tail _exit@plt + +.size make_fcontext,.-make_fcontext +# Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/make_s390x_sysv_elf_gas.S b/src/boost/libs/context/src/asm/make_s390x_sysv_elf_gas.S new file mode 100644 index 000000000..e7e2d5f6e --- /dev/null +++ b/src/boost/libs/context/src/asm/make_s390x_sysv_elf_gas.S @@ -0,0 +1,108 @@ +/******************************************************* + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * + * | t.fctx | t.data | r2 | r6 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * + * | r7 | r8 | r9 | r10 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 72 | 80 | 88 | * + * ------------------------------------------------- * + * | r11 | r12 | r13 | r14 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 104 | 112 | 120 | * + * ------------------------------------------------- * + * | f8 | f9 | f10 | f11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 136 | 144 | 152 | * + * ------------------------------------------------- * + * | f12 | f13 | f14 | f15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 168 | 176 | | * + * ------------------------------------------------- * + * | fpc | pc | | | * + * ------------------------------------------------- * + *******************************************************/ + +.text +.align 8 +.global make_fcontext +.type make_fcontext, @function + +#define ARG_OFFSET 0 +#define GR_OFFSET 16 +#define R14_OFFSET 88 +#define FP_OFFSET 96 +#define FPC_OFFSET 160 +#define PC_OFFSET 168 +#define CONTEXT_SIZE 176 + +/* + +fcontext_t make_fcontext( void * sp, std::size_t size, void (* fn)( transfer_t) ); + +Create and return a context below SP to call FN. + +Incoming args +r2 - The stack location where to create the context +r3 - The size of the context +r4 - The address of the context function + +*/ + +make_fcontext: + .machine "z10" + /* Align the stack to an 8 byte boundary. */ + nill %r2,0xfff0 + + /* Allocate stack space for the context. */ + aghi %r2,-CONTEXT_SIZE + + /* Set the r2 save slot to zero. This indicates jump_fcontext + that this is a special context. */ + mvghi GR_OFFSET(%r2),0 + + /* Save the floating point control register. */ + stfpc FPC_OFFSET(%r2) + + /* Store the address of the target function as new pc. */ + stg %r4,PC_OFFSET(%r2) + + /* Store a pointer to the finish routine as r14. If a function + called via context routines just returns that value will be + loaded and used as return address. Hence the program will + just exit. */ + larl %r1,finish + stg %r1,R14_OFFSET(%r2) + + /* Return as usual with the new context returned in r2. */ + br %r14 + +finish: + /* In finish tasks, you load the exit code and exit the + make_fcontext This is called when the context-function is + entirely executed. */ + lghi %r2,0 + brasl %r14,_exit@PLT + +.size make_fcontext,.-make_fcontext +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/make_x86_64_ms_pe_gas.asm b/src/boost/libs/context/src/asm/make_x86_64_ms_pe_gas.asm new file mode 100644 index 000000000..958a2a7b6 --- /dev/null +++ b/src/boost/libs/context/src/asm/make_x86_64_ms_pe_gas.asm @@ -0,0 +1,174 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* ---------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* ---------------------------------------------------------------------------------- * +* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* ---------------------------------------------------------------------------------- * +* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +* ---------------------------------------------------------------------------------- * +* | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +* ---------------------------------------------------------------------------------- * +* | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | * +* ---------------------------------------------------------------------------------- * +* | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | * +* ---------------------------------------------------------------------------------- * +* | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | * +* ---------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | * +* ---------------------------------------------------------------------------------- * +* | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | * +* ---------------------------------------------------------------------------------- * +* | limit | base | R12 | R13 | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | * +* ---------------------------------------------------------------------------------- * +* | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | * +* ---------------------------------------------------------------------------------- * +* | R14 | R15 | RDI | RSI | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | * +* ---------------------------------------------------------------------------------- * +* | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | * +* ---------------------------------------------------------------------------------- * +* | RBX | RBP | hidden | RIP | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | * +* ---------------------------------------------------------------------------------- * +* | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | * +* ---------------------------------------------------------------------------------- * +* | parameter area | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | * +* ---------------------------------------------------------------------------------- * +* | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | * +* ---------------------------------------------------------------------------------- * +* | FCTX | DATA | | * +* ---------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "make_x86_64_ms_pe_gas.asm" +.text +.p2align 4,,15 +.globl make_fcontext +.def make_fcontext; .scl 2; .type 32; .endef +.seh_proc make_fcontext +make_fcontext: +.seh_endprologue + + /* first arg of make_fcontext() == top of context-stack */ + movq %rcx, %rax + + /* shift address in RAX to lower 16 byte boundary */ + /* == pointer to fcontext_t and address of context stack */ + andq $-16, %rax + + /* reserve space for context-data on context-stack */ + /* on context-function entry: (RSP -0x8) % 16 == 0 */ + leaq -0x150(%rax), %rax + + /* third arg of make_fcontext() == address of context-function */ + movq %r8, 0x100(%rax) + + /* first arg of make_fcontext() == top of context-stack */ + /* save top address of context stack as 'base' */ + movq %rcx, 0xc8(%rax) + /* second arg of make_fcontext() == size of context-stack */ + /* negate stack size for LEA instruction (== substraction) */ + negq %rdx + /* compute bottom address of context stack (limit) */ + leaq (%rcx,%rdx), %rcx + /* save bottom address of context stack as 'limit' */ + movq %rcx, 0xc0(%rax) + /* save address of context stack limit as 'dealloction stack' */ + movq %rcx, 0xb8(%rax) + /* set fiber-storage to zero */ + xorq %rcx, %rcx + movq %rcx, 0xb0(%rax) + + /* save MMX control- and status-word */ + stmxcsr 0xa0(%rax) + /* save x87 control-word */ + fnstcw 0xa4(%rax) + + /* compute address of transport_t */ + leaq 0x140(%rax), %rcx + /* store address of transport_t in hidden field */ + movq %rcx, 0x110(%rax) + + /* compute abs address of label trampoline */ + leaq trampoline(%rip), %rcx + /* save address of finish as return-address for context-function */ + /* will be entered after jump_fcontext() first time */ + movq %rcx, 0x118(%rax) + + /* compute abs address of label finish */ + leaq finish(%rip), %rcx + /* save address of finish as return-address for context-function */ + /* will be entered after context-function returns */ + movq %rcx, 0x108(%rax) + + ret /* return pointer to context-data */ + +trampoline: + /* store return address on stack */ + /* fix stack alignment */ + pushq %rbp + /* jump to context-function */ + jmp *%rbx + +finish: + /* 32byte shadow-space for _exit() */ + andq $-32, %rsp + /* 32byte shadow-space for _exit() are */ + /* already reserved by make_fcontext() */ + /* exit code is zero */ + xorq %rcx, %rcx + /* exit application */ + call _exit + hlt +.seh_endproc + +.def _exit; .scl 2; .type 32; .endef /* standard C library function */ + +.section .drectve +.ascii " -export:\"make_fcontext\"" diff --git a/src/boost/libs/context/src/asm/make_x86_64_ms_pe_masm.asm b/src/boost/libs/context/src/asm/make_x86_64_ms_pe_masm.asm new file mode 100644 index 000000000..8f6c959a8 --- /dev/null +++ b/src/boost/libs/context/src/asm/make_x86_64_ms_pe_masm.asm @@ -0,0 +1,163 @@ + +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) + +; ---------------------------------------------------------------------------------- +; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +; ---------------------------------------------------------------------------------- +; | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | +; ---------------------------------------------------------------------------------- +; | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | +; ---------------------------------------------------------------------------------- +; | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | +; ---------------------------------------------------------------------------------- +; | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | +; ---------------------------------------------------------------------------------- +; | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | +; ---------------------------------------------------------------------------------- +; | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | +; ---------------------------------------------------------------------------------- +; | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | +; ---------------------------------------------------------------------------------- +; | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | +; ---------------------------------------------------------------------------------- +; | limit | base | R12 | R13 | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | +; ---------------------------------------------------------------------------------- +; | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | +; ---------------------------------------------------------------------------------- +; | R14 | R15 | RDI | RSI | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | +; ---------------------------------------------------------------------------------- +; | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | +; ---------------------------------------------------------------------------------- +; | RBX | RBP | hidden | RIP | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | +; ---------------------------------------------------------------------------------- +; | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | +; ---------------------------------------------------------------------------------- +; | parameter area | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | +; ---------------------------------------------------------------------------------- +; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | +; ---------------------------------------------------------------------------------- +; | FCTX | DATA | | +; ---------------------------------------------------------------------------------- + +; standard C library function +EXTERN _exit:PROC +.code + +; generate function table entry in .pdata and unwind information in +make_fcontext PROC BOOST_CONTEXT_EXPORT FRAME + ; .xdata for a function's structured exception handling unwind behavior + .endprolog + + ; first arg of make_fcontext() == top of context-stack + mov rax, rcx + + ; shift address in RAX to lower 16 byte boundary + ; == pointer to fcontext_t and address of context stack + and rax, -16 + + ; reserve space for context-data on context-stack + ; on context-function entry: (RSP -0x8) % 16 == 0 + sub rax, 0150h + + ; third arg of make_fcontext() == address of context-function + ; stored in RBX + mov [rax+0100h], r8 + + ; first arg of make_fcontext() == top of context-stack + ; save top address of context stack as 'base' + mov [rax+0c8h], rcx + ; second arg of make_fcontext() == size of context-stack + ; negate stack size for LEA instruction (== substraction) + neg rdx + ; compute bottom address of context stack (limit) + lea rcx, [rcx+rdx] + ; save bottom address of context stack as 'limit' + mov [rax+0c0h], rcx + ; save address of context stack limit as 'dealloction stack' + mov [rax+0b8h], rcx + ; set fiber-storage to zero + xor rcx, rcx + mov [rax+0b0h], rcx + + ; save MMX control- and status-word + stmxcsr [rax+0a0h] + ; save x87 control-word + fnstcw [rax+0a4h] + + ; compute address of transport_t + lea rcx, [rax+0140h] + ; store address of transport_t in hidden field + mov [rax+0110h], rcx + + ; compute abs address of label trampoline + lea rcx, trampoline + ; save address of trampoline as return-address for context-function + ; will be entered after calling jump_fcontext() first time + mov [rax+0118h], rcx + + ; compute abs address of label finish + lea rcx, finish + ; save address of finish as return-address for context-function in RBP + ; will be entered after context-function returns + mov [rax+0108h], rcx + + ret ; return pointer to context-data + +trampoline: + ; store return address on stack + ; fix stack alignment + push rbp + ; jump to context-function + jmp rbx + +finish: + ; exit code is zero + xor rcx, rcx + ; exit application + call _exit + hlt +make_fcontext ENDP +END diff --git a/src/boost/libs/context/src/asm/make_x86_64_sysv_elf_gas.S b/src/boost/libs/context/src/asm/make_x86_64_sysv_elf_gas.S new file mode 100644 index 000000000..0ef37569a --- /dev/null +++ b/src/boost/libs/context/src/asm/make_x86_64_sysv_elf_gas.S @@ -0,0 +1,82 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * + * ---------------------------------------------------------------------------------- * + * | R15 | RBX | RBP | RIP | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.file "make_x86_64_sysv_elf_gas.S" +.text +.globl make_fcontext +.type make_fcontext,@function +.align 16 +make_fcontext: + /* first arg of make_fcontext() == top of context-stack */ + movq %rdi, %rax + + /* shift address in RAX to lower 16 byte boundary */ + andq $-16, %rax + + /* reserve space for context-data on context-stack */ + /* on context-function entry: (RSP -0x8) % 16 == 0 */ + leaq -0x40(%rax), %rax + + /* third arg of make_fcontext() == address of context-function */ + /* stored in RBX */ + movq %rdx, 0x28(%rax) + + /* save MMX control- and status-word */ + stmxcsr (%rax) + /* save x87 control-word */ + fnstcw 0x4(%rax) + + /* compute abs address of label trampoline */ + leaq trampoline(%rip), %rcx + /* save address of trampoline as return-address for context-function */ + /* will be entered after calling jump_fcontext() first time */ + movq %rcx, 0x38(%rax) + + /* compute abs address of label finish */ + leaq finish(%rip), %rcx + /* save address of finish as return-address for context-function */ + /* will be entered after context-function returns */ + movq %rcx, 0x30(%rax) + + ret /* return pointer to context-data */ + +trampoline: + /* store return address on stack */ + /* fix stack alignment */ + push %rbp + /* jump to context-function */ + jmp *%rbx + +finish: + /* exit code is zero */ + xorq %rdi, %rdi + /* exit application */ + call _exit@PLT + hlt +.size make_fcontext,.-make_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/make_x86_64_sysv_macho_gas.S b/src/boost/libs/context/src/asm/make_x86_64_sysv_macho_gas.S new file mode 100644 index 000000000..5d6c5431c --- /dev/null +++ b/src/boost/libs/context/src/asm/make_x86_64_sysv_macho_gas.S @@ -0,0 +1,76 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * + * ---------------------------------------------------------------------------------- * + * | R15 | RBX | RBP | RIP | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.text +.globl _make_fcontext +.align 8 +_make_fcontext: + /* first arg of make_fcontext() == top of context-stack */ + movq %rdi, %rax + + /* shift address in RAX to lower 16 byte boundary */ + andq $-16, %rax + + /* reserve space for context-data on context-stack */ + /* on context-function entry: (RSP -0x8) % 16 == 0 */ + leaq -0x40(%rax), %rax + + /* third arg of make_fcontext() == address of context-function */ + /* stored in RBX */ + movq %rdx, 0x28(%rax) + + /* save MMX control- and status-word */ + stmxcsr (%rax) + /* save x87 control-word */ + fnstcw 0x4(%rax) + + /* compute abs address of label trampoline */ + leaq trampoline(%rip), %rcx + /* save address of trampoline as return-address for context-function */ + /* will be entered after calling jump_fcontext() first time */ + movq %rcx, 0x38(%rax) + + /* compute abs address of label finish */ + leaq finish(%rip), %rcx + /* save address of finish as return-address for context-function */ + /* will be entered after context-function returns */ + movq %rcx, 0x30(%rax) + + ret /* return pointer to context-data */ + +trampoline: + /* store return address on stack */ + /* fix stack alignment */ + push %rbp + /* jump to context-function */ + jmp *%rbx + +finish: + /* exit code is zero */ + xorq %rdi, %rdi + /* exit application */ + call __exit + hlt diff --git a/src/boost/libs/context/src/asm/ontop_arm64_aapcs_elf_gas.S b/src/boost/libs/context/src/asm/ontop_arm64_aapcs_elf_gas.S new file mode 100644 index 000000000..665ca5a2c --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_arm64_aapcs_elf_gas.S @@ -0,0 +1,113 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | d8 | d9 | d10 | d11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | d12 | d13 | d14 | d15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | x19 | x20 | x21 | x22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | x23 | x24 | x25 | x26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | x27 | x28 | FP | LR | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | | | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| | | * + * ------------------------------------------------- * + * | PC | align | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "ontop_arm64_aapcs_elf_gas.S" +.text +.align 2 +.global ontop_fcontext +.type ontop_fcontext, %function +ontop_fcontext: + # prepare stack for GP + FPU + sub sp, sp, #0xb0 + + # save d8 - d15 + stp d8, d9, [sp, #0x00] + stp d10, d11, [sp, #0x10] + stp d12, d13, [sp, #0x20] + stp d14, d15, [sp, #0x30] + + # save x19-x30 + stp x19, x20, [sp, #0x40] + stp x21, x22, [sp, #0x50] + stp x23, x24, [sp, #0x60] + stp x25, x26, [sp, #0x70] + stp x27, x28, [sp, #0x80] + stp x29, x30, [sp, #0x90] + + # save LR as PC + str x30, [sp, #0xa0] + + # store RSP (pointing to context-data) in X5 + mov x4, sp + + # restore RSP (pointing to context-data) from X1 + mov sp, x0 + + # load d8 - d15 + ldp d8, d9, [sp, #0x00] + ldp d10, d11, [sp, #0x10] + ldp d12, d13, [sp, #0x20] + ldp d14, d15, [sp, #0x30] + + # load x19-x30 + ldp x19, x20, [sp, #0x40] + ldp x21, x22, [sp, #0x50] + ldp x23, x24, [sp, #0x60] + ldp x25, x26, [sp, #0x70] + ldp x27, x28, [sp, #0x80] + ldp x29, x30, [sp, #0x90] + + # return transfer_t from jump + # pass transfer_t as first arg in context function + # X0 == FCTX, X1 == DATA + mov x0, x4 + + # skip pc + # restore stack from GP + FPU + add sp, sp, #0xb0 + + # jump to ontop-function + ret x2 +.size ontop_fcontext,.-ontop_fcontext +# Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/ontop_arm64_aapcs_macho_gas.S b/src/boost/libs/context/src/asm/ontop_arm64_aapcs_macho_gas.S new file mode 100644 index 000000000..a387d06dd --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_arm64_aapcs_macho_gas.S @@ -0,0 +1,108 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | d8 | d9 | d10 | d11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | d12 | d13 | d14 | d15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | x19 | x20 | x21 | x22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | x23 | x24 | x25 | x26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | x27 | x28 | FP | LR | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | | | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| | | * + * ------------------------------------------------- * + * | PC | align | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.global _ontop_fcontext +.balign 16 +_ontop_fcontext: + ; prepare stack for GP + FPU + sub sp, sp, #0xb0 + + ; save d8 - d15 + stp d8, d9, [sp, #0x00] + stp d10, d11, [sp, #0x10] + stp d12, d13, [sp, #0x20] + stp d14, d15, [sp, #0x30] + + ; save x19-x30 + stp x19, x20, [sp, #0x40] + stp x21, x22, [sp, #0x50] + stp x23, x24, [sp, #0x60] + stp x25, x26, [sp, #0x70] + stp x27, x28, [sp, #0x80] + stp x29, x30, [sp, #0x90] + + ; save LR as PC + str x30, [sp, #0xa0] + + ; store RSP (pointing to context-data) in X5 + mov x4, sp + + ; restore RSP (pointing to context-data) from X1 + mov sp, x0 + + ; load d8 - d15 + ldp d8, d9, [sp, #0x00] + ldp d10, d11, [sp, #0x10] + ldp d12, d13, [sp, #0x20] + ldp d14, d15, [sp, #0x30] + + ; load x19-x30 + ldp x19, x20, [sp, #0x40] + ldp x21, x22, [sp, #0x50] + ldp x23, x24, [sp, #0x60] + ldp x25, x26, [sp, #0x70] + ldp x27, x28, [sp, #0x80] + ldp x29, x30, [sp, #0x90] + + ; return transfer_t from jump + ; pass transfer_t as first arg in context function + ; X0 == FCTX, X1 == DATA + mov x0, x4 + + ; skip pc + ; restore stack from GP + FPU + add sp, sp, #0xb0 + + ; jump to ontop-function + ret x2 diff --git a/src/boost/libs/context/src/asm/ontop_arm_aapcs_elf_gas.S b/src/boost/libs/context/src/asm/ontop_arm_aapcs_elf_gas.S new file mode 100644 index 000000000..59ad5ca9c --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_arm_aapcs_elf_gas.S @@ -0,0 +1,93 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * |hiddn| v1 | v2 | v3 | v4 | v5 | v6 | v7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | v8 | lr | pc | FCTX| DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "ontop_arm_aapcs_elf_gas.S" +.text +.globl ontop_fcontext +.align 2 +.type ontop_fcontext,%function +.syntax unified +ontop_fcontext: + @ save LR as PC + push {lr} + @ save hidden,V1-V8,LR + push {a1,v1-v8,lr} + + @ prepare stack for FPU + sub sp, sp, #64 +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) + @ save S16-S31 + vstmia sp, {d8-d15} +#endif + + @ store RSP (pointing to context-data) in A1 + mov a1, sp + + @ restore RSP (pointing to context-data) from A2 + mov sp, a2 + + @ store parent context in A2 + mov a2, a1 + +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) + @ restore S16-S31 + vldmia sp, {d8-d15} +#endif + @ prepare stack for FPU + add sp, sp, #64 + + @ restore hidden,V1-V8,LR + pop {a1,v1-v8,lr} + + @ return transfer_t from jump + str a2, [a1, #0] + str a3, [a1, #4] + @ pass transfer_t as first arg in context function + @ A1 == hidden, A2 == FCTX, A3 == DATA + + @ skip PC + add sp, sp, #4 + + @ jump to ontop-function + bx a4 +.size ontop_fcontext,.-ontop_fcontext + +@ Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/ontop_arm_aapcs_macho_gas.S b/src/boost/libs/context/src/asm/ontop_arm_aapcs_macho_gas.S new file mode 100644 index 000000000..421fcb455 --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_arm_aapcs_macho_gas.S @@ -0,0 +1,100 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | sjlj|hiddn| v1 | v2 | v3 | v4 | v5 | v6 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | v7 | v8 | lr | pc | FCTX| DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.globl _ontop_fcontext +.align 2 +_ontop_fcontext: + @ save LR as PC + push {lr} + @ save hidden,V1-V8,LR + push {a1,v1-v8,lr} + + @ locate TLS to save/restore SjLj handler + mrc p15, 0, v2, c13, c0, #3 + bic v2, v2, #3 + + @ load TLS[__PTK_LIBC_DYLD_Unwind_SjLj_Key] + ldr v1, [v2, #8] + @ save SjLj handler + push {v1} + + @ prepare stack for FPU + sub sp, sp, #64 +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) + @ save S16-S31 + vstmia sp, {d8-d15} +#endif + + @ store RSP (pointing to context-data) in A1 + mov a1, sp + + @ restore RSP (pointing to context-data) from A2 + mov sp, a2 + +#if (defined(__VFP_FP__) && !defined(__SOFTFP__)) + @ restore S16-S31 + vldmia sp, {d8-d15} +#endif + @ prepare stack for FPU + add sp, sp, #64 + + @ restore SjLj handler + pop {v1} + @ store SjLj handler in TLS + str v1, [v2, #8] + + @ store parent context in A2 + mov a2, a1 + + @ restore hidden,V1-V8,LR + pop {a1,v1-v8,lr} + + @ return transfer_t from jump + str a2, [a1, #0] + str a3, [a1, #4] + @ pass transfer_t as first arg in context function + @ A1 == hidden, A2 == FCTX, A3 == DATA + + @ skip PC + add sp, sp, #4 + + @ jump to ontop-function + bx a4 diff --git a/src/boost/libs/context/src/asm/ontop_arm_aapcs_pe_armasm.asm b/src/boost/libs/context/src/asm/ontop_arm_aapcs_pe_armasm.asm new file mode 100644 index 000000000..f360a8ffc --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_arm_aapcs_pe_armasm.asm @@ -0,0 +1,86 @@ +;/* +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) +;*/ + +; ******************************************************* +; * * +; * ------------------------------------------------- * +; * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +; * ------------------------------------------------- * +; * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * +; * ------------------------------------------------- * +; * |deall|limit| base|hiddn| v1 | v2 | v3 | v4 | * +; * ------------------------------------------------- * +; * ------------------------------------------------- * +; * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +; * ------------------------------------------------- * +; * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * +; * ------------------------------------------------- * +; * | v5 | v6 | v7 | v8 | lr | pc | FCTX| DATA| * +; * ------------------------------------------------- * +; * * +; ******************************************************* + + AREA |.text|, CODE + ALIGN 4 + EXPORT ontop_fcontext + +ontop_fcontext PROC + ; save LR as PC + push {lr} + ; save hidden,V1-V8,LR + push {a1,v1-v8,lr} + + ; load TIB to save/restore thread size and limit. + ; we do not need preserve CPU flag and can use it's arg register + mrc p15, #0, v1, c13, c0, #2 + + ; save current stack base + ldr a1, [v1, #0x04] + push {a1} + ; save current stack limit + ldr a1, [v1, #0x08] + push {a1} + ; save current deallocation stack + ldr a1, [v1, #0xe0c] + push {a1} + + ; store RSP (pointing to context-data) in A1 + mov a1, sp + + ; restore RSP (pointing to context-data) from A2 + mov sp, a2 + + ; restore stack base + pop {a1} + str a1, [v1, #0x04] + ; restore stack limit + pop {a1} + str a1, [v1, #0x08] + ; restore deallocation stack + pop {a1} + str a1, [v1, #0xe0c] + + ; store parent context in A2 + mov a2, a1 + + ; restore hidden,V1-V8,LR + pop {a1,v1-v8,lr} + + ; return transfer_t from jump + str a2, [a1, #0] + str a3, [a1, #4] + ; pass transfer_t as first arg in context function + ; A1 == hidden, A2 == FCTX, A3 == DATA + + ; skip PC + add sp, sp, #4 + + ; jump to ontop-function + bx a4 + + ENDP + END diff --git a/src/boost/libs/context/src/asm/ontop_combined_sysv_macho_gas.S b/src/boost/libs/context/src/asm/ontop_combined_sysv_macho_gas.S new file mode 100644 index 000000000..20cbeb9f2 --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_combined_sysv_macho_gas.S @@ -0,0 +1,20 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__i386__) + #include "ontop_i386_sysv_macho_gas.S" +#elif defined(__x86_64__) + #include "ontop_x86_64_sysv_macho_gas.S" +#elif defined(__ppc__) + #include "ontop_ppc32_sysv_macho_gas.S" +#elif defined(__ppc64__) + #include "ontop_ppc64_sysv_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/src/boost/libs/context/src/asm/ontop_i386_ms_pe_gas.asm b/src/boost/libs/context/src/asm/ontop_i386_ms_pe_gas.asm new file mode 100644 index 000000000..c23e18a29 --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_i386_ms_pe_gas.asm @@ -0,0 +1,131 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* --------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* --------------------------------------------------------------------------------- * +* | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | * +* --------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | * +* --------------------------------------------------------------------------------- * +* --------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* --------------------------------------------------------------------------------- * +* | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | * +* --------------------------------------------------------------------------------- * +* | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| * +* --------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "ontop_i386_ms_pe_gas.asm" +.text +.p2align 4,,15 + +/* mark as using no unregistered SEH handlers */ +.globl @feat.00 +.def @feat.00; .scl 3; .type 0; .endef +.set @feat.00, 1 + +.globl _ontop_fcontext +.def _ontop_fcontext; .scl 2; .type 32; .endef +_ontop_fcontext: + /* prepare stack */ + leal -0x2c(%esp), %esp + +#if !defined(BOOST_USE_TSX) + /* save MMX control- and status-word */ + stmxcsr (%esp) + /* save x87 control-word */ + fnstcw 0x4(%esp) +#endif + + /* load NT_TIB */ + movl %fs:(0x18), %edx + /* load fiber local storage */ + movl 0x10(%edx), %eax + movl %eax, 0x8(%esp) + /* load current dealloction stack */ + movl 0xe0c(%edx), %eax + movl %eax, 0xc(%esp) + /* load current stack limit */ + movl 0x8(%edx), %eax + movl %eax, 0x10(%esp) + /* load current stack base */ + movl 0x4(%edx), %eax + movl %eax, 0x14(%esp) + /* load current SEH exception list */ + movl (%edx), %eax + movl %eax, 0x18(%esp) + + movl %edi, 0x1c(%esp) /* save EDI */ + movl %esi, 0x20(%esp) /* save ESI */ + movl %ebx, 0x24(%esp) /* save EBX */ + movl %ebp, 0x28(%esp) /* save EBP */ + + /* store ESP (pointing to context-data) in ECX */ + movl %esp, %ecx + + /* first arg of ontop_fcontext() == fcontext to jump to */ + movl 0x30(%esp), %eax + + /* pass parent fcontext_t */ + movl %ecx, 0x30(%eax) + + /* second arg of ontop_fcontext() == data to be transferred */ + movl 0x34(%esp), %ecx + + /* pass data */ + movl %ecx, 0x34(%eax) + + /* third arg of ontop_fcontext() == ontop-function */ + movl 0x38(%esp), %ecx + + /* restore ESP (pointing to context-data) from EDX */ + movl %eax, %esp + +#if !defined(BOOST_USE_TSX) + /* restore MMX control- and status-word */ + ldmxcsr (%esp) + /* restore x87 control-word */ + fldcw 0x4(%esp) +#endif + + /* restore NT_TIB into EDX */ + movl %fs:(0x18), %edx + /* restore fiber local storage */ + movl 0x8(%esp), %eax + movl %eax, 0x10(%edx) + /* restore current deallocation stack */ + movl 0xc(%esp), %eax + movl %eax, 0xe0c(%edx) + /* restore current stack limit */ + movl 0x10(%esp), %eax + movl %eax, 0x08(%edx) + /* restore current stack base */ + movl 0x14(%esp), %eax + movl %eax, 0x04(%edx) + /* restore current SEH exception list */ + movl 0x18(%esp), %eax + movl %eax, (%edx) + + movl 0x1c(%esp), %edi /* restore EDI */ + movl 0x20(%esp), %esi /* restore ESI */ + movl 0x24(%esp), %ebx /* restore EBX */ + movl 0x28(%esp), %ebp /* restore EBP */ + + /* prepare stack */ + leal 0x2c(%esp), %esp + + /* keep return-address on stack */ + + /* jump to context */ + jmp *%ecx + +.section .drectve +.ascii " -export:\"_ontop_fcontext\"" diff --git a/src/boost/libs/context/src/asm/ontop_i386_ms_pe_masm.asm b/src/boost/libs/context/src/asm/ontop_i386_ms_pe_masm.asm new file mode 100644 index 000000000..82246a4a2 --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_i386_ms_pe_masm.asm @@ -0,0 +1,124 @@ + +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) + +; --------------------------------------------------------------------------------- +; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +; --------------------------------------------------------------------------------- +; | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | +; --------------------------------------------------------------------------------- +; | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | +; --------------------------------------------------------------------------------- +; --------------------------------------------------------------------------------- +; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | +; --------------------------------------------------------------------------------- +; | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | +; --------------------------------------------------------------------------------- +; | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| +; --------------------------------------------------------------------------------- + +.386 +.XMM +.model flat, c +.code + +ontop_fcontext PROC BOOST_CONTEXT_EXPORT + ; prepare stack + lea esp, [esp-02ch] + +IFNDEF BOOST_USE_TSX + ; save MMX control- and status-word + stmxcsr [esp] + ; save x87 control-word + fnstcw [esp+04h] +ENDIF + + assume fs:nothing + ; load NT_TIB into ECX + mov edx, fs:[018h] + assume fs:error + ; load fiber local storage + mov eax, [edx+010h] + mov [esp+08h], eax + ; load current deallocation stack + mov eax, [edx+0e0ch] + mov [esp+0ch], eax + ; load current stack limit + mov eax, [edx+08h] + mov [esp+010h], eax + ; load current stack base + mov eax, [edx+04h] + mov [esp+014h], eax + ; load current SEH exception list + mov eax, [edx] + mov [esp+018h], eax + + mov [esp+01ch], edi ; save EDI + mov [esp+020h], esi ; save ESI + mov [esp+024h], ebx ; save EBX + mov [esp+028h], ebp ; save EBP + + ; store ESP (pointing to context-data) in ECX + mov ecx, esp + + ; first arg of ontop_fcontext() == fcontext to jump to + mov eax, [esp+030h] + + ; pass parent fcontext_t + mov [eax+030h], ecx + + ; second arg of ontop_fcontext() == data to be transferred + mov ecx, [esp+034h] + + ; pass data + mov [eax+034h], ecx + + ; third arg of ontop_fcontext() == ontop-function + mov ecx, [esp+038h] + + ; restore ESP (pointing to context-data) from EAX + mov esp, eax + +IFNDEF BOOST_USE_TSX + ; restore MMX control- and status-word + ldmxcsr [esp] + ; restore x87 control-word + fldcw [esp+04h] +ENDIF + + assume fs:nothing + ; load NT_TIB into EDX + mov edx, fs:[018h] + assume fs:error + ; restore fiber local storage + mov eax, [esp+08h] + mov [edx+010h], eax + ; restore current deallocation stack + mov eax, [esp+0ch] + mov [edx+0e0ch], eax + ; restore current stack limit + mov eax, [esp+010h] + mov [edx+08h], eax + ; restore current stack base + mov eax, [esp+014h] + mov [edx+04h], eax + ; restore current SEH exception list + mov eax, [esp+018h] + mov [edx], eax + + mov edi, [esp+01ch] ; restore EDI + mov esi, [esp+020h] ; restore ESI + mov ebx, [esp+024h] ; restore EBX + mov ebp, [esp+028h] ; restore EBP + + ; prepare stack + lea esp, [esp+02ch] + + ; keep return-address on stack + + ; jump to context + jmp ecx +ontop_fcontext ENDP +END diff --git a/src/boost/libs/context/src/asm/ontop_i386_sysv_elf_gas.S b/src/boost/libs/context/src/asm/ontop_i386_sysv_elf_gas.S new file mode 100644 index 000000000..40fe6c2ab --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_i386_sysv_elf_gas.S @@ -0,0 +1,90 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | hidden | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | | * + * ---------------------------------------------------------------------------------- * + * | to | data | | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.file "ontop_i386_sysv_elf_gas.S" +.text +.globl ontop_fcontext +.align 2 +.type ontop_fcontext,@function +ontop_fcontext: + leal -0x18(%esp), %esp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + stmxcsr (%esp) /* save MMX control- and status-word */ + fnstcw 0x4(%esp) /* save x87 control-word */ +#endif + + movl %edi, 0x8(%esp) /* save EDI */ + movl %esi, 0xc(%esp) /* save ESI */ + movl %ebx, 0x10(%esp) /* save EBX */ + movl %ebp, 0x14(%esp) /* save EBP */ + + /* store ESP (pointing to context-data) in ECX */ + movl %esp, %ecx + + /* first arg of ontop_fcontext() == fcontext to jump to */ + movl 0x20(%esp), %eax + + /* pass parent fcontext_t */ + movl %ecx, 0x20(%eax) + + /* second arg of ontop_fcontext() == data to be transferred */ + movl 0x24(%esp), %ecx + + /* pass data */ + movl %ecx, 0x24(%eax) + + /* third arg of ontop_fcontext() == ontop-function */ + movl 0x28(%esp), %ecx + + /* restore ESP (pointing to context-data) from EAX */ + movl %eax, %esp + + /* address of returned transport_t */ + movl 0x1c(%esp), %eax + /* return parent fcontext_t */ + movl %ecx, (%eax) + /* return data */ + movl %edx, 0x4(%eax) + +#if !defined(BOOST_USE_TSX) + ldmxcsr (%esp) /* restore MMX control- and status-word */ + fldcw 0x4(%esp) /* restore x87 control-word */ +#endif + + movl 0x8(%esp), %edi /* restore EDI */ + movl 0xc(%esp), %esi /* restore ESI */ + movl 0x10(%esp), %ebx /* restore EBX */ + movl 0x14(%esp), %ebp /* restore EBP */ + + leal 0x18(%esp), %esp /* prepare stack */ + + /* jump to context */ + jmp *%ecx +.size ontop_fcontext,.-ontop_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/ontop_i386_sysv_macho_gas.S b/src/boost/libs/context/src/asm/ontop_i386_sysv_macho_gas.S new file mode 100644 index 000000000..3a88372b3 --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_i386_sysv_macho_gas.S @@ -0,0 +1,81 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | to | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | | * + * ---------------------------------------------------------------------------------- * + * | data | | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.text +.globl _ontop_fcontext +.align 2 +_ontop_fcontext: + leal -0x18(%esp), %esp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + stmxcsr (%esp) /* save MMX control- and status-word */ + fnstcw 0x4(%esp) /* save x87 control-word */ +#endif + + movl %edi, 0x8(%esp) /* save EDI */ + movl %esi, 0xc(%esp) /* save ESI */ + movl %ebx, 0x10(%esp) /* save EBX */ + movl %ebp, 0x14(%esp) /* save EBP */ + + /* store ESP (pointing to context-data) in ECX */ + movl %esp, %ecx + + /* first arg of ontop_fcontext() == fcontext to jump to */ + movl 0x1c(%esp), %eax + + /* pass parent fcontext_t */ + movl %ecx, 0x1c(%eax) + + /* second arg of ontop_fcontext() == data to be transferred */ + movl 0x20(%esp), %ecx + + /* pass data */ + movl %ecx, 0x20(%eax) + + /* third arg of ontop_fcontext() == ontop-function */ + movl 0x24(%esp), %ecx + + /* restore ESP (pointing to context-data) from EAX */ + movl %eax, %esp + + /* return parent fcontext_t */ + movl %ecx, %eax + /* returned data is stored in EDX */ + +#if !defined(BOOST_USE_TSX) + ldmxcsr (%esp) /* restore MMX control- and status-word */ + fldcw 0x4(%esp) /* restore x87 control-word */ +#endif + + movl 0x8(%esp), %edi /* restore EDI */ + movl 0xc(%esp), %esi /* restore ESI */ + movl 0x10(%esp), %ebx /* restore EBX */ + movl 0x14(%esp), %ebp /* restore EBP */ + + leal 0x18(%esp), %esp /* prepare stack */ + + /* jump to context */ + jmp *%ecx diff --git a/src/boost/libs/context/src/asm/ontop_i386_x86_64_sysv_macho_gas.S b/src/boost/libs/context/src/asm/ontop_i386_x86_64_sysv_macho_gas.S new file mode 100644 index 000000000..393c5fe43 --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_i386_x86_64_sysv_macho_gas.S @@ -0,0 +1,16 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__i386__) + #include "ontop_i386_sysv_macho_gas.S" +#elif defined(__x86_64__) + #include "ontop_x86_64_sysv_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/src/boost/libs/context/src/asm/ontop_mips32_o32_elf_gas.S b/src/boost/libs/context/src/asm/ontop_mips32_o32_elf_gas.S new file mode 100644 index 000000000..c69203c65 --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_mips32_o32_elf_gas.S @@ -0,0 +1,120 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | F20 | F22 | F24 | F26 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | F28 | F30 | S0 | S1 | S2 | S3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | S4 | S5 | S6 | S7 | FP |hiddn| RA | PC | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | ABI ARGS | GP | FCTX| DATA| | * + * ------------------------------------------------- * + * * + * *****************************************************/ + +.file "ontop_mips32_o32_elf_gas.S" +.text +.globl ontop_fcontext +.align 2 +.type ontop_fcontext,@function +.ent ontop_fcontext +ontop_fcontext: + # reserve space on stack + addiu $sp, $sp, -96 + + sw $s0, 48($sp) # save S0 + sw $s1, 52($sp) # save S1 + sw $s2, 56($sp) # save S2 + sw $s3, 60($sp) # save S3 + sw $s4, 64($sp) # save S4 + sw $s5, 68($sp) # save S5 + sw $s6, 72($sp) # save S6 + sw $s7, 76($sp) # save S7 + sw $fp, 80($sp) # save FP + sw $a0, 84($sp) # save hidden, address of returned transfer_t + sw $ra, 88($sp) # save RA + sw $ra, 92($sp) # save RA as PC + +#if defined(__mips_hard_float) + s.d $f20, ($sp) # save F20 + s.d $f22, 8($sp) # save F22 + s.d $f24, 16($sp) # save F24 + s.d $f26, 24($sp) # save F26 + s.d $f28, 32($sp) # save F28 + s.d $f30, 40($sp) # save F30 +#endif + + # store SP (pointing to context-data) in A0 + move $a0, $sp + + # restore SP (pointing to context-data) from A1 + move $sp, $a1 + +#if defined(__mips_hard_float) + l.d $f20, ($sp) # restore F20 + l.d $f22, 8($sp) # restore F22 + l.d $f24, 16($sp) # restore F24 + l.d $f26, 24($sp) # restore F26 + l.d $f28, 32($sp) # restore F28 + l.d $f30, 40($sp) # restore F30 +#endif + + lw $s0, 48($sp) # restore S0 + lw $s1, 52($sp) # restore S1 + lw $s2, 56($sp) # restore S2 + lw $s3, 60($sp) # restore S3 + lw $s4, 64($sp) # restore S4 + lw $s5, 68($sp) # restore S5 + lw $s6, 72($sp) # restore S6 + lw $s7, 76($sp) # restore S7 + lw $fp, 80($sp) # restore FP + lw $v0, 84($sp) # restore hidden, address of returned transfer_t + lw $ra, 88($sp) # restore RA + + # load PC + move $t9, $a3 + + # adjust stack + addiu $sp, $sp, 96 + + # return transfer_t from jump + sw $a0, ($v0) # fctx of transfer_t + sw $a2, 4($v0) # data of transfer_t + # pass transfer_t as first arg in context function + # A0 == hidden, A1 == fctx, A2 == data + move $a1, $a0 + move $a0, $v0 + + # jump to context + jr $t9 +.end ontop_fcontext +.size ontop_fcontext, .-ontop_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/ontop_mips64_n64_elf_gas.S b/src/boost/libs/context/src/asm/ontop_mips64_n64_elf_gas.S new file mode 100644 index 000000000..a8a4f8acd --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_mips64_n64_elf_gas.S @@ -0,0 +1,120 @@ +/* + Copyright Jiaxun Yang 2018. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * + * | F24 | F25 | F26 | F27 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * + * | F28 | F29 | F30 | F31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 72 | 80 | 88 | * + * ------------------------------------------------- * + * | S0 | S1 | S2 | S3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | S4 | S5 | S6 | S7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | FP | GP | RA | PC | * + * ------------------------------------------------- * + * * + * *****************************************************/ + +.file "ontop_mips64_n64_elf_gas.S" +.text +.globl ontop_fcontext +.align 3 +.type ontop_fcontext,@function +.ent ontop_fcontext +ontop_fcontext: + # reserve space on stack + daddiu $sp, $sp, -160 + + sd $s0, 64($sp) # save S0 + sd $s1, 72($sp) # save S1 + sd $s2, 80($sp) # save S2 + sd $s3, 88($sp) # save S3 + sd $s4, 96($sp) # save S4 + sd $s5, 104($sp) # save S5 + sd $s6, 112($sp) # save S6 + sd $s7, 120($sp) # save S7 + sd $fp, 128($sp) # save FP + sd $ra, 144($sp) # save RA + sd $ra, 152($sp) # save RA as PC + + + s.d $f24, 0($sp) # save F24 + s.d $f25, 8($sp) # save F25 + s.d $f26, 16($sp) # save F26 + s.d $f27, 24($sp) # save F27 + s.d $f28, 32($sp) # save F28 + s.d $f29, 40($sp) # save F29 + s.d $f30, 48($sp) # save F30 + s.d $f31, 56($sp) # save F31 + + # store SP (pointing to context-data) in t0 + move $t0, $sp + + # restore SP (pointing to context-data) from a0 + move $sp, $a0 + + l.d $f24, 0($sp) # restore F24 + l.d $f25, 8($sp) # restore F25 + l.d $f26, 16($sp) # restore F26 + l.d $f27, 24($sp) # restore F27 + l.d $f28, 32($sp) # restore F28 + l.d $f29, 40($sp) # restore F29 + l.d $f30, 48($sp) # restore F30 + l.d $f31, 56($sp) # restore F31 + + ld $s0, 64($sp) # restore S0 + ld $s1, 72($sp) # restore S1 + ld $s2, 80($sp) # restore S2 + ld $s3, 88($sp) # restore S3 + ld $s4, 96($sp) # restore S4 + ld $s5, 104($sp) # restore S5 + ld $s6, 112($sp) # restore S6 + ld $s7, 120($sp) # restore S7 + ld $fp, 128($sp) # restore FP + ld $ra, 144($sp) # restore RA + + # load PC + move $t9, $a2 + + # adjust stack + daddiu $sp, $sp, 160 + + move $a0, $t0 # move param from t0 to a0 as param + + # jump to context + jr $t9 +.end ontop_fcontext +.size ontop_fcontext, .-ontop_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/ontop_ppc32_ppc64_sysv_macho_gas.S b/src/boost/libs/context/src/asm/ontop_ppc32_ppc64_sysv_macho_gas.S new file mode 100644 index 000000000..4632f4cc9 --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_ppc32_ppc64_sysv_macho_gas.S @@ -0,0 +1,16 @@ +/* + Copyright Sergue E. Leontiev 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +// Stub file for universal binary + +#if defined(__ppc__) + #include "ontop_ppc32_sysv_macho_gas.S" +#elif defined(__ppc64__) + #include "ontop_ppc64_sysv_macho_gas.S" +#else + #error "No arch's" +#endif diff --git a/src/boost/libs/context/src/asm/ontop_ppc32_sysv_elf_gas.S b/src/boost/libs/context/src/asm/ontop_ppc32_sysv_elf_gas.S new file mode 100644 index 000000000..464d99d59 --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_ppc32_sysv_elf_gas.S @@ -0,0 +1,193 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * |bchai|hiddn| fpscr | PC | CR | R14 | R15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R16 | R17 | R18 | R19 | R20 | R21 | R22 | R23 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R24 | R25 | R26 | R27 | R28 | R29 | R30 | R31 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------|------------ * + * | 224 | 228 | 232 | 236 | 240 | 244 | * + * ------------------------|------------ * + * | F30 | F31 |bchai| LR | * + * ------------------------|------------ * + * * + *******************************************************/ + +.file "ontop_ppc32_sysv_elf_gas.S" +.text +.globl ontop_fcontext +.align 2 +.type ontop_fcontext,@function +ontop_fcontext: + # Linux: ontop_fcontext( hidden transfer_t * R3, R4, R5, R6) + # Other: transfer_t R3:R4 = jump_fcontext( R3, R4, R5) + + mflr %r0 # return address from LR + mffs %f0 # FPSCR + mfcr %r8 # condition register + + stwu %r1, -240(%r1) # allocate stack space, R1 % 16 == 0 + stw %r0, 244(%r1) # save LR in caller's frame + +#ifdef __linux__ + stw %r3, 4(%r1) # hidden pointer +#endif + + stfd %f0, 8(%r1) # FPSCR + stw %r0, 16(%r1) # LR as PC + stw %r8, 20(%r1) # CR + + # Save registers R14 to R31. + # Don't change R2, the thread-local storage pointer. + # Don't change R13, the small data pointer. + stw %r14, 24(%r1) + stw %r15, 28(%r1) + stw %r16, 32(%r1) + stw %r17, 36(%r1) + stw %r18, 40(%r1) + stw %r19, 44(%r1) + stw %r20, 48(%r1) + stw %r21, 52(%r1) + stw %r22, 56(%r1) + stw %r23, 60(%r1) + stw %r24, 64(%r1) + stw %r25, 68(%r1) + stw %r26, 72(%r1) + stw %r27, 76(%r1) + stw %r28, 80(%r1) + stw %r29, 84(%r1) + stw %r30, 88(%r1) + stw %r31, 92(%r1) + + # Save registers F14 to F31 in slots with 8-byte alignment. + # 4-byte alignment may stall the pipeline of some processors. + # Less than 4 may cause alignment traps. + stfd %f14, 96(%r1) + stfd %f15, 104(%r1) + stfd %f16, 112(%r1) + stfd %f17, 120(%r1) + stfd %f18, 128(%r1) + stfd %f19, 136(%r1) + stfd %f20, 144(%r1) + stfd %f21, 152(%r1) + stfd %f22, 160(%r1) + stfd %f23, 168(%r1) + stfd %f24, 176(%r1) + stfd %f25, 184(%r1) + stfd %f26, 192(%r1) + stfd %f27, 200(%r1) + stfd %f28, 208(%r1) + stfd %f29, 216(%r1) + stfd %f30, 224(%r1) + stfd %f31, 232(%r1) + + # store RSP (pointing to context-data) in R7/R6 + # restore RSP (pointing to context-data) from R4/R3 +#ifdef __linux__ + mr %r7, %r1 + mr %r1, %r4 + lwz %r3, 4(%r1) # hidden pointer +#else + mr %r6, %r1 + mr %r1, %r3 +#endif + + # ignore PC at 16(%r1) + lfd %f0, 8(%r1) # FPSCR + lwz %r8, 20(%r1) # CR + + mtfsf 0xff, %f0 # restore FPSCR + mtcr %r8 # restore CR + + # restore R14 to R31 + lwz %r14, 24(%r1) + lwz %r15, 28(%r1) + lwz %r16, 32(%r1) + lwz %r17, 36(%r1) + lwz %r18, 40(%r1) + lwz %r19, 44(%r1) + lwz %r20, 48(%r1) + lwz %r21, 52(%r1) + lwz %r22, 56(%r1) + lwz %r23, 60(%r1) + lwz %r24, 64(%r1) + lwz %r25, 68(%r1) + lwz %r26, 72(%r1) + lwz %r27, 76(%r1) + lwz %r28, 80(%r1) + lwz %r29, 84(%r1) + lwz %r30, 88(%r1) + lwz %r31, 92(%r1) + + # restore F14 to F31 + lfd %f14, 96(%r1) + lfd %f15, 104(%r1) + lfd %f16, 112(%r1) + lfd %f17, 120(%r1) + lfd %f18, 128(%r1) + lfd %f19, 136(%r1) + lfd %f20, 144(%r1) + lfd %f21, 152(%r1) + lfd %f22, 160(%r1) + lfd %f23, 168(%r1) + lfd %f24, 176(%r1) + lfd %f25, 184(%r1) + lfd %f26, 192(%r1) + lfd %f27, 200(%r1) + lfd %f28, 208(%r1) + lfd %f29, 216(%r1) + lfd %f30, 224(%r1) + lfd %f31, 232(%r1) + + # restore LR from caller's frame + lwz %r0, 244(%r1) + mtlr %r0 + + # adjust stack + addi %r1, %r1, 240 + + # see tail_ppc32_sysv_elf_gas.cpp + # Linux: fcontext_ontop_tail( hidden transfer_t * R3, R4, R5, R6, R7) + # Other: transfer_t R3:R4 = fcontext_ontop_tail( R3, R4, R5, R6) + b ontop_fcontext_tail +.size ontop_fcontext, .-ontop_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/ontop_ppc32_sysv_macho_gas.S b/src/boost/libs/context/src/asm/ontop_ppc32_sysv_macho_gas.S new file mode 100644 index 000000000..1eb5f9340 --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_ppc32_sysv_macho_gas.S @@ -0,0 +1,201 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/****************************************************** + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F30 | F31 | fpscr | R13 | R14 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | R31 |hiddn| CR | LR | PC |bchai|linkr| FCTX| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | | * + * ------------------------------------------------- * + * | 256 | | * + * ------------------------------------------------- * + * | DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.globl _ontop_fcontext +.align 2 +_ontop_fcontext: + # reserve space on stack + subi r1, r1, 244 + + stfd f14, 0(r1) # save F14 + stfd f15, 8(r1) # save F15 + stfd f16, 16(r1) # save F16 + stfd f17, 24(r1) # save F17 + stfd f18, 32(r1) # save F18 + stfd f19, 40(r1) # save F19 + stfd f20, 48(r1) # save F20 + stfd f21, 56(r1) # save F21 + stfd f22, 64(r1) # save F22 + stfd f23, 72(r1) # save F23 + stfd f24, 80(r1) # save F24 + stfd f25, 88(r1) # save F25 + stfd f26, 96(r1) # save F26 + stfd f27, 104(r1) # save F27 + stfd f28, 112(r1) # save F28 + stfd f29, 120(r1) # save F29 + stfd f30, 128(r1) # save F30 + stfd f31, 136(r1) # save F31 + mffs f0 # load FPSCR + stfd f0, 144(r1) # save FPSCR + + stw r13, 152(r1) # save R13 + stw r14, 156(r1) # save R14 + stw r15, 160(r1) # save R15 + stw r16, 164(r1) # save R16 + stw r17, 168(r1) # save R17 + stw r18, 172(r1) # save R18 + stw r19, 176(r1) # save R19 + stw r20, 180(r1) # save R20 + stw r21, 184(r1) # save R21 + stw r22, 188(r1) # save R22 + stw r23, 192(r1) # save R23 + stw r24, 196(r1) # save R24 + stw r25, 200(r1) # save R25 + stw r26, 204(r1) # save R26 + stw r27, 208(r1) # save R27 + stw r28, 212(r1) # save R28 + stw r29, 216(r1) # save R29 + stw r30, 220(r1) # save R30 + stw r31, 224(r1) # save R31 + stw r3, 228(r1) # save hidden + + # save CR + mfcr r0 + stw r0, 232(r1) + # save LR + mflr r0 + stw r0, 236(r1) + # save LR as PC + stw r0, 240(r1) + + # store RSP (pointing to context-data) in R7 + mr r7, r1 + + # restore RSP (pointing to context-data) from R4 + mr r1, r4 + + lfd f14, 0(r1) # restore F14 + lfd f15, 8(r1) # restore F15 + lfd f16, 16(r1) # restore F16 + lfd f17, 24(r1) # restore F17 + lfd f18, 32(r1) # restore F18 + lfd f19, 40(r1) # restore F19 + lfd f20, 48(r1) # restore F20 + lfd f21, 56(r1) # restore F21 + lfd f22, 64(r1) # restore F22 + lfd f23, 72(r1) # restore F23 + lfd f24, 80(r1) # restore F24 + lfd f25, 88(r1) # restore F25 + lfd f26, 96(r1) # restore F26 + lfd f27, 104(r1) # restore F27 + lfd f28, 112(r1) # restore F28 + lfd f29, 120(r1) # restore F29 + lfd f30, 128(r1) # restore F30 + lfd f31, 136(r1) # restore F31 + lfd f0, 144(r1) # load FPSCR + mtfsf 0xff, f0 # restore FPSCR + + lwz r13, 152(r1) # restore R13 + lwz r14, 156(r1) # restore R14 + lwz r15, 160(r1) # restore R15 + lwz r16, 164(r1) # restore R16 + lwz r17, 168(r1) # restore R17 + lwz r18, 172(r1) # restore R18 + lwz r19, 176(r1) # restore R19 + lwz r20, 180(r1) # restore R20 + lwz r21, 184(r1) # restore R21 + lwz r22, 188(r1) # restore R22 + lwz r23, 192(r1) # restore R23 + lwz r24, 196(r1) # restore R24 + lwz r25, 200(r1) # restore R25 + lwz r26, 204(r1) # restore R26 + lwz r27, 208(r1) # restore R27 + lwz r28, 212(r1) # restore R28 + lwz r29, 216(r1) # restore R29 + lwz r30, 220(r1) # restore R30 + lwz r31, 224(r1) # restore R31 + lwz r4, 228(r1) # restore hidden + + # restore CR + lwz r0, 232(r1) + mtcr r0 + # restore LR + lwz r0, 236(r1) + mtlr r0 + # ignore PC + + # adjust stack + addi r1, r1, 244 + + # return transfer_t + stw r7, 0(r4) + stw r5, 4(r4) + + # restore CTR + mtctr r6 + + # jump to ontop-function + bctr diff --git a/src/boost/libs/context/src/asm/ontop_ppc32_sysv_xcoff_gas.S b/src/boost/libs/context/src/asm/ontop_ppc32_sysv_xcoff_gas.S new file mode 100644 index 000000000..a3c9fa233 --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_ppc32_sysv_xcoff_gas.S @@ -0,0 +1,203 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/****************************************************** + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | F14 | F15 | F16 | F17 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | F18 | F19 | F20 | F21 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | F22 | F23 | F24 | F25 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | F26 | F27 | F28 | F29 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | F30 | F31 | fpscr | R13 | R14 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | R31 |hiddn| CR | LR | PC |bchai|linkr| FCTX| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 64 | | * + * ------------------------------------------------- * + * | 256 | | * + * ------------------------------------------------- * + * | DATA| | * + * ------------------------------------------------- * + * * + *******************************************************/ +.globl .ontop_fcontext +.globl ontop_fcontext[DS] +.align 2 +.csect ontop_fcontext[DS] +ontop_fcontext: + .long .ontop_fcontext +.ontop_fcontext: + # reserve space on stack + subi r1, r1, 244 + + stfd f14, 0(r1) # save F14 + stfd f15, 8(r1) # save F15 + stfd f16, 16(r1) # save F16 + stfd f17, 24(r1) # save F17 + stfd f18, 32(r1) # save F18 + stfd f19, 40(r1) # save F19 + stfd f20, 48(r1) # save F20 + stfd f21, 56(r1) # save F21 + stfd f22, 64(r1) # save F22 + stfd f23, 72(r1) # save F23 + stfd f24, 80(r1) # save F24 + stfd f25, 88(r1) # save F25 + stfd f26, 96(r1) # save F26 + stfd f27, 104(r1) # save F27 + stfd f28, 112(r1) # save F28 + stfd f29, 120(r1) # save F29 + stfd f30, 128(r1) # save F30 + stfd f31, 136(r1) # save F31 + mffs f0 # load FPSCR + stfd f0, 144(r1) # save FPSCR + + stw r13, 152(r1) # save R13 + stw r14, 156(r1) # save R14 + stw r15, 160(r1) # save R15 + stw r16, 164(r1) # save R16 + stw r17, 168(r1) # save R17 + stw r18, 172(r1) # save R18 + stw r19, 176(r1) # save R19 + stw r20, 180(r1) # save R20 + stw r21, 184(r1) # save R21 + stw r22, 188(r1) # save R22 + stw r23, 192(r1) # save R23 + stw r24, 196(r1) # save R24 + stw r25, 200(r1) # save R25 + stw r26, 204(r1) # save R26 + stw r27, 208(r1) # save R27 + stw r28, 212(r1) # save R28 + stw r29, 216(r1) # save R29 + stw r30, 220(r1) # save R30 + stw r31, 224(r1) # save R31 + stw r3, 228(r1) # save hidden + + # save CR + mfcr r0 + stw r0, 232(r1) + # save LR + mflr r0 + stw r0, 236(r1) + # save LR as PC + stw r0, 240(r1) + + # store RSP (pointing to context-data) in R7 + mr r7, r1 + + # restore RSP (pointing to context-data) from R4 + mr r1, r4 + + lfd f14, 0(r1) # restore F14 + lfd f15, 8(r1) # restore F15 + lfd f16, 16(r1) # restore F16 + lfd f17, 24(r1) # restore F17 + lfd f18, 32(r1) # restore F18 + lfd f19, 40(r1) # restore F19 + lfd f20, 48(r1) # restore F20 + lfd f21, 56(r1) # restore F21 + lfd f22, 64(r1) # restore F22 + lfd f23, 72(r1) # restore F23 + lfd f24, 80(r1) # restore F24 + lfd f25, 88(r1) # restore F25 + lfd f26, 96(r1) # restore F26 + lfd f27, 104(r1) # restore F27 + lfd f28, 112(r1) # restore F28 + lfd f29, 120(r1) # restore F29 + lfd f30, 128(r1) # restore F30 + lfd f31, 136(r1) # restore F31 + lfd f0, 144(r1) # load FPSCR + mtfsf 0xff, f0 # restore FPSCR + + lwz r13, 152(r1) # restore R13 + lwz r14, 156(r1) # restore R14 + lwz r15, 160(r1) # restore R15 + lwz r16, 164(r1) # restore R16 + lwz r17, 168(r1) # restore R17 + lwz r18, 172(r1) # restore R18 + lwz r19, 176(r1) # restore R19 + lwz r20, 180(r1) # restore R20 + lwz r21, 184(r1) # restore R21 + lwz r22, 188(r1) # restore R22 + lwz r23, 192(r1) # restore R23 + lwz r24, 196(r1) # restore R24 + lwz r25, 200(r1) # restore R25 + lwz r26, 204(r1) # restore R26 + lwz r27, 208(r1) # restore R27 + lwz r28, 212(r1) # restore R28 + lwz r29, 216(r1) # restore R29 + lwz r30, 220(r1) # restore R30 + lwz r31, 224(r1) # restore R31 + lwz r4, 228(r1) # restore hidden + + # restore CR + lwz r0, 232(r1) + mtcr r0 + # restore LR + lwz r0, 236(r1) + mtlr r0 + # ignore PC + + # adjust stack + addi r1, r1, 244 + + # return transfer_t + stw r7, 0(r4) + stw r5, 4(r4) + + # restore CTR + mtctr r6 + + # jump to ontop-function + bctr diff --git a/src/boost/libs/context/src/asm/ontop_ppc64_sysv_elf_gas.S b/src/boost/libs/context/src/asm/ontop_ppc64_sysv_elf_gas.S new file mode 100644 index 000000000..cd97f4567 --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_ppc64_sysv_elf_gas.S @@ -0,0 +1,244 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | TOC | R14 | R15 | R16 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R17 | R18 | R19 | R20 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R21 | R22 | R23 | R24 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | R25 | R26 | R27 | R28 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | R29 | R30 | R31 | hidden | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | CR | LR | PC | back-chain| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | cr saved | lr saved | compiler | linker | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | TOC saved | FCTX | DATA | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "ontop_ppc64_sysv_elf_gas.S" +.globl ontop_fcontext +#if _CALL_ELF == 2 + .text + .align 2 +ontop_fcontext: + addis %r2, %r12, .TOC.-ontop_fcontext@ha + addi %r2, %r2, .TOC.-ontop_fcontext@l + .localentry ontop_fcontext, . - ontop_fcontext +#else + .section ".opd","aw" + .align 3 +ontop_fcontext: +# ifdef _CALL_LINUX + .quad .L.ontop_fcontext,.TOC.@tocbase,0 + .type ontop_fcontext,@function + .text + .align 2 +.L.ontop_fcontext: +# else + .hidden .ontop_fcontext + .globl .ontop_fcontext + .quad .ontop_fcontext,.TOC.@tocbase,0 + .size ontop_fcontext,24 + .type .ontop_fcontext,@function + .text + .align 2 +.ontop_fcontext: +# endif +#endif + # reserve space on stack + subi %r1, %r1, 184 + +#if _CALL_ELF != 2 + std %r2, 0(%r1) # save TOC +#endif + std %r14, 8(%r1) # save R14 + std %r15, 16(%r1) # save R15 + std %r16, 24(%r1) # save R16 + std %r17, 32(%r1) # save R17 + std %r18, 40(%r1) # save R18 + std %r19, 48(%r1) # save R19 + std %r20, 56(%r1) # save R20 + std %r21, 64(%r1) # save R21 + std %r22, 72(%r1) # save R22 + std %r23, 80(%r1) # save R23 + std %r24, 88(%r1) # save R24 + std %r25, 96(%r1) # save R25 + std %r26, 104(%r1) # save R26 + std %r27, 112(%r1) # save R27 + std %r28, 120(%r1) # save R28 + std %r29, 128(%r1) # save R29 + std %r30, 136(%r1) # save R30 + std %r31, 144(%r1) # save R31 +#if _CALL_ELF != 2 + std %r3, 152(%r1) # save hidden +#endif + + # save CR + mfcr %r0 + std %r0, 160(%r1) + # save LR + mflr %r0 + std %r0, 168(%r1) + # save LR as PC + std %r0, 176(%r1) + + # store RSP (pointing to context-data) in R7 + mr %r7, %r1 + +#if _CALL_ELF == 2 + # restore RSP (pointing to context-data) from R3 + mr %r1, %r3 +#else + # restore RSP (pointing to context-data) from R4 + mr %r1, %r4 +#endif + + ld %r14, 8(%r1) # restore R14 + ld %r15, 16(%r1) # restore R15 + ld %r16, 24(%r1) # restore R16 + ld %r17, 32(%r1) # restore R17 + ld %r18, 40(%r1) # restore R18 + ld %r19, 48(%r1) # restore R19 + ld %r20, 56(%r1) # restore R20 + ld %r21, 64(%r1) # restore R21 + ld %r22, 72(%r1) # restore R22 + ld %r23, 80(%r1) # restore R23 + ld %r24, 88(%r1) # restore R24 + ld %r25, 96(%r1) # restore R25 + ld %r26, 104(%r1) # restore R26 + ld %r27, 112(%r1) # restore R27 + ld %r28, 120(%r1) # restore R28 + ld %r29, 128(%r1) # restore R29 + ld %r30, 136(%r1) # restore R30 + ld %r31, 144(%r1) # restore R31 +#if _CALL_ELF != 2 + ld %r3, 152(%r1) # restore hidden +#endif + + # restore CR + ld %r0, 160(%r1) + mtcr %r0 + +#if _CALL_ELF == 2 + # restore CTR + mtctr %r5 + + # store cb entrypoint in %r12, used for TOC calculation + mr %r12, %r5 + + # copy transfer_t into ontop_fn arg registers + mr %r3, %r7 + # arg pointer already in %r4 +#else + # copy transfer_t into ontop_fn arg registers + mr %r4, %r7 + # arg pointer already in %r5 + # hidden arg already in %r3 + + # restore CTR + ld %r7, 0(%r6) + mtctr %r7 + # restore TOC + ld %r2, 8(%r6) + + # zero in r3 indicates first jump to context-function + cmpdi %r3, 0 + beq use_entry_arg +#endif + +return_to_ctx: + # restore LR + ld %r0, 168(%r1) + mtlr %r0 + + # adjust stack + addi %r1, %r1, 184 + + # jump to context + bctr + +#if _CALL_ELF == 2 + .size ontop_fcontext, .-ontop_fcontext +#else +use_entry_arg: + # compute return-value struct address + # (passed has hidden arg to ontop_fn) + addi %r3, %r1, 8 + + # jump to context and update LR + bctrl + + # restore CTR + ld %r7, 176(%r1) + mtctr %r7 +#if _CALL_ELF != 2 + # restore TOC + ld %r2, 0(%r1) +#endif + + # copy returned transfer_t into entry_fn arg registers + ld %r3, 8(%r1) + ld %r4, 16(%r1) + + b return_to_ctx +# ifdef _CALL_LINUX + .size .ontop_fcontext, .-.L.ontop_fcontext +# else + .size .ontop_fcontext, .-.ontop_fcontext +# endif +#endif + + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/ontop_ppc64_sysv_macho_gas.S b/src/boost/libs/context/src/asm/ontop_ppc64_sysv_macho_gas.S new file mode 100644 index 000000000..5de8acd10 --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_ppc64_sysv_macho_gas.S @@ -0,0 +1,151 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * + * ------------------------------------------------- * + * | TOC | R14 | R15 | R16 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * + * ------------------------------------------------- * + * | R17 | R18 | R19 | R20 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * + * ------------------------------------------------- * + * | R21 | R22 | R23 | R24 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * + * ------------------------------------------------- * + * | R25 | R26 | R27 | R28 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * + * | R29 | R30 | R31 | hidden | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * + * ------------------------------------------------- * + * | CR | LR | PC | back-chain| * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * + * ------------------------------------------------- * + * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * + * ------------------------------------------------- * + * | cr saved | lr saved | compiler | linker | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * + * ------------------------------------------------- * + * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * + * ------------------------------------------------- * + * | TOC saved | FCTX | DATA | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.text +.align 2 +.globl _ontop_fcontext + +_ontop_fcontext: + ; reserve space on stack + subi r1, r1, 184 + + std r14, 8(r1) ; save R14 + std r15, 16(r1) ; save R15 + std r16, 24(r1) ; save R16 + std r17, 32(r1) ; save R17 + std r18, 40(r1) ; save R18 + std r19, 48(r1) ; save R19 + std r20, 56(r1) ; save R20 + std r21, 64(r1) ; save R21 + std r22, 72(r1) ; save R22 + std r23, 80(r1) ; save R23 + std r24, 88(r1) ; save R24 + std r25, 96(r1) ; save R25 + std r26, 104(r1) ; save R26 + std r27, 112(r1) ; save R27 + std r28, 120(r1) ; save R28 + std r29, 128(r1) ; save R29 + std r30, 136(r1) ; save R30 + std r31, 144(r1) ; save R31 + std r3, 152(r1) ; save hidden + + ; save CR + mfcr r0 + std r0, 160(r1) + ; save LR + mflr r0 + std r0, 168(r1) + ; save LR as PC + std r0, 176(r1) + + ; store RSP (pointing to context-data) in R7 + mr r7, r1 + + ; restore RSP (pointing to context-data) from R4 + mr r1, r4 + + ld r14, 8(r1) ; restore R14 + ld r15, 16(r1) ; restore R15 + ld r16, 24(r1) ; restore R16 + ld r17, 32(r1) ; restore R17 + ld r18, 40(r1) ; restore R18 + ld r19, 48(r1) ; restore R19 + ld r20, 56(r1) ; restore R20 + ld r21, 64(r1) ; restore R21 + ld r22, 72(r1) ; restore R22 + ld r23, 80(r1) ; restore R23 + ld r24, 88(r1) ; restore R24 + ld r25, 96(r1) ; restore R25 + ld r26, 104(r1) ; restore R26 + ld r27, 112(r1) ; restore R27 + ld r28, 120(r1) ; restore R28 + ld r29, 128(r1) ; restore R29 + ld r30, 136(r1) ; restore R30 + ld r31, 144(r1) ; restore R31 + ld r4, 152(r1) ; restore hidden + + ; restore CR + ld r0, 160(r1) + mtcr r0 + ; restore LR + ld r0, 168(r1) + mtlr r0 + ; ignore PC + + ; adjust stack + addi r1, r1, 184 + + ; return transfer_t + std r7, 0(r4) + std r5, 8(r4) + + ; restore CTR + mtctr r6 + + ; jump to context + bctr diff --git a/src/boost/libs/context/src/asm/ontop_ppc64_sysv_xcoff_gas.S b/src/boost/libs/context/src/asm/ontop_ppc64_sysv_xcoff_gas.S new file mode 100644 index 000000000..93f8c2342 --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_ppc64_sysv_xcoff_gas.S @@ -0,0 +1,83 @@ +.align 2 +.globl .ontop_fcontext +.ontop_fcontext: + # reserve space on stack + subi 1, 1, 184 + + std 13, 0(1) # save R13 + std 14, 8(1) # save R14 + std 15, 16(1) # save R15 + std 16, 24(1) # save R16 + std 17, 32(1) # save R17 + std 18, 40(1) # save R18 + std 19, 48(1) # save R19 + std 20, 56(1) # save R20 + std 21, 64(1) # save R21 + std 22, 72(1) # save R22 + std 23, 80(1) # save R23 + std 24, 88(1) # save R24 + std 25, 96(1) # save R25 + std 26, 104(1) # save R26 + std 27, 112(1) # save R27 + std 29, 120(1) # save R28 + std 29, 128(1) # save R29 + std 30, 136(1) # save R30 + std 31, 144(1) # save R31 + std 3, 152(1) # save hidden + + # save CR + mfcr 0 + std 0, 160(1) + # save LR + mflr 0 + std 0, 168(1) + # save LR as PC + std 0, 176(1) + + # store RSP (pointing to context-data) in R7 + mr 7, 1 + + # restore RSP (pointing to context-data) from R4 + mr 1, 4 + + ld 13, 0(1) # restore R13 + ld 14, 8(1) # restore R14 + ld 15, 16(1) # restore R15 + ld 16, 24(1) # restore R16 + ld 17, 32(1) # restore R17 + ld 18, 40(1) # restore R18 + ld 19, 48(1) # restore R19 + ld 20, 56(1) # restore R20 + ld 21, 64(1) # restore R21 + ld 22, 72(1) # restore R22 + ld 23, 80(1) # restore R23 + ld 24, 88(1) # restore R24 + ld 25, 96(1) # restore R25 + ld 26, 104(1) # restore R26 + ld 27, 112(1) # restore R27 + ld 28, 120(1) # restore R28 + ld 29, 128(1) # restore R29 + ld 30, 136(1) # restore R30 + ld 31, 144(1) # restore R31 + ld 4, 152(1) # restore hidden + + # restore CR + ld 0, 160(1) + mtcr 0 + # restore LR + ld 0, 168(1) + mtlr 0 + # ignore PC + + # adjust stack + addi 1, 1, 184 + + # return transfer_t + std 7, 0(4) + std 5, 8(4) + + # restore CTR + mtctr 6 + + # jump to context + bctr diff --git a/src/boost/libs/context/src/asm/ontop_riscv64_sysv_elf_gas.S b/src/boost/libs/context/src/asm/ontop_riscv64_sysv_elf_gas.S new file mode 100644 index 000000000..61ab46bcc --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_riscv64_sysv_elf_gas.S @@ -0,0 +1,149 @@ +/* + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +/******************************************************* + * * + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * + * ------------------------------------------------- * + * | fs0 | fs1 | fs2 | fs3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * + * ------------------------------------------------- * + * | fs4 | fs5 | fs6 | fs7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * + * ------------------------------------------------- * + * | fs8 | fs9 | fs10 | fs11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * + * ------------------------------------------------- * + * | s0 | s1 | s2 | s3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * + * ------------------------------------------------- * + * | s4 | s5 | s6 | s7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * + * ------------------------------------------------- * + * | s8 | s9 | s10 | s11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 48 | 49 | 50 | 51 | | | | | * + * ------------------------------------------------- * + * | 0xc0| 0xc4| 0xc8| 0xcc| | | | | * + * ------------------------------------------------- * + * | ra | pc | | | * + * ------------------------------------------------- * + * * + *******************************************************/ + +.file "ontop_riscv64_sysv_elf_gas.S" +.text +.align 1 +.global ontop_fcontext +.type ontop_fcontext, %function +ontop_fcontext: + # prepare stack for GP + FPU + addi sp, sp, -0xd0 + + # save fs0 - fs11 + fsd fs0, 0x00(sp) + fsd fs1, 0x08(sp) + fsd fs2, 0x10(sp) + fsd fs3, 0x18(sp) + fsd fs4, 0x20(sp) + fsd fs5, 0x28(sp) + fsd fs6, 0x30(sp) + fsd fs7, 0x38(sp) + fsd fs8, 0x40(sp) + fsd fs9, 0x48(sp) + fsd fs10, 0x50(sp) + fsd fs11, 0x58(sp) + + # save s0-s11, ra + sd s0, 0x60(sp) + sd s1, 0x68(sp) + sd s2, 0x70(sp) + sd s3, 0x78(sp) + sd s4, 0x80(sp) + sd s5, 0x88(sp) + sd s6, 0x90(sp) + sd s7, 0x98(sp) + sd s8, 0xa0(sp) + sd s9, 0xa8(sp) + sd s10, 0xb0(sp) + sd s11, 0xb8(sp) + sd ra, 0xc0(sp) + + # save RA as PC + sd ra, 0xc8(sp) + + # store SP (pointing to context-data) in A3 + mv a3, sp + + # restore SP (pointing to context-data) from A0 + mv sp, a0 + + # load fs0 - fs11 + fld fs0, 0x00(sp) + fld fs1, 0x08(sp) + fld fs2, 0x10(sp) + fld fs3, 0x18(sp) + fld fs4, 0x20(sp) + fld fs5, 0x28(sp) + fld fs6, 0x30(sp) + fld fs7, 0x38(sp) + fld fs8, 0x40(sp) + fld fs9, 0x48(sp) + fld fs10, 0x50(sp) + fld fs11, 0x58(sp) + + # load s0-s11,ra + ld s0, 0x60(sp) + ld s1, 0x68(sp) + ld s2, 0x70(sp) + ld s3, 0x78(sp) + ld s4, 0x80(sp) + ld s5, 0x88(sp) + ld s6, 0x90(sp) + ld s7, 0x98(sp) + ld s8, 0xa0(sp) + ld s9, 0xa8(sp) + ld s10, 0xb0(sp) + ld s11, 0xb8(sp) + ld ra, 0xc0(sp) + + # return transfer_t from jump + # pass transfer_t as first arg in context function + # a0 == FCTX, a1 == DATA + mv a0, a3 + + # skip pc + # restore stack from GP + FPU + addi sp, sp, 0xd0 + + # jump to ontop-function + jr a2 +.size ontop_fcontext,.-ontop_fcontext +# Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/ontop_s390x_sysv_elf_gas.S b/src/boost/libs/context/src/asm/ontop_s390x_sysv_elf_gas.S new file mode 100644 index 000000000..709b3d602 --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_s390x_sysv_elf_gas.S @@ -0,0 +1,146 @@ +/******************************************************* + * ------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * + * | t.fctx | t.data | r2 | r6 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * + * | r7 | r8 | r9 | r10 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * + * ------------------------------------------------- * + * | 64 | 72 | 80 | 88 | * + * ------------------------------------------------- * + * | r11 | r12 | r13 | r14 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * + * ------------------------------------------------- * + * | 96 | 104 | 112 | 120 | * + * ------------------------------------------------- * + * | f8 | f9 | f10 | f11 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * + * ------------------------------------------------- * + * | 128 | 136 | 144 | 152 | * + * ------------------------------------------------- * + * | f12 | f13 | f14 | f15 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * + * ------------------------------------------------- * + * | 160 | 168 | 176 | | * + * ------------------------------------------------- * + * | fpc | pc | | | * + * ------------------------------------------------- * + *******************************************************/ + +.text +.align 8 +.global ontop_fcontext +.type ontop_fcontext, @function + +#define ARG_OFFSET 0 +#define GR_OFFSET 16 +#define R14_OFFSET 88 +#define FP_OFFSET 96 +#define FPC_OFFSET 160 +#define PC_OFFSET 168 +#define CONTEXT_SIZE 176 + + +/* + +typedef void* fcontext_t; + +struct transfer_t { + fcontext_t fctx; + void * data; +}; + +transfer_t ontop_fcontext( fcontext_t const to, + void * vp, + transfer_t (* fn)( transfer_t) ); + +Incoming args +r2 - Hidden argument to the location where the return transfer_t needs to be returned +r3 - Target context +r4 - Data pointer +r5 - Function to be executed + +This implementation assumes that ontop_fcontext will never be called with target contexts +created via make_fcontext. + +*/ + +ontop_fcontext: + /* Reserve stack space to store the current context. */ + aghi %r15,-CONTEXT_SIZE + + /* Save the argument register holding the location of the return value. */ + stg %r2,GR_OFFSET(%r15) + + /* Save the call-saved general purpose registers. */ + stmg %r6,%r14,GR_OFFSET+8(%r15) + + /* Save call-saved floating point registers. */ + std %f8,FP_OFFSET(%r15) + std %f9,FP_OFFSET+8(%r15) + std %f10,FP_OFFSET+16(%r15) + std %f11,FP_OFFSET+24(%r15) + std %f12,FP_OFFSET+32(%r15) + std %f13,FP_OFFSET+40(%r15) + std %f14,FP_OFFSET+48(%r15) + std %f15,FP_OFFSET+56(%r15) + + /* Save the return address as current pc. */ + stg %r14,PC_OFFSET(%r15) + + /* Save the floating point control register. */ + stfpc FPC_OFFSET(%r15) + + /* Backup the stack pointer pointing to the old context-data into r1. */ + lgr %r1,%r15 + + /* Load the new context pointer as stack pointer. */ + lgr %r15,%r3 + + /* Restore the call-saved GPRs from the new context. */ + lmg %r6,%r14,GR_OFFSET+8(%r15) + + /* Restore call-saved floating point registers. */ + ld %f8,FP_OFFSET(%r15) + ld %f9,FP_OFFSET+8(%r15) + ld %f10,FP_OFFSET+16(%r15) + ld %f11,FP_OFFSET+24(%r15) + ld %f12,FP_OFFSET+32(%r15) + ld %f13,FP_OFFSET+40(%r15) + ld %f14,FP_OFFSET+48(%r15) + ld %f15,FP_OFFSET+56(%r15) + + /* Load the floating point control register. */ + lfpc FPC_OFFSET(%r15) + + /* Store the transfer_t values located in the saved context. */ + stg %r1,0(%r1) /* transfer_t.fctx = old context */ + stg %r4,8(%r1) /* transfer_t.data = data */ + + /* Set up the arguments for the target function. */ + lg %r2,GR_OFFSET(%r15) + lgr %r3,%r1 + + /* Deallocate the context. */ + aghi %r15,CONTEXT_SIZE + + br %r5 + +.size ontop_fcontext,.-ontop_fcontext +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/ontop_x86_64_ms_pe_gas.asm b/src/boost/libs/context/src/asm/ontop_x86_64_ms_pe_gas.asm new file mode 100644 index 000000000..02e040c9d --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_x86_64_ms_pe_gas.asm @@ -0,0 +1,211 @@ +/* + Copyright Oliver Kowalke 2009. + Copyright Thomas Sailer 2013. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/************************************************************************************* +* ---------------------------------------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* ---------------------------------------------------------------------------------- * +* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* ---------------------------------------------------------------------------------- * +* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +* ---------------------------------------------------------------------------------- * +* | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +* ---------------------------------------------------------------------------------- * +* | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | * +* ---------------------------------------------------------------------------------- * +* | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | * +* ---------------------------------------------------------------------------------- * +* | SEE registers (XMM6-XMM15) | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | * +* ---------------------------------------------------------------------------------- * +* | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | * +* ---------------------------------------------------------------------------------- * +* | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | * +* ---------------------------------------------------------------------------------- * +* | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | * +* ---------------------------------------------------------------------------------- * +* | limit | base | R12 | R13 | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | * +* ---------------------------------------------------------------------------------- * +* | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | * +* ---------------------------------------------------------------------------------- * +* | R14 | R15 | RDI | RSI | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | * +* ---------------------------------------------------------------------------------- * +* | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | * +* ---------------------------------------------------------------------------------- * +* | RBX | RBP | hidden | RIP | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | * +* ---------------------------------------------------------------------------------- * +* | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | * +* ---------------------------------------------------------------------------------- * +* | parameter area | * +* ---------------------------------------------------------------------------------- * +* ---------------------------------------------------------------------------------- * +* | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | * +* ---------------------------------------------------------------------------------- * +* | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | * +* ---------------------------------------------------------------------------------- * +* | FCTX | DATA | | * +* ---------------------------------------------------------------------------------- * +**************************************************************************************/ + +.file "ontop_x86_64_ms_pe_gas.asm" +.text +.p2align 4,,15 +.globl ontop_fcontext +.def ontop_fcontext; .scl 2; .type 32; .endef +.seh_proc ontop_fcontext +ontop_fcontext: +.seh_endprologue + + leaq -0x118(%rsp), %rsp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + /* save XMM storage */ + movaps %xmm6, 0x0(%rsp) + movaps %xmm7, 0x10(%rsp) + movaps %xmm8, 0x20(%rsp) + movaps %xmm9, 0x30(%rsp) + movaps %xmm10, 0x40(%rsp) + movaps %xmm11, 0x50(%rsp) + movaps %xmm12, 0x60(%rsp) + movaps %xmm13, 0x70(%rsp) + movaps %xmm14, 0x80(%rsp) + movaps %xmm15, 0x90(%rsp) + stmxcsr 0xa0(%rsp) /* save MMX control- and status-word */ + fnstcw 0xa4(%rsp) /* save x87 control-word */ +#endif + + /* load NT_TIB */ + movq %gs:(0x30), %r10 + /* save fiber local storage */ + movq 0x20(%r10), %rax + movq %rax, 0xb0(%rsp) + /* save current deallocation stack */ + movq 0x1478(%r10), %rax + movq %rax, 0xb8(%rsp) + /* save current stack limit */ + movq 0x10(%r10), %rax + movq %rax, 0xc0(%rsp) + /* save current stack base */ + movq 0x08(%r10), %rax + movq %rax, 0xc8(%rsp) + + movq %r12, 0xd0(%rsp) /* save R12 */ + movq %r13, 0xd8(%rsp) /* save R13 */ + movq %r14, 0xe0(%rsp) /* save R14 */ + movq %r15, 0xe8(%rsp) /* save R15 */ + movq %rdi, 0xf0(%rsp) /* save RDI */ + movq %rsi, 0xf8(%rsp) /* save RSI */ + movq %rbx, 0x100(%rsp) /* save RBX */ + movq %rbp, 0x108(%rsp) /* save RBP */ + + movq %rcx, 0x110(%rsp) /* save hidden address of transport_t */ + + /* preserve RSP (pointing to context-data) in RCX */ + movq %rsp, %rcx + + /* restore RSP (pointing to context-data) from RDX */ + movq %rdx, %rsp + +#if !defined(BOOST_USE_TSX) + /* restore XMM storage */ + movaps 0x0(%rsp), %xmm6 + movaps 0x10(%rsp), %xmm7 + movaps 0x20(%rsp), %xmm8 + movaps 0x30(%rsp), %xmm9 + movaps 0x40(%rsp), %xmm10 + movaps 0x50(%rsp), %xmm11 + movaps 0x60(%rsp), %xmm12 + movaps 0x70(%rsp), %xmm13 + movaps 0x80(%rsp), %xmm14 + movaps 0x90(%rsp), %xmm15 + ldmxcsr 0xa0(%rsp) /* restore MMX control- and status-word */ + fldcw 0xa4(%rsp) /* restore x87 control-word */ +#endif + + /* load NT_TIB */ + movq %gs:(0x30), %r10 + /* restore fiber local storage */ + movq 0xb0(%rsp), %rax + movq %rax, 0x20(%r10) + /* restore current deallocation stack */ + movq 0xb8(%rsp), %rax + movq %rax, 0x1478(%r10) + /* restore current stack limit */ + movq 0xc0(%rsp), %rax + movq %rax, 0x10(%r10) + /* restore current stack base */ + movq 0xc8(%rsp), %rax + movq %rax, 0x08(%r10) + + movq 0xd0(%rsp), %r12 /* restore R12 */ + movq 0xd8(%rsp), %r13 /* restore R13 */ + movq 0xe0(%rsp), %r14 /* restore R14 */ + movq 0xe8(%rsp), %r15 /* restore R15 */ + movq 0xf0(%rsp), %rdi /* restore RDI */ + movq 0xf8(%rsp), %rsi /* restore RSI */ + movq 0x100(%rsp), %rbx /* restore RBX */ + movq 0x108(%rsp), %rbp /* restore RBP */ + + movq 0x110(%rsp), %rax /* restore hidden address of transport_t */ + + leaq 0x118(%rsp), %rsp /* prepare stack */ + + /* keep return-address on stack */ + + /* transport_t returned in RAX */ + /* return parent fcontext_t */ + movq %rcx, 0x0(%rax) + /* return data */ + movq %r8, 0x8(%rax) + + /* transport_t as 1.arg of context-function */ + /* RCX contains address of returned (hidden) transfer_t */ + movq %rax, %rcx + /* RDX contains address of passed transfer_t */ + movq %rax, %rdx + + /* indirect jump to context */ + jmp *%r9 +.seh_endproc + +.section .drectve +.ascii " -export:\"ontop_fcontext\"" diff --git a/src/boost/libs/context/src/asm/ontop_x86_64_ms_pe_masm.asm b/src/boost/libs/context/src/asm/ontop_x86_64_ms_pe_masm.asm new file mode 100644 index 000000000..b57dd1588 --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_x86_64_ms_pe_masm.asm @@ -0,0 +1,207 @@ + +; Copyright Oliver Kowalke 2009. +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) + +; ---------------------------------------------------------------------------------- +; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +; ---------------------------------------------------------------------------------- +; | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | +; ---------------------------------------------------------------------------------- +; | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | +; ---------------------------------------------------------------------------------- +; | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | +; ---------------------------------------------------------------------------------- +; | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | +; ---------------------------------------------------------------------------------- +; | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | +; ---------------------------------------------------------------------------------- +; | SEE registers (XMM6-XMM15) | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | +; ---------------------------------------------------------------------------------- +; | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | +; ---------------------------------------------------------------------------------- +; | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | +; ---------------------------------------------------------------------------------- +; | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | +; ---------------------------------------------------------------------------------- +; | limit | base | R12 | R13 | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | +; ---------------------------------------------------------------------------------- +; | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | +; ---------------------------------------------------------------------------------- +; | R14 | R15 | RDI | RSI | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | +; ---------------------------------------------------------------------------------- +; | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | +; ---------------------------------------------------------------------------------- +; | RBX | RBP | hidden | RIP | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | +; ---------------------------------------------------------------------------------- +; | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | +; ---------------------------------------------------------------------------------- +; | parameter area | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | +; ---------------------------------------------------------------------------------- +; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | +; ---------------------------------------------------------------------------------- +; | FCTX | DATA | | +; ---------------------------------------------------------------------------------- + +.code + +ontop_fcontext PROC BOOST_CONTEXT_EXPORT FRAME + .endprolog + + ; prepare stack + lea rsp, [rsp-0118h] + +IFNDEF BOOST_USE_TSX + ; save XMM storage + movaps [rsp], xmm6 + movaps [rsp+010h], xmm7 + movaps [rsp+020h], xmm8 + movaps [rsp+030h], xmm9 + movaps [rsp+040h], xmm10 + movaps [rsp+050h], xmm11 + movaps [rsp+060h], xmm12 + movaps [rsp+070h], xmm13 + movaps [rsp+080h], xmm14 + movaps [rsp+090h], xmm15 + ; save MMX control- and status-word + stmxcsr [rsp+0a0h] + ; save x87 control-word + fnstcw [rsp+0a4h] +ENDIF + + ; load NT_TIB + mov r10, gs:[030h] + ; save fiber local storage + mov rax, [r10+020h] + mov [rsp+0b0h], rax + ; save current deallocation stack + mov rax, [r10+01478h] + mov [rsp+0b8h], rax + ; save current stack limit + mov rax, [r10+010h] + mov [rsp+0c0h], rax + ; save current stack base + mov rax, [r10+08h] + mov [rsp+0c8h], rax + + mov [rsp+0d0h], r12 ; save R12 + mov [rsp+0d8h], r13 ; save R13 + mov [rsp+0e0h], r14 ; save R14 + mov [rsp+0e8h], r15 ; save R15 + mov [rsp+0f0h], rdi ; save RDI + mov [rsp+0f8h], rsi ; save RSI + mov [rsp+0100h], rbx ; save RBX + mov [rsp+0108h], rbp ; save RBP + + mov [rsp+0110h], rcx ; save hidden address of transport_t + + ; preserve RSP (pointing to context-data) in RCX + mov rcx, rsp + + ; restore RSP (pointing to context-data) from RDX + mov rsp, rdx + +IFNDEF BOOST_USE_TSX + ; restore XMM storage + movaps xmm6, [rsp] + movaps xmm7, [rsp+010h] + movaps xmm8, [rsp+020h] + movaps xmm9, [rsp+030h] + movaps xmm10, [rsp+040h] + movaps xmm11, [rsp+050h] + movaps xmm12, [rsp+060h] + movaps xmm13, [rsp+070h] + movaps xmm14, [rsp+080h] + movaps xmm15, [rsp+090h] + ; restore MMX control- and status-word + ldmxcsr [rsp+0a0h] + ; save x87 control-word + fldcw [rsp+0a4h] +ENDIF + + ; load NT_TIB + mov r10, gs:[030h] + ; restore fiber local storage + mov rax, [rsp+0b0h] + mov [r10+020h], rax + ; restore current deallocation stack + mov rax, [rsp+0b8h] + mov [r10+01478h], rax + ; restore current stack limit + mov rax, [rsp+0c0h] + mov [r10+010h], rax + ; restore current stack base + mov rax, [rsp+0c8h] + mov [r10+08h], rax + + mov r12, [rsp+0d0h] ; restore R12 + mov r13, [rsp+0d8h] ; restore R13 + mov r14, [rsp+0e0h] ; restore R14 + mov r15, [rsp+0e8h] ; restore R15 + mov rdi, [rsp+0f0h] ; restore RDI + mov rsi, [rsp+0f8h] ; restore RSI + mov rbx, [rsp+0100h] ; restore RBX + mov rbp, [rsp+0108h] ; restore RBP + + mov rax, [rsp+0110h] ; restore hidden address of transport_t + + ; prepare stack + lea rsp, [rsp+0118h] + + ; keep return-address on stack + + ; transport_t returned in RAX + ; return parent fcontext_t + mov [rax], rcx + ; return data + mov [rax+08h], r8 + + ; transport_t as 1.arg of context-function + ; RCX contains address of returned (hidden) transfer_t + mov rcx, rax + ; RDX contains address of passed transfer_t + mov rdx, rax + + ; indirect jump to context + jmp r9 +ontop_fcontext ENDP +END diff --git a/src/boost/libs/context/src/asm/ontop_x86_64_sysv_elf_gas.S b/src/boost/libs/context/src/asm/ontop_x86_64_sysv_elf_gas.S new file mode 100644 index 000000000..447a1ec6b --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_x86_64_sysv_elf_gas.S @@ -0,0 +1,84 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * + * ---------------------------------------------------------------------------------- * + * | R15 | RBX | RBP | RIP | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.file "ontop_x86_64_sysv_elf_gas.S" +.text +.globl ontop_fcontext +.type ontop_fcontext,@function +.align 16 +ontop_fcontext: + /* preserve ontop-function in R8 */ + movq %rdx, %r8 + + leaq -0x38(%rsp), %rsp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + stmxcsr (%rsp) /* save MMX control- and status-word */ + fnstcw 0x4(%rsp) /* save x87 control-word */ +#endif + + movq %r12, 0x8(%rsp) /* save R12 */ + movq %r13, 0x10(%rsp) /* save R13 */ + movq %r14, 0x18(%rsp) /* save R14 */ + movq %r15, 0x20(%rsp) /* save R15 */ + movq %rbx, 0x28(%rsp) /* save RBX */ + movq %rbp, 0x30(%rsp) /* save RBP */ + + /* store RSP (pointing to context-data) in RAX */ + movq %rsp, %rax + + /* restore RSP (pointing to context-data) from RDI */ + movq %rdi, %rsp + +#if !defined(BOOST_USE_TSX) + ldmxcsr (%rsp) /* restore MMX control- and status-word */ + fldcw 0x4(%rsp) /* restore x87 control-word */ +#endif + + movq 0x8(%rsp), %r12 /* restore R12 */ + movq 0x10(%rsp), %r13 /* restore R13 */ + movq 0x18(%rsp), %r14 /* restore R14 */ + movq 0x20(%rsp), %r15 /* restore R15 */ + movq 0x28(%rsp), %rbx /* restore RBX */ + movq 0x30(%rsp), %rbp /* restore RBP */ + + leaq 0x38(%rsp), %rsp /* prepare stack */ + + /* return transfer_t from jump */ + /* RAX == fctx, RDX == data */ + movq %rsi, %rdx + /* pass transfer_t as first arg in context function */ + /* RDI == fctx, RSI == data */ + movq %rax, %rdi + + /* keep return-address on stack */ + + /* indirect jump to context */ + jmp *%r8 +.size ontop_fcontext,.-ontop_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/src/boost/libs/context/src/asm/ontop_x86_64_sysv_macho_gas.S b/src/boost/libs/context/src/asm/ontop_x86_64_sysv_macho_gas.S new file mode 100644 index 000000000..49755c69b --- /dev/null +++ b/src/boost/libs/context/src/asm/ontop_x86_64_sysv_macho_gas.S @@ -0,0 +1,78 @@ +/* + Copyright Oliver Kowalke 2009. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/**************************************************************************************** + * * + * ---------------------------------------------------------------------------------- * + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * + * ---------------------------------------------------------------------------------- * + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * + * ---------------------------------------------------------------------------------- * + * | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | * + * ---------------------------------------------------------------------------------- * + * ---------------------------------------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ---------------------------------------------------------------------------------- * + * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * + * ---------------------------------------------------------------------------------- * + * | R15 | RBX | RBP | RIP | * + * ---------------------------------------------------------------------------------- * + * * + ****************************************************************************************/ + +.text +.globl _ontop_fcontext +.align 8 +_ontop_fcontext: + /* preserve ontop-function in R8 */ + movq %rdx, %r8 + + leaq -0x38(%rsp), %rsp /* prepare stack */ + +#if !defined(BOOST_USE_TSX) + stmxcsr (%rsp) /* save MMX control- and status-word */ + fnstcw 0x4(%rsp) /* save x87 control-word */ +#endif + + movq %r12, 0x8(%rsp) /* save R12 */ + movq %r13, 0x10(%rsp) /* save R13 */ + movq %r14, 0x18(%rsp) /* save R14 */ + movq %r15, 0x20(%rsp) /* save R15 */ + movq %rbx, 0x28(%rsp) /* save RBX */ + movq %rbp, 0x30(%rsp) /* save RBP */ + + /* store RSP (pointing to context-data) in RAX */ + movq %rsp, %rax + + /* restore RSP (pointing to context-data) from RDI */ + movq %rdi, %rsp + +#if !defined(BOOST_USE_TSX) + ldmxcsr (%rsp) /* restore MMX control- and status-word */ + fldcw 0x4(%rsp) /* restore x87 control-word */ +#endif + + movq 0x8(%rsp), %r12 /* restore R12 */ + movq 0x10(%rsp), %r13 /* restore R13 */ + movq 0x18(%rsp), %r14 /* restore R14 */ + movq 0x20(%rsp), %r15 /* restore R15 */ + movq 0x28(%rsp), %rbx /* restore RBX */ + movq 0x30(%rsp), %rbp /* restore RBP */ + + leaq 0x38(%rsp), %rsp /* prepare stack */ + + /* return transfer_t from jump */ + /* RAX == fctx, RDX == data */ + movq %rsi, %rdx + /* pass transfer_t as first arg in context function */ + /* RDI == fctx, RSI == data */ + movq %rax, %rdi + + /* keep return-address on stack */ + + /* indirect jump to context */ + jmp *%r8 diff --git a/src/boost/libs/context/src/asm/tail_ppc32_sysv_elf_gas.cpp b/src/boost/libs/context/src/asm/tail_ppc32_sysv_elf_gas.cpp new file mode 100644 index 000000000..348608460 --- /dev/null +++ b/src/boost/libs/context/src/asm/tail_ppc32_sysv_elf_gas.cpp @@ -0,0 +1,18 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/context/detail/fcontext.hpp> + +using boost::context::detail::fcontext_t; +using boost::context::detail::transfer_t; + +// This C++ tail of ontop_fcontext() allocates transfer_t{ from, vp } +// on the stack. If fn() throws a C++ exception, then the C++ runtime +// must remove this tail's stack frame. +extern "C" transfer_t +ontop_fcontext_tail( int ignore, void * vp, transfer_t (* fn)(transfer_t), fcontext_t const from) { + return fn( transfer_t{ from, vp }); +} diff --git a/src/boost/libs/context/src/continuation.cpp b/src/boost/libs/context/src/continuation.cpp new file mode 100644 index 000000000..0779baaba --- /dev/null +++ b/src/boost/libs/context/src/continuation.cpp @@ -0,0 +1,60 @@ + +// Copyright Oliver Kowalke 2017. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#if defined(BOOST_USE_UCONTEXT) +#include "boost/context/continuation_ucontext.hpp" +#elif defined(BOOST_USE_WINFIB) +#include "boost/context/continuation_winfib.hpp" +#else +#include "boost/context/execution_context.hpp" +#endif + +#include <boost/config.hpp> + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_PREFIX +#endif + +namespace boost { +namespace context { +namespace detail { + +// zero-initialization +thread_local activation_record * current_rec; +thread_local static std::size_t counter; + +// schwarz counter +activation_record_initializer::activation_record_initializer() noexcept { + if ( 0 == counter++) { + current_rec = new activation_record(); + } +} + +activation_record_initializer::~activation_record_initializer() { + if ( 0 == --counter) { + BOOST_ASSERT( current_rec->is_main_context() ); + delete current_rec; + } +} + +} + +namespace detail { + +activation_record *& +activation_record::current() noexcept { + // initialized the first time control passes; per thread + thread_local static activation_record_initializer initializer; + return current_rec; +} + +} + +}} + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_SUFFIX +#endif diff --git a/src/boost/libs/context/src/dummy.cpp b/src/boost/libs/context/src/dummy.cpp new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/boost/libs/context/src/dummy.cpp diff --git a/src/boost/libs/context/src/fiber.cpp b/src/boost/libs/context/src/fiber.cpp new file mode 100644 index 000000000..b6b790df5 --- /dev/null +++ b/src/boost/libs/context/src/fiber.cpp @@ -0,0 +1,58 @@ + +// Copyright Oliver Kowalke 2017. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#if defined(BOOST_USE_UCONTEXT) +#include "boost/context/fiber_ucontext.hpp" +#elif defined(BOOST_USE_WINFIB) +#include "boost/context/fiber_winfib.hpp" +#endif + +#include <boost/config.hpp> + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_PREFIX +#endif + +namespace boost { +namespace context { +namespace detail { + +// zero-initialization +thread_local fiber_activation_record * fib_current_rec; +thread_local static std::size_t counter; + +// schwarz counter +fiber_activation_record_initializer::fiber_activation_record_initializer() noexcept { + if ( 0 == counter++) { + fib_current_rec = new fiber_activation_record(); + } +} + +fiber_activation_record_initializer::~fiber_activation_record_initializer() { + if ( 0 == --counter) { + BOOST_ASSERT( fib_current_rec->is_main_context() ); + delete fib_current_rec; + } +} + +} + +namespace detail { + +fiber_activation_record *& +fiber_activation_record::current() noexcept { + // initialized the first time control passes; per thread + thread_local static fiber_activation_record_initializer initializer; + return fib_current_rec; +} + +} + +}} + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_SUFFIX +#endif diff --git a/src/boost/libs/context/src/posix/stack_traits.cpp b/src/boost/libs/context/src/posix/stack_traits.cpp new file mode 100644 index 000000000..ca4208885 --- /dev/null +++ b/src/boost/libs/context/src/posix/stack_traits.cpp @@ -0,0 +1,122 @@ + +// Copyright Oliver Kowalke 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include "boost/context/stack_traits.hpp" + +extern "C" { +#include <signal.h> +#include <sys/resource.h> +#include <sys/time.h> +#include <unistd.h> +} + +//#if _POSIX_C_SOURCE >= 200112L + +#include <algorithm> +#include <cmath> + +#include <boost/assert.hpp> +#include <boost/config.hpp> +#if defined(BOOST_NO_CXX11_HDR_MUTEX) +# include <boost/thread.hpp> +#else +# include <mutex> +#endif + +#if !defined (SIGSTKSZ) +# define SIGSTKSZ (32768) // 32kb minimum allowable stack +# define UDEF_SIGSTKSZ +#endif + +#if !defined (MINSIGSTKSZ) +# define MINSIGSTKSZ (131072) // 128kb recommended stack size +# define UDEF_MINSIGSTKSZ +#endif + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_PREFIX +#endif + +namespace { + +void pagesize_( std::size_t * size) BOOST_NOEXCEPT_OR_NOTHROW { + // conform to POSIX.1-2001 + * size = ::sysconf( _SC_PAGESIZE); +} + +void stacksize_limit_( rlimit * limit) BOOST_NOEXCEPT_OR_NOTHROW { + // conforming to POSIX.1-2001 + ::getrlimit( RLIMIT_STACK, limit); +} + +std::size_t pagesize() BOOST_NOEXCEPT_OR_NOTHROW { + static std::size_t size = 0; +#if defined(BOOST_NO_CXX11_HDR_MUTEX) + static boost::once_flag flag = BOOST_ONCE_INIT; + boost::call_once( flag, pagesize_, & size); +#else + static std::once_flag flag; + std::call_once( flag, pagesize_, & size); +#endif + return size; +} + +rlimit stacksize_limit() BOOST_NOEXCEPT_OR_NOTHROW { + static rlimit limit; +#if defined(BOOST_NO_CXX11_HDR_MUTEX) + static boost::once_flag flag = BOOST_ONCE_INIT; + boost::call_once( flag, stacksize_limit_, & limit); +#else + static std::once_flag flag; + std::call_once( flag, stacksize_limit_, & limit); +#endif + return limit; +} + +} + +namespace boost { +namespace context { + +bool +stack_traits::is_unbounded() BOOST_NOEXCEPT_OR_NOTHROW { + return RLIM_INFINITY == stacksize_limit().rlim_max; +} + +std::size_t +stack_traits::page_size() BOOST_NOEXCEPT_OR_NOTHROW { + return pagesize(); +} + +std::size_t +stack_traits::default_size() BOOST_NOEXCEPT_OR_NOTHROW { + return 128 * 1024; +} + +std::size_t +stack_traits::minimum_size() BOOST_NOEXCEPT_OR_NOTHROW { + return MINSIGSTKSZ; +} + +std::size_t +stack_traits::maximum_size() BOOST_NOEXCEPT_OR_NOTHROW { + BOOST_ASSERT( ! is_unbounded() ); + return static_cast< std::size_t >( stacksize_limit().rlim_max); +} + +}} + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_SUFFIX +#endif + +#ifdef UDEF_SIGSTKSZ +# undef SIGSTKSZ; +#endif + +#ifdef UDEF_MINSIGSTKSZ +# undef MINSIGSTKSZ +#endif diff --git a/src/boost/libs/context/src/untested.cpp b/src/boost/libs/context/src/untested.cpp new file mode 100644 index 000000000..d6e20868c --- /dev/null +++ b/src/boost/libs/context/src/untested.cpp @@ -0,0 +1,7 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#error "! code for this platform is untested - please remove this file from build/Jamfile.v2 and report the test-result on boost-track !" diff --git a/src/boost/libs/context/src/windows/stack_traits.cpp b/src/boost/libs/context/src/windows/stack_traits.cpp new file mode 100644 index 000000000..14016b1b3 --- /dev/null +++ b/src/boost/libs/context/src/windows/stack_traits.cpp @@ -0,0 +1,116 @@ + +// Copyright Oliver Kowalke 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include "boost/context/stack_traits.hpp" + +extern "C" { +#include <windows.h> +} + +//#if defined (BOOST_WINDOWS) || _POSIX_C_SOURCE >= 200112L + +#include <algorithm> +#include <cmath> +#include <cstddef> +#include <cstring> +#include <stdexcept> + +#include <boost/assert.hpp> +#include <boost/context/detail/config.hpp> +#if defined(BOOST_NO_CXX11_HDR_MUTEX) +# include <boost/thread.hpp> +#else +# include <mutex> +#endif + +#include <boost/context/stack_context.hpp> + +// x86_64 +// test x86_64 before i386 because icc might +// define __i686__ for x86_64 too +#if defined(__x86_64__) || defined(__x86_64) \ + || defined(__amd64__) || defined(__amd64) \ + || defined(_M_X64) || defined(_M_AMD64) + +// Windows seams not to provide a constant or function +// telling the minimal stacksize +# define MIN_STACKSIZE 8 * 1024 +#else +# define MIN_STACKSIZE 4 * 1024 +#endif + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_PREFIX +#endif + +namespace { + +void system_info_( SYSTEM_INFO * si) BOOST_NOEXCEPT_OR_NOTHROW { + ::GetSystemInfo( si); +} + +SYSTEM_INFO system_info() BOOST_NOEXCEPT_OR_NOTHROW { + static SYSTEM_INFO si; +#if defined(BOOST_NO_CXX11_HDR_MUTEX) + static boost::once_flag flag = BOOST_ONCE_INIT; + boost::call_once( flag, static_cast< void(*)( SYSTEM_INFO *) >( system_info_), & si); +#else + static std::once_flag flag; + std::call_once( flag, static_cast< void(*)( SYSTEM_INFO *) >( system_info_), & si); +#endif + return si; +} + +std::size_t pagesize() BOOST_NOEXCEPT_OR_NOTHROW { + return static_cast< std::size_t >( system_info().dwPageSize); +} + +} + +namespace boost { +namespace context { + +// Windows seams not to provide a limit for the stacksize +// libcoco uses 32k+4k bytes as minimum +BOOST_CONTEXT_DECL +bool +stack_traits::is_unbounded() BOOST_NOEXCEPT_OR_NOTHROW { + return true; +} + +BOOST_CONTEXT_DECL +std::size_t +stack_traits::page_size() BOOST_NOEXCEPT_OR_NOTHROW { + return pagesize(); +} + +BOOST_CONTEXT_DECL +std::size_t +stack_traits::default_size() BOOST_NOEXCEPT_OR_NOTHROW { + return 128 * 1024; +} + +// because Windows seams not to provide a limit for minimum stacksize +BOOST_CONTEXT_DECL +std::size_t +stack_traits::minimum_size() BOOST_NOEXCEPT_OR_NOTHROW { + return MIN_STACKSIZE; +} + +// because Windows seams not to provide a limit for maximum stacksize +// maximum_size() can never be called (pre-condition ! is_unbounded() ) +BOOST_CONTEXT_DECL +std::size_t +stack_traits::maximum_size() BOOST_NOEXCEPT_OR_NOTHROW { + BOOST_ASSERT( ! is_unbounded() ); + return 1 * 1024 * 1024 * 1024; // 1GB +} + +}} + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_SUFFIX +#endif diff --git a/src/boost/libs/context/test/Jamfile.v2 b/src/boost/libs/context/test/Jamfile.v2 new file mode 100644 index 000000000..07ab5c344 --- /dev/null +++ b/src/boost/libs/context/test/Jamfile.v2 @@ -0,0 +1,218 @@ +# Boost.Context Library Tests Jamfile + +# Copyright Oliver Kowalke 2009. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import common ; +import feature ; +import indirect ; +import modules ; +import os ; +import testing ; +import toolset ; +import ../../config/checks/config : requires ; + +project boost/context/test + : requirements + <library>../../test/build//boost_unit_test_framework + <library>/boost/context//boost_context + <toolset>gcc,<segmented-stacks>on:<cxxflags>-fsplit-stack + <toolset>gcc,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS + <toolset>clang,<segmented-stacks>on:<cxxflags>-fsplit-stack + <toolset>clang,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS + <link>static + <threading>multi + <variant>release + ; + + +rule native-impl ( properties * ) +{ + local result ; + if ( <target-os>android in $(properties) || + <target-os>darwin in $(properties) || + <target-os>openbsd in $(properties) ) + { + result = <build>no ; + } + else if ( ! ( <target-os>windows in $(properties) ) ) + { + result = <context-impl>ucontext ; + } + else + { + result = <context-impl>winfib ; + } + return $(result) ; +} + +rule segmented-stack ( properties * ) +{ + local result ; + if ( <toolset>gcc in $(properties) ) + { + result = <segmented-stacks>on ; + } + else + { + result = <build>no ; + } + return $(result) ; +} + +test-suite minimal : +[ run test_invoke.cpp : + : : + [ requires cxx11_auto_declarations + cxx11_constexpr + cxx11_defaulted_functions + cxx11_final + cxx11_hdr_thread + cxx11_hdr_tuple + cxx11_lambdas + cxx11_noexcept + cxx11_nullptr + cxx11_rvalue_references + cxx11_template_aliases + cxx11_thread_local + cxx11_variadic_templates ] ] + +[ run test_apply.cpp : + : : + [ requires cxx11_auto_declarations + cxx11_constexpr + cxx11_defaulted_functions + cxx11_final + cxx11_hdr_thread + cxx11_hdr_tuple + cxx11_lambdas + cxx11_noexcept + cxx11_nullptr + cxx11_rvalue_references + cxx11_template_aliases + cxx11_thread_local + cxx11_variadic_templates ] ] + +[ run test_fiber.cpp : + : : + <context-impl>fcontext + [ requires cxx11_auto_declarations + cxx11_constexpr + cxx11_defaulted_functions + cxx11_final + cxx11_hdr_thread + cxx11_hdr_tuple + cxx11_lambdas + cxx11_noexcept + cxx11_nullptr + cxx11_rvalue_references + cxx11_template_aliases + cxx11_thread_local + cxx11_variadic_templates ] + : test_fiber_asm ] + +[ run test_fiber.cpp : + : : + <conditional>@native-impl + [ requires cxx11_auto_declarations + cxx11_constexpr + cxx11_defaulted_functions + cxx11_final + cxx11_hdr_thread + cxx11_hdr_tuple + cxx11_lambdas + cxx11_noexcept + cxx11_nullptr + cxx11_rvalue_references + cxx11_template_aliases + cxx11_thread_local + cxx11_variadic_templates ] + : test_fiber_native ] + +[ run test_fiber.cpp : + : : + <context-impl>ucontext + <conditional>@segmented-stack + [ requires cxx11_auto_declarations + cxx11_constexpr + cxx11_defaulted_functions + cxx11_final + cxx11_hdr_thread + cxx11_hdr_tuple + cxx11_lambdas + cxx11_noexcept + cxx11_nullptr + cxx11_rvalue_references + cxx11_template_aliases + cxx11_thread_local + cxx11_variadic_templates ] + : test_fiber_segmented ] + +[ run test_callcc.cpp : + : : + <context-impl>fcontext + [ requires cxx11_auto_declarations + cxx11_constexpr + cxx11_defaulted_functions + cxx11_final + cxx11_hdr_thread + cxx11_hdr_tuple + cxx11_lambdas + cxx11_noexcept + cxx11_nullptr + cxx11_rvalue_references + cxx11_template_aliases + cxx11_thread_local + cxx11_variadic_templates ] + : test_callcc_asm ] + +[ run test_callcc.cpp : + : : + <conditional>@native-impl + [ requires cxx11_auto_declarations + cxx11_constexpr + cxx11_defaulted_functions + cxx11_final + cxx11_hdr_thread + cxx11_hdr_tuple + cxx11_lambdas + cxx11_noexcept + cxx11_nullptr + cxx11_rvalue_references + cxx11_template_aliases + cxx11_thread_local + cxx11_variadic_templates ] + : test_callcc_native ] + +[ run test_callcc.cpp : + : : + <context-impl>ucontext + <conditional>@segmented-stack + [ requires cxx11_auto_declarations + cxx11_constexpr + cxx11_defaulted_functions + cxx11_final + cxx11_hdr_thread + cxx11_hdr_tuple + cxx11_lambdas + cxx11_noexcept + cxx11_nullptr + cxx11_rvalue_references + cxx11_template_aliases + cxx11_thread_local + cxx11_variadic_templates ] + : test_callcc_segmented ] ; + + +test-suite full : + minimal ; + +test-suite fc : +[ run test_fcontext.cpp : + : : + ] ; + +explicit minimal ; +explicit fc ; diff --git a/src/boost/libs/context/test/test_apply.cpp b/src/boost/libs/context/test/test_apply.cpp new file mode 100644 index 000000000..d6b1a2022 --- /dev/null +++ b/src/boost/libs/context/test/test_apply.cpp @@ -0,0 +1,209 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <iostream> +#include <memory> +#include <sstream> +#include <stdexcept> +#include <string> +#include <tuple> +#include <utility> + +#include <boost/assert.hpp> +#include <boost/test/unit_test.hpp> + +#include <boost/context/detail/apply.hpp> +#include <boost/context/detail/config.hpp> + +namespace ctx = boost::context; + +struct callable { + int k{ 0 }; + + callable() = default; + + callable( int k_) : + k{ k_ } { + } + + int foo( int i, int j) const { + return i + j + k; + } + + int operator()( int i, int j) const { + return foo( i, j); + } +}; + +struct movable { + int k{ 0 }; + + movable() = default; + + movable( int k_) : + k{ k_ } { + } + + movable( movable const&) = delete; + movable & operator=( movable const&) = delete; + + movable( movable && other) : + k{ other.k } { + other.k = -1; + } + + movable & operator=( movable && other) { + if ( this == & other) return * this; + k = other.k; + other.k = -1; + return * this; + } + + int foo( int i, int j) const { + return i + j + k; + } + + int operator()( int i, int j) const { + return foo( i, j); + } +}; + +int fn1( int i, int j) { + return i + j; +} + +int * fn2( int * ip) { + return ip; +} + +int * fn3( int & ir) { + return & ir; +} + +int & fn4( int & ir) { + return ir; +} + +int fn5( int i, callable && c) { + return i + c.k; +} + +int fn6( int i, movable && m) { + return i + m.k; +} + +void test1() { + int result = ctx::detail::apply( fn1, std::make_tuple( 1, 2) ); + BOOST_CHECK_EQUAL( result, 3); +} + +void test2() { + { + int i = 3; + int * ip = & i; + int * result = ctx::detail::apply( fn2, std::make_tuple( ip) ); + BOOST_CHECK_EQUAL( result, ip); + BOOST_CHECK_EQUAL( * result, i); + } + { + int i = 3; + int * result = ctx::detail::apply( fn2, std::make_tuple( & i) ); + BOOST_CHECK_EQUAL( result, & i); + BOOST_CHECK_EQUAL( * result, i); + } +} + +void test3() { + { + int i = 'c'; + int & ir = i; + int * result = ctx::detail::apply( fn3, std::make_tuple( std::ref( ir) ) ); + BOOST_CHECK_EQUAL( result, & ir); + BOOST_CHECK_EQUAL( * result, i); + } + { + int i = 'c'; + int * result = ctx::detail::apply( fn3, std::make_tuple( std::ref( i) ) ); + BOOST_CHECK_EQUAL( result, & i); + BOOST_CHECK_EQUAL( * result, i); + } +} + +void test4() { + { + int i = 3; + int & ir = i; + int & result = ctx::detail::apply( fn4, std::make_tuple( std::ref( ir) ) ); + BOOST_CHECK_EQUAL( result, ir); + BOOST_CHECK_EQUAL( & result, & ir); + BOOST_CHECK_EQUAL( result, i); + } + { + int i = 3; + int & result = ctx::detail::apply( fn4, std::make_tuple( std::ref( i) ) ); + BOOST_CHECK_EQUAL( & result, & i); + BOOST_CHECK_EQUAL( result, i); + } +} + +void test5() { + { + callable c( 5); + int result = ctx::detail::apply( fn5, std::make_tuple( 1, std::move( c) ) ); + BOOST_CHECK_EQUAL( result, 6); + BOOST_CHECK_EQUAL( c.k, 5); + } + { + movable m( 5); + int result = ctx::detail::apply( fn6, std::make_tuple( 1, std::move( m) ) ); + BOOST_CHECK_EQUAL( result, 6); + BOOST_CHECK_EQUAL( m.k, -1); + } +} + +void test6() { + { + callable c; + int result = ctx::detail::apply( c, std::make_tuple( 1, 2) ); + BOOST_CHECK_EQUAL( result, 3); + BOOST_CHECK_EQUAL( c.k, 0); + } + { + callable c; + int result = ctx::detail::apply( & callable::foo, std::make_tuple( c, 1, 2) ); + BOOST_CHECK_EQUAL( result, 3); + BOOST_CHECK_EQUAL( c.k, 0); + } +} + +void test7() { + { + movable m; + int result = ctx::detail::apply( std::move( m), std::make_tuple( 1, 2) ); + BOOST_CHECK_EQUAL( result, 3); + } + { + movable m; + int result = ctx::detail::apply( & movable::foo, std::make_tuple( std::move( m), 1, 2) ); + BOOST_CHECK_EQUAL( result, 3); + } +} + +boost::unit_test::test_suite * init_unit_test_suite( int, char* []) +{ + boost::unit_test::test_suite * test = + BOOST_TEST_SUITE("Boost.Context: apply test suite"); + + test->add( BOOST_TEST_CASE( & test1) ); + test->add( BOOST_TEST_CASE( & test2) ); + test->add( BOOST_TEST_CASE( & test3) ); + test->add( BOOST_TEST_CASE( & test4) ); + test->add( BOOST_TEST_CASE( & test5) ); + test->add( BOOST_TEST_CASE( & test6) ); + test->add( BOOST_TEST_CASE( & test7) ); + + return test; +} diff --git a/src/boost/libs/context/test/test_callcc.cpp b/src/boost/libs/context/test/test_callcc.cpp new file mode 100644 index 000000000..7ba783e54 --- /dev/null +++ b/src/boost/libs/context/test/test_callcc.cpp @@ -0,0 +1,516 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <stdio.h> +#include <stdlib.h> + +#include <cmath> +#include <cstdint> +#include <cstdio> +#include <iostream> +#include <memory> +#include <sstream> +#include <stdexcept> +#include <string> +#include <thread> +#include <utility> +#include <vector> + +#include <boost/array.hpp> +#include <boost/assert.hpp> +#include <boost/lexical_cast.hpp> +#include <boost/test/unit_test.hpp> +#include <boost/utility.hpp> +#include <boost/variant.hpp> + +#include <boost/context/continuation.hpp> +#include <boost/context/detail/config.hpp> + +#ifdef BOOST_WINDOWS +#include <windows.h> +#endif + +#if defined(BOOST_MSVC) +# pragma warning(push) +# pragma warning(disable: 4702 4723 4996) +#endif + +typedef boost::variant<int,std::string> variant_t; + +namespace ctx = boost::context; + +int value1 = 0; +std::string value2; +double value3 = 0.; + +struct X { + ctx::continuation foo( ctx::continuation && c, int i) { + value1 = i; + return std::move( c); + } +}; + +struct Y { + Y() { + value1 = 3; + } + + Y( Y const&) = delete; + Y & operator=( Y const&) = delete; + + ~Y() { + value1 = 7; + } +}; + +class moveable { +public: + bool state; + int value; + + moveable() : + state( false), + value( -1) { + } + + moveable( int v) : + state( true), + value( v) { + } + + moveable( moveable && other) : + state( other.state), + value( other.value) { + other.state = false; + other.value = -1; + } + + moveable & operator=( moveable && other) { + if ( this == & other) return * this; + state = other.state; + value = other.value; + other.state = false; + other.value = -1; + return * this; + } + + moveable( moveable const& other) = delete; + moveable & operator=( moveable const& other) = delete; + + void operator()() { + value1 = value; + } +}; + +struct my_exception : public std::runtime_error { + ctx::continuation c; + my_exception( ctx::continuation && c_, char const* what) : + std::runtime_error( what), + c{ std::move( c_) } { + } +}; + +#ifdef BOOST_MSVC +// Optimizations can remove the integer-divide-by-zero here. +#pragma optimize("", off) +void seh( bool & catched) { + __try { + int i = 1; + i /= 0; + } __except( EXCEPTION_EXECUTE_HANDLER) { + catched = true; + } +} +#pragma optimize("", on) +#endif + +void test_move() { + value1 = 0; + int i = 1; + BOOST_CHECK_EQUAL( 0, value1); + ctx::continuation c1 = ctx::callcc( + [&i](ctx::continuation && c) { + value1 = i; + c = c.resume(); + value1 = i; + return std::move( c); + }); + BOOST_CHECK_EQUAL( 1, value1); + BOOST_CHECK( c1); + ctx::continuation c2; + BOOST_CHECK( ! c2); + c2 = std::move( c1); + BOOST_CHECK( ! c1); + BOOST_CHECK( c2); + i = 3; + c2.resume(); + BOOST_CHECK_EQUAL( 3, value1); + BOOST_CHECK( ! c1); + BOOST_CHECK( ! c2); +} + +void test_bind() { + value1 = 0; + X x; + ctx::continuation c = ctx::callcc( std::bind( & X::foo, x, std::placeholders::_1, 7) ); + BOOST_CHECK_EQUAL( 7, value1); +} + +void test_exception() { + { + const char * what = "hello world"; + ctx::continuation c = ctx::callcc( + [&what](ctx::continuation && c) { + try { + throw std::runtime_error( what); + } catch ( std::runtime_error const& e) { + value2 = e.what(); + } + return std::move( c); + }); + BOOST_CHECK_EQUAL( std::string( what), value2); + BOOST_CHECK( ! c); + } +#ifdef BOOST_MSVC + { + bool catched = false; + std::thread([&catched](){ + ctx::continuation c = ctx::callcc([&catched](ctx::continuation && c){ + c = c.resume(); + seh( catched); + return std::move( c); + }); + BOOST_CHECK( c ); + c.resume(); + }).join(); + BOOST_CHECK( catched); + } +#endif +} + +void test_fp() { + value3 = 0.; + double d = 7.13; + ctx::continuation c = ctx::callcc( + [&d]( ctx::continuation && c) { + d += 3.45; + value3 = d; + return std::move( c); + }); + BOOST_CHECK_EQUAL( 10.58, value3); + BOOST_CHECK( ! c); +} + +void test_stacked() { + value1 = 0; + value3 = 0.; + ctx::continuation c = ctx::callcc( + [](ctx::continuation && c) { + ctx::continuation c1 = ctx::callcc( + [](ctx::continuation && c) { + value1 = 3; + return std::move( c); + }); + value3 = 3.14; + return std::move( c); + }); + BOOST_CHECK_EQUAL( 3, value1); + BOOST_CHECK_EQUAL( 3.14, value3); + BOOST_CHECK( ! c ); +} + +void test_prealloc() { + value1 = 0; + ctx::default_stack alloc; + ctx::stack_context sctx( alloc.allocate() ); + void * sp = static_cast< char * >( sctx.sp) - 10; + std::size_t size = sctx.size - 10; + int i = 7; + ctx::continuation c = ctx::callcc( + std::allocator_arg, ctx::preallocated( sp, size, sctx), alloc, + [&i]( ctx::continuation && c) { + value1 = i; + return std::move( c); + }); + BOOST_CHECK_EQUAL( 7, value1); + BOOST_CHECK( ! c); +} + +void test_ontop() { + { + int i = 3; + ctx::continuation c = ctx::callcc([&i](ctx::continuation && c) { + for (;;) { + i *= 10; + c = c.resume(); + } + return std::move( c); + }); + c = c.resume_with( + [&i](ctx::continuation && c){ + i -= 10; + return std::move( c); + }); + BOOST_CHECK( c); + BOOST_CHECK_EQUAL( i, 200); + } + { + ctx::continuation c1; + ctx::continuation c = ctx::callcc([&c1](ctx::continuation && c) { + c = c.resume(); + BOOST_CHECK( ! c); + return std::move( c1); + }); + c = c.resume_with( + [&c1](ctx::continuation && c){ + c1 = std::move( c); + return std::move( c); + }); + } +} + +void test_ontop_exception() { + value1 = 0; + value2 = ""; + ctx::continuation c = ctx::callcc([](ctx::continuation && c){ + for (;;) { + value1 = 3; + try { + c = c.resume(); + } catch ( my_exception & ex) { + value2 = ex.what(); + return std::move( ex.c); + } + } + return std::move( c); + }); + c = c.resume(); + BOOST_CHECK_EQUAL( 3, value1); + const char * what = "hello world"; + c.resume_with( + [what](ctx::continuation && c){ + throw my_exception( std::move( c), what); + return std::move( c); + }); + BOOST_CHECK_EQUAL( 3, value1); + BOOST_CHECK_EQUAL( std::string( what), value2); +} + +void test_termination1() { + { + value1 = 0; + ctx::continuation c = ctx::callcc( + [](ctx::continuation && c){ + Y y; + return c.resume(); + }); + BOOST_CHECK_EQUAL( 3, value1); + } + BOOST_CHECK_EQUAL( 7, value1); + { + value1 = 0; + BOOST_CHECK_EQUAL( 0, value1); + ctx::continuation c = ctx::callcc( + [](ctx::continuation && c) { + value1 = 3; + return std::move( c); + }); + BOOST_CHECK_EQUAL( 3, value1); + BOOST_CHECK( ! c ); + } + { + value1 = 0; + BOOST_CHECK_EQUAL( 0, value1); + int i = 3; + ctx::continuation c = ctx::callcc( + [&i](ctx::continuation && c){ + value1 = i; + c = c.resume(); + value1 = i; + return std::move( c); + }); + BOOST_CHECK( c); + BOOST_CHECK_EQUAL( i, value1); + BOOST_CHECK( c); + i = 7; + c = c.resume(); + BOOST_CHECK( ! c); + BOOST_CHECK_EQUAL( i, value1); + } +} + +void test_termination2() { + { + value1 = 0; + value3 = 0.0; + ctx::continuation c = ctx::callcc( + [](ctx::continuation && c){ + Y y; + value1 = 3; + value3 = 4.; + c = c.resume(); + value1 = 7; + value3 = 8.; + c = c.resume(); + return std::move( c); + }); + BOOST_CHECK_EQUAL( 3, value1); + BOOST_CHECK_EQUAL( 4., value3); + c = c.resume(); + } + BOOST_CHECK_EQUAL( 7, value1); + BOOST_CHECK_EQUAL( 8., value3); +} + +void test_sscanf() { + ctx::continuation c = ctx::callcc( + []( ctx::continuation && c) { + { + double n1 = 0; + double n2 = 0; + sscanf("3.14 7.13", "%lf %lf", & n1, & n2); + BOOST_CHECK( n1 == 3.14); + BOOST_CHECK( n2 == 7.13); + } + { + int n1=0; + int n2=0; + sscanf("1 23", "%d %d", & n1, & n2); + BOOST_CHECK( n1 == 1); + BOOST_CHECK( n2 == 23); + } + { + int n1=0; + int n2=0; + sscanf("1 jjj 23", "%d %*[j] %d", & n1, & n2); + BOOST_CHECK( n1 == 1); + BOOST_CHECK( n2 == 23); + } + return std::move( c); + }); +} + +void test_snprintf() { + ctx::continuation c = ctx::callcc( + []( ctx::continuation && c) { + { + const char *fmt = "sqrt(2) = %f"; + char buf[19]; + snprintf( buf, sizeof( buf), fmt, std::sqrt( 2) ); + BOOST_CHECK( 0 < sizeof( buf) ); + BOOST_ASSERT( std::string("sqrt(2) = 1.41") == std::string( buf, 14) ); + } + { + std::uint64_t n = 0xbcdef1234567890; + const char *fmt = "0x%016llX"; + char buf[100]; + snprintf( buf, sizeof( buf), fmt, n); + BOOST_ASSERT( std::string("0x0BCDEF1234567890") == std::string( buf, 18) ); + } + return std::move( c); + }); +} + +#ifdef BOOST_WINDOWS +void test_bug12215() { + ctx::continuation c = ctx::callcc( + [](ctx::continuation && c) { + char buffer[MAX_PATH]; + GetModuleFileName( nullptr, buffer, MAX_PATH); + return std::move( c); + }); +} +#endif + +void test_goodcatch() { + value1 = 0; + value3 = 0.0; + { + ctx::continuation c = ctx::callcc( + [](ctx::continuation && c) { + Y y; + value3 = 2.; + c = c.resume(); + try { + value3 = 3.; + c = c.resume(); + } catch ( boost::context::detail::forced_unwind const&) { + value3 = 4.; + throw; + } catch (...) { + value3 = 5.; + } + value3 = 6.; + return std::move( c); + }); + BOOST_CHECK_EQUAL( 3, value1); + BOOST_CHECK_EQUAL( 2., value3); + c = c.resume(); + BOOST_CHECK_EQUAL( 3, value1); + BOOST_CHECK_EQUAL( 3., value3); + } + BOOST_CHECK_EQUAL( 7, value1); + BOOST_CHECK_EQUAL( 4., value3); +} + +void test_badcatch() { +#if 0 + value1 = 0; + value3 = 0.; + { + ctx::continuation c = ctx::callcc( + [](ctx::continuation && c) { + Y y; + try { + value3 = 3.; + c = c.resume(); + } catch (...) { + value3 = 5.; + } + return std::move( c); + }); + BOOST_CHECK_EQUAL( 3, value1); + BOOST_CHECK_EQUAL( 3., value3); + // the destruction of ctx here will cause a forced_unwind to be thrown that is not caught + // in fn19. That will trigger the "not caught" assertion in ~forced_unwind. Getting that + // assertion to propogate bak here cleanly is non-trivial, and there seems to not be a good + // way to hook directly into the assertion when it happens on an alternate stack. + std::move( c); + } + BOOST_CHECK_EQUAL( 7, value1); + BOOST_CHECK_EQUAL( 4., value3); +#endif +} + +boost::unit_test::test_suite * init_unit_test_suite( int, char* []) +{ + boost::unit_test::test_suite * test = + BOOST_TEST_SUITE("Boost.Context: callcc test suite"); + + test->add( BOOST_TEST_CASE( & test_move) ); + test->add( BOOST_TEST_CASE( & test_bind) ); + test->add( BOOST_TEST_CASE( & test_exception) ); + test->add( BOOST_TEST_CASE( & test_fp) ); + test->add( BOOST_TEST_CASE( & test_stacked) ); + test->add( BOOST_TEST_CASE( & test_prealloc) ); + test->add( BOOST_TEST_CASE( & test_ontop) ); + test->add( BOOST_TEST_CASE( & test_ontop_exception) ); + test->add( BOOST_TEST_CASE( & test_termination1) ); + test->add( BOOST_TEST_CASE( & test_termination2) ); + test->add( BOOST_TEST_CASE( & test_sscanf) ); + test->add( BOOST_TEST_CASE( & test_snprintf) ); +#ifdef BOOST_WINDOWS + test->add( BOOST_TEST_CASE( & test_bug12215) ); +#endif + test->add( BOOST_TEST_CASE( & test_goodcatch) ); + test->add( BOOST_TEST_CASE( & test_badcatch) ); + + return test; +} + +#if defined(BOOST_MSVC) +# pragma warning(pop) +#endif diff --git a/src/boost/libs/context/test/test_fcontext.cpp b/src/boost/libs/context/test/test_fcontext.cpp new file mode 100644 index 000000000..b8ae6d32a --- /dev/null +++ b/src/boost/libs/context/test/test_fcontext.cpp @@ -0,0 +1,352 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <stdio.h> +#include <stdlib.h> + +#include <cmath> +#include <cstdint> +#include <iostream> +#include <sstream> +#include <stdexcept> +#include <string> +#include <utility> + +#include <boost/array.hpp> +#include <boost/assert.hpp> +#include <boost/test/unit_test.hpp> +#include <boost/utility.hpp> + +#include <boost/context/detail/config.hpp> +#include <boost/context/detail/fcontext.hpp> + +template< std::size_t Max, std::size_t Default, std::size_t Min > +class simple_stack_allocator +{ +public: + static std::size_t maximum_stacksize() + { return Max; } + + static std::size_t default_stacksize() + { return Default; } + + static std::size_t minimum_stacksize() + { return Min; } + + void * allocate( std::size_t size) const + { + BOOST_ASSERT( minimum_stacksize() <= size); + BOOST_ASSERT( maximum_stacksize() >= size); + + void * limit = malloc( size); + if ( ! limit) throw std::bad_alloc(); + + return static_cast< char * >( limit) + size; + } + + void deallocate( void * vp, std::size_t size) const + { + BOOST_ASSERT( vp); + BOOST_ASSERT( minimum_stacksize() <= size); + BOOST_ASSERT( maximum_stacksize() >= size); + + void * limit = static_cast< char * >( vp) - size; + free( limit); + } +}; + +typedef simple_stack_allocator< + 8 * 1024 * 1024, 64 * 1024, 8 * 1024 + > stack_allocator; + +namespace ctx = boost::context::detail; + +typedef simple_stack_allocator< + 8 * 1024 * 1024, // 8MB + 64 * 1024, // 64kB + 8 * 1024 // 8kB +> stack_allocator; + +int value1 = 0; +std::string value2; +double value3 = 0.; +void * value4 = 0; + +void f1( ctx::transfer_t t) { + ++value1; + ctx::jump_fcontext( t.fctx, t.data); +} + +void f3( ctx::transfer_t t_) { + ++value1; + ctx::transfer_t t = ctx::jump_fcontext( t_.fctx, 0); + ++value1; + ctx::jump_fcontext( t.fctx, t.data); +} + +void f4( ctx::transfer_t t) { + int i = 7; + ctx::jump_fcontext( t.fctx, & i); +} + +void f5( ctx::transfer_t t) { + ctx::jump_fcontext( t.fctx, t.data); +} + +void f6( ctx::transfer_t t_) { + std::pair< int, int > data = * ( std::pair< int, int > * ) t_.data; + int res = data.first + data.second; + ctx::transfer_t t = ctx::jump_fcontext( t_.fctx, & res); + data = * ( std::pair< int, int > *) t.data; + res = data.first + data.second; + ctx::jump_fcontext( t.fctx, & res); +} + +void f7( ctx::transfer_t t) { + try { + throw std::runtime_error( * ( std::string *) t.data); + } catch ( std::runtime_error const& e) { + value2 = e.what(); + } + ctx::jump_fcontext( t.fctx, t.data); +} + +void f8( ctx::transfer_t t) { + double d = * ( double *) t.data; + d += 3.45; + value3 = d; + ctx::jump_fcontext( t.fctx, 0); +} + +void f10( ctx::transfer_t t) { + value1 = 3; + ctx::jump_fcontext( t.fctx, 0); +} + +void f9( ctx::transfer_t t) { + std::cout << "f1: entered" << std::endl; + stack_allocator alloc; + void * sp = alloc.allocate( stack_allocator::default_stacksize()); + ctx::fcontext_t ctx = ctx::make_fcontext( sp, stack_allocator::default_stacksize(), f10); + ctx::jump_fcontext( ctx, 0); + ctx::jump_fcontext( t.fctx, 0); +} + +ctx::transfer_t f11( ctx::transfer_t t_) { + value4 = t_.data; + ctx::transfer_t t = { t_.fctx, t_.data }; + return t; +} + +void f12( ctx::transfer_t t_) { + ctx::transfer_t t = ctx::jump_fcontext( t_.fctx, t_.data); + value1 = * ( int *) t.data; + ctx::jump_fcontext( t.fctx, t.data); +} + +void f13( ctx::transfer_t t) { + { + double n1 = 0; + double n2 = 0; + sscanf("3.14 7.13", "%lf %lf", & n1, & n2); + BOOST_CHECK( n1 == 3.14); + BOOST_CHECK( n2 == 7.13); + } + { + int n1=0; + int n2=0; + sscanf("1 23", "%d %d", & n1, & n2); + BOOST_CHECK( n1 == 1); + BOOST_CHECK( n2 == 23); + } + { + int n1=0; + int n2=0; + sscanf("1 jjj 23", "%d %*[j] %d", & n1, & n2); + BOOST_CHECK( n1 == 1); + BOOST_CHECK( n2 == 23); + } + ctx::jump_fcontext( t.fctx, 0); +} + +void f14( ctx::transfer_t t) { + { + const char *fmt = "sqrt(2) = %f"; + char buf[19]; + snprintf( buf, sizeof( buf), fmt, std::sqrt( 2) ); + BOOST_CHECK( 0 < sizeof( buf) ); + BOOST_CHECK_EQUAL( std::string("sqrt(2) = 1.41"), std::string( buf, 14) ); + } + { + std::uint64_t n = 0xbcdef1234567890; + const char *fmt = "0x%016llX"; + char buf[100]; + snprintf( buf, sizeof( buf), fmt, n); + BOOST_CHECK_EQUAL( std::string("0x0BCDEF1234567890"), std::string( buf, 18) ); + } + ctx::jump_fcontext( t.fctx, 0); +} + +void test_setup() { + stack_allocator alloc; + void * sp = alloc.allocate( stack_allocator::default_stacksize() ); + ctx::fcontext_t ctx = ctx::make_fcontext( sp, stack_allocator::default_stacksize(), f1); + BOOST_CHECK( ctx); + alloc.deallocate( sp, stack_allocator::default_stacksize() ); +} + +void test_start() { + value1 = 0; + stack_allocator alloc; + void * sp = alloc.allocate( stack_allocator::default_stacksize() ); + ctx::fcontext_t ctx = ctx::make_fcontext( sp, stack_allocator::default_stacksize(), f1); + BOOST_CHECK( ctx); + + BOOST_CHECK_EQUAL( 0, value1); + ctx::jump_fcontext( ctx, 0); + BOOST_CHECK_EQUAL( 1, value1); + alloc.deallocate( sp, stack_allocator::default_stacksize() ); +} + +void test_jump() { + value1 = 0; + stack_allocator alloc; + void * sp = alloc.allocate( stack_allocator::default_stacksize() ); + ctx::fcontext_t ctx = ctx::make_fcontext( sp, stack_allocator::default_stacksize(), f3); + BOOST_CHECK( ctx); + BOOST_CHECK_EQUAL( 0, value1); + ctx::transfer_t t = ctx::jump_fcontext( ctx, 0); + BOOST_CHECK_EQUAL( 1, value1); + ctx::jump_fcontext( t.fctx, 0); + BOOST_CHECK_EQUAL( 2, value1); + alloc.deallocate( sp, stack_allocator::default_stacksize() ); +} + +void test_result() { + stack_allocator alloc; + void * sp = alloc.allocate( stack_allocator::default_stacksize() ); + ctx::fcontext_t ctx = ctx::make_fcontext( sp, stack_allocator::default_stacksize(), f4); + BOOST_CHECK( ctx); + ctx::transfer_t t = ctx::jump_fcontext( ctx, 0); + int result = * ( int *) t.data; + BOOST_CHECK_EQUAL( 7, result); + alloc.deallocate( sp, stack_allocator::default_stacksize() ); +} + +void test_arg() { + stack_allocator alloc; + int i = 7; + void * sp = alloc.allocate( stack_allocator::default_stacksize() ); + ctx::fcontext_t ctx = ctx::make_fcontext( sp, stack_allocator::default_stacksize(), f5); + BOOST_CHECK( ctx); + ctx::transfer_t t = ctx::jump_fcontext( ctx, & i); + int result = * ( int *) t.data; + BOOST_CHECK_EQUAL( i, result); + alloc.deallocate( sp, stack_allocator::default_stacksize() ); +} + +void test_transfer() { + stack_allocator alloc; + std::pair< int, int > data = std::make_pair( 3, 7); + void * sp = alloc.allocate( stack_allocator::default_stacksize() ); + ctx::fcontext_t ctx = ctx::make_fcontext( sp, stack_allocator::default_stacksize(), f6); + BOOST_CHECK( ctx); + ctx::transfer_t t = ctx::jump_fcontext( ctx, & data); + int result = * ( int *) t.data; + BOOST_CHECK_EQUAL( 10, result); + data = std::make_pair( 7, 7); + t = ctx::jump_fcontext( t.fctx, & data); + result = * ( int *) t.data; + BOOST_CHECK_EQUAL( 14, result); + alloc.deallocate( sp, stack_allocator::default_stacksize() ); +} + +void test_exception() { + stack_allocator alloc; + std::string what("hello world"); + void * sp = alloc.allocate( stack_allocator::default_stacksize() ); + ctx::fcontext_t ctx = ctx::make_fcontext( sp, stack_allocator::default_stacksize(), f7); + BOOST_CHECK( ctx); + ctx::jump_fcontext( ctx, & what); + BOOST_CHECK_EQUAL( std::string( what), value2); + alloc.deallocate( sp, stack_allocator::default_stacksize() ); +} + +void test_fp() { + stack_allocator alloc; + double d = 7.13; + void * sp = alloc.allocate( stack_allocator::default_stacksize() ); + ctx::fcontext_t ctx = ctx::make_fcontext( sp, stack_allocator::default_stacksize(), f8); + BOOST_CHECK( ctx); + ctx::jump_fcontext( ctx, & d); + BOOST_CHECK_EQUAL( 10.58, value3); + alloc.deallocate( sp, stack_allocator::default_stacksize() ); +} + +void test_stacked() { + value1 = 0; + stack_allocator alloc; + void * sp = alloc.allocate( stack_allocator::default_stacksize()); + ctx::fcontext_t ctx = ctx::make_fcontext( sp, stack_allocator::default_stacksize(), f9); + ctx::jump_fcontext( ctx, 0); + BOOST_CHECK_EQUAL( 3, value1); + alloc.deallocate( sp, stack_allocator::default_stacksize() ); +} + +void test_ontop() { + value1 = 0; + value4 = 0; + stack_allocator alloc; + void * sp = alloc.allocate( stack_allocator::default_stacksize() ); + ctx::fcontext_t ctx = ctx::make_fcontext( sp, stack_allocator::default_stacksize(), f12); + BOOST_CHECK( ctx); + ctx::transfer_t t = ctx::jump_fcontext( ctx, 0); + BOOST_CHECK_EQUAL( 0, value1); + BOOST_CHECK( 0 == value4); + int i = -3; + t = ctx::ontop_fcontext( t.fctx, & i, f11); + BOOST_CHECK_EQUAL( -3, value1); + BOOST_CHECK_EQUAL( & i, value4); + BOOST_CHECK_EQUAL( -3, * ( int *) t.data); + BOOST_CHECK_EQUAL( & i, ( int *) t.data); + alloc.deallocate( sp, stack_allocator::default_stacksize() ); +} + +void test_sscanf() { + stack_allocator alloc; + void * sp = alloc.allocate( stack_allocator::default_stacksize() ); + ctx::fcontext_t ctx = ctx::make_fcontext( sp, stack_allocator::default_stacksize(), f13); + BOOST_CHECK( ctx); + ctx::jump_fcontext( ctx, 0); + alloc.deallocate( sp, stack_allocator::default_stacksize() ); +} + +void test_snprintf() { + stack_allocator alloc; + void * sp = alloc.allocate( stack_allocator::default_stacksize() ); + ctx::fcontext_t ctx = ctx::make_fcontext( sp, stack_allocator::default_stacksize(), f14); + ctx::jump_fcontext( ctx, 0); + alloc.deallocate( sp, stack_allocator::default_stacksize() ); +} + +boost::unit_test::test_suite * init_unit_test_suite( int, char* []) { + boost::unit_test::test_suite * test = + BOOST_TEST_SUITE("Boost.Context: fcontext test suite"); + test->add( BOOST_TEST_CASE( & test_setup) ); + test->add( BOOST_TEST_CASE( & test_start) ); + test->add( BOOST_TEST_CASE( & test_jump) ); + test->add( BOOST_TEST_CASE( & test_result) ); + test->add( BOOST_TEST_CASE( & test_arg) ); + test->add( BOOST_TEST_CASE( & test_transfer) ); + test->add( BOOST_TEST_CASE( & test_exception) ); + test->add( BOOST_TEST_CASE( & test_fp) ); + test->add( BOOST_TEST_CASE( & test_stacked) ); + test->add( BOOST_TEST_CASE( & test_ontop) ); + test->add( BOOST_TEST_CASE( & test_sscanf) ); + test->add( BOOST_TEST_CASE( & test_snprintf) ); + + return test; +} diff --git a/src/boost/libs/context/test/test_fiber.cpp b/src/boost/libs/context/test/test_fiber.cpp new file mode 100644 index 000000000..e883d1435 --- /dev/null +++ b/src/boost/libs/context/test/test_fiber.cpp @@ -0,0 +1,538 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <stdio.h> +#include <stdlib.h> + +#include <cmath> +#include <cstdint> +#include <cstdio> +#include <iostream> +#include <memory> +#include <sstream> +#include <stdexcept> +#include <string> +#include <thread> +#include <utility> +#include <vector> + +#include <boost/array.hpp> +#include <boost/assert.hpp> +#include <boost/lexical_cast.hpp> +#include <boost/test/unit_test.hpp> +#include <boost/utility.hpp> +#include <boost/variant.hpp> + +#include <boost/context/fiber.hpp> +#include <boost/context/detail/config.hpp> + +#ifdef BOOST_WINDOWS +#include <windows.h> +#endif + +#if defined(BOOST_MSVC) +# pragma warning(push) +# pragma warning(disable: 4702 4723 4996) +#endif + +typedef boost::variant<int,std::string> variant_t; + +namespace ctx = boost::context; + +int value1 = 0; +std::string value2; +double value3 = 0.; + +struct X { + ctx::fiber foo( ctx::fiber && f, int i) { + value1 = i; + return std::move( f); + } +}; + +struct Y { + Y() { + value1 = 3; + } + + Y( Y const&) = delete; + Y & operator=( Y const&) = delete; + + ~Y() { + value1 = 7; + } +}; + +class moveable { +public: + bool state; + int value; + + moveable() : + state( false), + value( -1) { + } + + moveable( int v) : + state( true), + value( v) { + } + + moveable( moveable && other) : + state( other.state), + value( other.value) { + other.state = false; + other.value = -1; + } + + moveable & operator=( moveable && other) { + if ( this == & other) return * this; + state = other.state; + value = other.value; + other.state = false; + other.value = -1; + return * this; + } + + moveable( moveable const& other) = delete; + moveable & operator=( moveable const& other) = delete; + + void operator()() { + value1 = value; + } +}; + +struct my_exception : public std::runtime_error { + ctx::fiber f; + my_exception( ctx::fiber && f_, char const* what) : + std::runtime_error( what), + f{ std::move( f_) } { + } +}; + +#ifdef BOOST_MSVC +// Optimizations can remove the integer-divide-by-zero here. +#pragma optimize("", off) +void seh( bool & catched) { + __try { + int i = 1; + i /= 0; + } __except( EXCEPTION_EXECUTE_HANDLER) { + catched = true; + } +} +#pragma optimize("", on) +#endif + +void test_move() { + value1 = 0; + int i = 1; + BOOST_CHECK_EQUAL( 0, value1); + ctx::fiber f1{ + [&i](ctx::fiber && f) { + value1 = i; + f = std::move( f).resume(); + value1 = i; + return std::move( f); + }}; + f1 = std::move( f1).resume(); + BOOST_CHECK_EQUAL( 1, value1); + BOOST_CHECK( f1); + ctx::fiber f2; + BOOST_CHECK( ! f2); + f2 = std::move( f1); + BOOST_CHECK( ! f1); + BOOST_CHECK( f2); + i = 3; + f2 = std::move( f2).resume(); + BOOST_CHECK_EQUAL( 3, value1); + BOOST_CHECK( ! f1); + BOOST_CHECK( ! f2); +} + +void test_bind() { + value1 = 0; + X x; + ctx::fiber f{ std::bind( & X::foo, x, std::placeholders::_1, 7) }; + f = std::move( f).resume(); + BOOST_CHECK_EQUAL( 7, value1); +} + +void test_exception() { + { + const char * what = "hello world"; + ctx::fiber f{ + [&what](ctx::fiber && f) { + try { + throw std::runtime_error( what); + } catch ( std::runtime_error const& e) { + value2 = e.what(); + } + return std::move( f); + }}; + f = std::move( f).resume(); + BOOST_CHECK_EQUAL( std::string( what), value2); + BOOST_CHECK( ! f); + } +#ifdef BOOST_MSVC + { + bool catched = false; + std::thread([&catched](){ + ctx::fiber f{ [&catched](ctx::fiber && f){ + seh( catched); + return std::move( f); + }}; + BOOST_CHECK( f); + f = std::move( f).resume(); + }).join(); + BOOST_CHECK( catched); + } +#endif +} + +void test_fp() { + value3 = 0.; + double d = 7.13; + ctx::fiber f{ + [&d]( ctx::fiber && f) { + d += 3.45; + value3 = d; + return std::move( f); + }}; + f = std::move( f).resume(); + BOOST_CHECK_EQUAL( 10.58, value3); + BOOST_CHECK( ! f); +} + +void test_stacked() { + value1 = 0; + value3 = 0.; + ctx::fiber f{ + [](ctx::fiber && f) { + ctx::fiber f1{ + [](ctx::fiber && f) { + value1 = 3; + return std::move( f); + }}; + f1 = std::move( f1).resume(); + value3 = 3.14; + return std::move( f); + }}; + f = std::move( f).resume(); + BOOST_CHECK_EQUAL( 3, value1); + BOOST_CHECK_EQUAL( 3.14, value3); + BOOST_CHECK( ! f); +} + +void test_prealloc() { + value1 = 0; + ctx::default_stack alloc; + ctx::stack_context sctx( alloc.allocate() ); + void * sp = static_cast< char * >( sctx.sp) - 10; + std::size_t size = sctx.size - 10; + int i = 7; + ctx::fiber f{ + std::allocator_arg, ctx::preallocated( sp, size, sctx), alloc, + [&i]( ctx::fiber && f) { + value1 = i; + return std::move( f); + }}; + f = std::move( f).resume(); + BOOST_CHECK_EQUAL( 7, value1); + BOOST_CHECK( ! f); +} + +void test_ontop() { + { + int i = 3; + ctx::fiber f{ [&i](ctx::fiber && f) { + for (;;) { + i *= 10; + f = std::move( f).resume(); + } + return std::move( f); + }}; + f = std::move( f).resume(); + // Pass fn by reference to see if the types are properly decayed. + auto fn = [&i](ctx::fiber && f){ + i -= 10; + return std::move( f); + }; + f = std::move( f).resume_with(fn); + BOOST_CHECK( f); + BOOST_CHECK_EQUAL( i, 200); + } + { + ctx::fiber f1; + ctx::fiber f{ [&f1](ctx::fiber && f) { + f = std::move( f).resume(); + BOOST_CHECK( ! f); + return std::move( f1); + }}; + f = std::move( f).resume(); + f = std::move( f).resume_with( + [&f1](ctx::fiber && f){ + f1 = std::move( f); + return std::move( f); + }); + } +} + +void test_ontop_exception() { + value1 = 0; + value2 = ""; + ctx::fiber f{ [](ctx::fiber && f){ + for (;;) { + value1 = 3; + try { + f = std::move( f).resume(); + } catch ( my_exception & ex) { + value2 = ex.what(); + return std::move( ex.f); + } + } + return std::move( f); + }}; + f = std::move( f).resume(); + BOOST_CHECK_EQUAL( 3, value1); + const char * what = "hello world"; + f = std::move( f).resume_with( + [what](ctx::fiber && f){ + throw my_exception( std::move( f), what); + return std::move( f); + }); + BOOST_CHECK_EQUAL( 3, value1); + BOOST_CHECK_EQUAL( std::string( what), value2); +} + +void test_termination1() { + { + value1 = 0; + ctx::fiber f{ + [](ctx::fiber && f){ + Y y; + f = std::move( f).resume(); + return std::move(f); + }}; + f = std::move( f).resume(); + BOOST_CHECK_EQUAL( 3, value1); + } + BOOST_CHECK_EQUAL( 7, value1); + { + value1 = 0; + BOOST_CHECK_EQUAL( 0, value1); + ctx::fiber f{ + [](ctx::fiber && f) { + value1 = 3; + return std::move( f); + }}; + f = std::move( f).resume(); + BOOST_CHECK_EQUAL( 3, value1); + BOOST_CHECK( ! f); + } + { + value1 = 0; + BOOST_CHECK_EQUAL( 0, value1); + int i = 3; + ctx::fiber f{ + [&i](ctx::fiber && f){ + value1 = i; + f = std::move( f).resume(); + value1 = i; + return std::move( f); + }}; + f = std::move( f).resume(); + BOOST_CHECK( f); + BOOST_CHECK_EQUAL( i, value1); + BOOST_CHECK( f); + i = 7; + f = std::move( f).resume(); + BOOST_CHECK( ! f); + BOOST_CHECK_EQUAL( i, value1); + } +} + +void test_termination2() { + { + value1 = 0; + value3 = 0.0; + ctx::fiber f{ + [](ctx::fiber && f){ + Y y; + value1 = 3; + value3 = 4.; + f = std::move( f).resume(); + value1 = 7; + value3 = 8.; + f = std::move( f).resume(); + return std::move( f); + }}; + BOOST_CHECK_EQUAL( 0, value1); + BOOST_CHECK_EQUAL( 0., value3); + f = std::move( f).resume(); + BOOST_CHECK_EQUAL( 3, value1); + BOOST_CHECK_EQUAL( 4., value3); + f = std::move( f).resume(); + } + BOOST_CHECK_EQUAL( 7, value1); + BOOST_CHECK_EQUAL( 8., value3); +} + +void test_sscanf() { + ctx::fiber{ + []( ctx::fiber && f) { + { + double n1 = 0; + double n2 = 0; + sscanf("3.14 7.13", "%lf %lf", & n1, & n2); + BOOST_CHECK( n1 == 3.14); + BOOST_CHECK( n2 == 7.13); + } + { + int n1=0; + int n2=0; + sscanf("1 23", "%d %d", & n1, & n2); + BOOST_CHECK( n1 == 1); + BOOST_CHECK( n2 == 23); + } + { + int n1=0; + int n2=0; + sscanf("1 jjj 23", "%d %*[j] %d", & n1, & n2); + BOOST_CHECK( n1 == 1); + BOOST_CHECK( n2 == 23); + } + return std::move( f); + }}.resume(); +} + +void test_snprintf() { + ctx::fiber{ + []( ctx::fiber && f) { + { + const char *fmt = "sqrt(2) = %f"; + char buf[19]; + snprintf( buf, sizeof( buf), fmt, std::sqrt( 2) ); + BOOST_CHECK( 0 < sizeof( buf) ); + BOOST_ASSERT( std::string("sqrt(2) = 1.41") == std::string( buf, 14) ); + } + { + std::uint64_t n = 0xbcdef1234567890; + const char *fmt = "0x%016llX"; + char buf[100]; + snprintf( buf, sizeof( buf), fmt, n); + BOOST_ASSERT( std::string("0x0BCDEF1234567890") == std::string( buf, 18) ); + } + return std::move( f); + }}.resume(); +} + +#ifdef BOOST_WINDOWS +void test_bug12215() { + ctx::fiber{ + [](ctx::fiber && f) { + char buffer[MAX_PATH]; + GetModuleFileName( nullptr, buffer, MAX_PATH); + return std::move( f); + }}.resume(); +} +#endif + +void test_goodcatch() { + value1 = 0; + value3 = 0.0; + { + ctx::fiber f{ + []( ctx::fiber && f) { + Y y; + value3 = 2.; + f = std::move( f).resume(); + try { + value3 = 3.; + f = std::move( f).resume(); + } catch ( boost::context::detail::forced_unwind const&) { + value3 = 4.; + throw; + } catch (...) { + value3 = 5.; + } + value3 = 6.; + return std::move( f); + }}; + BOOST_CHECK_EQUAL( 0, value1); + BOOST_CHECK_EQUAL( 0., value3); + f = std::move( f).resume(); + BOOST_CHECK_EQUAL( 3, value1); + BOOST_CHECK_EQUAL( 2., value3); + f = std::move( f).resume(); + BOOST_CHECK_EQUAL( 3, value1); + BOOST_CHECK_EQUAL( 3., value3); + } + BOOST_CHECK_EQUAL( 7, value1); + BOOST_CHECK_EQUAL( 4., value3); +} + +void test_badcatch() { +#if 0 + value1 = 0; + value3 = 0.; + { + ctx::fiber f{ + []( ctx::fiber && f) { + Y y; + try { + value3 = 3.; + f = std::move( f).resume(); + } catch (...) { + value3 = 5.; + } + return std::move( f); + }}; + BOOST_CHECK_EQUAL( 0, value1); + BOOST_CHECK_EQUAL( 0., value3); + f = std::move( f).resume(); + BOOST_CHECK_EQUAL( 3, value1); + BOOST_CHECK_EQUAL( 3., value3); + // the destruction of ctx here will cause a forced_unwind to be thrown that is not caught + // in fn19. That will trigger the "not caught" assertion in ~forced_unwind. Getting that + // assertion to propogate bak here cleanly is non-trivial, and there seems to not be a good + // way to hook directly into the assertion when it happens on an alternate stack. + std::move( f); + } + BOOST_CHECK_EQUAL( 7, value1); + BOOST_CHECK_EQUAL( 4., value3); +#endif +} + +boost::unit_test::test_suite * init_unit_test_suite( int, char* []) +{ + boost::unit_test::test_suite * test = + BOOST_TEST_SUITE("Boost.Context: fiber test suite"); + + test->add( BOOST_TEST_CASE( & test_move) ); + test->add( BOOST_TEST_CASE( & test_bind) ); + test->add( BOOST_TEST_CASE( & test_exception) ); + test->add( BOOST_TEST_CASE( & test_fp) ); + test->add( BOOST_TEST_CASE( & test_stacked) ); + test->add( BOOST_TEST_CASE( & test_prealloc) ); + test->add( BOOST_TEST_CASE( & test_ontop) ); + test->add( BOOST_TEST_CASE( & test_ontop_exception) ); + test->add( BOOST_TEST_CASE( & test_termination1) ); + test->add( BOOST_TEST_CASE( & test_termination2) ); + test->add( BOOST_TEST_CASE( & test_sscanf) ); + test->add( BOOST_TEST_CASE( & test_snprintf) ); +#ifdef BOOST_WINDOWS + test->add( BOOST_TEST_CASE( & test_bug12215) ); +#endif + test->add( BOOST_TEST_CASE( & test_goodcatch) ); + test->add( BOOST_TEST_CASE( & test_badcatch) ); + + return test; +} + +#if defined(BOOST_MSVC) +# pragma warning(pop) +#endif diff --git a/src/boost/libs/context/test/test_invoke.cpp b/src/boost/libs/context/test/test_invoke.cpp new file mode 100644 index 000000000..c8c0b08ab --- /dev/null +++ b/src/boost/libs/context/test/test_invoke.cpp @@ -0,0 +1,233 @@ + +// Copyright Oliver Kowalke 2009. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <iostream> +#include <memory> +#include <sstream> +#include <stdexcept> +#include <string> +#include <tuple> +#include <utility> + +#include <boost/assert.hpp> +#include <boost/test/unit_test.hpp> + +#include <boost/context/detail/invoke.hpp> +#include <boost/context/detail/config.hpp> + +namespace ctx = boost::context; + +struct callable { + int k{ 0 }; + + callable() = default; + + callable( int k_) : + k{ k_ } { + } + + int foo( int i, int j) const { + return i + j + k; + } + + int operator()( int i, int j) const { + return foo( i, j); + } +}; + +struct movable { + int k{ 0 }; + + movable() = default; + + movable( int k_) : + k{ k_ } { + } + + movable( movable const&) = delete; + movable & operator=( movable const&) = delete; + + movable( movable && other) : + k{ other.k } { + other.k = -1; + } + + movable & operator=( movable && other) { + if ( this == & other) return * this; + k = other.k; + other.k = -1; + return * this; + } + + int foo( int i, int j) const { + return i + j + k; + } + + int operator()( int i, int j) const { + return foo( i, j); + } +}; + +int fn1( int i, int j) { + return i + j; +} + +int * fn2( int * ip) { + return ip; +} + +int * fn3( int & ir) { + return & ir; +} + +int & fn4( int & ir) { + return ir; +} + +template< typename T > +int fn5( int i, T && t_) { + T t = std::forward< T >( t_); + return i + t.k; +} + +void test1() { + int result = ctx::detail::invoke( fn1, 1, 2); + BOOST_CHECK_EQUAL( result, 3); +} + +void test2() { + { + int i = 3; + int * ip = & i; + int * result = ctx::detail::invoke( fn2, ip); + BOOST_CHECK_EQUAL( result, ip); + BOOST_CHECK_EQUAL( * result, i); + } + { + int i = 3; + int * result = ctx::detail::invoke( fn2, & i); + BOOST_CHECK_EQUAL( result, & i); + BOOST_CHECK_EQUAL( * result, i); + } +} + +void test3() { + { + int i = 3; + int & ir = i; + int * result = ctx::detail::invoke( fn3, ir); + BOOST_CHECK_EQUAL( result, & ir); + BOOST_CHECK_EQUAL( * result, i); + } + { + int i = 3; + int * result = ctx::detail::invoke( fn3, i); + BOOST_CHECK_EQUAL( result, & i); + BOOST_CHECK_EQUAL( * result, i); + } +} + +void test4() { + { + int i = 3; + int & ir = i; + int & result = ctx::detail::invoke( fn4, ir); + BOOST_CHECK_EQUAL( result, ir); + BOOST_CHECK_EQUAL( & result, & ir); + BOOST_CHECK_EQUAL( result, i); + } + { + int i = 3; + int & result = ctx::detail::invoke( fn4, i); + BOOST_CHECK_EQUAL( & result, & i); + BOOST_CHECK_EQUAL( result, i); + } +} + +void test5() { + { + callable c( 5); + int result = ctx::detail::invoke( fn5< callable >, 1, std::move( c) ); + BOOST_CHECK_EQUAL( result, 6); + BOOST_CHECK_EQUAL( c.k, 5); + } + { + movable m( 5); + int result = ctx::detail::invoke( fn5< movable >, 1, std::move( m) ); + BOOST_CHECK_EQUAL( result, 6); + BOOST_CHECK_EQUAL( m.k, -1); + } +} + +void test6() { + { + callable c; + int result = ctx::detail::invoke( c, 1, 2); + BOOST_CHECK_EQUAL( result, 3); + BOOST_CHECK_EQUAL( c.k, 0); + } + { + callable c; + int result = ctx::detail::invoke( & callable::foo, c, 1, 2); + BOOST_CHECK_EQUAL( result, 3); + BOOST_CHECK_EQUAL( c.k, 0); + } +} + +void test7() { + { + int result = ctx::detail::invoke( movable{}, 1, 2); + BOOST_CHECK_EQUAL( result, 3); + } + { + int result = ctx::detail::invoke( & movable::foo, movable{}, 1, 2); + BOOST_CHECK_EQUAL( result, 3); + } +} + +template< typename R, typename Fn, typename ... Args > +R apply( Fn && fn, Args && ... args) { + return ctx::detail::invoke( + std::forward< Fn >( fn), + std::forward< Args >( args) ... ); +} + +void test8() { + { + int result = apply< int >( fn1, 1, 2); + BOOST_CHECK_EQUAL( result, 3); + } + { + int i = 3; + int & ir = i; + int * result = apply< int * >( fn3, ir); + BOOST_CHECK_EQUAL( result, & ir); + BOOST_CHECK_EQUAL( * result, i); + } + { + movable m( 5); + int result = apply< int >( fn5< movable >, 1, std::move( m) ); + BOOST_CHECK_EQUAL( result, 6); + BOOST_CHECK_EQUAL( m.k, -1); + } +} + +boost::unit_test::test_suite * init_unit_test_suite( int, char* []) +{ + boost::unit_test::test_suite * test = + BOOST_TEST_SUITE("Boost.Context: invoke test suite"); + + test->add( BOOST_TEST_CASE( & test1) ); + test->add( BOOST_TEST_CASE( & test2) ); + test->add( BOOST_TEST_CASE( & test3) ); + test->add( BOOST_TEST_CASE( & test4) ); + test->add( BOOST_TEST_CASE( & test5) ); + test->add( BOOST_TEST_CASE( & test6) ); + test->add( BOOST_TEST_CASE( & test7) ); + test->add( BOOST_TEST_CASE( & test8) ); + + return test; +} |