From 70cc97c00009f0eed6b2e1b2aa29cd48220fd16e Mon Sep 17 00:00:00 2001 From: Wenlong Zhang Date: Thu, 12 Jan 2023 15:12:37 +0800 Subject: [PATCH] update the patch for loongarch fix build error: No best alternative for libs/context/build/asm_sources --- ...oost-context-support-for-loongarch64.patch | 745 +++++++++++------- boost.spec | 6 +- 2 files changed, 476 insertions(+), 275 deletions(-) diff --git a/boost-1.78-add-boost-context-support-for-loongarch64.patch b/boost-1.78-add-boost-context-support-for-loongarch64.patch index bd92493..dbb47b8 100644 --- a/boost-1.78-add-boost-context-support-for-loongarch64.patch +++ b/boost-1.78-add-boost-context-support-for-loongarch64.patch @@ -1,100 +1,312 @@ -From 0c117efe905a79d82f5ec638dec6f315d9e3f41c Mon Sep 17 00:00:00 2001 +From 217e51b9101fb4779c8dc00a562f77c0c9a70afe Mon Sep 17 00:00:00 2001 From: Wenlong Zhang -Date: Tue, 10 Jan 2023 20:54:06 +0800 -Subject: [PATCH] add boost context support for loongarch64 +Date: Wed, 11 Jan 2023 17:28:18 +0800 +Subject: [PATCH] add boost context support for loongarch64 new --- - boost/predef/other/endian.h | 3 +- - libs/context/build/Jamfile.v2 | 26 ++++ - .../src/asm/jump_loongarch64_lp64_elf_gas.S | 117 ++++++++++++++++++ - .../src/asm/make_loongarch64_lp64_elf_gas.S | 85 +++++++++++++ - .../src/asm/ontop_loongarch64_lp64_elf_gas.S | 117 ++++++++++++++++++ + boost/predef/architecture.h | 1 + + boost/predef/architecture/loongarch.h | 39 ++++++ + boost/predef/other/endian.h | 1 + + boostcpp.jam | 5 +- + libs/config/checks/architecture/Jamfile.jam | 1 + + libs/config/checks/architecture/loongarch.cpp | 11 ++ + libs/context/CMakeLists.txt | 4 +- + libs/context/build/Jamfile.v2 | 13 ++ + libs/context/build/architecture.jam | 4 + + libs/context/doc/architectures.qbk | 1 + + libs/context/doc/context.xml | 27 ++++ + .../doc/html/context/architectures.html | 27 ++++ + .../src/asm/jump_loongarch64_sysv_elf_gas.S | 121 ++++++++++++++++++ + .../src/asm/make_loongarch64_sysv_elf_gas.S | 72 +++++++++++ + .../src/asm/ontop_loongarch64_sysv_elf_gas.S | 118 +++++++++++++++++ tools/build/src/engine/jam.h | 4 + - tools/build/src/tools/builtin.py | 3 + .../tools/features/architecture-feature.jam | 3 + - 8 files changed, 357 insertions(+), 1 deletion(-) - create mode 100644 libs/context/src/asm/jump_loongarch64_lp64_elf_gas.S - create mode 100644 libs/context/src/asm/make_loongarch64_lp64_elf_gas.S - create mode 100644 libs/context/src/asm/ontop_loongarch64_lp64_elf_gas.S + 17 files changed, 448 insertions(+), 4 deletions(-) + create mode 100644 boost/predef/architecture/loongarch.h + create mode 100644 libs/config/checks/architecture/loongarch.cpp + create mode 100644 libs/context/src/asm/jump_loongarch64_sysv_elf_gas.S + create mode 100644 libs/context/src/asm/make_loongarch64_sysv_elf_gas.S + create mode 100644 libs/context/src/asm/ontop_loongarch64_sysv_elf_gas.S +diff --git a/boost/predef/architecture.h b/boost/predef/architecture.h +index 471c263..55d036f 100644 +--- a/boost/predef/architecture.h ++++ b/boost/predef/architecture.h +@@ -17,6 +17,7 @@ http://www.boost.org/LICENSE_1_0.txt) + #include + #include + #include ++#include + #include + #include + #include +diff --git a/boost/predef/architecture/loongarch.h b/boost/predef/architecture/loongarch.h +new file mode 100644 +index 0000000..17015d8 +--- /dev/null ++++ b/boost/predef/architecture/loongarch.h +@@ -0,0 +1,39 @@ ++/* ++Copyright Zhang Na 2022 ++Distributed under the Boost Software License, Version 1.0. ++(See accompanying file LICENSE_1_0.txt or copy at ++http://www.boost.org/LICENSE_1_0.txt) ++*/ ++ ++#ifndef BOOST_PREDEF_ARCHITECTURE_LOONGARCH_H ++#define BOOST_PREDEF_ARCHITECTURE_LOONGARCH_H ++ ++#include ++#include ++ ++/* tag::reference[] ++= `BOOST_ARCH_LOONGARCH` ++[options="header"] ++|=== ++| {predef_symbol} | {predef_version} ++| `+__loongarch__+` | {predef_detection} ++|=== ++*/ // end::reference[] ++ ++#define BOOST_ARCH_LOONGARCH BOOST_VERSION_NUMBER_NOT_AVAILABLE ++ ++#if defined(__loongarch__) ++# undef BOOST_ARCH_LOONGARCH ++# define BOOST_ARCH_LOONGARCH BOOST_VERSION_NUMBER_AVAILABLE ++#endif ++ ++#if BOOST_ARCH_LOONGARCH ++# define BOOST_ARCH_LOONGARCH_AVAILABLE ++#endif ++ ++#define BOOST_ARCH_LOONGARCH_NAME "LoongArch" ++ ++#endif ++ ++#include ++BOOST_PREDEF_DECLARE_TEST(BOOST_ARCH_LOONGARCH,BOOST_ARCH_LOONGARCH_NAME) diff --git a/boost/predef/other/endian.h b/boost/predef/other/endian.h -index d8ec63ff5..4d0630af0 100644 +index d8ec63f..b712673 100644 --- a/boost/predef/other/endian.h +++ b/boost/predef/other/endian.h -@@ -125,7 +125,8 @@ information and acquired knowledge: +@@ -121,6 +121,7 @@ information and acquired knowledge: + defined(__ARMEL__) || \ + defined(__THUMBEL__) || \ + defined(__AARCH64EL__) || \ ++ defined(__loongarch__) || \ + defined(_MIPSEL) || \ defined(__MIPSEL) || \ defined(__MIPSEL__) || \ - defined(__riscv) || \ -- defined(__e2k__) -+ defined(__e2k__) || \ -+ defined(__loongarch64) - # undef BOOST_ENDIAN_LITTLE_BYTE - # define BOOST_ENDIAN_LITTLE_BYTE BOOST_VERSION_NUMBER_AVAILABLE - # endif -diff --git a/libs/context/build/Jamfile.v2 b/libs/context/build/Jamfile.v2 -index 30e959839..68e6981a7 100644 ---- a/libs/context/build/Jamfile.v2 -+++ b/libs/context/build/Jamfile.v2 -@@ -83,6 +83,7 @@ local rule default_abi ( ) - else if [ os.platform ] = "SW_64" { tmp = aapcs ; } - else if [ os.platform ] = "MIPS32" { tmp = o32 ; } - else if [ os.platform ] = "MIPS64" { tmp = n64 ; } -+ else if [ os.platform ] = "LOONGARCH64" { tmp = lp64 ; } - return $(tmp) ; +diff --git a/boostcpp.jam b/boostcpp.jam +index f60e85c..c938b72 100644 +--- a/boostcpp.jam ++++ b/boostcpp.jam +@@ -634,7 +634,7 @@ rule address-model ( ) + return @boostcpp.deduce-address-model ; } -@@ -92,6 +93,7 @@ feature.feature abi - ms - n32 - n64 -+ lp64 - o32 - o64 - sysv -@@ -207,6 +209,30 @@ alias asm_sources - gcc +-local deducable-architectures = sw_64 arm mips1 power riscv s390x sparc x86 combined ; ++local deducable-architectures = sw_64 arm loongarch mips1 power riscv s390x sparc x86 combined ; + feature.feature deduced-architecture : $(deducable-architectures) : propagated optional composite hidden ; + for a in $(deducable-architectures) + { +@@ -645,10 +645,11 @@ rule deduce-architecture ( properties * ) + { + local result ; + local filtered = [ toolset-properties $(properties) ] ; +- local names = arm sw_64 mips1 power riscv s390x sparc x86 combined ; ++ local names = arm sw_64 loongarch mips1 power riscv s390x sparc x86 combined ; + local idx = [ configure.find-builds "default architecture" : $(filtered) + : /boost/architecture//arm + : /boost/architecture//sw_64 ++ : /boost/architecture//loongarch + : /boost/architecture//mips1 + : /boost/architecture//power + : /boost/architecture//riscv +diff --git a/libs/config/checks/architecture/Jamfile.jam b/libs/config/checks/architecture/Jamfile.jam +index f86c732..ee260ff 100644 +--- a/libs/config/checks/architecture/Jamfile.jam ++++ b/libs/config/checks/architecture/Jamfile.jam +@@ -19,6 +19,7 @@ obj 64 : 64.cpp ; + obj arm : arm.cpp ; + obj sw_64 : sw_64.cpp ; + obj combined : combined.cpp ; ++obj loongarch : loongarch.cpp ; + obj mips1 : mips1.cpp ; + obj power : power.cpp ; + obj riscv : riscv.cpp ; +diff --git a/libs/config/checks/architecture/loongarch.cpp b/libs/config/checks/architecture/loongarch.cpp +new file mode 100644 +index 0000000..5be8cb0 +--- /dev/null ++++ b/libs/config/checks/architecture/loongarch.cpp +@@ -0,0 +1,11 @@ ++// loongarch.cpp ++// ++// Copyright (c) 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) ++ ++#if !defined(__loongarch__) ++#error "Not LoongArch" ++#endif +diff --git a/libs/context/CMakeLists.txt b/libs/context/CMakeLists.txt +index 99c11b2..f301143 100644 +--- a/libs/context/CMakeLists.txt ++++ b/libs/context/CMakeLists.txt +@@ -48,7 +48,7 @@ unset(_default_abi) + + ## Arch-and-model + +-set(_all_archs arm arm64 sw_64 mips32 mips64 ppc32 ppc64 riscv64 s390x i386 x86_64 combined) ++set(_all_archs arm arm64 loongarch64 sw_64 mips32 mips64 ppc32 ppc64 riscv64 s390x i386 x86_64 combined) + + # Try at start to auto determine arch from CMake. + if(CMAKE_SYSTEM_PROCESSOR IN_LIST _all_archs) +@@ -74,7 +74,7 @@ else() + endif() + endif() + +-set(BOOST_CONTEXT_ARCHITECTURE "${_default_arch}" CACHE STRING "Boost.Context architecture (arm, arm64, mips32, sw_64, mips64, ppc32, ppc64, riscv64, s390x, i386, x86_64, combined)") ++set(BOOST_CONTEXT_ARCHITECTURE "${_default_arch}" CACHE STRING "Boost.Context architecture (arm, arm64, loongarch64, mips32, sw_64, mips64, ppc32, ppc64, riscv64, s390x, i386, x86_64, combined)") + set_property(CACHE BOOST_CONTEXT_ARCHITECTURE PROPERTY STRINGS ${_all_archs}) + + unset(_all_archs) +diff --git a/libs/context/build/Jamfile.v2 b/libs/context/build/Jamfile.v2 +index 30e9598..6238510 100644 +--- a/libs/context/build/Jamfile.v2 ++++ b/libs/context/build/Jamfile.v2 +@@ -254,6 +254,19 @@ alias asm_sources + darwin ; -+# LOONGARCH -+# LOONGARCH64/LP64/ELF ++# LOONGARCH64 ++# LOONGARCH64/SYSV/ELF +alias asm_sources -+ : asm/make_loongarch64_lp64_elf_gas.S -+ asm/jump_loongarch64_lp64_elf_gas.S -+ asm/ontop_loongarch64_lp64_elf_gas.S -+ : lp64 ++ : asm/make_loongarch64_sysv_elf_gas.S ++ asm/jump_loongarch64_sysv_elf_gas.S ++ asm/ontop_loongarch64_sysv_elf_gas.S ++ : sysv + 64 -+ loongarch64 -+ elf -+ clang -+ ; -+ -+alias asm_sources -+ : asm/make_loongarch64_lp64_elf_gas.S -+ asm/jump_loongarch64_lp64_elf_gas.S -+ asm/ontop_loongarch64_lp64_elf_gas.S -+ : lp64 -+ 64 -+ loongarch64 ++ loongarch + elf + gcc + ; + - # ARM64 - # ARM64/AAPCS/ELF + # MIPS + # MIPS32/O32/ELF alias asm_sources -diff --git a/libs/context/src/asm/jump_loongarch64_lp64_elf_gas.S b/libs/context/src/asm/jump_loongarch64_lp64_elf_gas.S +diff --git a/libs/context/build/architecture.jam b/libs/context/build/architecture.jam +index 4c7d211..78820cd 100644 +--- a/libs/context/build/architecture.jam ++++ b/libs/context/build/architecture.jam +@@ -59,6 +59,10 @@ rule deduce-architecture ( properties * ) + { + return sw_64 ; + } ++ else if [ configure.builds /boost/architecture//loongarch : $(properties) : loongarch ] ++ { ++ return loongarch ; ++ } + else if [ configure.builds /boost/architecture//mips : $(properties) : mips ] + { + return mips ; +diff --git a/libs/context/doc/architectures.qbk b/libs/context/doc/architectures.qbk +index 4be823c..76d6d58 100644 +--- a/libs/context/doc/architectures.qbk ++++ b/libs/context/doc/architectures.qbk +@@ -15,6 +15,7 @@ architectures: + [[arm (aarch32)] [AAPCS|ELF] [AAPCS|PE] [-] [AAPCS|MACH-O]] + [[arm (aarch64)] [AAPCS|ELF] [-] [AAPCS|MACH-O] [AAPCS|MACH-O]] + [[i386] [SYSV|ELF] [MS|PE] [SYSV|MACH-O] [-]] ++ [[loongarch64] [SYSV|ELF] [-] [-] [-]] + [[mips] [O32|N64|ELF] [-] [-] [-]] + [[ppc32] [SYSV|ELF|XCOFF] [-] [SYSV|MACH-O] [-]] + [[ppc64] [SYSV|ELF|XCOFF] [-] [SYSV|MACH-O] [-]] +diff --git a/libs/context/doc/context.xml b/libs/context/doc/context.xml +index d83439d..ef920cd 100644 +--- a/libs/context/doc/context.xml ++++ b/libs/context/doc/context.xml +@@ -3379,6 +3379,33 @@ + + + ++ ++ ++ ++ loongarch64 ++ ++ ++ ++ ++ SYSV|ELF ++ ++ ++ ++ ++ - ++ ++ ++ ++ ++ - ++ ++ ++ ++ ++ - ++ ++ ++ + + + +diff --git a/libs/context/doc/html/context/architectures.html b/libs/context/doc/html/context/architectures.html +index 416627d..29bd803 100644 +--- a/libs/context/doc/html/context/architectures.html ++++ b/libs/context/doc/html/context/architectures.html +@@ -151,6 +151,33 @@ + + + ++ ++

++ loongarch64 ++

++ ++ ++

++ SYSV|ELF ++

++ ++ ++

++ - ++

++ ++ ++

++ - ++

++ ++ ++

++ - ++

++ ++ ++ + +

+ mips +diff --git a/libs/context/src/asm/jump_loongarch64_sysv_elf_gas.S b/libs/context/src/asm/jump_loongarch64_sysv_elf_gas.S new file mode 100644 -index 000000000..a95a9eeb9 +index 0000000..74c081e --- /dev/null -+++ b/libs/context/src/asm/jump_loongarch64_lp64_elf_gas.S -@@ -0,0 +1,117 @@ -+/* -+ Copyright loongson 2018. -+ Distributed under the Boost Software License, Version 1.0. -+ (See accompanying file LICENSE_1_0.txt or copy at -+ http://www.boost.org/LICENSE_1_0.txt) -+*/ -+ ++++ b/libs/context/src/asm/jump_loongarch64_sysv_elf_gas.S +@@ -0,0 +1,121 @@ +/******************************************************* + * * + * ------------------------------------------------- * @@ -102,14 +314,14 @@ index 000000000..a95a9eeb9 + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * -+ * | F24 | F25 | F26 | F27 | * ++ * | FS0 | FS1 | FS2 | FS3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * -+ * | F28 | F29 | F30 | F31 | * ++ * | FS4 | FS5 | FS6 | FS7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * @@ -130,94 +342,98 @@ index 000000000..a95a9eeb9 + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * -+ * | FP | GP | RA | PC | * ++ * | S8 | FP | RA | PC | * + * ------------------------------------------------- * + * * + * *****************************************************/ + -+.file "jump_loongarch64_lp64_elf_gas.S" ++.file "jump_loongarch64_sysv_elf_gas.S" +.text +.globl jump_fcontext -+.align 3 ++.align 2 +.type jump_fcontext,@function +jump_fcontext: -+ # reserve space on stack -+ addi.d $sp, $sp, -160 -+ -+ st.d $s0, $sp, 64 # save S0 -+ st.d $s1, $sp, 72 # save S1 -+ st.d $s2, $sp, 80 # save S2 -+ st.d $s3, $sp, 88 # save S3 -+ st.d $s4, $sp, 96 # save S4 -+ st.d $s5, $sp, 104 # save S5 -+ st.d $s6, $sp, 112 # save S6 -+ st.d $s7, $sp, 120 # save S7 -+ st.d $s8, $sp, 128 # save S8 -+ st.d $fp, $sp, 136 # save FP -+ st.d $ra, $sp, 144 # save RA -+ st.d $ra, $sp, 152 # save RA as PC -+ -+ -+ fst.d $fs0, $sp, 0 # save F24 -+ fst.d $fs1, $sp, 8 # save F25 -+ fst.d $fs2, $sp, 16 # save F26 -+ fst.d $fs3, $sp, 24 # save F27 -+ fst.d $fs4, $sp, 32 # save F28 -+ fst.d $fs5, $sp, 40 # save F29 -+ fst.d $fs6, $sp, 48 # save F30 -+ fst.d $fs7, $sp, 56 # save F31 -+ -+ # swap a0(new stack), sp(old stack) -+ xor $a0, $a0, $sp -+ xor $sp, $a0, $sp -+ xor $a0, $a0, $sp -+ -+ fld.d $fs0, $sp, 0 # restore F24 -+ fld.d $fs1, $sp, 8 # restore F25 -+ fld.d $fs2, $sp, 16 # restore F26 -+ fld.d $fs3, $sp, 24 # restore F27 -+ fld.d $fs4, $sp, 32 # restore F28 -+ fld.d $fs5, $sp, 40 # restore F29 -+ fld.d $fs6, $sp, 48 # restore F30 -+ fld.d $fs7, $sp, 56 # restore F31 -+ -+ ld.d $s0, $sp, 64 # restore S0 -+ ld.d $s1, $sp, 72 # restore S1 -+ ld.d $s2, $sp, 80 # restore S2 -+ ld.d $s3, $sp, 88 # restore S3 -+ ld.d $s4, $sp, 96 # restore S4 -+ ld.d $s5, $sp, 104 # restore S5 -+ ld.d $s6, $sp, 112 # restore S6 -+ ld.d $s7, $sp, 120 # restore S7 -+ ld.d $s8, $sp, 128 # restore S8 -+ ld.d $fp, $sp, 136 # restore FP -+ ld.d $ra, $sp, 144 # restore RA -+ -+ # load PC -+ ld.d $t8, $sp, 152 -+ -+ # adjust stack -+ addi.d $sp, $sp, 160 -+ -+ # jump to context -+ jr $t8 ++ # reserve space on stack ++ addi.d $sp, $sp, -160 ++ ++ # save fs0 - fs7 ++ fst.d $fs0, $sp, 0 ++ fst.d $fs1, $sp, 8 ++ fst.d $fs2, $sp, 16 ++ fst.d $fs3, $sp, 24 ++ fst.d $fs4, $sp, 32 ++ fst.d $fs5, $sp, 40 ++ fst.d $fs6, $sp, 48 ++ fst.d $fs7, $sp, 56 ++ ++ # save s0 - s8, fp, ra ++ st.d $s0, $sp, 64 ++ st.d $s1, $sp, 72 ++ st.d $s2, $sp, 80 ++ st.d $s3, $sp, 88 ++ st.d $s4, $sp, 96 ++ st.d $s5, $sp, 104 ++ st.d $s6, $sp, 112 ++ st.d $s7, $sp, 120 ++ st.d $s8, $sp, 128 ++ st.d $fp, $sp, 136 ++ st.d $ra, $sp, 144 ++ ++ # save RA as PC ++ st.d $ra, $sp, 152 ++ ++ # store SP (pointing to context-data) in A2 ++ move $a2, $sp ++ ++ # restore SP (pointing to context-data) from A0 ++ move $sp, $a0 ++ ++ # load fs0 - fs7 ++ fld.d $fs0, $sp, 0 ++ fld.d $fs1, $sp, 8 ++ fld.d $fs2, $sp, 16 ++ fld.d $fs3, $sp, 24 ++ fld.d $fs4, $sp, 32 ++ fld.d $fs5, $sp, 40 ++ fld.d $fs6, $sp, 48 ++ fld.d $fs7, $sp, 56 ++ ++ #load s0 - s7 ++ ld.d $s0, $sp, 64 ++ ld.d $s1, $sp, 72 ++ ld.d $s2, $sp, 80 ++ ld.d $s3, $sp, 88 ++ ld.d $s4, $sp, 96 ++ ld.d $s5, $sp, 104 ++ ld.d $s6, $sp, 112 ++ ld.d $s7, $sp, 120 ++ ld.d $s8, $sp, 128 ++ ld.d $fp, $sp, 136 ++ ld.d $ra, $sp, 144 ++ ++ # return transfer_t from jump ++ # pass transfer_t as first arg in context function ++ # a0 == FCTX, a1 == DATA ++ move $a0, $a2 ++ ++ # load PC ++ ld.d $a2, $sp, 152 ++ ++ # restore stack ++ addi.d $sp, $sp, 160 ++ ++ # jump to context ++ jr $a2 +.size jump_fcontext, .-jump_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits -diff --git a/libs/context/src/asm/make_loongarch64_lp64_elf_gas.S b/libs/context/src/asm/make_loongarch64_lp64_elf_gas.S +diff --git a/libs/context/src/asm/make_loongarch64_sysv_elf_gas.S b/libs/context/src/asm/make_loongarch64_sysv_elf_gas.S new file mode 100644 -index 000000000..20106bee4 +index 0000000..5506270 --- /dev/null -+++ b/libs/context/src/asm/make_loongarch64_lp64_elf_gas.S -@@ -0,0 +1,85 @@ -+/* -+ Copyright loongson 2018. -+ Distributed under the Boost Software License, Version 1.0. -+ (See accompanying file LICENSE_1_0.txt or copy at -+ http://www.boost.org/LICENSE_1_0.txt) -+*/ -+ ++++ b/libs/context/src/asm/make_loongarch64_sysv_elf_gas.S +@@ -0,0 +1,72 @@ +/******************************************************* + * * + * ------------------------------------------------- * @@ -225,14 +441,14 @@ index 000000000..20106bee4 + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * -+ * | F24 | F25 | F26 | F27 | * ++ * | FS0 | FS1 | FS2 | FS3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * -+ * | F28 | F29 | F30 | F31 | * ++ * | FS4 | FS5 | FS6 | FS7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * @@ -253,62 +469,49 @@ index 000000000..20106bee4 + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * -+ * | FP | GP | RA | PC | * ++ * | S8 | FP | RA | PC | * + * ------------------------------------------------- * + * * + * *****************************************************/ + -+.file "make_loongarch64_lp64_elf_gas.S" ++.file "make_loongarch64_sysv_elf_gas.S" +.text +.globl make_fcontext -+.align 3 ++.align 2 +.type make_fcontext,@function +make_fcontext: -+ # shift address in A0 to lower 16 byte boundary -+ li.w $t0, 0xfffffffffffffff0 -+ and $a0, $a0, $t0 -+ -+ # reserve space for context-data on context-stack -+ addi.d $a0, $a0, -160 -+ -+ # third arg of make_fcontext() == address of context-function -+ st.d $a2, $a0, 152 -+ -+ # save address of finish as return-address for context-function -+ # will be entered after context-function returns -+ la.local $t8, finish -+ st.d $t8, $a0, 144 ++ # shift address in A0 to lower 16 byte boundary ++ bstrins.d $a0, $zero, 3, 0 + -+ # return pointer to context-data -+ jr $ra ++ # reserve space for context-data on context-stack ++ addi.d $a0, $a0, -160 ++ ++ # third arg of make_fcontext() == address of context-function ++ st.d $a2, $a0, 152 ++ ++ # save address of finish as return-address for context-function ++ # will be entered after context-function returns ++ la.local $a4, finish ++ st.d $a4, $a0, 144 ++ ++ # return pointer to context-data ++ jr $ra + +finish: -+ # reload our gp register (needed for la) -+ addi.d $t0, $sp, -160 -+ -+ # call _exit(0) -+ # the previous function should have left the 16 bytes incoming argument -+ # area on the stack which we reuse for calling _exit -+ la.global $t8, _exit -+ move $a0, $zero -+ jr $t8 -+.size make_fcontext, .-make_fcontext ++ # exit code is zero ++ li.d $a0, 0 ++ # call _exit(0) ++ b %plt(_exit) + ++.size make_fcontext, .-make_fcontext +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits -diff --git a/libs/context/src/asm/ontop_loongarch64_lp64_elf_gas.S b/libs/context/src/asm/ontop_loongarch64_lp64_elf_gas.S +diff --git a/libs/context/src/asm/ontop_loongarch64_sysv_elf_gas.S b/libs/context/src/asm/ontop_loongarch64_sysv_elf_gas.S new file mode 100644 -index 000000000..3f976fcfe +index 0000000..c6ea044 --- /dev/null -+++ b/libs/context/src/asm/ontop_loongarch64_lp64_elf_gas.S -@@ -0,0 +1,117 @@ -+/* -+ Copyright loongson 2018. -+ Distributed under the Boost Software License, Version 1.0. -+ (See accompanying file LICENSE_1_0.txt or copy at -+ http://www.boost.org/LICENSE -+*/ -+ ++++ b/libs/context/src/asm/ontop_loongarch64_sysv_elf_gas.S +@@ -0,0 +1,118 @@ +/******************************************************* + * * + * ------------------------------------------------- * @@ -316,14 +519,14 @@ index 000000000..3f976fcfe + * ------------------------------------------------- * + * | 0 | 8 | 16 | 24 | * + * ------------------------------------------------- * -+ * | F24 | F25 | F26 | F27 | * ++ * | FS0 | FS1 | FS2 | FS3 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * + * ------------------------------------------------- * + * | 32 | 40 | 48 | 56 | * + * ------------------------------------------------- * -+ * | F28 | F29 | F30 | F31 | * ++ * | FS4 | FS5 | FS6 | FS7 | * + * ------------------------------------------------- * + * ------------------------------------------------- * + * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * @@ -344,83 +547,91 @@ index 000000000..3f976fcfe + * ------------------------------------------------- * + * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * + * ------------------------------------------------- * -+ * | FP | GP | RA | PC | * ++ * | S8 | FP | RA | PC | * + * ------------------------------------------------- * + * * + * *****************************************************/ + -+.file "ontop_loongarch64_lp64_elf_gas.S" ++.file "ontop_loongarch64_sysv_elf_gas.S" +.text +.globl ontop_fcontext -+.align 3 ++.align 2 +.type ontop_fcontext,@function +ontop_fcontext: -+ # reserve space on stack -+ addi.d $sp, $sp, -160 -+ -+ st.d $s0, $sp, 64 # save S0 -+ st.d $s1, $sp, 72 # save S1 -+ st.d $s2, $sp, 80 # save S2 -+ st.d $s3, $sp, 88 # save S3 -+ st.d $s4, $sp, 96 # save S4 -+ st.d $s5, $sp, 104 # save S5 -+ st.d $s6, $sp, 112 # save S6 -+ st.d $s7, $sp, 120 # save S7 -+ st.d $s8, $sp, 128 # save S8 -+ st.d $fp, $sp, 136 # save FP -+ st.d $ra, $sp, 144 # save RA -+ st.d $ra, $sp, 152 # save RA as PC -+ -+ -+ fst.d $fs0, $sp, 0 # save F24 -+ fst.d $fs1, $sp, 8 # save F25 -+ fst.d $fs2, $sp, 16 # save F26 -+ fst.d $fs3, $sp, 24 # save F27 -+ fst.d $fs4, $sp, 32 # save F28 -+ fst.d $fs5, $sp, 40 # save F29 -+ fst.d $fs6, $sp, 48 # save F30 -+ fst.d $fs7, $sp, 56 # save F31 -+ -+ # swap a0,sp -+ xor $a0, $a0, $sp -+ xor $sp, $a0, $sp -+ xor $a0, $a0, $sp -+ -+ fld.d $fs0, $sp, 0 # restore F24 -+ fld.d $fs1, $sp, 8 # restore F25 -+ fld.d $fs2, $sp, 16 # restore F26 -+ fld.d $fs3, $sp, 24 # restore F27 -+ fld.d $fs4, $sp, 32 # restore F28 -+ fld.d $fs5, $sp, 40 # restore F29 -+ fld.d $fs6, $sp, 48 # restore F30 -+ fld.d $fs7, $sp, 56 # restore F31 -+ -+ ld.d $s0, $sp, 64 # restore S0 -+ ld.d $s1, $sp, 72 # restore S1 -+ ld.d $s2, $sp, 80 # restore S2 -+ ld.d $s3, $sp, 88 # restore S3 -+ ld.d $s4, $sp, 96 # restore S4 -+ ld.d $s5, $sp, 104 # restore S5 -+ ld.d $s6, $sp, 112 # restore S6 -+ ld.d $s7, $sp, 120 # restore S7 -+ ld.d $s8, $sp, 128 # restore S8 -+ ld.d $fp, $sp, 136 # restore FP -+ ld.d $ra, $sp, 144 # restore RA -+ -+ # load PC -+ move $t8, $a2 -+ -+ # adjust stack -+ addi.d $sp, $sp, 160 -+ -+ # jump to context -+ jr $t8 ++ # reserve space on stack ++ addi.d $sp, $sp, -160 ++ ++ # save fs0 - fs7 ++ fst.d $fs0, $sp, 0 ++ fst.d $fs1, $sp, 8 ++ fst.d $fs2, $sp, 16 ++ fst.d $fs3, $sp, 24 ++ fst.d $fs4, $sp, 32 ++ fst.d $fs5, $sp, 40 ++ fst.d $fs6, $sp, 48 ++ fst.d $fs7, $sp, 56 ++ ++ # save s0 - s8, fp, ra ++ st.d $s0, $sp, 64 ++ st.d $s1, $sp, 72 ++ st.d $s2, $sp, 80 ++ st.d $s3, $sp, 88 ++ st.d $s4, $sp, 96 ++ st.d $s5, $sp, 104 ++ st.d $s6, $sp, 112 ++ st.d $s7, $sp, 120 ++ st.d $s8, $sp, 128 ++ st.d $fp, $sp, 136 ++ st.d $ra, $sp, 144 ++ ++ # save RA as PC ++ st.d $ra, $sp, 152 ++ ++ # store SP (pointing to context-data) in A3 ++ move $a3, $sp ++ ++ # restore SP (pointing to context-data) from A0 ++ move $sp, $a0 ++ ++ # load fs0 - fs11 ++ fld.d $fs0, $sp, 0 ++ fld.d $fs1, $sp, 8 ++ fld.d $fs2, $sp, 16 ++ fld.d $fs3, $sp, 24 ++ fld.d $fs4, $sp, 32 ++ fld.d $fs5, $sp, 40 ++ fld.d $fs6, $sp, 48 ++ fld.d $fs7, $sp, 56 ++ ++ #load s0 - s11, fp, ra ++ ld.d $s0, $sp, 64 ++ ld.d $s1, $sp, 72 ++ ld.d $s2, $sp, 80 ++ ld.d $s3, $sp, 88 ++ ld.d $s4, $sp, 96 ++ ld.d $s5, $sp, 104 ++ ld.d $s6, $sp, 112 ++ ld.d $s7, $sp, 120 ++ ld.d $s8, $sp, 128 ++ ld.d $fp, $sp, 136 ++ ld.d $ra, $sp, 144 ++ ++ # return transfer_t from jump ++ # pass transfer_t as first arg in context function ++ # a0 == FCTX, a1 == DATA ++ move $a0, $a3 ++ ++ # adjust stack ++ addi.d $sp, $sp, 160 ++ ++ # jump to context ++ jr $a2 +.size ontop_fcontext, .-ontop_fcontext + +/* Mark that we don't need executable stack. */ +.section .note.GNU-stack,"",%progbits diff --git a/tools/build/src/engine/jam.h b/tools/build/src/engine/jam.h -index 59e5f82c0..76a786979 100644 +index 59e5f82..76a7869 100644 --- a/tools/build/src/engine/jam.h +++ b/tools/build/src/engine/jam.h @@ -446,6 +446,10 @@ @@ -434,30 +645,16 @@ index 59e5f82c0..76a786979 100644 #ifndef OSPLAT #define OSPLAT "" #endif -diff --git a/tools/build/src/tools/builtin.py b/tools/build/src/tools/builtin.py -index 0368f6520..02ba21013 100644 ---- a/tools/build/src/tools/builtin.py -+++ b/tools/build/src/tools/builtin.py -@@ -276,6 +276,9 @@ def register_globals (): - # z Systems (aka s390x) - 's390x', - -+ # loongarch -+ 'loongarch64', -+ - # Combined architectures for platforms/toolsets that support building for - # multiple architectures at once. "combined" would be the default multi-arch - # for the toolset. diff --git a/tools/build/src/tools/features/architecture-feature.jam b/tools/build/src/tools/features/architecture-feature.jam -index e3203078e..1048feafd 100644 +index e320307..124b4be 100644 --- a/tools/build/src/tools/features/architecture-feature.jam +++ b/tools/build/src/tools/features/architecture-feature.jam @@ -45,6 +45,9 @@ feature.feature architecture # RISC-V riscv -+ # loongarch -+ loongarch64 ++ # loongarch ++ loongarch + # z Systems (aka s390x) s390x diff --git a/boost.spec b/boost.spec index f12cb22..6ed5d36 100644 --- a/boost.spec +++ b/boost.spec @@ -2,7 +2,7 @@ Name: boost Version: 1.78.0 -Release: 16 +Release: 17 Summary: The free peer-reviewed portable C++ source libraries License: Boost Software License 1.0 URL: http://www.boost.org @@ -464,6 +464,10 @@ find libs -name example -exec cp {} boost-example --parents -r \; %{_libdir}/*.a %changelog +* Fri Jan 6 2023 Wenlong Zhang - 1.78.0-17 +- update the patch for loongarch +- fix build error: No best alternative for libs/context/build/asm_sources + * Fri Jan 6 2023 Wenlong Zhang - 1.78.0-16 - add boost context support for loongarch64