├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── 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_all_macho_gas.S ├── jump_combined_sysv_macho_gas.S ├── jump_i386_ms_pe_clang_gas.S ├── jump_i386_ms_pe_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_mips64_n64_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_riscv64_sysv_elf_gas.S ├── jump_s390x_sysv_elf_gas.S ├── jump_x86_64_ms_pe_clang_gas.S ├── jump_x86_64_ms_pe_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_all_macho_gas.S ├── make_combined_sysv_macho_gas.S ├── make_i386_ms_pe_clang_gas.S ├── make_i386_ms_pe_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_mips64_n64_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_riscv64_sysv_elf_gas.S ├── make_s390x_sysv_elf_gas.S ├── make_x86_64_ms_pe_clang_gas.S ├── make_x86_64_ms_pe_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 ├── ontop_arm64_aapcs_elf_gas.S ├── ontop_arm64_aapcs_macho_gas.S ├── ontop_arm_aapcs_elf_gas.S ├── ontop_arm_aapcs_macho_gas.S ├── ontop_arm_aapcs_pe_armasm.asm ├── ontop_combined_all_macho_gas.S ├── ontop_combined_sysv_macho_gas.S ├── ontop_i386_ms_pe_clang_gas.S ├── ontop_i386_ms_pe_gas.S ├── ontop_i386_ms_pe_gas.asm ├── ontop_i386_ms_pe_masm.asm ├── ontop_i386_sysv_elf_gas.S ├── ontop_i386_sysv_macho_gas.S ├── ontop_i386_x86_64_sysv_macho_gas.S ├── ontop_mips32_o32_elf_gas.S ├── ontop_mips64_n64_elf_gas.S ├── ontop_ppc32_ppc64_sysv_macho_gas.S ├── ontop_ppc32_sysv_elf_gas.S ├── ontop_ppc32_sysv_macho_gas.S ├── ontop_ppc32_sysv_xcoff_gas.S ├── ontop_ppc64_sysv_elf_gas.S ├── ontop_ppc64_sysv_macho_gas.S ├── ontop_ppc64_sysv_xcoff_gas.S ├── ontop_riscv64_sysv_elf_gas.S ├── ontop_s390x_sysv_elf_gas.S ├── ontop_x86_64_ms_pe_clang_gas.S ├── ontop_x86_64_ms_pe_gas.S ├── ontop_x86_64_ms_pe_gas.asm ├── ontop_x86_64_ms_pe_masm.asm ├── ontop_x86_64_sysv_elf_gas.S ├── ontop_x86_64_sysv_macho_gas.S └── tail_ppc32_sysv_elf_gas.cpp ├── cmake └── ios.toolchain.cmake ├── copy_pe_gas_win.bat ├── include └── fcontext │ └── fcontext.h ├── source └── stack.c └── test └── test_fcontext.c /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | .build 24 | build 25 | 26 | # Visual Studio 2015 cache/options directory 27 | .vs/ 28 | # Uncomment if you have tasks that create the project's static files in wwwroot 29 | #wwwroot/ 30 | 31 | # MSTest test Results 32 | [Tt]est[Rr]esult*/ 33 | [Bb]uild[Ll]og.* 34 | 35 | # NUNIT 36 | *.VisualState.xml 37 | TestResult.xml 38 | 39 | # Build Results of an ATL Project 40 | [Dd]ebugPS/ 41 | [Rr]eleasePS/ 42 | dlldata.c 43 | 44 | # DNX 45 | project.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | # TODO: Comment the next line if you want to checkin your web deploy settings 143 | # but database connection strings (with potential passwords) will be unencrypted 144 | *.pubxml 145 | *.publishproj 146 | 147 | # NuGet Packages 148 | *.nupkg 149 | # The packages folder can be ignored because of Package Restore 150 | **/packages/* 151 | # except build/, which is used as an MSBuild target. 152 | !**/packages/build/ 153 | # Uncomment if necessary however generally it will be regenerated when needed 154 | #!**/packages/repositories.config 155 | # NuGet v3's project.json files produces more ignoreable files 156 | *.nuget.props 157 | *.nuget.targets 158 | 159 | # Microsoft Azure Build Output 160 | csx/ 161 | *.build.csdef 162 | 163 | # Microsoft Azure Emulator 164 | ecf/ 165 | rcf/ 166 | 167 | # Microsoft Azure ApplicationInsights config file 168 | ApplicationInsights.config 169 | 170 | # Windows Store app package directory 171 | AppPackages/ 172 | BundleArtifacts/ 173 | 174 | # Visual Studio cache files 175 | # files ending in .cache can be ignored 176 | *.[Cc]ache 177 | # but keep track of directories ending in .cache 178 | !*.[Cc]ache/ 179 | 180 | # Others 181 | ClientBin/ 182 | ~$* 183 | *~ 184 | *.dbmdl 185 | *.dbproj.schemaview 186 | *.pfx 187 | *.publishsettings 188 | node_modules/ 189 | orleans.codegen.cs 190 | 191 | # RIA/Silverlight projects 192 | Generated_Code/ 193 | 194 | # Backup & report files from converting an old project file 195 | # to a newer Visual Studio version. Backup files are not needed, 196 | # because we have git ;-) 197 | _UpgradeReport_Files/ 198 | Backup*/ 199 | UpgradeLog*.XML 200 | UpgradeLog*.htm 201 | 202 | # SQL Server files 203 | *.mdf 204 | *.ldf 205 | 206 | # Business Intelligence projects 207 | *.rdl.data 208 | *.bim.layout 209 | *.bim_*.settings 210 | 211 | # Microsoft Fakes 212 | FakesAssemblies/ 213 | 214 | # GhostDoc plugin setting file 215 | *.GhostDoc.xml 216 | 217 | # Node.js Tools for Visual Studio 218 | .ntvs_analysis.dat 219 | 220 | # Visual Studio 6 build log 221 | *.plg 222 | 223 | # Visual Studio 6 workspace options file 224 | *.opt 225 | 226 | # Visual Studio LightSwitch build output 227 | **/*.HTMLClient/GeneratedArtifacts 228 | **/*.DesktopClient/GeneratedArtifacts 229 | **/*.DesktopClient/ModelManifest.xml 230 | **/*.Server/GeneratedArtifacts 231 | **/*.Server/ModelManifest.xml 232 | _Pvt_Extensions 233 | 234 | # Paket dependency manager 235 | .paket/paket.exe 236 | 237 | # FAKE - F# Make 238 | .fake/ 239 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # PROJECT: fcontext 2 | cmake_minimum_required(VERSION 3.10) 3 | project(fcontext C) 4 | 5 | option(BUILD_TEST "build test app" 0) 6 | 7 | if (NOT CMAKE_MODULE_PATH) 8 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 9 | endif() 10 | 11 | if (MSVC AND NOT CMAKE_C_COMPILER_ID MATCHES "Clang") 12 | enable_language(CXX ASM_MASM) 13 | else() 14 | enable_language(CXX ASM) 15 | endif() 16 | 17 | if(MSVC) 18 | add_definitions(-D_ITERATOR_DEBUG_LEVEL=0) 19 | add_definitions(-D_HAS_EXCEPTIONS=0) 20 | endif() 21 | add_definitions(-DBOOST_CONTEXT_EXPORT=) 22 | 23 | set(HEADER "include/fcontext/fcontext.h") 24 | set(SOURCES "source/stack.c") 25 | 26 | # OS 27 | if (APPLE) 28 | set(CPU_ARCH "combined") 29 | set(ASM_EXT "all_macho_gas.S") 30 | elseif (ANDROID) 31 | # Android 32 | if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") 33 | set(CPU_ARCH "arm") 34 | set(ASM_EXT "aapcs_elf_gas.S") 35 | elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") 36 | set(CPU_ARCH "arm64") 37 | set(ASM_EXT "aapcs_elf_gas.S") 38 | elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "i686") 39 | set(CPU_ARCH "i386") 40 | set(ASM_EXT "sysv_elf_gas.S") 41 | elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") 42 | set(CPU_ARCH "x86_64") 43 | set(ASM_EXT "sysv_elf_gas.S") 44 | endif() 45 | elseif (UNIX) 46 | # PC (ARM) 47 | if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") 48 | set(CPU_ARCH "arm") 49 | set(ASM_EXT "aapcs_elf_gas.S") 50 | elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") 51 | set(CPU_ARCH "arm64") 52 | set(ASM_EXT "aapcs_elf_gas.S") 53 | # PC (x86/x64) 54 | elseif (CMAKE_SIZEOF_VOID_P EQUAL 8) 55 | set(CPU_ARCH "x86_64") 56 | set(ASM_EXT "sysv_elf_gas.S") 57 | else() 58 | set(CPU_ARCH "i386") 59 | set(ASM_EXT "sysv_elf_gas.S") 60 | endif() 61 | elseif (WIN32) 62 | # Windows PC 63 | if (CMAKE_SIZEOF_VOID_P EQUAL 8) 64 | set(CPU_ARCH "x86_64") 65 | else() 66 | set(CPU_ARCH "i386") 67 | endif() 68 | 69 | if (CMAKE_C_COMPILER_ID MATCHES "Clang") 70 | set(ASM_EXT "ms_pe_clang_gas.S") 71 | elseif (MSVC) 72 | set(ASM_EXT "ms_pe_masm.asm") 73 | elseif (CMAKE_C_COMPILER_ID MATCHES "GNU") 74 | set(ASM_EXT "ms_pe_gas.S") 75 | endif() 76 | 77 | endif() 78 | 79 | set(ASM_SOURCES "asm/make_${CPU_ARCH}_${ASM_EXT}" 80 | "asm/jump_${CPU_ARCH}_${ASM_EXT}" 81 | "asm/ontop_${CPU_ARCH}_${ASM_EXT}") 82 | 83 | add_library(fcontext STATIC ${SOURCES} ${ASM_SOURCES}) 84 | target_include_directories(fcontext 85 | PRIVATE include/fcontext 86 | INTERFACE include) 87 | 88 | set_target_properties(fcontext PROPERTIES FOLDER Deps ${IOS_GENERAL_PROPERTIES}) 89 | 90 | install(TARGETS fcontext DESTINATION lib) 91 | install(FILES ${HEADER} DESTINATION include/fcontext) 92 | 93 | if (BUILD_TEST) 94 | add_executable(test_fcontext test/test_fcontext.c) 95 | target_link_libraries(test_fcontext fcontext) 96 | endif() 97 | 98 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Sepehr Taghdisian 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## deboost.context 2 | "Deboostified" version of boost.context (coroutines), Plain and simple C API for context switching. Easy build on multiple platforms. 3 | 4 | ### Build 5 | #### Currently supported platforms 6 | - Windows (x86_64, Win32) 7 | - Linux (x86_64/x86/ARM/ARM64) 8 | - OSX (x86_64/x86) 9 | - Android (ARM/x86/ARM64/x86_64) 10 | - iOS (Arm64, Arm7, x86_64, i386) 11 | 12 | #### iOS 13 | I've made an extra xcode project files for iOS ```projects/xcode/fcontext``` because I didn't know how to set different ASM files for each ARM architecture in cmake. So If you know how to do it, I'd be happy if you tell me. 14 | So, you can use the included toolchain file or use your own, just define _IOS_ to include the xcode project instead of generating it with cmake. 15 | ``` 16 | cd deboost.context 17 | mkdir .build 18 | cd .build 19 | cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/ios.toolchain.cmake -G Xcode 20 | ``` 21 | 22 | 23 | ### Usage 24 | Link your program with fcontext.lib/libfcontext.a and include the file _fcontext.h_. 25 | See _include/fcontext/fcontext.h_ for API usage. 26 | More info is available at: [boost.context](http://www.boost.org/doc/libs/1_60_0/libs/context/doc/html/index.html) 27 | 28 | ### Credits 29 | - Boost.context: This library uses the code from boost.context [github](https://github.com/boostorg/context) 30 | 31 | ### Thanks 32 | - Ali Salehi [github](https://github.com/lordhippo) 33 | 34 | -------------------------------------------------------------------------------- /asm/jump_arm64_aapcs_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Edward Nevill + Oliver Kowalke 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 | .file "jump_arm64_aapcs_elf_gas.S" 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 | # save d8 - d15 64 | stp d8, d9, [sp, #0x00] 65 | stp d10, d11, [sp, #0x10] 66 | stp d12, d13, [sp, #0x20] 67 | stp d14, d15, [sp, #0x30] 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 x29, x30, [sp, #0x90] 76 | 77 | # save LR as PC 78 | str x30, [sp, #0xa0] 79 | 80 | # store RSP (pointing to context-data) in X0 81 | mov x4, sp 82 | 83 | # restore RSP (pointing to context-data) from X1 84 | mov sp, x0 85 | 86 | # load d8 - d15 87 | ldp d8, d9, [sp, #0x00] 88 | ldp d10, d11, [sp, #0x10] 89 | ldp d12, d13, [sp, #0x20] 90 | ldp d14, d15, [sp, #0x30] 91 | 92 | # load x19-x30 93 | ldp x19, x20, [sp, #0x40] 94 | ldp x21, x22, [sp, #0x50] 95 | ldp x23, x24, [sp, #0x60] 96 | ldp x25, x26, [sp, #0x70] 97 | ldp x27, x28, [sp, #0x80] 98 | ldp x29, x30, [sp, #0x90] 99 | 100 | # return transfer_t from jump 101 | # pass transfer_t as first arg in context function 102 | # X0 == FCTX, X1 == DATA 103 | mov x0, x4 104 | 105 | # load pc 106 | ldr x4, [sp, #0xa0] 107 | 108 | # restore stack from GP + FPU 109 | add sp, sp, #0xb0 110 | 111 | ret x4 112 | .size jump_fcontext,.-jump_fcontext 113 | # Mark that we don't need executable stack. 114 | .section .note.GNU-stack,"",%progbits 115 | -------------------------------------------------------------------------------- /asm/jump_arm64_aapcs_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Edward Nevill + Oliver Kowalke 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 | .text 55 | .globl _jump_fcontext 56 | .balign 16 57 | _jump_fcontext: 58 | ; prepare stack for GP + FPU 59 | sub sp, sp, #0xb0 60 | 61 | ; save d8 - d15 62 | stp d8, d9, [sp, #0x00] 63 | stp d10, d11, [sp, #0x10] 64 | stp d12, d13, [sp, #0x20] 65 | stp d14, d15, [sp, #0x30] 66 | 67 | ; save x19-x30 68 | stp x19, x20, [sp, #0x40] 69 | stp x21, x22, [sp, #0x50] 70 | stp x23, x24, [sp, #0x60] 71 | stp x25, x26, [sp, #0x70] 72 | stp x27, x28, [sp, #0x80] 73 | stp fp, lr, [sp, #0x90] 74 | 75 | ; save LR as PC 76 | str lr, [sp, #0xa0] 77 | 78 | ; store RSP (pointing to context-data) in X0 79 | mov x4, sp 80 | 81 | ; restore RSP (pointing to context-data) from X1 82 | mov sp, x0 83 | 84 | ; load d8 - d15 85 | ldp d8, d9, [sp, #0x00] 86 | ldp d10, d11, [sp, #0x10] 87 | ldp d12, d13, [sp, #0x20] 88 | ldp d14, d15, [sp, #0x30] 89 | 90 | ; load x19-x30 91 | ldp x19, x20, [sp, #0x40] 92 | ldp x21, x22, [sp, #0x50] 93 | ldp x23, x24, [sp, #0x60] 94 | ldp x25, x26, [sp, #0x70] 95 | ldp x27, x28, [sp, #0x80] 96 | ldp fp, lr, [sp, #0x90] 97 | 98 | ; return transfer_t from jump 99 | ; pass transfer_t as first arg in context function 100 | ; X0 == FCTX, X1 == DATA 101 | mov x0, x4 102 | 103 | ; load pc 104 | ldr x4, [sp, #0xa0] 105 | 106 | ; restore stack from GP + FPU 107 | add sp, sp, #0xb0 108 | 109 | ret x4 110 | -------------------------------------------------------------------------------- /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 | * |hiddn| v1 | v2 | v3 | v4 | v5 | v6 | v7 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * 35 | * ------------------------------------------------- * 36 | * | v8 | lr | pc | FCTX| DATA| | * 37 | * ------------------------------------------------- * 38 | * * 39 | *******************************************************/ 40 | 41 | .file "jump_arm_aapcs_elf_gas.S" 42 | .text 43 | .globl jump_fcontext 44 | .align 2 45 | .type jump_fcontext,%function 46 | .syntax unified 47 | jump_fcontext: 48 | @ save LR as PC 49 | push {lr} 50 | @ save hidden,V1-V8,LR 51 | push {a1,v1-v8,lr} 52 | 53 | @ prepare stack for FPU 54 | sub sp, sp, #64 55 | #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) 56 | @ save S16-S31 57 | vstmia sp, {d8-d15} 58 | #endif 59 | 60 | @ store RSP (pointing to context-data) in A1 61 | mov a1, sp 62 | 63 | @ restore RSP (pointing to context-data) from A2 64 | mov sp, a2 65 | 66 | #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) 67 | @ restore S16-S31 68 | vldmia sp, {d8-d15} 69 | #endif 70 | @ prepare stack for FPU 71 | add sp, sp, #64 72 | 73 | @ restore hidden,V1-V8,LR 74 | pop {a4,v1-v8,lr} 75 | 76 | @ return transfer_t from jump 77 | str a1, [a4, #0] 78 | str a3, [a4, #4] 79 | @ pass transfer_t as first arg in context function 80 | @ A1 == FCTX, A2 == DATA 81 | mov a2, a3 82 | 83 | @ restore PC 84 | pop {pc} 85 | .size jump_fcontext,.-jump_fcontext 86 | 87 | @ Mark that we don't need executable stack. 88 | .section .note.GNU-stack,"",%progbits 89 | -------------------------------------------------------------------------------- /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 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * 28 | * ------------------------------------------------- * 29 | * | sjlj|hiddn| v1 | v2 | v3 | v4 | v5 | v6 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 35 | * ------------------------------------------------- * 36 | * | v7 | v8 | lr | pc | FCTX| DATA| | * 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 hidden,V1-V8,LR 48 | push {a1,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, #8] 56 | @ save SjLj handler 57 | push {v1} 58 | 59 | @ prepare stack for FPU 60 | sub sp, sp, #64 61 | #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) 62 | @ save S16-S31 63 | vstmia sp, {d8-d15} 64 | #endif 65 | 66 | @ store RSP (pointing to context-data) in A1 67 | mov a1, sp 68 | 69 | @ restore RSP (pointing to context-data) from A2 70 | mov sp, a2 71 | 72 | #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) 73 | @ restore S16-S31 74 | vldmia sp, {d8-d15} 75 | #endif 76 | @ prepare stack for FPU 77 | add sp, sp, #64 78 | 79 | @ r#estore SjLj handler 80 | pop {v1} 81 | @ store SjLj handler in TLS 82 | str v1, [v2, #8] 83 | 84 | @ restore hidden,V1-V8,LR 85 | pop {a4,v1-v8,lr} 86 | 87 | @ return transfer_t from jump 88 | str a1, [a4, #0] 89 | str a3, [a4, #4] 90 | @ pass transfer_t as first arg in context function 91 | @ A1 == FCTX, A2 == DATA 92 | mov a2, a3 93 | 94 | @ restore PC 95 | pop {pc} 96 | -------------------------------------------------------------------------------- /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 | ; * |deall|limit| base|hiddn| v1 | v2 | v3 | v4 | * 16 | ; * ------------------------------------------------- * 17 | ; * ------------------------------------------------- * 18 | ; * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | ; * ------------------------------------------------- * 20 | ; * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 21 | ; * ------------------------------------------------- * 22 | ; * | v5 | v6 | v7 | v8 | lr | pc | FCTX| DATA| * 23 | ; * ------------------------------------------------- * 24 | ; * * 25 | ; ******************************************************* 26 | 27 | AREA |.text|, CODE 28 | ALIGN 4 29 | EXPORT jump_fcontext 30 | 31 | jump_fcontext PROC 32 | ; save LR as PC 33 | push {lr} 34 | ; save hidden,V1-V8,LR 35 | push {a1,v1-v8,lr} 36 | 37 | ; load TIB to save/restore thread size and limit. 38 | ; we do not need preserve CPU flag and can use it's arg register 39 | mrc p15, #0, v1, c13, c0, #2 40 | 41 | ; save current stack base 42 | ldr a5, [v1, #0x04] 43 | push {a5} 44 | ; save current stack limit 45 | ldr a5, [v1, #0x08] 46 | push {a5} 47 | ; save current deallocation stack 48 | ldr a5, [v1, #0xe0c] 49 | push {a5} 50 | 51 | ; store RSP (pointing to context-data) in A1 52 | mov a1, sp 53 | 54 | ; restore RSP (pointing to context-data) from A2 55 | mov sp, a2 56 | 57 | ; restore deallocation stack 58 | pop {a5} 59 | str a5, [v1, #0xe0c] 60 | ; restore stack limit 61 | pop {a5} 62 | str a5, [v1, #0x08] 63 | ; restore stack base 64 | pop {a5} 65 | str a5, [v1, #0x04] 66 | 67 | ; restore hidden,V1-V8,LR 68 | pop {a4,v1-v8,lr} 69 | 70 | ; return transfer_t from jump 71 | str a1, [a4, #0] 72 | str a3, [a4, #4] 73 | ; pass transfer_t as first arg in context function 74 | ; A1 == FCTX, A2 == DATA 75 | mov a2, a3 76 | 77 | ; restore PC 78 | pop {pc} 79 | 80 | ENDP 81 | END 82 | -------------------------------------------------------------------------------- /asm/jump_combined_all_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(__arm__) || defined(__aarch64__) || defined(_M_ARM) 11 | #if defined(__aarch64__) 12 | #include "jump_arm64_aapcs_macho_gas.S" 13 | #else 14 | #include "jump_arm_aapcs_macho_gas.S" 15 | #endif 16 | #else 17 | #if defined(__i386__) 18 | #include "jump_i386_sysv_macho_gas.S" 19 | #elif defined(__x86_64__) 20 | #include "jump_x86_64_sysv_macho_gas.S" 21 | #elif defined(__ppc__) 22 | #include "jump_ppc32_sysv_macho_gas.S" 23 | #elif defined(__ppc64__) 24 | #include "jump_ppc64_sysv_macho_gas.S" 25 | #else 26 | #error "No arch's" 27 | #endif 28 | #endif -------------------------------------------------------------------------------- /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 | #elif defined(__arm__) 19 | #include "jump_arm_aapcs_macho_gas.S" 20 | #elif defined(__arm64__) 21 | #include "jump_arm64_aapcs_macho_gas.S" 22 | #else 23 | #error "No arch's" 24 | #endif 25 | -------------------------------------------------------------------------------- /asm/jump_i386_ms_pe_clang_gas.S: -------------------------------------------------------------------------------- 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 | to | data | EH NXT |SEH HNDLR| * 23 | * --------------------------------------------------------------------------------- * 24 | **************************************************************************************/ 25 | 26 | .file "jump_i386_ms_pe_clang_gas.S" 27 | .text 28 | .p2align 4,,15 29 | 30 | /* mark as using no unregistered SEH handlers */ 31 | .globl @feat.00 32 | .def @feat.00; .scl 3; .type 0; .endef 33 | .set @feat.00, 1 34 | 35 | .globl _jump_fcontext 36 | .def _jump_fcontext; .scl 2; .type 32; .endef 37 | _jump_fcontext: 38 | /* prepare stack */ 39 | leal -0x2c(%esp), %esp 40 | 41 | #if !defined(BOOST_USE_TSX) 42 | /* save MMX control- and status-word */ 43 | stmxcsr (%esp) 44 | /* save x87 control-word */ 45 | fnstcw 0x4(%esp) 46 | #endif 47 | 48 | /* load NT_TIB */ 49 | movl %fs:(0x18), %edx 50 | /* load fiber local storage */ 51 | movl 0x10(%edx), %eax 52 | movl %eax, 0x8(%esp) 53 | /* load current dealloction stack */ 54 | movl 0xe0c(%edx), %eax 55 | movl %eax, 0xc(%esp) 56 | /* load current stack limit */ 57 | movl 0x8(%edx), %eax 58 | movl %eax, 0x10(%esp) 59 | /* load current stack base */ 60 | movl 0x4(%edx), %eax 61 | movl %eax, 0x14(%esp) 62 | /* load current SEH exception list */ 63 | movl (%edx), %eax 64 | movl %eax, 0x18(%esp) 65 | 66 | movl %edi, 0x1c(%esp) /* save EDI */ 67 | movl %esi, 0x20(%esp) /* save ESI */ 68 | movl %ebx, 0x24(%esp) /* save EBX */ 69 | movl %ebp, 0x28(%esp) /* save EBP */ 70 | 71 | /* store ESP (pointing to context-data) in EAX */ 72 | movl %esp, %eax 73 | 74 | /* firstarg of jump_fcontext() == fcontext to jump to */ 75 | movl 0x30(%esp), %ecx 76 | 77 | /* restore ESP (pointing to context-data) from ECX */ 78 | movl %ecx, %esp 79 | 80 | #if !defined(BOOST_USE_TSX) 81 | /* restore MMX control- and status-word */ 82 | ldmxcsr (%esp) 83 | /* restore x87 control-word */ 84 | fldcw 0x4(%esp) 85 | #endif 86 | 87 | /* restore NT_TIB into EDX */ 88 | movl %fs:(0x18), %edx 89 | /* restore fiber local storage */ 90 | movl 0x8(%esp), %ecx 91 | movl %ecx, 0x10(%edx) 92 | /* restore current deallocation stack */ 93 | movl 0xc(%esp), %ecx 94 | movl %ecx, 0xe0c(%edx) 95 | /* restore current stack limit */ 96 | movl 0x10(%esp), %ecx 97 | movl %ecx, 0x8(%edx) 98 | /* restore current stack base */ 99 | movl 0x14(%esp), %ecx 100 | movl %ecx, 0x4(%edx) 101 | /* restore current SEH exception list */ 102 | movl 0x18(%esp), %ecx 103 | movl %ecx, (%edx) 104 | 105 | movl 0x2c(%esp), %ecx /* restore EIP */ 106 | 107 | movl 0x1c(%esp), %edi /* restore EDI */ 108 | movl 0x20(%esp), %esi /* restore ESI */ 109 | movl 0x24(%esp), %ebx /* restore EBX */ 110 | movl 0x28(%esp), %ebp /* restore EBP */ 111 | 112 | /* prepare stack */ 113 | leal 0x30(%esp), %esp 114 | 115 | /* return transfer_t */ 116 | /* FCTX == EAX, DATA == EDX */ 117 | movl 0x34(%eax), %edx 118 | 119 | /* jump to context */ 120 | jmp *%ecx 121 | 122 | .section .drectve 123 | .ascii " -export:\"_jump_fcontext\"" 124 | -------------------------------------------------------------------------------- /asm/jump_i386_ms_pe_gas.S: -------------------------------------------------------------------------------- 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 | to | data | EH NXT |SEH HNDLR| * 23 | * --------------------------------------------------------------------------------- * 24 | **************************************************************************************/ 25 | 26 | .file "jump_i386_ms_pe_gas.asm" 27 | .text 28 | .p2align 4,,15 29 | 30 | /* mark as using no unregistered SEH handlers */ 31 | .globl @feat.00 32 | .def @feat.00; .scl 3; .type 0; .endef 33 | .set @feat.00, 1 34 | 35 | .globl _jump_fcontext 36 | .def _jump_fcontext; .scl 2; .type 32; .endef 37 | _jump_fcontext: 38 | /* prepare stack */ 39 | leal -0x2c(%esp), %esp 40 | 41 | #if !defined(BOOST_USE_TSX) 42 | /* save MMX control- and status-word */ 43 | stmxcsr (%esp) 44 | /* save x87 control-word */ 45 | fnstcw 0x4(%esp) 46 | #endif 47 | 48 | /* load NT_TIB */ 49 | movl %fs:(0x18), %edx 50 | /* load fiber local storage */ 51 | movl 0x10(%edx), %eax 52 | movl %eax, 0x8(%esp) 53 | /* load current dealloction stack */ 54 | movl 0xe0c(%edx), %eax 55 | movl %eax, 0xc(%esp) 56 | /* load current stack limit */ 57 | movl 0x8(%edx), %eax 58 | movl %eax, 0x10(%esp) 59 | /* load current stack base */ 60 | movl 0x4(%edx), %eax 61 | movl %eax, 0x14(%esp) 62 | /* load current SEH exception list */ 63 | movl (%edx), %eax 64 | movl %eax, 0x18(%esp) 65 | 66 | movl %edi, 0x1c(%esp) /* save EDI */ 67 | movl %esi, 0x20(%esp) /* save ESI */ 68 | movl %ebx, 0x24(%esp) /* save EBX */ 69 | movl %ebp, 0x28(%esp) /* save EBP */ 70 | 71 | /* store ESP (pointing to context-data) in EAX */ 72 | movl %esp, %eax 73 | 74 | /* firstarg of jump_fcontext() == fcontext to jump to */ 75 | movl 0x30(%esp), %ecx 76 | 77 | /* restore ESP (pointing to context-data) from ECX */ 78 | movl %ecx, %esp 79 | 80 | #if !defined(BOOST_USE_TSX) 81 | /* restore MMX control- and status-word */ 82 | ldmxcsr (%esp) 83 | /* restore x87 control-word */ 84 | fldcw 0x4(%esp) 85 | #endif 86 | 87 | /* restore NT_TIB into EDX */ 88 | movl %fs:(0x18), %edx 89 | /* restore fiber local storage */ 90 | movl 0x8(%esp), %ecx 91 | movl %ecx, 0x10(%edx) 92 | /* restore current deallocation stack */ 93 | movl 0xc(%esp), %ecx 94 | movl %ecx, 0xe0c(%edx) 95 | /* restore current stack limit */ 96 | movl 0x10(%esp), %ecx 97 | movl %ecx, 0x8(%edx) 98 | /* restore current stack base */ 99 | movl 0x14(%esp), %ecx 100 | movl %ecx, 0x4(%edx) 101 | /* restore current SEH exception list */ 102 | movl 0x18(%esp), %ecx 103 | movl %ecx, (%edx) 104 | 105 | movl 0x2c(%esp), %ecx /* restore EIP */ 106 | 107 | movl 0x1c(%esp), %edi /* restore EDI */ 108 | movl 0x20(%esp), %esi /* restore ESI */ 109 | movl 0x24(%esp), %ebx /* restore EBX */ 110 | movl 0x28(%esp), %ebp /* restore EBP */ 111 | 112 | /* prepare stack */ 113 | leal 0x30(%esp), %esp 114 | 115 | /* return transfer_t */ 116 | /* FCTX == EAX, DATA == EDX */ 117 | movl 0x34(%eax), %edx 118 | 119 | /* jump to context */ 120 | jmp *%ecx 121 | 122 | .section .drectve 123 | .ascii " -export:\"jump_fcontext\"" 124 | -------------------------------------------------------------------------------- /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 | to | data | EH NXT |SEH HNDLR| * 23 | * --------------------------------------------------------------------------------- * 24 | **************************************************************************************/ 25 | 26 | .file "jump_i386_ms_pe_gas.asm" 27 | .text 28 | .p2align 4,,15 29 | 30 | /* mark as using no unregistered SEH handlers */ 31 | .globl @feat.00 32 | .def @feat.00; .scl 3; .type 0; .endef 33 | .set @feat.00, 1 34 | 35 | .globl _jump_fcontext 36 | .def _jump_fcontext; .scl 2; .type 32; .endef 37 | _jump_fcontext: 38 | /* prepare stack */ 39 | leal -0x2c(%esp), %esp 40 | 41 | #if !defined(BOOST_USE_TSX) 42 | /* save MMX control- and status-word */ 43 | stmxcsr (%esp) 44 | /* save x87 control-word */ 45 | fnstcw 0x4(%esp) 46 | #endif 47 | 48 | /* load NT_TIB */ 49 | movl %fs:(0x18), %edx 50 | /* load fiber local storage */ 51 | movl 0x10(%edx), %eax 52 | movl %eax, 0x8(%esp) 53 | /* load current dealloction stack */ 54 | movl 0xe0c(%edx), %eax 55 | movl %eax, 0xc(%esp) 56 | /* load current stack limit */ 57 | movl 0x8(%edx), %eax 58 | movl %eax, 0x10(%esp) 59 | /* load current stack base */ 60 | movl 0x4(%edx), %eax 61 | movl %eax, 0x14(%esp) 62 | /* load current SEH exception list */ 63 | movl (%edx), %eax 64 | movl %eax, 0x18(%esp) 65 | 66 | movl %edi, 0x1c(%esp) /* save EDI */ 67 | movl %esi, 0x20(%esp) /* save ESI */ 68 | movl %ebx, 0x24(%esp) /* save EBX */ 69 | movl %ebp, 0x28(%esp) /* save EBP */ 70 | 71 | /* store ESP (pointing to context-data) in EAX */ 72 | movl %esp, %eax 73 | 74 | /* firstarg of jump_fcontext() == fcontext to jump to */ 75 | movl 0x30(%esp), %ecx 76 | 77 | /* restore ESP (pointing to context-data) from ECX */ 78 | movl %ecx, %esp 79 | 80 | #if !defined(BOOST_USE_TSX) 81 | /* restore MMX control- and status-word */ 82 | ldmxcsr (%esp) 83 | /* restore x87 control-word */ 84 | fldcw 0x4(%esp) 85 | #endif 86 | 87 | /* restore NT_TIB into EDX */ 88 | movl %fs:(0x18), %edx 89 | /* restore fiber local storage */ 90 | movl 0x8(%esp), %ecx 91 | movl %ecx, 0x10(%edx) 92 | /* restore current deallocation stack */ 93 | movl 0xc(%esp), %ecx 94 | movl %ecx, 0xe0c(%edx) 95 | /* restore current stack limit */ 96 | movl 0x10(%esp), %ecx 97 | movl %ecx, 0x8(%edx) 98 | /* restore current stack base */ 99 | movl 0x14(%esp), %ecx 100 | movl %ecx, 0x4(%edx) 101 | /* restore current SEH exception list */ 102 | movl 0x18(%esp), %ecx 103 | movl %ecx, (%edx) 104 | 105 | movl 0x2c(%esp), %ecx /* restore EIP */ 106 | 107 | movl 0x1c(%esp), %edi /* restore EDI */ 108 | movl 0x20(%esp), %esi /* restore ESI */ 109 | movl 0x24(%esp), %ebx /* restore EBX */ 110 | movl 0x28(%esp), %ebp /* restore EBP */ 111 | 112 | /* prepare stack */ 113 | leal 0x30(%esp), %esp 114 | 115 | /* return transfer_t */ 116 | /* FCTX == EAX, DATA == EDX */ 117 | movl 0x34(%eax), %edx 118 | 119 | /* jump to context */ 120 | jmp *%ecx 121 | 122 | .section .drectve 123 | .ascii " -export:\"jump_fcontext\"" 124 | -------------------------------------------------------------------------------- /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 | to | data | EH NXT |SEH HNDLR| 20 | ; --------------------------------------------------------------------------------- 21 | 22 | .386 23 | .XMM 24 | .model flat, c 25 | .code 26 | 27 | jump_fcontext PROC BOOST_CONTEXT_EXPORT 28 | ; prepare stack 29 | lea esp, [esp-02ch] 30 | 31 | IFNDEF BOOST_USE_TSX 32 | ; save MMX control- and status-word 33 | stmxcsr [esp] 34 | ; save x87 control-word 35 | fnstcw [esp+04h] 36 | ENDIF 37 | 38 | assume fs:nothing 39 | ; load NT_TIB into ECX 40 | mov edx, fs:[018h] 41 | assume fs:error 42 | ; load fiber local storage 43 | mov eax, [edx+010h] 44 | mov [esp+08h], eax 45 | ; load current deallocation stack 46 | mov eax, [edx+0e0ch] 47 | mov [esp+0ch], eax 48 | ; load current stack limit 49 | mov eax, [edx+08h] 50 | mov [esp+010h], eax 51 | ; load current stack base 52 | mov eax, [edx+04h] 53 | mov [esp+014h], eax 54 | ; load current SEH exception list 55 | mov eax, [edx] 56 | mov [esp+018h], eax 57 | 58 | mov [esp+01ch], edi ; save EDI 59 | mov [esp+020h], esi ; save ESI 60 | mov [esp+024h], ebx ; save EBX 61 | mov [esp+028h], ebp ; save EBP 62 | 63 | ; store ESP (pointing to context-data) in EAX 64 | mov eax, esp 65 | 66 | ; firstarg of jump_fcontext() == fcontext to jump to 67 | mov ecx, [esp+030h] 68 | 69 | ; restore ESP (pointing to context-data) from ECX 70 | mov esp, ecx 71 | 72 | IFNDEF BOOST_USE_TSX 73 | ; restore MMX control- and status-word 74 | ldmxcsr [esp] 75 | ; restore x87 control-word 76 | fldcw [esp+04h] 77 | ENDIF 78 | 79 | assume fs:nothing 80 | ; load NT_TIB into EDX 81 | mov edx, fs:[018h] 82 | assume fs:error 83 | ; restore fiber local storage 84 | mov ecx, [esp+08h] 85 | mov [edx+010h], ecx 86 | ; restore current deallocation stack 87 | mov ecx, [esp+0ch] 88 | mov [edx+0e0ch], ecx 89 | ; restore current stack limit 90 | mov ecx, [esp+010h] 91 | mov [edx+08h], ecx 92 | ; restore current stack base 93 | mov ecx, [esp+014h] 94 | mov [edx+04h], ecx 95 | ; restore current SEH exception list 96 | mov ecx, [esp+018h] 97 | mov [edx], ecx 98 | 99 | mov ecx, [esp+02ch] ; restore EIP 100 | 101 | mov edi, [esp+01ch] ; restore EDI 102 | mov esi, [esp+020h] ; restore ESI 103 | mov ebx, [esp+024h] ; restore EBX 104 | mov ebp, [esp+028h] ; restore EBP 105 | 106 | ; prepare stack 107 | lea esp, [esp+030h] 108 | 109 | ; return transfer_t 110 | ; FCTX == EAX, DATA == EDX 111 | mov edx, [eax+034h] 112 | 113 | ; jump to context 114 | jmp ecx 115 | jump_fcontext ENDP 116 | END 117 | -------------------------------------------------------------------------------- /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 | hidden | * 16 | * ---------------------------------------------------------------------------------- * 17 | * ---------------------------------------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ---------------------------------------------------------------------------------- * 20 | * | 0x20 | 0x24 | | * 21 | * ---------------------------------------------------------------------------------- * 22 | * | to | data | | * 23 | * ---------------------------------------------------------------------------------- * 24 | * * 25 | ****************************************************************************************/ 26 | 27 | .file "jump_i386_sysv_elf_gas.S" 28 | .text 29 | .globl jump_fcontext 30 | .align 2 31 | .type jump_fcontext,@function 32 | jump_fcontext: 33 | leal -0x18(%esp), %esp /* prepare stack */ 34 | 35 | #if !defined(BOOST_USE_TSX) 36 | stmxcsr (%esp) /* save MMX control- and status-word */ 37 | fnstcw 0x4(%esp) /* save x87 control-word */ 38 | #endif 39 | 40 | movl %edi, 0x8(%esp) /* save EDI */ 41 | movl %esi, 0xc(%esp) /* save ESI */ 42 | movl %ebx, 0x10(%esp) /* save EBX */ 43 | movl %ebp, 0x14(%esp) /* save EBP */ 44 | 45 | /* store ESP (pointing to context-data) in ECX */ 46 | movl %esp, %ecx 47 | 48 | /* first arg of jump_fcontext() == fcontext to jump to */ 49 | movl 0x20(%esp), %eax 50 | 51 | /* second arg of jump_fcontext() == data to be transferred */ 52 | movl 0x24(%esp), %edx 53 | 54 | /* restore ESP (pointing to context-data) from EAX */ 55 | movl %eax, %esp 56 | 57 | /* address of returned transport_t */ 58 | movl 0x1c(%esp), %eax 59 | /* return parent fcontext_t */ 60 | movl %ecx, (%eax) 61 | /* return data */ 62 | movl %edx, 0x4(%eax) 63 | 64 | movl 0x18(%esp), %ecx /* restore EIP */ 65 | 66 | #if !defined(BOOST_USE_TSX) 67 | ldmxcsr (%esp) /* restore MMX control- and status-word */ 68 | fldcw 0x4(%esp) /* restore x87 control-word */ 69 | #endif 70 | 71 | movl 0x8(%esp), %edi /* restore EDI */ 72 | movl 0xc(%esp), %esi /* restore ESI */ 73 | movl 0x10(%esp), %ebx /* restore EBX */ 74 | movl 0x14(%esp), %ebp /* restore EBP */ 75 | 76 | leal 0x20(%esp), %esp /* prepare stack */ 77 | 78 | /* jump to context */ 79 | jmp *%ecx 80 | .size jump_fcontext,.-jump_fcontext 81 | 82 | /* Mark that we don't need executable stack. */ 83 | .section .note.GNU-stack,"",%progbits 84 | -------------------------------------------------------------------------------- /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 | to | * 16 | * ---------------------------------------------------------------------------------- * 17 | * ---------------------------------------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ---------------------------------------------------------------------------------- * 20 | * | 0x20 | | * 21 | * ---------------------------------------------------------------------------------- * 22 | * | data | | * 23 | * ---------------------------------------------------------------------------------- * 24 | * * 25 | ****************************************************************************************/ 26 | 27 | .text 28 | .globl _jump_fcontext 29 | .align 2 30 | _jump_fcontext: 31 | leal -0x18(%esp), %esp /* prepare stack */ 32 | 33 | #if !defined(BOOST_USE_TSX) 34 | stmxcsr (%esp) /* save MMX control- and status-word */ 35 | fnstcw 0x4(%esp) /* save x87 control-word */ 36 | #endif 37 | 38 | movl %edi, 0x8(%esp) /* save EDI */ 39 | movl %esi, 0xc(%esp) /* save ESI */ 40 | movl %ebx, 0x10(%esp) /* save EBX */ 41 | movl %ebp, 0x14(%esp) /* save EBP */ 42 | 43 | /* store ESP (pointing to context-data) in ECX */ 44 | movl %esp, %ecx 45 | 46 | /* first arg of jump_fcontext() == fcontext to jump to */ 47 | movl 0x1c(%esp), %eax 48 | 49 | /* second arg of jump_fcontext() == data to be transferred */ 50 | movl 0x20(%esp), %edx 51 | 52 | /* restore ESP (pointing to context-data) from EAX */ 53 | movl %eax, %esp 54 | 55 | /* return parent fcontext_t */ 56 | movl %ecx, %eax 57 | /* returned data is stored in EDX */ 58 | 59 | movl 0x18(%esp), %ecx /* restore EIP */ 60 | 61 | #if !defined(BOOST_USE_TSX) 62 | ldmxcsr (%esp) /* restore MMX control- and status-word */ 63 | fldcw 0x4(%esp) /* restore x87 control-word */ 64 | #endif 65 | 66 | movl 0x8(%esp), %edi /* restore EDI */ 67 | movl 0xc(%esp), %esi /* restore ESI */ 68 | movl 0x10(%esp), %ebx /* restore EBX */ 69 | movl 0x14(%esp), %ebp /* restore EBP */ 70 | 71 | leal 0x1c(%esp), %esp /* prepare stack */ 72 | 73 | /* jump to context */ 74 | jmp *%ecx 75 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * 28 | * ------------------------------------------------- * 29 | * | S4 | S5 | S6 | S7 | FP |hiddn| RA | PC | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * 35 | * ------------------------------------------------- * 36 | * | ABI ARGS | GP | FCTX| DATA| | * 37 | * ------------------------------------------------- * 38 | * * 39 | * *****************************************************/ 40 | 41 | .file "jump_mips32_o32_elf_gas.S" 42 | .text 43 | .globl jump_fcontext 44 | .align 2 45 | .type jump_fcontext,@function 46 | .ent jump_fcontext 47 | jump_fcontext: 48 | # reserve space on stack 49 | addiu $sp, $sp, -96 50 | 51 | sw $s0, 48($sp) # save S0 52 | sw $s1, 52($sp) # save S1 53 | sw $s2, 56($sp) # save S2 54 | sw $s3, 60($sp) # save S3 55 | sw $s4, 64($sp) # save S4 56 | sw $s5, 68($sp) # save S5 57 | sw $s6, 72($sp) # save S6 58 | sw $s7, 76($sp) # save S7 59 | sw $fp, 80($sp) # save FP 60 | sw $a0, 84($sp) # save hidden, address of returned transfer_t 61 | sw $ra, 88($sp) # save RA 62 | sw $ra, 92($sp) # save RA as PC 63 | 64 | #if defined(__mips_hard_float) 65 | s.d $f20, ($sp) # save F20 66 | s.d $f22, 8($sp) # save F22 67 | s.d $f24, 16($sp) # save F24 68 | s.d $f26, 24($sp) # save F26 69 | s.d $f28, 32($sp) # save F28 70 | s.d $f30, 40($sp) # save F30 71 | #endif 72 | 73 | # store SP (pointing to context-data) in A0 74 | move $a0, $sp 75 | 76 | # restore SP (pointing to context-data) from A1 77 | move $sp, $a1 78 | 79 | #if defined(__mips_hard_float) 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 | #endif 87 | 88 | lw $s0, 48($sp) # restore S0 89 | lw $s1, 52($sp) # restore S1 90 | lw $s2, 56($sp) # restore S2 91 | lw $s3, 60($sp) # restore S3 92 | lw $s4, 64($sp) # restore S4 93 | lw $s5, 68($sp) # restore S5 94 | lw $s6, 72($sp) # restore S6 95 | lw $s7, 76($sp) # restore S7 96 | lw $fp, 80($sp) # restore FP 97 | lw $v0, 84($sp) # restore hidden, address of returned transfer_t 98 | lw $ra, 88($sp) # restore RA 99 | 100 | # load PC 101 | lw $t9, 92($sp) 102 | 103 | # adjust stack 104 | addiu $sp, $sp, 96 105 | 106 | # return transfer_t from jump 107 | sw $a0, ($v0) # fctx of transfer_t 108 | sw $a2, 4($v0) # data of transfer_t 109 | # pass transfer_t as first arg in context function 110 | # A0 == fctx, A1 == data 111 | move $a1, $a2 112 | 113 | # jump to context 114 | jr $t9 115 | .end jump_fcontext 116 | .size jump_fcontext, .-jump_fcontext 117 | 118 | /* Mark that we don't need executable stack. */ 119 | .section .note.GNU-stack,"",%progbits 120 | -------------------------------------------------------------------------------- /asm/jump_mips64_n64_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Jiaxun Yang 2018. 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 | 8 | 16 | 24 | * 14 | * ------------------------------------------------- * 15 | * | F24 | F25 | F26 | F27 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 32 | 40 | 48 | 56 | * 21 | * ------------------------------------------------- * 22 | * | F28 | F29 | F30 | F31 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 64 | 72 | 80 | 88 | * 28 | * ------------------------------------------------- * 29 | * | S0 | S1 | S2 | S3 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * 35 | * ------------------------------------------------- * 36 | * | S4 | S5 | S6 | S7 | * 37 | * ------------------------------------------------- * 38 | * ------------------------------------------------- * 39 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 40 | * ------------------------------------------------- * 41 | * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * 42 | * ------------------------------------------------- * 43 | * | FP | GP | RA | PC | * 44 | * ------------------------------------------------- * 45 | * * 46 | * *****************************************************/ 47 | 48 | .file "jump_mips64_n64_elf_gas.S" 49 | .text 50 | .globl jump_fcontext 51 | .align 3 52 | .type jump_fcontext,@function 53 | .ent jump_fcontext 54 | jump_fcontext: 55 | # reserve space on stack 56 | daddiu $sp, $sp, -160 57 | 58 | sd $s0, 64($sp) # save S0 59 | sd $s1, 72($sp) # save S1 60 | sd $s2, 80($sp) # save S2 61 | sd $s3, 88($sp) # save S3 62 | sd $s4, 96($sp) # save S4 63 | sd $s5, 104($sp) # save S5 64 | sd $s6, 112($sp) # save S6 65 | sd $s7, 120($sp) # save S7 66 | sd $fp, 128($sp) # save FP 67 | sd $ra, 144($sp) # save RA 68 | sd $ra, 152($sp) # save RA as PC 69 | 70 | #if defined(__mips_hard_float) 71 | s.d $f24, 0($sp) # save F24 72 | s.d $f25, 8($sp) # save F25 73 | s.d $f26, 16($sp) # save F26 74 | s.d $f27, 24($sp) # save F27 75 | s.d $f28, 32($sp) # save F28 76 | s.d $f29, 40($sp) # save F29 77 | s.d $f30, 48($sp) # save F30 78 | s.d $f31, 56($sp) # save F31 79 | #endif 80 | 81 | # store SP (pointing to old context-data) in v0 as return 82 | move $v0, $sp 83 | 84 | # get SP (pointing to new context-data) from a0 param 85 | move $sp, $a0 86 | 87 | #if defined(__mips_hard_float) 88 | l.d $f24, 0($sp) # restore F24 89 | l.d $f25, 8($sp) # restore F25 90 | l.d $f26, 16($sp) # restore F26 91 | l.d $f27, 24($sp) # restore F27 92 | l.d $f28, 32($sp) # restore F28 93 | l.d $f29, 40($sp) # restore F29 94 | l.d $f30, 48($sp) # restore F30 95 | l.d $f31, 56($sp) # restore F31 96 | #endif 97 | 98 | ld $s0, 64($sp) # restore S0 99 | ld $s1, 72($sp) # restore S1 100 | ld $s2, 80($sp) # restore S2 101 | ld $s3, 88($sp) # restore S3 102 | ld $s4, 96($sp) # restore S4 103 | ld $s5, 104($sp) # restore S5 104 | ld $s6, 112($sp) # restore S6 105 | ld $s7, 120($sp) # restore S7 106 | ld $fp, 128($sp) # restore FP 107 | ld $ra, 144($sp) # restore RAa 108 | 109 | # load PC 110 | ld $t9, 152($sp) 111 | 112 | # adjust stack 113 | daddiu $sp, $sp, 160 114 | 115 | move $a0, $v0 # move old sp from v0 to a0 as param 116 | move $v1, $a1 # move *data from a1 to v1 as return 117 | 118 | # jump to context 119 | jr $t9 120 | .end jump_fcontext 121 | .size jump_fcontext, .-jump_fcontext 122 | 123 | /* Mark that we don't need executable stack. */ 124 | .section .note.GNU-stack,"",%progbits 125 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /asm/jump_ppc64_sysv_xcoff_gas.S: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright Oliver Kowalke 2009. 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 | .align 2 10 | .globl .jump_fcontext 11 | .jump_fcontext: 12 | # reserve space on stack 13 | subi 1, 1, 184 14 | 15 | std 13, 0(1) # save R13 16 | std 14, 8(1) # save R14 17 | std 15, 16(1) # save R15 18 | std 16, 24(1) # save R16 19 | std 17, 32(1) # save R17 20 | std 18, 40(1) # save R18 21 | std 19, 48(1) # save R19 22 | std 20, 56(1) # save R20 23 | std 21, 64(1) # save R21 24 | std 22, 72(1) # save R22 25 | std 23, 80(1) # save R23 26 | std 24, 88(1) # save R24 27 | std 25, 96(1) # save R25 28 | std 26, 104(1) # save R26 29 | std 27, 112(1) # save R27 30 | std 29, 120(1) # save R28 31 | std 29, 128(1) # save R29 32 | std 30, 136(1) # save R30 33 | std 31, 144(1) # save R31 34 | std 3, 152(1) # save hidden 35 | 36 | # save CR 37 | mfcr 0 38 | std 0, 160(1) 39 | # save LR 40 | mflr 0 41 | std 0, 168(1) 42 | # save LR as PC 43 | std 0, 176(1) 44 | 45 | # store RSP (pointing to context-data) in R6 46 | mr 6, 1 47 | 48 | # restore RSP (pointing to context-data) from R4 49 | mr 1, 4 50 | 51 | ld 13, 0(1) # restore R13 52 | ld 14, 8(1) # restore R14 53 | ld 15, 16(1) # restore R15 54 | ld 16, 24(1) # restore R16 55 | ld 17, 32(1) # restore R17 56 | ld 18, 40(1) # restore R18 57 | ld 19, 48(1) # restore R19 58 | ld 20, 56(1) # restore R20 59 | ld 21, 64(1) # restore R21 60 | ld 22, 72(1) # restore R22 61 | ld 23, 80(1) # restore R23 62 | ld 24, 88(1) # restore R24 63 | ld 25, 96(1) # restore R25 64 | ld 26, 104(1) # restore R26 65 | ld 27, 112(1) # restore R27 66 | ld 28, 120(1) # restore R28 67 | ld 29, 128(1) # restore R29 68 | ld 30, 136(1) # restore R30 69 | ld 31, 144(1) # restore R31 70 | ld 3, 152(1) # restore hidden 71 | 72 | # restore CR 73 | ld 0, 160(1) 74 | mtcr 0 75 | # restore LR 76 | ld 0, 168(1) 77 | mtlr 0 78 | 79 | # load PC 80 | ld 0, 176(1) 81 | # restore CTR 82 | mtctr 0 83 | 84 | # adjust stack 85 | addi 1, 1, 184 86 | 87 | # return transfer_t 88 | std 6, 0(3) 89 | std 5, 8(3) 90 | 91 | # jump to context 92 | bctr 93 | -------------------------------------------------------------------------------- /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 | ****************************************************************************************/ 26 | 27 | .file "jump_x86_64_sysv_elf_gas.S" 28 | .text 29 | .globl jump_fcontext 30 | .type jump_fcontext,@function 31 | .align 16 32 | jump_fcontext: 33 | leaq -0x38(%rsp), %rsp /* prepare stack */ 34 | 35 | #if !defined(BOOST_USE_TSX) 36 | stmxcsr (%rsp) /* save MMX control- and status-word */ 37 | fnstcw 0x4(%rsp) /* save x87 control-word */ 38 | #endif 39 | 40 | movq %r12, 0x8(%rsp) /* save R12 */ 41 | movq %r13, 0x10(%rsp) /* save R13 */ 42 | movq %r14, 0x18(%rsp) /* save R14 */ 43 | movq %r15, 0x20(%rsp) /* save R15 */ 44 | movq %rbx, 0x28(%rsp) /* save RBX */ 45 | movq %rbp, 0x30(%rsp) /* save RBP */ 46 | 47 | /* store RSP (pointing to context-data) in RAX */ 48 | movq %rsp, %rax 49 | 50 | /* restore RSP (pointing to context-data) from RDI */ 51 | movq %rdi, %rsp 52 | 53 | movq 0x38(%rsp), %r8 /* restore return-address */ 54 | 55 | #if !defined(BOOST_USE_TSX) 56 | ldmxcsr (%rsp) /* restore MMX control- and status-word */ 57 | fldcw 0x4(%rsp) /* restore x87 control-word */ 58 | #endif 59 | 60 | movq 0x8(%rsp), %r12 /* restore R12 */ 61 | movq 0x10(%rsp), %r13 /* restore R13 */ 62 | movq 0x18(%rsp), %r14 /* restore R14 */ 63 | movq 0x20(%rsp), %r15 /* restore R15 */ 64 | movq 0x28(%rsp), %rbx /* restore RBX */ 65 | movq 0x30(%rsp), %rbp /* restore RBP */ 66 | 67 | leaq 0x40(%rsp), %rsp /* prepare stack */ 68 | 69 | /* return transfer_t from jump */ 70 | #if !defined(_ILP32) 71 | /* RAX == fctx, RDX == data */ 72 | movq %rsi, %rdx 73 | #else 74 | /* RAX == data:fctx */ 75 | salq $32, %rsi 76 | orq %rsi, %rax 77 | #endif 78 | /* pass transfer_t as first arg in context function */ 79 | #if !defined(_ILP32) 80 | /* RDI == fctx, RSI == data */ 81 | #else 82 | /* RDI == data:fctx */ 83 | #endif 84 | movq %rax, %rdi 85 | 86 | /* indirect jump to context */ 87 | jmp *%r8 88 | .size jump_fcontext,.-jump_fcontext 89 | 90 | /* Mark that we don't need executable stack. */ 91 | .section .note.GNU-stack,"",%progbits 92 | -------------------------------------------------------------------------------- /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 | ****************************************************************************************/ 26 | 27 | .text 28 | .globl _jump_fcontext 29 | .align 8 30 | _jump_fcontext: 31 | leaq -0x38(%rsp), %rsp /* prepare stack */ 32 | 33 | #if !defined(BOOST_USE_TSX) 34 | stmxcsr (%rsp) /* save MMX control- and status-word */ 35 | fnstcw 0x4(%rsp) /* save x87 control-word */ 36 | #endif 37 | 38 | movq %r12, 0x8(%rsp) /* save R12 */ 39 | movq %r13, 0x10(%rsp) /* save R13 */ 40 | movq %r14, 0x18(%rsp) /* save R14 */ 41 | movq %r15, 0x20(%rsp) /* save R15 */ 42 | movq %rbx, 0x28(%rsp) /* save RBX */ 43 | movq %rbp, 0x30(%rsp) /* save RBP */ 44 | 45 | /* store RSP (pointing to context-data) in RAX */ 46 | movq %rsp, %rax 47 | 48 | /* restore RSP (pointing to context-data) from RDI */ 49 | movq %rdi, %rsp 50 | 51 | movq 0x38(%rsp), %r8 /* restore return-address */ 52 | 53 | #if !defined(BOOST_USE_TSX) 54 | ldmxcsr (%rsp) /* restore MMX control- and status-word */ 55 | fldcw 0x4(%rsp) /* restore x87 control-word */ 56 | #endif 57 | 58 | movq 0x8(%rsp), %r12 /* restore R12 */ 59 | movq 0x10(%rsp), %r13 /* restore R13 */ 60 | movq 0x18(%rsp), %r14 /* restore R14 */ 61 | movq 0x20(%rsp), %r15 /* restore R15 */ 62 | movq 0x28(%rsp), %rbx /* restore RBX */ 63 | movq 0x30(%rsp), %rbp /* restore RBP */ 64 | 65 | leaq 0x40(%rsp), %rsp /* prepare stack */ 66 | 67 | /* return transfer_t from jump */ 68 | /* RAX == fctx, RDX == data */ 69 | movq %rsi, %rdx 70 | /* pass transfer_t as first arg in context function */ 71 | /* RDI == fctx, RSI == data */ 72 | movq %rax, %rdi 73 | 74 | /* indirect jump to context */ 75 | jmp *%r8 76 | -------------------------------------------------------------------------------- /asm/make_arm64_aapcs_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Edward Nevill + Oliver Kowalke 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 | .file "make_arm64_aapcs_elf_gas.S" 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 | -------------------------------------------------------------------------------- /asm/make_arm64_aapcs_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Edward Nevill + Oliver Kowalke 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 | .text 55 | .globl _make_fcontext 56 | .balign 16 57 | 58 | _make_fcontext: 59 | ; shift address in x0 (allocated stack) to lower 16 byte boundary 60 | and x0, x0, ~0xF 61 | 62 | ; reserve space for context-data on context-stack 63 | sub x0, x0, #0xb0 64 | 65 | ; third arg of make_fcontext() == address of context-function 66 | ; store address as a PC to jump in 67 | str x2, [x0, #0xa0] 68 | 69 | ; compute abs address of label finish 70 | ; 0x0c = 3 instructions * size (4) before label 'finish' 71 | 72 | ; TODO: Numeric offset since llvm still does not support labels in ADR. Fix: 73 | ; http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140407/212336.html 74 | adr x1, 0x0c 75 | 76 | ; save address of finish as return-address for context-function 77 | ; will be entered after context-function returns (LR register) 78 | str x1, [x0, #0x98] 79 | 80 | ret lr ; return pointer to context-data (x0) 81 | 82 | finish: 83 | ; exit code is zero 84 | mov x0, #0 85 | ; exit application 86 | bl __exit 87 | 88 | 89 | -------------------------------------------------------------------------------- /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 | * |hiddn| v1 | v2 | v3 | v4 | v5 | v6 | v7 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * 35 | * ------------------------------------------------- * 36 | * | v8 | lr | pc | FCTX| DATA| | * 37 | * ------------------------------------------------- * 38 | * * 39 | *******************************************************/ 40 | 41 | .file "make_arm_aapcs_elf_gas.S" 42 | .text 43 | .globl make_fcontext 44 | .align 2 45 | .type make_fcontext,%function 46 | .syntax unified 47 | make_fcontext: 48 | @ shift address in A1 to lower 16 byte boundary 49 | bic a1, a1, #15 50 | 51 | @ reserve space for context-data on context-stack 52 | sub a1, a1, #124 53 | 54 | @ third arg of make_fcontext() == address of context-function 55 | str a3, [a1, #104] 56 | 57 | @ compute address of returned transfer_t 58 | add a2, a1, #108 59 | mov a3, a2 60 | str a3, [a1, #64] 61 | 62 | @ compute abs address of label finish 63 | adr a2, finish 64 | @ save address of finish as return-address for context-function 65 | @ will be entered after context-function returns 66 | str a2, [a1, #100] 67 | 68 | #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) 69 | #endif 70 | 71 | bx lr @ return pointer to context-data 72 | 73 | finish: 74 | @ exit code is zero 75 | mov a1, #0 76 | @ exit application 77 | bl _exit@PLT 78 | .size make_fcontext,.-make_fcontext 79 | 80 | @ Mark that we don't need executable stack. 81 | .section .note.GNU-stack,"",%progbits 82 | -------------------------------------------------------------------------------- /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 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * 28 | * ------------------------------------------------- * 29 | * | sjlj|hiddn| v1 | v2 | v3 | v4 | v5 | v6 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 35 | * ------------------------------------------------- * 36 | * | v7 | v8 | lr | pc | FCTX| DATA| | * 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, #124 50 | 51 | @ third arg of make_fcontext() == address of context-function 52 | str a3, [a1, #108] 53 | 54 | @ compute address of returned transfer_t 55 | add a2, a1, #112 56 | mov a3, a2 57 | str a3, [a1, #68] 58 | 59 | @ compute abs address of label finish 60 | adr a2, finish 61 | @ save address of finish as return-address for context-function 62 | @ will be entered after context-function returns 63 | str a2, [a1, #104] 64 | 65 | bx lr @ return pointer to context-data 66 | 67 | finish: 68 | @ exit code is zero 69 | mov a1, #0 70 | @ exit application 71 | bl __exit 72 | -------------------------------------------------------------------------------- /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 | ; * |deall|limit| base|hiddn| v1 | v2 | v3 | v4 | * 16 | ; * ------------------------------------------------- * 17 | ; * ------------------------------------------------- * 18 | ; * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | ; * ------------------------------------------------- * 20 | ; * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 21 | ; * ------------------------------------------------- * 22 | ; * | v5 | v6 | v7 | v8 | lr | pc | FCTX| DATA| * 23 | ; * ------------------------------------------------- * 24 | ; * * 25 | ; ******************************************************* 26 | 27 | 28 | AREA |.text|, CODE 29 | ALIGN 4 30 | EXPORT make_fcontext 31 | IMPORT _exit 32 | 33 | make_fcontext PROC 34 | ; first arg of make_fcontext() == top of context-stack 35 | ; save top of context-stack (base) A4 36 | mov a4, a1 37 | 38 | ; shift address in A1 to lower 16 byte boundary 39 | bic a1, a1, #0x0f 40 | 41 | ; reserve space for context-data on context-stack 42 | sub a1, a1, #0x48 43 | 44 | ; save top address of context_stack as 'base' 45 | str a4, [a1, #0x8] 46 | ; second arg of make_fcontext() == size of context-stack 47 | ; compute bottom address of context-stack (limit) 48 | sub a4, a4, a2 49 | ; save bottom address of context-stack as 'limit' 50 | str a4, [a1, #0x4] 51 | ; save bottom address of context-stack as 'dealloction stack' 52 | str a4, [a1, #0x0] 53 | 54 | ; third arg of make_fcontext() == address of context-function 55 | str a3, [a1, #0x34] 56 | 57 | ; compute address of returned transfer_t 58 | add a2, a1, #0x38 59 | mov a3, a2 60 | str a3, [a1, #0xc] 61 | 62 | ; compute abs address of label finish 63 | adr a2, finish 64 | ; save address of finish as return-address for context-function 65 | ; will be entered after context-function returns 66 | str a2, [a1, #0x30] 67 | 68 | bx lr ; return pointer to context-data 69 | 70 | finish 71 | ; exit code is zero 72 | mov a1, #0 73 | ; exit application 74 | bl _exit 75 | 76 | ENDP 77 | END 78 | -------------------------------------------------------------------------------- /asm/make_combined_all_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(__arm__) || defined(__aarch64__) || defined(_M_ARM) 11 | #if defined(__aarch64__) 12 | #include "make_arm64_aapcs_macho_gas.S" 13 | #else 14 | #include "make_arm_aapcs_macho_gas.S" 15 | #endif 16 | #else 17 | #if defined(__i386__) 18 | #include "make_i386_sysv_macho_gas.S" 19 | #elif defined(__x86_64__) 20 | #include "make_x86_64_sysv_macho_gas.S" 21 | #elif defined(__ppc__) 22 | #include "make_ppc32_sysv_macho_gas.S" 23 | #elif defined(__ppc64__) 24 | #include "make_ppc64_sysv_macho_gas.S" 25 | #else 26 | #error "No arch's" 27 | #endif 28 | #endif 29 | -------------------------------------------------------------------------------- /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 | #elif defined(__arm__) 19 | #include "make_arm_aapcs_macho_gas.S" 20 | #elif defined(__arm64__) 21 | #include "make_arm64_aapcs_macho_gas.S" 22 | #else 23 | #error "No arch's" 24 | #endif 25 | -------------------------------------------------------------------------------- /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 | to | data | EH 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 BOOST_CONTEXT_EXPORT 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 | ; on context-function entry: (ESP -0x4) % 8 == 0 42 | ; additional space is required for SEH 43 | lea eax, [eax-040h] 44 | 45 | ; save MMX control- and status-word 46 | stmxcsr [eax] 47 | ; save x87 control-word 48 | fnstcw [eax+04h] 49 | 50 | ; first arg of make_fcontext() == top of context-stack 51 | mov ecx, [esp+04h] 52 | ; save top address of context stack as 'base' 53 | mov [eax+014h], ecx 54 | ; second arg of make_fcontext() == size of context-stack 55 | mov edx, [esp+08h] 56 | ; negate stack size for LEA instruction (== substraction) 57 | neg edx 58 | ; compute bottom address of context stack (limit) 59 | lea ecx, [ecx+edx] 60 | ; save bottom address of context-stack as 'limit' 61 | mov [eax+010h], ecx 62 | ; save bottom address of context-stack as 'dealloction stack' 63 | mov [eax+0ch], ecx 64 | ; set fiber-storage to zero 65 | xor ecx, ecx 66 | mov [eax+08h], ecx 67 | 68 | ; third arg of make_fcontext() == address of context-function 69 | ; stored in EBX 70 | mov ecx, [esp+0ch] 71 | mov [eax+024h], ecx 72 | 73 | ; compute abs address of label trampoline 74 | mov ecx, trampoline 75 | ; save address of trampoline as return-address for context-function 76 | ; will be entered after calling jump_fcontext() first time 77 | mov [eax+02ch], ecx 78 | 79 | ; compute abs address of label finish 80 | mov ecx, finish 81 | ; save address of finish as return-address for context-function in EBP 82 | ; will be entered after context-function returns 83 | mov [eax+028h], ecx 84 | 85 | ; traverse current seh chain to get the last exception handler installed by Windows 86 | ; note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default 87 | ; the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler 88 | ; at its end by RaiseException all seh-handlers are disregarded if not present and the 89 | ; program is aborted 90 | assume fs:nothing 91 | ; load NT_TIB into ECX 92 | mov ecx, fs:[0h] 93 | assume fs:error 94 | 95 | walk: 96 | ; load 'next' member of current SEH into EDX 97 | mov edx, [ecx] 98 | ; test if 'next' of current SEH is last (== 0xffffffff) 99 | inc edx 100 | jz found 101 | dec edx 102 | ; exchange content; ECX contains address of next SEH 103 | xchg edx, ecx 104 | ; inspect next SEH 105 | jmp walk 106 | 107 | found: 108 | ; load 'handler' member of SEH == address of last SEH handler installed by Windows 109 | mov ecx, [ecx+04h] 110 | ; save address in ECX as SEH handler for context 111 | mov [eax+03ch], ecx 112 | ; set ECX to -1 113 | mov ecx, 0ffffffffh 114 | ; save ECX as next SEH item 115 | mov [eax+038h], ecx 116 | ; load address of next SEH item 117 | lea ecx, [eax+038h] 118 | ; save next SEH 119 | mov [eax+018h], ecx 120 | 121 | ret ; return pointer to context-data 122 | 123 | trampoline: 124 | ; move transport_t for entering context-function 125 | ; FCTX == EAX, DATA == EDX 126 | mov [esp], eax 127 | mov [esp+04h], edx 128 | push ebp 129 | ; jump to context-function 130 | jmp ebx 131 | 132 | finish: 133 | ; exit code is zero 134 | xor eax, eax 135 | mov [esp], eax 136 | ; exit application 137 | call _exit 138 | hlt 139 | make_fcontext ENDP 140 | END 141 | -------------------------------------------------------------------------------- /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 | hidden | * 16 | * ---------------------------------------------------------------------------------- * 17 | * ---------------------------------------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ---------------------------------------------------------------------------------- * 20 | * | 0x20 | 0x24 | | * 21 | * ---------------------------------------------------------------------------------- * 22 | * | to | data | | * 23 | * ---------------------------------------------------------------------------------- * 24 | * * 25 | ****************************************************************************************/ 26 | 27 | .file "make_i386_sysv_elf_gas.S" 28 | .text 29 | .globl make_fcontext 30 | .align 2 31 | .type make_fcontext,@function 32 | make_fcontext: 33 | /* first arg of make_fcontext() == top of context-stack */ 34 | movl 0x4(%esp), %eax 35 | 36 | /* reserve space for first argument of context-function 37 | eax might already point to a 16byte border */ 38 | leal -0x8(%eax), %eax 39 | 40 | /* shift address in EAX to lower 16 byte boundary */ 41 | andl $-16, %eax 42 | 43 | /* reserve space for context-data on context-stack */ 44 | leal -0x28(%eax), %eax 45 | 46 | /* third arg of make_fcontext() == address of context-function */ 47 | /* stored in EBX */ 48 | movl 0xc(%esp), %ecx 49 | movl %ecx, 0x10(%eax) 50 | 51 | /* save MMX control- and status-word */ 52 | stmxcsr (%eax) 53 | /* save x87 control-word */ 54 | fnstcw 0x4(%eax) 55 | 56 | /* return transport_t */ 57 | /* FCTX == EDI, DATA == ESI */ 58 | leal 0x8(%eax), %ecx 59 | movl %ecx, 0x1c(%eax) 60 | 61 | /* compute abs address of label trampoline */ 62 | call 1f 63 | /* address of trampoline 1 */ 64 | 1: popl %ecx 65 | /* compute abs address of label trampoline */ 66 | addl $trampoline-1b, %ecx 67 | /* save address of trampoline as return address */ 68 | /* will be entered after calling jump_fcontext() first time */ 69 | movl %ecx, 0x18(%eax) 70 | 71 | /* compute abs address of label finish */ 72 | call 2f 73 | /* address of label 2 */ 74 | 2: popl %ecx 75 | /* compute abs address of label finish */ 76 | addl $finish-2b, %ecx 77 | /* save address of finish as return-address for context-function */ 78 | /* will be entered after context-function returns */ 79 | movl %ecx, 0x14(%eax) 80 | 81 | ret /* return pointer to context-data */ 82 | 83 | trampoline: 84 | /* move transport_t for entering context-function */ 85 | movl %edi, (%esp) 86 | movl %esi, 0x4(%esp) 87 | pushl %ebp 88 | /* jump to context-function */ 89 | jmp *%ebx 90 | 91 | finish: 92 | call 3f 93 | /* address of label 3 */ 94 | 3: popl %ebx 95 | /* compute address of GOT and store it in EBX */ 96 | addl $_GLOBAL_OFFSET_TABLE_+[.-3b], %ebx 97 | 98 | /* exit code is zero */ 99 | xorl %eax, %eax 100 | movl %eax, (%esp) 101 | /* exit application */ 102 | call _exit@PLT 103 | hlt 104 | .size make_fcontext,.-make_fcontext 105 | 106 | /* Mark that we don't need executable stack. */ 107 | .section .note.GNU-stack,"",%progbits 108 | -------------------------------------------------------------------------------- /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 | to | * 16 | * ---------------------------------------------------------------------------------- * 17 | * ---------------------------------------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ---------------------------------------------------------------------------------- * 20 | * | 0x20 | | * 21 | * ---------------------------------------------------------------------------------- * 22 | * | data | | * 23 | * ---------------------------------------------------------------------------------- * 24 | * * 25 | ****************************************************************************************/ 26 | 27 | .text 28 | .globl _make_fcontext 29 | .align 2 30 | _make_fcontext: 31 | /* first arg of make_fcontext() == top of context-stack */ 32 | movl 0x4(%esp), %eax 33 | 34 | /* reserve space for first argument of context-function 35 | eax might already point to a 16byte border */ 36 | leal -0x8(%eax), %eax 37 | 38 | /* shift address in EAX to lower 16 byte boundary */ 39 | andl $-16, %eax 40 | 41 | /* reserve space for context-data on context-stack */ 42 | leal -0x2c(%eax), %eax 43 | 44 | /* third arg of make_fcontext() == address of context-function */ 45 | /* stored in EBX */ 46 | movl 0xc(%esp), %ecx 47 | movl %ecx, 0x10(%eax) 48 | 49 | /* save MMX control- and status-word */ 50 | stmxcsr (%eax) 51 | /* save x87 control-word */ 52 | fnstcw 0x4(%eax) 53 | 54 | /* compute abs address of label trampoline */ 55 | call 1f 56 | /* address of trampoline 1 */ 57 | 1: popl %ecx 58 | /* compute abs address of label trampoline */ 59 | addl $trampoline-1b, %ecx 60 | /* save address of trampoline as return address */ 61 | /* will be entered after calling jump_fcontext() first time */ 62 | movl %ecx, 0x18(%eax) 63 | 64 | /* compute abs address of label finish */ 65 | call 2f 66 | /* address of label 2 */ 67 | 2: popl %ecx 68 | /* compute abs address of label finish */ 69 | addl $finish-2b, %ecx 70 | /* save address of finish as return-address for context-function */ 71 | /* will be entered after context-function returns */ 72 | movl %ecx, 0x14(%eax) 73 | 74 | ret /* return pointer to context-data */ 75 | 76 | trampoline: 77 | /* move transport_t for entering context-function */ 78 | movl %eax, (%esp) 79 | movl %edx, 0x4(%esp) 80 | pushl %ebp 81 | /* jump to context-function */ 82 | jmp *%ebx 83 | 84 | finish: 85 | /* exit code is zero */ 86 | xorl %eax, %eax 87 | movl %eax, (%esp) 88 | /* exit application */ 89 | call __exit 90 | hlt 91 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * 28 | * ------------------------------------------------- * 29 | * | S4 | S5 | S6 | S7 | FP |hiddn| RA | PC | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * 35 | * ------------------------------------------------- * 36 | * | ABI ARGS | GP | FCTX| DATA| | * 37 | * ------------------------------------------------- * 38 | * * 39 | * *****************************************************/ 40 | 41 | .file "make_mips32_o32_elf_gas.S" 42 | .text 43 | .globl make_fcontext 44 | .align 2 45 | .type make_fcontext,@function 46 | .ent make_fcontext 47 | make_fcontext: 48 | #ifdef __PIC__ 49 | .set noreorder 50 | .cpload $t9 51 | .set reorder 52 | #endif 53 | # shift address in A0 to lower 16 byte boundary 54 | li $v1, -16 # 0xfffffffffffffff0 55 | and $v0, $v1, $a0 56 | 57 | # reserve space for context-data on context-stack 58 | # includes an extra 32 bytes for: 59 | # - 16-byte incoming argument area required by mips ABI used when 60 | # jump_context calls the initial function 61 | # - 4 bytes to save our GP register used in finish 62 | # - 8 bytes to as space for transfer_t returned to finish 63 | # - 4 bytes for alignment 64 | addiu $v0, $v0, -128 65 | 66 | # third arg of make_fcontext() == address of context-function 67 | sw $a2, 92($v0) 68 | # save global pointer in context-data 69 | sw $gp, 112($v0) 70 | 71 | # compute address of returned transfer_t 72 | addiu $t0, $v0, 116 73 | sw $t0, 84($v0) 74 | 75 | # compute abs address of label finish 76 | la $t9, finish 77 | # save address of finish as return-address for context-function 78 | # will be entered after context-function returns 79 | sw $t9, 88($v0) 80 | 81 | jr $ra # return pointer to context-data 82 | 83 | finish: 84 | # reload our gp register (needed for la) 85 | lw $gp, 16($sp) 86 | 87 | # call _exit(0) 88 | # the previous function should have left the 16 bytes incoming argument 89 | # area on the stack which we reuse for calling _exit 90 | la $t9, _exit 91 | move $a0, $zero 92 | jr $t9 93 | .end make_fcontext 94 | .size make_fcontext, .-make_fcontext 95 | 96 | /* Mark that we don't need executable stack. */ 97 | .section .note.GNU-stack,"",%progbits 98 | -------------------------------------------------------------------------------- /asm/make_mips64_n64_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Jiaxun Yang 2018. 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 | 8 | 16 | 24 | * 14 | * ------------------------------------------------- * 15 | * | F24 | F25 | F26 | F27 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 32 | 40 | 48 | 56 | * 21 | * ------------------------------------------------- * 22 | * | F28 | F29 | F30 | F31 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 64 | 72 | 80 | 88 | * 28 | * ------------------------------------------------- * 29 | * | S0 | S1 | S2 | S3 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * 35 | * ------------------------------------------------- * 36 | * | S4 | S5 | S6 | S7 | * 37 | * ------------------------------------------------- * 38 | * ------------------------------------------------- * 39 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 40 | * ------------------------------------------------- * 41 | * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * 42 | * ------------------------------------------------- * 43 | * | FP | GP | RA | PC | * 44 | * ------------------------------------------------- * 45 | * * 46 | * *****************************************************/ 47 | 48 | .file "make_mips64_n64_elf_gas.S" 49 | .text 50 | .globl make_fcontext 51 | .align 3 52 | .type make_fcontext,@function 53 | .ent make_fcontext 54 | make_fcontext: 55 | #ifdef __PIC__ 56 | .set noreorder 57 | .cpload $t9 58 | .set reorder 59 | #endif 60 | # shift address in A0 to lower 16 byte boundary 61 | li $v1, 0xfffffffffffffff0 62 | and $v0, $v1, $a0 63 | 64 | # reserve space for context-data on context-stack 65 | daddiu $v0, $v0, -160 66 | 67 | # third arg of make_fcontext() == address of context-function 68 | sd $a2, 152($v0) 69 | # save global pointer in context-data 70 | sd $gp, 136($v0) 71 | 72 | # psudo instruction compute abs address of label finish based on GP 73 | dla $t9, finish 74 | 75 | # save address of finish as return-address for context-function 76 | # will be entered after context-function returns 77 | sd $t9, 144($v0) 78 | 79 | jr $ra # return pointer to context-data 80 | 81 | finish: 82 | # reload our gp register (needed for la) 83 | daddiu $t0, $sp, -160 84 | ld $gp, 136($t0) 85 | 86 | # call _exit(0) 87 | # the previous function should have left the 16 bytes incoming argument 88 | # area on the stack which we reuse for calling _exit 89 | dla $t9, _exit 90 | move $a0, $zero 91 | jr $t9 92 | .end make_fcontext 93 | .size make_fcontext, .-make_fcontext 94 | 95 | /* Mark that we don't need executable stack. */ 96 | .section .note.GNU-stack,"",%progbits 97 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | * | TOC | R14 | R15 | R16 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * 21 | * ------------------------------------------------- * 22 | * | R17 | R18 | R19 | R20 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * 28 | * ------------------------------------------------- * 29 | * | R21 | R22 | R23 | R24 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * 35 | * ------------------------------------------------- * 36 | * | R25 | R26 | R27 | R28 | * 37 | * ------------------------------------------------- * 38 | * ------------------------------------------------- * 39 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 40 | * ------------------------------------------------- * 41 | * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * 42 | * ------------------------------------------------- * 43 | * | R29 | R30 | R31 | hidden | * 44 | * ------------------------------------------------- * 45 | * ------------------------------------------------- * 46 | * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * 47 | * ------------------------------------------------- * 48 | * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * 49 | * ------------------------------------------------- * 50 | * | CR | LR | PC | back-chain| * 51 | * ------------------------------------------------- * 52 | * ------------------------------------------------- * 53 | * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * 54 | * ------------------------------------------------- * 55 | * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * 56 | * ------------------------------------------------- * 57 | * | cr saved | lr saved | compiler | linker | * 58 | * ------------------------------------------------- * 59 | * ------------------------------------------------- * 60 | * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * 61 | * ------------------------------------------------- * 62 | * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * 63 | * ------------------------------------------------- * 64 | * | TOC saved | FCTX | DATA | | * 65 | * ------------------------------------------------- * 66 | * * 67 | 68 | .text 69 | .globl _make_fcontext 70 | _make_fcontext: 71 | ; save return address into R6 72 | mflr r6 73 | 74 | ; first arg of make_fcontext() == top address of context-function 75 | ; shift address in R3 to lower 16 byte boundary 76 | clrrwi r3, r3, 4 77 | 78 | ; reserve space for context-data on context-stack 79 | ; including 64 byte of linkage + parameter area (R1 16 == 0) 80 | subi r3, r3, 248 81 | 82 | ; third arg of make_fcontext() == address of context-function 83 | stw r5, 176(r3) 84 | 85 | ; set back-chain to zero 86 | li %r0, 0 87 | std %r0, 184(%r3) 88 | 89 | ; compute address of returned transfer_t 90 | addi %r0, %r3, 232 91 | mr %r4, %r0 92 | std %r4, 152(%r3) 93 | 94 | ; load LR 95 | mflr r0 96 | ; jump to label 1 97 | bl l1 98 | l1: 99 | ; load LR into R4 100 | mflr r4 101 | ; compute abs address of label finish 102 | addi r4, r4, lo16((finish - .) + 4) 103 | ; restore LR 104 | mtlr r0 105 | ; save address of finish as return-address for context-function 106 | ; will be entered after context-function returns 107 | std r4, 168(r3) 108 | 109 | ; restore return address from R6 110 | mtlr r6 111 | 112 | blr ; return pointer to context-data 113 | 114 | finish: 115 | ; save return address into R0 116 | mflr r0 117 | ; save return address on stack, set up stack frame 118 | stw r0, 8(r1) 119 | ; allocate stack space, R1 16 == 0 120 | stwu r1, -32(r1) 121 | 122 | ; set return value to zero 123 | li r3, 0 124 | ; exit application 125 | bl __exit 126 | nop 127 | -------------------------------------------------------------------------------- /asm/make_ppc64_sysv_xcoff_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 | .globl make_fcontext[DS] 8 | .globl .make_fcontext[PR] 9 | .align 2 10 | .csect .make_fcontext[PR], 3 11 | .globl _make_fcontext 12 | #._make_fcontext: 13 | # save return address into R6 14 | mflr 6 15 | 16 | # first arg of make_fcontext() == top address of context-function 17 | # shift address in R3 to lower 16 byte boundary 18 | clrrwi 3, 3, 4 19 | 20 | # reserve space for context-data on context-stack 21 | # including 64 byte of linkage + parameter area (R1 % 16 == 0) 22 | subi 3, 3, 248 23 | 24 | # third arg of make_fcontext() == address of context-function 25 | stw 5, 176(3) 26 | 27 | # set back-chain to zero 28 | li 0, 0 29 | std 0, 184(3) 30 | 31 | # compute address of returned transfer_t 32 | addi 0, 3, 232 33 | mr 4, 0 34 | std 4, 152(3) 35 | 36 | # load LR 37 | mflr 0 38 | # jump to label 1 39 | bl .Label 40 | .Label: 41 | # load LR into R4 42 | mflr 4 43 | # compute abs address of label .L_finish 44 | addi 4, 4, .L_finish - .Label 45 | # restore LR 46 | mtlr 0 47 | # save address of finish as return-address for context-function 48 | # will be entered after context-function returns 49 | stw 4, 168(3) 50 | 51 | # restore return address from R6 52 | mtlr 6 53 | 54 | blr # return pointer to context-data 55 | 56 | .L_finish: 57 | # save return address into R0 58 | mflr 0 59 | # save return address on stack, set up stack frame 60 | stw 0, 8(1) 61 | # allocate stack space, R1 % 16 == 0 62 | stwu 1, -32(1) 63 | 64 | # exit code is zero 65 | li 3, 0 66 | # exit application 67 | bl ._exit 68 | nop 69 | -------------------------------------------------------------------------------- /asm/make_riscv64_sysv_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Distributed under the Boost Software License, Version 1.0. 3 | (See accompanying file LICENSE_1_0.txt or copy at 4 | http://www.boost.org/LICENSE_1_0.txt) 5 | */ 6 | /******************************************************* 7 | * * 8 | * ------------------------------------------------- * 9 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 10 | * ------------------------------------------------- * 11 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * 12 | * ------------------------------------------------- * 13 | * | fs0 | fs1 | fs2 | fs3 | * 14 | * ------------------------------------------------- * 15 | * ------------------------------------------------- * 16 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 17 | * ------------------------------------------------- * 18 | * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 19 | * ------------------------------------------------- * 20 | * | fs4 | fs5 | fs6 | fs7 | * 21 | * ------------------------------------------------- * 22 | * ------------------------------------------------- * 23 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 24 | * ------------------------------------------------- * 25 | * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * 26 | * ------------------------------------------------- * 27 | * | fs8 | fs9 | fs10 | fs11 | * 28 | * ------------------------------------------------- * 29 | * ------------------------------------------------- * 30 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 31 | * ------------------------------------------------- * 32 | * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * 33 | * ------------------------------------------------- * 34 | * | s0 | s1 | s2 | s3 | * 35 | * ------------------------------------------------- * 36 | * ------------------------------------------------- * 37 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 38 | * ------------------------------------------------- * 39 | * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * 40 | * ------------------------------------------------- * 41 | * | s4 | s5 | s6 | s7 | * 42 | * ------------------------------------------------- * 43 | * ------------------------------------------------- * 44 | * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * 45 | * ------------------------------------------------- * 46 | * | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * 47 | * ------------------------------------------------- * 48 | * | s8 | s9 | s10 | s11 | * 49 | * ------------------------------------------------- * 50 | * ------------------------------------------------- * 51 | * | 48 | 49 | 50 | 51 | | | | | * 52 | * ------------------------------------------------- * 53 | * | 0xc0| 0xc4| 0xc8| 0xcc| | | | | * 54 | * ------------------------------------------------- * 55 | * | ra | pc | | | * 56 | * ------------------------------------------------- * 57 | * * 58 | *******************************************************/ 59 | 60 | .file "make_riscv64_sysv_elf_gas.S" 61 | .text 62 | .align 1 63 | .global make_fcontext 64 | .type make_fcontext, %function 65 | make_fcontext: 66 | # shift address in a0 (allocated stack) to lower 16 byte boundary 67 | andi a0, a0, ~0xF 68 | 69 | # reserve space for context-data on context-stack 70 | addi a0, a0, -0xd0 71 | 72 | # third arg of make_fcontext() == address of context-function 73 | # store address as a PC to jump in 74 | sd a2, 0xc8(a0) 75 | 76 | # save address of finish as return-address for context-function 77 | # will be entered after context-function returns (RA register) 78 | lla a4, finish 79 | sd a4, 0xc0(a0) 80 | 81 | ret // return pointer to context-data (a0) 82 | 83 | finish: 84 | # exit code is zero 85 | li a0, 0 86 | # exit application 87 | tail _exit@plt 88 | 89 | .size make_fcontext,.-make_fcontext 90 | # Mark that we don't need executable stack. 91 | .section .note.GNU-stack,"",%progbits 92 | -------------------------------------------------------------------------------- /asm/make_s390x_sysv_elf_gas.S: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * ------------------------------------------------- * 3 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 4 | * ------------------------------------------------- * 5 | * | 0 | 8 | 16 | 24 | * 6 | * ------------------------------------------------- * 7 | * | t.fctx | t.data | r2 | r6 | * 8 | * ------------------------------------------------- * 9 | * ------------------------------------------------- * 10 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 11 | * ------------------------------------------------- * 12 | * | 32 | 40 | 48 | 56 | * 13 | * ------------------------------------------------- * 14 | * | r7 | r8 | r9 | r10 | * 15 | * ------------------------------------------------- * 16 | * ------------------------------------------------- * 17 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 18 | * ------------------------------------------------- * 19 | * | 64 | 72 | 80 | 88 | * 20 | * ------------------------------------------------- * 21 | * | r11 | r12 | r13 | r14 | * 22 | * ------------------------------------------------- * 23 | * ------------------------------------------------- * 24 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 25 | * ------------------------------------------------- * 26 | * | 96 | 104 | 112 | 120 | * 27 | * ------------------------------------------------- * 28 | * | f8 | f9 | f10 | f11 | * 29 | * ------------------------------------------------- * 30 | * ------------------------------------------------- * 31 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 32 | * ------------------------------------------------- * 33 | * | 128 | 136 | 144 | 152 | * 34 | * ------------------------------------------------- * 35 | * | f12 | f13 | f14 | f15 | * 36 | * ------------------------------------------------- * 37 | * ------------------------------------------------- * 38 | * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * 39 | * ------------------------------------------------- * 40 | * | 160 | 168 | 176 | | * 41 | * ------------------------------------------------- * 42 | * | fpc | pc | | | * 43 | * ------------------------------------------------- * 44 | *******************************************************/ 45 | 46 | .text 47 | .align 8 48 | .global make_fcontext 49 | .type make_fcontext, @function 50 | 51 | #define ARG_OFFSET 0 52 | #define GR_OFFSET 16 53 | #define R14_OFFSET 88 54 | #define FP_OFFSET 96 55 | #define FPC_OFFSET 160 56 | #define PC_OFFSET 168 57 | #define CONTEXT_SIZE 176 58 | 59 | /* 60 | 61 | fcontext_t make_fcontext( void * sp, std::size_t size, void (* fn)( transfer_t) ); 62 | 63 | Create and return a context below SP to call FN. 64 | 65 | Incoming args 66 | r2 - The stack location where to create the context 67 | r3 - The size of the context 68 | r4 - The address of the context function 69 | 70 | */ 71 | 72 | make_fcontext: 73 | .machine "z10" 74 | /* Align the stack to an 8 byte boundary. */ 75 | nill %r2,0xfff0 76 | 77 | /* Allocate stack space for the context. */ 78 | aghi %r2,-CONTEXT_SIZE 79 | 80 | /* Set the r2 save slot to zero. This indicates jump_fcontext 81 | that this is a special context. */ 82 | mvghi GR_OFFSET(%r2),0 83 | 84 | /* Save the floating point control register. */ 85 | stfpc FPC_OFFSET(%r2) 86 | 87 | /* Store the address of the target function as new pc. */ 88 | stg %r4,PC_OFFSET(%r2) 89 | 90 | /* Store a pointer to the finish routine as r14. If a function 91 | called via context routines just returns that value will be 92 | loaded and used as return address. Hence the program will 93 | just exit. */ 94 | larl %r1,finish 95 | stg %r1,R14_OFFSET(%r2) 96 | 97 | /* Return as usual with the new context returned in r2. */ 98 | br %r14 99 | 100 | finish: 101 | /* In finish tasks, you load the exit code and exit the 102 | make_fcontext This is called when the context-function is 103 | entirely executed. */ 104 | lghi %r2,0 105 | brasl %r14,_exit@PLT 106 | 107 | .size make_fcontext,.-make_fcontext 108 | .section .note.GNU-stack,"",%progbits 109 | -------------------------------------------------------------------------------- /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 | ****************************************************************************************/ 26 | 27 | .file "make_x86_64_sysv_elf_gas.S" 28 | .text 29 | .globl make_fcontext 30 | .type make_fcontext,@function 31 | .align 16 32 | make_fcontext: 33 | /* first arg of make_fcontext() == top of context-stack */ 34 | movq %rdi, %rax 35 | 36 | /* shift address in RAX to lower 16 byte boundary */ 37 | andq $-16, %rax 38 | 39 | /* reserve space for context-data on context-stack */ 40 | /* on context-function entry: (RSP -0x8) % 16 == 0 */ 41 | leaq -0x40(%rax), %rax 42 | 43 | /* third arg of make_fcontext() == address of context-function */ 44 | /* stored in RBX */ 45 | movq %rdx, 0x28(%rax) 46 | 47 | /* save MMX control- and status-word */ 48 | stmxcsr (%rax) 49 | /* save x87 control-word */ 50 | fnstcw 0x4(%rax) 51 | 52 | /* compute abs address of label trampoline */ 53 | leaq trampoline(%rip), %rcx 54 | /* save address of trampoline as return-address for context-function */ 55 | /* will be entered after calling jump_fcontext() first time */ 56 | movq %rcx, 0x38(%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, 0x30(%rax) 63 | 64 | ret /* return pointer to context-data */ 65 | 66 | trampoline: 67 | /* store return address on stack */ 68 | /* fix stack alignment */ 69 | push %rbp 70 | /* jump to context-function */ 71 | jmp *%rbx 72 | 73 | finish: 74 | /* exit code is zero */ 75 | xorq %rdi, %rdi 76 | /* exit application */ 77 | call _exit@PLT 78 | hlt 79 | .size make_fcontext,.-make_fcontext 80 | 81 | /* Mark that we don't need executable stack. */ 82 | .section .note.GNU-stack,"",%progbits 83 | -------------------------------------------------------------------------------- /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 | ****************************************************************************************/ 26 | 27 | .text 28 | .globl _make_fcontext 29 | .align 8 30 | _make_fcontext: 31 | /* first arg of make_fcontext() == top of context-stack */ 32 | movq %rdi, %rax 33 | 34 | /* shift address in RAX to lower 16 byte boundary */ 35 | andq $-16, %rax 36 | 37 | /* reserve space for context-data on context-stack */ 38 | /* on context-function entry: (RSP -0x8) % 16 == 0 */ 39 | leaq -0x40(%rax), %rax 40 | 41 | /* third arg of make_fcontext() == address of context-function */ 42 | /* stored in RBX */ 43 | movq %rdx, 0x28(%rax) 44 | 45 | /* save MMX control- and status-word */ 46 | stmxcsr (%rax) 47 | /* save x87 control-word */ 48 | fnstcw 0x4(%rax) 49 | 50 | /* compute abs address of label trampoline */ 51 | leaq trampoline(%rip), %rcx 52 | /* save address of trampoline as return-address for context-function */ 53 | /* will be entered after calling jump_fcontext() first time */ 54 | movq %rcx, 0x38(%rax) 55 | 56 | /* compute abs address of label finish */ 57 | leaq finish(%rip), %rcx 58 | /* save address of finish as return-address for context-function */ 59 | /* will be entered after context-function returns */ 60 | movq %rcx, 0x30(%rax) 61 | 62 | ret /* return pointer to context-data */ 63 | 64 | trampoline: 65 | /* store return address on stack */ 66 | /* fix stack alignment */ 67 | push %rbp 68 | /* jump to context-function */ 69 | jmp *%rbx 70 | 71 | finish: 72 | /* exit code is zero */ 73 | xorq %rdi, %rdi 74 | /* exit application */ 75 | call __exit 76 | hlt 77 | -------------------------------------------------------------------------------- /asm/ontop_arm64_aapcs_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Edward Nevill + Oliver Kowalke 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 | .file "ontop_arm64_aapcs_elf_gas.S" 55 | .text 56 | .align 2 57 | .global ontop_fcontext 58 | .type ontop_fcontext, %function 59 | ontop_fcontext: 60 | # prepare stack for GP + FPU 61 | sub sp, sp, #0xb0 62 | 63 | # save d8 - d15 64 | stp d8, d9, [sp, #0x00] 65 | stp d10, d11, [sp, #0x10] 66 | stp d12, d13, [sp, #0x20] 67 | stp d14, d15, [sp, #0x30] 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 x29, x30, [sp, #0x90] 76 | 77 | # save LR as PC 78 | str x30, [sp, #0xa0] 79 | 80 | # store RSP (pointing to context-data) in X5 81 | mov x4, sp 82 | 83 | # restore RSP (pointing to context-data) from X1 84 | mov sp, x0 85 | 86 | # load d8 - d15 87 | ldp d8, d9, [sp, #0x00] 88 | ldp d10, d11, [sp, #0x10] 89 | ldp d12, d13, [sp, #0x20] 90 | ldp d14, d15, [sp, #0x30] 91 | 92 | # load x19-x30 93 | ldp x19, x20, [sp, #0x40] 94 | ldp x21, x22, [sp, #0x50] 95 | ldp x23, x24, [sp, #0x60] 96 | ldp x25, x26, [sp, #0x70] 97 | ldp x27, x28, [sp, #0x80] 98 | ldp x29, x30, [sp, #0x90] 99 | 100 | # return transfer_t from jump 101 | # pass transfer_t as first arg in context function 102 | # X0 == FCTX, X1 == DATA 103 | mov x0, x4 104 | 105 | # skip pc 106 | # restore stack from GP + FPU 107 | add sp, sp, #0xb0 108 | 109 | # jump to ontop-function 110 | ret x2 111 | .size ontop_fcontext,.-ontop_fcontext 112 | # Mark that we don't need executable stack. 113 | .section .note.GNU-stack,"",%progbits 114 | -------------------------------------------------------------------------------- /asm/ontop_arm64_aapcs_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Edward Nevill + Oliver Kowalke 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 | .text 55 | .global _ontop_fcontext 56 | .balign 16 57 | _ontop_fcontext: 58 | ; prepare stack for GP + FPU 59 | sub sp, sp, #0xb0 60 | 61 | ; save d8 - d15 62 | stp d8, d9, [sp, #0x00] 63 | stp d10, d11, [sp, #0x10] 64 | stp d12, d13, [sp, #0x20] 65 | stp d14, d15, [sp, #0x30] 66 | 67 | ; save x19-x30 68 | stp x19, x20, [sp, #0x40] 69 | stp x21, x22, [sp, #0x50] 70 | stp x23, x24, [sp, #0x60] 71 | stp x25, x26, [sp, #0x70] 72 | stp x27, x28, [sp, #0x80] 73 | stp x29, x30, [sp, #0x90] 74 | 75 | ; save LR as PC 76 | str x30, [sp, #0xa0] 77 | 78 | ; store RSP (pointing to context-data) in X5 79 | mov x4, sp 80 | 81 | ; restore RSP (pointing to context-data) from X1 82 | mov sp, x0 83 | 84 | ; load d8 - d15 85 | ldp d8, d9, [sp, #0x00] 86 | ldp d10, d11, [sp, #0x10] 87 | ldp d12, d13, [sp, #0x20] 88 | ldp d14, d15, [sp, #0x30] 89 | 90 | ; load x19-x30 91 | ldp x19, x20, [sp, #0x40] 92 | ldp x21, x22, [sp, #0x50] 93 | ldp x23, x24, [sp, #0x60] 94 | ldp x25, x26, [sp, #0x70] 95 | ldp x27, x28, [sp, #0x80] 96 | ldp x29, x30, [sp, #0x90] 97 | 98 | ; return transfer_t from jump 99 | ; pass transfer_t as first arg in context function 100 | ; X0 == FCTX, X1 == DATA 101 | mov x0, x4 102 | 103 | ; skip pc 104 | ; restore stack from GP + FPU 105 | add sp, sp, #0xb0 106 | 107 | ; jump to ontop-function 108 | ret x2 109 | -------------------------------------------------------------------------------- /asm/ontop_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 | * |hiddn| v1 | v2 | v3 | v4 | v5 | v6 | v7 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * 35 | * ------------------------------------------------- * 36 | * | v8 | lr | pc | FCTX| DATA| | * 37 | * ------------------------------------------------- * 38 | * * 39 | *******************************************************/ 40 | 41 | .file "ontop_arm_aapcs_elf_gas.S" 42 | .text 43 | .globl ontop_fcontext 44 | .align 2 45 | .type ontop_fcontext,%function 46 | .syntax unified 47 | ontop_fcontext: 48 | @ save LR as PC 49 | push {lr} 50 | @ save hidden,V1-V8,LR 51 | push {a1,v1-v8,lr} 52 | 53 | @ prepare stack for FPU 54 | sub sp, sp, #64 55 | #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) 56 | @ save S16-S31 57 | vstmia sp, {d8-d15} 58 | #endif 59 | 60 | @ store RSP (pointing to context-data) in A1 61 | mov a1, sp 62 | 63 | @ restore RSP (pointing to context-data) from A2 64 | mov sp, a2 65 | 66 | @ store parent context in A2 67 | mov a2, a1 68 | 69 | #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) 70 | @ restore S16-S31 71 | vldmia sp, {d8-d15} 72 | #endif 73 | @ prepare stack for FPU 74 | add sp, sp, #64 75 | 76 | @ restore hidden,V1-V8,LR 77 | pop {a1,v1-v8,lr} 78 | 79 | @ return transfer_t from jump 80 | str a2, [a1, #0] 81 | str a3, [a1, #4] 82 | @ pass transfer_t as first arg in context function 83 | @ A1 == hidden, A2 == FCTX, A3 == DATA 84 | 85 | @ skip PC 86 | add sp, sp, #4 87 | 88 | @ jump to ontop-function 89 | bx a4 90 | .size ontop_fcontext,.-ontop_fcontext 91 | 92 | @ Mark that we don't need executable stack. 93 | .section .note.GNU-stack,"",%progbits 94 | -------------------------------------------------------------------------------- /asm/ontop_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 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * 28 | * ------------------------------------------------- * 29 | * | sjlj|hiddn| v1 | v2 | v3 | v4 | v5 | v6 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 35 | * ------------------------------------------------- * 36 | * | v7 | v8 | lr | pc | FCTX| DATA| | * 37 | * ------------------------------------------------- * 38 | * * 39 | *******************************************************/ 40 | 41 | .text 42 | .globl _ontop_fcontext 43 | .align 2 44 | _ontop_fcontext: 45 | @ save LR as PC 46 | push {lr} 47 | @ save hidden,V1-V8,LR 48 | push {a1,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, #8] 56 | @ save SjLj handler 57 | push {v1} 58 | 59 | @ prepare stack for FPU 60 | sub sp, sp, #64 61 | #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) 62 | @ save S16-S31 63 | vstmia sp, {d8-d15} 64 | #endif 65 | 66 | @ store RSP (pointing to context-data) in A1 67 | mov a1, sp 68 | 69 | @ restore RSP (pointing to context-data) from A2 70 | mov sp, a2 71 | 72 | #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) 73 | @ restore S16-S31 74 | vldmia sp, {d8-d15} 75 | #endif 76 | @ prepare stack for FPU 77 | add sp, sp, #64 78 | 79 | @ restore SjLj handler 80 | pop {v1} 81 | @ store SjLj handler in TLS 82 | str v1, [v2, #8] 83 | 84 | @ store parent context in A2 85 | mov a2, a1 86 | 87 | @ restore hidden,V1-V8,LR 88 | pop {a1,v1-v8,lr} 89 | 90 | @ return transfer_t from jump 91 | str a2, [a1, #0] 92 | str a3, [a1, #4] 93 | @ pass transfer_t as first arg in context function 94 | @ A1 == hidden, A2 == FCTX, A3 == DATA 95 | 96 | @ skip PC 97 | add sp, sp, #4 98 | 99 | @ jump to ontop-function 100 | bx a4 101 | -------------------------------------------------------------------------------- /asm/ontop_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 | ; * |deall|limit| base|hiddn| v1 | v2 | v3 | v4 | * 16 | ; * ------------------------------------------------- * 17 | ; * ------------------------------------------------- * 18 | ; * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | ; * ------------------------------------------------- * 20 | ; * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * 21 | ; * ------------------------------------------------- * 22 | ; * | v5 | v6 | v7 | v8 | lr | pc | FCTX| DATA| * 23 | ; * ------------------------------------------------- * 24 | ; * * 25 | ; ******************************************************* 26 | 27 | AREA |.text|, CODE 28 | ALIGN 4 29 | EXPORT ontop_fcontext 30 | 31 | ontop_fcontext PROC 32 | ; save LR as PC 33 | push {lr} 34 | ; save hidden,V1-V8,LR 35 | push {a1,v1-v8,lr} 36 | 37 | ; load TIB to save/restore thread size and limit. 38 | ; we do not need preserve CPU flag and can use it's arg register 39 | mrc p15, #0, v1, c13, c0, #2 40 | 41 | ; save current stack base 42 | ldr a1, [v1, #0x04] 43 | push {a1} 44 | ; save current stack limit 45 | ldr a1, [v1, #0x08] 46 | push {a1} 47 | ; save current deallocation stack 48 | ldr a1, [v1, #0xe0c] 49 | push {a1} 50 | 51 | ; store RSP (pointing to context-data) in A1 52 | mov a1, sp 53 | 54 | ; restore RSP (pointing to context-data) from A2 55 | mov sp, a2 56 | 57 | ; restore stack base 58 | pop {a1} 59 | str a1, [v1, #0x04] 60 | ; restore stack limit 61 | pop {a1} 62 | str a1, [v1, #0x08] 63 | ; restore deallocation stack 64 | pop {a1} 65 | str a1, [v1, #0xe0c] 66 | 67 | ; store parent context in A2 68 | mov a2, a1 69 | 70 | ; restore hidden,V1-V8,LR 71 | pop {a1,v1-v8,lr} 72 | 73 | ; return transfer_t from jump 74 | str a2, [a1, #0] 75 | str a3, [a1, #4] 76 | ; pass transfer_t as first arg in context function 77 | ; A1 == hidden, A2 == FCTX, A3 == DATA 78 | 79 | ; skip PC 80 | add sp, sp, #4 81 | 82 | ; jump to ontop-function 83 | bx a4 84 | 85 | ENDP 86 | END 87 | -------------------------------------------------------------------------------- /asm/ontop_combined_all_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(__arm__) || defined(__aarch64__) || defined(_M_ARM) 11 | #if defined(__aarch64__) 12 | #include "make_arm64_aapcs_macho_gas.S" 13 | #else 14 | #include "make_arm_aapcs_macho_gas.S" 15 | #endif 16 | #else 17 | #if defined(__i386__) 18 | #include "ontop_i386_sysv_macho_gas.S" 19 | #elif defined(__x86_64__) 20 | #include "ontop_x86_64_sysv_macho_gas.S" 21 | #elif defined(__ppc__) 22 | #include "ontop_ppc32_sysv_macho_gas.S" 23 | #elif defined(__ppc64__) 24 | #include "ontop_ppc64_sysv_macho_gas.S" 25 | #else 26 | #error "No arch's" 27 | #endif 28 | #endif 29 | -------------------------------------------------------------------------------- /asm/ontop_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 "ontop_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "ontop_x86_64_sysv_macho_gas.S" 14 | #elif defined(__ppc__) 15 | #include "ontop_ppc32_sysv_macho_gas.S" 16 | #elif defined(__ppc64__) 17 | #include "ontop_ppc64_sysv_macho_gas.S" 18 | #elif defined(__arm__) 19 | #include "ontop_arm_aapcs_macho_gas.S" 20 | #elif defined(__arm64__) 21 | #include "ontop_arm64_aapcs_macho_gas.S" 22 | #else 23 | #error "No arch's" 24 | #endif 25 | -------------------------------------------------------------------------------- /asm/ontop_i386_ms_pe_clang_gas.S: -------------------------------------------------------------------------------- 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 | to | data | EH NXT |SEH HNDLR| * 23 | * --------------------------------------------------------------------------------- * 24 | **************************************************************************************/ 25 | 26 | .file "ontop_i386_ms_pe_clang_gas.S" 27 | .text 28 | .p2align 4,,15 29 | 30 | /* mark as using no unregistered SEH handlers */ 31 | .globl @feat.00 32 | .def @feat.00; .scl 3; .type 0; .endef 33 | .set @feat.00, 1 34 | 35 | .globl _ontop_fcontext 36 | .def _ontop_fcontext; .scl 2; .type 32; .endef 37 | _ontop_fcontext: 38 | /* prepare stack */ 39 | leal -0x2c(%esp), %esp 40 | 41 | #if !defined(BOOST_USE_TSX) 42 | /* save MMX control- and status-word */ 43 | stmxcsr (%esp) 44 | /* save x87 control-word */ 45 | fnstcw 0x4(%esp) 46 | #endif 47 | 48 | /* load NT_TIB */ 49 | movl %fs:(0x18), %edx 50 | /* load fiber local storage */ 51 | movl 0x10(%edx), %eax 52 | movl %eax, 0x8(%esp) 53 | /* load current dealloction stack */ 54 | movl 0xe0c(%edx), %eax 55 | movl %eax, 0xc(%esp) 56 | /* load current stack limit */ 57 | movl 0x8(%edx), %eax 58 | movl %eax, 0x10(%esp) 59 | /* load current stack base */ 60 | movl 0x4(%edx), %eax 61 | movl %eax, 0x14(%esp) 62 | /* load current SEH exception list */ 63 | movl (%edx), %eax 64 | movl %eax, 0x18(%esp) 65 | 66 | movl %edi, 0x1c(%esp) /* save EDI */ 67 | movl %esi, 0x20(%esp) /* save ESI */ 68 | movl %ebx, 0x24(%esp) /* save EBX */ 69 | movl %ebp, 0x28(%esp) /* save EBP */ 70 | 71 | /* store ESP (pointing to context-data) in ECX */ 72 | movl %esp, %ecx 73 | 74 | /* first arg of ontop_fcontext() == fcontext to jump to */ 75 | movl 0x30(%esp), %eax 76 | 77 | /* pass parent fcontext_t */ 78 | movl %ecx, 0x30(%eax) 79 | 80 | /* second arg of ontop_fcontext() == data to be transferred */ 81 | movl 0x34(%esp), %ecx 82 | 83 | /* pass data */ 84 | movl %ecx, 0x34(%eax) 85 | 86 | /* third arg of ontop_fcontext() == ontop-function */ 87 | movl 0x38(%esp), %ecx 88 | 89 | /* restore ESP (pointing to context-data) from EDX */ 90 | movl %eax, %esp 91 | 92 | #if !defined(BOOST_USE_TSX) 93 | /* restore MMX control- and status-word */ 94 | ldmxcsr (%esp) 95 | /* restore x87 control-word */ 96 | fldcw 0x4(%esp) 97 | #endif 98 | 99 | /* restore NT_TIB into EDX */ 100 | movl %fs:(0x18), %edx 101 | /* restore fiber local storage */ 102 | movl 0x8(%esp), %eax 103 | movl %eax, 0x10(%edx) 104 | /* restore current deallocation stack */ 105 | movl 0xc(%esp), %eax 106 | movl %eax, 0xe0c(%edx) 107 | /* restore current stack limit */ 108 | movl 0x10(%esp), %eax 109 | movl %eax, 0x08(%edx) 110 | /* restore current stack base */ 111 | movl 0x14(%esp), %eax 112 | movl %eax, 0x04(%edx) 113 | /* restore current SEH exception list */ 114 | movl 0x18(%esp), %eax 115 | movl %eax, (%edx) 116 | 117 | movl 0x1c(%esp), %edi /* restore EDI */ 118 | movl 0x20(%esp), %esi /* restore ESI */ 119 | movl 0x24(%esp), %ebx /* restore EBX */ 120 | movl 0x28(%esp), %ebp /* restore EBP */ 121 | 122 | /* prepare stack */ 123 | leal 0x2c(%esp), %esp 124 | 125 | /* keep return-address on stack */ 126 | 127 | /* jump to context */ 128 | jmp *%ecx 129 | 130 | .section .drectve 131 | .ascii " -export:\"_ontop_fcontext\"" 132 | -------------------------------------------------------------------------------- /asm/ontop_i386_ms_pe_gas.S: -------------------------------------------------------------------------------- 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 | to | data | EH NXT |SEH HNDLR| * 23 | * --------------------------------------------------------------------------------- * 24 | **************************************************************************************/ 25 | 26 | .file "ontop_i386_ms_pe_gas.asm" 27 | .text 28 | .p2align 4,,15 29 | 30 | /* mark as using no unregistered SEH handlers */ 31 | .globl @feat.00 32 | .def @feat.00; .scl 3; .type 0; .endef 33 | .set @feat.00, 1 34 | 35 | .globl _ontop_fcontext 36 | .def _ontop_fcontext; .scl 2; .type 32; .endef 37 | _ontop_fcontext: 38 | /* prepare stack */ 39 | leal -0x2c(%esp), %esp 40 | 41 | #if !defined(BOOST_USE_TSX) 42 | /* save MMX control- and status-word */ 43 | stmxcsr (%esp) 44 | /* save x87 control-word */ 45 | fnstcw 0x4(%esp) 46 | #endif 47 | 48 | /* load NT_TIB */ 49 | movl %fs:(0x18), %edx 50 | /* load fiber local storage */ 51 | movl 0x10(%edx), %eax 52 | movl %eax, 0x8(%esp) 53 | /* load current dealloction stack */ 54 | movl 0xe0c(%edx), %eax 55 | movl %eax, 0xc(%esp) 56 | /* load current stack limit */ 57 | movl 0x8(%edx), %eax 58 | movl %eax, 0x10(%esp) 59 | /* load current stack base */ 60 | movl 0x4(%edx), %eax 61 | movl %eax, 0x14(%esp) 62 | /* load current SEH exception list */ 63 | movl (%edx), %eax 64 | movl %eax, 0x18(%esp) 65 | 66 | movl %edi, 0x1c(%esp) /* save EDI */ 67 | movl %esi, 0x20(%esp) /* save ESI */ 68 | movl %ebx, 0x24(%esp) /* save EBX */ 69 | movl %ebp, 0x28(%esp) /* save EBP */ 70 | 71 | /* store ESP (pointing to context-data) in ECX */ 72 | movl %esp, %ecx 73 | 74 | /* first arg of ontop_fcontext() == fcontext to jump to */ 75 | movl 0x30(%esp), %eax 76 | 77 | /* pass parent fcontext_t */ 78 | movl %ecx, 0x30(%eax) 79 | 80 | /* second arg of ontop_fcontext() == data to be transferred */ 81 | movl 0x34(%esp), %ecx 82 | 83 | /* pass data */ 84 | movl %ecx, 0x34(%eax) 85 | 86 | /* third arg of ontop_fcontext() == ontop-function */ 87 | movl 0x38(%esp), %ecx 88 | 89 | /* restore ESP (pointing to context-data) from EDX */ 90 | movl %eax, %esp 91 | 92 | #if !defined(BOOST_USE_TSX) 93 | /* restore MMX control- and status-word */ 94 | ldmxcsr (%esp) 95 | /* restore x87 control-word */ 96 | fldcw 0x4(%esp) 97 | #endif 98 | 99 | /* restore NT_TIB into EDX */ 100 | movl %fs:(0x18), %edx 101 | /* restore fiber local storage */ 102 | movl 0x8(%esp), %eax 103 | movl %eax, 0x10(%edx) 104 | /* restore current deallocation stack */ 105 | movl 0xc(%esp), %eax 106 | movl %eax, 0xe0c(%edx) 107 | /* restore current stack limit */ 108 | movl 0x10(%esp), %eax 109 | movl %eax, 0x08(%edx) 110 | /* restore current stack base */ 111 | movl 0x14(%esp), %eax 112 | movl %eax, 0x04(%edx) 113 | /* restore current SEH exception list */ 114 | movl 0x18(%esp), %eax 115 | movl %eax, (%edx) 116 | 117 | movl 0x1c(%esp), %edi /* restore EDI */ 118 | movl 0x20(%esp), %esi /* restore ESI */ 119 | movl 0x24(%esp), %ebx /* restore EBX */ 120 | movl 0x28(%esp), %ebp /* restore EBP */ 121 | 122 | /* prepare stack */ 123 | leal 0x2c(%esp), %esp 124 | 125 | /* keep return-address on stack */ 126 | 127 | /* jump to context */ 128 | jmp *%ecx 129 | 130 | .section .drectve 131 | .ascii " -export:\"ontop_fcontext\"" 132 | -------------------------------------------------------------------------------- /asm/ontop_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 | to | data | EH NXT |SEH HNDLR| * 23 | * --------------------------------------------------------------------------------- * 24 | **************************************************************************************/ 25 | 26 | .file "ontop_i386_ms_pe_gas.asm" 27 | .text 28 | .p2align 4,,15 29 | 30 | /* mark as using no unregistered SEH handlers */ 31 | .globl @feat.00 32 | .def @feat.00; .scl 3; .type 0; .endef 33 | .set @feat.00, 1 34 | 35 | .globl _ontop_fcontext 36 | .def _ontop_fcontext; .scl 2; .type 32; .endef 37 | _ontop_fcontext: 38 | /* prepare stack */ 39 | leal -0x2c(%esp), %esp 40 | 41 | #if !defined(BOOST_USE_TSX) 42 | /* save MMX control- and status-word */ 43 | stmxcsr (%esp) 44 | /* save x87 control-word */ 45 | fnstcw 0x4(%esp) 46 | #endif 47 | 48 | /* load NT_TIB */ 49 | movl %fs:(0x18), %edx 50 | /* load fiber local storage */ 51 | movl 0x10(%edx), %eax 52 | movl %eax, 0x8(%esp) 53 | /* load current dealloction stack */ 54 | movl 0xe0c(%edx), %eax 55 | movl %eax, 0xc(%esp) 56 | /* load current stack limit */ 57 | movl 0x8(%edx), %eax 58 | movl %eax, 0x10(%esp) 59 | /* load current stack base */ 60 | movl 0x4(%edx), %eax 61 | movl %eax, 0x14(%esp) 62 | /* load current SEH exception list */ 63 | movl (%edx), %eax 64 | movl %eax, 0x18(%esp) 65 | 66 | movl %edi, 0x1c(%esp) /* save EDI */ 67 | movl %esi, 0x20(%esp) /* save ESI */ 68 | movl %ebx, 0x24(%esp) /* save EBX */ 69 | movl %ebp, 0x28(%esp) /* save EBP */ 70 | 71 | /* store ESP (pointing to context-data) in ECX */ 72 | movl %esp, %ecx 73 | 74 | /* first arg of ontop_fcontext() == fcontext to jump to */ 75 | movl 0x30(%esp), %eax 76 | 77 | /* pass parent fcontext_t */ 78 | movl %ecx, 0x30(%eax) 79 | 80 | /* second arg of ontop_fcontext() == data to be transferred */ 81 | movl 0x34(%esp), %ecx 82 | 83 | /* pass data */ 84 | movl %ecx, 0x34(%eax) 85 | 86 | /* third arg of ontop_fcontext() == ontop-function */ 87 | movl 0x38(%esp), %ecx 88 | 89 | /* restore ESP (pointing to context-data) from EDX */ 90 | movl %eax, %esp 91 | 92 | #if !defined(BOOST_USE_TSX) 93 | /* restore MMX control- and status-word */ 94 | ldmxcsr (%esp) 95 | /* restore x87 control-word */ 96 | fldcw 0x4(%esp) 97 | #endif 98 | 99 | /* restore NT_TIB into EDX */ 100 | movl %fs:(0x18), %edx 101 | /* restore fiber local storage */ 102 | movl 0x8(%esp), %eax 103 | movl %eax, 0x10(%edx) 104 | /* restore current deallocation stack */ 105 | movl 0xc(%esp), %eax 106 | movl %eax, 0xe0c(%edx) 107 | /* restore current stack limit */ 108 | movl 0x10(%esp), %eax 109 | movl %eax, 0x08(%edx) 110 | /* restore current stack base */ 111 | movl 0x14(%esp), %eax 112 | movl %eax, 0x04(%edx) 113 | /* restore current SEH exception list */ 114 | movl 0x18(%esp), %eax 115 | movl %eax, (%edx) 116 | 117 | movl 0x1c(%esp), %edi /* restore EDI */ 118 | movl 0x20(%esp), %esi /* restore ESI */ 119 | movl 0x24(%esp), %ebx /* restore EBX */ 120 | movl 0x28(%esp), %ebp /* restore EBP */ 121 | 122 | /* prepare stack */ 123 | leal 0x2c(%esp), %esp 124 | 125 | /* keep return-address on stack */ 126 | 127 | /* jump to context */ 128 | jmp *%ecx 129 | 130 | .section .drectve 131 | .ascii " -export:\"ontop_fcontext\"" 132 | -------------------------------------------------------------------------------- /asm/ontop_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 | to | data | EH NXT |SEH HNDLR| 20 | ; --------------------------------------------------------------------------------- 21 | 22 | .386 23 | .XMM 24 | .model flat, c 25 | .code 26 | 27 | ontop_fcontext PROC BOOST_CONTEXT_EXPORT 28 | ; prepare stack 29 | lea esp, [esp-02ch] 30 | 31 | IFNDEF BOOST_USE_TSX 32 | ; save MMX control- and status-word 33 | stmxcsr [esp] 34 | ; save x87 control-word 35 | fnstcw [esp+04h] 36 | ENDIF 37 | 38 | assume fs:nothing 39 | ; load NT_TIB into ECX 40 | mov edx, fs:[018h] 41 | assume fs:error 42 | ; load fiber local storage 43 | mov eax, [edx+010h] 44 | mov [esp+08h], eax 45 | ; load current deallocation stack 46 | mov eax, [edx+0e0ch] 47 | mov [esp+0ch], eax 48 | ; load current stack limit 49 | mov eax, [edx+08h] 50 | mov [esp+010h], eax 51 | ; load current stack base 52 | mov eax, [edx+04h] 53 | mov [esp+014h], eax 54 | ; load current SEH exception list 55 | mov eax, [edx] 56 | mov [esp+018h], eax 57 | 58 | mov [esp+01ch], edi ; save EDI 59 | mov [esp+020h], esi ; save ESI 60 | mov [esp+024h], ebx ; save EBX 61 | mov [esp+028h], ebp ; save EBP 62 | 63 | ; store ESP (pointing to context-data) in ECX 64 | mov ecx, esp 65 | 66 | ; first arg of ontop_fcontext() == fcontext to jump to 67 | mov eax, [esp+030h] 68 | 69 | ; pass parent fcontext_t 70 | mov [eax+030h], ecx 71 | 72 | ; second arg of ontop_fcontext() == data to be transferred 73 | mov ecx, [esp+034h] 74 | 75 | ; pass data 76 | mov [eax+034h], ecx 77 | 78 | ; third arg of ontop_fcontext() == ontop-function 79 | mov ecx, [esp+038h] 80 | 81 | ; restore ESP (pointing to context-data) from EAX 82 | mov esp, eax 83 | 84 | IFNDEF BOOST_USE_TSX 85 | ; restore MMX control- and status-word 86 | ldmxcsr [esp] 87 | ; restore x87 control-word 88 | fldcw [esp+04h] 89 | ENDIF 90 | 91 | assume fs:nothing 92 | ; load NT_TIB into EDX 93 | mov edx, fs:[018h] 94 | assume fs:error 95 | ; restore fiber local storage 96 | mov eax, [esp+08h] 97 | mov [edx+010h], eax 98 | ; restore current deallocation stack 99 | mov eax, [esp+0ch] 100 | mov [edx+0e0ch], eax 101 | ; restore current stack limit 102 | mov eax, [esp+010h] 103 | mov [edx+08h], eax 104 | ; restore current stack base 105 | mov eax, [esp+014h] 106 | mov [edx+04h], eax 107 | ; restore current SEH exception list 108 | mov eax, [esp+018h] 109 | mov [edx], eax 110 | 111 | mov edi, [esp+01ch] ; restore EDI 112 | mov esi, [esp+020h] ; restore ESI 113 | mov ebx, [esp+024h] ; restore EBX 114 | mov ebp, [esp+028h] ; restore EBP 115 | 116 | ; prepare stack 117 | lea esp, [esp+02ch] 118 | 119 | ; keep return-address on stack 120 | 121 | ; jump to context 122 | jmp ecx 123 | ontop_fcontext ENDP 124 | END 125 | -------------------------------------------------------------------------------- /asm/ontop_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 | hidden | * 16 | * ---------------------------------------------------------------------------------- * 17 | * ---------------------------------------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ---------------------------------------------------------------------------------- * 20 | * | 0x20 | 0x24 | | * 21 | * ---------------------------------------------------------------------------------- * 22 | * | to | data | | * 23 | * ---------------------------------------------------------------------------------- * 24 | * * 25 | ****************************************************************************************/ 26 | 27 | .file "ontop_i386_sysv_elf_gas.S" 28 | .text 29 | .globl ontop_fcontext 30 | .align 2 31 | .type ontop_fcontext,@function 32 | ontop_fcontext: 33 | leal -0x18(%esp), %esp /* prepare stack */ 34 | 35 | #if !defined(BOOST_USE_TSX) 36 | stmxcsr (%esp) /* save MMX control- and status-word */ 37 | fnstcw 0x4(%esp) /* save x87 control-word */ 38 | #endif 39 | 40 | movl %edi, 0x8(%esp) /* save EDI */ 41 | movl %esi, 0xc(%esp) /* save ESI */ 42 | movl %ebx, 0x10(%esp) /* save EBX */ 43 | movl %ebp, 0x14(%esp) /* save EBP */ 44 | 45 | /* store ESP (pointing to context-data) in ECX */ 46 | movl %esp, %ecx 47 | 48 | /* first arg of ontop_fcontext() == fcontext to jump to */ 49 | movl 0x20(%esp), %eax 50 | 51 | /* pass parent fcontext_t */ 52 | movl %ecx, 0x20(%eax) 53 | 54 | /* second arg of ontop_fcontext() == data to be transferred */ 55 | movl 0x24(%esp), %ecx 56 | 57 | /* pass data */ 58 | movl %ecx, 0x24(%eax) 59 | 60 | /* third arg of ontop_fcontext() == ontop-function */ 61 | movl 0x28(%esp), %ecx 62 | 63 | /* restore ESP (pointing to context-data) from EAX */ 64 | movl %eax, %esp 65 | 66 | /* address of returned transport_t */ 67 | movl 0x1c(%esp), %eax 68 | /* return parent fcontext_t */ 69 | movl %ecx, (%eax) 70 | /* return data */ 71 | movl %edx, 0x4(%eax) 72 | 73 | #if !defined(BOOST_USE_TSX) 74 | ldmxcsr (%esp) /* restore MMX control- and status-word */ 75 | fldcw 0x4(%esp) /* restore x87 control-word */ 76 | #endif 77 | 78 | movl 0x8(%esp), %edi /* restore EDI */ 79 | movl 0xc(%esp), %esi /* restore ESI */ 80 | movl 0x10(%esp), %ebx /* restore EBX */ 81 | movl 0x14(%esp), %ebp /* restore EBP */ 82 | 83 | leal 0x18(%esp), %esp /* prepare stack */ 84 | 85 | /* jump to context */ 86 | jmp *%ecx 87 | .size ontop_fcontext,.-ontop_fcontext 88 | 89 | /* Mark that we don't need executable stack. */ 90 | .section .note.GNU-stack,"",%progbits 91 | -------------------------------------------------------------------------------- /asm/ontop_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 | to | * 16 | * ---------------------------------------------------------------------------------- * 17 | * ---------------------------------------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ---------------------------------------------------------------------------------- * 20 | * | 0x20 | | * 21 | * ---------------------------------------------------------------------------------- * 22 | * | data | | * 23 | * ---------------------------------------------------------------------------------- * 24 | * * 25 | ****************************************************************************************/ 26 | 27 | .text 28 | .globl _ontop_fcontext 29 | .align 2 30 | _ontop_fcontext: 31 | leal -0x18(%esp), %esp /* prepare stack */ 32 | 33 | #if !defined(BOOST_USE_TSX) 34 | stmxcsr (%esp) /* save MMX control- and status-word */ 35 | fnstcw 0x4(%esp) /* save x87 control-word */ 36 | #endif 37 | 38 | movl %edi, 0x8(%esp) /* save EDI */ 39 | movl %esi, 0xc(%esp) /* save ESI */ 40 | movl %ebx, 0x10(%esp) /* save EBX */ 41 | movl %ebp, 0x14(%esp) /* save EBP */ 42 | 43 | /* store ESP (pointing to context-data) in ECX */ 44 | movl %esp, %ecx 45 | 46 | /* first arg of ontop_fcontext() == fcontext to jump to */ 47 | movl 0x1c(%esp), %eax 48 | 49 | /* pass parent fcontext_t */ 50 | movl %ecx, 0x1c(%eax) 51 | 52 | /* second arg of ontop_fcontext() == data to be transferred */ 53 | movl 0x20(%esp), %ecx 54 | 55 | /* pass data */ 56 | movl %ecx, 0x20(%eax) 57 | 58 | /* third arg of ontop_fcontext() == ontop-function */ 59 | movl 0x24(%esp), %ecx 60 | 61 | /* restore ESP (pointing to context-data) from EAX */ 62 | movl %eax, %esp 63 | 64 | /* return parent fcontext_t */ 65 | movl %ecx, %eax 66 | /* returned data is stored in EDX */ 67 | 68 | #if !defined(BOOST_USE_TSX) 69 | ldmxcsr (%esp) /* restore MMX control- and status-word */ 70 | fldcw 0x4(%esp) /* restore x87 control-word */ 71 | #endif 72 | 73 | movl 0x8(%esp), %edi /* restore EDI */ 74 | movl 0xc(%esp), %esi /* restore ESI */ 75 | movl 0x10(%esp), %ebx /* restore EBX */ 76 | movl 0x14(%esp), %ebp /* restore EBP */ 77 | 78 | leal 0x18(%esp), %esp /* prepare stack */ 79 | 80 | /* jump to context */ 81 | jmp *%ecx 82 | -------------------------------------------------------------------------------- /asm/ontop_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 "ontop_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "ontop_x86_64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /asm/ontop_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 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * 28 | * ------------------------------------------------- * 29 | * | S4 | S5 | S6 | S7 | FP |hiddn| RA | PC | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * 35 | * ------------------------------------------------- * 36 | * | ABI ARGS | GP | FCTX| DATA| | * 37 | * ------------------------------------------------- * 38 | * * 39 | * *****************************************************/ 40 | 41 | .file "ontop_mips32_o32_elf_gas.S" 42 | .text 43 | .globl ontop_fcontext 44 | .align 2 45 | .type ontop_fcontext,@function 46 | .ent ontop_fcontext 47 | ontop_fcontext: 48 | # reserve space on stack 49 | addiu $sp, $sp, -96 50 | 51 | sw $s0, 48($sp) # save S0 52 | sw $s1, 52($sp) # save S1 53 | sw $s2, 56($sp) # save S2 54 | sw $s3, 60($sp) # save S3 55 | sw $s4, 64($sp) # save S4 56 | sw $s5, 68($sp) # save S5 57 | sw $s6, 72($sp) # save S6 58 | sw $s7, 76($sp) # save S7 59 | sw $fp, 80($sp) # save FP 60 | sw $a0, 84($sp) # save hidden, address of returned transfer_t 61 | sw $ra, 88($sp) # save RA 62 | sw $ra, 92($sp) # save RA as PC 63 | 64 | #if defined(__mips_hard_float) 65 | s.d $f20, ($sp) # save F20 66 | s.d $f22, 8($sp) # save F22 67 | s.d $f24, 16($sp) # save F24 68 | s.d $f26, 24($sp) # save F26 69 | s.d $f28, 32($sp) # save F28 70 | s.d $f30, 40($sp) # save F30 71 | #endif 72 | 73 | # store SP (pointing to context-data) in A0 74 | move $a0, $sp 75 | 76 | # restore SP (pointing to context-data) from A1 77 | move $sp, $a1 78 | 79 | #if defined(__mips_hard_float) 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 | #endif 87 | 88 | lw $s0, 48($sp) # restore S0 89 | lw $s1, 52($sp) # restore S1 90 | lw $s2, 56($sp) # restore S2 91 | lw $s3, 60($sp) # restore S3 92 | lw $s4, 64($sp) # restore S4 93 | lw $s5, 68($sp) # restore S5 94 | lw $s6, 72($sp) # restore S6 95 | lw $s7, 76($sp) # restore S7 96 | lw $fp, 80($sp) # restore FP 97 | lw $v0, 84($sp) # restore hidden, address of returned transfer_t 98 | lw $ra, 88($sp) # restore RA 99 | 100 | # load PC 101 | move $t9, $a3 102 | 103 | # adjust stack 104 | addiu $sp, $sp, 96 105 | 106 | # return transfer_t from jump 107 | sw $a0, ($v0) # fctx of transfer_t 108 | sw $a2, 4($v0) # data of transfer_t 109 | # pass transfer_t as first arg in context function 110 | # A0 == hidden, A1 == fctx, A2 == data 111 | move $a1, $a0 112 | move $a0, $v0 113 | 114 | # jump to context 115 | jr $t9 116 | .end ontop_fcontext 117 | .size ontop_fcontext, .-ontop_fcontext 118 | 119 | /* Mark that we don't need executable stack. */ 120 | .section .note.GNU-stack,"",%progbits 121 | -------------------------------------------------------------------------------- /asm/ontop_mips64_n64_elf_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Jiaxun Yang 2018. 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 6 | */ 7 | 8 | /******************************************************* 9 | * * 10 | * ------------------------------------------------- * 11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 | * ------------------------------------------------- * 13 | * | 0 | 8 | 16 | 24 | * 14 | * ------------------------------------------------- * 15 | * | F24 | F25 | F26 | F27 | * 16 | * ------------------------------------------------- * 17 | * ------------------------------------------------- * 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 | * ------------------------------------------------- * 20 | * | 32 | 40 | 48 | 56 | * 21 | * ------------------------------------------------- * 22 | * | F28 | F29 | F30 | F31 | * 23 | * ------------------------------------------------- * 24 | * ------------------------------------------------- * 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 | * ------------------------------------------------- * 27 | * | 64 | 72 | 80 | 88 | * 28 | * ------------------------------------------------- * 29 | * | S0 | S1 | S2 | S3 | * 30 | * ------------------------------------------------- * 31 | * ------------------------------------------------- * 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 | * ------------------------------------------------- * 34 | * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * 35 | * ------------------------------------------------- * 36 | * | S4 | S5 | S6 | S7 | * 37 | * ------------------------------------------------- * 38 | * ------------------------------------------------- * 39 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 40 | * ------------------------------------------------- * 41 | * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * 42 | * ------------------------------------------------- * 43 | * | FP | GP | RA | PC | * 44 | * ------------------------------------------------- * 45 | * * 46 | * *****************************************************/ 47 | 48 | .file "ontop_mips64_n64_elf_gas.S" 49 | .text 50 | .globl ontop_fcontext 51 | .align 3 52 | .type ontop_fcontext,@function 53 | .ent ontop_fcontext 54 | ontop_fcontext: 55 | # reserve space on stack 56 | daddiu $sp, $sp, -160 57 | 58 | sd $s0, 64($sp) # save S0 59 | sd $s1, 72($sp) # save S1 60 | sd $s2, 80($sp) # save S2 61 | sd $s3, 88($sp) # save S3 62 | sd $s4, 96($sp) # save S4 63 | sd $s5, 104($sp) # save S5 64 | sd $s6, 112($sp) # save S6 65 | sd $s7, 120($sp) # save S7 66 | sd $fp, 128($sp) # save FP 67 | sd $ra, 144($sp) # save RA 68 | sd $ra, 152($sp) # save RA as PC 69 | 70 | #if defined(__mips_hard_float) 71 | s.d $f24, 0($sp) # save F24 72 | s.d $f25, 8($sp) # save F25 73 | s.d $f26, 16($sp) # save F26 74 | s.d $f27, 24($sp) # save F27 75 | s.d $f28, 32($sp) # save F28 76 | s.d $f29, 40($sp) # save F29 77 | s.d $f30, 48($sp) # save F30 78 | s.d $f31, 56($sp) # save F31 79 | #endif 80 | 81 | # store SP (pointing to context-data) in t0 82 | move $t0, $sp 83 | 84 | # restore SP (pointing to context-data) from a0 85 | move $sp, $a0 86 | 87 | #if defined(__mips_hard_float) 88 | l.d $f24, 0($sp) # restore F24 89 | l.d $f25, 8($sp) # restore F25 90 | l.d $f26, 16($sp) # restore F26 91 | l.d $f27, 24($sp) # restore F27 92 | l.d $f28, 32($sp) # restore F28 93 | l.d $f29, 40($sp) # restore F29 94 | l.d $f30, 48($sp) # restore F30 95 | l.d $f31, 56($sp) # restore F31 96 | #endif 97 | 98 | ld $s0, 64($sp) # restore S0 99 | ld $s1, 72($sp) # restore S1 100 | ld $s2, 80($sp) # restore S2 101 | ld $s3, 88($sp) # restore S3 102 | ld $s4, 96($sp) # restore S4 103 | ld $s5, 104($sp) # restore S5 104 | ld $s6, 112($sp) # restore S6 105 | ld $s7, 120($sp) # restore S7 106 | ld $fp, 128($sp) # restore FP 107 | ld $ra, 144($sp) # restore RA 108 | 109 | # load PC 110 | move $t9, $a2 111 | 112 | # adjust stack 113 | daddiu $sp, $sp, 160 114 | 115 | move $a0, $t0 # move param from t0 to a0 as param 116 | 117 | # jump to context 118 | jr $t9 119 | .end ontop_fcontext 120 | .size ontop_fcontext, .-ontop_fcontext 121 | 122 | /* Mark that we don't need executable stack. */ 123 | .section .note.GNU-stack,"",%progbits 124 | -------------------------------------------------------------------------------- /asm/ontop_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 "ontop_ppc32_sysv_macho_gas.S" 12 | #elif defined(__ppc64__) 13 | #include "ontop_ppc64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /asm/ontop_ppc64_sysv_xcoff_gas.S: -------------------------------------------------------------------------------- 1 | .align 2 2 | .globl .ontop_fcontext 3 | .ontop_fcontext: 4 | # reserve space on stack 5 | subi 1, 1, 184 6 | 7 | std 13, 0(1) # save R13 8 | std 14, 8(1) # save R14 9 | std 15, 16(1) # save R15 10 | std 16, 24(1) # save R16 11 | std 17, 32(1) # save R17 12 | std 18, 40(1) # save R18 13 | std 19, 48(1) # save R19 14 | std 20, 56(1) # save R20 15 | std 21, 64(1) # save R21 16 | std 22, 72(1) # save R22 17 | std 23, 80(1) # save R23 18 | std 24, 88(1) # save R24 19 | std 25, 96(1) # save R25 20 | std 26, 104(1) # save R26 21 | std 27, 112(1) # save R27 22 | std 29, 120(1) # save R28 23 | std 29, 128(1) # save R29 24 | std 30, 136(1) # save R30 25 | std 31, 144(1) # save R31 26 | std 3, 152(1) # save hidden 27 | 28 | # save CR 29 | mfcr 0 30 | std 0, 160(1) 31 | # save LR 32 | mflr 0 33 | std 0, 168(1) 34 | # save LR as PC 35 | std 0, 176(1) 36 | 37 | # store RSP (pointing to context-data) in R7 38 | mr 7, 1 39 | 40 | # restore RSP (pointing to context-data) from R4 41 | mr 1, 4 42 | 43 | ld 13, 0(1) # restore R13 44 | ld 14, 8(1) # restore R14 45 | ld 15, 16(1) # restore R15 46 | ld 16, 24(1) # restore R16 47 | ld 17, 32(1) # restore R17 48 | ld 18, 40(1) # restore R18 49 | ld 19, 48(1) # restore R19 50 | ld 20, 56(1) # restore R20 51 | ld 21, 64(1) # restore R21 52 | ld 22, 72(1) # restore R22 53 | ld 23, 80(1) # restore R23 54 | ld 24, 88(1) # restore R24 55 | ld 25, 96(1) # restore R25 56 | ld 26, 104(1) # restore R26 57 | ld 27, 112(1) # restore R27 58 | ld 28, 120(1) # restore R28 59 | ld 29, 128(1) # restore R29 60 | ld 30, 136(1) # restore R30 61 | ld 31, 144(1) # restore R31 62 | ld 4, 152(1) # restore hidden 63 | 64 | # restore CR 65 | ld 0, 160(1) 66 | mtcr 0 67 | # restore LR 68 | ld 0, 168(1) 69 | mtlr 0 70 | # ignore PC 71 | 72 | # adjust stack 73 | addi 1, 1, 184 74 | 75 | # return transfer_t 76 | std 7, 0(4) 77 | std 5, 8(4) 78 | 79 | # restore CTR 80 | mtctr 6 81 | 82 | # jump to context 83 | bctr 84 | -------------------------------------------------------------------------------- /asm/ontop_s390x_sysv_elf_gas.S: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * ------------------------------------------------- * 3 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 4 | * ------------------------------------------------- * 5 | * | 0 | 8 | 16 | 24 | * 6 | * ------------------------------------------------- * 7 | * | t.fctx | t.data | r2 | r6 | * 8 | * ------------------------------------------------- * 9 | * ------------------------------------------------- * 10 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 11 | * ------------------------------------------------- * 12 | * | 32 | 40 | 48 | 56 | * 13 | * ------------------------------------------------- * 14 | * | r7 | r8 | r9 | r10 | * 15 | * ------------------------------------------------- * 16 | * ------------------------------------------------- * 17 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 18 | * ------------------------------------------------- * 19 | * | 64 | 72 | 80 | 88 | * 20 | * ------------------------------------------------- * 21 | * | r11 | r12 | r13 | r14 | * 22 | * ------------------------------------------------- * 23 | * ------------------------------------------------- * 24 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 25 | * ------------------------------------------------- * 26 | * | 96 | 104 | 112 | 120 | * 27 | * ------------------------------------------------- * 28 | * | f8 | f9 | f10 | f11 | * 29 | * ------------------------------------------------- * 30 | * ------------------------------------------------- * 31 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 32 | * ------------------------------------------------- * 33 | * | 128 | 136 | 144 | 152 | * 34 | * ------------------------------------------------- * 35 | * | f12 | f13 | f14 | f15 | * 36 | * ------------------------------------------------- * 37 | * ------------------------------------------------- * 38 | * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * 39 | * ------------------------------------------------- * 40 | * | 160 | 168 | 176 | | * 41 | * ------------------------------------------------- * 42 | * | fpc | pc | | | * 43 | * ------------------------------------------------- * 44 | *******************************************************/ 45 | 46 | .text 47 | .align 8 48 | .global ontop_fcontext 49 | .type ontop_fcontext, @function 50 | 51 | #define ARG_OFFSET 0 52 | #define GR_OFFSET 16 53 | #define R14_OFFSET 88 54 | #define FP_OFFSET 96 55 | #define FPC_OFFSET 160 56 | #define PC_OFFSET 168 57 | #define CONTEXT_SIZE 176 58 | 59 | 60 | /* 61 | 62 | typedef void* fcontext_t; 63 | 64 | struct transfer_t { 65 | fcontext_t fctx; 66 | void * data; 67 | }; 68 | 69 | transfer_t ontop_fcontext( fcontext_t const to, 70 | void * vp, 71 | transfer_t (* fn)( transfer_t) ); 72 | 73 | Incoming args 74 | r2 - Hidden argument to the location where the return transfer_t needs to be returned 75 | r3 - Target context 76 | r4 - Data pointer 77 | r5 - Function to be executed 78 | 79 | This implementation assumes that ontop_fcontext will never be called with target contexts 80 | created via make_fcontext. 81 | 82 | */ 83 | 84 | ontop_fcontext: 85 | /* Reserve stack space to store the current context. */ 86 | aghi %r15,-CONTEXT_SIZE 87 | 88 | /* Save the argument register holding the location of the return value. */ 89 | stg %r2,GR_OFFSET(%r15) 90 | 91 | /* Save the call-saved general purpose registers. */ 92 | stmg %r6,%r14,GR_OFFSET+8(%r15) 93 | 94 | /* Save call-saved floating point registers. */ 95 | std %f8,FP_OFFSET(%r15) 96 | std %f9,FP_OFFSET+8(%r15) 97 | std %f10,FP_OFFSET+16(%r15) 98 | std %f11,FP_OFFSET+24(%r15) 99 | std %f12,FP_OFFSET+32(%r15) 100 | std %f13,FP_OFFSET+40(%r15) 101 | std %f14,FP_OFFSET+48(%r15) 102 | std %f15,FP_OFFSET+56(%r15) 103 | 104 | /* Save the return address as current pc. */ 105 | stg %r14,PC_OFFSET(%r15) 106 | 107 | /* Save the floating point control register. */ 108 | stfpc FPC_OFFSET(%r15) 109 | 110 | /* Backup the stack pointer pointing to the old context-data into r1. */ 111 | lgr %r1,%r15 112 | 113 | /* Load the new context pointer as stack pointer. */ 114 | lgr %r15,%r3 115 | 116 | /* Restore the call-saved GPRs from the new context. */ 117 | lmg %r6,%r14,GR_OFFSET+8(%r15) 118 | 119 | /* Restore call-saved floating point registers. */ 120 | ld %f8,FP_OFFSET(%r15) 121 | ld %f9,FP_OFFSET+8(%r15) 122 | ld %f10,FP_OFFSET+16(%r15) 123 | ld %f11,FP_OFFSET+24(%r15) 124 | ld %f12,FP_OFFSET+32(%r15) 125 | ld %f13,FP_OFFSET+40(%r15) 126 | ld %f14,FP_OFFSET+48(%r15) 127 | ld %f15,FP_OFFSET+56(%r15) 128 | 129 | /* Load the floating point control register. */ 130 | lfpc FPC_OFFSET(%r15) 131 | 132 | /* Store the transfer_t values located in the saved context. */ 133 | stg %r1,0(%r1) /* transfer_t.fctx = old context */ 134 | stg %r4,8(%r1) /* transfer_t.data = data */ 135 | 136 | /* Set up the arguments for the target function. */ 137 | lg %r2,GR_OFFSET(%r15) 138 | lgr %r3,%r1 139 | 140 | /* Deallocate the context. */ 141 | aghi %r15,CONTEXT_SIZE 142 | 143 | br %r5 144 | 145 | .size ontop_fcontext,.-ontop_fcontext 146 | .section .note.GNU-stack,"",%progbits 147 | -------------------------------------------------------------------------------- /asm/ontop_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 | ****************************************************************************************/ 26 | 27 | .file "ontop_x86_64_sysv_elf_gas.S" 28 | .text 29 | .globl ontop_fcontext 30 | .type ontop_fcontext,@function 31 | .align 16 32 | ontop_fcontext: 33 | /* preserve ontop-function in R8 */ 34 | movq %rdx, %r8 35 | 36 | leaq -0x38(%rsp), %rsp /* prepare stack */ 37 | 38 | #if !defined(BOOST_USE_TSX) 39 | stmxcsr (%rsp) /* save MMX control- and status-word */ 40 | fnstcw 0x4(%rsp) /* save x87 control-word */ 41 | #endif 42 | 43 | movq %r12, 0x8(%rsp) /* save R12 */ 44 | movq %r13, 0x10(%rsp) /* save R13 */ 45 | movq %r14, 0x18(%rsp) /* save R14 */ 46 | movq %r15, 0x20(%rsp) /* save R15 */ 47 | movq %rbx, 0x28(%rsp) /* save RBX */ 48 | movq %rbp, 0x30(%rsp) /* save RBP */ 49 | 50 | /* store RSP (pointing to context-data) in RAX */ 51 | movq %rsp, %rax 52 | 53 | /* restore RSP (pointing to context-data) from RDI */ 54 | movq %rdi, %rsp 55 | 56 | #if !defined(BOOST_USE_TSX) 57 | ldmxcsr (%rsp) /* restore MMX control- and status-word */ 58 | fldcw 0x4(%rsp) /* restore x87 control-word */ 59 | #endif 60 | 61 | movq 0x8(%rsp), %r12 /* restore R12 */ 62 | movq 0x10(%rsp), %r13 /* restore R13 */ 63 | movq 0x18(%rsp), %r14 /* restore R14 */ 64 | movq 0x20(%rsp), %r15 /* restore R15 */ 65 | movq 0x28(%rsp), %rbx /* restore RBX */ 66 | movq 0x30(%rsp), %rbp /* restore RBP */ 67 | 68 | leaq 0x38(%rsp), %rsp /* prepare stack */ 69 | 70 | /* return transfer_t from jump */ 71 | #if !defined(_ILP32) 72 | /* RAX == fctx, RDX == data */ 73 | movq %rsi, %rdx 74 | #else 75 | /* RAX == data:fctx */ 76 | salq $32, %rsi 77 | orq %rsi, %rax 78 | #endif 79 | /* pass transfer_t as first arg in context function */ 80 | #if !defined(_ILP32) 81 | /* RDI == fctx, RSI == data */ 82 | #else 83 | /* RDI == data:fctx */ 84 | #endif 85 | movq %rax, %rdi 86 | 87 | /* keep return-address on stack */ 88 | 89 | /* indirect jump to context */ 90 | jmp *%r8 91 | .size ontop_fcontext,.-ontop_fcontext 92 | 93 | /* Mark that we don't need executable stack. */ 94 | .section .note.GNU-stack,"",%progbits 95 | -------------------------------------------------------------------------------- /asm/ontop_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 | ****************************************************************************************/ 26 | 27 | .text 28 | .globl _ontop_fcontext 29 | .align 8 30 | _ontop_fcontext: 31 | /* preserve ontop-function in R8 */ 32 | movq %rdx, %r8 33 | 34 | leaq -0x38(%rsp), %rsp /* prepare stack */ 35 | 36 | #if !defined(BOOST_USE_TSX) 37 | stmxcsr (%rsp) /* save MMX control- and status-word */ 38 | fnstcw 0x4(%rsp) /* save x87 control-word */ 39 | #endif 40 | 41 | movq %r12, 0x8(%rsp) /* save R12 */ 42 | movq %r13, 0x10(%rsp) /* save R13 */ 43 | movq %r14, 0x18(%rsp) /* save R14 */ 44 | movq %r15, 0x20(%rsp) /* save R15 */ 45 | movq %rbx, 0x28(%rsp) /* save RBX */ 46 | movq %rbp, 0x30(%rsp) /* save RBP */ 47 | 48 | /* store RSP (pointing to context-data) in RAX */ 49 | movq %rsp, %rax 50 | 51 | /* restore RSP (pointing to context-data) from RDI */ 52 | movq %rdi, %rsp 53 | 54 | #if !defined(BOOST_USE_TSX) 55 | ldmxcsr (%rsp) /* restore MMX control- and status-word */ 56 | fldcw 0x4(%rsp) /* restore x87 control-word */ 57 | #endif 58 | 59 | movq 0x8(%rsp), %r12 /* restore R12 */ 60 | movq 0x10(%rsp), %r13 /* restore R13 */ 61 | movq 0x18(%rsp), %r14 /* restore R14 */ 62 | movq 0x20(%rsp), %r15 /* restore R15 */ 63 | movq 0x28(%rsp), %rbx /* restore RBX */ 64 | movq 0x30(%rsp), %rbp /* restore RBP */ 65 | 66 | leaq 0x38(%rsp), %rsp /* prepare stack */ 67 | 68 | /* return transfer_t from jump */ 69 | /* RAX == fctx, RDX == data */ 70 | movq %rsi, %rdx 71 | /* pass transfer_t as first arg in context function */ 72 | /* RDI == fctx, RSI == data */ 73 | movq %rax, %rdi 74 | 75 | /* keep return-address on stack */ 76 | 77 | /* indirect jump to context */ 78 | jmp *%r8 79 | -------------------------------------------------------------------------------- /asm/tail_ppc32_sysv_elf_gas.cpp: -------------------------------------------------------------------------------- 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 | #include 8 | 9 | using boost::context::detail::fcontext_t; 10 | using boost::context::detail::transfer_t; 11 | 12 | // This C++ tail of ontop_fcontext() allocates transfer_t{ from, vp } 13 | // on the stack. If fn() throws a C++ exception, then the C++ runtime 14 | // must remove this tail's stack frame. 15 | extern "C" transfer_t 16 | ontop_fcontext_tail( int ignore, void * vp, transfer_t (* fn)(transfer_t), fcontext_t const from) { 17 | return fn( transfer_t{ from, vp }); 18 | } 19 | -------------------------------------------------------------------------------- /copy_pe_gas_win.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | 4 | pushd asm 5 | 6 | copy /y jump_i386_ms_pe_gas.asm jump_i386_ms_pe_gas.S 7 | copy /y jump_x86_64_ms_pe_gas.asm jump_x86_64_ms_pe_gas.S 8 | copy /y make_i386_ms_pe_gas.asm make_i386_ms_pe_gas.S 9 | copy /y make_x86_64_ms_pe_gas.asm make_x86_64_ms_pe_gas.S 10 | copy /y ontop_i386_ms_pe_gas.asm ontop_i386_ms_pe_gas.S 11 | copy /y ontop_x86_64_ms_pe_gas.asm ontop_x86_64_ms_pe_gas.S 12 | 13 | popd -------------------------------------------------------------------------------- /include/fcontext/fcontext.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | typedef void* fcontext_t; 10 | 11 | typedef struct 12 | { 13 | fcontext_t ctx; 14 | void* data; 15 | } fcontext_transfer_t; 16 | 17 | typedef struct 18 | { 19 | void* sptr; 20 | size_t ssize; 21 | } fcontext_stack_t; 22 | 23 | /** 24 | * Callback definition for context (coroutine) 25 | */ 26 | typedef void (*pfn_fcontext)(fcontext_transfer_t); 27 | 28 | /** 29 | * Switches to another context 30 | * @param to Target context to switch to 31 | * @param vp Custom user pointer to pass to new context 32 | */ 33 | fcontext_transfer_t jump_fcontext(fcontext_t const to, void * vp); 34 | 35 | /** 36 | * Make a new context 37 | * @param sp Pointer to allocated stack memory 38 | * @param size Stack memory size 39 | * @param corofn Callback function for context (coroutine) 40 | */ 41 | fcontext_t make_fcontext(void * sp, size_t size, pfn_fcontext corofn); 42 | 43 | fcontext_transfer_t ontop_fcontext(fcontext_t const to, void * vp, fcontext_transfer_t(*fn)(fcontext_transfer_t)); 44 | 45 | fcontext_stack_t create_fcontext_stack(size_t size); 46 | void destroy_fcontext_stack(fcontext_stack_t* s); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif -------------------------------------------------------------------------------- /source/stack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "fcontext.h" 6 | 7 | // Detect posix 8 | #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) 9 | /* UNIX-style OS. ------------------------------------------- */ 10 | # include 11 | # define _HAVE_POSIX 1 12 | #endif 13 | 14 | #ifdef _WIN32 15 | # define WIN32_LEAN_AND_LEAN 16 | # include 17 | /* x86_64 18 | * test x86_64 before i386 because icc might 19 | * define __i686__ for x86_64 too */ 20 | #if defined(__x86_64__) || defined(__x86_64) \ 21 | || defined(__amd64__) || defined(__amd64) \ 22 | || defined(_M_X64) || defined(_M_AMD64) 23 | /* Windows seams not to provide a constant or function 24 | * telling the minimal stacksize */ 25 | # define MINSIGSTKSZ 8192 26 | #else 27 | # define MINSIGSTKSZ 4096 28 | #endif 29 | 30 | static size_t getPageSize() 31 | { 32 | SYSTEM_INFO si; 33 | GetSystemInfo(&si); 34 | return (size_t)si.dwPageSize; 35 | } 36 | 37 | static size_t getMinSize() 38 | { 39 | return MINSIGSTKSZ; 40 | } 41 | 42 | static size_t getMaxSize() 43 | { 44 | return 1 * 1024 * 1024 * 1024; /* 1GB */ 45 | } 46 | 47 | static size_t getDefaultSize() 48 | { 49 | return 131072; // 128kb 50 | } 51 | 52 | #elif defined(_HAVE_POSIX) 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | 60 | #if !defined (SIGSTKSZ) 61 | # define SIGSTKSZ 131072 // 128kb recommended 62 | # define UDEF_SIGSTKSZ 63 | #endif 64 | 65 | #if !defined (MINSIGSTKSZ) 66 | # define MINSIGSTKSZ 32768 // 32kb minimum 67 | # define UDEF_MINSIGSTKSZ 68 | #endif 69 | 70 | static size_t getPageSize() 71 | { 72 | /* conform to POSIX.1-2001 */ 73 | return (size_t)sysconf(_SC_PAGESIZE); 74 | } 75 | 76 | static size_t getMinSize() 77 | { 78 | return MINSIGSTKSZ; 79 | } 80 | 81 | static size_t getMaxSize() 82 | { 83 | struct rlimit limit; 84 | getrlimit(RLIMIT_STACK, &limit); 85 | 86 | return (size_t)limit.rlim_max; 87 | } 88 | 89 | static size_t getDefaultSize() 90 | { 91 | return SIGSTKSZ; 92 | } 93 | #endif 94 | 95 | /* Stack allocation and protection*/ 96 | fcontext_stack_t create_fcontext_stack(size_t size) 97 | { 98 | size_t pages; 99 | size_t size_; 100 | void* vp; 101 | fcontext_stack_t s; 102 | s.sptr = NULL; 103 | s.ssize = 0; 104 | 105 | /* fix size */ 106 | if (size == 0) 107 | size = getDefaultSize(); 108 | size_t minsz = getMinSize(); 109 | size_t maxsz = getMaxSize(); 110 | if (size < minsz) 111 | size = minsz; 112 | if (size > maxsz) 113 | size = maxsz; 114 | 115 | pages = (size_t)floorf((float)size/(float)getPageSize()); 116 | assert(pages >= 2); /* at least two pages must fit into stack (one page is guard-page) */ 117 | 118 | size_ = pages * getPageSize(); 119 | assert(size_ != 0 && size != 0); 120 | assert(size_ <= size); 121 | 122 | #ifdef _WIN32 123 | vp = VirtualAlloc(0, size_, MEM_COMMIT, PAGE_READWRITE); 124 | if (!vp) 125 | return s; 126 | 127 | DWORD old_options; 128 | VirtualProtect(vp, getPageSize(), PAGE_READWRITE | PAGE_GUARD, &old_options); 129 | #elif defined(_HAVE_POSIX) 130 | # if defined(MAP_ANON) 131 | vp = mmap(0, size_, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); 132 | # else 133 | vp = mmap(0, size_, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 134 | # endif 135 | if (vp == MAP_FAILED) 136 | return s; 137 | mprotect(vp, getPageSize(), PROT_NONE); 138 | #else 139 | vp = malloc(size_); 140 | if (!vp) 141 | return s; 142 | #endif 143 | 144 | s.sptr = (char*)vp + size_; 145 | s.ssize = size_; 146 | return s; 147 | } 148 | 149 | void destroy_fcontext_stack(fcontext_stack_t* s) 150 | { 151 | void* vp; 152 | 153 | assert(s->ssize >= getMinSize()); 154 | assert(s->ssize <= getMaxSize()); 155 | 156 | vp = (char*)s->sptr - s->ssize; 157 | 158 | #ifdef _WIN32 159 | VirtualFree(vp, 0, MEM_RELEASE); 160 | #elif defined(_HAVE_POSIX) 161 | munmap(vp, s->ssize); 162 | #else 163 | free(vp); 164 | #endif 165 | 166 | memset(s, 0x00, sizeof(fcontext_stack_t)); 167 | } 168 | 169 | #ifdef UDEF_SIGSTKSZ 170 | # undef SIGSTKSZ 171 | #endif 172 | 173 | #ifdef UDEF_MINSIGSTKSZ 174 | # undef MINSIGSTKSZ 175 | #endif 176 | -------------------------------------------------------------------------------- /test/test_fcontext.c: -------------------------------------------------------------------------------- 1 | #ifdef _WIN32 2 | # define WIN32_LEAN_AND_MEAN 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | fcontext_t ctx; 12 | fcontext_t ctx2; 13 | 14 | static inline void fsleep(uint32_t _ms) 15 | { 16 | #ifdef _WIN32 17 | Sleep(_ms); 18 | #else 19 | struct timespec req = { (time_t)_ms / 1000, (long)((_ms % 1000) * 1000000) }; 20 | struct timespec rem = { 0, 0 }; 21 | nanosleep(&req, &rem); 22 | #endif 23 | } 24 | 25 | static void doo(fcontext_transfer_t t) 26 | { 27 | puts("DOO"); 28 | fsleep(1000); 29 | jump_fcontext(t.ctx, NULL); 30 | } 31 | 32 | static void foo(fcontext_transfer_t t) 33 | { 34 | puts("FOO"); 35 | fsleep(1000); 36 | jump_fcontext(ctx2, NULL); 37 | puts("FOO 2"); 38 | fsleep(1000); 39 | jump_fcontext(t.ctx, NULL); 40 | } 41 | 42 | int main() 43 | { 44 | fcontext_stack_t s = create_fcontext_stack(16 * 1024); 45 | fcontext_stack_t s2 = create_fcontext_stack(0); 46 | 47 | ctx = make_fcontext(s.sptr, s.ssize, foo); 48 | ctx2 = make_fcontext(s2.sptr, s2.ssize, doo); 49 | 50 | jump_fcontext(ctx, NULL); 51 | puts("END"); 52 | 53 | destroy_fcontext_stack(&s); 54 | destroy_fcontext_stack(&s2); 55 | return 0; 56 | } --------------------------------------------------------------------------------