├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── COPYING ├── README.md ├── appveyor.yml ├── cmake ├── linux_i386_toolchain.cmake └── unix_i386_toolchain.cmake ├── include └── sewing.h ├── src ├── asm │ ├── jump_arm64_aapcs_elf_gas.S │ ├── jump_arm64_aapcs_macho_gas.S │ ├── jump_arm_aapcs_elf_gas.S │ ├── jump_arm_aapcs_macho_gas.S │ ├── jump_arm_aapcs_pe_armasm.asm │ ├── jump_combined_sysv_macho_gas.S │ ├── jump_i386_ms_pe_gas.asm │ ├── jump_i386_ms_pe_masm.asm │ ├── jump_i386_sysv_elf_gas.S │ ├── jump_i386_sysv_macho_gas.S │ ├── jump_i386_x86_64_sysv_macho_gas.S │ ├── jump_mips32_o32_elf_gas.S │ ├── jump_ppc32_ppc64_sysv_macho_gas.S │ ├── jump_ppc32_sysv_elf_gas.S │ ├── jump_ppc32_sysv_macho_gas.S │ ├── jump_ppc32_sysv_xcoff_gas.S │ ├── jump_ppc64_sysv_elf_gas.S │ ├── jump_ppc64_sysv_macho_gas.S │ ├── jump_ppc64_sysv_xcoff_gas.S │ ├── jump_sparc64_sysv_elf_gas.S │ ├── jump_sparc_sysv_elf_gas.S │ ├── jump_x86_64_ms_pe_gas.asm │ ├── jump_x86_64_ms_pe_masm.asm │ ├── jump_x86_64_sysv_elf_gas.S │ ├── jump_x86_64_sysv_macho_gas.S │ ├── make_arm64_aapcs_elf_gas.S │ ├── make_arm64_aapcs_macho_gas.S │ ├── make_arm_aapcs_elf_gas.S │ ├── make_arm_aapcs_macho_gas.S │ ├── make_arm_aapcs_pe_armasm.asm │ ├── make_combined_sysv_macho_gas.S │ ├── make_i386_ms_pe_gas.asm │ ├── make_i386_ms_pe_masm.asm │ ├── make_i386_sysv_elf_gas.S │ ├── make_i386_sysv_macho_gas.S │ ├── make_i386_x86_64_sysv_macho_gas.S │ ├── make_mips32_o32_elf_gas.S │ ├── make_ppc32_ppc64_sysv_macho_gas.S │ ├── make_ppc32_sysv_elf_gas.S │ ├── make_ppc32_sysv_macho_gas.S │ ├── make_ppc32_sysv_xcoff_gas.S │ ├── make_ppc64_sysv_elf_gas.S │ ├── make_ppc64_sysv_macho_gas.S │ ├── make_ppc64_sysv_xcoff_gas.S │ ├── make_sparc64_sysv_elf_gas.S │ ├── make_sparc_sysv_elf_gas.S │ ├── make_x86_64_ms_pe_gas.asm │ ├── make_x86_64_ms_pe_masm.asm │ ├── make_x86_64_sysv_elf_gas.S │ └── make_x86_64_sysv_macho_gas.S ├── fcontext.h └── sewing.c └── test └── sewing_test.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | *.su 34 | 35 | # Working Directories 36 | *.user 37 | b-* 38 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Richard Maxwell 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | # SOFTWARE. 20 | 21 | # Use Ubuntu 14.04 22 | sudo: required 23 | dist: trusty 24 | 25 | language: c 26 | 27 | # Supporting non-standard gcc/clang taken from 28 | # http://genbattle.bitbucket.org/blog/2016/01/17/c++-travis-ci/ 29 | 30 | matrix: 31 | include: 32 | - os: osx 33 | osx_image: xcode7.3 34 | compiler: clang 35 | env: MY_CC=clang MY_CXX=clang++ 36 | before_install: 37 | - brew update 38 | - brew install ninja 39 | 40 | - os: osx 41 | osx_image: xcode7.3 42 | compiler: clang 43 | env: MY_CC=clang MY_CXX=clang++ CMAKE_OPTIONS="-DCMAKE_TOOLCHAIN_FILE=../cmake/unix_i386_toolchain.cmake" 44 | before_install: 45 | - brew update 46 | - brew install ninja 47 | 48 | - os: linux 49 | compiler: gcc 50 | addons: 51 | apt: 52 | sources: 53 | - ubuntu-toolchain-r-test 54 | packages: 55 | - gcc-5 56 | - g++-5 57 | - ninja-build 58 | env: MY_CC=gcc-5 MY_CXX=g++-5 59 | 60 | - os: linux 61 | compiler: gcc 62 | addons: 63 | apt: 64 | sources: 65 | - ubuntu-toolchain-r-test 66 | packages: 67 | - gcc-5-multilib 68 | - g++-5-multilib 69 | - ninja-build 70 | env: MY_CC=gcc-5 MY_CXX=g++-5 CMAKE_OPTIONS="-DCMAKE_TOOLCHAIN_FILE=../cmake/unix_i386_toolchain.cmake" 71 | 72 | - os: linux 73 | compiler: clang 74 | addons: 75 | apt: 76 | sources: 77 | - ubuntu-toolchain-r-test 78 | - llvm-toolchain-precise-3.7 79 | packages: 80 | - clang-3.7 81 | - ninja-build 82 | env: MY_CC=clang-3.7 MY_CXX=clang++-3.7 83 | 84 | - os: linux 85 | compiler: clang 86 | addons: 87 | apt: 88 | sources: 89 | - ubuntu-toolchain-r-test 90 | - llvm-toolchain-precise-3.7 91 | packages: 92 | - clang-3.7 93 | - ninja-build 94 | - gcc-multilib 95 | - g++-multilib 96 | env: MY_CC=clang-3.7 MY_CXX=clang++-3.7 CMAKE_OPTIONS="-DCMAKE_TOOLCHAIN_FILE=../cmake/unix_i386_toolchain.cmake" 97 | 98 | script: 99 | - mkdir build 100 | - cd build 101 | - CC=$MY_CC CXX=$MY_CXX cmake ../ -G Ninja $CMAKE_OPTIONS 102 | - ninja 103 | - file ./sewing_test 104 | - ctest --timeout 60 105 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Richard Maxwell 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | # SOFTWARE. 20 | 21 | # ------------------------------------------------------------------------------ 22 | # sewing library 23 | # ------------------------------------------------------------------------------ 24 | 25 | # ========================================= 26 | # Possible support matrix (from Boost 1.60) 27 | # ========================================= 28 | 29 | # Arch | Linux(unix) | Windows | MacOS X | iOS 30 | # =======|====================|============|===============|=============== 31 | # arm32 | AAPCS / ELF | AAPCS / PE | - | AAPCS / MACH-O 32 | # arm64 | AAPCS / ELF | - | - | AAPCS / MACH-O 33 | # i386 | SYSV / ELF | MS / PE | SYSV / MACH-O | - 34 | # mip1 | O32 / ELF | - | - | - 35 | # ppc32 | SYSV / ELF,XCOFF | - | SYSV / MACH-O | - 36 | # ppc64 | SYSV / ELF,XCOFF | - | SYSV / MACH-O | - 37 | # sparc | - | - | - | - 38 | # x86_64 | SYSV,X32 / ELF | MS / PE | SYSV / MACH-O | - 39 | 40 | # arch names: arm, aarch64, mips64el, mipsel, x86, x86_64 41 | 42 | set(PROJECT_NAME_SEWING "sewing") 43 | project(${PROJECT_NAME_SEWING}) 44 | 45 | cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) 46 | 47 | # ------------------------------------------------------------------------------ 48 | 49 | set(sewing_use_cxx_11 OFF CACHE BOOL "Build C++11 instead of C11.") 50 | set(sewing_use_hwloc OFF CACHE BOOL "Test: Bind threads to cores (hwloc).") 51 | set(sewing_use_valgrind OFF CACHE BOOL "Build valgrind friendly library.") 52 | set(sewing_guard_page "0" CACHE STRING "Stack guard page size (bytes).") 53 | 54 | if (sewing_use_cxx_11) 55 | enable_language(CXX) 56 | set(sewing_language "CXX") 57 | else() 58 | enable_language(C) 59 | set(sewing_language "C") 60 | endif() 61 | 62 | # ------------------------------------------------------------------------------ 63 | 64 | if (WIN32) 65 | enable_language(ASM_MASM) 66 | else() 67 | enable_language(ASM) 68 | endif() 69 | 70 | # ------------------------------------------------------------------------------ 71 | 72 | if (UNIX) 73 | Find_Package(Threads REQUIRED) 74 | if (NOT THREADS_FOUND) 75 | message(FATAL_ERROR "Threading Library not found!") 76 | endif() 77 | 78 | set(sewing_dependencies ${CMAKE_THREAD_LIBS_INIT}) 79 | endif() 80 | 81 | # ------------------------------------------------------------------------------ 82 | 83 | if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") 84 | set(sewing_platform "x86_64") 85 | endif() 86 | 87 | if (CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") 88 | set(sewing_platform "x86_64") 89 | endif() 90 | 91 | if (CMAKE_SYSTEM_PROCESSOR STREQUAL "i386") 92 | set(sewing_platform "i386") 93 | endif() 94 | 95 | if (sewing_platform STREQUAL "x86_64") 96 | if("${CMAKE_SIZEOF_VOID_P}" EQUAL "4") 97 | set(sewing_platform "i386") 98 | endif() 99 | endif() 100 | 101 | if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm") 102 | if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") 103 | set(sewing_platform "arm64") 104 | else() 105 | set(sewing_platform "arm") 106 | endif() 107 | 108 | set(sewing_os "aapcs") 109 | endif() 110 | 111 | if (WIN32) 112 | if (sewing_platform STREQUAL "x86_64") 113 | set(WINXXBITS Win64) 114 | else() 115 | set(WINXXBITS Win32) 116 | endif() 117 | 118 | if (NOT sewing_os) 119 | set(sewing_os "ms") 120 | endif() 121 | 122 | set(sewing_abi "pe") 123 | 124 | if (MSVC) 125 | set(sewing_asm "masm.asm") 126 | endif() 127 | elseif(APPLE) 128 | set(sewing_os "sysv") 129 | set(sewing_abi "macho") 130 | set(sewing_asm "gas.S") 131 | elseif(UNIX) 132 | if (NOT sewing_os) 133 | set(sewing_os "sysv") 134 | endif() 135 | 136 | set(sewing_abi "elf") 137 | set(sewing_asm "gas.S") 138 | endif() 139 | 140 | # ------------------------------------------------------------------------------ 141 | 142 | if (WIN32) 143 | if (sewing_use_cxx_11) 144 | set(CMAKE_EXE_LINKER_FLAGS "/SAFESEH:NO") 145 | endif() 146 | endif() 147 | 148 | # ------------------------------------------------------------------------------ 149 | 150 | message("-- System processor: ${CMAKE_SYSTEM_PROCESSOR}") 151 | message("-- Target processor: ${sewing_platform}") 152 | message("-- Target asm : ${sewing_platform}-${sewing_os}-${sewing_abi}-${sewing_asm}") 153 | 154 | # ------------------------------------------------------------------------------ 155 | 156 | if (NOT sewing_platform) 157 | message(FATAL_ERROR "Platform not supported.") 158 | endif() 159 | 160 | if (NOT sewing_os) 161 | message(FATAL_ERROR "OS not supported.") 162 | endif() 163 | 164 | if (NOT sewing_abi) 165 | message(FATAL_ERROR "ABI not supported.") 166 | endif() 167 | 168 | if (NOT sewing_asm) 169 | message(FATAL_ERROR "assembler not supported.") 170 | endif() 171 | 172 | # ------------------------------------------------------------------------------ 173 | 174 | set(ASM_SOURCES 175 | src/asm/make_${sewing_platform}_${sewing_os}_${sewing_abi}_${sewing_asm} 176 | src/asm/jump_${sewing_platform}_${sewing_os}_${sewing_abi}_${sewing_asm} 177 | src/fcontext.h) 178 | 179 | # ------------------------------------------------------------------------------ 180 | 181 | include_directories(${CMAKE_SOURCE_DIR}/include) 182 | 183 | set(SEWING_SOURCE 184 | README.md 185 | include/sewing.h 186 | src/sewing.c) 187 | 188 | # Oh comon cmake, why would you mark a .md file as compilable? 189 | set_source_files_properties("README.md" PROPERTIES HEADER_FILE_ONLY TRUE) 190 | 191 | set_source_files_properties(${SEWING_SOURCE} 192 | PROPERTIES LANGUAGE ${sewing_language}) 193 | 194 | add_library( 195 | ${PROJECT_NAME_SEWING} 196 | STATIC 197 | ${ASM_SOURCES} 198 | ${SEWING_SOURCE}) 199 | 200 | if (sewing_dependencies) 201 | target_link_libraries(${PROJECT_NAME_SEWING} ${sewing_dependencies}) 202 | endif() 203 | 204 | if (sewing_use_cxx_11) 205 | set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) 206 | set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) 207 | else() 208 | set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11) 209 | set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD_REQUIRED ON) 210 | endif() 211 | 212 | if (sewing_use_valgrind) 213 | add_definitions(-DSEW_VALGRIND=1) 214 | endif() 215 | 216 | if (WIN32) 217 | add_definitions(-DWIN32_LEAN_AND_MEAN) 218 | endif() 219 | 220 | add_definitions(-DSEW_STACK_GUARD=${sewing_guard_page}) 221 | 222 | # ------------------------------------------------------------------------------ 223 | 224 | set(PROJECT_NAME "sewing_test") 225 | project(${PROJECT_NAME} C) 226 | 227 | set(SOURCES_EXAMPLE 228 | test/sewing_test.c) 229 | 230 | add_executable( 231 | ${PROJECT_NAME} 232 | ${SOURCES_EXAMPLE}) 233 | 234 | target_link_libraries(${PROJECT_NAME} sewing) 235 | 236 | set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 99) 237 | set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD_REQUIRED ON) 238 | 239 | if (sewing_use_hwloc) 240 | find_path(HWLOC_PATH hwloc.h) 241 | find_library(HWLOC_LIB NAMES hwloc libhwloc) 242 | 243 | if (HWLOC_PATH-NOTFOUND) 244 | message(FATAL_ERROR "Cannot find hwloc.h") 245 | endif() 246 | 247 | if (HWLOC_LIB-NOTFOUND) 248 | message(FATAL_ERROR "Cannot find the hwloc library") 249 | endif() 250 | 251 | add_definitions(-DSEW_DEMO_USE_HWLOC=1) 252 | include_directories(${HWLOC_PATH}) 253 | target_link_libraries(${PROJECT_NAME} ${HWLOC_LIB}) 254 | endif() 255 | 256 | enable_testing() 257 | add_test(${PROJECT_NAME} ${PROJECT_NAME}) 258 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | The "sewing" code is released under the MIT license (see full text below). 2 | The "sewing" files under the directory src/asm are released under the BOOST v1.0 3 | license which can be found at http://www.boost.org/LICENSE_1_0.txt 4 | 5 | -------------------------------------------------------------------------------- 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Richard Maxwell 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | # SOFTWARE. 20 | 21 | os: Visual Studio 2015 22 | clone_folder: c:\projects\sewing 23 | 24 | configuration: Release 25 | 26 | environment: 27 | matrix: 28 | - VS_GENERATOR: "Visual Studio 14 2015 Win64" 29 | - VS_GENERATOR: "Visual Studio 14 2015" 30 | 31 | build: 32 | 33 | build_script: 34 | - cmd: cd "c:\projects\sewing" 35 | - cmd: mkdir build 36 | - cmd: cd build 37 | - cmd: cmake cmake -Dsewing_use_cxx_11=ON ../ -G"%VS_GENERATOR%" 38 | - cmd: msbuild /m /p:Configuration=Release sewing_test.sln 39 | - cmd: ctest --timeout 60 40 | -------------------------------------------------------------------------------- /cmake/linux_i386_toolchain.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Richard Maxwell 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | # SOFTWARE. 20 | 21 | # the name of the target operating system 22 | set(CMAKE_SYSTEM_NAME Linux) 23 | set(CMAKE_SYSTEM_PROCESSOR i386) 24 | 25 | # force 32 bit builds. 26 | set(CMAKE_C_FLAGS "-m32" CACHE STRING "" FORCE) 27 | set(CMAKE_CXX_FLAGS "-m32" CACHE STRING "" FORCE) 28 | set(CMAKE_ASM_FLAGS "-m32" CACHE STRING "" FORCE) 29 | 30 | # here is the target environment located 31 | #set(CMAKE_FIND_ROOT_PATH /usr/lib32) 32 | 33 | # adjust the default behaviour of the FIND_XXX() commands: 34 | # search headers and libraries in the target environment, search 35 | # programs in the host environment 36 | #set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 37 | #set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 38 | #set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 39 | -------------------------------------------------------------------------------- /cmake/unix_i386_toolchain.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Richard Maxwell 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | # SOFTWARE. 20 | 21 | set(CMAKE_SYSTEM_PROCESSOR i386) 22 | 23 | # force 32 bit builds. 24 | set(CMAKE_C_FLAGS "-m32" CACHE STRING "" FORCE) 25 | set(CMAKE_CXX_FLAGS "-m32" CACHE STRING "" FORCE) 26 | set(CMAKE_ASM_FLAGS "-m32" CACHE STRING "" FORCE) 27 | -------------------------------------------------------------------------------- /include/sewing.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Richard Maxwell 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | #ifndef SEWING_H 24 | #define SEWING_H 25 | 26 | #include 27 | // size_t 28 | 29 | // ----------------------------------------------------------------------------- 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | // ----------------------------------------------------------------------------- 36 | 37 | #if (__linux__ || __APPLE__) 38 | 39 | #include 40 | typedef pthread_t Sew_Thread; 41 | 42 | #elif defined(_WIN32) 43 | 44 | #include 45 | 46 | typedef struct Sew_Thread 47 | { 48 | HANDLE handle; 49 | DWORD id; 50 | } 51 | Sew_Thread; 52 | 53 | #else 54 | 55 | #error Platform not supported, sorry. 56 | 57 | #endif 58 | 59 | 60 | // ----------------------------------------------------------------------------- 61 | 62 | struct Sewing; 63 | 64 | typedef void* Sew_Chain; 65 | typedef void* Sew_Procedure_Argument; 66 | typedef void (*Sew_Procedure)(Sew_Procedure_Argument); 67 | 68 | typedef void (*Sew_Procedure_Main) 69 | ( 70 | struct Sewing* sewing 71 | , Sew_Thread* threads 72 | , size_t thread_count 73 | , Sew_Procedure_Argument procedure_argument 74 | ); 75 | 76 | typedef struct Sew_Stitch 77 | { 78 | Sew_Procedure procedure; 79 | Sew_Procedure_Argument argument; 80 | const char* name; 81 | } 82 | Sew_Stitch; 83 | 84 | // ----------------------------------------------------------------------------- 85 | 86 | //! Run 'stitch_count' amount of jobs (passed in the flat array 'stitches'), 87 | //! and wait for all of them to finish. 88 | //! 89 | //! This will block until all items have been queued in the job queue. 90 | //! 91 | //! 'sewing' is the opaque pointer passed into the call to sew_it's 92 | //! 'main_procedure' procedure. 93 | void sew_stitches_and_wait 94 | ( 95 | struct Sewing* sewing 96 | , Sew_Stitch* stitches 97 | , size_t stitch_count 98 | ); 99 | 100 | // ----------------------------------------------------------------------------- 101 | 102 | //! Run 'stitch_count' amount of jobs (passed in the flat array 'stithces'), and 103 | //! if chain is non-null, then set chain to a value that can be used to wait for 104 | //! the jobs in a call to 'sew_wait'. 105 | //! 106 | //! This will block until all items have been queued in the job queue. 107 | //! 108 | //! 'sewing' is the opaque pointer passed into the call to sew_it's 109 | //! 'main_procedure' procedure. 110 | void sew_stitches 111 | ( 112 | struct Sewing* sewing 113 | , Sew_Stitch* stitches 114 | , size_t stitch_count 115 | , Sew_Chain* chain 116 | ); 117 | 118 | //! If chain is non-null, then wait for all the jobs attached to chain have 119 | //! finished running. 120 | //! 121 | //! If chain is null, then the call may or may not yield to the job system 122 | //! before returning. 123 | void sew_wait(struct Sewing* sewing, Sew_Chain chain); 124 | 125 | // ----------------------------------------------------------------------------- 126 | 127 | //! Used to get a chain that's not tied to any stitches. The chain is marked as 128 | //! "in progress", and will block any call to sew_wait until it is marked 129 | //! as finished. 130 | void sew_external(struct Sewing* sewing, Sew_Chain* chain); 131 | 132 | //! Used to mark a chain taken from sew_external as finished. 133 | // 134 | //! Once called, the chain is now invalid, and calling sew_external_finished 135 | //! again with this invalid chain can result in undefined behaviour. 136 | //! 137 | //! WARNING: Do not pass in a chain from sew_stitches, as it will result in 138 | //! undefined behaviour (fiber leaks, unrelated jobs finishing, etcetc) 139 | void sew_external_finished(Sew_Chain chain); 140 | 141 | // ----------------------------------------------------------------------------- 142 | 143 | //! Dual use: 144 | //! 1) Entry point to the sewing system. 145 | //! 2) Get the amount of memory required for sewing_memory (in bytes) 146 | //! 147 | //! When passed with a non-null value of 'sew_memory', then it will initilise 148 | //! its internal state using the memory pointed to by 'sewing_memory'. It will 149 | //! create 'fiber_count' fibers, using a stack of 'stack_bytes'. It will create 150 | //! a threadsafe job queue with a size of (1 << log_2_job_count) jobs. 151 | //! It will then create and initilise 'thread_count- 1' threads before calling 152 | //! 'main_procedure' with the arguments of 'sewing', 'threads', 'thread_count' 153 | //! and 'main_procedure_argument'. Where 'sewing' is an opaque pointer to the 154 | //! sewing system required by any call to the sewing system. When the function 155 | //! returns then 'sewing_memory' may be deallocated. Returns the value of 0. 156 | //! 157 | //! If 'sew_memory' is NULL, then sew_it will return the amount of bytes needed 158 | //! for its internal state using 'thread_count' threads, 'fiber_count' fibers 159 | //! using a stack size of 'stack_bytes', and a job queue of 160 | //! (1 << log_2_job_count) jobs. Create a buffer of that size and pass that into 161 | //! sew_it to start the sewing system. 162 | size_t sew_it 163 | ( 164 | void* sewing_memory 165 | , size_t stack_bytes 166 | , size_t thread_count 167 | , size_t log_2_job_count 168 | , size_t fiber_count 169 | , Sew_Procedure_Main main_procedure 170 | , Sew_Procedure_Argument main_procedure_argument 171 | ); 172 | 173 | // ----------------------------------------------------------------------------- 174 | 175 | #ifdef __cplusplus 176 | } 177 | #endif 178 | 179 | // ----------------------------------------------------------------------------- 180 | 181 | #endif 182 | 183 | -------------------------------------------------------------------------------- /src/asm/jump_arm64_aapcs_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Edward Nevill 2015 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | /******************************************************* 8 | * * 9 | * ------------------------------------------------- * 10 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 11 | * ------------------------------------------------- * 12 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * 13 | * ------------------------------------------------- * 14 | * | d8 | d9 | d10 | d11 | * 15 | * ------------------------------------------------- * 16 | * ------------------------------------------------- * 17 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 18 | * ------------------------------------------------- * 19 | * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 20 | * ------------------------------------------------- * 21 | * | d12 | d13 | d14 | d15 | * 22 | * ------------------------------------------------- * 23 | * ------------------------------------------------- * 24 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 25 | * ------------------------------------------------- * 26 | * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * 27 | * ------------------------------------------------- * 28 | * | x19 | x20 | x21 | x22 | * 29 | * ------------------------------------------------- * 30 | * ------------------------------------------------- * 31 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 32 | * ------------------------------------------------- * 33 | * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * 34 | * ------------------------------------------------- * 35 | * | x23 | x24 | x25 | x26 | * 36 | * ------------------------------------------------- * 37 | * ------------------------------------------------- * 38 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 39 | * ------------------------------------------------- * 40 | * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * 41 | * ------------------------------------------------- * 42 | * | x27 | x28 | FP | LR | * 43 | * ------------------------------------------------- * 44 | * ------------------------------------------------- * 45 | * | 40 | 41 | 42 | 43 | | | * 46 | * ------------------------------------------------- * 47 | * | 0xa0| 0xa4| 0xa8| 0xac| | | * 48 | * ------------------------------------------------- * 49 | * | PC | align | | | * 50 | * ------------------------------------------------- * 51 | * * 52 | *******************************************************/ 53 | 54 | .cpu generic+fp+simd 55 | .text 56 | .align 2 57 | .global jump_fcontext 58 | .type jump_fcontext, %function 59 | jump_fcontext: 60 | # prepare stack for GP + FPU 61 | sub sp, sp, #0xb0 62 | 63 | # Because gcc may save integer registers in fp registers across a 64 | # function call we cannot skip saving the fp registers. 65 | # 66 | # Do not reinstate this test unless you fully understand what you 67 | # are doing. 68 | # 69 | # # test if fpu env should be preserved 70 | # cmp w3, #0 71 | # b.eq 1f 72 | 73 | # save d8 - d15 74 | stp d8, d9, [sp, #0x00] 75 | stp d10, d11, [sp, #0x10] 76 | stp d12, d13, [sp, #0x20] 77 | stp d14, d15, [sp, #0x30] 78 | 79 | 1: 80 | # save x19-x30 81 | stp x19, x20, [sp, #0x40] 82 | stp x21, x22, [sp, #0x50] 83 | stp x23, x24, [sp, #0x60] 84 | stp x25, x26, [sp, #0x70] 85 | stp x27, x28, [sp, #0x80] 86 | stp x29, x30, [sp, #0x90] 87 | 88 | # save LR as PC 89 | str x30, [sp, #0xa0] 90 | 91 | # store RSP (pointing to context-data) in first argument (x0). 92 | # STR cannot have sp as a target register 93 | mov x4, sp 94 | str x4, [x0] 95 | 96 | # restore RSP (pointing to context-data) from A2 (x1) 97 | mov sp, x1 98 | 99 | # # test if fpu env should be preserved 100 | # cmp w3, #0 101 | # b.eq 2f 102 | 103 | # load d8 - d15 104 | ldp d8, d9, [sp, #0x00] 105 | ldp d10, d11, [sp, #0x10] 106 | ldp d12, d13, [sp, #0x20] 107 | ldp d14, d15, [sp, #0x30] 108 | 109 | 2: 110 | # load x19-x30 111 | ldp x19, x20, [sp, #0x40] 112 | ldp x21, x22, [sp, #0x50] 113 | ldp x23, x24, [sp, #0x60] 114 | ldp x25, x26, [sp, #0x70] 115 | ldp x27, x28, [sp, #0x80] 116 | ldp x29, x30, [sp, #0x90] 117 | 118 | # use third arg as return value after jump 119 | # and as first arg in context function 120 | mov x0, x2 121 | 122 | # load pc 123 | ldr x4, [sp, #0xa0] 124 | 125 | # restore stack from GP + FPU 126 | add sp, sp, #0xb0 127 | 128 | ret x4 129 | .size jump_fcontext,.-jump_fcontext 130 | # Mark that we don't need executable stack. 131 | .section .note.GNU-stack,"",%progbits 132 | -------------------------------------------------------------------------------- /src/asm/jump_arm64_aapcs_macho_gas.S: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * * 3 | * ------------------------------------------------- * 4 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 5 | * ------------------------------------------------- * 6 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * 7 | * ------------------------------------------------- * 8 | * | d8 | d9 | d10 | d11 | * 9 | * ------------------------------------------------- * 10 | * ------------------------------------------------- * 11 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 12 | * ------------------------------------------------- * 13 | * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 14 | * ------------------------------------------------- * 15 | * | d12 | d13 | d14 | d15 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 19 | * ------------------------------------------------- * 20 | * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * 21 | * ------------------------------------------------- * 22 | * | x19 | x20 | x21 | x22 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 26 | * ------------------------------------------------- * 27 | * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * 28 | * ------------------------------------------------- * 29 | * | x23 | x24 | x25 | x26 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 33 | * ------------------------------------------------- * 34 | * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * 35 | * ------------------------------------------------- * 36 | * | x27 | x28 | FP | LR | * 37 | * ------------------------------------------------- * 38 | * ------------------------------------------------- * 39 | * | 40 | 41 | 42 | 43 | | | * 40 | * ------------------------------------------------- * 41 | * | 0xa0| 0xa4| 0xa8| 0xac| | | * 42 | * ------------------------------------------------- * 43 | * | PC | align | | | * 44 | * ------------------------------------------------- * 45 | * * 46 | *******************************************************/ 47 | 48 | .text 49 | .globl _jump_fcontext 50 | .balign 16 51 | _jump_fcontext: 52 | ; prepare stack for GP + FPU 53 | sub sp, sp, #0xb0 54 | 55 | #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) 56 | ; test if fpu env should be preserved 57 | cmp w3, #0 58 | b.eq 1f 59 | 60 | ; save d8 - d15 61 | stp d8, d9, [sp, #0x00] 62 | stp d10, d11, [sp, #0x10] 63 | stp d12, d13, [sp, #0x20] 64 | stp d14, d15, [sp, #0x30] 65 | 66 | 1: 67 | #endif 68 | 69 | ; save x19-x30 70 | stp x19, x20, [sp, #0x40] 71 | stp x21, x22, [sp, #0x50] 72 | stp x23, x24, [sp, #0x60] 73 | stp x25, x26, [sp, #0x70] 74 | stp x27, x28, [sp, #0x80] 75 | stp fp, lr, [sp, #0x90] 76 | 77 | ; save LR as PC 78 | str lr, [sp, #0xa0] 79 | 80 | ; store RSP (pointing to context-data) in first argument (x0). 81 | ; STR cannot have sp as a target register 82 | mov x4, sp 83 | str x4, [x0] 84 | 85 | ; restore RSP (pointing to context-data) from A2 (x1) 86 | mov sp, x1 87 | 88 | #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) 89 | ; test if fpu env should be preserved 90 | cmp w3, #0 91 | b.eq 2f 92 | 93 | ; load d8 - d15 94 | ldp d8, d9, [sp, #0x00] 95 | ldp d10, d11, [sp, #0x10] 96 | ldp d12, d13, [sp, #0x20] 97 | ldp d14, d15, [sp, #0x30] 98 | 99 | 2: 100 | #endif 101 | 102 | ; load x19-x30 103 | ldp x19, x20, [sp, #0x40] 104 | ldp x21, x22, [sp, #0x50] 105 | ldp x23, x24, [sp, #0x60] 106 | ldp x25, x26, [sp, #0x70] 107 | ldp x27, x28, [sp, #0x80] 108 | ldp fp, lr, [sp, #0x90] 109 | 110 | ; use third arg as return value after jump 111 | ; and as first arg in context function 112 | mov x0, x2 113 | 114 | ; load pc 115 | ldr x4, [sp, #0xa0] 116 | 117 | ; restore stack from GP + FPU 118 | add sp, sp, #0xb0 119 | 120 | ret x4 121 | -------------------------------------------------------------------------------- /src/asm/jump_arm_aapcs_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************* 9 | * * 10 | * ------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ------------------------------------------------- * 13 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * 14 | * ------------------------------------------------- * 15 | * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 21 | * ------------------------------------------------- * 22 | * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * 28 | * ------------------------------------------------- * 29 | * | v1 | v2 | v3 | v4 | v5 | v6 | v7 | v8 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | | * 33 | * ------------------------------------------------- * 34 | * | 0x60| 0x64| | * 35 | * ------------------------------------------------- * 36 | * | lr | pc | | * 37 | * ------------------------------------------------- * 38 | * * 39 | *******************************************************/ 40 | 41 | .text 42 | .globl jump_fcontext 43 | .align 2 44 | .type jump_fcontext,%function 45 | jump_fcontext: 46 | @ save LR as PC 47 | push {lr} 48 | @ save V1-V8,LR 49 | push {v1-v8,lr} 50 | 51 | @ prepare stack for FPU 52 | sub sp, sp, #64 53 | 54 | #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) 55 | @ test if fpu env should be preserved 56 | cmp a4, #0 57 | beq 1f 58 | 59 | @ save S16-S31 60 | vstmia sp, {d8-d15} 61 | 62 | 1: 63 | #endif 64 | 65 | @ store RSP (pointing to context-data) in A1 66 | str sp, [a1] 67 | 68 | @ restore RSP (pointing to context-data) from A2 69 | mov sp, a2 70 | 71 | #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) 72 | @ test if fpu env should be preserved 73 | cmp a4, #0 74 | beq 2f 75 | 76 | @ restore S16-S31 77 | vldmia sp, {d8-d15} 78 | 2: 79 | #endif 80 | 81 | @ prepare stack for FPU 82 | add sp, sp, #64 83 | 84 | @ use third arg as return value after jump 85 | @ and as first arg in context function 86 | mov a1, a3 87 | 88 | @ restore v1-V8,LR,PC 89 | pop {v1-v8,lr,pc} 90 | .size jump_fcontext,.-jump_fcontext 91 | 92 | @ Mark that we don't need executable stack. 93 | .section .note.GNU-stack,"",%progbits 94 | -------------------------------------------------------------------------------- /src/asm/jump_arm_aapcs_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************* 9 | * * 10 | * ------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ------------------------------------------------- * 13 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * 14 | * ------------------------------------------------- * 15 | * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 21 | * ------------------------------------------------- * 22 | * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * 28 | * ------------------------------------------------- * 29 | * | sjlj| v1 | v2 | v3 | v4 | v5 | v6 | v7 | 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | | * 33 | * ------------------------------------------------- * 34 | * | 0x60| 0x64| 0x68| | * 35 | * ------------------------------------------------- * 36 | * | v8 | lr | pc | | * 37 | * ------------------------------------------------- * 38 | * * 39 | * *****************************************************/ 40 | 41 | .text 42 | .globl _jump_fcontext 43 | .align 2 44 | _jump_fcontext: 45 | @ save LR as PC 46 | push {lr} 47 | @ save V1-V8,LR 48 | push {v1-v8,lr} 49 | 50 | @ locate TLS to save/restore SjLj handler 51 | mrc p15, 0, v2, c13, c0, #3 52 | bic v2, v2, #3 53 | 54 | @ load TLS[__PTK_LIBC_DYLD_Unwind_SjLj_Key] 55 | ldr v1, [v2, #72] 56 | @ save SjLj handler 57 | push {v1} 58 | 59 | @ prepare stack for FPU 60 | sub sp, sp, #64 61 | 62 | #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) 63 | @ test if fpu env should be preserved 64 | cmp a4, #0 65 | beq 1f 66 | 67 | @ save S16-S31 68 | vstmia sp, {d8-d15} 69 | 70 | 1: 71 | #endif 72 | 73 | @ store RSP (pointing to context-data) in A1 74 | str sp, [a1] 75 | 76 | @ restore RSP (pointing to context-data) from A2 77 | mov sp, a2 78 | 79 | #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) 80 | @ test if fpu env should be preserved 81 | cmp a4, #0 82 | beq 2f 83 | 84 | @ restore S16-S31 85 | vldmia sp, {d8-d15} 86 | 87 | 2: 88 | #endif 89 | 90 | @ prepare stack for FPU 91 | add sp, sp, #64 92 | 93 | @ restore SjLj handler 94 | pop {v1} 95 | @ store SjLj handler in TLS 96 | str v1, [v2, #72] 97 | 98 | @ use third arg as return value after jump 99 | @ and as first arg in context function 100 | mov a1, a3 101 | 102 | @ restore v1-V8,LR,PC 103 | pop {v1-v8,lr,pc} 104 | -------------------------------------------------------------------------------- /src/asm/jump_arm_aapcs_pe_armasm.asm: -------------------------------------------------------------------------------- 1 | ;/* 2 | ; Copyright Oliver Kowalke 2009. 3 | ; Distributed under the Boost Software License, Version 1.0. 4 | ; (See accompanying file LICENSE_1_0.txt or copy at 5 | ; http://www.boost.org/LICENSE_1_0.txt) 6 | ;*/ 7 | 8 | ; ******************************************************* 9 | ; * * 10 | ; * ------------------------------------------------- * 11 | ; * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | ; * ------------------------------------------------- * 13 | ; * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * 14 | ; * ------------------------------------------------- * 15 | ; * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * 16 | ; * ------------------------------------------------- * 17 | ; * ------------------------------------------------- * 18 | ; * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | ; * ------------------------------------------------- * 20 | ; * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 21 | ; * ------------------------------------------------- * 22 | ; * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * 23 | ; * ------------------------------------------------- * 24 | ; * ------------------------------------------------- * 25 | ; * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | ; * ------------------------------------------------- * 27 | ; * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * 28 | ; * ------------------------------------------------- * 29 | ; * |deall|limit| base| v1 | v2 | v3 | v4 | v5 | * 30 | ; * ------------------------------------------------- * 31 | ; * ------------------------------------------------- * 32 | ; * | 24 | 25 | 26 | 27 | 28 | | * 33 | ; * ------------------------------------------------- * 34 | ; * | 0x60| 0x64| 0x68| 0x6c| 0x70| | * 35 | ; * ------------------------------------------------- * 36 | ; * | v6 | v7 | v8 | lr | pc | | * 37 | ; * ------------------------------------------------- * 38 | ; * * 39 | ; ******************************************************* 40 | 41 | AREA |.text|, CODE 42 | ALIGN 4 43 | EXPORT jump_fcontext 44 | 45 | jump_fcontext PROC 46 | @ save LR as PC 47 | push {lr} 48 | @ save V1-V8,LR 49 | push {v1-v8,lr} 50 | 51 | @ prepare stack for FPU 52 | sub sp, sp, #0x4c 53 | 54 | @ test if fpu env should be preserved 55 | cmp a4, #0 56 | beq 1f 57 | 58 | @ save S16-S31 59 | vstmia sp, {d8-d15} 60 | 61 | 1: 62 | ; load TIB to save/restore thread size and limit. 63 | ; we do not need preserve CPU flag and can use it's arg register 64 | mrc p15, #0, v1, c13, c0, #2 65 | 66 | ; save current stack base 67 | ldr a5, [v1,#0x04] 68 | str a5, [sp,#0x48] 69 | ; save current stack limit 70 | ldr a5, [v1,#0x08] 71 | str a5, [sp,#0x44] 72 | ; save current deallocation stack 73 | ldr a5, [v1,#0xe0c] 74 | str a5, [sp,#0x40] 75 | 76 | @ store RSP (pointing to context-data) in A1 77 | str sp, [a1] 78 | 79 | @ restore RSP (pointing to context-data) from A2 80 | mov sp, a2 81 | 82 | @ test if fpu env should be preserved 83 | cmp a4, #0 84 | beq 2f 85 | 86 | @ restore S16-S31 87 | vldmia sp, {d8-d15} 88 | 89 | 2: 90 | ; restore stack base 91 | ldr a5, [sp,#0x48] 92 | str a5, [v1,#0x04] 93 | ; restore stack limit 94 | ldr a5, [sp,#0x44] 95 | str a5, [v1,#0x08] 96 | ; restore deallocation stack 97 | ldr a5, [sp,#0x40] 98 | str a5, [v1,#0xe0c] 99 | 100 | @ prepare stack for FPU 101 | add sp, sp, #0x4c 102 | 103 | ; use third arg as return value after jump 104 | ; and as first arg in context function 105 | mov a1, a3 106 | 107 | @ restore v1-V8,LR 108 | pop {v1-v8,lr} 109 | pop {pc} 110 | 111 | ENDP 112 | END 113 | -------------------------------------------------------------------------------- /src/asm/jump_combined_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__i386__) 11 | #include "jump_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "jump_x86_64_sysv_macho_gas.S" 14 | #elif defined(__ppc__) 15 | #include "jump_ppc32_sysv_macho_gas.S" 16 | #elif defined(__ppc64__) 17 | #include "jump_ppc64_sysv_macho_gas.S" 18 | #else 19 | #error "No arch's" 20 | #endif 21 | -------------------------------------------------------------------------------- /src/asm/jump_i386_ms_pe_gas.asm: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Copyright Thomas Sailer 2013. 4 | Distributed under the Boost Software License, Version 1.0. 5 | (See accompanying file LICENSE_1_0.txt or copy at 6 | http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | 9 | /******************************************************************** 10 | --------------------------------------------------------------------------------- 11 | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | --------------------------------------------------------------------------------- 13 | | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | 14 | --------------------------------------------------------------------------------- 15 | | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | 16 | --------------------------------------------------------------------------------- 17 | --------------------------------------------------------------------------------- 18 | | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | --------------------------------------------------------------------------------- 20 | | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | 21 | --------------------------------------------------------------------------------- 22 | | ESI | EBX | EBP | EIP | EXIT | | SEH NXT |SEH HNDLR| 23 | --------------------------------------------------------------------------------- 24 | * *****************************************************************/ 25 | 26 | .file "jump_i386_ms_pe_gas.asm" 27 | .text 28 | .p2align 4,,15 29 | .globl _jump_fcontext 30 | .def _jump_fcontext; .scl 2; .type 32; .endef 31 | _jump_fcontext: 32 | /* fourth arg of jump_fcontext() == flag indicating preserving FPU */ 33 | movl 0x10(%esp), %ecx 34 | 35 | pushl %ebp /* save EBP */ 36 | pushl %ebx /* save EBX */ 37 | pushl %esi /* save ESI */ 38 | pushl %edi /* save EDI */ 39 | 40 | /* load NT_TIB */ 41 | movl %fs:(0x18), %edx 42 | 43 | /* load current SEH exception list */ 44 | movl (%edx), %eax 45 | push %eax 46 | 47 | /* load current stack base */ 48 | movl 0x04(%edx), %eax 49 | push %eax 50 | 51 | /* load current stack limit */ 52 | movl 0x08(%edx), %eax 53 | push %eax 54 | 55 | /* load current dealloction stack */ 56 | movl 0xe0c(%edx), %eax 57 | push %eax 58 | 59 | /* load fiber local storage */ 60 | movl 0x10(%edx), %eax 61 | push %eax 62 | 63 | /* prepare stack for FPU */ 64 | leal -0x08(%esp), %esp 65 | 66 | /* test for flag preserve_fpu */ 67 | testl %ecx, %ecx 68 | je 1f 69 | 70 | /* save MMX control word */ 71 | stmxcsr (%esp) 72 | /* save x87 control word */ 73 | fnstcw 0x04(%esp) 74 | 75 | 1: 76 | /* first arg of jump_fcontext() == context jumping from */ 77 | movl 0x30(%esp), %eax 78 | 79 | /* store ESP (pointing to context-data) in EAX */ 80 | movl %esp, (%eax) 81 | 82 | /* second arg of jump_fcontext() == context jumping to */ 83 | movl 0x34(%esp), %edx 84 | 85 | /* third arg of jump_fcontext() == value to be returned after jump */ 86 | movl 0x38(%esp), %eax 87 | 88 | /* restore ESP (pointing to context-data) from EDX */ 89 | movl %edx, %esp 90 | 91 | /* test for flag preserve_fpu */ 92 | testl %ecx, %ecx 93 | je 2f 94 | 95 | /* restore MMX control- and status-word */ 96 | ldmxcsr (%esp) 97 | /* restore x87 control-word */ 98 | fldcw 0x04(%esp) 99 | 100 | 2: 101 | /* prepare stack for FPU */ 102 | leal 0x08(%esp), %esp 103 | 104 | /* load NT_TIB into ECX */ 105 | movl %fs:(0x18), %edx 106 | 107 | /* restore fiber local storage */ 108 | popl %ecx 109 | movl %ecx, 0x10(%edx) 110 | 111 | /* restore current deallocation stack */ 112 | popl %ecx 113 | movl %ecx, 0xe0c(%edx) 114 | 115 | /* restore current stack limit */ 116 | popl %ecx 117 | movl %ecx, 0x08(%edx) 118 | 119 | /* restore current stack base */ 120 | popl %ecx 121 | movl %ecx, 0x04(%edx) 122 | 123 | /* restore current SEH exception list */ 124 | popl %ecx 125 | movl %ecx, (%edx) 126 | 127 | popl %edi /* save EDI */ 128 | popl %esi /* save ESI */ 129 | popl %ebx /* save EBX */ 130 | popl %ebp /* save EBP */ 131 | 132 | /* restore return-address */ 133 | popl %edx 134 | 135 | /* use value in EAX as return-value after jump */ 136 | /* use value in EAX as first arg in context function */ 137 | movl %eax, 0x04(%esp) 138 | 139 | /* indirect jump to context */ 140 | jmp *%edx 141 | -------------------------------------------------------------------------------- /src/asm/jump_i386_ms_pe_masm.asm: -------------------------------------------------------------------------------- 1 | 2 | ; Copyright Oliver Kowalke 2009. 3 | ; Distributed under the Boost Software License, Version 1.0. 4 | ; (See accompanying file LICENSE_1_0.txt or copy at 5 | ; http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | ; --------------------------------------------------------------------------------- 8 | ; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | ; --------------------------------------------------------------------------------- 10 | ; | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | 11 | ; --------------------------------------------------------------------------------- 12 | ; | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | 13 | ; --------------------------------------------------------------------------------- 14 | ; --------------------------------------------------------------------------------- 15 | ; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | ; --------------------------------------------------------------------------------- 17 | ; | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | 18 | ; --------------------------------------------------------------------------------- 19 | ; | ESI | EBX | EBP | EIP | EXIT | | SEH NXT |SEH HNDLR| 20 | ; --------------------------------------------------------------------------------- 21 | 22 | .386 23 | .XMM 24 | .model flat, c 25 | .code 26 | 27 | jump_fcontext PROC 28 | ; fourth arg of jump_fcontext() == flag indicating preserving FPU 29 | mov ecx, [esp+010h] 30 | 31 | push ebp ; save EBP 32 | push ebx ; save EBX 33 | push esi ; save ESI 34 | push edi ; save EDI 35 | 36 | assume fs:nothing 37 | ; load NT_TIB into ECX 38 | mov edx, fs:[018h] 39 | assume fs:error 40 | 41 | ; load current SEH exception list 42 | mov eax, [edx] 43 | push eax 44 | 45 | ; load current stack base 46 | mov eax, [edx+04h] 47 | push eax 48 | 49 | ; load current stack limit 50 | mov eax, [edx+08h] 51 | push eax 52 | 53 | ; load current deallocation stack 54 | mov eax, [edx+0e0ch] 55 | push eax 56 | 57 | ; load fiber local storage 58 | mov eax, [edx+010h] 59 | push eax 60 | 61 | ; prepare stack for FPU 62 | lea esp, [esp-08h] 63 | 64 | ; test for flag preserve_fpu 65 | test ecx, ecx 66 | je nxt1 67 | 68 | ; save MMX control- and status-word 69 | stmxcsr [esp] 70 | ; save x87 control-word 71 | fnstcw [esp+04h] 72 | 73 | nxt1: 74 | ; first arg of jump_fcontext() == context jumping from 75 | mov eax, [esp+030h] 76 | 77 | ; store ESP (pointing to context-data) in EAX 78 | mov [eax], esp 79 | 80 | ; second arg of jump_fcontext() == context jumping to 81 | mov edx, [esp+034h] 82 | 83 | ; third arg of jump_fcontext() == value to be returned after jump 84 | mov eax, [esp+038h] 85 | 86 | ; restore ESP (pointing to context-data) from EDX 87 | mov esp, edx 88 | 89 | ; test for flag preserve_fpu 90 | test ecx, ecx 91 | je nxt2 92 | 93 | ; restore MMX control- and status-word 94 | ldmxcsr [esp] 95 | ; restore x87 control-word 96 | fldcw [esp+04h] 97 | 98 | nxt2: 99 | ; prepare stack for FPU 100 | lea esp, [esp+08h] 101 | 102 | assume fs:nothing 103 | ; load NT_TIB into ECX 104 | mov edx, fs:[018h] 105 | assume fs:error 106 | 107 | ; restore fiber local storage 108 | pop ecx 109 | mov [edx+010h], ecx 110 | 111 | ; restore current deallocation stack 112 | pop ecx 113 | mov [edx+0e0ch], ecx 114 | 115 | ; restore current stack limit 116 | pop ecx 117 | mov [edx+08h], ecx 118 | 119 | ; restore current stack base 120 | pop ecx 121 | mov [edx+04h], ecx 122 | 123 | ; restore current SEH exception list 124 | pop ecx 125 | mov [edx], ecx 126 | 127 | pop edi ; save EDI 128 | pop esi ; save ESI 129 | pop ebx ; save EBX 130 | pop ebp ; save EBP 131 | 132 | ; restore return-address 133 | pop edx 134 | 135 | ; use value in EAX as return-value after jump 136 | ; use value in EAX as first arg in context function 137 | mov [esp+04h], eax 138 | 139 | ; indirect jump to context 140 | jmp edx 141 | jump_fcontext ENDP 142 | END 143 | -------------------------------------------------------------------------------- /src/asm/jump_i386_sysv_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /**************************************************************************************** 9 | * * 10 | * ---------------------------------------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ---------------------------------------------------------------------------------- * 13 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * 14 | * ---------------------------------------------------------------------------------- * 15 | * | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | EXIT | * 16 | * ---------------------------------------------------------------------------------- * 17 | * * 18 | ****************************************************************************************/ 19 | 20 | .text 21 | .globl jump_fcontext 22 | .align 2 23 | .type jump_fcontext,@function 24 | jump_fcontext: 25 | /* fourth arg of jump_fcontext() == flag indicating preserving FPU */ 26 | movl 0x10(%esp), %ecx 27 | 28 | pushl %ebp /* save EBP */ 29 | pushl %ebx /* save EBX */ 30 | pushl %esi /* save ESI */ 31 | pushl %edi /* save EDI */ 32 | 33 | /* prepare stack for FPU */ 34 | leal -0x8(%esp), %esp 35 | 36 | /* test for flag preserve_fpu */ 37 | test %ecx, %ecx 38 | je 1f 39 | 40 | /* save MMX control- and status-word */ 41 | stmxcsr (%esp) 42 | /* save x87 control-word */ 43 | fnstcw 0x4(%esp) 44 | 45 | 1: 46 | /* first arg of jump_fcontext() == context jumping from */ 47 | movl 0x1c(%esp), %eax 48 | 49 | /* store ESP (pointing to context-data) in EAX */ 50 | movl %esp, (%eax) 51 | 52 | /* second arg of jump_fcontext() == context jumping to */ 53 | movl 0x20(%esp), %edx 54 | 55 | /* third arg of jump_fcontext() == value to be returned after jump */ 56 | movl 0x24(%esp), %eax 57 | 58 | /* restore ESP (pointing to context-data) from EDX */ 59 | movl %edx, %esp 60 | 61 | /* test for flag preserve_fpu */ 62 | test %ecx, %ecx 63 | je 2f 64 | 65 | /* restore MMX control- and status-word */ 66 | ldmxcsr (%esp) 67 | /* restore x87 control-word */ 68 | fldcw 0x4(%esp) 69 | 2: 70 | /* prepare stack for FPU */ 71 | leal 0x8(%esp), %esp 72 | 73 | popl %edi /* restore EDI */ 74 | popl %esi /* restore ESI */ 75 | popl %ebx /* restore EBX */ 76 | popl %ebp /* restore EBP */ 77 | 78 | /* restore return-address */ 79 | popl %edx 80 | 81 | /* use value in EAX as return-value after jump */ 82 | /* use value in EAX as first arg in context function */ 83 | movl %eax, 0x4(%esp) 84 | 85 | /* indirect jump to context */ 86 | jmp *%edx 87 | .size jump_fcontext,.-jump_fcontext 88 | 89 | /* Mark that we don't need executable stack. */ 90 | .section .note.GNU-stack,"",%progbits 91 | -------------------------------------------------------------------------------- /src/asm/jump_i386_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /**************************************************************************************** 9 | * * 10 | * ---------------------------------------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ---------------------------------------------------------------------------------- * 13 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * 14 | * ---------------------------------------------------------------------------------- * 15 | * | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | EXIT | * 16 | * ---------------------------------------------------------------------------------- * 17 | * * 18 | ****************************************************************************************/ 19 | 20 | .text 21 | .globl _jump_fcontext 22 | .align 2 23 | _jump_fcontext: 24 | /* fourth arg of jump_fcontext() == flag indicating preserving FPU */ 25 | movl 0x10(%esp), %ecx 26 | 27 | pushl %ebp /* save EBP */ 28 | pushl %ebx /* save EBX */ 29 | pushl %esi /* save ESI */ 30 | pushl %edi /* save EDI */ 31 | 32 | /* prepare stack for FPU */ 33 | leal -0x8(%esp), %esp 34 | 35 | /* test for flag preserve_fpu */ 36 | test %ecx, %ecx 37 | je 1f 38 | 39 | /* save MMX control- and status-word */ 40 | stmxcsr (%esp) 41 | /* save x87 control-word */ 42 | fnstcw 0x4(%esp) 43 | 44 | 1: 45 | /* first arg of jump_fcontext() == context jumping from */ 46 | movl 0x1c(%esp), %eax 47 | 48 | /* store ESP (pointing to context-data) in EAX */ 49 | movl %esp, (%eax) 50 | 51 | /* second arg of jump_fcontext() == context jumping to */ 52 | movl 0x20(%esp), %edx 53 | 54 | /* third arg of jump_fcontext() == value to be returned after jump */ 55 | movl 0x24(%esp), %eax 56 | 57 | /* restore ESP (pointing to context-data) from EDX */ 58 | movl %edx, %esp 59 | 60 | /* test for flag preserve_fpu */ 61 | test %ecx, %ecx 62 | je 2f 63 | 64 | /* restore MMX control- and status-word */ 65 | ldmxcsr (%esp) 66 | /* restore x87 control-word */ 67 | fldcw 0x4(%esp) 68 | 2: 69 | /* prepare stack for FPU */ 70 | leal 0x8(%esp), %esp 71 | 72 | popl %edi /* restore EDI */ 73 | popl %esi /* restore ESI */ 74 | popl %ebx /* restore EBX */ 75 | popl %ebp /* restore EBP */ 76 | 77 | /* restore return-address */ 78 | popl %edx 79 | 80 | /* use value in EAX as return-value after jump */ 81 | /* use value in EAX as first arg in context function */ 82 | movl %eax, 0x4(%esp) 83 | 84 | /* indirect jump to context */ 85 | jmp *%edx 86 | -------------------------------------------------------------------------------- /src/asm/jump_i386_x86_64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__i386__) 11 | #include "jump_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "jump_x86_64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /src/asm/jump_mips32_o32_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************* 9 | * * 10 | * ------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ------------------------------------------------- * 13 | * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * 14 | * ------------------------------------------------- * 15 | * | F20 | F22 | F24 | F26 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * 21 | * ------------------------------------------------- * 22 | * | F28 | F30 | S0 | S1 | S2 | S3 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | | * 26 | * ------------------------------------------------- * 27 | * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | | * 28 | * ------------------------------------------------- * 29 | * | S4 | S5 | S6 | S7 | FP | RA | PC | | * 30 | * ------------------------------------------------- * 31 | * * 32 | * *****************************************************/ 33 | 34 | .text 35 | .globl jump_fcontext 36 | .align 2 37 | .type jump_fcontext,@function 38 | .ent jump_fcontext 39 | jump_fcontext: 40 | # reserve space on stack 41 | addiu $sp, $sp, -92 42 | 43 | sw $s0, 48($sp) # save S0 44 | sw $s1, 52($sp) # save S1 45 | sw $s2, 56($sp) # save S2 46 | sw $s3, 60($sp) # save S3 47 | sw $s4, 64($sp) # save S4 48 | sw $s5, 68($sp) # save S5 49 | sw $s6, 72($sp) # save S6 50 | sw $s7, 76($sp) # save S7 51 | sw $fp, 80($sp) # save FP 52 | sw $ra, 84($sp) # save RA 53 | sw $ra, 88($sp) # save RA as PC 54 | 55 | #if defined(__mips_hard_float) 56 | # test if fpu env should be preserved 57 | beqz $a3, 1f 58 | 59 | s.d $f20, ($sp) # save F20 60 | s.d $f22, 8($sp) # save F22 61 | s.d $f24, 16($sp) # save F24 62 | s.d $f26, 24($sp) # save F26 63 | s.d $f28, 32($sp) # save F28 64 | s.d $f30, 40($sp) # save F30 65 | 66 | 1: 67 | #endif 68 | 69 | # store SP (pointing to context-data) in A0 70 | sw $sp, ($a0) 71 | 72 | # restore SP (pointing to context-data) from A1 73 | move $sp, $a1 74 | 75 | 76 | #if defined(__mips_hard_float) 77 | # test if fpu env should be preserved 78 | beqz $a3, 2f 79 | 80 | l.d $f20, ($sp) # restore F20 81 | l.d $f22, 8($sp) # restore F22 82 | l.d $f24, 16($sp) # restore F24 83 | l.d $f26, 24($sp) # restore F26 84 | l.d $f28, 32($sp) # restore F28 85 | l.d $f30, 40($sp) # restore F30 86 | 87 | 2: 88 | #endif 89 | 90 | lw $s0, 48($sp) # restore S0 91 | lw $s1, 52($sp) # restore S1 92 | lw $s2, 56($sp) # restore S2 93 | lw $s3, 60($sp) # restore S3 94 | lw $s4, 64($sp) # restore S4 95 | lw $s5, 68($sp) # restore S5 96 | lw $s6, 72($sp) # restore S6 97 | lw $s7, 76($sp) # restore S7 98 | lw $fp, 80($sp) # restore FP 99 | lw $ra, 84($sp) # restore RA 100 | 101 | # load PC 102 | lw $t9, 88($sp) 103 | 104 | # adjust stack 105 | addiu $sp, $sp, 92 106 | 107 | # use third arg as return value after jump 108 | move $v0, $a2 109 | # use third arg as first arg in context function 110 | move $a0, $a2 111 | 112 | # jump to context 113 | jr $t9 114 | .end jump_fcontext 115 | .size jump_fcontext, .-jump_fcontext 116 | 117 | /* Mark that we don't need executable stack. */ 118 | .section .note.GNU-stack,"",%progbits 119 | -------------------------------------------------------------------------------- /src/asm/jump_ppc32_ppc64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__ppc__) 11 | #include "jump_ppc32_sysv_macho_gas.S" 12 | #elif defined(__ppc64__) 13 | #include "jump_ppc64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /src/asm/jump_ppc32_sysv_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************* 9 | * * 10 | * ------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ------------------------------------------------- * 13 | * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * 14 | * ------------------------------------------------- * 15 | * | F14 | F15 | F16 | F17 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * 21 | * ------------------------------------------------- * 22 | * | F18 | F19 | F20 | F21 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * 28 | * ------------------------------------------------- * 29 | * | F22 | F23 | F24 | F25 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * 35 | * ------------------------------------------------- * 36 | * | F26 | F27 | F28 | F29 | * 37 | * ------------------------------------------------- * 38 | * ------------------------------------------------- * 39 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 40 | * ------------------------------------------------- * 41 | * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * 42 | * ------------------------------------------------- * 43 | * | F30 | F31 | fpscr | R13 | R14 | * 44 | * ------------------------------------------------- * 45 | * ------------------------------------------------- * 46 | * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * 47 | * ------------------------------------------------- * 48 | * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * 49 | * ------------------------------------------------- * 50 | * | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | * 51 | * ------------------------------------------------- * 52 | * ------------------------------------------------- * 53 | * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * 54 | * ------------------------------------------------- * 55 | * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * 56 | * ------------------------------------------------- * 57 | * | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | * 58 | * ------------------------------------------------- * 59 | * ------------------------------------------------- * 60 | * | 56 | 57 | 58 | 59 | | * 61 | * ------------------------------------------------- * 62 | * | 224 | 228 | 232 | 236 | | * 63 | * ------------------------------------------------- * 64 | * | R31 | CR | LR | PC | | * 65 | * ------------------------------------------------- * 66 | * * 67 | *******************************************************/ 68 | 69 | .text 70 | .globl jump_fcontext 71 | .align 2 72 | .type jump_fcontext,@function 73 | jump_fcontext: 74 | # reserve space on stack 75 | subi %r1, %r1, 240 76 | 77 | stw %r13, 152(%r1) # save R13 78 | stw %r14, 156(%r1) # save R14 79 | stw %r15, 160(%r1) # save R15 80 | stw %r16, 164(%r1) # save R16 81 | stw %r17, 168(%r1) # save R17 82 | stw %r18, 172(%r1) # save R18 83 | stw %r19, 176(%r1) # save R19 84 | stw %r20, 180(%r1) # save R20 85 | stw %r21, 184(%r1) # save R21 86 | stw %r22, 188(%r1) # save R22 87 | stw %r23, 192(%r1) # save R23 88 | stw %r24, 196(%r1) # save R24 89 | stw %r25, 200(%r1) # save R25 90 | stw %r26, 204(%r1) # save R26 91 | stw %r27, 208(%r1) # save R27 92 | stw %r28, 212(%r1) # save R28 93 | stw %r29, 216(%r1) # save R29 94 | stw %r30, 220(%r1) # save R30 95 | stw %r31, 224(%r1) # save R31 96 | 97 | # save CR 98 | mfcr %r0 99 | stw %r0, 228(%r1) 100 | # save LR 101 | mflr %r0 102 | stw %r0, 232(%r1) 103 | # save LR as PC 104 | stw %r0, 236(%r1) 105 | 106 | # test if fpu env should be preserved 107 | cmpwi cr7, %r6, 0 108 | beq cr7, 1f 109 | 110 | stfd %f14, 0(%r1) # save F14 111 | stfd %f15, 8(%r1) # save F15 112 | stfd %f16, 16(%r1) # save F16 113 | stfd %f17, 24(%r1) # save F17 114 | stfd %f18, 32(%r1) # save F18 115 | stfd %f19, 40(%r1) # save F19 116 | stfd %f20, 48(%r1) # save F20 117 | stfd %f21, 56(%r1) # save F21 118 | stfd %f22, 64(%r1) # save F22 119 | stfd %f23, 72(%r1) # save F23 120 | stfd %f24, 80(%r1) # save F24 121 | stfd %f25, 88(%r1) # save F25 122 | stfd %f26, 96(%r1) # save F26 123 | stfd %f27, 104(%r1) # save F27 124 | stfd %f28, 112(%r1) # save F28 125 | stfd %f29, 120(%r1) # save F29 126 | stfd %f30, 128(%r1) # save F30 127 | stfd %f31, 136(%r1) # save F31 128 | mffs %f0 # load FPSCR 129 | stfd %f0, 144(%r1) # save FPSCR 130 | 131 | 1: 132 | # store RSP (pointing to context-data) in R3 133 | stw %r1, 0(%r3) 134 | 135 | # restore RSP (pointing to context-data) from R4 136 | mr %r1, %r4 137 | 138 | # test if fpu env should be preserved 139 | cmpwi cr7, %r6, 0 140 | beq cr7, 2f 141 | 142 | lfd %f14, 0(%r1) # restore F14 143 | lfd %f15, 8(%r1) # restore F15 144 | lfd %f16, 16(%r1) # restore F16 145 | lfd %f17, 24(%r1) # restore F17 146 | lfd %f18, 32(%r1) # restore F18 147 | lfd %f19, 40(%r1) # restore F19 148 | lfd %f20, 48(%r1) # restore F20 149 | lfd %f21, 56(%r1) # restore F21 150 | lfd %f22, 64(%r1) # restore F22 151 | lfd %f23, 72(%r1) # restore F23 152 | lfd %f24, 80(%r1) # restore F24 153 | lfd %f25, 88(%r1) # restore F25 154 | lfd %f26, 96(%r1) # restore F26 155 | lfd %f27, 104(%r1) # restore F27 156 | lfd %f28, 112(%r1) # restore F28 157 | lfd %f29, 120(%r1) # restore F29 158 | lfd %f30, 128(%r1) # restore F30 159 | lfd %f31, 136(%r1) # restore F31 160 | lfd %f0, 144(%r1) # load FPSCR 161 | mtfsf 0xff, %f0 # restore FPSCR 162 | 163 | 2: 164 | lwz %r13, 152(%r1) # restore R13 165 | lwz %r14, 156(%r1) # restore R14 166 | lwz %r15, 160(%r1) # restore R15 167 | lwz %r16, 164(%r1) # restore R16 168 | lwz %r17, 168(%r1) # restore R17 169 | lwz %r18, 172(%r1) # restore R18 170 | lwz %r19, 176(%r1) # restore R19 171 | lwz %r20, 180(%r1) # restore R20 172 | lwz %r21, 184(%r1) # restore R21 173 | lwz %r22, 188(%r1) # restore R22 174 | lwz %r23, 192(%r1) # restore R23 175 | lwz %r24, 196(%r1) # restore R24 176 | lwz %r25, 200(%r1) # restore R25 177 | lwz %r26, 204(%r1) # restore R26 178 | lwz %r27, 208(%r1) # restore R27 179 | lwz %r28, 212(%r1) # restore R28 180 | lwz %r29, 216(%r1) # restore R29 181 | lwz %r30, 220(%r1) # restore R30 182 | lwz %r31, 224(%r1) # restore R31 183 | 184 | # restore CR 185 | lwz %r0, 228(%r1) 186 | mtcr %r0 187 | # restore LR 188 | lwz %r0, 232(%r1) 189 | mtlr %r0 190 | 191 | # load PC 192 | lwz %r0, 236(%r1) 193 | # restore CTR 194 | mtctr %r0 195 | 196 | # adjust stack 197 | addi %r1, %r1, 240 198 | 199 | # use third arg as return value after jump 200 | # use third arg as first arg in context function 201 | mr %r3, %r5 202 | 203 | # jump to context 204 | bctr 205 | .size jump_fcontext, .-jump_fcontext 206 | 207 | /* Mark that we don't need executable stack. */ 208 | .section .note.GNU-stack,"",%progbits 209 | -------------------------------------------------------------------------------- /src/asm/jump_ppc32_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************* 9 | * * 10 | * ------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ------------------------------------------------- * 13 | * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * 14 | * ------------------------------------------------- * 15 | * | F14 | F15 | F16 | F17 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * 21 | * ------------------------------------------------- * 22 | * | F18 | F19 | F20 | F21 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * 28 | * ------------------------------------------------- * 29 | * | F22 | F23 | F24 | F25 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * 35 | * ------------------------------------------------- * 36 | * | F26 | F27 | F28 | F29 | * 37 | * ------------------------------------------------- * 38 | * ------------------------------------------------- * 39 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 40 | * ------------------------------------------------- * 41 | * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * 42 | * ------------------------------------------------- * 43 | * | F30 | F31 | fpscr | R13 | R14 | * 44 | * ------------------------------------------------- * 45 | * ------------------------------------------------- * 46 | * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * 47 | * ------------------------------------------------- * 48 | * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * 49 | * ------------------------------------------------- * 50 | * | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | * 51 | * ------------------------------------------------- * 52 | * ------------------------------------------------- * 53 | * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * 54 | * ------------------------------------------------- * 55 | * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * 56 | * ------------------------------------------------- * 57 | * | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | * 58 | * ------------------------------------------------- * 59 | * ------------------------------------------------- * 60 | * | 56 | 57 | 58 | 59 | | * 61 | * ------------------------------------------------- * 62 | * | 224 | 228 | 232 | 236 | | * 63 | * ------------------------------------------------- * 64 | * | R31 | CR | LR | PC | | * 65 | * ------------------------------------------------- * 66 | * * 67 | *******************************************************/ 68 | 69 | .text 70 | .globl _jump_fcontext 71 | .align 2 72 | _jump_fcontext: 73 | ; reserve space on stack 74 | subi r1, r1, 240 75 | 76 | stw r13, 152(r1) ; save R13 77 | stw r14, 156(r1) ; save R14 78 | stw r15, 160(r1) ; save R15 79 | stw r16, 164(r1) ; save R16 80 | stw r17, 168(r1) ; save R17 81 | stw r18, 172(r1) ; save R18 82 | stw r19, 176(r1) ; save R19 83 | stw r20, 180(r1) ; save R20 84 | stw r21, 184(r1) ; save R21 85 | stw r22, 188(r1) ; save R22 86 | stw r23, 192(r1) ; save R23 87 | stw r24, 196(r1) ; save R24 88 | stw r25, 200(r1) ; save R25 89 | stw r26, 204(r1) ; save R26 90 | stw r27, 208(r1) ; save R27 91 | stw r28, 212(r1) ; save R28 92 | stw r29, 216(r1) ; save R29 93 | stw r30, 220(r1) ; save R30 94 | stw r31, 224(r1) ; save R31 95 | 96 | ; save CR 97 | mfcr r0 98 | stw r0, 228(r1) 99 | ; save LR 100 | mflr r0 101 | stw r0, 232(r1) 102 | ; save LR as PC 103 | stw r0, 236(r1) 104 | 105 | ; test if fpu env should be preserved 106 | cmpwi cr7, r6, 0 107 | beq cr7, l1 108 | 109 | stfd f14, 0(r1) ; save F14 110 | stfd f15, 8(r1) ; save F15 111 | stfd f16, 16(r1) ; save F16 112 | stfd f17, 24(r1) ; save F17 113 | stfd f18, 32(r1) ; save F18 114 | stfd f19, 40(r1) ; save F19 115 | stfd f20, 48(r1) ; save F20 116 | stfd f21, 56(r1) ; save F21 117 | stfd f22, 64(r1) ; save F22 118 | stfd f23, 72(r1) ; save F23 119 | stfd f24, 80(r1) ; save F24 120 | stfd f25, 88(r1) ; save F25 121 | stfd f26, 96(r1) ; save F26 122 | stfd f27, 104(r1) ; save F27 123 | stfd f28, 112(r1) ; save F28 124 | stfd f29, 120(r1) ; save F29 125 | stfd f30, 128(r1) ; save F30 126 | stfd f31, 136(r1) ; save F31 127 | mffs f0 ; load FPSCR 128 | stfd f0, 144(r1) ; save FPSCR 129 | 130 | l1: 131 | ; store RSP (pointing to context-data) in R3 132 | stw r1, 0(r3) 133 | 134 | ; restore RSP (pointing to context-data) from R4 135 | mr r1, r4 136 | 137 | ; test if fpu env should be preserved 138 | cmpwi cr7, r6, 0 139 | beq cr7, l2 140 | 141 | lfd f14, 0(r1) ; restore F14 142 | lfd f15, 8(r1) ; restore F15 143 | lfd f16, 16(r1) ; restore F16 144 | lfd f17, 24(r1) ; restore F17 145 | lfd f18, 32(r1) ; restore F18 146 | lfd f19, 40(r1) ; restore F19 147 | lfd f20, 48(r1) ; restore F20 148 | lfd f21, 56(r1) ; restore F21 149 | lfd f22, 64(r1) ; restore F22 150 | lfd f23, 72(r1) ; restore F23 151 | lfd f24, 80(r1) ; restore F24 152 | lfd f25, 88(r1) ; restore F25 153 | lfd f26, 96(r1) ; restore F26 154 | lfd f27, 104(r1) ; restore F27 155 | lfd f28, 112(r1) ; restore F28 156 | lfd f29, 120(r1) ; restore F29 157 | lfd f30, 128(r1) ; restore F30 158 | lfd f31, 136(r1) ; restore F31 159 | lfd f0, 144(r1) ; load FPSCR 160 | mtfsf 0xff, f0 ; restore FPSCR 161 | 162 | l2: 163 | lwz r13, 152(r1) ; restore R13 164 | lwz r14, 156(r1) ; restore R14 165 | lwz r15, 160(r1) ; restore R15 166 | lwz r16, 164(r1) ; restore R16 167 | lwz r17, 168(r1) ; restore R17 168 | lwz r18, 172(r1) ; restore R18 169 | lwz r19, 176(r1) ; restore R19 170 | lwz r20, 180(r1) ; restore R20 171 | lwz r21, 184(r1) ; restore R21 172 | lwz r22, 188(r1) ; restore R22 173 | lwz r23, 192(r1) ; restore R23 174 | lwz r24, 196(r1) ; restore R24 175 | lwz r25, 200(r1) ; restore R25 176 | lwz r26, 204(r1) ; restore R26 177 | lwz r27, 208(r1) ; restore R27 178 | lwz r28, 212(r1) ; restore R28 179 | lwz r29, 216(r1) ; restore R29 180 | lwz r30, 220(r1) ; restore R30 181 | lwz r31, 224(r1) ; restore R31 182 | 183 | ; restore CR 184 | lwz r0, 228(r1) 185 | mtcr r0 186 | ; restore LR 187 | lwz r0, 232(r1) 188 | mtlr r0 189 | 190 | ; load PC 191 | lwz r0, 236(r1) 192 | ; restore CTR 193 | mtctr r0 194 | 195 | ; adjust stack 196 | addi r1, r1, 240 197 | 198 | ; use third arg as return value after jump 199 | ; use third arg as first arg in context function 200 | mr r3, r5 201 | 202 | ; jump to context 203 | bctr 204 | -------------------------------------------------------------------------------- /src/asm/jump_ppc32_sysv_xcoff_gas.S: -------------------------------------------------------------------------------- 1 | .globl .jump_fcontext 2 | .globl jump_fcontext[DS] 3 | .align 2 4 | .csect jump_fcontext[DS] 5 | jump_fcontext: 6 | .long .jump_fcontext 7 | .jump_fcontext: 8 | # reserve space on stack 9 | subi 1, 1, 240 10 | 11 | stw 13, 152(1) # save R13 12 | stw 14, 156(1) # save R14 13 | stw 15, 160(1) # save R15 14 | stw 16, 164(1) # save R16 15 | stw 17, 168(1) # save R17 16 | stw 18, 172(1) # save R18 17 | stw 19, 176(1) # save R19 18 | stw 20, 180(1) # save R20 19 | stw 21, 184(1) # save R21 20 | stw 22, 188(1) # save R22 21 | stw 23, 192(1) # save R23 22 | stw 24, 196(1) # save R24 23 | stw 25, 200(1) # save R25 24 | stw 26, 204(1) # save R26 25 | stw 27, 208(1) # save R27 26 | stw 28, 212(1) # save R28 27 | stw 29, 216(1) # save R29 28 | stw 30, 220(1) # save R30 29 | stw 31, 224(1) # save R31 30 | 31 | # save CR 32 | mfcr 0 33 | stw 0, 228(1) 34 | # save LR 35 | mflr 0 36 | stw 0, 232(1) 37 | # save LR as PC 38 | stw 0, 236(1) 39 | 40 | # test if fpu env should be preserved 41 | cmpwi 7, 6, 0 42 | beq 7, label1 43 | 44 | stfd 14, 0(1) # save F14 45 | stfd 15, 8(1) # save F15 46 | stfd 16, 16(1) # save F16 47 | stfd 17, 24(1) # save F17 48 | stfd 18, 32(1) # save F18 49 | stfd 19, 40(1) # save F19 50 | stfd 20, 48(1) # save F20 51 | stfd 21, 56(1) # save F21 52 | stfd 22, 64(1) # save F22 53 | stfd 23, 72(1) # save F23 54 | stfd 24, 80(1) # save F24 55 | stfd 25, 88(1) # save F25 56 | stfd 26, 96(1) # save F26 57 | stfd 27, 104(1) # save F27 58 | stfd 28, 112(1) # save F28 59 | stfd 29, 120(1) # save F29 60 | stfd 30, 128(1) # save F30 61 | stfd 31, 136(1) # save F31 62 | mffs 0 # load FPSCR 63 | stfd 0, 144(1) # save FPSCR 64 | 65 | label1: 66 | # store RSP (pointing to context-data) in R3 67 | stw 1, 0(3) 68 | 69 | # restore RSP (pointing to context-data) from R4 70 | mr 1, 4 71 | 72 | # test if fpu env should be preserved 73 | cmpwi 7, 6, 0 74 | beq 7, label2 75 | 76 | lfd 14, 0(1) # restore F14 77 | lfd 15, 8(1) # restore F15 78 | lfd 16, 16(1) # restore F16 79 | lfd 17, 24(1) # restore F17 80 | lfd 18, 32(1) # restore F18 81 | lfd 19, 40(1) # restore F19 82 | lfd 20, 48(1) # restore F20 83 | lfd 21, 56(1) # restore F21 84 | lfd 22, 64(1) # restore F22 85 | lfd 23, 72(1) # restore F23 86 | lfd 24, 80(1) # restore F24 87 | lfd 25, 88(1) # restore F25 88 | lfd 26, 96(1) # restore F26 89 | lfd 27, 104(1) # restore F27 90 | lfd 28, 112(1) # restore F28 91 | lfd 29, 120(1) # restore F29 92 | lfd 30, 128(1) # restore F30 93 | lfd 31, 136(1) # restore F31 94 | lfd 0, 144(1) # load FPSCR 95 | mtfsf 0xff, 0 # restore FPSCR 96 | 97 | label2: 98 | lwz 13, 152(1) # restore R13 99 | lwz 14, 156(1) # restore R14 100 | lwz 15, 160(1) # restore R15 101 | lwz 16, 164(1) # restore R16 102 | lwz 17, 168(1) # restore R17 103 | lwz 18, 172(1) # restore R18 104 | lwz 19, 176(1) # restore R19 105 | lwz 20, 180(1) # restore R20 106 | lwz 21, 184(1) # restore R21 107 | lwz 22, 188(1) # restore R22 108 | lwz 23, 192(1) # restore R23 109 | lwz 24, 196(1) # restore R24 110 | lwz 25, 200(1) # restore R25 111 | lwz 26, 204(1) # restore R26 112 | lwz 27, 208(1) # restore R27 113 | lwz 28, 212(1) # restore R28 114 | lwz 29, 216(1) # restore R29 115 | lwz 30, 220(1) # restore R30 116 | lwz 31, 224(1) # restore R31 117 | 118 | # restore CR 119 | lwz 0, 228(1) 120 | mtcr 0 121 | # restore LR 122 | lwz 0, 232(1) 123 | mtlr 0 124 | 125 | # load PC 126 | lwz 0, 236(1) 127 | # restore CTR 128 | mtctr 0 129 | 130 | # adjust stack 131 | addi 1, 1, 240 132 | 133 | # use third arg as return value after jump 134 | # use third arg as first arg in context function 135 | mr 3, 5 136 | 137 | # jump to context 138 | bctr 139 | -------------------------------------------------------------------------------- /src/asm/jump_ppc64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************* 9 | * * 10 | * ------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ------------------------------------------------- * 13 | * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * 14 | * ------------------------------------------------- * 15 | * | F14 | F15 | F16 | F17 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * 21 | * ------------------------------------------------- * 22 | * | F18 | F19 | F20 | F21 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * 28 | * ------------------------------------------------- * 29 | * | F22 | F23 | F24 | F25 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * 35 | * ------------------------------------------------- * 36 | * | F26 | F27 | F28 | F29 | * 37 | * ------------------------------------------------- * 38 | * ------------------------------------------------- * 39 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 40 | * ------------------------------------------------- * 41 | * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * 42 | * ------------------------------------------------- * 43 | * | F30 | F31 | fpscr | R13 | * 44 | * ------------------------------------------------- * 45 | * ------------------------------------------------- * 46 | * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * 47 | * ------------------------------------------------- * 48 | * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * 49 | * ------------------------------------------------- * 50 | * | R14 | R15 | R16 | R17 | * 51 | * ------------------------------------------------- * 52 | * ------------------------------------------------- * 53 | * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * 54 | * ------------------------------------------------- * 55 | * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * 56 | * ------------------------------------------------- * 57 | * | R18 | R19 | R20 | R21 | * 58 | * ------------------------------------------------- * 59 | * ------------------------------------------------- * 60 | * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * 61 | * ------------------------------------------------- * 62 | * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * 63 | * ------------------------------------------------- * 64 | * | R22 | R23 | R24 | R25 | * 65 | * ------------------------------------------------- * 66 | * ------------------------------------------------- * 67 | * | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | * 68 | * ------------------------------------------------- * 69 | * | 256 | 260 | 264 | 268 | 272 | 276 | 280 | 284 | * 70 | * ------------------------------------------------- * 71 | * | R26 | R27 | R28 | R29 | * 72 | * ------------------------------------------------- * 73 | * ------------------------------------------------- * 74 | * | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | * 75 | * ------------------------------------------------- * 76 | * | 288 | 292 | 296 | 300 | 304 | 308 | 312 | 316 | * 77 | * ------------------------------------------------- * 78 | * ------------------------------------------------- * 79 | * | R30 | R31 | CR | LR | * 80 | * ------------------------------------------------- * 81 | * ------------------------------------------------- * 82 | * | 80 | 81 | | * 83 | * ------------------------------------------------- * 84 | * | 320 | 324 | | * 85 | * ------------------------------------------------- * 86 | * | PC | | * 87 | * ------------------------------------------------- * 88 | * * 89 | *******************************************************/ 90 | 91 | .text 92 | .align 2 93 | .globl jump_fcontext 94 | 95 | _jump_fcontext: 96 | ; reserve space on stack 97 | subi r1, r1, 328 98 | 99 | std r13, 152(r1) ; save R13 100 | std r14, 160(r1) ; save R14 101 | std r15, 168(r1) ; save R15 102 | std r16, 176(r1) ; save R16 103 | std r17, 184(r1) ; save R17 104 | std r18, 192(r1) ; save R18 105 | std r19, 200(r1) ; save R19 106 | std r20, 208(r1) ; save R20 107 | std r21, 216(r1) ; save R21 108 | std r22, 224(r1) ; save R22 109 | std r23, 232(r1) ; save R23 110 | std r24, 240(r1) ; save R24 111 | std r25, 248(r1) ; save R25 112 | std r26, 256(r1) ; save R26 113 | std r27, 264(r1) ; save R27 114 | std r28, 272(r1) ; save R28 115 | std r29, 280(r1) ; save R29 116 | std r30, 288(r1) ; save R30 117 | std r31, 296(r1) ; save R31 118 | 119 | ; save CR 120 | mfcr r0 121 | std r0, 304(r1) 122 | ; save LR 123 | mflr r0 124 | std r0, 312(r1) 125 | ; save LR as PC 126 | std r0, 320(r1) 127 | 128 | ; test if fpu env should be preserved 129 | cmpwi cr7, r6, 0 130 | beq cr7, l1 131 | 132 | stfd f14, 0(r1) ; save F14 133 | stfd f15, 8(r1) ; save F15 134 | stfd f16, 16(r1) ; save F16 135 | stfd f17, 24(r1) ; save F17 136 | stfd f18, 32(r1) ; save F18 137 | stfd f19, 40(r1) ; save F19 138 | stfd f20, 48(r1) ; save F20 139 | stfd f21, 56(r1) ; save F21 140 | stfd f22, 64(r1) ; save F22 141 | stfd f23, 72(r1) ; save F23 142 | stfd f24, 80(r1) ; save F24 143 | stfd f25, 88(r1) ; save F25 144 | stfd f26, 96(r1) ; save F26 145 | stfd f27, 104(r1) ; save F27 146 | stfd f28, 112(r1) ; save F28 147 | stfd f29, 120(r1) ; save F29 148 | stfd f30, 128(r1) ; save F30 149 | stfd f31, 136(r1) ; save F31 150 | mffs f0 ; load FPSCR 151 | stfd f0, 144(r1) ; save FPSCR 152 | 153 | l1: 154 | ; store RSP (pointing to context-data) in R3 155 | stw r1, 0(r3) 156 | 157 | ; restore RSP (pointing to context-data) from R4 158 | mr r1, r4 159 | 160 | ; test if fpu env should be preserved 161 | cmpwi cr7, r6, 0 162 | beq cr7, l2 163 | 164 | lfd f14, 0(r1) ; restore F14 165 | lfd f15, 8(r1) ; restore F15 166 | lfd f16, 16(r1) ; restore F16 167 | lfd f17, 24(r1) ; restore F17 168 | lfd f18, 32(r1) ; restore F18 169 | lfd f19, 40(r1) ; restore F19 170 | lfd f20, 48(r1) ; restore F20 171 | lfd f21, 56(r1) ; restore F21 172 | lfd f22, 64(r1) ; restore F22 173 | lfd f23, 72(r1) ; restore F23 174 | lfd f24, 80(r1) ; restore F24 175 | lfd f25, 88(r1) ; restore F25 176 | lfd f26, 96(r1) ; restore F26 177 | lfd f27, 104(r1) ; restore F27 178 | lfd f28, 112(r1) ; restore F28 179 | lfd f29, 120(r1) ; restore F29 180 | lfd f30, 128(r1) ; restore F30 181 | lfd f31, 136(r1) ; restore F31 182 | lfd f0, 144(r1) ; load FPSCR 183 | mtfsf 0xff, f0 ; restore FPSCR 184 | 185 | 2: 186 | ld r13, 152(r1) ; restore R13 187 | ld r14, 160(r1) ; restore R14 188 | ld r15, 168(r1) ; restore R15 189 | ld r16, 176(r1) ; restore R16 190 | ld r17, 184(r1) ; restore R17 191 | ld r18, 192(r1) ; restore R18 192 | ld r19, 200(r1) ; restore R19 193 | ld r20, 208(r1) ; restore R20 194 | ld r21, 216(r1) ; restore R21 195 | ld r22, 224(r1) ; restore R22 196 | ld r23, 232(r1) ; restore R23 197 | ld r24, 240(r1) ; restore R24 198 | ld r25, 248(r1) ; restore R25 199 | ld r26, 256(r1) ; restore R26 200 | ld r27, 264(r1) ; restore R27 201 | ld r28, 272(r1) ; restore R28 202 | ld r29, 280(r1) ; restore R29 203 | ld r30, 288(r1) ; restore R30 204 | ld r31, 296(r1) ; restore R31 205 | 206 | ; restore CR 207 | ld r0, 304(r1) 208 | mtcr r0 209 | ; restore LR 210 | ld r0, 312(r1) 211 | mtlr r0 212 | 213 | ; load PC 214 | ld r0, 320(r1) 215 | ; restore CTR 216 | mtctr r0 217 | 218 | ; adjust stack 219 | addi r1, r1, 328 220 | 221 | ; use third arg as return value after jump 222 | ; use third arg as first arg in context function 223 | mr r3, r5 224 | 225 | ; jump to context 226 | bctr 227 | -------------------------------------------------------------------------------- /src/asm/jump_ppc64_sysv_xcoff_gas.S: -------------------------------------------------------------------------------- 1 | .align 2 2 | .globl .jump_fcontext 3 | .jump_fcontext: 4 | # reserve space on stack 5 | subi 1, 1, 328 6 | 7 | std 13, 152(1) # save R13 8 | std 14, 160(1) # save R14 9 | std 15, 168(1) # save R15 10 | std 16, 176(1) # save R16 11 | std 17, 184(1) # save R17 12 | std 18, 192(1) # save R18 13 | std 19, 200(1) # save R19 14 | std 20, 208(1) # save R20 15 | std 21, 216(1) # save R21 16 | std 22, 224(1) # save R22 17 | std 23, 232(1) # save R23 18 | std 24, 240(1) # save R24 19 | std 25, 248(1) # save R25 20 | std 26, 256(1) # save R26 21 | std 27, 264(1) # save R27 22 | std 28, 272(1) # save R28 23 | std 29, 280(1) # save R29 24 | std 30, 288(1) # save R30 25 | std 31, 296(1) # save R31 26 | 27 | # save CR 28 | mfcr 0 29 | std 0, 304(1) 30 | # save LR 31 | mflr 0 32 | std 0, 312(1) 33 | # save LR as PC 34 | std 0, 320(1) 35 | 36 | # test if fpu env should be preserved 37 | cmpwi 7, 6, 0 38 | beq 7, label1 39 | 40 | stfd 14, 0(1) # save F14 41 | stfd 15, 8(1) # save F15 42 | stfd 16, 16(1) # save F16 43 | stfd 17, 24(1) # save F17 44 | stfd 18, 32(1) # save F18 45 | stfd 19, 40(1) # save F19 46 | stfd 20, 48(1) # save F20 47 | stfd 21, 56(1) # save F21 48 | stfd 22, 64(1) # save F22 49 | stfd 23, 72(1) # save F23 50 | stfd 24, 80(1) # save F24 51 | stfd 25, 88(1) # save F25 52 | stfd 26, 96(1) # save F26 53 | stfd 27, 104(1) # save F27 54 | stfd 28, 112(1) # save F28 55 | stfd 29, 120(1) # save F29 56 | stfd 30, 128(1) # save F30 57 | stfd 31, 136(1) # save F31 58 | mffs 0 # load FPSCR 59 | stfd 0, 144(1) # save FPSCR 60 | 61 | label1: 62 | # store RSP (pointing to context-data) in R3 63 | stw 1, 0(3) 64 | 65 | # restore RSP (pointing to context-data) from R4 66 | mr 1, 4 67 | 68 | # test if fpu env should be preserved 69 | cmpwi 7, 6, 0 70 | beq 7, label2 71 | 72 | lfd 14, 0(1) # restore F14 73 | lfd 15, 8(1) # restore F15 74 | lfd 16, 16(1) # restore F16 75 | lfd 17, 24(1) # restore F17 76 | lfd 18, 32(1) # restore F18 77 | lfd 19, 40(1) # restore F19 78 | lfd 20, 48(1) # restore F20 79 | lfd 21, 56(1) # restore F21 80 | lfd 22, 64(1) # restore F22 81 | lfd 23, 72(1) # restore F23 82 | lfd 24, 80(1) # restore F24 83 | lfd 25, 88(1) # restore F25 84 | lfd 26, 96(1) # restore F26 85 | lfd 27, 104(1) # restore F27 86 | lfd 28, 112(1) # restore F28 87 | lfd 29, 120(1) # restore F29 88 | lfd 30, 128(1) # restore F30 89 | lfd 31, 136(1) # restore F31 90 | lfd 0, 144(1) # load FPSCR 91 | mtfsf 0xff, 0 # restore FPSCR 92 | 93 | label2: 94 | ld 13, 152(1) # restore R13 95 | ld 14, 160(1) # restore R14 96 | ld 15, 168(1) # restore R15 97 | ld 16, 176(1) # restore R16 98 | ld 17, 184(1) # restore R17 99 | ld 18, 192(1) # restore R18 100 | ld 19, 200(1) # restore R19 101 | ld 20, 208(1) # restore R20 102 | ld 21, 216(1) # restore R21 103 | ld 22, 224(1) # restore R22 104 | ld 23, 232(1) # restore R23 105 | ld 24, 240(1) # restore R24 106 | ld 25, 248(1) # restore R25 107 | ld 26, 256(1) # restore R26 108 | ld 27, 264(1) # restore R27 109 | ld 28, 272(1) # restore R28 110 | ld 29, 280(1) # restore R29 111 | ld 30, 288(1) # restore R30 112 | ld 31, 296(1) # restore R31 113 | 114 | # restore CR 115 | ld 0, 304(1) 116 | mtcr 0 117 | # restore LR 118 | ld 0, 312(1) 119 | mtlr 0 120 | 121 | # load PC 122 | ld 0, 320(1) 123 | # restore CTR 124 | mtctr 0 125 | 126 | # adjust stack 127 | addi 1, 1, 328 128 | 129 | # use third arg as return value after jump 130 | # use third arg as first arg in context function 131 | mr 3, 5 132 | 133 | # jump to context 134 | bctr 135 | -------------------------------------------------------------------------------- /src/asm/jump_sparc64_sysv_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Martin Husemann 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************************* 9 | * * 10 | * ------------------------------------------------------------- * 11 | * | Offset (in 4 or 8 byte units) | Content | * 12 | * ------------------------------------------------------------- * 13 | * | 0 | %sp | * 14 | * ------------------------------------------------------------- * 15 | * | 1 | %pc | * 16 | * ------------------------------------------------------------- * 17 | * | 2 | %i7 (return address) | * 18 | * ------------------------------------------------------------- * 19 | * | 3 | %g1 | * 20 | * ------------------------------------------------------------- * 21 | * | 4 | %g2 | * 22 | * ------------------------------------------------------------- * 23 | * | 5 | %g3 | * 24 | * ------------------------------------------------------------- * 25 | * | 6 | %g6 | * 26 | * ------------------------------------------------------------- * 27 | * | 7 | %g7 | * 28 | * ------------------------------------------------------------- * 29 | * The local and in registers are stored on the stack. * 30 | *******************************************************************/ 31 | 32 | #define OFF(N) (8*(N)) 33 | #define CCFSZ 176 // C Compiler Frame Size 34 | #define BIAS (2048-1) // Stack offset for 64 bit programs 35 | #define FC_SZ 448 // sizeof(fcontext_t) 36 | #define FC_STK 384 // offsetof(fcontext_t, fc_stack) 37 | #define FC_FPU 0 // offsetof(fcontext_t, fc_fp) 38 | #define FC_FSR 264 // offsetof(fcontext_t, fc_fp.fp_fsr) 39 | #define FC_FPRS 256 // offsetof(fcontext_t, fc_fp.fp_fprs) 40 | #define FC_GREG 320 // offsetof(fcontext_t, fc_greg) 41 | #define BLOCK_SIZE 64 42 | 43 | .register %g2,#ignore 44 | .register %g3,#ignore 45 | .register %g6,#ignore 46 | 47 | .text 48 | .globl jump_fcontext 49 | .align 4 50 | .type jump_fcontext,@function 51 | // intptr_t 52 | // jump_fcontext( fcontext_t * ofc, fcontext_t const* nfc, intptr_t vp, 53 | // bool preserve_fpu = true); 54 | jump_fcontext: 55 | // %o0 = pointer to old fcontext, save current state here 56 | // %o1 = new context to jump to 57 | // %o2 = new return value in context %o0 58 | // %o3 = preserve fpu registers 59 | // Save current state in %o0 fcontext, then activate %o1. 60 | // If %o3, include fpu registers. 61 | 62 | flushw // make sure all shadow registers are up to date in the current stack 63 | 64 | // save current state to fcontext_t at %o0 65 | stx %sp, [%o0 + FC_GREG + OFF(0)] // current stack pointer 66 | add %o7, 8, %o4 // calculate next instruction past call 67 | stx %o4, [%o0 + FC_GREG + OFF(1)] // and store it as %pc in save context 68 | stx %o7, [%o0 + FC_GREG + OFF(2)] 69 | stx %g1, [%o0 + FC_GREG + OFF(3)] 70 | stx %g2, [%o0 + FC_GREG + OFF(4)] 71 | stx %g3, [%o0 + FC_GREG + OFF(5)] 72 | stx %g6, [%o0 + FC_GREG + OFF(6)] 73 | stx %g7, [%o0 + FC_GREG + OFF(7)] 74 | 75 | // do we need to handle fpu? 76 | brz %o3, Lno_fpu 77 | nop 78 | 79 | add %o0, FC_FPU, %o5 80 | stda %f0, [%o5] 0xf0 /* ASI_BLOCK_PRIMARY */ 81 | add %o5, BLOCK_SIZE, %o5 82 | stda %f16, [%o5] 0xf0 83 | add %o5, BLOCK_SIZE, %o5 84 | stda %f32, [%o5] 0xf0 85 | add %o5, BLOCK_SIZE, %o5 86 | stda %f48, [%o5] 0xf0 87 | stx %fsr, [%o0+FC_FSR] 88 | rd %fprs, %o4 89 | stx %o4, [%o0+FC_FPRS] 90 | 91 | add %o1, FC_FPU, %o5 92 | ldda [%o5] 0xf0 /* ASI_BLOCK_PRIMARY */, %f0 93 | add %o5, BLOCK_SIZE, %o5 94 | ldda [%o5] 0xf0, %f16 95 | add %o5, BLOCK_SIZE, %o5 96 | ldda [%o5] 0xf0, %f32 97 | add %o5, BLOCK_SIZE, %o5 98 | ldda [%o5] 0xf0, %f48 99 | ldx [%o1+FC_FSR], %fsr 100 | ldx [%o1+FC_FPRS], %o4 101 | wr %o4,0,%fprs 102 | 103 | Lno_fpu: 104 | // load new state from %o1 105 | ldx [%o1 + FC_GREG + OFF(1)], %o4 106 | ldx [%o1 + FC_GREG + OFF(2)], %o7 107 | ldx [%o1 + FC_GREG + OFF(3)], %g1 108 | ldx [%o1 + FC_GREG + OFF(4)], %g2 109 | ldx [%o1 + FC_GREG + OFF(5)], %g3 110 | ldx [%o1 + FC_GREG + OFF(6)], %g6 111 | ldx [%o1 + FC_GREG + OFF(7)], %g7 112 | // switch to new stack 113 | ldx [%o1 + FC_GREG + OFF(0)], %sp 114 | // and now reload from this stack the shadow regist bank contents 115 | ldx [%sp + BIAS + OFF(0)], %l0 116 | ldx [%sp + BIAS + OFF(1)], %l1 117 | ldx [%sp + BIAS + OFF(2)], %l2 118 | ldx [%sp + BIAS + OFF(3)], %l3 119 | ldx [%sp + BIAS + OFF(4)], %l4 120 | ldx [%sp + BIAS + OFF(5)], %l5 121 | ldx [%sp + BIAS + OFF(6)], %l6 122 | ldx [%sp + BIAS + OFF(7)], %l7 123 | ldx [%sp + BIAS + OFF(8)], %i0 124 | ldx [%sp + BIAS + OFF(9)], %i1 125 | ldx [%sp + BIAS + OFF(10)], %i2 126 | ldx [%sp + BIAS + OFF(11)], %i3 127 | ldx [%sp + BIAS + OFF(12)], %i4 128 | ldx [%sp + BIAS + OFF(13)], %i5 129 | ldx [%sp + BIAS + OFF(14)], %i6 130 | ldx [%sp + BIAS + OFF(15)], %i7 131 | 132 | // finally continue execution in new context 133 | jmp %o4 134 | mov %o2, %o0 // return arg as result 135 | 136 | .size jump_fcontext,.-jump_fcontext 137 | 138 | /* Mark that we don't need executable stack. */ 139 | .section .note.GNU-stack,"",%progbits 140 | -------------------------------------------------------------------------------- /src/asm/jump_sparc_sysv_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Martin Husemann 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************************* 9 | * * 10 | * ------------------------------------------------------------- * 11 | * | Offset (in 4 or 8 byte units) | Content | * 12 | * ------------------------------------------------------------- * 13 | * | 0 | %sp | * 14 | * ------------------------------------------------------------- * 15 | * | 1 | %pc | * 16 | * ------------------------------------------------------------- * 17 | * | 2 | %i7 (return address) | * 18 | * ------------------------------------------------------------- * 19 | * | 3 | %g1 | * 20 | * ------------------------------------------------------------- * 21 | * | 4 | %g2 | * 22 | * ------------------------------------------------------------- * 23 | * | 5 | %g3 | * 24 | * ------------------------------------------------------------- * 25 | * | 6 | %g6 | * 26 | * ------------------------------------------------------------- * 27 | * | 7 | %g7 | * 28 | * ------------------------------------------------------------- * 29 | * The local and in registers are stored on the stack. * 30 | *******************************************************************/ 31 | 32 | #define OFF(N) (4*(N)) 33 | #define CCFSZ 96 34 | #define FC_SZ 176 35 | #define FC_stK 168 // offsetof(fcontext_t, fc_stack) 36 | #define FC_FPU 0 // offsetof(fcontext_t, fc_fp) 37 | #define FC_FSR 128 // offsetof(fcontext_t, fc_fp.fp_fsr) 38 | #define FC_GREG 136 // offsetof(fcontext_t, fc_greg) 39 | #define BLOCK_SIZE 8 40 | #ifdef __NetBSD__ 41 | #define FLUSHW t 0x83; nop // T_FLUSHWIN 42 | #endif 43 | 44 | .text 45 | .globl jump_fcontext 46 | .align 4 47 | .type jump_fcontext,@function 48 | // intptr_t 49 | // jump_fcontext( fcontext_t * ofc, fcontext_t const* nfc, intptr_t vp, 50 | // bool preserve_fpu = true); 51 | jump_fcontext: 52 | // %o0 = pointer to old fcontext, save current state here 53 | // %o1 = new context to jump to 54 | // %o2 = new return value in context %o0 55 | // %o3 = preserve fpu registers 56 | // Save current state in %o0 fcontext, then activate %o1. 57 | // If %o3, include fpu registers. 58 | 59 | FLUSHW // make sure all shadow registers are up to date in the current stack 60 | 61 | // save current state to fcontext_t at %o0 62 | st %sp, [%o0 + FC_GREG + OFF(0)] // current stack pointer 63 | add %o7, 8, %o4 // calculate next instruction past call 64 | st %o4, [%o0 + FC_GREG + OFF(1)] // and store it as %pc in save context 65 | st %o7, [%o0 + FC_GREG + OFF(2)] 66 | st %g1, [%o0 + FC_GREG + OFF(3)] 67 | st %g2, [%o0 + FC_GREG + OFF(4)] 68 | st %g3, [%o0 + FC_GREG + OFF(5)] 69 | st %g6, [%o0 + FC_GREG + OFF(6)] 70 | st %g7, [%o0 + FC_GREG + OFF(7)] 71 | 72 | // do we need to handle fpu? 73 | cmp %o3, 0 74 | bz Lno_fpu 75 | nop 76 | 77 | add %o0, FC_FPU, %o5 78 | std %f0, [%o5] 79 | std %f2, [%o5+0x08] 80 | std %f4, [%o5+0x10] 81 | std %f6, [%o5+0x18] 82 | std %f8, [%o5+0x20] 83 | std %f10, [%o5+0x28] 84 | std %f12, [%o5+0x30] 85 | std %f14, [%o5+0x38] 86 | st %fsr, [%o0+FC_FSR] 87 | 88 | add %o1, FC_FPU, %o5 89 | ldd [%o5], %f0 90 | ldd [%o5+0x08], %f2 91 | ldd [%o5+0x10], %f4 92 | ldd [%o5+0x18], %f6 93 | ldd [%o5+0x20], %f8 94 | ldd [%o5+0x28], %f10 95 | ldd [%o5+0x30], %f12 96 | ldd [%o5+0x38], %f14 97 | ld [%o1+FC_FSR], %fsr 98 | 99 | Lno_fpu: 100 | // load new state from %o1 101 | ld [%o1 + FC_GREG + OFF(1)], %o4 102 | ld [%o1 + FC_GREG + OFF(2)], %o7 103 | ld [%o1 + FC_GREG + OFF(3)], %g1 104 | ld [%o1 + FC_GREG + OFF(4)], %g2 105 | ld [%o1 + FC_GREG + OFF(5)], %g3 106 | ld [%o1 + FC_GREG + OFF(6)], %g6 107 | ld [%o1 + FC_GREG + OFF(7)], %g7 108 | // switch to new stack 109 | ld [%o1 + FC_GREG + OFF(0)], %sp 110 | // and now reload from this stack the shadow regist bank contents 111 | ld [%sp + OFF(0)], %l0 112 | ld [%sp + OFF(1)], %l1 113 | ld [%sp + OFF(2)], %l2 114 | ld [%sp + OFF(3)], %l3 115 | ld [%sp + OFF(4)], %l4 116 | ld [%sp + OFF(5)], %l5 117 | ld [%sp + OFF(6)], %l6 118 | ld [%sp + OFF(7)], %l7 119 | ld [%sp + OFF(8)], %i0 120 | ld [%sp + OFF(9)], %i1 121 | ld [%sp + OFF(10)], %i2 122 | ld [%sp + OFF(11)], %i3 123 | ld [%sp + OFF(12)], %i4 124 | ld [%sp + OFF(13)], %i5 125 | ld [%sp + OFF(14)], %i6 126 | ld [%sp + OFF(15)], %i7 127 | 128 | // finally continue execution in new context 129 | jmp %o4 130 | mov %o2, %o0 // return arg as result 131 | 132 | .size jump_fcontext,.-jump_fcontext 133 | 134 | /* Mark that we don't need executable stack. */ 135 | .section .note.GNU-stack,"",%progbits 136 | -------------------------------------------------------------------------------- /src/asm/jump_x86_64_sysv_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /**************************************************************************************** 9 | * * 10 | * ---------------------------------------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ---------------------------------------------------------------------------------- * 13 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * 14 | * ---------------------------------------------------------------------------------- * 15 | * | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | * 16 | * ---------------------------------------------------------------------------------- * 17 | * ---------------------------------------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ---------------------------------------------------------------------------------- * 20 | * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * 21 | * ---------------------------------------------------------------------------------- * 22 | * | R15 | RBX | RBP | RIP | * 23 | * ---------------------------------------------------------------------------------- * 24 | * ---------------------------------------------------------------------------------- * 25 | * | 16 | 17 | | * 26 | * ---------------------------------------------------------------------------------- * 27 | * | 0x40 | 0x44 | | * 28 | * ---------------------------------------------------------------------------------- * 29 | * | EXIT | | * 30 | * ---------------------------------------------------------------------------------- * 31 | * * 32 | ****************************************************************************************/ 33 | 34 | .text 35 | .globl jump_fcontext 36 | .type jump_fcontext,@function 37 | .align 16 38 | jump_fcontext: 39 | pushq %rbp /* save RBP */ 40 | pushq %rbx /* save RBX */ 41 | pushq %r15 /* save R15 */ 42 | pushq %r14 /* save R14 */ 43 | pushq %r13 /* save R13 */ 44 | pushq %r12 /* save R12 */ 45 | 46 | /* prepare stack for FPU */ 47 | leaq -0x8(%rsp), %rsp 48 | 49 | /* test for flag preserve_fpu */ 50 | cmp $0, %rcx 51 | je 1f 52 | 53 | /* save MMX control- and status-word */ 54 | stmxcsr (%rsp) 55 | /* save x87 control-word */ 56 | fnstcw 0x4(%rsp) 57 | 58 | 1: 59 | /* store RSP (pointing to context-data) in RDI */ 60 | movq %rsp, (%rdi) 61 | 62 | /* restore RSP (pointing to context-data) from RSI */ 63 | movq %rsi, %rsp 64 | 65 | /* test for flag preserve_fpu */ 66 | cmp $0, %rcx 67 | je 2f 68 | 69 | /* restore MMX control- and status-word */ 70 | ldmxcsr (%rsp) 71 | /* restore x87 control-word */ 72 | fldcw 0x4(%rsp) 73 | 74 | 2: 75 | /* prepare stack for FPU */ 76 | leaq 0x8(%rsp), %rsp 77 | 78 | popq %r12 /* restrore R12 */ 79 | popq %r13 /* restrore R13 */ 80 | popq %r14 /* restrore R14 */ 81 | popq %r15 /* restrore R15 */ 82 | popq %rbx /* restrore RBX */ 83 | popq %rbp /* restrore RBP */ 84 | 85 | /* restore return-address */ 86 | popq %r8 87 | 88 | /* use third arg as return-value after jump */ 89 | movq %rdx, %rax 90 | /* use third arg as first arg in context function */ 91 | movq %rdx, %rdi 92 | 93 | /* indirect jump to context */ 94 | jmp *%r8 95 | .size jump_fcontext,.-jump_fcontext 96 | 97 | /* Mark that we don't need executable stack. */ 98 | .section .note.GNU-stack,"",%progbits 99 | -------------------------------------------------------------------------------- /src/asm/jump_x86_64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /**************************************************************************************** 9 | * * 10 | * ---------------------------------------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ---------------------------------------------------------------------------------- * 13 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * 14 | * ---------------------------------------------------------------------------------- * 15 | * | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | * 16 | * ---------------------------------------------------------------------------------- * 17 | * ---------------------------------------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ---------------------------------------------------------------------------------- * 20 | * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * 21 | * ---------------------------------------------------------------------------------- * 22 | * | R15 | RBX | RBP | RIP | * 23 | * ---------------------------------------------------------------------------------- * 24 | * ---------------------------------------------------------------------------------- * 25 | * | 16 | 17 | | * 26 | * ---------------------------------------------------------------------------------- * 27 | * | 0x40 | 0x44 | | * 28 | * ---------------------------------------------------------------------------------- * 29 | * | EXIT | | * 30 | * ---------------------------------------------------------------------------------- * 31 | * * 32 | ****************************************************************************************/ 33 | 34 | .text 35 | .globl _jump_fcontext 36 | .align 8 37 | _jump_fcontext: 38 | pushq %rbp /* save RBP */ 39 | pushq %rbx /* save RBX */ 40 | pushq %r15 /* save R15 */ 41 | pushq %r14 /* save R14 */ 42 | pushq %r13 /* save R13 */ 43 | pushq %r12 /* save R12 */ 44 | 45 | /* prepare stack for FPU */ 46 | leaq -0x8(%rsp), %rsp 47 | 48 | /* test for flag preserve_fpu */ 49 | cmp $0, %rcx 50 | je 1f 51 | 52 | /* save MMX control- and status-word */ 53 | stmxcsr (%rsp) 54 | /* save x87 control-word */ 55 | fnstcw 0x4(%rsp) 56 | 57 | 1: 58 | /* store RSP (pointing to context-data) in RDI */ 59 | movq %rsp, (%rdi) 60 | 61 | /* restore RSP (pointing to context-data) from RSI */ 62 | movq %rsi, %rsp 63 | 64 | /* test for flag preserve_fpu */ 65 | cmp $0, %rcx 66 | je 2f 67 | 68 | /* restore MMX control- and status-word */ 69 | ldmxcsr (%rsp) 70 | /* restore x87 control-word */ 71 | fldcw 0x4(%rsp) 72 | 73 | 2: 74 | /* prepare stack for FPU */ 75 | leaq 0x8(%rsp), %rsp 76 | 77 | popq %r12 /* restrore R12 */ 78 | popq %r13 /* restrore R13 */ 79 | popq %r14 /* restrore R14 */ 80 | popq %r15 /* restrore R15 */ 81 | popq %rbx /* restrore RBX */ 82 | popq %rbp /* restrore RBP */ 83 | 84 | /* restore return-address */ 85 | popq %r8 86 | 87 | /* use third arg as return-value after jump */ 88 | movq %rdx, %rax 89 | /* use third arg as first arg in context function */ 90 | movq %rdx, %rdi 91 | 92 | /* indirect jump to context */ 93 | jmp *%r8 94 | -------------------------------------------------------------------------------- /src/asm/make_arm64_aapcs_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Edward Nevill 2015 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | /******************************************************* 8 | * * 9 | * ------------------------------------------------- * 10 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 11 | * ------------------------------------------------- * 12 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * 13 | * ------------------------------------------------- * 14 | * | d8 | d9 | d10 | d11 | * 15 | * ------------------------------------------------- * 16 | * ------------------------------------------------- * 17 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 18 | * ------------------------------------------------- * 19 | * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 20 | * ------------------------------------------------- * 21 | * | d12 | d13 | d14 | d15 | * 22 | * ------------------------------------------------- * 23 | * ------------------------------------------------- * 24 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 25 | * ------------------------------------------------- * 26 | * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * 27 | * ------------------------------------------------- * 28 | * | x19 | x20 | x21 | x22 | * 29 | * ------------------------------------------------- * 30 | * ------------------------------------------------- * 31 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 32 | * ------------------------------------------------- * 33 | * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * 34 | * ------------------------------------------------- * 35 | * | x23 | x24 | x25 | x26 | * 36 | * ------------------------------------------------- * 37 | * ------------------------------------------------- * 38 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 39 | * ------------------------------------------------- * 40 | * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * 41 | * ------------------------------------------------- * 42 | * | x27 | x28 | FP | LR | * 43 | * ------------------------------------------------- * 44 | * ------------------------------------------------- * 45 | * | 40 | 41 | 42 | 43 | | | * 46 | * ------------------------------------------------- * 47 | * | 0xa0| 0xa4| 0xa8| 0xac| | | * 48 | * ------------------------------------------------- * 49 | * | PC | align | | | * 50 | * ------------------------------------------------- * 51 | * * 52 | *******************************************************/ 53 | 54 | .cpu generic+fp+simd 55 | .text 56 | .align 2 57 | .global make_fcontext 58 | .type make_fcontext, %function 59 | make_fcontext: 60 | # shift address in x0 (allocated stack) to lower 16 byte boundary 61 | and x0, x0, ~0xF 62 | 63 | # reserve space for context-data on context-stack 64 | sub x0, x0, #0xb0 65 | 66 | # third arg of make_fcontext() == address of context-function 67 | # store address as a PC to jump in 68 | str x2, [x0, #0xa0] 69 | 70 | # save address of finish as return-address for context-function 71 | # will be entered after context-function returns (LR register) 72 | adr x1, finish 73 | str x1, [x0, #0x98] 74 | 75 | ret x30 // return pointer to context-data (x0) 76 | 77 | finish: 78 | # exit code is zero 79 | mov x0, #0 80 | # exit application 81 | bl _exit 82 | 83 | .size make_fcontext,.-make_fcontext 84 | # Mark that we don't need executable stack. 85 | .section .note.GNU-stack,"",%progbits 86 | -------------------------------------------------------------------------------- /src/asm/make_arm64_aapcs_macho_gas.S: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * * 3 | * ------------------------------------------------- * 4 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 5 | * ------------------------------------------------- * 6 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * 7 | * ------------------------------------------------- * 8 | * | d8 | d9 | d10 | d11 | * 9 | * ------------------------------------------------- * 10 | * ------------------------------------------------- * 11 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 12 | * ------------------------------------------------- * 13 | * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 14 | * ------------------------------------------------- * 15 | * | d12 | d13 | d14 | d15 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 19 | * ------------------------------------------------- * 20 | * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * 21 | * ------------------------------------------------- * 22 | * | x19 | x20 | x21 | x22 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 26 | * ------------------------------------------------- * 27 | * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * 28 | * ------------------------------------------------- * 29 | * | x23 | x24 | x25 | x26 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 33 | * ------------------------------------------------- * 34 | * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * 35 | * ------------------------------------------------- * 36 | * | x27 | x28 | FP | LR | * 37 | * ------------------------------------------------- * 38 | * ------------------------------------------------- * 39 | * | 40 | 41 | 42 | 43 | | | * 40 | * ------------------------------------------------- * 41 | * | 0xa0| 0xa4| 0xa8| 0xac| | | * 42 | * ------------------------------------------------- * 43 | * | PC | align | | | * 44 | * ------------------------------------------------- * 45 | * * 46 | *******************************************************/ 47 | 48 | 49 | .text 50 | .globl _make_fcontext 51 | .balign 16 52 | 53 | _make_fcontext: 54 | ; shift address in x0 (allocated stack) to lower 16 byte boundary 55 | and x0, x0, ~0xF 56 | 57 | ; reserve space for context-data on context-stack 58 | sub x0, x0, #0xb0 59 | 60 | ; third arg of make_fcontext() == address of context-function 61 | ; store address as a PC to jump in 62 | str x2, [x0, #0xa0] 63 | 64 | ; compute abs address of label finish 65 | ; 0x0c = 3 instructions * size (4) before label 'finish' 66 | 67 | ; TODO: Numeric offset since llvm still does not support labels in ADR. Fix: 68 | ; http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140407/212336.html 69 | adr x1, 0x0c 70 | 71 | ; save address of finish as return-address for context-function 72 | ; will be entered after context-function returns (LR register) 73 | str x1, [x0, #0x98] 74 | 75 | ret lr ; return pointer to context-data (x0) 76 | 77 | finish: 78 | ; exit code is zero 79 | mov x0, #0 80 | ; exit application 81 | bl __exit 82 | 83 | 84 | -------------------------------------------------------------------------------- /src/asm/make_arm_aapcs_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************* 9 | * * 10 | * ------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ------------------------------------------------- * 13 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * 14 | * ------------------------------------------------- * 15 | * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 21 | * ------------------------------------------------- * 22 | * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * 28 | * ------------------------------------------------- * 29 | * | v1 | v2 | v3 | v4 | v5 | v6 | v7 | v8 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | | * 33 | * ------------------------------------------------- * 34 | * | 0x60| 0x64| | * 35 | * ------------------------------------------------- * 36 | * | lr | pc | | * 37 | * ------------------------------------------------- * 38 | * * 39 | *******************************************************/ 40 | 41 | .text 42 | .globl make_fcontext 43 | .align 2 44 | .type make_fcontext,%function 45 | make_fcontext: 46 | @ shift address in A1 to lower 16 byte boundary 47 | bic a1, a1, #15 48 | 49 | @ reserve space for context-data on context-stack 50 | sub a1, a1, #104 51 | 52 | @ third arg of make_fcontext() == address of context-function 53 | str a3, [a1,#100] 54 | 55 | @ compute abs address of label finish 56 | adr a2, finish 57 | @ save address of finish as return-address for context-function 58 | @ will be entered after context-function returns 59 | str a2, [a1,#96] 60 | 61 | bx lr @ return pointer to context-data 62 | 63 | finish: 64 | @ exit code is zero 65 | mov a1, #0 66 | @ exit application 67 | bl _exit@PLT 68 | .size make_fcontext,.-make_fcontext 69 | 70 | @ Mark that we don't need executable stack. 71 | .section .note.GNU-stack,"",%progbits 72 | -------------------------------------------------------------------------------- /src/asm/make_arm_aapcs_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************* 9 | * * 10 | * ------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ------------------------------------------------- * 13 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * 14 | * ------------------------------------------------- * 15 | * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 21 | * ------------------------------------------------- * 22 | * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * 28 | * ------------------------------------------------- * 29 | * | sjlj| v1 | v2 | v3 | v4 | v5 | v6 | v7 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | | * 33 | * ------------------------------------------------- * 34 | * | 0x60| 0x64| 0x68| | * 35 | * ------------------------------------------------- * 36 | * | v8 | lr | pc | | * 37 | * ------------------------------------------------- * 38 | * * 39 | *******************************************************/ 40 | 41 | .text 42 | .globl _make_fcontext 43 | .align 2 44 | _make_fcontext: 45 | @ shift address in A1 to lower 16 byte boundary 46 | bic a1, a1, #15 47 | 48 | @ reserve space for context-data on context-stack 49 | sub a1, a1, #108 50 | 51 | @ third arg of make_fcontext() == address of context-function 52 | str a3, [a1,#104] 53 | 54 | @ compute abs address of label finish 55 | adr a2, finish 56 | @ save address of finish as return-address for context-function 57 | @ will be entered after context-function returns 58 | str a2, [a1,#100] 59 | 60 | bx lr @ return pointer to context-data 61 | 62 | finish: 63 | @ exit code is zero 64 | mov a1, #0 65 | @ exit application 66 | bl __exit 67 | -------------------------------------------------------------------------------- /src/asm/make_arm_aapcs_pe_armasm.asm: -------------------------------------------------------------------------------- 1 | ;/* 2 | ; Copyright Oliver Kowalke 2009. 3 | ; Distributed under the Boost Software License, Version 1.0. 4 | ; (See accompanying file LICENSE_1_0.txt or copy at 5 | ; http://www.boost.org/LICENSE_1_0.txt) 6 | ;*/ 7 | 8 | ; ******************************************************* 9 | ; * * 10 | ; * ------------------------------------------------- * 11 | ; * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | ; * ------------------------------------------------- * 13 | ; * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * 14 | ; * ------------------------------------------------- * 15 | ; * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | * 16 | ; * ------------------------------------------------- * 17 | ; * ------------------------------------------------- * 18 | ; * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | ; * ------------------------------------------------- * 20 | ; * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 21 | ; * ------------------------------------------------- * 22 | ; * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | * 23 | ; * ------------------------------------------------- * 24 | ; * ------------------------------------------------- * 25 | ; * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | ; * ------------------------------------------------- * 27 | ; * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * 28 | ; * ------------------------------------------------- * 29 | ; * |deall|limit| base| v1 | v2 | v3 | v4 | v5 | * 30 | ; * ------------------------------------------------- * 31 | ; * ------------------------------------------------- * 32 | ; * | 24 | 25 | 26 | 27 | 28 | | * 33 | ; * ------------------------------------------------- * 34 | ; * | 0x60| 0x64| 0x68| 0x6c| 0x70| | * 35 | ; * ------------------------------------------------- * 36 | ; * | v6 | v7 | v8 | lr | pc | | * 37 | ; * ------------------------------------------------- * 38 | ; * * 39 | ; ******************************************************* 40 | 41 | 42 | AREA |.text|, CODE 43 | ALIGN 4 44 | EXPORT make_fcontext 45 | IMPORT _exit 46 | 47 | make_fcontext PROC 48 | ; first arg of make_fcontext() == top of context-stack 49 | ; save top of context-stack (base) A4 50 | mov a4, a1 51 | 52 | ; shift address in A1 to lower 16 byte boundary 53 | bic a1, a1, #0x0f 54 | 55 | ; reserve space for context-data on context-stack 56 | sub a1, a1, #0x74 57 | 58 | ; save top address of context_stack as 'base' 59 | str a4, [a1,#0x48] 60 | ; second arg of make_fcontext() == size of context-stack 61 | ; compute bottom address of context-stack (limit) 62 | sub a4, a4, a2 63 | ; save bottom address of context-stack as 'limit' 64 | str a4, [a1,#0x44] 65 | ; save bottom address of context-stack as 'dealloction stack' 66 | str a4, [a1,#0x40] 67 | 68 | ; third arg of make_fcontext() == address of context-function 69 | str a3, [a1,#0x70] 70 | 71 | ; compute abs address of label finish 72 | adr a2, finish 73 | ; save address of finish as return-address for context-function 74 | ; will be entered after context-function returns 75 | str a2, [a1,#0x6c] 76 | 77 | bx lr ; return pointer to context-data 78 | 79 | finish 80 | ; exit code is zero 81 | mov a1, #0 82 | ; exit application 83 | bl _exit 84 | 85 | ENDP 86 | END 87 | -------------------------------------------------------------------------------- /src/asm/make_combined_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__i386__) 11 | #include "make_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "make_x86_64_sysv_macho_gas.S" 14 | #elif defined(__ppc__) 15 | #include "make_ppc32_sysv_macho_gas.S" 16 | #elif defined(__ppc64__) 17 | #include "make_ppc64_sysv_macho_gas.S" 18 | #else 19 | #error "No arch's" 20 | #endif 21 | -------------------------------------------------------------------------------- /src/asm/make_i386_ms_pe_gas.asm: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Copyright Thomas Sailer 2013. 4 | Distributed under the Boost Software License, Version 1.0. 5 | (See accompanying file LICENSE_1_0.txt or copy at 6 | http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | 9 | /******************************************************************** 10 | --------------------------------------------------------------------------------- 11 | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | --------------------------------------------------------------------------------- 13 | | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | 14 | --------------------------------------------------------------------------------- 15 | | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | 16 | --------------------------------------------------------------------------------- 17 | --------------------------------------------------------------------------------- 18 | | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | --------------------------------------------------------------------------------- 20 | | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | 21 | --------------------------------------------------------------------------------- 22 | | ESI | EBX | EBP | EIP | EXIT | | SEH NXT |SEH HNDLR| 23 | --------------------------------------------------------------------------------- 24 | *******************************************************************/ 25 | 26 | .file "make_i386_ms_pe_gas.asm" 27 | .text 28 | .p2align 4,,15 29 | .globl _make_fcontext 30 | .def _make_fcontext; .scl 2; .type 32; .endef 31 | _make_fcontext: 32 | /* first arg of make_fcontext() == top of context-stack */ 33 | movl 0x04(%esp), %eax 34 | 35 | /* reserve space for first argument of context-function */ 36 | /* EAX might already point to a 16byte border */ 37 | leal -0x08(%eax), %eax 38 | 39 | /* shift address in EAX to lower 16 byte boundary */ 40 | andl $-16, %eax 41 | 42 | /* reserve space for context-data on context-stack */ 43 | /* size for fc_mxcsr .. EIP + return-address for context-function */ 44 | /* on context-function entry: (ESP -0x4) % 8 == 0 */ 45 | /* additional space is required for SEH */ 46 | leal -0x3c(%eax), %eax 47 | 48 | /* first arg of make_fcontext() == top of context-stack */ 49 | movl 0x04(%esp), %ecx 50 | /* save top address of context stack as 'base' */ 51 | movl %ecx, 0x14(%eax) 52 | /* second arg of make_fcontext() == size of context-stack */ 53 | movl 0x08(%esp), %edx 54 | /* negate stack size for LEA instruction (== substraction) */ 55 | negl %edx 56 | /* compute bottom address of context stack (limit) */ 57 | leal (%ecx,%edx), %ecx 58 | /* save bottom address of context-stack as 'limit' */ 59 | movl %ecx, 0x10(%eax) 60 | /* save bottom address of context-stack as 'dealloction stack' */ 61 | movl %ecx, 0xc(%eax) 62 | 63 | /* third arg of make_fcontext() == address of context-function */ 64 | movl 0xc(%esp), %ecx 65 | movl %ecx, 0x2c(%eax) 66 | 67 | /* save MMX control- and status-word */ 68 | stmxcsr (%eax) 69 | /* save x87 control-word */ 70 | fnstcw 0x04(%eax) 71 | 72 | /* compute abs address of label finish */ 73 | movl $finish, %ecx 74 | /* save address of finish as return-address for context-function */ 75 | /* will be entered after context-function returns */ 76 | movl %ecx, 0x30(%eax) 77 | 78 | /* traverse current seh chain to get the last exception handler installed by Windows */ 79 | /* note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default */ 80 | /* the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler */ 81 | /* at its end by RaiseException all seh andlers are disregarded if not present and the */ 82 | /* program is aborted */ 83 | /* load NT_TIB into ECX */ 84 | movl %fs:(0x0), %ecx 85 | 86 | walk: 87 | /* load 'next' member of current SEH into EDX */ 88 | movl (%ecx), %edx 89 | /* test if 'next' of current SEH is last (== 0xffffffff) */ 90 | incl %edx 91 | jz found 92 | decl %edx 93 | /* exchange content; ECX contains address of next SEH */ 94 | xchgl %ecx, %edx 95 | /* inspect next SEH */ 96 | jmp walk 97 | 98 | found: 99 | /* load 'handler' member of SEH == address of last SEH handler installed by Windows */ 100 | movl 0x04(%ecx), %ecx 101 | /* save address in ECX as SEH handler for context */ 102 | movl %ecx, 0x3c(%eax) 103 | /* set ECX to -1 */ 104 | movl $0xffffffff, %ecx 105 | /* save ECX as next SEH item */ 106 | movl %ecx, 0x38(%eax) 107 | /* load address of next SEH item */ 108 | leal 0x38(%eax), %ecx 109 | /* save next SEH */ 110 | movl %ecx, 0x18(%eax) 111 | 112 | /* return pointer to context-data */ 113 | ret 114 | 115 | finish: 116 | /* ESP points to same address as ESP on entry of context function + 0x4 */ 117 | xorl %eax, %eax 118 | /* exit code is zero */ 119 | movl %eax, (%esp) 120 | /* exit application */ 121 | call __exit 122 | hlt 123 | 124 | .def __exit; .scl 2; .type 32; .endef /* standard C library function */ 125 | -------------------------------------------------------------------------------- /src/asm/make_i386_ms_pe_masm.asm: -------------------------------------------------------------------------------- 1 | 2 | ; Copyright Oliver Kowalke 2009. 3 | ; Distributed under the Boost Software License, Version 1.0. 4 | ; (See accompanying file LICENSE_1_0.txt or copy at 5 | ; http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | ; --------------------------------------------------------------------------------- 8 | ; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | ; --------------------------------------------------------------------------------- 10 | ; | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | 11 | ; --------------------------------------------------------------------------------- 12 | ; | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | 13 | ; --------------------------------------------------------------------------------- 14 | ; --------------------------------------------------------------------------------- 15 | ; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | ; --------------------------------------------------------------------------------- 17 | ; | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | 18 | ; --------------------------------------------------------------------------------- 19 | ; | ESI | EBX | EBP | EIP | EXIT | | SEH NXT |SEH HNDLR| 20 | ; --------------------------------------------------------------------------------- 21 | 22 | .386 23 | .XMM 24 | .model flat, c 25 | ; standard C library function 26 | _exit PROTO, value:SDWORD 27 | .code 28 | 29 | make_fcontext PROC 30 | ; first arg of make_fcontext() == top of context-stack 31 | mov eax, [esp+04h] 32 | 33 | ; reserve space for first argument of context-function 34 | ; EAX might already point to a 16byte border 35 | lea eax, [eax-08h] 36 | 37 | ; shift address in EAX to lower 16 byte boundary 38 | and eax, -16 39 | 40 | ; reserve space for context-data on context-stack 41 | ; size for fc_mxcsr .. EIP + return-address for context-function 42 | ; on context-function entry: (ESP -0x4) % 8 == 0 43 | ; additional space is required for SEH 44 | lea eax, [eax-03ch] 45 | 46 | ; first arg of make_fcontext() == top of context-stack 47 | mov ecx, [esp+04h] 48 | ; save top address of context stack as 'base' 49 | mov [eax+014h], ecx 50 | ; second arg of make_fcontext() == size of context-stack 51 | mov edx, [esp+08h] 52 | ; negate stack size for LEA instruction (== substraction) 53 | neg edx 54 | ; compute bottom address of context stack (limit) 55 | lea ecx, [ecx+edx] 56 | ; save bottom address of context-stack as 'limit' 57 | mov [eax+010h], ecx 58 | ; save bottom address of context-stack as 'dealloction stack' 59 | mov [eax+0ch], ecx 60 | 61 | ; third arg of make_fcontext() == address of context-function 62 | mov ecx, [esp+0ch] 63 | mov [eax+02ch], ecx 64 | 65 | ; save MMX control- and status-word 66 | stmxcsr [eax] 67 | ; save x87 control-word 68 | fnstcw [eax+04h] 69 | 70 | ; compute abs address of label finish 71 | mov ecx, finish 72 | ; save address of finish as return-address for context-function 73 | ; will be entered after context-function returns 74 | mov [eax+030h], ecx 75 | 76 | ; traverse current seh chain to get the last exception handler installed by Windows 77 | ; note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default 78 | ; the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler 79 | ; at its end by RaiseException all seh-handlers are disregarded if not present and the 80 | ; program is aborted 81 | assume fs:nothing 82 | ; load NT_TIB into ECX 83 | mov ecx, fs:[0h] 84 | assume fs:error 85 | 86 | walk: 87 | ; load 'next' member of current SEH into EDX 88 | mov edx, [ecx] 89 | ; test if 'next' of current SEH is last (== 0xffffffff) 90 | inc edx 91 | jz found 92 | dec edx 93 | ; exchange content; ECX contains address of next SEH 94 | xchg edx, ecx 95 | ; inspect next SEH 96 | jmp walk 97 | 98 | found: 99 | ; load 'handler' member of SEH == address of last SEH handler installed by Windows 100 | mov ecx, [ecx+04h] 101 | ; save address in ECX as SEH handler for context 102 | mov [eax+03ch], ecx 103 | ; set ECX to -1 104 | mov ecx, 0ffffffffh 105 | ; save ECX as next SEH item 106 | mov [eax+038h], ecx 107 | ; load address of next SEH item 108 | lea ecx, [eax+038h] 109 | ; save next SEH 110 | mov [eax+018h], ecx 111 | 112 | ret ; return pointer to context-data 113 | 114 | finish: 115 | ; exit code is zero 116 | xor eax, eax 117 | mov [esp], eax 118 | ; exit application 119 | call _exit 120 | hlt 121 | make_fcontext ENDP 122 | END 123 | -------------------------------------------------------------------------------- /src/asm/make_i386_sysv_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /**************************************************************************************** 9 | * * 10 | * ---------------------------------------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ---------------------------------------------------------------------------------- * 13 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * 14 | * ---------------------------------------------------------------------------------- * 15 | * | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | EXIT | * 16 | * ---------------------------------------------------------------------------------- * 17 | * * 18 | ****************************************************************************************/ 19 | 20 | .text 21 | .globl make_fcontext 22 | .align 2 23 | .type make_fcontext,@function 24 | make_fcontext: 25 | /* first arg of make_fcontext() == top of context-stack */ 26 | movl 0x4(%esp), %eax 27 | 28 | /* reserve space for first argument of context-function 29 | rax might already point to a 16byte border */ 30 | leal -0x8(%eax), %eax 31 | 32 | /* shift address in EAX to lower 16 byte boundary */ 33 | andl $-16, %eax 34 | 35 | /* reserve space for context-data on context-stack */ 36 | /* size for fc_mxcsr .. EIP + return-address for context-function */ 37 | /* on context-function entry: (ESP -0x4) % 8 == 0 */ 38 | leal -0x20(%eax), %eax 39 | 40 | /* third arg of make_fcontext() == address of context-function */ 41 | movl 0xc(%esp), %edx 42 | movl %edx, 0x18(%eax) 43 | 44 | /* save MMX control- and status-word */ 45 | stmxcsr (%eax) 46 | /* save x87 control-word */ 47 | fnstcw 0x4(%eax) 48 | 49 | /* compute abs address of label finish */ 50 | call 1f 51 | /* address of label 1 */ 52 | 1: popl %ecx 53 | /* compute abs address of label finish */ 54 | addl $finish-1b, %ecx 55 | /* save address of finish as return-address for context-function */ 56 | /* will be entered after context-function returns */ 57 | movl %ecx, 0x1c(%eax) 58 | 59 | ret /* return pointer to context-data */ 60 | 61 | finish: 62 | call 2f 63 | /* address of label 2 */ 64 | 2: popl %ebx 65 | /* compute address of GOT and store it in EBX */ 66 | addl $_GLOBAL_OFFSET_TABLE_+[.-2b], %ebx 67 | 68 | /* exit code is zero */ 69 | xorl %eax, %eax 70 | movl %eax, (%esp) 71 | /* exit application */ 72 | call _exit@PLT 73 | hlt 74 | .size make_fcontext,.-make_fcontext 75 | 76 | /* Mark that we don't need executable stack. */ 77 | .section .note.GNU-stack,"",%progbits 78 | -------------------------------------------------------------------------------- /src/asm/make_i386_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /**************************************************************************************** 9 | * * 10 | * ---------------------------------------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ---------------------------------------------------------------------------------- * 13 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * 14 | * ---------------------------------------------------------------------------------- * 15 | * | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | EXIT | * 16 | * ---------------------------------------------------------------------------------- * 17 | * * 18 | ****************************************************************************************/ 19 | 20 | .text 21 | .globl _make_fcontext 22 | .align 2 23 | _make_fcontext: 24 | /* first arg of make_fcontext() == top of context-stack */ 25 | movl 0x4(%esp), %eax 26 | 27 | /* reserve space for first argument of context-function 28 | rax might already point to a 16byte border */ 29 | leal -0x8(%eax), %eax 30 | 31 | /* shift address in EAX to lower 16 byte boundary */ 32 | andl $-16, %eax 33 | 34 | /* reserve space for context-data on context-stack */ 35 | /* size for fc_mxcsr .. EIP + return-address for context-function */ 36 | /* on context-function entry: (ESP -0x4) % 8 == 0 */ 37 | leal -0x20(%eax), %eax 38 | 39 | /* thrid arg of make_fcontext() == address of context-function */ 40 | movl 0xc(%esp), %edx 41 | movl %edx, 0x18(%eax) 42 | 43 | /* save MMX control- and status-word */ 44 | stmxcsr (%eax) 45 | /* save x87 control-word */ 46 | fnstcw 0x4(%eax) 47 | 48 | /* compute abs address of label finish */ 49 | call 1f 50 | /* address of label 1 */ 51 | 1: popl %ecx 52 | /* compute abs address of label finish */ 53 | addl $finish-1b, %ecx 54 | /* save address of finish as return-address for context-function */ 55 | /* will be entered after context-function returns */ 56 | movl %ecx, 0x1c(%eax) 57 | 58 | ret /* return pointer to context-data */ 59 | 60 | finish: 61 | /* exit code is zero */ 62 | xorl %eax, %eax 63 | movl %eax, (%esp) 64 | /* exit application */ 65 | call __exit 66 | hlt 67 | -------------------------------------------------------------------------------- /src/asm/make_i386_x86_64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__i386__) 11 | #include "make_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "make_x86_64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /src/asm/make_mips32_o32_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************* 9 | * * 10 | * ------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ------------------------------------------------- * 13 | * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * 14 | * ------------------------------------------------- * 15 | * | F20 | F22 | F24 | F26 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * 21 | * ------------------------------------------------- * 22 | * | F28 | F30 | S0 | S1 | S2 | S3 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | | * 26 | * ------------------------------------------------- * 27 | * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | | * 28 | * ------------------------------------------------- * 29 | * | S4 | S5 | S6 | S7 | FP | RA | PC | | * 30 | * ------------------------------------------------- * 31 | * * 32 | * *****************************************************/ 33 | 34 | .text 35 | .globl make_fcontext 36 | .align 2 37 | .type make_fcontext,@function 38 | .ent make_fcontext 39 | make_fcontext: 40 | #ifdef __PIC__ 41 | .set noreorder 42 | .cpload $t9 43 | .set reorder 44 | #endif 45 | # first arg of make_fcontext() == top address of context-stack 46 | move $v0, $a0 47 | 48 | # shift address in A0 to lower 16 byte boundary 49 | move $v1, $v0 50 | li $v0, -16 # 0xfffffffffffffff0 51 | and $v0, $v1, $v0 52 | 53 | # reserve space for context-data on context-stack 54 | # including 48 byte of shadow space (sp % 16 == 0) 55 | addiu $v0, $v0, -140 56 | 57 | # third arg of make_fcontext() == address of context-function 58 | sw $a2, 88($v0) 59 | # save global pointer in context-data 60 | # S0 will contain address of global pointer 61 | sw $gp, 48($v0) 62 | 63 | # compute abs address of label finish 64 | la $t9, finish 65 | # save address of finish as return-address for context-function 66 | # will be entered after context-function returns 67 | sw $t9, 84($v0) 68 | 69 | jr $ra # return pointer to context-data 70 | 71 | finish: 72 | # allocate stack space (contains shadow space for subroutines) 73 | addiu $sp, $sp, -32 74 | # save return address 75 | sw $ra, 28($sp) 76 | 77 | # restore GP (global pointer) 78 | move $gp, $s0 79 | # exit code is zero 80 | move $a0, $zero 81 | # address of exit 82 | lw $t9, %call16(_exit)($gp) 83 | # exit application 84 | jalr $t9 85 | .end make_fcontext 86 | .size make_fcontext, .-make_fcontext 87 | 88 | /* Mark that we don't need executable stack. */ 89 | .section .note.GNU-stack,"",%progbits 90 | -------------------------------------------------------------------------------- /src/asm/make_ppc32_ppc64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__ppc__) 11 | #include "make_ppc32_sysv_macho_gas.S" 12 | #elif defined(__ppc64__) 13 | #include "make_ppc64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /src/asm/make_ppc32_sysv_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************* 9 | * * 10 | * ------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ------------------------------------------------- * 13 | * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * 14 | * ------------------------------------------------- * 15 | * | F14 | F15 | F16 | F17 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * 21 | * ------------------------------------------------- * 22 | * | F18 | F19 | F20 | F21 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * 28 | * ------------------------------------------------- * 29 | * | F22 | F23 | F24 | F25 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * 35 | * ------------------------------------------------- * 36 | * | F26 | F27 | F28 | F29 | * 37 | * ------------------------------------------------- * 38 | * ------------------------------------------------- * 39 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 40 | * ------------------------------------------------- * 41 | * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * 42 | * ------------------------------------------------- * 43 | * | F30 | F31 | fpscr | R13 | R14 | * 44 | * ------------------------------------------------- * 45 | * ------------------------------------------------- * 46 | * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * 47 | * ------------------------------------------------- * 48 | * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * 49 | * ------------------------------------------------- * 50 | * | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | * 51 | * ------------------------------------------------- * 52 | * ------------------------------------------------- * 53 | * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * 54 | * ------------------------------------------------- * 55 | * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * 56 | * ------------------------------------------------- * 57 | * | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | * 58 | * ------------------------------------------------- * 59 | * ------------------------------------------------- * 60 | * | 56 | 57 | 58 | 59 | | * 61 | * ------------------------------------------------- * 62 | * | 224 | 228 | 232 | 236 | | * 63 | * ------------------------------------------------- * 64 | * | R31 | CR | LR | PC | | * 65 | * ------------------------------------------------- * 66 | * * 67 | *******************************************************/ 68 | 69 | .text 70 | .globl make_fcontext 71 | .align 2 72 | .type make_fcontext,@function 73 | make_fcontext: 74 | # save return address into R6 75 | mflr %r6 76 | 77 | # first arg of make_fcontext() == top address of context-function 78 | # shift address in R3 to lower 16 byte boundary 79 | clrrwi %r3, %r3, 4 80 | 81 | # reserve space for context-data on context-stack 82 | # including 64 byte of linkage + parameter area (R1 % 16 == 0) 83 | subi %r3, %r3, 304 84 | 85 | # third arg of make_fcontext() == address of context-function 86 | stw %r5, 236(%r3) 87 | 88 | # load LR 89 | mflr %r0 90 | # jump to label 1 91 | bl 1f 92 | 1: 93 | # load LR into R4 94 | mflr %r4 95 | # compute abs address of label finish 96 | addi %r4, %r4, finish - 1b 97 | # restore LR 98 | mtlr %r0 99 | # save address of finish as return-address for context-function 100 | # will be entered after context-function returns 101 | stw %r4, 232(%r3) 102 | 103 | # restore return address from R6 104 | mtlr %r6 105 | 106 | blr # return pointer to context-data 107 | 108 | finish: 109 | # save return address into R0 110 | mflr %r0 111 | # save return address on stack, set up stack frame 112 | stw %r0, 4(%r1) 113 | # allocate stack space, R1 % 16 == 0 114 | stwu %r1, -16(%r1) 115 | 116 | # exit code is zero 117 | li %r3, 0 118 | # exit application 119 | bl _exit@plt 120 | .size make_fcontext, .-make_fcontext 121 | 122 | /* Mark that we don't need executable stack. */ 123 | .section .note.GNU-stack,"",%progbits 124 | -------------------------------------------------------------------------------- /src/asm/make_ppc32_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************* 9 | * * 10 | * ------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ------------------------------------------------- * 13 | * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * 14 | * ------------------------------------------------- * 15 | * | F14 | F15 | F16 | F17 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * 21 | * ------------------------------------------------- * 22 | * | F18 | F19 | F20 | F21 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * 28 | * ------------------------------------------------- * 29 | * | F22 | F23 | F24 | F25 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * 35 | * ------------------------------------------------- * 36 | * | F26 | F27 | F28 | F29 | * 37 | * ------------------------------------------------- * 38 | * ------------------------------------------------- * 39 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 40 | * ------------------------------------------------- * 41 | * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * 42 | * ------------------------------------------------- * 43 | * | F30 | F31 | fpscr | R13 | R14 | * 44 | * ------------------------------------------------- * 45 | * ------------------------------------------------- * 46 | * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * 47 | * ------------------------------------------------- * 48 | * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * 49 | * ------------------------------------------------- * 50 | * | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | * 51 | * ------------------------------------------------- * 52 | * ------------------------------------------------- * 53 | * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * 54 | * ------------------------------------------------- * 55 | * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * 56 | * ------------------------------------------------- * 57 | * | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | * 58 | * ------------------------------------------------- * 59 | * ------------------------------------------------- * 60 | * | 56 | 57 | 58 | 59 | | * 61 | * ------------------------------------------------- * 62 | * | 224 | 228 | 232 | 236 | | * 63 | * ------------------------------------------------- * 64 | * | R31 | CR | LR | PC | | * 65 | * ------------------------------------------------- * 66 | * * 67 | *******************************************************/ 68 | 69 | .text 70 | .globl _make_fcontext 71 | .align 2 72 | _make_fcontext: 73 | ; save return address into R6 74 | mflr r6 75 | 76 | ; first arg of make_fcontext() == top address of context-function 77 | ; shift address in R3 to lower 16 byte boundary 78 | clrrwi r3, r3, 4 79 | 80 | ; reserve space for context-data on context-stack 81 | ; including 64 byte of linkage + parameter area (R1 % 16 == 0) 82 | subi r3, r3, 304 83 | 84 | ; third arg of make_fcontext() == address of context-function 85 | stw r5, 236(r3) 86 | 87 | ; load LR 88 | mflr r0 89 | ; jump to label 1 90 | bl l1 91 | l1: 92 | ; load LR into R4 93 | mflr r4 94 | ; compute abs address of label finish 95 | addi r4, r4, lo16((finish - .)+4) 96 | # restore LR 97 | mtlr r0 98 | ; save address of finish as return-address for context-function 99 | ; will be entered after context-function returns 100 | stw r4, 232(r3) 101 | 102 | ; restore return address from R6 103 | mtlr r6 104 | 105 | blr ; return pointer to context-data 106 | 107 | finish: 108 | ; save return address into R0 109 | mflr r0 110 | ; save return address on stack, set up stack frame 111 | stw r0, 4(r1) 112 | ; allocate stack space, R1 % 16 == 0 113 | stwu r1, -16(r1) 114 | 115 | ; exit code is zero 116 | li r3, 0 117 | ; exit application 118 | bl __exit 119 | -------------------------------------------------------------------------------- /src/asm/make_ppc32_sysv_xcoff_gas.S: -------------------------------------------------------------------------------- 1 | .globl make_fcontext[DS] 2 | .globl .make_fcontext[PR] 3 | .align 2 4 | .csect make_fcontext[DS] 5 | make_fcontext: 6 | .long .make_fcontext[PR] 7 | .csect .make_fcontext[PR], 3 8 | #.make_fcontext: 9 | # save return address into R6 10 | mflr 6 11 | 12 | # first arg of make_fcontext() == top address of context-function 13 | # shift address in R3 to lower 16 byte boundary 14 | clrrwi 3, 3, 4 15 | 16 | # reserve space for context-data on context-stack 17 | # including 64 byte of linkage + parameter area (R1 % 16 == 0) 18 | subi 3, 3, 304 19 | 20 | # third arg of make_fcontext() == address of context-function 21 | stw 5, 236(3) 22 | 23 | # load LR 24 | mflr 0 25 | # jump to label 1 26 | bl .Label 27 | .Label: 28 | # load LR into R4 29 | mflr 4 30 | # compute abs address of label .L_finish 31 | addi 4, 4, .L_finish - .Label 32 | # restore LR 33 | mtlr 0 34 | # save address of finish as return-address for context-function 35 | # will be entered after context-function returns 36 | stw 4, 232(3) 37 | 38 | # restore return address from R6 39 | mtlr 6 40 | 41 | blr # return pointer to context-data 42 | 43 | .L_finish: 44 | # save return address into R0 45 | mflr 0 46 | # save return address on stack, set up stack frame 47 | stw 0, 4(1) 48 | # allocate stack space, R1 % 16 == 0 49 | stwu 1, -16(1) 50 | 51 | # exit code is zero 52 | li 3, 0 53 | # exit application 54 | bl ._exit 55 | nop 56 | -------------------------------------------------------------------------------- /src/asm/make_ppc64_sysv_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************* 9 | * * 10 | * ------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ------------------------------------------------- * 13 | * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * 14 | * ------------------------------------------------- * 15 | * | F14 | F15 | F16 | F17 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * 21 | * ------------------------------------------------- * 22 | * | F18 | F19 | F20 | F21 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * 28 | * ------------------------------------------------- * 29 | * | F22 | F23 | F24 | F25 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * 35 | * ------------------------------------------------- * 36 | * | F26 | F27 | F28 | F29 | * 37 | * ------------------------------------------------- * 38 | * ------------------------------------------------- * 39 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 40 | * ------------------------------------------------- * 41 | * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * 42 | * ------------------------------------------------- * 43 | * | F30 | F31 | fpscr | TOC | * 44 | * ------------------------------------------------- * 45 | * ------------------------------------------------- * 46 | * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * 47 | * ------------------------------------------------- * 48 | * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * 49 | * ------------------------------------------------- * 50 | * | R14 | R15 | R16 | R17 | * 51 | * ------------------------------------------------- * 52 | * ------------------------------------------------- * 53 | * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * 54 | * ------------------------------------------------- * 55 | * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * 56 | * ------------------------------------------------- * 57 | * | R18 | R19 | R20 | R21 | * 58 | * ------------------------------------------------- * 59 | * ------------------------------------------------- * 60 | * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * 61 | * ------------------------------------------------- * 62 | * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * 63 | * ------------------------------------------------- * 64 | * | R22 | R23 | R24 | R25 | * 65 | * ------------------------------------------------- * 66 | * ------------------------------------------------- * 67 | * | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | * 68 | * ------------------------------------------------- * 69 | * | 256 | 260 | 264 | 268 | 272 | 276 | 280 | 284 | * 70 | * ------------------------------------------------- * 71 | * | R26 | R27 | R28 | R29 | * 72 | * ------------------------------------------------- * 73 | * ------------------------------------------------- * 74 | * | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | * 75 | * ------------------------------------------------- * 76 | * | 288 | 292 | 296 | 300 | 304 | 308 | 312 | 316 | * 77 | * ------------------------------------------------- * 78 | * ------------------------------------------------- * 79 | * | R30 | R31 | CR | LR | * 80 | * ------------------------------------------------- * 81 | * ------------------------------------------------- * 82 | * | 80 | 81 | | * 83 | * ------------------------------------------------- * 84 | * | 320 | 324 | | * 85 | * ------------------------------------------------- * 86 | * | PC | | * 87 | * ------------------------------------------------- * 88 | * * 89 | *******************************************************/ 90 | 91 | .globl make_fcontext 92 | #if _CALL_ELF == 2 93 | .text 94 | .align 2 95 | make_fcontext: 96 | addis %r2, %r12, .TOC.-make_fcontext@ha 97 | addi %r2, %r2, .TOC.-make_fcontext@l 98 | .localentry make_fcontext, . - make_fcontext 99 | #else 100 | .section ".opd","aw" 101 | .align 3 102 | make_fcontext: 103 | # ifdef _CALL_LINUX 104 | .quad .L.make_fcontext,.TOC.@tocbase,0 105 | .type make_fcontext,@function 106 | .text 107 | .align 2 108 | .L.make_fcontext: 109 | # else 110 | .hidden .make_fcontext 111 | .globl .make_fcontext 112 | .quad .make_fcontext,.TOC.@tocbase,0 113 | .size make_fcontext,24 114 | .type .make_fcontext,@function 115 | .text 116 | .align 2 117 | .make_fcontext: 118 | # endif 119 | #endif 120 | # save return address into R6 121 | mflr %r6 122 | 123 | # first arg of make_fcontext() == top address of context-stack 124 | # shift address in R3 to lower 16 byte boundary 125 | clrrdi %r3, %r3, 4 126 | 127 | # reserve space for context-data on context-stack 128 | # including 64 byte of linkage + parameter area (R1 % 16 == 0) 129 | subi %r3, %r3, 392 130 | 131 | # third arg of make_fcontext() == address of context-function 132 | # entry point (ELFv2) or descriptor (ELFv1) 133 | #if _CALL_ELF == 2 134 | # save address of context-function entry point 135 | std %r5, 320(%r3) 136 | #else 137 | # save address of context-function entry point 138 | ld %r4, 0(%r5) 139 | std %r4, 320(%r3) 140 | # save TOC of context-function 141 | ld %r4, 8(%r5) 142 | std %r4, 152(%r3) 143 | #endif 144 | 145 | # load LR 146 | mflr %r0 147 | # jump to label 1 148 | bl 1f 149 | 1: 150 | # load LR into R4 151 | mflr %r4 152 | # compute abs address of label finish 153 | addi %r4, %r4, finish - 1b 154 | # restore LR 155 | mtlr %r0 156 | # save address of finish as return-address for context-function 157 | # will be entered after context-function returns 158 | std %r4, 312(%r3) 159 | 160 | # restore return address from R6 161 | mtlr %r6 162 | 163 | blr # return pointer to context-data 164 | 165 | finish: 166 | # save return address into R0 167 | mflr %r0 168 | # save return address on stack, set up stack frame 169 | std %r0, 8(%r1) 170 | # allocate stack space, R1 % 16 == 0 171 | stdu %r1, -32(%r1) 172 | 173 | # exit code is zero 174 | li %r3, 0 175 | # exit application 176 | bl _exit 177 | nop 178 | #if _CALL_ELF == 2 179 | .size make_fcontext, .-make_fcontext 180 | #else 181 | # ifdef _CALL_LINUX 182 | .size .make_fcontext, .-.L.make_fcontext 183 | # else 184 | .size .make_fcontext, .-.make_fcontext 185 | # endif 186 | #endif 187 | 188 | /* Mark that we don't need executable stack. */ 189 | .section .note.GNU-stack,"",%progbits 190 | -------------------------------------------------------------------------------- /src/asm/make_ppc64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************* 9 | * * 10 | * ------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ------------------------------------------------- * 13 | * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * 14 | * ------------------------------------------------- * 15 | * | F14 | F15 | F16 | F17 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * 21 | * ------------------------------------------------- * 22 | * | F18 | F19 | F20 | F21 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * 28 | * ------------------------------------------------- * 29 | * | F22 | F23 | F24 | F25 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * 35 | * ------------------------------------------------- * 36 | * | F26 | F27 | F28 | F29 | * 37 | * ------------------------------------------------- * 38 | * ------------------------------------------------- * 39 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 40 | * ------------------------------------------------- * 41 | * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * 42 | * ------------------------------------------------- * 43 | * | F30 | F31 | fpscr | R13 | * 44 | * ------------------------------------------------- * 45 | * ------------------------------------------------- * 46 | * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * 47 | * ------------------------------------------------- * 48 | * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * 49 | * ------------------------------------------------- * 50 | * | R14 | R15 | R16 | R17 | * 51 | * ------------------------------------------------- * 52 | * ------------------------------------------------- * 53 | * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * 54 | * ------------------------------------------------- * 55 | * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * 56 | * ------------------------------------------------- * 57 | * | R18 | R19 | R20 | R21 | * 58 | * ------------------------------------------------- * 59 | * ------------------------------------------------- * 60 | * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * 61 | * ------------------------------------------------- * 62 | * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * 63 | * ------------------------------------------------- * 64 | * | R22 | R23 | R24 | R25 | * 65 | * ------------------------------------------------- * 66 | * ------------------------------------------------- * 67 | * | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | * 68 | * ------------------------------------------------- * 69 | * | 256 | 260 | 264 | 268 | 272 | 276 | 280 | 284 | * 70 | * ------------------------------------------------- * 71 | * | R26 | R27 | R28 | R29 | * 72 | * ------------------------------------------------- * 73 | * ------------------------------------------------- * 74 | * | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | * 75 | * ------------------------------------------------- * 76 | * | 288 | 292 | 296 | 300 | 304 | 308 | 312 | 316 | * 77 | * ------------------------------------------------- * 78 | * ------------------------------------------------- * 79 | * | R30 | R31 | CR | LR | * 80 | * ------------------------------------------------- * 81 | * ------------------------------------------------- * 82 | * | 80 | 81 | | * 83 | * ------------------------------------------------- * 84 | * | 320 | 324 | | * 85 | * ------------------------------------------------- * 86 | * | PC | | * 87 | * ------------------------------------------------- * 88 | * * 89 | *******************************************************/ 90 | 91 | .text 92 | .globl _make_fcontext 93 | _make_fcontext: 94 | ; save return address into R6 95 | mflr r6 96 | 97 | ; first arg of make_fcontext() == top address of context-function 98 | ; shift address in R3 to lower 16 byte boundary 99 | clrrwi r3, r3, 4 100 | 101 | ; reserve space for context-data on context-stack 102 | ; including 64 byte of linkage + parameter area (R1 16 == 0) 103 | subi r3, r3, 392 104 | 105 | ; third arg of make_fcontext() == address of context-function 106 | stw r5, 320(r3) 107 | 108 | ; load LR 109 | mflr r0 110 | ; jump to label 1 111 | bl l1 112 | l1: 113 | ; load LR into R4 114 | mflr r4 115 | ; compute abs address of label finish 116 | addi r4, r4, lo16((finish - .) + 4) 117 | ; restore LR 118 | mtlr r0 119 | ; save address of finish as return-address for context-function 120 | ; will be entered after context-function returns 121 | std r4, 312(r3) 122 | 123 | ; restore return address from R6 124 | mtlr r6 125 | 126 | blr ; return pointer to context-data 127 | 128 | finish: 129 | ; save return address into R0 130 | mflr r0 131 | ; save return address on stack, set up stack frame 132 | stw r0, 8(r1) 133 | ; allocate stack space, R1 16 == 0 134 | stwu r1, -32(r1) 135 | 136 | ; set return value to zero 137 | li r3, 0 138 | ; exit application 139 | bl __exit 140 | nop 141 | -------------------------------------------------------------------------------- /src/asm/make_ppc64_sysv_xcoff_gas.S: -------------------------------------------------------------------------------- 1 | .globl make_fcontext[DS] 2 | .globl .make_fcontext[PR] 3 | .align 2 4 | .csect .make_fcontext[PR], 3 5 | .globl _make_fcontext 6 | #._make_fcontext: 7 | # save return address into R6 8 | mflr 6 9 | 10 | # first arg of make_fcontext() == top address of context-function 11 | # shift address in R3 to lower 16 byte boundary 12 | clrrwi 3, 3, 4 13 | 14 | # reserve space for context-data on context-stack 15 | # including 64 byte of linkage + parameter area (R1 % 16 == 0) 16 | subi 3, 3, 392 17 | 18 | # third arg of make_fcontext() == address of context-function 19 | stw 5, 320(3) 20 | 21 | # load LR 22 | mflr 0 23 | # jump to label 1 24 | bl .Label 25 | .Label: 26 | # load LR into R4 27 | mflr 4 28 | # compute abs address of label .L_finish 29 | addi 4, 4, .L_finish - .Label 30 | # restore LR 31 | mtlr 0 32 | # save address of finish as return-address for context-function 33 | # will be entered after context-function returns 34 | stw 4, 312(3) 35 | 36 | # restore return address from R6 37 | mtlr 6 38 | 39 | blr # return pointer to context-data 40 | 41 | .L_finish: 42 | # save return address into R0 43 | mflr 0 44 | # save return address on stack, set up stack frame 45 | stw 0, 8(1) 46 | # allocate stack space, R1 % 16 == 0 47 | stwu 1, -32(1) 48 | 49 | # exit code is zero 50 | li 3, 0 51 | # exit application 52 | bl ._exit 53 | nop 54 | -------------------------------------------------------------------------------- /src/asm/make_sparc64_sysv_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Martin Husemann 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************************* 9 | * * 10 | * ------------------------------------------------------------- * 11 | * | Offset (in 4 or 8 byte units) | Content | * 12 | * ------------------------------------------------------------- * 13 | * | 0 | %sp | * 14 | * ------------------------------------------------------------- * 15 | * | 1 | %pc | * 16 | * ------------------------------------------------------------- * 17 | * | 2 | %i7 (return address) | * 18 | * ------------------------------------------------------------- * 19 | * | 3 | %g1 | * 20 | * ------------------------------------------------------------- * 21 | * | 4 | %g2 | * 22 | * ------------------------------------------------------------- * 23 | * | 5 | %g3 | * 24 | * ------------------------------------------------------------- * 25 | * | 6 | %g6 | * 26 | * ------------------------------------------------------------- * 27 | * | 7 | %g7 | * 28 | * ------------------------------------------------------------- * 29 | * The local and in registers are stored on the stack. * 30 | *******************************************************************/ 31 | 32 | #define OFF(N) (8*(N)) 33 | #define CCFSZ 176 // C Compiler Frame Size 34 | #define BIAS (2048-1) // Stack offset for 64 bit programs 35 | #define FC_SZ 448 // sizeof(fcontext_t) 36 | #define FC_STK 384 // offsetof(fcontext_t, fc_stack) 37 | #define FC_FPU 0 // offsetof(fcontext_t, fc_fp) 38 | #define FC_FSR 264 // offsetof(fcontext_t, fc_fp.fp_fsr) 39 | #define FC_FPRS 256 // offsetof(fcontext_t, fc_fp.fp_fprs) 40 | #define FC_GREG 320 // offsetof(fcontext_t, fc_greg) 41 | #define BLOCK_SIZE 64 42 | 43 | .register %g2,#ignore 44 | .register %g3,#ignore 45 | .register %g6,#ignore 46 | 47 | .text 48 | .globl make_fcontext 49 | .align 4 50 | .type make_fcontext,@function 51 | // fcontext_t * 52 | // make_fcontext( void * sp, std::size_t size, void (* fn)( intptr_t) ) 53 | make_fcontext: 54 | save %sp, -CCFSZ, %sp 55 | // %i0 initial stack pointer 56 | // %i1 stack size limit 57 | // %i2 function pointer for context start function 58 | 59 | sub %i0, FC_SZ, %i4 // allocate fcontext_t at on the new stack and keep pointer as return value 60 | andn %i4, BLOCK_SIZE-1, %i5 // force block ops usable alignement and keep pointer to fcontext in %i5 61 | 62 | stx %i0, [%i5+FC_STK+OFF(0)] // save fs_stack.sp 63 | stx %i1, [%i5+FC_STK+OFF(1)] // save fs_stack.size 64 | sub %i5, CCFSZ+BIAS, %o1 // leave space for one register window (and offset stack for 64bit) 65 | stx %o1, [%i5+FC_GREG+OFF(0)] // save new stack pointer 66 | stx %i2, [%i5+FC_GREG+OFF(1)] // save new %pc (function pointer) 67 | stx %g1, [%i5+FC_GREG+OFF(3)] 68 | stx %g2, [%i5+FC_GREG+OFF(4)] 69 | stx %g3, [%i5+FC_GREG+OFF(5)] 70 | stx %g6, [%i5+FC_GREG+OFF(6)] 71 | stx %g7, [%i5+FC_GREG+OFF(7)] 72 | 73 | // synthesize "return address": jump to finish 74 | 1: rd %pc, %i4 75 | add %i4, finish-1b-8, %i4 76 | stx %i4, [%i5+FC_GREG+OFF(2)] 77 | 78 | ret 79 | restore %g0, %i5, %o0 // return fcontext_t 80 | 81 | finish: 82 | mov %g0, %o0 83 | call _exit 84 | nop 85 | 86 | .size make_fcontext,.-make_fcontext 87 | 88 | /* Mark that we don't need executable stack. */ 89 | .section .note.GNU-stack,"",%progbits 90 | -------------------------------------------------------------------------------- /src/asm/make_sparc_sysv_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Martin Husemann 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /******************************************************************* 9 | * * 10 | * ------------------------------------------------------------- * 11 | * | Offset (in 4 or 8 byte units) | Content | * 12 | * ------------------------------------------------------------- * 13 | * | 0 | %sp | * 14 | * ------------------------------------------------------------- * 15 | * | 1 | %pc | * 16 | * ------------------------------------------------------------- * 17 | * | 2 | %i7 (return address) | * 18 | * ------------------------------------------------------------- * 19 | * | 3 | %g1 | * 20 | * ------------------------------------------------------------- * 21 | * | 4 | %g2 | * 22 | * ------------------------------------------------------------- * 23 | * | 5 | %g3 | * 24 | * ------------------------------------------------------------- * 25 | * | 6 | %g6 | * 26 | * ------------------------------------------------------------- * 27 | * | 7 | %g7 | * 28 | * ------------------------------------------------------------- * 29 | * The local and in registers are stored on the stack. * 30 | *******************************************************************/ 31 | 32 | #define OFF(N) (4*(N)) 33 | #define CCFSZ 96 34 | #define FC_SZ 176 35 | #define FC_stK 168 // offsetof(fcontext_t, fc_stack) 36 | #define FC_FPU 0 // offsetof(fcontext_t, fc_fp) 37 | #define FC_FSR 128 // offsetof(fcontext_t, fc_fp.fp_fsr) 38 | #define FC_GREG 136 // offsetof(fcontext_t, fc_greg) 39 | #define BLOCK_SIZE 8 40 | 41 | .text 42 | .globl make_fcontext 43 | .align 4 44 | .type make_fcontext,@function 45 | // fcontext_t * 46 | // make_fcontext( void * sp, std::size_t size, void (* fn)( intptr_t) ) 47 | make_fcontext: 48 | save %sp, -CCFSZ, %sp 49 | // %i0 initial stack pointer 50 | // %i1 stack size limit 51 | // %i2 function pointer for context start function 52 | 53 | sub %i0, FC_SZ, %i4 // allocate fcontext_t at on the new stack and keep pointer as return value 54 | andn %i4, BLOCK_SIZE-1, %i5 // force block ops usable alignement and keep pointer to fcontext in %i5 55 | 56 | st %i0, [%i5+FC_stK+OFF(0)] // save fs_stack.sp 57 | st %i1, [%i5+FC_stK+OFF(1)] // save fs_stack.size 58 | sub %i5, CCFSZ, %o1 // leave space for one register window 59 | st %o1, [%i5+FC_GREG+OFF(0)] // save new stack pointer 60 | st %i2, [%i5+FC_GREG+OFF(1)] // save new %pc (function pointer) 61 | st %g1, [%i5+FC_GREG+OFF(3)] 62 | st %g2, [%i5+FC_GREG+OFF(4)] 63 | st %g3, [%i5+FC_GREG+OFF(5)] 64 | st %g6, [%i5+FC_GREG+OFF(6)] 65 | st %g7, [%i5+FC_GREG+OFF(7)] 66 | 67 | // synthesize "return address": jump to finish 68 | mov %i7, %l0 69 | 2: call 3f 70 | nop 71 | 3: add finish-2b-8, %o7, %i4 72 | st %i4, [%i5+FC_GREG+OFF(2)] 73 | 74 | ret 75 | restore %g0, %i5, %o0 // return fcontext_t 76 | 77 | finish: 78 | mov %g0, %o0 79 | call _exit 80 | nop 81 | 82 | .size make_fcontext,.-make_fcontext 83 | 84 | /* Mark that we don't need executable stack. */ 85 | .section .note.GNU-stack,"",%progbits 86 | -------------------------------------------------------------------------------- /src/asm/make_x86_64_ms_pe_gas.asm: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Copyright Thomas Sailer 2013. 4 | Distributed under the Boost Software License, Version 1.0. 5 | (See accompanying file LICENSE_1_0.txt or copy at 6 | http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | 9 | /**************************************************************************************** 10 | * * 11 | * ---------------------------------------------------------------------------------- 12 | * | 0 | 1 | | 13 | * ---------------------------------------------------------------------------------- 14 | * | 0x0 | 0x4 | | 15 | * ---------------------------------------------------------------------------------- 16 | * | | | 17 | * ---------------------------------------------------------------------------------- 18 | * ---------------------------------------------------------------------------------- 19 | * | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 20 | * ---------------------------------------------------------------------------------- 21 | * | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | 0x20 | 0x24 | 22 | * ---------------------------------------------------------------------------------- 23 | * | SEE registers (XMM6-XMM15) | 24 | * ---------------------------------------------------------------------------------- 25 | * ---------------------------------------------------------------------------------- 26 | * | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 27 | * ---------------------------------------------------------------------------------- 28 | * | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | 0x40 | 0x44 | 29 | * ---------------------------------------------------------------------------------- 30 | * | SEE registers (XMM6-XMM15) | 31 | * ---------------------------------------------------------------------------------- 32 | * ---------------------------------------------------------------------------------- 33 | * | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 34 | * ---------------------------------------------------------------------------------- 35 | * | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | 0x60 | 0x64 | 36 | * ---------------------------------------------------------------------------------- 37 | * | SEE registers (XMM6-XMM15) | 38 | * ---------------------------------------------------------------------------------- 39 | * ---------------------------------------------------------------------------------- 40 | * | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 | * ---------------------------------------------------------------------------------- 42 | * | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | 0x80 | 0x84 | 43 | * ---------------------------------------------------------------------------------- 44 | * | SEE registers (XMM6-XMM15) | 45 | * ---------------------------------------------------------------------------------- 46 | * ---------------------------------------------------------------------------------- 47 | * | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 48 | * ---------------------------------------------------------------------------------- 49 | * | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | 0xa0 | 0xa4 | 50 | * ---------------------------------------------------------------------------------- 51 | * | SEE registers (XMM6-XMM15) | 52 | * ---------------------------------------------------------------------------------- 53 | * ---------------------------------------------------------------------------------- 54 | * | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 55 | * ---------------------------------------------------------------------------------- 56 | * | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | 0xc0 | 0xc4 | 57 | * ---------------------------------------------------------------------------------- 58 | * | fc_mxcsr|fc_x87_cw| | fbr_strg | fc_dealloc | 59 | * ---------------------------------------------------------------------------------- 60 | * ---------------------------------------------------------------------------------- 61 | * | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 62 | * ---------------------------------------------------------------------------------- 63 | * | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | 0xe0 | 0xe4 | 64 | * ---------------------------------------------------------------------------------- 65 | * | limit | base | R12 | R13 | 66 | * ---------------------------------------------------------------------------------- 67 | * ---------------------------------------------------------------------------------- 68 | * | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 69 | * ---------------------------------------------------------------------------------- 70 | * | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | 0x100 | 0x104 | 71 | * ---------------------------------------------------------------------------------- 72 | * | R14 | R15 | RDI | RSI | 73 | * ---------------------------------------------------------------------------------- 74 | * ---------------------------------------------------------------------------------- 75 | * | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 76 | * ---------------------------------------------------------------------------------- 77 | * | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | 0x120 | 0x124 | 78 | * ---------------------------------------------------------------------------------- 79 | * | RBX | RBP | RIP | EXIT | 80 | * ---------------------------------------------------------------------------------- 81 | * * 82 | * *************************************************************************************/ 83 | 84 | .file "make_x86_64_ms_pe_gas.asm" 85 | .text 86 | .p2align 4,,15 87 | .globl make_fcontext 88 | .def make_fcontext; .scl 2; .type 32; .endef 89 | .seh_proc make_fcontext 90 | make_fcontext: 91 | .seh_endprologue 92 | 93 | /* first arg of make_fcontext() == top of context-stack */ 94 | movq %rcx, %rax 95 | 96 | /* reserve 32byte shadow-space for context-function */ 97 | leaq -0x28(%rax), %rax 98 | 99 | /* shift address in RAX to lower 16 byte boundary */ 100 | /* == pointer to fcontext_t and address of context stack */ 101 | andq $-16, %rax 102 | 103 | /* reserve space for context-data on context-stack */ 104 | /* size for fc_mxcsr .. RIP + return-address for context-function */ 105 | /* on context-function entry: (RSP -0x8) % 16 == 0 */ 106 | leaq -0x128(%rax), %rax 107 | 108 | /* third arg of make_fcontext() == address of context-function */ 109 | movq %r8, 0x118(%rax) 110 | 111 | /* first arg of make_fcontext() == top of context-stack */ 112 | /* save top address of context stack as 'base' */ 113 | movq %rcx, 0xd0(%rax) 114 | /* second arg of make_fcontext() == size of context-stack */ 115 | /* negate stack size for LEA instruction (== substraction) */ 116 | negq %rdx 117 | /* compute bottom address of context stack (limit) */ 118 | leaq (%rcx,%rdx), %rcx 119 | /* save bottom address of context stack as 'limit' */ 120 | movq %rcx, 0xc8(%rax) 121 | /* save address of context stack limit as 'dealloction stack' */ 122 | movq %rcx, 0xc0(%rax) 123 | 124 | /* save MMX control- and status-word */ 125 | stmxcsr 0xa8(%rax) 126 | /* save x87 control-word */ 127 | fnstcw 0xac(%rax) 128 | 129 | /* compute abs address of label finish */ 130 | leaq finish(%rip), %rcx 131 | /* save address of finish as return-address for context-function */ 132 | /* will be entered after context-function returns */ 133 | movq %rcx, 0x120(%rax) 134 | 135 | /* set indicator */ 136 | movq 1, %rcx 137 | movq %rcx, (%rax) 138 | 139 | ret /* return pointer to context-data */ 140 | 141 | finish: 142 | /* 32byte shadow-space for _exit() are */ 143 | /* already reserved by make_fcontext() */ 144 | /* exit code is zero */ 145 | xorq %rcx, %rcx 146 | /* exit application */ 147 | call _exit 148 | hlt 149 | .seh_endproc 150 | 151 | .def _exit; .scl 2; .type 32; .endef /* standard C library function */ 152 | -------------------------------------------------------------------------------- /src/asm/make_x86_64_ms_pe_masm.asm: -------------------------------------------------------------------------------- 1 | 2 | ; Copyright Oliver Kowalke 2009. 3 | ; Distributed under the Boost Software License, Version 1.0. 4 | ; (See accompanying file LICENSE_1_0.txt or copy at 5 | ; http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | ; ---------------------------------------------------------------------------------- 8 | ; | 0 | 1 | | 9 | ; ---------------------------------------------------------------------------------- 10 | ; | 0x0 | 0x4 | | 11 | ; ---------------------------------------------------------------------------------- 12 | ; | | | 13 | ; ---------------------------------------------------------------------------------- 14 | ; ---------------------------------------------------------------------------------- 15 | ; | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 16 | ; ---------------------------------------------------------------------------------- 17 | ; | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | 0x20 | 0x24 | 18 | ; ---------------------------------------------------------------------------------- 19 | ; | SEE registers (XMM6-XMM15) | 20 | ; ---------------------------------------------------------------------------------- 21 | ; ---------------------------------------------------------------------------------- 22 | ; | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 23 | ; ---------------------------------------------------------------------------------- 24 | ; | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | 0x40 | 0x44 | 25 | ; ---------------------------------------------------------------------------------- 26 | ; | SEE registers (XMM6-XMM15) | 27 | ; ---------------------------------------------------------------------------------- 28 | ; ---------------------------------------------------------------------------------- 29 | ; | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 30 | ; ---------------------------------------------------------------------------------- 31 | ; | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | 0x60 | 0x64 | 32 | ; ---------------------------------------------------------------------------------- 33 | ; | SEE registers (XMM6-XMM15) | 34 | ; ---------------------------------------------------------------------------------- 35 | ; ---------------------------------------------------------------------------------- 36 | ; | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 37 | ; ---------------------------------------------------------------------------------- 38 | ; | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | 0x80 | 0x84 | 39 | ; ---------------------------------------------------------------------------------- 40 | ; | SEE registers (XMM6-XMM15) | 41 | ; ---------------------------------------------------------------------------------- 42 | ; ---------------------------------------------------------------------------------- 43 | ; | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 44 | ; ---------------------------------------------------------------------------------- 45 | ; | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | 0xa0 | 0xa4 | 46 | ; ---------------------------------------------------------------------------------- 47 | ; | SEE registers (XMM6-XMM15) | 48 | ; ---------------------------------------------------------------------------------- 49 | ; ---------------------------------------------------------------------------------- 50 | ; | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 51 | ; ---------------------------------------------------------------------------------- 52 | ; | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | 0xc0 | 0xc4 | 53 | ; ---------------------------------------------------------------------------------- 54 | ; | fc_mxcsr|fc_x87_cw| | fbr_strg | fc_dealloc | 55 | ; ---------------------------------------------------------------------------------- 56 | ; ---------------------------------------------------------------------------------- 57 | ; | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | ; ---------------------------------------------------------------------------------- 59 | ; | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | 0xe0 | 0xe4 | 60 | ; ---------------------------------------------------------------------------------- 61 | ; | limit | base | R12 | R13 | 62 | ; ---------------------------------------------------------------------------------- 63 | ; ---------------------------------------------------------------------------------- 64 | ; | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 65 | ; ---------------------------------------------------------------------------------- 66 | ; | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | 0x100 | 0x104 | 67 | ; ---------------------------------------------------------------------------------- 68 | ; | R14 | R15 | RDI | RSI | 69 | ; ---------------------------------------------------------------------------------- 70 | ; ---------------------------------------------------------------------------------- 71 | ; | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 72 | ; ---------------------------------------------------------------------------------- 73 | ; | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | 0x120 | 0x124 | 74 | ; ---------------------------------------------------------------------------------- 75 | ; | RBX | RBP | RIP | EXIT | 76 | ; ---------------------------------------------------------------------------------- 77 | 78 | ; standard C library function 79 | EXTERN _exit:PROC 80 | .code 81 | 82 | ; generate function table entry in .pdata and unwind information in 83 | make_fcontext PROC FRAME 84 | ; .xdata for a function's structured exception handling unwind behavior 85 | .endprolog 86 | 87 | ; first arg of make_fcontext() == top of context-stack 88 | mov rax, rcx 89 | 90 | ; reserve 32byte shadow-space for context-function 91 | sub rax, 028h 92 | 93 | ; shift address in RAX to lower 16 byte boundary 94 | ; == pointer to fcontext_t and address of context stack 95 | and rax, -16 96 | 97 | ; reserve space for context-data on context-stack 98 | ; size for fc_mxcsr .. RIP + return-address for context-function 99 | ; on context-function entry: (RSP -0x8) % 16 == 0 100 | sub rax, 0128h 101 | 102 | ; third arg of make_fcontext() == address of context-function 103 | mov [rax+0118h], r8 104 | 105 | ; first arg of make_fcontext() == top of context-stack 106 | ; save top address of context stack as 'base' 107 | mov [rax+0d0h], rcx 108 | ; second arg of make_fcontext() == size of context-stack 109 | ; negate stack size for LEA instruction (== substraction) 110 | neg rdx 111 | ; compute bottom address of context stack (limit) 112 | lea rcx, [rcx+rdx] 113 | ; save bottom address of context stack as 'limit' 114 | mov [rax+0c8h], rcx 115 | ; save address of context stack limit as 'dealloction stack' 116 | mov [rax+0c0h], rcx 117 | 118 | ; save MMX control- and status-word 119 | stmxcsr [rax+0a8h] 120 | ; save x87 control-word 121 | fnstcw [rax+0ach] 122 | 123 | ; compute abs address of label finish 124 | lea rcx, finish 125 | ; save address of finish as return-address for context-function 126 | ; will be entered after context-function returns 127 | mov [rax+0120h], rcx 128 | 129 | ; set indicator 130 | mov rcx, 1 131 | mov [rax], rcx 132 | 133 | ret ; return pointer to context-data 134 | 135 | finish: 136 | ; 32byte shadow-space for _exit() are 137 | ; already reserved by make_fcontext() 138 | ; exit code is zero 139 | xor rcx, rcx 140 | ; exit application 141 | call _exit 142 | hlt 143 | make_fcontext ENDP 144 | END 145 | -------------------------------------------------------------------------------- /src/asm/make_x86_64_sysv_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /**************************************************************************************** 9 | * * 10 | * ---------------------------------------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ---------------------------------------------------------------------------------- * 13 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * 14 | * ---------------------------------------------------------------------------------- * 15 | * | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | * 16 | * ---------------------------------------------------------------------------------- * 17 | * ---------------------------------------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ---------------------------------------------------------------------------------- * 20 | * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * 21 | * ---------------------------------------------------------------------------------- * 22 | * | R15 | RBX | RBP | RIP | * 23 | * ---------------------------------------------------------------------------------- * 24 | * ---------------------------------------------------------------------------------- * 25 | * | 16 | 17 | | * 26 | * ---------------------------------------------------------------------------------- * 27 | * | 0x40 | 0x44 | | * 28 | * ---------------------------------------------------------------------------------- * 29 | * | EXIT | | * 30 | * ---------------------------------------------------------------------------------- * 31 | * * 32 | ****************************************************************************************/ 33 | 34 | .text 35 | .globl make_fcontext 36 | .type make_fcontext,@function 37 | .align 16 38 | make_fcontext: 39 | /* first arg of make_fcontext() == top of context-stack */ 40 | movq %rdi, %rax 41 | 42 | /* shift address in RAX to lower 16 byte boundary */ 43 | andq $-16, %rax 44 | 45 | /* reserve space for context-data on context-stack */ 46 | /* size for fc_mxcsr .. RIP + return-address for context-function */ 47 | /* on context-function entry: (RSP -0x8) % 16 == 0 */ 48 | leaq -0x48(%rax), %rax 49 | 50 | /* third arg of make_fcontext() == address of context-function */ 51 | movq %rdx, 0x38(%rax) 52 | 53 | /* save MMX control- and status-word */ 54 | stmxcsr (%rax) 55 | /* save x87 control-word */ 56 | fnstcw 0x4(%rax) 57 | 58 | /* compute abs address of label finish */ 59 | leaq finish(%rip), %rcx 60 | /* save address of finish as return-address for context-function */ 61 | /* will be entered after context-function returns */ 62 | movq %rcx, 0x40(%rax) 63 | 64 | ret /* return pointer to context-data */ 65 | 66 | finish: 67 | /* exit code is zero */ 68 | xorq %rdi, %rdi 69 | /* exit application */ 70 | call _exit@PLT 71 | hlt 72 | .size make_fcontext,.-make_fcontext 73 | 74 | /* Mark that we don't need executable stack. */ 75 | .section .note.GNU-stack,"",%progbits 76 | -------------------------------------------------------------------------------- /src/asm/make_x86_64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | /**************************************************************************************** 9 | * * 10 | * ---------------------------------------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ---------------------------------------------------------------------------------- * 13 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * 14 | * ---------------------------------------------------------------------------------- * 15 | * | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | * 16 | * ---------------------------------------------------------------------------------- * 17 | * ---------------------------------------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ---------------------------------------------------------------------------------- * 20 | * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * 21 | * ---------------------------------------------------------------------------------- * 22 | * | R15 | RBX | RBP | RIP | * 23 | * ---------------------------------------------------------------------------------- * 24 | * ---------------------------------------------------------------------------------- * 25 | * | 16 | 17 | | * 26 | * ---------------------------------------------------------------------------------- * 27 | * | 0x40 | 0x44 | | * 28 | * ---------------------------------------------------------------------------------- * 29 | * | EXIT | | * 30 | * ---------------------------------------------------------------------------------- * 31 | * * 32 | ****************************************************************************************/ 33 | 34 | .text 35 | .globl _make_fcontext 36 | .align 8 37 | _make_fcontext: 38 | /* first arg of make_fcontext() == top of context-stack */ 39 | movq %rdi, %rax 40 | 41 | /* shift address in RAX to lower 16 byte boundary */ 42 | movabs $-16, %r8 43 | andq %r8, %rax 44 | 45 | /* reserve space for context-data on context-stack */ 46 | /* size for fc_mxcsr .. RIP + return-address for context-function */ 47 | /* on context-function entry: (RSP -0x8) % 16 == 0 */ 48 | leaq -0x48(%rax), %rax 49 | 50 | /* third arg of make_fcontext() == address of context-function */ 51 | movq %rdx, 0x38(%rax) 52 | 53 | /* save MMX control- and status-word */ 54 | stmxcsr (%rax) 55 | /* save x87 control-word */ 56 | fnstcw 0x4(%rax) 57 | 58 | /* compute abs address of label finish */ 59 | leaq finish(%rip), %rcx 60 | /* save address of finish as return-address for context-function */ 61 | /* will be entered after context-function returns */ 62 | movq %rcx, 0x40(%rax) 63 | 64 | ret /* return pointer to context-data */ 65 | 66 | finish: 67 | /* exit code is zero */ 68 | xorq %rdi, %rdi 69 | /* exit application */ 70 | call __exit 71 | hlt 72 | -------------------------------------------------------------------------------- /src/fcontext.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Richard Maxwell 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | #ifndef FCONTEXT_H 24 | #define FCONTEXT_H 25 | 26 | #include 27 | // intptr_t 28 | 29 | #include 30 | // size_t 31 | 32 | // ----------------------------------------------------------------------------- 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | // ----------------------------------------------------------------------------- 37 | 38 | typedef void* fcontext_t; 39 | 40 | intptr_t jump_fcontext 41 | ( 42 | fcontext_t* ofc 43 | , fcontext_t nfc 44 | , intptr_t vp 45 | , int preserve_fpu 46 | ); 47 | 48 | fcontext_t make_fcontext 49 | ( 50 | void* sp 51 | , size_t size 52 | , void (*fn)(intptr_t) 53 | ); 54 | // sp is the pointer to the _top_ of the stack (ie &stack_buffer[size]). 55 | 56 | // ----------------------------------------------------------------------------- 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | // ----------------------------------------------------------------------------- 61 | 62 | #endif 63 | --------------------------------------------------------------------------------