From 2fb0373629828024d33d63a89da59179c942ce5a Mon Sep 17 00:00:00 2001 From: Nikita Kniazev Date: Wed, 22 Mar 2023 23:46:33 +0300 Subject: [PATCH 1/3] Select assembly sources via preprocessor Fixes cross-compilation abi and binformat detection. `abi` and `binary-format` are now optional but can be used to override autodetection. --- build/Jamfile.v2 | 828 +----------------- build/architecture.jam | 96 -- example/callcc/Jamfile.v2 | 1 - example/fiber/Jamfile.v2 | 1 - src/asm/common.h | 88 ++ src/asm/jump.S | 7 + ...86_ms_pe_gas.asm => jump_i386_ms_pe_gas.S} | 0 ..._ms_pe_gas.asm => jump_x86_64_ms_pe_gas.S} | 0 src/asm/make.S | 7 + ...86_ms_pe_gas.asm => make_i386_ms_pe_gas.S} | 0 ..._ms_pe_gas.asm => make_x86_64_ms_pe_gas.S} | 0 src/asm/ontop.S | 7 + ...6_ms_pe_gas.asm => ontop_i386_ms_pe_gas.S} | 0 ...ms_pe_gas.asm => ontop_x86_64_ms_pe_gas.S} | 0 src/dummy.cpp | 0 15 files changed, 124 insertions(+), 911 deletions(-) delete mode 100644 build/architecture.jam create mode 100644 src/asm/common.h create mode 100644 src/asm/jump.S rename src/asm/{jump_i386_ms_pe_gas.asm => jump_i386_ms_pe_gas.S} (100%) rename src/asm/{jump_x86_64_ms_pe_gas.asm => jump_x86_64_ms_pe_gas.S} (100%) create mode 100644 src/asm/make.S rename src/asm/{make_i386_ms_pe_gas.asm => make_i386_ms_pe_gas.S} (100%) rename src/asm/{make_x86_64_ms_pe_gas.asm => make_x86_64_ms_pe_gas.S} (100%) create mode 100644 src/asm/ontop.S rename src/asm/{ontop_i386_ms_pe_gas.asm => ontop_i386_ms_pe_gas.S} (100%) rename src/asm/{ontop_x86_64_ms_pe_gas.asm => ontop_x86_64_ms_pe_gas.S} (100%) delete mode 100644 src/dummy.cpp diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index faaf892c..a02f4e05 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -54,36 +54,19 @@ project boost/context ; -local rule default_binary_format ( ) -{ - local tmp = elf ; - if [ os.name ] = "NT" { tmp = pe ; } - else if [ os.name ] = "CYGWIN" { tmp = pe ; } - else if [ os.name ] = "AIX" { tmp = xcoff ; } - else if [ os.name ] = "MACOSX" { tmp = mach-o ; } - return $(tmp) ; -} - feature.feature binary-format : elf mach-o pe xcoff : propagated + composite + optional ; -feature.set-default binary-format : [ default_binary_format ] ; - - -local rule default_abi ( ) -{ - local tmp = sysv ; - if [ os.name ] = "NT" { tmp = ms ; } - else if [ os.name ] = "CYGWIN" { tmp = ms ; } - else if [ os.platform ] in ARM ARM64 { tmp = aapcs ; } - else if [ os.platform ] = "MIPS32" { tmp = o32 ; } - else if [ os.platform ] = "MIPS64" { tmp = n64 ; } - return $(tmp) ; -} +feature.compose elf : BOOST_CONTEXT_ARCH=elf ; +feature.compose mach-o : BOOST_CONTEXT_ARCH=macho ; +feature.compose pe : BOOST_CONTEXT_ARCH=pe ; +feature.compose xcoff : BOOST_CONTEXT_ARCH=xcoff ; feature.feature abi : aapcs @@ -96,9 +79,12 @@ feature.feature abi sysv x32 : propagated + composite + optional ; -feature.set-default abi : [ default_abi ] ; - +for local abi in [ feature.values ] { + feature.compose $(abi) : BOOST_CONTEXT_ABI=$(abi) ; +} feature.feature context-impl : fcontext @@ -111,796 +97,12 @@ feature.set-default context-impl : fcontext ; feature.compose ucontext : BOOST_USE_UCONTEXT ; feature.compose winfib : BOOST_USE_WINFIB ; -# ARM -# ARM/AAPCS/ELF -alias asm_sources - : asm/make_arm_aapcs_elf_gas.S - asm/jump_arm_aapcs_elf_gas.S - asm/ontop_arm_aapcs_elf_gas.S - : aapcs - 32 - arm - elf - clang - ; - -alias asm_sources - : asm/make_arm_aapcs_elf_gas.S - asm/jump_arm_aapcs_elf_gas.S - asm/ontop_arm_aapcs_elf_gas.S - : aapcs - 32 - arm - elf - gcc - ; - -alias asm_sources - : asm/make_arm_aapcs_elf_gas.S - asm/jump_arm_aapcs_elf_gas.S - asm/ontop_arm_aapcs_elf_gas.S - : aapcs - 32 - arm - elf - qcc - ; - -# ARM/AAPCS/MACH-O -alias asm_sources - : asm/make_arm_aapcs_macho_gas.S - asm/jump_arm_aapcs_macho_gas.S - asm/ontop_arm_aapcs_macho_gas.S - : aapcs - 32 - arm - mach-o - clang - ; - -alias asm_sources - : asm/make_arm_aapcs_macho_gas.S - asm/jump_arm_aapcs_macho_gas.S - asm/ontop_arm_aapcs_macho_gas.S - : aapcs - 32 - arm - mach-o - darwin - ; - -# ARM/AAPCS/PE -alias asm_sources - : asm/make_arm_aapcs_pe_armasm.asm - asm/jump_arm_aapcs_pe_armasm.asm - asm/ontop_arm_aapcs_pe_armasm.asm - untested.cpp - : aapcs - 32 - arm - pe - msvc - ; - -# ARM64 -# ARM64/AAPCS/ELF -alias asm_sources - : asm/make_arm64_aapcs_elf_gas.S - asm/jump_arm64_aapcs_elf_gas.S - asm/ontop_arm64_aapcs_elf_gas.S - : aapcs - 64 - arm - elf - clang - ; - -alias asm_sources - : asm/make_arm64_aapcs_elf_gas.S - asm/jump_arm64_aapcs_elf_gas.S - asm/ontop_arm64_aapcs_elf_gas.S - : aapcs - 64 - arm - elf - gcc - ; - -# ARM64/AAPCS/MACH-O -alias asm_sources - : asm/make_arm64_aapcs_macho_gas.S - asm/jump_arm64_aapcs_macho_gas.S - asm/ontop_arm64_aapcs_macho_gas.S - : aapcs - 64 - arm - mach-o - clang - ; - -alias asm_sources - : asm/make_arm64_aapcs_macho_gas.S - asm/jump_arm64_aapcs_macho_gas.S - asm/ontop_arm64_aapcs_macho_gas.S - : aapcs - 64 - arm - mach-o - darwin - ; - -# ARM64/AAPCS/PE -alias asm_sources - : asm/make_arm64_aapcs_pe_armasm.asm - asm/jump_arm64_aapcs_pe_armasm.asm - asm/ontop_arm64_aapcs_pe_armasm.asm - : aapcs - 64 - arm - pe - msvc - ; - -# LOONGARCH64 -# LOONGARCH64/SYSV/ELF -alias asm_sources - : asm/make_loongarch64_sysv_elf_gas.S - asm/jump_loongarch64_sysv_elf_gas.S - asm/ontop_loongarch64_sysv_elf_gas.S - : sysv - 64 - loongarch - elf - gcc - ; - -# MIPS -# MIPS32/O32/ELF -alias asm_sources - : asm/make_mips32_o32_elf_gas.S - asm/jump_mips32_o32_elf_gas.S - asm/ontop_mips32_o32_elf_gas.S - : o32 - 32 - mips - elf - clang - ; - -alias asm_sources - : asm/make_mips32_o32_elf_gas.S - asm/jump_mips32_o32_elf_gas.S - asm/ontop_mips32_o32_elf_gas.S - : o32 - 32 - mips - elf - gcc - ; - -# MIPS64/N64/ELF -alias asm_sources - : asm/make_mips64_n64_elf_gas.S - asm/jump_mips64_n64_elf_gas.S - asm/ontop_mips64_n64_elf_gas.S - : n64 - 64 - mips - elf - clang - ; - -alias asm_sources - : asm/make_mips64_n64_elf_gas.S - asm/jump_mips64_n64_elf_gas.S - asm/ontop_mips64_n64_elf_gas.S - : n64 - 64 - mips - elf - gcc - ; - -# POWERPC_32 -# POWERPC_32/SYSV/ELF -alias asm_sources - : asm/make_ppc32_sysv_elf_gas.S - asm/jump_ppc32_sysv_elf_gas.S - asm/ontop_ppc32_sysv_elf_gas.S - asm/tail_ontop_ppc32_sysv.cpp - : sysv - 32 - power - elf - clang - ; - -alias asm_sources - : asm/make_ppc32_sysv_elf_gas.S - asm/jump_ppc32_sysv_elf_gas.S - asm/ontop_ppc32_sysv_elf_gas.S - asm/tail_ontop_ppc32_sysv.cpp - : sysv - 32 - power - elf - gcc - ; - -# POWERPC_32/SYSV/MACH-O -alias asm_sources - : asm/make_ppc32_sysv_macho_gas.S - asm/jump_ppc32_sysv_macho_gas.S - asm/ontop_ppc32_sysv_macho_gas.S - asm/tail_ontop_ppc32_sysv.cpp - : sysv - 32 - power - mach-o - clang - ; - -alias asm_sources - : asm/make_ppc32_sysv_macho_gas.S - asm/jump_ppc32_sysv_macho_gas.S - asm/ontop_ppc32_sysv_macho_gas.S - asm/tail_ontop_ppc32_sysv.cpp - : sysv - 32 - power - mach-o - gcc - ; - -alias asm_sources - : asm/make_ppc32_sysv_macho_gas.S - asm/jump_ppc32_sysv_macho_gas.S - asm/ontop_ppc32_sysv_macho_gas.S - asm/tail_ontop_ppc32_sysv.cpp - : sysv - 32 - power - mach-o - darwin - ; - -#POWERPC_32/SYSV/XCOFF -alias asm_sources - : asm/make_ppc32_sysv_xcoff_gas.S - asm/jump_ppc32_sysv_xcoff_gas.S - asm/ontop_ppc32_sysv_xcoff_gas.S - : sysv - 32 - power - xcoff - clang - ; - -alias asm_sources - : asm/make_ppc32_sysv_xcoff_gas.S - asm/jump_ppc32_sysv_xcoff_gas.S - asm/ontop_ppc32_sysv_xcoff_gas.S - : sysv - 32 - power - xcoff - gcc - ; - -# POWERPC_64 -# POWERPC_64/SYSV/ELF -alias asm_sources - : asm/make_ppc64_sysv_elf_gas.S - asm/jump_ppc64_sysv_elf_gas.S - asm/ontop_ppc64_sysv_elf_gas.S - : sysv - 64 - power - elf - clang - ; - -alias asm_sources - : asm/make_ppc64_sysv_elf_gas.S - asm/jump_ppc64_sysv_elf_gas.S - asm/ontop_ppc64_sysv_elf_gas.S - : sysv - 64 - power - elf - gcc - ; - -# POWERPC_64/SYSV/MACH-O -alias asm_sources - : asm/make_ppc64_sysv_macho_gas.S - asm/jump_ppc64_sysv_macho_gas.S - asm/ontop_ppc64_sysv_macho_gas.S - untested.cpp - : sysv - 64 - power - mach-o - clang - ; - -alias asm_sources - : asm/make_ppc64_sysv_macho_gas.S - asm/jump_ppc64_sysv_macho_gas.S - asm/ontop_ppc64_sysv_macho_gas.S - untested.cpp - : sysv - 64 - power - mach-o - gcc - ; - -alias asm_sources - : asm/make_ppc64_sysv_macho_gas.S - asm/jump_ppc64_sysv_macho_gas.S - asm/ontop_ppc64_sysv_macho_gas.S - untested.cpp - : sysv - 64 - power - mach-o - darwin - ; - -# POWERPC_64/SYSV/XCOFF -alias asm_sources - : asm/make_ppc64_sysv_xcoff_gas.S - asm/jump_ppc64_sysv_xcoff_gas.S - asm/ontop_ppc64_sysv_xcoff_gas.S - : sysv - 64 - power - xcoff - clang - ; - -alias asm_sources - : asm/make_ppc64_sysv_xcoff_gas.S - asm/jump_ppc64_sysv_xcoff_gas.S - asm/ontop_ppc64_sysv_xcoff_gas.S - : sysv - 64 - power - xcoff - gcc - ; - -# POWERPC universal -# POWERPC_32_64/SYSV/MACH-O -alias asm_sources - : asm/make_ppc32_ppc64_sysv_macho_gas.S - asm/jump_ppc32_ppc64_sysv_macho_gas.S - asm/ontop_ppc32_ppc64_sysv_macho_gas.S - : sysv - 32_64 - power - mach-o - ; - -# RISCV64 -# RISCV64/SYSV/ELF -alias asm_sources - : asm/make_riscv64_sysv_elf_gas.S - asm/jump_riscv64_sysv_elf_gas.S - asm/ontop_riscv64_sysv_elf_gas.S - : sysv - 64 - riscv - elf - clang - ; - -alias asm_sources - : asm/make_riscv64_sysv_elf_gas.S - asm/jump_riscv64_sysv_elf_gas.S - asm/ontop_riscv64_sysv_elf_gas.S - : sysv - 64 - riscv - elf - gcc - ; - -# S390X -# S390X/SYSV/ELF -alias asm_sources - : asm/make_s390x_sysv_elf_gas.S - asm/jump_s390x_sysv_elf_gas.S - asm/ontop_s390x_sysv_elf_gas.S - : sysv - 64 - s390x - elf - gcc - ; - -alias asm_sources - : asm/make_s390x_sysv_elf_gas.S - asm/jump_s390x_sysv_elf_gas.S - asm/ontop_s390x_sysv_elf_gas.S - : sysv - 64 - s390x - elf - clang - ; - -# X86 -# X86/SYSV/ELF -alias asm_sources - : asm/make_i386_sysv_elf_gas.S - asm/jump_i386_sysv_elf_gas.S - asm/ontop_i386_sysv_elf_gas.S - : sysv - 32 - x86 - elf - clang - ; - -alias asm_sources - : asm/make_i386_sysv_elf_gas.S - asm/jump_i386_sysv_elf_gas.S - asm/ontop_i386_sysv_elf_gas.S - : sysv - 32 - x86 - elf - gcc - ; - -alias asm_sources - : asm/make_i386_sysv_elf_gas.S - asm/jump_i386_sysv_elf_gas.S - asm/ontop_i386_sysv_elf_gas.S - : sysv - 32 - x86 - elf - intel - ; - -# X86/SYSV/MACH-O -alias asm_sources - : asm/make_i386_sysv_macho_gas.S - asm/jump_i386_sysv_macho_gas.S - asm/ontop_i386_sysv_macho_gas.S - : sysv - 32 - x86 - mach-o - clang - ; - -alias asm_sources - : asm/make_i386_sysv_macho_gas.S - asm/jump_i386_sysv_macho_gas.S - asm/ontop_i386_sysv_macho_gas.S - : sysv - 32 - x86 - mach-o - darwin - ; - -# X86/MS/PE -alias asm_sources - : asm/make_i386_ms_pe_gas.asm - asm/jump_i386_ms_pe_gas.asm - asm/ontop_i386_ms_pe_gas.asm - dummy.cpp - : ms - 32 - x86 - pe - clang - ; - -alias asm_sources - : asm/make_i386_ms_pe_masm.asm - asm/jump_i386_ms_pe_masm.asm - asm/ontop_i386_ms_pe_masm.asm - dummy.cpp - : ms - 32 - x86 - pe - clang-win - ; - -alias asm_sources - : asm/make_i386_ms_pe_gas.asm - asm/jump_i386_ms_pe_gas.asm - asm/ontop_i386_ms_pe_gas.asm - dummy.cpp - : ms - 32 - x86 - pe - gcc - ; - -alias asm_sources - : asm/make_i386_ms_pe_masm.asm - asm/jump_i386_ms_pe_masm.asm - asm/ontop_i386_ms_pe_masm.asm - dummy.cpp - : ms - 32 - x86 - pe - intel - ; - -alias asm_sources - : asm/make_i386_ms_pe_masm.asm - asm/jump_i386_ms_pe_masm.asm - asm/ontop_i386_ms_pe_masm.asm - dummy.cpp - : ms - 32 - x86 - pe - msvc - ; - -# Embarcadero on Windows for 32-bits, bcc32x, uses tasm32, -# which is masm compatible -# This is configured in the embarcadero toolset as using -# 'tasm32 /ml' - -alias asm_sources - : asm/make_i386_ms_pe_masm.asm - asm/jump_i386_ms_pe_masm.asm - asm/ontop_i386_ms_pe_masm.asm - dummy.cpp - : ms - 32 - x86 - pe - embarcadero - ; - -# Borland on Windows for 32-bits, bcc32c, uses tasm32, -# which is masm compatible -# This is configured in the borland toolset as using -# 'tasm32 /ml' - -alias asm_sources - : asm/make_i386_ms_pe_masm.asm - asm/jump_i386_ms_pe_masm.asm - asm/ontop_i386_ms_pe_masm.asm - dummy.cpp - : ms - 32 - x86 - pe - borland - ; - -# X86_64 -# X86_64/SYSV/ELF -alias asm_sources - : asm/make_x86_64_sysv_elf_gas.S - asm/jump_x86_64_sysv_elf_gas.S - asm/ontop_x86_64_sysv_elf_gas.S - : sysv - 64 - x86 - elf - clang - ; - -alias asm_sources - : asm/make_x86_64_sysv_elf_gas.S - asm/jump_x86_64_sysv_elf_gas.S - asm/ontop_x86_64_sysv_elf_gas.S - : sysv - 64 - x86 - elf - gcc - ; - -alias asm_sources - : asm/make_x86_64_sysv_elf_gas.S - asm/jump_x86_64_sysv_elf_gas.S - asm/ontop_x86_64_sysv_elf_gas.S - : sysv - 64 - x86 - elf - intel - ; - -# X86_64/SYSV/MACH-O -alias asm_sources - : asm/make_x86_64_sysv_macho_gas.S - asm/jump_x86_64_sysv_macho_gas.S - asm/ontop_x86_64_sysv_macho_gas.S - : sysv - 64 - x86 - mach-o - clang - ; - -alias asm_sources - : asm/make_x86_64_sysv_macho_gas.S - asm/jump_x86_64_sysv_macho_gas.S - asm/ontop_x86_64_sysv_macho_gas.S - : sysv - 64 - x86 - mach-o - gcc - ; - -alias asm_sources - : asm/make_x86_64_sysv_macho_gas.S - asm/jump_x86_64_sysv_macho_gas.S - asm/ontop_x86_64_sysv_macho_gas.S - : sysv - 64 - x86 - mach-o - darwin - ; - -alias asm_sources - : asm/make_x86_64_sysv_macho_gas.S - asm/jump_x86_64_sysv_macho_gas.S - asm/ontop_x86_64_sysv_macho_gas.S - : sysv - 64 - x86 - mach-o - intel - ; - -# X86_64/MS/PE -alias asm_sources - : asm/make_x86_64_ms_pe_gas.asm - asm/jump_x86_64_ms_pe_gas.asm - asm/ontop_x86_64_ms_pe_gas.asm - dummy.cpp - : ms - 64 - x86 - pe - clang - ; - -alias asm_sources - : asm/make_x86_64_ms_pe_masm.asm - asm/jump_x86_64_ms_pe_masm.asm - asm/ontop_x86_64_ms_pe_masm.asm - dummy.cpp - : ms - 64 - x86 - pe - clang-win - ; - -alias asm_sources - : asm/make_x86_64_ms_pe_gas.asm - asm/jump_x86_64_ms_pe_gas.asm - asm/ontop_x86_64_ms_pe_gas.asm - dummy.cpp - : ms - 64 - x86 - pe - gcc - ; - -alias asm_sources - : asm/make_x86_64_ms_pe_masm.asm - asm/jump_x86_64_ms_pe_masm.asm - asm/ontop_x86_64_ms_pe_masm.asm - dummy.cpp - : ms - 64 - x86 - pe - intel - ; - -alias asm_sources - : asm/make_x86_64_ms_pe_masm.asm - asm/jump_x86_64_ms_pe_masm.asm - asm/ontop_x86_64_ms_pe_masm.asm - dummy.cpp - : ms - 64 - x86 - pe - msvc - ; - -# Embarcadero on Windows, bcc64, uses the sysv-elf format for 64-bits -# This is configured in the embarcadero toolset as using bcc64 with the -# command line option '-x assembler-with-cpp'. - -alias asm_sources - : asm/make_x86_64_sysv_elf_gas.S - asm/jump_x86_64_sysv_elf_gas.S - asm/ontop_x86_64_sysv_elf_gas.S - : ms - 64 - x86 - pe - embarcadero - ; - -# X86_64/SYSV/X32 -alias asm_sources - : asm/make_x86_64_sysv_elf_gas.S - asm/jump_x86_64_sysv_elf_gas.S - asm/ontop_x86_64_sysv_elf_gas.S - : x32 - 32 - x86 - elf - clang - ; - -alias asm_sources - : asm/make_x86_64_sysv_elf_gas.S - asm/jump_x86_64_sysv_elf_gas.S - asm/ontop_x86_64_sysv_elf_gas.S - : x32 - 32 - x86 - elf - gcc - ; - -alias asm_sources - : asm/make_x86_64_sysv_elf_gas.S - asm/jump_x86_64_sysv_elf_gas.S - asm/ontop_x86_64_sysv_elf_gas.S - : x32 - 32 - x86 - elf - intel - ; - -#X86 universal -alias asm_sources - : asm/make_i386_x86_64_sysv_macho_gas.S - asm/jump_i386_x86_64_sysv_macho_gas.S - asm/ontop_i386_x86_64_sysv_macho_gas.S - : sysv - 32_64 - x86 - mach-o - ; - -# COMBINED -alias asm_sources - : asm/make_combined_sysv_macho_gas.S - asm/jump_combined_sysv_macho_gas.S - asm/ontop_combined_sysv_macho_gas.S - : sysv - arm+x86 - mach-o - ; - -explicit asm_sources ; - - # fcontext_t alias impl_sources - : asm_sources + : asm/make.S + asm/jump.S + asm/ontop.S + asm/tail_ontop_ppc32_sysv.cpp : fcontext ; diff --git a/build/architecture.jam b/build/architecture.jam deleted file mode 100644 index d1dd356b..00000000 --- a/build/architecture.jam +++ /dev/null @@ -1,96 +0,0 @@ -# architecture.jam -# -# Copyright 2012 Steven Watanabe -# -# Distributed under the Boost Software License Version 1.0. (See -# accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) - -import configure ; -import project ; -import path ; -import property ; - -local here = [ modules.binding $(__name__) ] ; - -project.push-current [ project.current ] ; -project.load [ path.join [ path.make $(here:D) ] ../config ] ; -project.pop-current ; - -rule deduce-address-model ( properties * ) -{ - local result = [ property.select : $(properties) ] ; - if $(result) - { - return $(result) ; - } - else - { - if [ configure.builds /boost/architecture//32 : $(properties) : 32-bit ] - { - return 32 ; - } - else if [ configure.builds /boost/architecture//64 : $(properties) : 64-bit ] - { - return 64 ; - } - } -} - -rule address-model ( ) -{ - return @architecture.deduce-address-model ; -} - -rule deduce-architecture ( properties * ) -{ - local result = [ property.select : $(properties) ] ; - if $(result) - { - return $(result) ; - } - else - { - if [ configure.builds /boost/architecture//arm : $(properties) : arm ] - { - return arm ; - } - else if [ configure.builds /boost/architecture//loongarch : $(properties) : loongarch ] - { - return loongarch ; - } - else if [ configure.builds /boost/architecture//mips : $(properties) : mips ] - { - return mips ; - } - else if [ configure.builds /boost/architecture//power : $(properties) : power ] - { - return power ; - } - else if [ configure.builds /boost/architecture//riscv : $(properties) : riscv ] - { - return riscv ; - } - else if [ configure.builds /boost/architecture//s390x : $(properties) : s390x ] - { - return s390x ; - } - else if [ configure.builds /boost/architecture//sparc : $(properties) : sparc ] - { - return sparc ; - } - else if [ configure.builds /boost/architecture//x86 : $(properties) : x86 ] - { - return x86 ; - } - else if [ configure.builds /boost/architecture//arm+x86 : $(properties) : arm+x86 ] - { - return arm+x86 ; - } - } -} - -rule architecture ( ) -{ - return @architecture.deduce-architecture ; -} diff --git a/example/callcc/Jamfile.v2 b/example/callcc/Jamfile.v2 index ba792c89..acfbaa3d 100644 --- a/example/callcc/Jamfile.v2 +++ b/example/callcc/Jamfile.v2 @@ -13,7 +13,6 @@ import indirect ; import modules ; import os ; import toolset ; -import architecture ; project boost/context/example/callcc : requirements diff --git a/example/fiber/Jamfile.v2 b/example/fiber/Jamfile.v2 index bf3c1bd2..08a9146a 100644 --- a/example/fiber/Jamfile.v2 +++ b/example/fiber/Jamfile.v2 @@ -13,7 +13,6 @@ import indirect ; import modules ; import os ; import toolset ; -import architecture ; project boost/context/example/fiber : requirements diff --git a/src/asm/common.h b/src/asm/common.h new file mode 100644 index 00000000..7a633004 --- /dev/null +++ b/src/asm/common.h @@ -0,0 +1,88 @@ +// Copyright Nikita Kniazev 2023. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include + +// Predef bug https://github.com/boostorg/predef/issues/127 +#if defined(BOOST_ARCH_MIPS_AVAILABLE) && !defined(__mips64) +# undef BOOST_ARCH_WORD_BITS +# define BOOST_ARCH_WORD_BITS 32 +#endif + +#if defined(BOOST_CONTEXT_ARCH) +// Defined by user +#elif defined(BOOST_ARCH_X86_64_AVAILABLE) +# define BOOST_CONTEXT_ARCH x86_64 +#elif defined(BOOST_ARCH_X86_32_AVAILABLE) +# undef i386 +# define BOOST_CONTEXT_ARCH i386 +#elif defined(BOOST_ARCH_ARM_AVAILABLE) && BOOST_ARCH_WORD_BITS == 64 +# define BOOST_CONTEXT_ARCH arm64 +#elif defined(BOOST_ARCH_ARM_AVAILABLE) && BOOST_ARCH_WORD_BITS == 32 +# define BOOST_CONTEXT_ARCH arm +#elif defined(BOOST_ARCH_MIPS_AVAILABLE) && BOOST_ARCH_WORD_BITS == 64 +# define BOOST_CONTEXT_ARCH mips64 +#elif defined(BOOST_ARCH_MIPS_AVAILABLE) && BOOST_ARCH_WORD_BITS == 32 +# define BOOST_CONTEXT_ARCH mips32 +#elif defined(BOOST_ARCH_PPC_64_AVAILABLE) +# define BOOST_CONTEXT_ARCH ppc64 +#elif defined(BOOST_ARCH_PPC_AVAILABLE) +# define BOOST_CONTEXT_ARCH ppc32 +#elif defined(BOOST_ARCH_RISCV_AVAILABLE) +# define BOOST_CONTEXT_ARCH riscv64 +#elif defined(BOOST_ARCH_SYS390_AVAILABLE) +# define BOOST_CONTEXT_ARCH s390x +#elif defined(BOOST_ARCH_LOONGARCH_AVAILABLE) +# define BOOST_CONTEXT_ARCH loongarch64 +#else +# error "Unsupported architecture" +#endif + +#if defined(BOOST_CONTEXT_ABI) +// Defined by user +#elif defined(BOOST_ARCH_ARM_AVAILABLE) +# define BOOST_CONTEXT_ABI aapcs +#elif defined(BOOST_ARCH_MIPS_AVAILABLE) && BOOST_ARCH_WORD_BITS == 64 +# define BOOST_CONTEXT_ABI n64 +#elif defined(BOOST_ARCH_MIPS_AVAILABLE) && BOOST_ARCH_WORD_BITS == 32 +# define BOOST_CONTEXT_ABI o32 +#elif defined(BOOST_OS_WINDOWS_AVAILABLE) +# define BOOST_CONTEXT_ABI ms +#else +# define BOOST_CONTEXT_ABI sysv +#endif + +#if defined(BOOST_CONTEXT_BINFMT) +// Defined by user +#elif defined(BOOST_OS_WINDOWS_AVAILABLE) +# define BOOST_CONTEXT_BINFMT pe +#elif defined(BOOST_OS_AIX_AVAILABLE) +# define BOOST_CONTEXT_BINFMT xcoff +#elif defined(BOOST_OS_MACOS_AVAILABLE) +# define BOOST_CONTEXT_BINFMT macho +#else +# define BOOST_CONTEXT_BINFMT elf +#endif + +#if defined(BOOST_CONTEXT_ASSEMBLER) +// Defined by user +#elif defined(__GNUC__) +# define BOOST_CONTEXT_ASSEMBLER gas.S +#elif defined(BOOST_ARCH_ARM_AVAILABLE) +# define BOOST_CONTEXT_ASSEMBLER armasm.asm +#elif defined(BOOST_OS_WINDOWS_AVAILABLE) +# define BOOST_CONTEXT_ASSEMBLER masm.asm +#else +# define BOOST_CONTEXT_ASSEMBLER gas.S +#endif + +#include + +#define BOOST_CONTEXT_ASM_INCLUDE(name) \ + BOOST_STRINGIZE(BOOST_JOIN(BOOST_JOIN(BOOST_JOIN(BOOST_JOIN(BOOST_JOIN(BOOST_JOIN(BOOST_JOIN(BOOST_JOIN( \ + name, _), BOOST_CONTEXT_ARCH), _), BOOST_CONTEXT_ABI), _), BOOST_CONTEXT_BINFMT), _), BOOST_CONTEXT_ASSEMBLER)) + diff --git a/src/asm/jump.S b/src/asm/jump.S new file mode 100644 index 00000000..50d52d69 --- /dev/null +++ b/src/asm/jump.S @@ -0,0 +1,7 @@ +// Copyright Nikita Kniazev 2023. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include "common.h" +#include BOOST_CONTEXT_ASM_INCLUDE(jump) diff --git a/src/asm/jump_i386_ms_pe_gas.asm b/src/asm/jump_i386_ms_pe_gas.S similarity index 100% rename from src/asm/jump_i386_ms_pe_gas.asm rename to src/asm/jump_i386_ms_pe_gas.S diff --git a/src/asm/jump_x86_64_ms_pe_gas.asm b/src/asm/jump_x86_64_ms_pe_gas.S similarity index 100% rename from src/asm/jump_x86_64_ms_pe_gas.asm rename to src/asm/jump_x86_64_ms_pe_gas.S diff --git a/src/asm/make.S b/src/asm/make.S new file mode 100644 index 00000000..b4376c4e --- /dev/null +++ b/src/asm/make.S @@ -0,0 +1,7 @@ +// Copyright Nikita Kniazev 2023. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include "common.h" +#include BOOST_CONTEXT_ASM_INCLUDE(make) diff --git a/src/asm/make_i386_ms_pe_gas.asm b/src/asm/make_i386_ms_pe_gas.S similarity index 100% rename from src/asm/make_i386_ms_pe_gas.asm rename to src/asm/make_i386_ms_pe_gas.S diff --git a/src/asm/make_x86_64_ms_pe_gas.asm b/src/asm/make_x86_64_ms_pe_gas.S similarity index 100% rename from src/asm/make_x86_64_ms_pe_gas.asm rename to src/asm/make_x86_64_ms_pe_gas.S diff --git a/src/asm/ontop.S b/src/asm/ontop.S new file mode 100644 index 00000000..d03e312a --- /dev/null +++ b/src/asm/ontop.S @@ -0,0 +1,7 @@ +// Copyright Nikita Kniazev 2023. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include "common.h" +#include BOOST_CONTEXT_ASM_INCLUDE(ontop) diff --git a/src/asm/ontop_i386_ms_pe_gas.asm b/src/asm/ontop_i386_ms_pe_gas.S similarity index 100% rename from src/asm/ontop_i386_ms_pe_gas.asm rename to src/asm/ontop_i386_ms_pe_gas.S diff --git a/src/asm/ontop_x86_64_ms_pe_gas.asm b/src/asm/ontop_x86_64_ms_pe_gas.S similarity index 100% rename from src/asm/ontop_x86_64_ms_pe_gas.asm rename to src/asm/ontop_x86_64_ms_pe_gas.S diff --git a/src/dummy.cpp b/src/dummy.cpp deleted file mode 100644 index e69de29b..00000000 From 65b179db288d13da21447e4f430400338ce08ca2 Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Sat, 22 Jul 2023 17:23:17 +0200 Subject: [PATCH 2/3] Revert "Select assembly sources via preprocessor" This reverts commit 2fb0373629828024d33d63a89da59179c942ce5a. --- build/Jamfile.v2 | 828 +++++++++++++++++- build/architecture.jam | 96 ++ example/callcc/Jamfile.v2 | 1 + example/fiber/Jamfile.v2 | 1 + src/asm/common.h | 88 -- src/asm/jump.S | 7 - ...86_ms_pe_gas.S => jump_i386_ms_pe_gas.asm} | 0 ..._ms_pe_gas.S => jump_x86_64_ms_pe_gas.asm} | 0 src/asm/make.S | 7 - ...86_ms_pe_gas.S => make_i386_ms_pe_gas.asm} | 0 ..._ms_pe_gas.S => make_x86_64_ms_pe_gas.asm} | 0 src/asm/ontop.S | 7 - ...6_ms_pe_gas.S => ontop_i386_ms_pe_gas.asm} | 0 ...ms_pe_gas.S => ontop_x86_64_ms_pe_gas.asm} | 0 src/dummy.cpp | 0 15 files changed, 911 insertions(+), 124 deletions(-) create mode 100644 build/architecture.jam delete mode 100644 src/asm/common.h delete mode 100644 src/asm/jump.S rename src/asm/{jump_i386_ms_pe_gas.S => jump_i386_ms_pe_gas.asm} (100%) rename src/asm/{jump_x86_64_ms_pe_gas.S => jump_x86_64_ms_pe_gas.asm} (100%) delete mode 100644 src/asm/make.S rename src/asm/{make_i386_ms_pe_gas.S => make_i386_ms_pe_gas.asm} (100%) rename src/asm/{make_x86_64_ms_pe_gas.S => make_x86_64_ms_pe_gas.asm} (100%) delete mode 100644 src/asm/ontop.S rename src/asm/{ontop_i386_ms_pe_gas.S => ontop_i386_ms_pe_gas.asm} (100%) rename src/asm/{ontop_x86_64_ms_pe_gas.S => ontop_x86_64_ms_pe_gas.asm} (100%) create mode 100644 src/dummy.cpp diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index a02f4e05..faaf892c 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -54,19 +54,36 @@ project boost/context ; +local rule default_binary_format ( ) +{ + local tmp = elf ; + if [ os.name ] = "NT" { tmp = pe ; } + else if [ os.name ] = "CYGWIN" { tmp = pe ; } + else if [ os.name ] = "AIX" { tmp = xcoff ; } + else if [ os.name ] = "MACOSX" { tmp = mach-o ; } + return $(tmp) ; +} + feature.feature binary-format : elf mach-o pe xcoff : propagated - composite - optional ; -feature.compose elf : BOOST_CONTEXT_ARCH=elf ; -feature.compose mach-o : BOOST_CONTEXT_ARCH=macho ; -feature.compose pe : BOOST_CONTEXT_ARCH=pe ; -feature.compose xcoff : BOOST_CONTEXT_ARCH=xcoff ; +feature.set-default binary-format : [ default_binary_format ] ; + + +local rule default_abi ( ) +{ + local tmp = sysv ; + if [ os.name ] = "NT" { tmp = ms ; } + else if [ os.name ] = "CYGWIN" { tmp = ms ; } + else if [ os.platform ] in ARM ARM64 { tmp = aapcs ; } + else if [ os.platform ] = "MIPS32" { tmp = o32 ; } + else if [ os.platform ] = "MIPS64" { tmp = n64 ; } + return $(tmp) ; +} feature.feature abi : aapcs @@ -79,12 +96,9 @@ feature.feature abi sysv x32 : propagated - composite - optional ; -for local abi in [ feature.values ] { - feature.compose $(abi) : BOOST_CONTEXT_ABI=$(abi) ; -} +feature.set-default abi : [ default_abi ] ; + feature.feature context-impl : fcontext @@ -97,12 +111,796 @@ feature.set-default context-impl : fcontext ; feature.compose ucontext : BOOST_USE_UCONTEXT ; feature.compose winfib : BOOST_USE_WINFIB ; +# ARM +# ARM/AAPCS/ELF +alias asm_sources + : asm/make_arm_aapcs_elf_gas.S + asm/jump_arm_aapcs_elf_gas.S + asm/ontop_arm_aapcs_elf_gas.S + : aapcs + 32 + arm + elf + clang + ; + +alias asm_sources + : asm/make_arm_aapcs_elf_gas.S + asm/jump_arm_aapcs_elf_gas.S + asm/ontop_arm_aapcs_elf_gas.S + : aapcs + 32 + arm + elf + gcc + ; + +alias asm_sources + : asm/make_arm_aapcs_elf_gas.S + asm/jump_arm_aapcs_elf_gas.S + asm/ontop_arm_aapcs_elf_gas.S + : aapcs + 32 + arm + elf + qcc + ; + +# ARM/AAPCS/MACH-O +alias asm_sources + : asm/make_arm_aapcs_macho_gas.S + asm/jump_arm_aapcs_macho_gas.S + asm/ontop_arm_aapcs_macho_gas.S + : aapcs + 32 + arm + mach-o + clang + ; + +alias asm_sources + : asm/make_arm_aapcs_macho_gas.S + asm/jump_arm_aapcs_macho_gas.S + asm/ontop_arm_aapcs_macho_gas.S + : aapcs + 32 + arm + mach-o + darwin + ; + +# ARM/AAPCS/PE +alias asm_sources + : asm/make_arm_aapcs_pe_armasm.asm + asm/jump_arm_aapcs_pe_armasm.asm + asm/ontop_arm_aapcs_pe_armasm.asm + untested.cpp + : aapcs + 32 + arm + pe + msvc + ; + +# ARM64 +# ARM64/AAPCS/ELF +alias asm_sources + : asm/make_arm64_aapcs_elf_gas.S + asm/jump_arm64_aapcs_elf_gas.S + asm/ontop_arm64_aapcs_elf_gas.S + : aapcs + 64 + arm + elf + clang + ; + +alias asm_sources + : asm/make_arm64_aapcs_elf_gas.S + asm/jump_arm64_aapcs_elf_gas.S + asm/ontop_arm64_aapcs_elf_gas.S + : aapcs + 64 + arm + elf + gcc + ; + +# ARM64/AAPCS/MACH-O +alias asm_sources + : asm/make_arm64_aapcs_macho_gas.S + asm/jump_arm64_aapcs_macho_gas.S + asm/ontop_arm64_aapcs_macho_gas.S + : aapcs + 64 + arm + mach-o + clang + ; + +alias asm_sources + : asm/make_arm64_aapcs_macho_gas.S + asm/jump_arm64_aapcs_macho_gas.S + asm/ontop_arm64_aapcs_macho_gas.S + : aapcs + 64 + arm + mach-o + darwin + ; + +# ARM64/AAPCS/PE +alias asm_sources + : asm/make_arm64_aapcs_pe_armasm.asm + asm/jump_arm64_aapcs_pe_armasm.asm + asm/ontop_arm64_aapcs_pe_armasm.asm + : aapcs + 64 + arm + pe + msvc + ; + +# LOONGARCH64 +# LOONGARCH64/SYSV/ELF +alias asm_sources + : asm/make_loongarch64_sysv_elf_gas.S + asm/jump_loongarch64_sysv_elf_gas.S + asm/ontop_loongarch64_sysv_elf_gas.S + : sysv + 64 + loongarch + elf + gcc + ; + +# MIPS +# MIPS32/O32/ELF +alias asm_sources + : asm/make_mips32_o32_elf_gas.S + asm/jump_mips32_o32_elf_gas.S + asm/ontop_mips32_o32_elf_gas.S + : o32 + 32 + mips + elf + clang + ; + +alias asm_sources + : asm/make_mips32_o32_elf_gas.S + asm/jump_mips32_o32_elf_gas.S + asm/ontop_mips32_o32_elf_gas.S + : o32 + 32 + mips + elf + gcc + ; + +# MIPS64/N64/ELF +alias asm_sources + : asm/make_mips64_n64_elf_gas.S + asm/jump_mips64_n64_elf_gas.S + asm/ontop_mips64_n64_elf_gas.S + : n64 + 64 + mips + elf + clang + ; + +alias asm_sources + : asm/make_mips64_n64_elf_gas.S + asm/jump_mips64_n64_elf_gas.S + asm/ontop_mips64_n64_elf_gas.S + : n64 + 64 + mips + elf + gcc + ; + +# POWERPC_32 +# POWERPC_32/SYSV/ELF +alias asm_sources + : asm/make_ppc32_sysv_elf_gas.S + asm/jump_ppc32_sysv_elf_gas.S + asm/ontop_ppc32_sysv_elf_gas.S + asm/tail_ontop_ppc32_sysv.cpp + : sysv + 32 + power + elf + clang + ; + +alias asm_sources + : asm/make_ppc32_sysv_elf_gas.S + asm/jump_ppc32_sysv_elf_gas.S + asm/ontop_ppc32_sysv_elf_gas.S + asm/tail_ontop_ppc32_sysv.cpp + : sysv + 32 + power + elf + gcc + ; + +# POWERPC_32/SYSV/MACH-O +alias asm_sources + : asm/make_ppc32_sysv_macho_gas.S + asm/jump_ppc32_sysv_macho_gas.S + asm/ontop_ppc32_sysv_macho_gas.S + asm/tail_ontop_ppc32_sysv.cpp + : sysv + 32 + power + mach-o + clang + ; + +alias asm_sources + : asm/make_ppc32_sysv_macho_gas.S + asm/jump_ppc32_sysv_macho_gas.S + asm/ontop_ppc32_sysv_macho_gas.S + asm/tail_ontop_ppc32_sysv.cpp + : sysv + 32 + power + mach-o + gcc + ; + +alias asm_sources + : asm/make_ppc32_sysv_macho_gas.S + asm/jump_ppc32_sysv_macho_gas.S + asm/ontop_ppc32_sysv_macho_gas.S + asm/tail_ontop_ppc32_sysv.cpp + : sysv + 32 + power + mach-o + darwin + ; + +#POWERPC_32/SYSV/XCOFF +alias asm_sources + : asm/make_ppc32_sysv_xcoff_gas.S + asm/jump_ppc32_sysv_xcoff_gas.S + asm/ontop_ppc32_sysv_xcoff_gas.S + : sysv + 32 + power + xcoff + clang + ; + +alias asm_sources + : asm/make_ppc32_sysv_xcoff_gas.S + asm/jump_ppc32_sysv_xcoff_gas.S + asm/ontop_ppc32_sysv_xcoff_gas.S + : sysv + 32 + power + xcoff + gcc + ; + +# POWERPC_64 +# POWERPC_64/SYSV/ELF +alias asm_sources + : asm/make_ppc64_sysv_elf_gas.S + asm/jump_ppc64_sysv_elf_gas.S + asm/ontop_ppc64_sysv_elf_gas.S + : sysv + 64 + power + elf + clang + ; + +alias asm_sources + : asm/make_ppc64_sysv_elf_gas.S + asm/jump_ppc64_sysv_elf_gas.S + asm/ontop_ppc64_sysv_elf_gas.S + : sysv + 64 + power + elf + gcc + ; + +# POWERPC_64/SYSV/MACH-O +alias asm_sources + : asm/make_ppc64_sysv_macho_gas.S + asm/jump_ppc64_sysv_macho_gas.S + asm/ontop_ppc64_sysv_macho_gas.S + untested.cpp + : sysv + 64 + power + mach-o + clang + ; + +alias asm_sources + : asm/make_ppc64_sysv_macho_gas.S + asm/jump_ppc64_sysv_macho_gas.S + asm/ontop_ppc64_sysv_macho_gas.S + untested.cpp + : sysv + 64 + power + mach-o + gcc + ; + +alias asm_sources + : asm/make_ppc64_sysv_macho_gas.S + asm/jump_ppc64_sysv_macho_gas.S + asm/ontop_ppc64_sysv_macho_gas.S + untested.cpp + : sysv + 64 + power + mach-o + darwin + ; + +# POWERPC_64/SYSV/XCOFF +alias asm_sources + : asm/make_ppc64_sysv_xcoff_gas.S + asm/jump_ppc64_sysv_xcoff_gas.S + asm/ontop_ppc64_sysv_xcoff_gas.S + : sysv + 64 + power + xcoff + clang + ; + +alias asm_sources + : asm/make_ppc64_sysv_xcoff_gas.S + asm/jump_ppc64_sysv_xcoff_gas.S + asm/ontop_ppc64_sysv_xcoff_gas.S + : sysv + 64 + power + xcoff + gcc + ; + +# POWERPC universal +# POWERPC_32_64/SYSV/MACH-O +alias asm_sources + : asm/make_ppc32_ppc64_sysv_macho_gas.S + asm/jump_ppc32_ppc64_sysv_macho_gas.S + asm/ontop_ppc32_ppc64_sysv_macho_gas.S + : sysv + 32_64 + power + mach-o + ; + +# RISCV64 +# RISCV64/SYSV/ELF +alias asm_sources + : asm/make_riscv64_sysv_elf_gas.S + asm/jump_riscv64_sysv_elf_gas.S + asm/ontop_riscv64_sysv_elf_gas.S + : sysv + 64 + riscv + elf + clang + ; + +alias asm_sources + : asm/make_riscv64_sysv_elf_gas.S + asm/jump_riscv64_sysv_elf_gas.S + asm/ontop_riscv64_sysv_elf_gas.S + : sysv + 64 + riscv + elf + gcc + ; + +# S390X +# S390X/SYSV/ELF +alias asm_sources + : asm/make_s390x_sysv_elf_gas.S + asm/jump_s390x_sysv_elf_gas.S + asm/ontop_s390x_sysv_elf_gas.S + : sysv + 64 + s390x + elf + gcc + ; + +alias asm_sources + : asm/make_s390x_sysv_elf_gas.S + asm/jump_s390x_sysv_elf_gas.S + asm/ontop_s390x_sysv_elf_gas.S + : sysv + 64 + s390x + elf + clang + ; + +# X86 +# X86/SYSV/ELF +alias asm_sources + : asm/make_i386_sysv_elf_gas.S + asm/jump_i386_sysv_elf_gas.S + asm/ontop_i386_sysv_elf_gas.S + : sysv + 32 + x86 + elf + clang + ; + +alias asm_sources + : asm/make_i386_sysv_elf_gas.S + asm/jump_i386_sysv_elf_gas.S + asm/ontop_i386_sysv_elf_gas.S + : sysv + 32 + x86 + elf + gcc + ; + +alias asm_sources + : asm/make_i386_sysv_elf_gas.S + asm/jump_i386_sysv_elf_gas.S + asm/ontop_i386_sysv_elf_gas.S + : sysv + 32 + x86 + elf + intel + ; + +# X86/SYSV/MACH-O +alias asm_sources + : asm/make_i386_sysv_macho_gas.S + asm/jump_i386_sysv_macho_gas.S + asm/ontop_i386_sysv_macho_gas.S + : sysv + 32 + x86 + mach-o + clang + ; + +alias asm_sources + : asm/make_i386_sysv_macho_gas.S + asm/jump_i386_sysv_macho_gas.S + asm/ontop_i386_sysv_macho_gas.S + : sysv + 32 + x86 + mach-o + darwin + ; + +# X86/MS/PE +alias asm_sources + : asm/make_i386_ms_pe_gas.asm + asm/jump_i386_ms_pe_gas.asm + asm/ontop_i386_ms_pe_gas.asm + dummy.cpp + : ms + 32 + x86 + pe + clang + ; + +alias asm_sources + : asm/make_i386_ms_pe_masm.asm + asm/jump_i386_ms_pe_masm.asm + asm/ontop_i386_ms_pe_masm.asm + dummy.cpp + : ms + 32 + x86 + pe + clang-win + ; + +alias asm_sources + : asm/make_i386_ms_pe_gas.asm + asm/jump_i386_ms_pe_gas.asm + asm/ontop_i386_ms_pe_gas.asm + dummy.cpp + : ms + 32 + x86 + pe + gcc + ; + +alias asm_sources + : asm/make_i386_ms_pe_masm.asm + asm/jump_i386_ms_pe_masm.asm + asm/ontop_i386_ms_pe_masm.asm + dummy.cpp + : ms + 32 + x86 + pe + intel + ; + +alias asm_sources + : asm/make_i386_ms_pe_masm.asm + asm/jump_i386_ms_pe_masm.asm + asm/ontop_i386_ms_pe_masm.asm + dummy.cpp + : ms + 32 + x86 + pe + msvc + ; + +# Embarcadero on Windows for 32-bits, bcc32x, uses tasm32, +# which is masm compatible +# This is configured in the embarcadero toolset as using +# 'tasm32 /ml' + +alias asm_sources + : asm/make_i386_ms_pe_masm.asm + asm/jump_i386_ms_pe_masm.asm + asm/ontop_i386_ms_pe_masm.asm + dummy.cpp + : ms + 32 + x86 + pe + embarcadero + ; + +# Borland on Windows for 32-bits, bcc32c, uses tasm32, +# which is masm compatible +# This is configured in the borland toolset as using +# 'tasm32 /ml' + +alias asm_sources + : asm/make_i386_ms_pe_masm.asm + asm/jump_i386_ms_pe_masm.asm + asm/ontop_i386_ms_pe_masm.asm + dummy.cpp + : ms + 32 + x86 + pe + borland + ; + +# X86_64 +# X86_64/SYSV/ELF +alias asm_sources + : asm/make_x86_64_sysv_elf_gas.S + asm/jump_x86_64_sysv_elf_gas.S + asm/ontop_x86_64_sysv_elf_gas.S + : sysv + 64 + x86 + elf + clang + ; + +alias asm_sources + : asm/make_x86_64_sysv_elf_gas.S + asm/jump_x86_64_sysv_elf_gas.S + asm/ontop_x86_64_sysv_elf_gas.S + : sysv + 64 + x86 + elf + gcc + ; + +alias asm_sources + : asm/make_x86_64_sysv_elf_gas.S + asm/jump_x86_64_sysv_elf_gas.S + asm/ontop_x86_64_sysv_elf_gas.S + : sysv + 64 + x86 + elf + intel + ; + +# X86_64/SYSV/MACH-O +alias asm_sources + : asm/make_x86_64_sysv_macho_gas.S + asm/jump_x86_64_sysv_macho_gas.S + asm/ontop_x86_64_sysv_macho_gas.S + : sysv + 64 + x86 + mach-o + clang + ; + +alias asm_sources + : asm/make_x86_64_sysv_macho_gas.S + asm/jump_x86_64_sysv_macho_gas.S + asm/ontop_x86_64_sysv_macho_gas.S + : sysv + 64 + x86 + mach-o + gcc + ; + +alias asm_sources + : asm/make_x86_64_sysv_macho_gas.S + asm/jump_x86_64_sysv_macho_gas.S + asm/ontop_x86_64_sysv_macho_gas.S + : sysv + 64 + x86 + mach-o + darwin + ; + +alias asm_sources + : asm/make_x86_64_sysv_macho_gas.S + asm/jump_x86_64_sysv_macho_gas.S + asm/ontop_x86_64_sysv_macho_gas.S + : sysv + 64 + x86 + mach-o + intel + ; + +# X86_64/MS/PE +alias asm_sources + : asm/make_x86_64_ms_pe_gas.asm + asm/jump_x86_64_ms_pe_gas.asm + asm/ontop_x86_64_ms_pe_gas.asm + dummy.cpp + : ms + 64 + x86 + pe + clang + ; + +alias asm_sources + : asm/make_x86_64_ms_pe_masm.asm + asm/jump_x86_64_ms_pe_masm.asm + asm/ontop_x86_64_ms_pe_masm.asm + dummy.cpp + : ms + 64 + x86 + pe + clang-win + ; + +alias asm_sources + : asm/make_x86_64_ms_pe_gas.asm + asm/jump_x86_64_ms_pe_gas.asm + asm/ontop_x86_64_ms_pe_gas.asm + dummy.cpp + : ms + 64 + x86 + pe + gcc + ; + +alias asm_sources + : asm/make_x86_64_ms_pe_masm.asm + asm/jump_x86_64_ms_pe_masm.asm + asm/ontop_x86_64_ms_pe_masm.asm + dummy.cpp + : ms + 64 + x86 + pe + intel + ; + +alias asm_sources + : asm/make_x86_64_ms_pe_masm.asm + asm/jump_x86_64_ms_pe_masm.asm + asm/ontop_x86_64_ms_pe_masm.asm + dummy.cpp + : ms + 64 + x86 + pe + msvc + ; + +# Embarcadero on Windows, bcc64, uses the sysv-elf format for 64-bits +# This is configured in the embarcadero toolset as using bcc64 with the +# command line option '-x assembler-with-cpp'. + +alias asm_sources + : asm/make_x86_64_sysv_elf_gas.S + asm/jump_x86_64_sysv_elf_gas.S + asm/ontop_x86_64_sysv_elf_gas.S + : ms + 64 + x86 + pe + embarcadero + ; + +# X86_64/SYSV/X32 +alias asm_sources + : asm/make_x86_64_sysv_elf_gas.S + asm/jump_x86_64_sysv_elf_gas.S + asm/ontop_x86_64_sysv_elf_gas.S + : x32 + 32 + x86 + elf + clang + ; + +alias asm_sources + : asm/make_x86_64_sysv_elf_gas.S + asm/jump_x86_64_sysv_elf_gas.S + asm/ontop_x86_64_sysv_elf_gas.S + : x32 + 32 + x86 + elf + gcc + ; + +alias asm_sources + : asm/make_x86_64_sysv_elf_gas.S + asm/jump_x86_64_sysv_elf_gas.S + asm/ontop_x86_64_sysv_elf_gas.S + : x32 + 32 + x86 + elf + intel + ; + +#X86 universal +alias asm_sources + : asm/make_i386_x86_64_sysv_macho_gas.S + asm/jump_i386_x86_64_sysv_macho_gas.S + asm/ontop_i386_x86_64_sysv_macho_gas.S + : sysv + 32_64 + x86 + mach-o + ; + +# COMBINED +alias asm_sources + : asm/make_combined_sysv_macho_gas.S + asm/jump_combined_sysv_macho_gas.S + asm/ontop_combined_sysv_macho_gas.S + : sysv + arm+x86 + mach-o + ; + +explicit asm_sources ; + + # fcontext_t alias impl_sources - : asm/make.S - asm/jump.S - asm/ontop.S - asm/tail_ontop_ppc32_sysv.cpp + : asm_sources : fcontext ; diff --git a/build/architecture.jam b/build/architecture.jam new file mode 100644 index 00000000..d1dd356b --- /dev/null +++ b/build/architecture.jam @@ -0,0 +1,96 @@ +# architecture.jam +# +# Copyright 2012 Steven Watanabe +# +# Distributed under the Boost Software License Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import configure ; +import project ; +import path ; +import property ; + +local here = [ modules.binding $(__name__) ] ; + +project.push-current [ project.current ] ; +project.load [ path.join [ path.make $(here:D) ] ../config ] ; +project.pop-current ; + +rule deduce-address-model ( properties * ) +{ + local result = [ property.select : $(properties) ] ; + if $(result) + { + return $(result) ; + } + else + { + if [ configure.builds /boost/architecture//32 : $(properties) : 32-bit ] + { + return 32 ; + } + else if [ configure.builds /boost/architecture//64 : $(properties) : 64-bit ] + { + return 64 ; + } + } +} + +rule address-model ( ) +{ + return @architecture.deduce-address-model ; +} + +rule deduce-architecture ( properties * ) +{ + local result = [ property.select : $(properties) ] ; + if $(result) + { + return $(result) ; + } + else + { + if [ configure.builds /boost/architecture//arm : $(properties) : arm ] + { + return arm ; + } + else if [ configure.builds /boost/architecture//loongarch : $(properties) : loongarch ] + { + return loongarch ; + } + else if [ configure.builds /boost/architecture//mips : $(properties) : mips ] + { + return mips ; + } + else if [ configure.builds /boost/architecture//power : $(properties) : power ] + { + return power ; + } + else if [ configure.builds /boost/architecture//riscv : $(properties) : riscv ] + { + return riscv ; + } + else if [ configure.builds /boost/architecture//s390x : $(properties) : s390x ] + { + return s390x ; + } + else if [ configure.builds /boost/architecture//sparc : $(properties) : sparc ] + { + return sparc ; + } + else if [ configure.builds /boost/architecture//x86 : $(properties) : x86 ] + { + return x86 ; + } + else if [ configure.builds /boost/architecture//arm+x86 : $(properties) : arm+x86 ] + { + return arm+x86 ; + } + } +} + +rule architecture ( ) +{ + return @architecture.deduce-architecture ; +} diff --git a/example/callcc/Jamfile.v2 b/example/callcc/Jamfile.v2 index acfbaa3d..ba792c89 100644 --- a/example/callcc/Jamfile.v2 +++ b/example/callcc/Jamfile.v2 @@ -13,6 +13,7 @@ import indirect ; import modules ; import os ; import toolset ; +import architecture ; project boost/context/example/callcc : requirements diff --git a/example/fiber/Jamfile.v2 b/example/fiber/Jamfile.v2 index 08a9146a..bf3c1bd2 100644 --- a/example/fiber/Jamfile.v2 +++ b/example/fiber/Jamfile.v2 @@ -13,6 +13,7 @@ import indirect ; import modules ; import os ; import toolset ; +import architecture ; project boost/context/example/fiber : requirements diff --git a/src/asm/common.h b/src/asm/common.h deleted file mode 100644 index 7a633004..00000000 --- a/src/asm/common.h +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright Nikita Kniazev 2023. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include - -// Predef bug https://github.com/boostorg/predef/issues/127 -#if defined(BOOST_ARCH_MIPS_AVAILABLE) && !defined(__mips64) -# undef BOOST_ARCH_WORD_BITS -# define BOOST_ARCH_WORD_BITS 32 -#endif - -#if defined(BOOST_CONTEXT_ARCH) -// Defined by user -#elif defined(BOOST_ARCH_X86_64_AVAILABLE) -# define BOOST_CONTEXT_ARCH x86_64 -#elif defined(BOOST_ARCH_X86_32_AVAILABLE) -# undef i386 -# define BOOST_CONTEXT_ARCH i386 -#elif defined(BOOST_ARCH_ARM_AVAILABLE) && BOOST_ARCH_WORD_BITS == 64 -# define BOOST_CONTEXT_ARCH arm64 -#elif defined(BOOST_ARCH_ARM_AVAILABLE) && BOOST_ARCH_WORD_BITS == 32 -# define BOOST_CONTEXT_ARCH arm -#elif defined(BOOST_ARCH_MIPS_AVAILABLE) && BOOST_ARCH_WORD_BITS == 64 -# define BOOST_CONTEXT_ARCH mips64 -#elif defined(BOOST_ARCH_MIPS_AVAILABLE) && BOOST_ARCH_WORD_BITS == 32 -# define BOOST_CONTEXT_ARCH mips32 -#elif defined(BOOST_ARCH_PPC_64_AVAILABLE) -# define BOOST_CONTEXT_ARCH ppc64 -#elif defined(BOOST_ARCH_PPC_AVAILABLE) -# define BOOST_CONTEXT_ARCH ppc32 -#elif defined(BOOST_ARCH_RISCV_AVAILABLE) -# define BOOST_CONTEXT_ARCH riscv64 -#elif defined(BOOST_ARCH_SYS390_AVAILABLE) -# define BOOST_CONTEXT_ARCH s390x -#elif defined(BOOST_ARCH_LOONGARCH_AVAILABLE) -# define BOOST_CONTEXT_ARCH loongarch64 -#else -# error "Unsupported architecture" -#endif - -#if defined(BOOST_CONTEXT_ABI) -// Defined by user -#elif defined(BOOST_ARCH_ARM_AVAILABLE) -# define BOOST_CONTEXT_ABI aapcs -#elif defined(BOOST_ARCH_MIPS_AVAILABLE) && BOOST_ARCH_WORD_BITS == 64 -# define BOOST_CONTEXT_ABI n64 -#elif defined(BOOST_ARCH_MIPS_AVAILABLE) && BOOST_ARCH_WORD_BITS == 32 -# define BOOST_CONTEXT_ABI o32 -#elif defined(BOOST_OS_WINDOWS_AVAILABLE) -# define BOOST_CONTEXT_ABI ms -#else -# define BOOST_CONTEXT_ABI sysv -#endif - -#if defined(BOOST_CONTEXT_BINFMT) -// Defined by user -#elif defined(BOOST_OS_WINDOWS_AVAILABLE) -# define BOOST_CONTEXT_BINFMT pe -#elif defined(BOOST_OS_AIX_AVAILABLE) -# define BOOST_CONTEXT_BINFMT xcoff -#elif defined(BOOST_OS_MACOS_AVAILABLE) -# define BOOST_CONTEXT_BINFMT macho -#else -# define BOOST_CONTEXT_BINFMT elf -#endif - -#if defined(BOOST_CONTEXT_ASSEMBLER) -// Defined by user -#elif defined(__GNUC__) -# define BOOST_CONTEXT_ASSEMBLER gas.S -#elif defined(BOOST_ARCH_ARM_AVAILABLE) -# define BOOST_CONTEXT_ASSEMBLER armasm.asm -#elif defined(BOOST_OS_WINDOWS_AVAILABLE) -# define BOOST_CONTEXT_ASSEMBLER masm.asm -#else -# define BOOST_CONTEXT_ASSEMBLER gas.S -#endif - -#include - -#define BOOST_CONTEXT_ASM_INCLUDE(name) \ - BOOST_STRINGIZE(BOOST_JOIN(BOOST_JOIN(BOOST_JOIN(BOOST_JOIN(BOOST_JOIN(BOOST_JOIN(BOOST_JOIN(BOOST_JOIN( \ - name, _), BOOST_CONTEXT_ARCH), _), BOOST_CONTEXT_ABI), _), BOOST_CONTEXT_BINFMT), _), BOOST_CONTEXT_ASSEMBLER)) - diff --git a/src/asm/jump.S b/src/asm/jump.S deleted file mode 100644 index 50d52d69..00000000 --- a/src/asm/jump.S +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright Nikita Kniazev 2023. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include "common.h" -#include BOOST_CONTEXT_ASM_INCLUDE(jump) diff --git a/src/asm/jump_i386_ms_pe_gas.S b/src/asm/jump_i386_ms_pe_gas.asm similarity index 100% rename from src/asm/jump_i386_ms_pe_gas.S rename to src/asm/jump_i386_ms_pe_gas.asm diff --git a/src/asm/jump_x86_64_ms_pe_gas.S b/src/asm/jump_x86_64_ms_pe_gas.asm similarity index 100% rename from src/asm/jump_x86_64_ms_pe_gas.S rename to src/asm/jump_x86_64_ms_pe_gas.asm diff --git a/src/asm/make.S b/src/asm/make.S deleted file mode 100644 index b4376c4e..00000000 --- a/src/asm/make.S +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright Nikita Kniazev 2023. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include "common.h" -#include BOOST_CONTEXT_ASM_INCLUDE(make) diff --git a/src/asm/make_i386_ms_pe_gas.S b/src/asm/make_i386_ms_pe_gas.asm similarity index 100% rename from src/asm/make_i386_ms_pe_gas.S rename to src/asm/make_i386_ms_pe_gas.asm diff --git a/src/asm/make_x86_64_ms_pe_gas.S b/src/asm/make_x86_64_ms_pe_gas.asm similarity index 100% rename from src/asm/make_x86_64_ms_pe_gas.S rename to src/asm/make_x86_64_ms_pe_gas.asm diff --git a/src/asm/ontop.S b/src/asm/ontop.S deleted file mode 100644 index d03e312a..00000000 --- a/src/asm/ontop.S +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright Nikita Kniazev 2023. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include "common.h" -#include BOOST_CONTEXT_ASM_INCLUDE(ontop) diff --git a/src/asm/ontop_i386_ms_pe_gas.S b/src/asm/ontop_i386_ms_pe_gas.asm similarity index 100% rename from src/asm/ontop_i386_ms_pe_gas.S rename to src/asm/ontop_i386_ms_pe_gas.asm diff --git a/src/asm/ontop_x86_64_ms_pe_gas.S b/src/asm/ontop_x86_64_ms_pe_gas.asm similarity index 100% rename from src/asm/ontop_x86_64_ms_pe_gas.S rename to src/asm/ontop_x86_64_ms_pe_gas.asm diff --git a/src/dummy.cpp b/src/dummy.cpp new file mode 100644 index 00000000..e69de29b From e878e8edb268a8ffe5cdaa1f1abc6705eb6d1680 Mon Sep 17 00:00:00 2001 From: Liryna Date: Wed, 19 Jun 2024 02:09:25 +0000 Subject: [PATCH 3/3] Convert ARM64 armasm to armclang for Windows clang --- build/Jamfile.v2 | 12 ++ src/asm/jump_arm64_aapcs_pe_armclang.S | 141 ++++++++++++++++++++++++ src/asm/make_arm64_aapcs_pe_armclang.S | 118 ++++++++++++++++++++ src/asm/ontop_arm64_aapcs_pe_armclang.S | 140 +++++++++++++++++++++++ 4 files changed, 411 insertions(+) create mode 100644 src/asm/jump_arm64_aapcs_pe_armclang.S create mode 100644 src/asm/make_arm64_aapcs_pe_armclang.S create mode 100644 src/asm/ontop_arm64_aapcs_pe_armclang.S diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index 5e7690d2..a732a32b 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -253,6 +253,18 @@ alias asm_sources msvc ; +# ARM64/AAPCS/PE +alias asm_sources + : asm/make_arm64_aapcs_pe_armclang.asm + asm/jump_arm64_aapcs_pe_armclang.asm + asm/ontop_arm64_aapcs_pe_armclang.asm + : aapcs + 64 + arm + pe + clang + ; + # LOONGARCH64 # LOONGARCH64/SYSV/ELF alias asm_sources diff --git a/src/asm/jump_arm64_aapcs_pe_armclang.S b/src/asm/jump_arm64_aapcs_pe_armclang.S new file mode 100644 index 00000000..0ad7ac1f --- /dev/null +++ b/src/asm/jump_arm64_aapcs_pe_armclang.S @@ -0,0 +1,141 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/****************************************************** +* * +* ------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* ------------------------------------------------- * +* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * +* ------------------------------------------------- * +* | d8 | d9 | d10 | d11 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* ------------------------------------------------- * +* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * +* ------------------------------------------------- * +* | d12 | d13 | d14 | d15 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +* ------------------------------------------------- * +* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * +* ------------------------------------------------- * +* | x19 | x20 | x21 | x22 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +* ------------------------------------------------- * +* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * +* ------------------------------------------------- * +* | x23 | x24 | x25 | x26 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * +* ------------------------------------------------- * +* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * +* ------------------------------------------------- * +* | x27 | x28 | FP | LR | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * +* ------------------------------------------------- * +* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * +* ------------------------------------------------- * +* | fiber data| base | limit | dealloc | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 48 | 49 | 50 | 51 | | | * +* ------------------------------------------------- * +* | 0xc0| 0xc4| 0xc8| 0xcc| | | * +* ------------------------------------------------- * +* | PC | align | | | * +* ------------------------------------------------- * +* * +*******************************************************/ + +.file "jump_arm64_aapcs_pe_armclang.S" +.text +.balign 4 + +.def jump_fcontext; .scl 2; .type 32; .endef +.seh_proc jump_fcontext +jump_fcontext: +.seh_endprologue + // prepare stack for GP + FPU + sub sp, sp, #0xd0 + + // save d8 - d15 + stp d8, d9, [sp, #0x00] + stp d10, d11, [sp, #0x10] + stp d12, d13, [sp, #0x20] + stp d14, d15, [sp, #0x30] + + // save x19-x30 + stp x19, x20, [sp, #0x40] + stp x21, x22, [sp, #0x50] + stp x23, x24, [sp, #0x60] + stp x25, x26, [sp, #0x70] + stp x27, x28, [sp, #0x80] + stp x29, x30, [sp, #0x90] + + // save LR as PC + str x30, [sp, #0xc0] + + // save current stack base and limit + ldp x5, x6, [x18, #0x08] // TeStackBase and TeStackLimit at ksarm64.h + stp x5, x6, [sp, #0xa0] + // save current fiber data and deallocation stack + ldr x5, [x18, #0x1478] // TeDeallocationStack at ksarm64.h + ldr x6, [x18, #0x20] // TeFiberData at ksarm64.h + stp x5, x6, [sp, #0xb0] + + // store RSP (pointing to context-data) in X0 + mov x4, sp + + // restore RSP (pointing to context-data) from X1 + mov sp, x0 + + // restore stack base and limit + ldp x5, x6, [sp, #0xa0] + stp x5, x6, [x18, #0x08] // TeStackBase and TeStackLimit at ksarm64.h + // restore fiber data and deallocation stack + ldp x5, x6, [sp, #0xb0] + str x5, [x18, #0x1478] // TeDeallocationStack at ksarm64.h + str x6, [x18, #0x20] // TeFiberData at ksarm64.h + + // load d8 - d15 + ldp d8, d9, [sp, #0x00] + ldp d10, d11, [sp, #0x10] + ldp d12, d13, [sp, #0x20] + ldp d14, d15, [sp, #0x30] + + // load x19-x30 + ldp x19, x20, [sp, #0x40] + ldp x21, x22, [sp, #0x50] + ldp x23, x24, [sp, #0x60] + ldp x25, x26, [sp, #0x70] + ldp x27, x28, [sp, #0x80] + ldp x29, x30, [sp, #0x90] + + // return transfer_t from jump + // pass transfer_t as first arg in context function + // X0 == FCTX, X1 == DATA + mov x0, x4 + + // load pc + ldr x4, [sp, #0xc0] + + // restore stack from GP + FPU + add sp, sp, #0xd0 + + ret x4 +.seh_endproc + +.section .drectve +.ascii " -export:\"jump_fcontext\"" diff --git a/src/asm/make_arm64_aapcs_pe_armclang.S b/src/asm/make_arm64_aapcs_pe_armclang.S new file mode 100644 index 00000000..cab00e92 --- /dev/null +++ b/src/asm/make_arm64_aapcs_pe_armclang.S @@ -0,0 +1,118 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/****************************************************** +* * +* ------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* ------------------------------------------------- * +* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * +* ------------------------------------------------- * +* | d8 | d9 | d10 | d11 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* ------------------------------------------------- * +* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * +* ------------------------------------------------- * +* | d12 | d13 | d14 | d15 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +* ------------------------------------------------- * +* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * +* ------------------------------------------------- * +* | x19 | x20 | x21 | x22 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +* ------------------------------------------------- * +* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * +* ------------------------------------------------- * +* | x23 | x24 | x25 | x26 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * +* ------------------------------------------------- * +* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * +* ------------------------------------------------- * +* | x27 | x28 | FP | LR | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * +* ------------------------------------------------- * +* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * +* ------------------------------------------------- * +* | base | limit | dealloc | fiber data| * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 48 | 49 | 50 | 51 | | | * +* ------------------------------------------------- * +* | 0xc0| 0xc4| 0xc8| 0xcc| | | * +* ------------------------------------------------- * +* | PC | align | | | * +* ------------------------------------------------- * +* * +*******************************************************/ + +.file "make_arm64_aapcs_pe_armclang.S" +.text +.balign 4 + +.globl make_fcontext +.def make_fcontext; .scl 2; .type 32; .endef +.seh_proc make_fcontext +make_fcontext: +.seh_endprologue + // save stack top address to x3 + mov x3, x0 + + // shift address in x0 (allocated stack) to lower 16 byte boundary + and x0, x0, ~0xF + + // reserve space for context-data on context-stack + sub x0, x0, #0xd0 + + // save top address of context_stack as 'base' + str x3, [x0, #0xa0] + // save bottom address of context-stack as 'limit' and 'dealloction stack' + sub x3, x3, x1 + stp x3, x3, [x0, #0xa8] + // save 0 as 'fiber data' + str xzr, [x0, #0xb8] + + // third arg of make_fcontext() == address of context-function + // store address as x19 for trampoline + str x2, [x0, #0x40] + // store trampoline address as pc + adr x2, trampoline + str x2, [x0, #0xc0] + + // save address of finish as return-address for context-function + // will be entered after context-function returns (LR register) + adr x1, finish + str x1, [x0, #0x98] + + ret x30 // return pointer to context-data (x0) + +trampoline: + stp fp, lr, [sp, #-0x10]! + mov fp, sp + blr x19 + +finish: + // exit code is zero + mov x0, #0 + // exit application + bl _exit + +.seh_endproc + +.def _exit; .scl 2; .type 32; .endef /* standard C library function */ + +.section .drectve +.ascii " -export:\"make_fcontext\"" diff --git a/src/asm/ontop_arm64_aapcs_pe_armclang.S b/src/asm/ontop_arm64_aapcs_pe_armclang.S new file mode 100644 index 00000000..bdf097b7 --- /dev/null +++ b/src/asm/ontop_arm64_aapcs_pe_armclang.S @@ -0,0 +1,140 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/****************************************************** +* * +* ------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* ------------------------------------------------- * +* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * +* ------------------------------------------------- * +* | d8 | d9 | d10 | d11 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* ------------------------------------------------- * +* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * +* ------------------------------------------------- * +* | d12 | d13 | d14 | d15 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +* ------------------------------------------------- * +* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * +* ------------------------------------------------- * +* | x19 | x20 | x21 | x22 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +* ------------------------------------------------- * +* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * +* ------------------------------------------------- * +* | x23 | x24 | x25 | x26 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * +* ------------------------------------------------- * +* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * +* ------------------------------------------------- * +* | x27 | x28 | FP | LR | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * +* ------------------------------------------------- * +* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * +* ------------------------------------------------- * +* | fiber data| base | limit | dealloc | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 48 | 49 | 50 | 51 | | | * +* ------------------------------------------------- * +* | 0xc0| 0xc4| 0xc8| 0xcc| | | * +* ------------------------------------------------- * +* | PC | align | | | * +* ------------------------------------------------- * +* * +*******************************************************/ + +.file "ontop_arm64_aapcs_pe_armclang.S" +.text +.balign 4 + +.def ontop_fcontext; .scl 2; .type 32; .endef +.seh_proc ontop_fcontext +ontop_fcontext: +.seh_endprologue + // prepare stack for GP + FPU + sub sp, sp, #0xd0 + + // save d8 - d15 + stp d8, d9, [sp, #0x00] + stp d10, d11, [sp, #0x10] + stp d12, d13, [sp, #0x20] + stp d14, d15, [sp, #0x30] + + // save x19-x30 + stp x19, x20, [sp, #0x40] + stp x21, x22, [sp, #0x50] + stp x23, x24, [sp, #0x60] + stp x25, x26, [sp, #0x70] + stp x27, x28, [sp, #0x80] + stp x29, x30, [sp, #0x90] + + // save LR as PC + str x30, [sp, #0xc0] + + // save current stack base and limit + ldp x5, x6, [x18, #0x08] // TeStackBase and TeStackLimit at ksarm64.h + stp x5, x6, [sp, #0xa0] + // save current fiber data and deallocation stack + ldr x5, [x18, #0x1478] // TeDeallocationStack at ksarm64.h + ldr x6, [x18, #0x20] // TeFiberData at ksarm64.h + stp x5, x6, [sp, #0xb0] + + // store RSP (pointing to context-data) in X5 + mov x4, sp + + // restore RSP (pointing to context-data) from X1 + mov sp, x0 + + // restore stack base and limit + ldp x5, x6, [sp, #0xa0] + stp x5, x6, [x18, #0x08] // TeStackBase and TeStackLimit at ksarm64.h + // restore fiber data and deallocation stack + ldp x5, x6, [sp, #0xb0] + str x5, [x18, #0x1478] // TeDeallocationStack at ksarm64.h + str x6, [x18, #0x20] // TeFiberData at ksarm64.h + + // load d8 - d15 + ldp d8, d9, [sp, #0x00] + ldp d10, d11, [sp, #0x10] + ldp d12, d13, [sp, #0x20] + ldp d14, d15, [sp, #0x30] + + // load x19-x30 + ldp x19, x20, [sp, #0x40] + ldp x21, x22, [sp, #0x50] + ldp x23, x24, [sp, #0x60] + ldp x25, x26, [sp, #0x70] + ldp x27, x28, [sp, #0x80] + ldp x29, x30, [sp, #0x90] + + // return transfer_t from jump + // pass transfer_t as first arg in context function + // X0 == FCTX, X1 == DATA + mov x0, x4 + + // skip pc + // restore stack from GP + FPU + add sp, sp, #0xc0 + + // jump to ontop-function + ret x2 +.seh_endproc + +.section .drectve +.ascii " -export:\"ontop_fcontext\""