From f9ab5d2c612c1818125ba928520407bd6c7d9516 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Mon, 30 Dec 2013 11:53:12 -0600 Subject: [PATCH] Add -fvisibility options to significantly reduce binary sizes. Switch to boost::context for all platforms, almost. Please try your platform by commenting out fcontext.s in common/CMakeLists.txt. --- CMakeLists.txt | 26 +- CMakeModules/PerformFeatureChecks.cmake | 61 +-- CMakeModules/download_boost.cmake | 46 +- common/CMakeLists.txt | 31 +- demos/CMakeLists.txt | 13 +- patches/boost_mingw.patch | 594 ++++++++++++++++++++++++ 6 files changed, 697 insertions(+), 74 deletions(-) create mode 100644 patches/boost_mingw.patch diff --git a/CMakeLists.txt b/CMakeLists.txt index cb7fc24c38..7d200af8f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,6 +114,14 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) set( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG" ) set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG" ) + if( GXX_HAS_VISIBILITY_FLAG ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden" ) + endif() + + if( GXX_HAS_VISIBILITY_INLINES_FLAG ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden" ) + endif() + if( MINGW ) set( CMAKE_EXE_LINKER_FLAGS_RELEASE "-s" ) @@ -132,8 +140,8 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) # Disable this response file for includes ( See Windows-GNU.cmake module ) if( WIN32 AND MSYS AND NOT CMAKE_CROSSCOMPILING ) # fixme: it is needed only with MSYS+MINGW32? or always under MINGW - if (${CMAKE_SIZEOF_VOID_P} MATCHES 4) - set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 0) + if( ${CMAKE_SIZEOF_VOID_P} MATCHES 4 ) + set( CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 0 ) endif() endif() @@ -160,13 +168,13 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) if( GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8 ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs" ) endif() - - if( APPLE ) + + if( APPLE ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__ASSERTMACROS__" ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__ASSERTMACROS__" ) endif() - -endif( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + +endif( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) if( KICAD_KEEPCASE ) add_definitions( -DKICAD_KEEPCASE ) @@ -251,7 +259,7 @@ include( Functions ) include( ExternalProject ) -if ( APPLE ) +if ( APPLE ) set( KICAD_BUILD_STATIC ON) if( NOT CMAKE_CXX_COMPILER ) @@ -286,13 +294,13 @@ if ( KICAD_BUILD_STATIC ) set( PKG_CONFIG_EXECUTABLE "${PKGCONFIG_ROOT}/bin/pkg-config") include( download_glew ) set( GLEW_GLEW_LIBRARY "${GLEW_ROOT}/lib/libGLEW.a") - set( GLEW_INCLUDE_DIR "${GLEW_ROOT}/include") + set( GLEW_INCLUDE_DIR "${GLEW_ROOT}/include") include( download_pixman ) set( PIXMAN_LIBRARY "${PIXMAN_ROOT}/lib/libpixman-1.a") include( download_libpng ) include( download_cairo ) set( CAIRO_INCLUDE_DIR "${CAIRO_ROOT}/include/cairo") - set( CAIRO_LIBRARY "${CAIRO_ROOT}/lib/libcairo.a") + set( CAIRO_LIBRARY "${CAIRO_ROOT}/lib/libcairo.a") endif( KICAD_BUILD_STATIC ) ##################### diff --git a/CMakeModules/PerformFeatureChecks.cmake b/CMakeModules/PerformFeatureChecks.cmake index 6f8bc8586b..5c9d092957 100644 --- a/CMakeModules/PerformFeatureChecks.cmake +++ b/CMakeModules/PerformFeatureChecks.cmake @@ -36,17 +36,21 @@ # Consider it a benchmark when writing your own feature tests. # -macro(perform_feature_checks) +macro( perform_feature_checks ) - include(CheckIncludeFile) - #include(CheckFunctionExists) - include(CheckLibraryExists) - include(CheckSymbolExists) - include(CheckIncludeFileCXX) - include(CheckCXXSymbolExists) - include(CheckCXXSourceCompiles) + include( CheckIncludeFile ) + #include( CheckFunctionExists ) + include( CheckLibraryExists ) + include( CheckSymbolExists ) + include( CheckIncludeFileCXX ) + include( CheckCXXSymbolExists ) + include( CheckCXXSourceCompiles ) + include( CheckCXXCompilerFlag ) - check_include_file("malloc.h" HAVE_MALLOC_H) + check_cxx_compiler_flag( -fvisibility=hidden GXX_HAS_VISIBILITY_FLAG ) + check_cxx_compiler_flag( -fvisibility-inlines-hidden GXX_HAS_VISIBILITY_INLINES_FLAG ) + + check_include_file( "malloc.h" HAVE_MALLOC_H ) # FIXME: Visual C++ does not support the "not" keyword natively. It is # defined as a macro in . There should be a cmake macro @@ -54,7 +58,7 @@ macro(perform_feature_checks) # then check for and include it. Although it doesn't # appear to cause any problems with other compilers, that doesn't # mean won't fail somewhere down the line. - check_include_file("iso646.h" HAVE_ISO646_H) + check_include_file( "iso646.h" HAVE_ISO646_H ) # The STDINT header file test is required because MinGW under Windows # doesn't define HAVE_STDINT_H even though it does have it. @@ -62,7 +66,7 @@ macro(perform_feature_checks) # We need to add it to the global compiler definitions as config.h is not # included in pyport.h which is where the problem ocurrs without this # fix. - check_include_file("stdint.h" HAVE_STDINT_H) + check_include_file( "stdint.h" HAVE_STDINT_H ) if( HAVE_STDINT_H ) add_definitions( -DHAVE_STDINT_H ) @@ -73,40 +77,41 @@ macro(perform_feature_checks) # re-introduce this. # check_include_file("strings.h" HAVE_STRINGS_H) - check_symbol_exists(strcasecmp "string.h" HAVE_STRCASECMP) - check_symbol_exists(strcasecmp "strings.h" HAVE_STRCASECMP) - check_symbol_exists(strncasecmp "string.h" HAVE_STRNCASECMP) - check_symbol_exists(strncasecmp "strings.h" HAVE_STRNCASECMP) + check_symbol_exists( strcasecmp "string.h" HAVE_STRCASECMP ) + check_symbol_exists( strcasecmp "strings.h" HAVE_STRCASECMP ) + check_symbol_exists( strncasecmp "string.h" HAVE_STRNCASECMP ) + check_symbol_exists( strncasecmp "strings.h" HAVE_STRNCASECMP ) check_symbol_exists( strtok_r "string.h" HAVE_STRTOKR ) # Some platforms define malloc and free in malloc.h instead of stdlib.h. - check_symbol_exists(malloc "stdlib.h" MALLOC_IN_STDLIB_H) + check_symbol_exists( malloc "stdlib.h" MALLOC_IN_STDLIB_H ) # Check for functions in math.h. - check_include_file("math.h" HAVE_MATH_H) + check_include_file( "math.h" HAVE_MATH_H ) # Check for functions in C++ cmath. - check_include_file_cxx(cmath HAVE_CXX_CMATH) - check_cxx_symbol_exists(asinh cmath HAVE_CMATH_ASINH ) - check_cxx_symbol_exists(acosh cmath HAVE_CMATH_ACOSH ) - check_cxx_symbol_exists(atanh cmath HAVE_CMATH_ATANH ) + check_include_file_cxx( cmath HAVE_CXX_CMATH ) + check_cxx_symbol_exists( asinh cmath HAVE_CMATH_ASINH ) + check_cxx_symbol_exists( acosh cmath HAVE_CMATH_ACOSH ) + check_cxx_symbol_exists( atanh cmath HAVE_CMATH_ATANH ) # CMakes check_cxx_symbol_exists() doesn't work for templates so we must create a # small program to verify isinf() exists in cmath. check_cxx_source_compiles( "#include \nint main(int argc, char** argv)\n{\n (void)argv;\n std::isinf(1.0); (void)argc;\n return 0;\n}\n" HAVE_CMATH_ISINF ) - #check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME) non-standard library, does not work - check_library_exists(rt clock_gettime "" HAVE_CLOCK_GETTIME) + #check_symbol_exists( clock_gettime "time.h" HAVE_CLOCK_GETTIME ) non-standard library, does not work + check_library_exists( rt clock_gettime "" HAVE_CLOCK_GETTIME ) # HAVE_GETTIMEOFDAY is already in use within 2.9 wxWidgets, so use HAVE_GETTIMEOFDAY_FUNC - check_symbol_exists(gettimeofday "sys/time.h" HAVE_GETTIMEOFDAY_FUNC) + check_symbol_exists( gettimeofday "sys/time.h" HAVE_GETTIMEOFDAY_FUNC ) # Check for Posix getc_unlocked() for improved performance over getc(). Fall back to # getc() on platforms where getc_unlocked() doesn't exist. - check_symbol_exists(getc_unlocked "stdio.h" HAVE_FGETC_NOLOCK) + check_symbol_exists( getc_unlocked "stdio.h" HAVE_FGETC_NOLOCK ) # Generate config.h. - configure_file(${PROJECT_SOURCE_DIR}/CMakeModules/config.h.cmake - ${CMAKE_BINARY_DIR}/config.h) + configure_file( ${PROJECT_SOURCE_DIR}/CMakeModules/config.h.cmake + ${CMAKE_BINARY_DIR}/config.h + ) -endmacro(perform_feature_checks) +endmacro( perform_feature_checks ) diff --git a/CMakeModules/download_boost.cmake b/CMakeModules/download_boost.cmake index 9c6041ecef..9ab0c571d3 100644 --- a/CMakeModules/download_boost.cmake +++ b/CMakeModules/download_boost.cmake @@ -41,14 +41,9 @@ set( BOOST_ROOT "${PROJECT_SOURCE_DIR}/boost_root" ) # Chosen libraries are based on AVHTTP requirements, and possibly # unit_test_framework for its own worth. # tool_manager.cpp -> coroutine -> context (_jump_fcontext) (on OSX) -if( APPLE ) - set( BOOST_EXTRA_LIBS "context" ) -else() - set( BOOST_EXTRA_LIBS "" ) -endif() set( BOOST_LIBS_BUILT - ${BOOST_EXTRA_LIBS} + context #coroutine date_time #exception @@ -98,9 +93,9 @@ string( REPLACE "unit_test_framework" "test" boost_libs_list "${BOOST_LIBS_BUILT set( BOOST_TOOLSET "toolset=gcc" ) if( KICAD_BUILD_STATIC ) - set(BOOST_LINKTYPE "link=static") + set( BOOST_LINKTYPE "link=static" ) else() - set( BOOST_LINKTYPE "#link=static") + unset( BOOST_LINKTYPE ) endif() @@ -129,14 +124,15 @@ else() unset( b2_libs ) endif() + if( APPLE ) # I set this to being compatible with wxWidgets # wxWidgets still using libstdc++ (gcc), meanwhile OSX # has switched to libc++ (llvm) by default - set(BOOST_CXXFLAGS "cxxflags=-mmacosx-version-min=10.5 -fno-common" ) - set(BOOST_LINKFLAGS "linkflags=-mmacosx-version-min=10.5 -fno-common" ) - set(BOOST_TOOLSET "toolset=darwin" ) - + set( BOOST_CXXFLAGS "cxxflags=-mmacosx-version-min=10.5 -fno-common" ) + set( BOOST_LINKFLAGS "linkflags=-mmacosx-version-min=10.5 -fno-common" ) + set( BOOST_TOOLSET "toolset=darwin" ) + if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) set(BOOST_CXXFLAGS "${BOOST_CXXFLAGS} -fno-lto" ) set(BOOST_LINKFLAGS "${BOOST_LINKFLAGS} -fno-lto" ) @@ -146,9 +142,9 @@ if( APPLE ) if( (CMAKE_OSX_ARCHITECTURES MATCHES "386" OR CMAKE_OSX_ARCHITECTURES MATCHES "ppc ") AND (CMAKE_OSX_ARCHITECTURES MATCHES "64")) - message("-- BOOST found 32/64 Address Model") + message( "-- BOOST found 32/64 Address Model" ) - set(BOOST_ADDRESSMODEL "address-model=32_64") + set( BOOST_ADDRESSMODEL "address-model=32_64" ) endif() if( (CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" OR CMAKE_OSX_ARCHITECTURES MATCHES "386") AND @@ -166,9 +162,9 @@ if( APPLE ) set(BOOST_ARCHITECTURE "architecture=ppc") endif() - set(BOOST_CFLAGS "${BOOST_CFLAGS} -arch ${CMAKE_OSX_ARCHITECTURES}" ) - set(BOOST_CXXFLAGS "${BOOST_CXXFLAGS} -arch ${CMAKE_OSX_ARCHITECTURES}" ) - set(BOOST_LINKFLAGS "${BOOST_LINKFLAGS} -arch ${CMAKE_OSX_ARCHITECTURES}" ) + set( BOOST_CFLAGS "${BOOST_CFLAGS} -arch ${CMAKE_OSX_ARCHITECTURES}" ) + set( BOOST_CXXFLAGS "${BOOST_CXXFLAGS} -arch ${CMAKE_OSX_ARCHITECTURES}" ) + set( BOOST_LINKFLAGS "${BOOST_LINKFLAGS} -arch ${CMAKE_OSX_ARCHITECTURES}" ) endif() endif() @@ -187,9 +183,21 @@ ExternalProject_Add( boost # PATCH_COMMAND continuation (any *_COMMAND here can be continued with COMMAND): COMMAND bzr patch -p0 "${PROJECT_SOURCE_DIR}/patches/boost_minkowski.patch" COMMAND bzr patch -p0 "${PROJECT_SOURCE_DIR}/patches/boost_cstdint.patch" + COMMAND bzr patch -p0 "${PROJECT_SOURCE_DIR}/patches/boost_macosx_x86.patch" #https://svn.boost.org/trac/boost/ticket/8266 + # tell bzr about new files added by last patch so above "bzr revert" works: + COMMAND bzr add libs/context/src/asm/jump_i386_x86_64_sysv_macho_gas.S + COMMAND bzr add libs/context/src/asm/make_i386_x86_64_sysv_macho_gas.S + COMMAND bzr patch -p0 "${PROJECT_SOURCE_DIR}/patches/boost_macosx_x86_build.patch" #https://svn.boost.org/trac/boost/ticket/8266 + COMMAND bzr patch -p0 "${PROJECT_SOURCE_DIR}/patches/boost_mingw.patch" #https://svn.boost.org/trac/boost/ticket/7262 + # tell bzr about new files added by last patch so above "bzr revert" works: + COMMAND bzr add libs/context/src/asm/make_i386_ms_pe_gas.S + COMMAND bzr add libs/context/src/asm/jump_i386_ms_pe_gas.S + COMMAND bzr add libs/context/src/asm/make_x86_64_ms_pe_gas.S + COMMAND bzr add libs/context/src/asm/jump_x86_64_ms_pe_gas.S + # [Mis-]use this step to erase all the boost headers and libraries before # replacing them below. UPDATE_COMMAND ${CMAKE_COMMAND} -E remove_directory "${BOOST_ROOT}" @@ -240,8 +248,8 @@ endif() set( boost_libs "" ) set_boost_lib_names( "${BOOST_LIBS_BUILT}" boost_libs ) -set( Boost_LIBRARIES ${boost_libs} CACHE FILEPATH "Boost libraries directory" ) -set( Boost_INCLUDE_DIR "${BOOST_INCLUDE}" CACHE FILEPATH "Boost include directory" ) +set( Boost_LIBRARIES ${boost_libs} ) +set( Boost_INCLUDE_DIR "${BOOST_INCLUDE}" ) mark_as_advanced( Boost_LIBRARIES Boost_INCLUDE_DIR ) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index dc0697f357..20101747ad 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,4 +1,4 @@ -include_directories(BEFORE ${INC_BEFORE}) +include_directories( BEFORE ${INC_BEFORE} ) include_directories( ./dialogs ./dialog_about @@ -62,7 +62,7 @@ if(WIN32 AND MSYS) add_definitions(-DGLEW_STATIC) endif(WIN32 AND MSYS) -set(COMMON_ABOUT_DLG_SRCS +set( COMMON_ABOUT_DLG_SRCS dialog_about/AboutDialog_main.cpp dialog_about/dialog_about.cpp dialog_about/dialog_about_base.cpp @@ -78,7 +78,7 @@ set(COMMON_ABOUT_DLG_SRCS dialogs/dialog_page_settings_base.cpp ) -set(COMMON_PAGE_LAYOUT_SRCS +set( COMMON_PAGE_LAYOUT_SRCS page_layout/title_block_shapes.cpp page_layout/class_worksheet_dataitem.cpp page_layout/class_worksheet_layout.cpp @@ -88,7 +88,7 @@ set(COMMON_PAGE_LAYOUT_SRCS page_layout/page_layout_reader.cpp ) -set(COMMON_SRCS +set( COMMON_SRCS ${COMMON_ABOUT_DLG_SRCS} ${COMMON_PAGE_LAYOUT_SRCS} base_struct.cpp @@ -153,17 +153,14 @@ if( NOT HAVE_STRTOKR ) set( COMMON_SRCS ${COMMON_SRCS} strtok_r.c ) endif() -enable_language(C CXX ASM) -set_source_files_properties(system/fcontext.s PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp") -set(COMMON_SRCS +set( COMMON_SRCS ${COMMON_SRCS} view/view.cpp view/view_item.cpp view/view_group.cpp math/math_util.cpp - system/fcontext.s tool/tool_base.cpp tool/tool_manager.cpp @@ -179,9 +176,19 @@ set(COMMON_SRCS geometry/shape_index.cpp ) -add_library(common STATIC ${COMMON_SRCS}) +# TODO: remove this whole if test and remove the sytem/*.s sources once every platform is tested with +# boost::context library +if( UNIX AND NOT APPLE ) +else() + enable_language( C CXX ASM ) + set_source_files_properties( system/fcontext.s PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp" ) + list( APPEND COMMON_SRCS system/fcontext.s ) +endif() -set(PCB_COMMON_SRCS + +add_library( common STATIC ${COMMON_SRCS} ) + +set( PCB_COMMON_SRCS base_screen.cpp eda_text.cpp class_page_info.cpp @@ -235,7 +242,7 @@ set(PCB_COMMON_SRCS fp_lib_table.cpp ) -set(PCB_COMMON_SRCS +set( PCB_COMMON_SRCS ${PCB_COMMON_SRCS} ../pcbnew/pcb_painter.cpp ) @@ -245,7 +252,7 @@ set_source_files_properties( ${PCB_COMMON_SRCS} PROPERTIES COMPILE_DEFINITIONS "PCBNEW" ) -add_library(pcbcommon STATIC ${PCB_COMMON_SRCS}) +add_library( pcbcommon STATIC ${PCB_COMMON_SRCS} ) # auto-generate specctra_lexer.h and specctra_keywords.cpp make_lexer( diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt index aec5809bf7..5e25018f91 100644 --- a/demos/CMakeLists.txt +++ b/demos/CMakeLists.txt @@ -1,6 +1,7 @@ -install(DIRECTORY complex_hierarchy ecc83 electric flat_hierarchy - kit-dev-coldfire-xilinx_5213 interf_u microwave - pic_programmer pspice "sonde xilinx" test_xil_95108 video - DESTINATION ${KICAD_DEMOS} - COMPONENT resources - PATTERN ".svn" EXCLUDE) +install( DIRECTORY complex_hierarchy + ecc83 electric flat_hierarchy + kit-dev-coldfire-xilinx_5213 interf_u microwave + pic_programmer pspice "sonde xilinx" test_xil_95108 video + DESTINATION ${KICAD_DEMOS} + COMPONENT resources + ) diff --git a/patches/boost_mingw.patch b/patches/boost_mingw.patch new file mode 100644 index 0000000000..8d9dfa6fe4 --- /dev/null +++ b/patches/boost_mingw.patch @@ -0,0 +1,594 @@ +--- libs/context/build/Jamfile.v2.orig 2013-03-03 13:39:59.684868916 +0100 ++++ libs/context/build/Jamfile.v2 2013-03-03 15:09:09.893232829 +0100 +@@ -282,6 +284,17 @@ + ; + + alias asm_context_sources ++ : asm/make_i386_ms_pe_gas.S ++ asm/jump_i386_ms_pe_gas.S ++ dummy.cpp ++ : 32 ++ x86 ++ pe ++ windows ++ gcc ++ ; ++ ++alias asm_context_sources + : asm/make_i386_ms_pe_masm.asm + asm/jump_i386_ms_pe_masm.asm + dummy.cpp +@@ -379,6 +392,17 @@ + ; + + alias asm_context_sources ++ : asm/make_x86_64_ms_pe_gas.S ++ asm/jump_x86_64_ms_pe_gas.S ++ dummy.cpp ++ : 64 ++ x86 ++ pe ++ windows ++ gcc ++ ; ++ ++alias asm_context_sources + : asm/make_x86_64_ms_pe_masm.asm + asm/jump_x86_64_ms_pe_masm.asm + dummy.cpp +--- libs/context/src/asm/make_i386_ms_pe_gas.S.orig 2013-03-03 13:41:28.645502113 +0100 ++++ libs/context/src/asm/make_i386_ms_pe_gas.S 2013-03-03 14:39:27.590477410 +0100 +@@ -0,0 +1,115 @@ ++/* ++ Copyright Oliver Kowalke 2009. ++ Copyright Thomas Sailer 2013. ++ Distributed under the Boost Software License, Version 1.0. ++ (See accompanying file LICENSE_1_0.txt or copy at ++ http://www.boost.org/LICENSE_1_0.txt) ++*/ ++ ++/******************************************************************** ++ * * ++ * -------------------------------------------------------------- * ++ * | 0 | 1 | 2 | 3 | 4 | 5 | * ++ * -------------------------------------------------------------- * ++ * | 0h | 04h | 08h | 0ch | 010h | 014h | * ++ * -------------------------------------------------------------- * ++ * | EDI | ESI | EBX | EBP | ESP | EIP | * ++ * -------------------------------------------------------------- * ++ * -------------------------------------------------------------- * ++ * | 6 | 7 | 8 | | * ++ * -------------------------------------------------------------- * ++ * | 018h | 01ch | 020h | | * ++ * -------------------------------------------------------------- * ++ * | sp | size | limit | | * ++ * -------------------------------------------------------------- * ++ * -------------------------------------------------------------- * ++ * | 9 | | * ++ * -------------------------------------------------------------- * ++ * | 024h | | * ++ * -------------------------------------------------------------- * ++ * |fc_execpt| | * ++ * -------------------------------------------------------------- * ++ * -------------------------------------------------------------- * ++ * | 10 | | * ++ * -------------------------------------------------------------- * ++ * | 028h | | * ++ * -------------------------------------------------------------- * ++ * |fc_strage| | * ++ * -------------------------------------------------------------- * ++ * -------------------------------------------------------------- * ++ * | 11 | 12 | | * ++ * -------------------------------------------------------------- * ++ * | 02ch | 030h | | * ++ * -------------------------------------------------------------- * ++ * | fc_mxcsr|fc_x87_cw| | * ++ * -------------------------------------------------------------- * ++ * * ++ * *****************************************************************/ ++ ++.file "make_i386_ms_pe_gas.S" ++.text ++.p2align 4,,15 ++.globl _make_fcontext ++.def _make_fcontext; .scl 2; .type 32; .endef ++_make_fcontext: ++ movl 0x04(%esp), %eax /* load 1. arg of make_fcontext, pointer to context stack (base) */ ++ leal -0x34(%eax),%eax /* reserve space for fcontext_t at top of context stack */ ++ ++ /* shift address in EAX to lower 16 byte boundary */ ++ /* == pointer to fcontext_t and address of context stack */ ++ andl $-16, %eax ++ ++ movl 0x04(%esp), %ecx /* load 1. arg of make_fcontext, pointer to context stack (base) */ ++ movl %ecx, 0x18(%eax) /* save address of context stack (base) in fcontext_t */ ++ movl 0x08(%esp), %edx /* load 2. arg of make_fcontext, context stack size */ ++ movl %edx, 0x1c(%eax) /* save context stack size in fcontext_t */ ++ negl %edx /* negate stack size for LEA instruction (== substraction) */ ++ leal (%ecx,%edx),%ecx /* compute bottom address of context stack (limit) */ ++ movl %ecx, 0x20(%eax) /* save address of context stack (limit) in fcontext_t */ ++ movl 0x0c(%esp), %ecx /* load 3. arg of make_fcontext, pointer to context function */ ++ movl %ecx, 0x14(%eax) /* save address of context function in fcontext_t */ ++ ++ stmxcsr 0x02c(%eax) /* save MMX control word */ ++ fnstcw 0x030(%eax) /* save x87 control word */ ++ ++ leal -0x1c(%eax),%edx /* reserve space for last frame and seh on context stack, (ESP - 0x4) % 16 == 0 */ ++ movl %edx, 0x10(%eax) /* save address in EDX as stack pointer for context function */ ++ ++ movl $finish, %ecx /* abs address of finish */ ++ movl %ecx, (%edx) /* save address of finish as return address for context function */ ++ /* entered after context function returns */ ++ ++ /* traverse current seh chain to get the last exception handler installed by Windows */ ++ /* note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default */ ++ /* the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler */ ++ /* at its end by RaiseException all seh andlers are disregarded if not present and the */ ++ /* program is aborted */ ++ movl %fs:(0x18), %ecx /* load NT_TIB into ECX */ ++ ++walk: ++ movl (%ecx), %edx /* load 'next' member of current SEH into EDX */ ++ incl %edx /* test if 'next' of current SEH is last (== 0xffffffff) */ ++ jz found ++ decl %edx ++ xchgl %ecx, %edx /* exchange content; ECX contains address of next SEH */ ++ jmp walk /* inspect next SEH */ ++ ++found: ++ movl 0x04(%ecx), %ecx /* load 'handler' member of SEH == address of last SEH handler installed by Windows */ ++ movl 0x10(%eax), %edx /* load address of stack pointer for context function */ ++ movl %ecx, 0x18(%edx) /* save address in ECX as SEH handler for context */ ++ movl $0xffffffff,%ecx /* set ECX to -1 */ ++ movl %ecx, 0x14(%edx) /* save ECX as next SEH item */ ++ leal 0x14(%edx), %ecx /* load address of next SEH item */ ++ movl %ecx, 0x24(%eax) /* save next SEH */ ++ ++ ret ++ ++finish: ++ /* ESP points to same address as ESP on entry of context function + 0x4 */ ++ xorl %eax, %eax ++ movl %eax, (%esp) /* exit code is zero */ ++ call __exit /* exit application */ ++ hlt ++ ++.def __exit; .scl 2; .type 32; .endef /* standard C library function */ +--- libs/context/src/asm/jump_i386_ms_pe_gas.S.orig 2013-03-03 13:41:34.332670479 +0100 ++++ libs/context/src/asm/jump_i386_ms_pe_gas.S 2013-03-03 14:35:35.634611625 +0100 +@@ -0,0 +1,108 @@ ++/* ++ Copyright Oliver Kowalke 2009. ++ Copyright Thomas Sailer 2013. ++ Distributed under the Boost Software License, Version 1.0. ++ (See accompanying file LICENSE_1_0.txt or copy at ++ http://www.boost.org/LICENSE_1_0.txt) ++*/ ++ ++/******************************************************************** ++ * * ++ * -------------------------------------------------------------- * ++ * | 0 | 1 | 2 | 3 | 4 | 5 | * ++ * -------------------------------------------------------------- * ++ * | 0h | 04h | 08h | 0ch | 010h | 014h | * ++ * -------------------------------------------------------------- * ++ * | EDI | ESI | EBX | EBP | ESP | EIP | * ++ * -------------------------------------------------------------- * ++ * -------------------------------------------------------------- * ++ * | 6 | 7 | 8 | | * ++ * -------------------------------------------------------------- * ++ * | 018h | 01ch | 020h | | * ++ * -------------------------------------------------------------- * ++ * | sp | size | limit | | * ++ * -------------------------------------------------------------- * ++ * -------------------------------------------------------------- * ++ * | 9 | | * ++ * -------------------------------------------------------------- * ++ * | 024h | | * ++ * -------------------------------------------------------------- * ++ * |fc_execpt| | * ++ * -------------------------------------------------------------- * ++ * -------------------------------------------------------------- * ++ * | 10 | | * ++ * -------------------------------------------------------------- * ++ * | 028h | | * ++ * -------------------------------------------------------------- * ++ * |fc_strage| | * ++ * -------------------------------------------------------------- * ++ * -------------------------------------------------------------- * ++ * | 11 | 12 | | * ++ * -------------------------------------------------------------- * ++ * | 02ch | 030h | | * ++ * -------------------------------------------------------------- * ++ * | fc_mxcsr|fc_x87_cw| | * ++ * -------------------------------------------------------------- * ++ * * ++ * *****************************************************************/ ++ ++.file "jump_i386_ms_pe_gas.S" ++.text ++.p2align 4,,15 ++.globl _jump_fcontext ++.def _jump_fcontext; .scl 2; .type 32; .endef ++_jump_fcontext: ++ movl 0x04(%esp), %ecx /* load address of the first fcontext_t arg */ ++ movl %edi, (%ecx) /* save EDI */ ++ movl %esi, 0x04(%ecx) /* save ESI */ ++ movl %ebx, 0x08(%ecx) /* save EBX */ ++ movl %ebp, 0x0c(%ecx) /* save EBP */ ++ ++ movl %fs:(0x18), %edx /* load NT_TIB */ ++ movl (%edx), %eax /* load current SEH exception list */ ++ movl %eax, 0x24(%ecx) /* save current exception list */ ++ movl 0x04(%edx), %eax /* load current stack base */ ++ movl %eax, 0x18(%ecx) /* save current stack base */ ++ movl 0x08(%edx), %eax /* load current stack limit */ ++ movl %eax, 0x20(%ecx) /* save current stack limit */ ++ movl 0x10(%edx), %eax /* load fiber local storage */ ++ movl %eax, 0x28(%ecx) /* save fiber local storage */ ++ ++ leal 0x04(%esp), %eax /* exclude the return address */ ++ movl %eax, 0x10(%ecx) /* save as stack pointer */ ++ movl (%esp), %eax /* load return address */ ++ movl %eax, 0x14(%ecx) /* save return address */ ++ ++ movl 0x08(%esp), %edx /* load address of the second fcontext_t arg */ ++ movl (%edx), %edi /* restore EDI */ ++ movl 0x04(%edx), %esi /* restore ESI */ ++ movl 0x08(%edx), %ebx /* restore EBX */ ++ movl 0x0c(%edx), %ebp /* restore EBP */ ++ ++ movl 0x10(%esp), %eax /* check if fpu enve preserving was requested */ ++ testl %eax, %eax ++ je 1f ++ ++ stmxcsr 0x2c(%ecx) /* save MMX control word */ ++ fnstcw 0x30(%ecx) /* save x87 control word */ ++ ldmxcsr 0x2c(%edx) /* restore MMX control word */ ++ fldcw 0x30(%edx) /* restore x87 control word */ ++1: ++ movl %edx, %ecx ++ movl %fs:(0x18), %edx /* load NT_TIB */ ++ movl 0x24(%ecx), %eax /* load SEH exception list */ ++ movl %eax, (%edx) /* restore next SEH item */ ++ movl 0x18(%ecx), %eax /* load stack base */ ++ movl %eax, 0x04(%edx) /* restore stack base */ ++ movl 0x20(%ecx), %eax /* load stack limit */ ++ movl %eax, 0x08(%edx) /* restore stack limit */ ++ movl 0x28(%ecx), %eax /* load fiber local storage */ ++ movl %eax, 0x10(%edx) /* restore fiber local storage */ ++ ++ movl 0x0c(%esp), %eax /* use third arg as return value after jump */ ++ ++ movl 0x10(%ecx), %esp /* restore ESP */ ++ movl %eax, 0x04(%esp) /* use third arg as first arg in context function */ ++ movl 0x14(%ecx), %ecx /* fetch the address to return to */ ++ ++ jmp *%ecx /* indirect jump to context */ +--- libs/context/src/asm/make_x86_64_ms_pe_gas.S.orig 2013-03-03 13:43:03.137299031 +0100 ++++ libs/context/src/asm/make_x86_64_ms_pe_gas.S 2013-03-03 14:54:16.036775106 +0100 +@@ -0,0 +1,132 @@ ++/* ++ Copyright Oliver Kowalke 2009. ++ Copyright Thomas Sailer 2013. ++ Distributed under the Boost Software License, Version 1.0. ++ (See accompanying file LICENSE_1_0.txt or copy at ++ http://www.boost.org/LICENSE_1_0.txt) ++*/ ++ ++/**************************************************************************************** ++ * * ++ * ---------------------------------------------------------------------------------- * ++ * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * ++ * ---------------------------------------------------------------------------------- * ++ * | R12 | R13 | R14 | R15 | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * ++ * ---------------------------------------------------------------------------------- * ++ * | RDI | RSI | RBX | RBP | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 16 | 17 | 18 | 19 | | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0x40 | 0x44 | 0x48 | 0x4c | | * ++ * ---------------------------------------------------------------------------------- * ++ * | RSP | RIP | | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 20 | 21 | 22 | 23 | 24 | 25 | | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0x50 | 0x54 | 0x58 | 0x5c | 0x60 | 0x64 | | * ++ * ---------------------------------------------------------------------------------- * ++ * | sp | size | limit | | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 26 | 27 | | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0x68 | 0x6c | | * ++ * ---------------------------------------------------------------------------------- * ++ * | fbr_strg | | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0x70 | 0x74 | 0x78 | 0x7c | 0x80 | 0x84 | 0x88 | 0x8c | * ++ * ---------------------------------------------------------------------------------- * ++ * | fc_mxcsr|fc_x87_cw| fc_xmm | SEE registers (XMM6-XMM15) | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0x90 | 0x94 | 0x98 | 0x9c | 0xa0 | 0xa4 | 0xa8 | 0xac | * ++ * ---------------------------------------------------------------------------------- * ++ * | SEE registers (XMM6-XMM15) | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0xb0 | 0xb4 | 0xb8 | 0xbc | 0xc0 | 0xc4 | 0xc8 | 0xcc | * ++ * ---------------------------------------------------------------------------------- * ++ * | SEE registers (XMM6-XMM15) | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0xd0 | 0xd4 | 0xd8 | 0xdc | 0xe0 | 0xe4 | 0xe8 | 0xec | * ++ * ---------------------------------------------------------------------------------- * ++ * | SEE registers (XMM6-XMM15) | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0xf0 | 0xf4 | 0xf8 | 0xfc | 0x100 | 0x104 | 0x108 | 0x10c | * ++ * ---------------------------------------------------------------------------------- * ++ * | SEE registers (XMM6-XMM15) | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0x110 | 0x114 | 0x118 | 0x11c | 0x120 | 0x124 | 0x128 | 0x12c | * ++ * ---------------------------------------------------------------------------------- * ++ * | SEE registers (XMM6-XMM15) | * ++ * ---------------------------------------------------------------------------------- * ++ * * ++ * *************************************************************************************/ ++ ++.file "make_x86_64_ms_pe_gas.S" ++.text ++.p2align 4,,15 ++.globl make_fcontext ++.def make_fcontext; .scl 2; .type 32; .endef ++.seh_proc make_fcontext ++make_fcontext: ++.seh_endprologue ++ leaq -0x130(%rcx),%rax /* reserve space for fcontext_t at top of context stack */ ++ ++ /* shift address in RAX to lower 16 byte boundary */ ++ /* == pointer to fcontext_t and address of context stack */ ++ andq $-16, %rax ++ ++ movq %r8, 0x48(%rax) /* save address of context function in fcontext_t */ ++ movq %rdx, 0x58(%rax) /* save context stack size in fcontext_t */ ++ movq %rcx, 0x50(%rax) /* save address of context stack pointer (base) in fcontext_t */ ++ ++ negq %rdx /* negate stack size for LEA instruction (== substraction) */ ++ leaq (%rcx,%rdx),%rcx /* compute bottom address of context stack (limit) */ ++ movq %rcx, 0x60(%rax) /* save bottom address of context stack (limit) in fcontext_t */ ++ ++ stmxcsr 0x70(%rax) /* save MMX control and status word */ ++ fnstcw 0x74(%rax) /* save x87 control word */ ++ ++ leaq -0x28(%rax),%rdx /* reserve 32byte shadow space + return address on stack, (RSP - 0x8) % 16 == 0 */ ++ movq %rdx, 0x40(%rax) /* save address in RDX as stack pointer for context function */ ++ ++ leaq finish(%rip),%rcx /* compute abs address of label finish */ ++ movq %rcx,(%rdx) /* save address of finish as return address for context function */ ++ /* entered after context function returns */ ++ ++ ret ++ ++finish: ++ /* RSP points to same address as RSP on entry of context function + 0x8 */ ++ xorq %rcx, %rcx /* exit code is zero */ ++ call _exit /* exit application */ ++ hlt ++.seh_endproc ++ ++.def _exit; .scl 2; .type 32; .endef /* standard C library function */ +--- libs/context/src/asm/jump_x86_64_ms_pe_gas.S.orig 2013-03-03 13:42:57.753139784 +0100 ++++ libs/context/src/asm/jump_x86_64_ms_pe_gas.S 2013-03-03 15:06:08.269856857 +0100 +@@ -0,0 +1,189 @@ ++/* ++ Copyright Oliver Kowalke 2009. ++ Copyright Thomas Sailer 2013. ++ Distributed under the Boost Software License, Version 1.0. ++ (See accompanying file LICENSE_1_0.txt or copy at ++ http://www.boost.org/LICENSE_1_0.txt) ++*/ ++ ++/**************************************************************************************** ++ * * ++ * ---------------------------------------------------------------------------------- * ++ * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * ++ * ---------------------------------------------------------------------------------- * ++ * | R12 | R13 | R14 | R15 | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * ++ * ---------------------------------------------------------------------------------- * ++ * | RDI | RSI | RBX | RBP | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 16 | 17 | 18 | 19 | | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0x40 | 0x44 | 0x48 | 0x4c | | * ++ * ---------------------------------------------------------------------------------- * ++ * | RSP | RIP | | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 20 | 21 | 22 | 23 | 24 | 25 | | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0x50 | 0x54 | 0x58 | 0x5c | 0x60 | 0x64 | | * ++ * ---------------------------------------------------------------------------------- * ++ * | sp | size | limit | | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 26 | 27 | | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0x68 | 0x6c | | * ++ * ---------------------------------------------------------------------------------- * ++ * | fbr_strg | | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0x70 | 0x74 | 0x78 | 0x7c | 0x80 | 0x84 | 0x88 | 0x8c | * ++ * ---------------------------------------------------------------------------------- * ++ * | fc_mxcsr|fc_x87_cw| fc_xmm | SEE registers (XMM6-XMM15) | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0x90 | 0x94 | 0x98 | 0x9c | 0xa0 | 0xa4 | 0xa8 | 0xac | * ++ * ---------------------------------------------------------------------------------- * ++ * | SEE registers (XMM6-XMM15) | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0xb0 | 0xb4 | 0xb8 | 0xbc | 0xc0 | 0xc4 | 0xc8 | 0xcc | * ++ * ---------------------------------------------------------------------------------- * ++ * | SEE registers (XMM6-XMM15) | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0xd0 | 0xd4 | 0xd8 | 0xdc | 0xe0 | 0xe4 | 0xe8 | 0xec | * ++ * ---------------------------------------------------------------------------------- * ++ * | SEE registers (XMM6-XMM15) | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0xf0 | 0xf4 | 0xf8 | 0xfc | 0x100 | 0x104 | 0x108 | 0x10c | * ++ * ---------------------------------------------------------------------------------- * ++ * | SEE registers (XMM6-XMM15) | * ++ * ---------------------------------------------------------------------------------- * ++ * ---------------------------------------------------------------------------------- * ++ * | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | * ++ * ---------------------------------------------------------------------------------- * ++ * | 0x110 | 0x114 | 0x118 | 0x11c | 0x120 | 0x124 | 0x128 | 0x12c | * ++ * ---------------------------------------------------------------------------------- * ++ * | SEE registers (XMM6-XMM15) | * ++ * ---------------------------------------------------------------------------------- * ++ * * ++ * *************************************************************************************/ ++ ++.file "jump_x86_64_ms_pe_gas.S" ++.text ++.p2align 4,,15 ++.globl jump_fcontext ++.def jump_fcontext; .scl 2; .type 32; .endef ++.seh_proc jump_fcontext ++jump_fcontext: ++.seh_endprologue ++ movq %r12, (%rcx) /* save R12 */ ++ movq %r13, 0x08(%rcx) /* save R13 */ ++ movq %r14, 0x10(%rcx) /* save R14 */ ++ movq %r15, 0x18(%rcx) /* save R15 */ ++ movq %rdi, 0x20(%rcx) /* save RDI */ ++ movq %rsi, 0x28(%rcx) /* save RSI */ ++ movq %rbx, 0x30(%rcx) /* save RBX */ ++ movq %rbp, 0x38(%rcx) /* save RBP */ ++ ++ movq %gs:(0x30), %r10 /* load NT_TIB */ ++ movq 0x08(%r10), %rax /* load current stack base */ ++ movq %rax, 0x50(%rcx) /* save current stack base */ ++ movq 0x10(%r10), %rax /* load current stack limit */ ++ movq %rax, 0x60(%rcx) /* save current stack limit */ ++ movq 0x18(%r10), %rax /* load fiber local storage */ ++ movq %rax, 0x68(%rcx) /* save fiber local storage */ ++ ++ testq %r9, %r9 ++ je 1f ++ ++ stmxcsr 0x70(%rcx) /* save MMX control and status word */ ++ fnstcw 0x74(%rcx) /* save x87 control word */ ++ /* save XMM storage */ ++ /* save start address of SSE register block in R10 */ ++ leaq 0x90(%rcx), %r10 ++ /* shift address in R10 to lower 16 byte boundary */ ++ /* == pointer to SEE register block */ ++ andq $-16, %r10 ++ ++ movaps %xmm6, (%r10) ++ movaps %xmm7, 0x10(%r10) ++ movaps %xmm8, 0x20(%r10) ++ movaps %xmm9, 0x30(%r10) ++ movaps %xmm10, 0x40(%r10) ++ movaps %xmm11, 0x50(%r10) ++ movaps %xmm12, 0x60(%r10) ++ movaps %xmm13, 0x70(%r10) ++ movaps %xmm14, 0x80(%r10) ++ movaps %xmm15, 0x90(%r10) ++ ++ ldmxcsr 0x70(%rdx) /* restore MMX control and status word */ ++ fldcw 0x74(%rdx) /* restore x87 control word */ ++ /* restore XMM storage */ ++ /* save start address of SSE register block in R10 */ ++ leaq 0x90(%rdx), %r10 ++ /* shift address in R10 to lower 16 byte boundary */ ++ /* == pointer to SEE register block */ ++ andq $-16, %r10 ++ ++ movaps (%r10), %xmm6 ++ movaps 0x10(%r10), %xmm7 ++ movaps 0x20(%r10), %xmm8 ++ movaps 0x30(%r10), %xmm9 ++ movaps 0x40(%r10), %xmm10 ++ movaps 0x50(%r10), %xmm11 ++ movaps 0x60(%r10), %xmm12 ++ movaps 0x70(%r10), %xmm13 ++ movaps 0x80(%r10), %xmm14 ++ movaps 0x90(%r10), %xmm15 ++ ++1: ++ leaq 0x08(%rsp), %rax /* exclude the return address */ ++ movq %rax, 0x40(%rcx) /* save as stack pointer */ ++ movq (%rsp), %rax /* load return address */ ++ movq %rax, 0x48(%rcx) /* save return address */ ++ ++ movq (%rdx), %r12 /* restore R12 */ ++ movq 0x08(%rdx), %r13 /* restore R13 */ ++ movq 0x10(%rdx), %r14 /* restore R14 */ ++ movq 0x18(%rdx), %r15 /* restore R15 */ ++ movq 0x20(%rdx), %rdi /* restore RDI */ ++ movq 0x28(%rdx), %rsi /* restore RSI */ ++ movq 0x30(%rdx), %rbx /* restore RBX */ ++ movq 0x38(%rdx), %rbp /* restore RBP */ ++ ++ movq %gs:(0x30), %r10 /* load NT_TIB */ ++ movq 0x50(%rdx), %rax /* load stack base */ ++ movq %rax, 0x08(%r10) /* restore stack base */ ++ movq 0x60(%rdx), %rax /* load stack limit */ ++ movq %rax, 0x10(%r10) /* restore stack limit */ ++ movq 0x68(%rdx), %rax /* load fiber local storage */ ++ movq %rax, 0x18(%r10) /* restore fiber local storage */ ++ ++ movq 0x40(%rdx), %rsp /* restore RSP */ ++ movq 0x48(%rdx), %r10 /* fetch the address to returned to */ ++ ++ movq %r8, %rax /* use third arg as return value after jump */ ++ movq %r8, %rcx /* use third arg as first arg in context function */ ++ ++ jmp *%r10 /* indirect jump to caller */ ++.seh_endproc