From 021aabd339ad7d7d0552fc9ae64d7252b34a2133 Mon Sep 17 00:00:00 2001 From: wxiat Date: Wed, 19 Jul 2023 14:20:42 +0800 Subject: [PATCH] Add sw64 architecture Signed-off-by: wxiat --- 0002-libffi-add-sw.patch | 1002 ++++++++++++++++++++++++++++++++++++++ libffi.spec | 7 +- 2 files changed, 1008 insertions(+), 1 deletion(-) create mode 100644 0002-libffi-add-sw.patch diff --git a/0002-libffi-add-sw.patch b/0002-libffi-add-sw.patch new file mode 100644 index 0000000..5ef66f0 --- /dev/null +++ b/0002-libffi-add-sw.patch @@ -0,0 +1,1002 @@ +From 2de41a43f103156bc0cc8d42b2055e97d852f92a Mon Sep 17 00:00:00 2001 +From: wxiat +Date: Wed, 28 Jun 2023 10:31:58 +0800 +Subject: [PATCH] add sw + +Signed-off-by: wxiat +--- + Makefile.am | 5 + + Makefile.in | 25 ++- + configure | 21 +++ + configure.ac | 7 + + m4/ax_gcc_archflag.m4 | 1 + + src/sw_64/ffi.c | 288 +++++++++++++++++++++++++++++++ + src/sw_64/ffitarget.h | 53 ++++++ + src/sw_64/osf.S | 387 ++++++++++++++++++++++++++++++++++++++++++ + src/types.c | 2 +- + 9 files changed, 786 insertions(+), 3 deletions(-) + create mode 100644 src/sw_64/ffi.c + create mode 100644 src/sw_64/ffitarget.h + create mode 100644 src/sw_64/osf.S + +diff --git a/Makefile.am b/Makefile.am +index 542179d..aba715c 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -8,6 +8,8 @@ SUBDIRS = include testsuite man + + EXTRA_DIST = LICENSE ChangeLog.v1 ChangeLog.libgcj \ + src/aarch64/ffi.c src/aarch64/ffitarget.h src/aarch64/sysv.S \ ++ src/sw_64/ffi.c src/sw_64/osf.S \ ++ src/sw_64/ffitarget.h \ + src/alpha/ffi.c src/alpha/osf.S \ + src/alpha/ffitarget.h src/arc/ffi.c src/arc/arcompact.S \ + src/arc/ffitarget.h src/arm/ffi.c src/arm/sysv.S \ +@@ -146,6 +148,9 @@ endif + if SPARC + nodist_libffi_la_SOURCES += src/sparc/ffi.c src/sparc/v8.S src/sparc/v9.S + endif ++if SW_64 ++nodist_libffi_la_SOURCES += src/sw_64/ffi.c src/sw_64/osf.S ++endif + if ALPHA + nodist_libffi_la_SOURCES += src/alpha/ffi.c src/alpha/osf.S + endif +diff --git a/Makefile.in b/Makefile.in +index 556379c..7aa0660 100644 +--- a/Makefile.in ++++ b/Makefile.in +@@ -91,6 +91,7 @@ target_triplet = @target@ + @X86_DARWIN32_TRUE@@X86_DARWIN_TRUE@am__append_9 = src/x86/win32.S + @SPARC_TRUE@am__append_10 = src/sparc/ffi.c src/sparc/v8.S src/sparc/v9.S + @ALPHA_TRUE@am__append_11 = src/alpha/ffi.c src/alpha/osf.S ++@SW_64_TRUE@am__append_11 = src/sw_64/ffi.c src/sw_64/osf.S + @IA64_TRUE@am__append_12 = src/ia64/ffi.c src/ia64/unix.S + @M32R_TRUE@am__append_13 = src/m32r/sysv.S src/m32r/ffi.c + @M68K_TRUE@am__append_14 = src/m68k/ffi.c src/m68k/sysv.S +@@ -203,6 +204,7 @@ am_libffi_la_OBJECTS = src/prep_cif.lo src/types.lo src/raw_api.lo \ + @SPARC_TRUE@am__objects_10 = src/sparc/ffi.lo src/sparc/v8.lo \ + @SPARC_TRUE@ src/sparc/v9.lo + @ALPHA_TRUE@am__objects_11 = src/alpha/ffi.lo src/alpha/osf.lo ++@SW_64_TRUE@am__objects_11 = src/sw_64/ffi.lo src/sw_64/osf.lo + @IA64_TRUE@am__objects_12 = src/ia64/ffi.lo src/ia64/unix.lo + @M32R_TRUE@am__objects_13 = src/m32r/sysv.lo src/m32r/ffi.lo + @M68K_TRUE@am__objects_14 = src/m68k/ffi.lo src/m68k/sysv.lo +@@ -609,6 +611,8 @@ ACLOCAL_AMFLAGS = -I m4 + SUBDIRS = include testsuite man + EXTRA_DIST = LICENSE ChangeLog.v1 ChangeLog.libgcj \ + src/aarch64/ffi.c src/aarch64/ffitarget.h src/aarch64/sysv.S \ ++ src/sw_64/ffi.c src/sw_64/osf.S \ ++ src/sw_64/ffitarget.h \ + src/alpha/ffi.c src/alpha/osf.S \ + src/alpha/ffitarget.h src/arc/ffi.c src/arc/arcompact.S \ + src/arc/ffitarget.h src/arm/ffi.c src/arm/sysv.S \ +@@ -897,6 +901,16 @@ src/sparc/v8.lo: src/sparc/$(am__dirstamp) \ + src/sparc/$(DEPDIR)/$(am__dirstamp) + src/sparc/v9.lo: src/sparc/$(am__dirstamp) \ + src/sparc/$(DEPDIR)/$(am__dirstamp) ++src/sw_64/$(am__dirstamp): ++ @$(MKDIR_P) src/sw_64 ++ @: > src/sw_64/$(am__dirstamp) ++src/sw_64/$(DEPDIR)/$(am__dirstamp): ++ @$(MKDIR_P) src/sw_64/$(DEPDIR) ++ @: > src/sw_64/$(DEPDIR)/$(am__dirstamp) ++src/sw_64/ffi.lo: src/sw_64/$(am__dirstamp) \ ++ src/sw_64/$(DEPDIR)/$(am__dirstamp) ++src/sw_64/osf.lo: src/sw_64/$(am__dirstamp) \ ++ src/sw_64/$(DEPDIR)/$(am__dirstamp) + src/alpha/$(am__dirstamp): + @$(MKDIR_P) src/alpha + @: > src/alpha/$(am__dirstamp) +@@ -1174,6 +1188,8 @@ mostlyclean-compile: + -rm -f src/*.lo + -rm -f src/aarch64/*.$(OBJEXT) + -rm -f src/aarch64/*.lo ++ -rm -f src/sw_64/*.$(OBJEXT) ++ -rm -f src/sw_64/*.lo + -rm -f src/alpha/*.$(OBJEXT) + -rm -f src/alpha/*.lo + -rm -f src/arc/*.$(OBJEXT) +@@ -1240,6 +1256,8 @@ distclean-compile: + @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/types.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@src/aarch64/$(DEPDIR)/ffi.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@src/aarch64/$(DEPDIR)/sysv.Plo@am__quote@ ++@AMDEP_TRUE@@am__include@ @am__quote@src/sw_64/$(DEPDIR)/ffi.Plo@am__quote@ ++@AMDEP_TRUE@@am__include@ @am__quote@src/sw_64/$(DEPDIR)/osf.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@src/alpha/$(DEPDIR)/ffi.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@src/alpha/$(DEPDIR)/osf.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@src/arc/$(DEPDIR)/arcompact.Plo@am__quote@ +@@ -1372,6 +1390,7 @@ clean-libtool: + -rm -rf src/.libs src/_libs + -rm -rf src/aarch64/.libs src/aarch64/_libs + -rm -rf src/alpha/.libs src/alpha/_libs ++ -rm -rf src/sw_64/.libs src/sw_64/_libs + -rm -rf src/arc/.libs src/arc/_libs + -rm -rf src/arm/.libs src/arm/_libs + -rm -rf src/avr32/.libs src/avr32/_libs +@@ -1916,6 +1935,8 @@ distclean-generic: + -rm -f src/$(am__dirstamp) + -rm -f src/aarch64/$(DEPDIR)/$(am__dirstamp) + -rm -f src/aarch64/$(am__dirstamp) ++ -rm -f src/sw_64/$(DEPDIR)/$(am__dirstamp) ++ -rm -f src/sw_64/$(am__dirstamp) + -rm -f src/alpha/$(DEPDIR)/$(am__dirstamp) + -rm -f src/alpha/$(am__dirstamp) + -rm -f src/arc/$(DEPDIR)/$(am__dirstamp) +@@ -1982,7 +2003,7 @@ clean-am: clean-aminfo clean-generic clean-libtool \ + + distclean: distclean-recursive + -rm -f $(am__CONFIG_DISTCLEAN_FILES) +- -rm -rf src/$(DEPDIR) src/aarch64/$(DEPDIR) src/alpha/$(DEPDIR) src/arc/$(DEPDIR) src/arm/$(DEPDIR) src/avr32/$(DEPDIR) src/bfin/$(DEPDIR) src/cris/$(DEPDIR) src/frv/$(DEPDIR) src/ia64/$(DEPDIR) src/loongarch/$(DEPDIR) src/m32r/$(DEPDIR) src/m68k/$(DEPDIR) src/m88k/$(DEPDIR) src/metag/$(DEPDIR) src/microblaze/$(DEPDIR) src/mips/$(DEPDIR) src/moxie/$(DEPDIR) src/nios2/$(DEPDIR) src/pa/$(DEPDIR) src/powerpc/$(DEPDIR) src/s390/$(DEPDIR) src/sh/$(DEPDIR) src/sh64/$(DEPDIR) src/sparc/$(DEPDIR) src/tile/$(DEPDIR) src/vax/$(DEPDIR) src/x86/$(DEPDIR) src/xtensa/$(DEPDIR) ++ -rm -rf src/$(DEPDIR) src/aarch64/$(DEPDIR) src/alpha/$(DEPDIR) src/sw_64/$(DEPDIR) src/arc/$(DEPDIR) src/arm/$(DEPDIR) src/avr32/$(DEPDIR) src/bfin/$(DEPDIR) src/cris/$(DEPDIR) src/frv/$(DEPDIR) src/ia64/$(DEPDIR) src/loongarch/$(DEPDIR) src/m32r/$(DEPDIR) src/m68k/$(DEPDIR) src/m88k/$(DEPDIR) src/metag/$(DEPDIR) src/microblaze/$(DEPDIR) src/mips/$(DEPDIR) src/moxie/$(DEPDIR) src/nios2/$(DEPDIR) src/pa/$(DEPDIR) src/powerpc/$(DEPDIR) src/s390/$(DEPDIR) src/sh/$(DEPDIR) src/sh64/$(DEPDIR) src/sparc/$(DEPDIR) src/tile/$(DEPDIR) src/vax/$(DEPDIR) src/x86/$(DEPDIR) src/xtensa/$(DEPDIR) + -rm -f Makefile + distclean-am: clean-am distclean-compile distclean-generic \ + distclean-hdr distclean-libtool distclean-tags +@@ -2121,7 +2142,7 @@ installcheck-am: + maintainer-clean: maintainer-clean-recursive + -rm -f $(am__CONFIG_DISTCLEAN_FILES) + -rm -rf $(top_srcdir)/autom4te.cache +- -rm -rf src/$(DEPDIR) src/aarch64/$(DEPDIR) src/alpha/$(DEPDIR) src/arc/$(DEPDIR) src/arm/$(DEPDIR) src/avr32/$(DEPDIR) src/bfin/$(DEPDIR) src/cris/$(DEPDIR) src/frv/$(DEPDIR) src/ia64/$(DEPDIR) src/loongarch/$(DEPDIR) src/m32r/$(DEPDIR) src/m68k/$(DEPDIR) src/m88k/$(DEPDIR) src/metag/$(DEPDIR) src/microblaze/$(DEPDIR) src/mips/$(DEPDIR) src/moxie/$(DEPDIR) src/nios2/$(DEPDIR) src/pa/$(DEPDIR) src/powerpc/$(DEPDIR) src/s390/$(DEPDIR) src/sh/$(DEPDIR) src/sh64/$(DEPDIR) src/sparc/$(DEPDIR) src/tile/$(DEPDIR) src/vax/$(DEPDIR) src/x86/$(DEPDIR) src/xtensa/$(DEPDIR) ++ -rm -rf src/$(DEPDIR) src/aarch64/$(DEPDIR) src/alpha/$(DEPDIR) src/sw_64/$(DEPDIR) src/arc/$(DEPDIR) src/arm/$(DEPDIR) src/avr32/$(DEPDIR) src/bfin/$(DEPDIR) src/cris/$(DEPDIR) src/frv/$(DEPDIR) src/ia64/$(DEPDIR) src/loongarch/$(DEPDIR) src/m32r/$(DEPDIR) src/m68k/$(DEPDIR) src/m88k/$(DEPDIR) src/metag/$(DEPDIR) src/microblaze/$(DEPDIR) src/mips/$(DEPDIR) src/moxie/$(DEPDIR) src/nios2/$(DEPDIR) src/pa/$(DEPDIR) src/powerpc/$(DEPDIR) src/s390/$(DEPDIR) src/sh/$(DEPDIR) src/sh64/$(DEPDIR) src/sparc/$(DEPDIR) src/tile/$(DEPDIR) src/vax/$(DEPDIR) src/x86/$(DEPDIR) src/xtensa/$(DEPDIR) + -rm -f Makefile + maintainer-clean-am: distclean-am maintainer-clean-aminfo \ + maintainer-clean-generic maintainer-clean-vti +diff --git a/configure b/configure +index b3c4f69..ac15b27 100755 +--- a/configure ++++ b/configure +@@ -708,6 +708,8 @@ IA64_FALSE + IA64_TRUE + ALPHA_FALSE + ALPHA_TRUE ++SW_64_FALSE ++SW_64_TRUE + X86_DARWIN64_FALSE + X86_DARWIN64_TRUE + X86_DARWIN32_FALSE +@@ -16686,6 +16688,7 @@ fi + *cypress*) ax_gcc_arch=cypress ;; + esac ;; + ++ sw_64*) ax_gcc_arch=sw6b ;; + alphaev5) ax_gcc_arch=ev5 ;; + alphaev56) ax_gcc_arch=ev56 ;; + alphapca56) ax_gcc_arch="pca56 ev56" ;; +@@ -17183,6 +17186,12 @@ case "$host" in + TARGET=AARCH64; TARGETDIR=aarch64 + ;; + ++ sw_64*-*-*) ++ TARGET=SW_64; TARGETDIR=sw_64; ++ # Support 128-bit long double, changeable via command-line switch. ++ HAVE_LONG_DOUBLE='defined(__LONG_DOUBLE_128__)' ++ ;; ++ + alpha*-*-*) + TARGET=ALPHA; TARGETDIR=alpha; + # Support 128-bit long double, changeable via command-line switch. +@@ -17491,6 +17500,14 @@ else + ALPHA_FALSE= + fi + ++ if test x$TARGET = xSW_64; then ++ SW_64_TRUE= ++ SW_64_FALSE='#' ++else ++ SW_64_TRUE='#' ++ SW_64_FALSE= ++fi ++ + if test x$TARGET = xIA64; then + IA64_TRUE= + IA64_FALSE='#' +@@ -19046,6 +19063,10 @@ if test -z "${ALPHA_TRUE}" && test -z "${ALPHA_FALSE}"; then + as_fn_error $? "conditional \"ALPHA\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${SW_64_TRUE}" && test -z "${SW_64_FALSE}"; then ++ as_fn_error $? "conditional \"SW_64\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${IA64_TRUE}" && test -z "${IA64_FALSE}"; then + as_fn_error $? "conditional \"IA64\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/configure.ac b/configure.ac +index 0cf6811..669da05 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -86,6 +86,12 @@ case "$host" in + HAVE_LONG_DOUBLE='defined(__LONG_DOUBLE_128__)' + ;; + ++ sw_64*-*-*) ++ TARGET=SW_64; TARGETDIR=sw_64; ++ # Support 128-bit long double, changeable via command-line switch. ++ HAVE_LONG_DOUBLE='defined(__LONG_DOUBLE_128__)' ++ ;; ++ + arc*-*-*) + TARGET=ARC; TARGETDIR=arc + ;; +@@ -307,6 +313,7 @@ AM_CONDITIONAL(X86_DARWIN, test x$TARGET = xX86_DARWIN) + AM_CONDITIONAL(X86_DARWIN32, test x$TARGET = xX86_DARWIN && test $ac_cv_sizeof_size_t = 4) + AM_CONDITIONAL(X86_DARWIN64, test x$TARGET = xX86_DARWIN && test $ac_cv_sizeof_size_t = 8) + AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA) ++AM_CONDITIONAL(SW_64, test x$TARGET = xSW_64) + AM_CONDITIONAL(IA64, test x$TARGET = xIA64) + AM_CONDITIONAL(M32R, test x$TARGET = xM32R) + AM_CONDITIONAL(M68K, test x$TARGET = xM68K) +diff --git a/m4/ax_gcc_archflag.m4 b/m4/ax_gcc_archflag.m4 +index aab2661..5fd9bb3 100644 +--- a/m4/ax_gcc_archflag.m4 ++++ b/m4/ax_gcc_archflag.m4 +@@ -165,6 +165,7 @@ case $host_cpu in + *cypress*) ax_gcc_arch=cypress ;; + esac ;; + ++ sw_64*) ax_gcc_arch=sw6b ;; + alphaev5) ax_gcc_arch=ev5 ;; + alphaev56) ax_gcc_arch=ev56 ;; + alphapca56) ax_gcc_arch="pca56 ev56" ;; +diff --git a/src/sw_64/ffi.c b/src/sw_64/ffi.c +new file mode 100644 +index 0000000..7f14278 +--- /dev/null ++++ b/src/sw_64/ffi.c +@@ -0,0 +1,288 @@ ++/* ----------------------------------------------------------------------- ++ ffi.c - Copyright (c) 2012 Anthony Green ++ Copyright (c) 1998, 2001, 2007, 2008 Red Hat, Inc. ++ ++ Sw_64 Foreign Function Interface ++ ++ Permission is hereby granted, free of charge, to any person obtaining ++ a copy of this software and associated documentation files (the ++ ``Software''), to deal in the Software without restriction, including ++ without limitation the rights to use, copy, modify, merge, publish, ++ distribute, sublicense, and/or sell copies of the Software, and to ++ permit persons to whom the Software is furnished to do so, subject to ++ the following conditions: ++ ++ The above copyright notice and this permission notice shall be included ++ in all copies or substantial portions of the Software. ++ ++ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, ++ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ++ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ++ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT ++ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, ++ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ++ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ++ DEALINGS IN THE SOFTWARE. ++ ----------------------------------------------------------------------- */ ++ ++#include ++#include ++#include ++ ++/* Force FFI_TYPE_LONGDOUBLE to be different than FFI_TYPE_DOUBLE; ++ all further uses in this file will refer to the 128-bit type. */ ++#if defined(__LONG_DOUBLE_128__) ++# if FFI_TYPE_LONGDOUBLE != 4 ++# error FFI_TYPE_LONGDOUBLE out of date ++# endif ++#else ++# undef FFI_TYPE_LONGDOUBLE ++# define FFI_TYPE_LONGDOUBLE 4 ++#endif ++ ++extern void ffi_call_osf(void *, unsigned long, unsigned, void *, void (*)(void)) ++ FFI_HIDDEN; ++extern void ffi_closure_osf(void) FFI_HIDDEN; ++ ++ ++ffi_status ++ffi_prep_cif_machdep(ffi_cif *cif) ++{ ++ /* Adjust cif->bytes to represent a minimum 6 words for the temporary ++ register argument loading area. */ ++ if (cif->bytes < 6*FFI_SIZEOF_ARG) ++ cif->bytes = 6*FFI_SIZEOF_ARG; ++ ++ /* Set the return type flag */ ++ switch (cif->rtype->type) ++ { ++ case FFI_TYPE_STRUCT: ++ case FFI_TYPE_FLOAT: ++ case FFI_TYPE_DOUBLE: ++ cif->flags = cif->rtype->type; ++ break; ++ ++ case FFI_TYPE_LONGDOUBLE: ++ /* 128-bit long double is returned in memory, like a struct. */ ++ cif->flags = FFI_TYPE_STRUCT; ++ break; ++ ++ default: ++ cif->flags = FFI_TYPE_INT; ++ break; ++ } ++ ++ return FFI_OK; ++} ++ ++ ++void ++ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) ++{ ++ unsigned long *stack, *argp; ++ long i, avn; ++ ffi_type **arg_types; ++ ++ /* If the return value is a struct and we don't have a return ++ value address then we need to make one. */ ++ if (rvalue == NULL && cif->flags == FFI_TYPE_STRUCT) ++ rvalue = alloca(cif->rtype->size); ++ ++ /* Allocate the space for the arguments, plus 4 words of temp ++ space for ffi_call_osf. */ ++ argp = stack = alloca(cif->bytes + 4*FFI_SIZEOF_ARG); ++ ++ if (cif->flags == FFI_TYPE_STRUCT) ++ *(void **) argp++ = rvalue; ++ ++ i = 0; ++ avn = cif->nargs; ++ arg_types = cif->arg_types; ++ ++ while (i < avn) ++ { ++ size_t size = (*arg_types)->size; ++ ++ switch ((*arg_types)->type) ++ { ++ case FFI_TYPE_SINT8: ++ *(SINT64 *) argp = *(SINT8 *)(* avalue); ++ break; ++ ++ case FFI_TYPE_UINT8: ++ *(SINT64 *) argp = *(UINT8 *)(* avalue); ++ break; ++ ++ case FFI_TYPE_SINT16: ++ *(SINT64 *) argp = *(SINT16 *)(* avalue); ++ break; ++ ++ case FFI_TYPE_UINT16: ++ *(SINT64 *) argp = *(UINT16 *)(* avalue); ++ break; ++ ++ case FFI_TYPE_SINT32: ++ case FFI_TYPE_UINT32: ++ /* Note that unsigned 32-bit quantities are sign extended. */ ++ *(SINT64 *) argp = *(SINT32 *)(* avalue); ++ break; ++ ++ case FFI_TYPE_SINT64: ++ case FFI_TYPE_UINT64: ++ case FFI_TYPE_POINTER: ++ *(UINT64 *) argp = *(UINT64 *)(* avalue); ++ break; ++ ++ case FFI_TYPE_FLOAT: ++ if (argp - stack < 6) ++ { ++ /* Note the conversion -- all the fp regs are loaded as ++ doubles. The in-register format is the same. */ ++ *(double *) argp = *(float *)(* avalue); ++ } ++ else ++ *(float *) argp = *(float *)(* avalue); ++ break; ++ ++ case FFI_TYPE_DOUBLE: ++ *(double *) argp = *(double *)(* avalue); ++ break; ++ ++ case FFI_TYPE_LONGDOUBLE: ++ /* 128-bit long double is passed by reference. */ ++ *(long double **) argp = (long double *)(* avalue); ++ size = sizeof (long double *); ++ break; ++ ++ case FFI_TYPE_STRUCT: ++ memcpy(argp, *avalue, (*arg_types)->size); ++ break; ++ ++ default: ++ FFI_ASSERT(0); ++ } ++ ++ argp += ALIGN(size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG; ++ i++, arg_types++, avalue++; ++ } ++ ++ ffi_call_osf(stack, cif->bytes, cif->flags, rvalue, fn); ++} ++ ++ ++ffi_status ++ffi_prep_closure_loc (ffi_closure* closure, ++ ffi_cif* cif, ++ void (*fun)(ffi_cif*, void*, void**, void*), ++ void *user_data, ++ void *codeloc) ++{ ++ unsigned int *tramp; ++ ++ if (cif->abi != FFI_OSF) ++ return FFI_BAD_ABI; ++ ++ tramp = (unsigned int *) &closure->tramp[0]; ++ tramp[0] = 0x47fb0401; /* mov $27,$1 */ ++ tramp[1] = 0xa77b0010; /* ldq $27,16($27) */ ++ tramp[2] = 0x6bfb0000; /* jmp $31,($27),0 */ ++ tramp[3] = 0x47ff041f; /* nop */ ++ *(void **) &tramp[4] = ffi_closure_osf; ++ ++ closure->cif = cif; ++ closure->fun = fun; ++ closure->user_data = user_data; ++ ++ /* Flush the Icache. ++ ++ Tru64 UNIX as doesn't understand the imb mnemonic, so use call_pal ++ instead, since both Compaq as and gas can handle it. ++ ++ 0x86 is PAL_imb in Tru64 UNIX . */ ++ asm volatile ("sys_call 0x86" : : : "memory"); ++ ++ return FFI_OK; ++} ++ ++ ++long FFI_HIDDEN ++ffi_closure_osf_inner(ffi_closure *closure, void *rvalue, unsigned long *argp) ++{ ++ ffi_cif *cif; ++ void **avalue; ++ ffi_type **arg_types; ++ long i, avn, argn; ++ ++ cif = closure->cif; ++ avalue = alloca(cif->nargs * sizeof(void *)); ++ ++ argn = 0; ++ ++ /* Copy the caller's structure return address to that the closure ++ returns the data directly to the caller. */ ++ if (cif->flags == FFI_TYPE_STRUCT) ++ { ++ rvalue = (void *) argp[0]; ++ argn = 1; ++ } ++ ++ i = 0; ++ avn = cif->nargs; ++ arg_types = cif->arg_types; ++ ++ /* Grab the addresses of the arguments from the stack frame. */ ++ while (i < avn) ++ { ++ size_t size = arg_types[i]->size; ++ ++ switch (arg_types[i]->type) ++ { ++ case FFI_TYPE_SINT8: ++ case FFI_TYPE_UINT8: ++ case FFI_TYPE_SINT16: ++ case FFI_TYPE_UINT16: ++ case FFI_TYPE_SINT32: ++ case FFI_TYPE_UINT32: ++ case FFI_TYPE_SINT64: ++ case FFI_TYPE_UINT64: ++ case FFI_TYPE_POINTER: ++ case FFI_TYPE_STRUCT: ++ avalue[i] = &argp[argn]; ++ break; ++ ++ case FFI_TYPE_FLOAT: ++ if (argn < 6) ++ { ++ /* Floats coming from registers need conversion from double ++ back to float format. */ ++ *(float *)&argp[argn - 6] = *(double *)&argp[argn - 6]; ++ avalue[i] = &argp[argn - 6]; ++ } ++ else ++ avalue[i] = &argp[argn]; ++ break; ++ ++ case FFI_TYPE_DOUBLE: ++ avalue[i] = &argp[argn - (argn < 6 ? 6 : 0)]; ++ break; ++ ++ case FFI_TYPE_LONGDOUBLE: ++ /* 128-bit long double is passed by reference. */ ++ avalue[i] = (long double *) argp[argn]; ++ size = sizeof (long double *); ++ break; ++ ++ default: ++ abort (); ++ } ++ ++ argn += ALIGN(size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG; ++ i++; ++ } ++ ++ /* Invoke the closure. */ ++ closure->fun (cif, rvalue, avalue, closure->user_data); ++ ++ /* Tell ffi_closure_osf how to perform return type promotions. */ ++ return cif->rtype->type; ++} +diff --git a/src/sw_64/ffitarget.h b/src/sw_64/ffitarget.h +new file mode 100644 +index 0000000..af145bc +--- /dev/null ++++ b/src/sw_64/ffitarget.h +@@ -0,0 +1,53 @@ ++/* -----------------------------------------------------------------*-C-*- ++ ffitarget.h - Copyright (c) 2012 Anthony Green ++ Copyright (c) 1996-2003 Red Hat, Inc. ++ Target configuration macros for Alpha. ++ ++ Permission is hereby granted, free of charge, to any person obtaining ++ a copy of this software and associated documentation files (the ++ ``Software''), to deal in the Software without restriction, including ++ without limitation the rights to use, copy, modify, merge, publish, ++ distribute, sublicense, and/or sell copies of the Software, and to ++ permit persons to whom the Software is furnished to do so, subject to ++ the following conditions: ++ ++ The above copyright notice and this permission notice shall be included ++ in all copies or substantial portions of the Software. ++ ++ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, ++ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ++ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ++ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT ++ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, ++ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ++ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ++ DEALINGS IN THE SOFTWARE. ++ ++ ----------------------------------------------------------------------- */ ++ ++#ifndef LIBFFI_TARGET_H ++#define LIBFFI_TARGET_H ++ ++#ifndef LIBFFI_H ++#error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." ++#endif ++ ++#ifndef LIBFFI_ASM ++typedef unsigned long ffi_arg; ++typedef signed long ffi_sarg; ++ ++typedef enum ffi_abi { ++ FFI_FIRST_ABI = 0, ++ FFI_OSF, ++ FFI_LAST_ABI, ++ FFI_DEFAULT_ABI = FFI_OSF ++} ffi_abi; ++#endif ++ ++/* ---- Definitions for closures ----------------------------------------- */ ++ ++#define FFI_CLOSURES 1 ++#define FFI_TRAMPOLINE_SIZE 24 ++#define FFI_NATIVE_RAW_API 0 ++ ++#endif +diff --git a/src/sw_64/osf.S b/src/sw_64/osf.S +new file mode 100644 +index 0000000..a6d94db +--- /dev/null ++++ b/src/sw_64/osf.S +@@ -0,0 +1,387 @@ ++/* ----------------------------------------------------------------------- ++ osf.S - Copyright (c) 1998, 2001, 2007, 2008, 2011 Red Hat ++ ++ Sw_64/OSF Foreign Function Interface ++ ++ Permission is hereby granted, free of charge, to any person obtaining ++ a copy of this software and associated documentation files (the ++ ``Software''), to deal in the Software without restriction, including ++ without limitation the rights to use, copy, modify, merge, publish, ++ distribute, sublicense, and/or sell copies of the Software, and to ++ permit persons to whom the Software is furnished to do so, subject to ++ the following conditions: ++ ++ The above copyright notice and this permission notice shall be included ++ in all copies or substantial portions of the Software. ++ ++ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, ++ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ++ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ++ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT ++ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, ++ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ++ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ++ DEALINGS IN THE SOFTWARE. ++ ----------------------------------------------------------------------- */ ++ ++#define LIBFFI_ASM ++#include ++#include ++ ++ .arch sw6b ++ .text ++ ++/* ffi_call_osf (void *args, unsigned long bytes, unsigned flags, ++ void *raddr, void (*fnaddr)(void)); ++ ++ Bit o trickiness here -- ARGS+BYTES is the base of the stack frame ++ for this function. This has been allocated by ffi_call. We also ++ deallocate some of the stack that has been alloca'd. */ ++ ++ .align 3 ++ .globl ffi_call_osf ++ .ent ffi_call_osf ++ FFI_HIDDEN(ffi_call_osf) ++ ++ffi_call_osf: ++ .frame $15, 32, $26, 0 ++ .mask 0x4008000, -32 ++$LFB1: ++ addl $16,$17,$1 ++ mov $16, $30 ++ stl $26, 0($1) ++ stl $15, 8($1) ++ stl $18, 16($1) ++ mov $1, $15 ++$LCFI1: ++ .prologue 0 ++ ++ stl $19, 24($1) ++ mov $20, $27 ++ ++ # Load up all of the (potential) argument registers. ++ ldl $16, 0($30) ++ fldd $f16, 0($30) ++ fldd $f17, 8($30) ++ ldl $17, 8($30) ++ fldd $f18, 16($30) ++ ldl $18, 16($30) ++ fldd $f19, 24($30) ++ ldl $19, 24($30) ++ fldd $f20, 32($30) ++ ldl $20, 32($30) ++ fldd $f21, 40($30) ++ ldl $21, 40($30) ++ ++ # Deallocate the register argument area. ++ ldi $30, 48($30) ++ ++ call $26, ($27), 0 ++ ldgp $29, 0($26) ++ ++ # If the return value pointer is NULL, assume no return value. ++ ldl $19, 24($15) ++ ldl $18, 16($15) ++ ldl $26, 0($15) ++$LCFI2: ++ beq $19, $noretval ++ ++ # Store the return value out in the proper type. ++ cmpeq $18, FFI_TYPE_INT, $1 ++ bne $1, $retint ++ cmpeq $18, FFI_TYPE_FLOAT, $2 ++ bne $2, $retfloat ++ cmpeq $18, FFI_TYPE_DOUBLE, $3 ++ bne $3, $retdouble ++ ++ .align 3 ++$noretval: ++ ldl $15, 8($15) ++ ret ++ ++ .align 4 ++$retint: ++ stl $0, 0($19) ++ nop ++ ldl $15, 8($15) ++ ret ++ ++ .align 4 ++$retfloat: ++ fsts $f0, 0($19) ++ nop ++ ldl $15, 8($15) ++ ret ++ ++ .align 4 ++$retdouble: ++ fstd $f0, 0($19) ++ nop ++ ldl $15, 8($15) ++ ret ++$LFE1: ++ ++ .end ffi_call_osf ++ ++/* ffi_closure_osf(...) ++ ++ Receives the closure argument in $1. */ ++ ++ .align 3 ++ .globl ffi_closure_osf ++ .ent ffi_closure_osf ++ FFI_HIDDEN(ffi_closure_osf) ++ ++ffi_closure_osf: ++ .frame $30, 16*8, $26, 0 ++ .mask 0x4000000, -16*8 ++$LFB2: ++ ldgp $29, 0($27) ++ subl $30, 16*8, $30 ++$LCFI5: ++ stl $26, 0($30) ++$LCFI6: ++ .prologue 1 ++ ++ # Store all of the potential argument registers in va_list format. ++ fstd $f16, 4*8($30) ++ fstd $f17, 5*8($30) ++ fstd $f18, 6*8($30) ++ fstd $f19, 7*8($30) ++ fstd $f20, 8*8($30) ++ fstd $f21, 9*8($30) ++ stl $16, 10*8($30) ++ stl $17, 11*8($30) ++ stl $18, 12*8($30) ++ stl $19, 13*8($30) ++ stl $20, 14*8($30) ++ stl $21, 15*8($30) ++ ++ # Call ffi_closure_osf_inner to do the bulk of the work. ++ mov $1, $16 ++ ldi $17, 2*8($30) ++ ldi $18, 10*8($30) ++ call $26, ffi_closure_osf_inner ++ ldgp $29, 0($26) ++ ldl $26, 0($30) ++ ++ # Load up the return value in the proper type. ++ ldi $1, $load_table ++ s4addl $0, $1, $1 ++ ldw $1, 0($1) ++ addl $1, $29, $1 ++ jmp $31, ($1), $load_32 ++ ++ .align 4 ++$load_none: ++ addl $30, 16*8, $30 ++ ret ++ ++ .align 4 ++$load_float: ++ flds $f0, 16($30) ++ nop ++ addl $30, 16*8, $30 ++ ret ++ ++ .align 4 ++$load_double: ++ fldd $f0, 16($30) ++ nop ++ addl $30, 16*8, $30 ++ ret ++ ++ .align 4 ++$load_u8: ++#ifdef __sw_64_bwx__ ++ ldbu $0, 16($30) ++ nop ++#else ++ ldl $0, 16($30) ++ and $0, 255, $0 ++#endif ++ addl $30, 16*8, $30 ++ ret ++ ++ .align 4 ++$load_s8: ++#ifdef __sw_64_bwx__ ++ ldbu $0, 16($30) ++ sextb $0, $0 ++#else ++ ldl $0, 16($30) ++ sll $0, 56, $0 ++ sra $0, 56, $0 ++#endif ++ addl $30, 16*8, $30 ++ ret ++ ++ .align 4 ++$load_u16: ++#ifdef __sw_64_bwx__ ++ ldhu $0, 16($30) ++ nop ++#else ++ ldl $0, 16($30) ++ zapnot $0, 3, $0 ++#endif ++ addl $30, 16*8, $30 ++ ret ++ ++ .align 4 ++$load_s16: ++#ifdef __sw_64_bwx__ ++ ldhu $0, 16($30) ++ sexth $0, $0 ++#else ++ ldl $0, 16($30) ++ sll $0, 48, $0 ++ sra $0, 48, $0 ++#endif ++ addl $30, 16*8, $30 ++ ret ++ ++ .align 4 ++$load_32: ++ ldw $0, 16($30) ++ nop ++ addl $30, 16*8, $30 ++ ret ++ ++ .align 4 ++$load_64: ++ ldl $0, 16($30) ++ nop ++ addl $30, 16*8, $30 ++ ret ++$LFE2: ++ ++ .end ffi_closure_osf ++ ++#ifdef __ELF__ ++.section .rodata ++#else ++.rdata ++#endif ++$load_table: ++ .gprel32 $load_none # FFI_TYPE_VOID ++ .gprel32 $load_32 # FFI_TYPE_INT ++ .gprel32 $load_float # FFI_TYPE_FLOAT ++ .gprel32 $load_double # FFI_TYPE_DOUBLE ++ .gprel32 $load_none # FFI_TYPE_LONGDOUBLE ++ .gprel32 $load_u8 # FFI_TYPE_UINT8 ++ .gprel32 $load_s8 # FFI_TYPE_SINT8 ++ .gprel32 $load_u16 # FFI_TYPE_UINT16 ++ .gprel32 $load_s16 # FFI_TYPE_SINT16 ++ .gprel32 $load_32 # FFI_TYPE_UINT32 ++ .gprel32 $load_32 # FFI_TYPE_SINT32 ++ .gprel32 $load_64 # FFI_TYPE_UINT64 ++ .gprel32 $load_64 # FFI_TYPE_SINT64 ++ .gprel32 $load_none # FFI_TYPE_STRUCT ++ .gprel32 $load_64 # FFI_TYPE_POINTER ++ ++/* Assert that the table above is in sync with ffi.h. */ ++ ++#if FFI_TYPE_FLOAT != 2 \ ++ || FFI_TYPE_DOUBLE != 3 \ ++ || FFI_TYPE_UINT8 != 5 \ ++ || FFI_TYPE_SINT8 != 6 \ ++ || FFI_TYPE_UINT16 != 7 \ ++ || FFI_TYPE_SINT16 != 8 \ ++ || FFI_TYPE_UINT32 != 9 \ ++ || FFI_TYPE_SINT32 != 10 \ ++ || FFI_TYPE_UINT64 != 11 \ ++ || FFI_TYPE_SINT64 != 12 \ ++ || FFI_TYPE_STRUCT != 13 \ ++ || FFI_TYPE_POINTER != 14 \ ++ || FFI_TYPE_LAST != 14 ++#error "osf.S out of sync with ffi.h" ++#endif ++ ++#ifdef __ELF__ ++# define UA_SI .4byte ++# define FDE_ENCODING 0x1b /* pcrel sdata4 */ ++# define FDE_ENCODE(X) .4byte X-. ++# define FDE_ARANGE(X) .4byte X ++#elif defined __osf__ ++# define UA_SI .align 0; .long ++# define FDE_ENCODING 0x50 /* aligned absolute */ ++# define FDE_ENCODE(X) .align 3; .quad X ++# define FDE_ARANGE(X) .align 0; .quad X ++#endif ++ ++#ifdef __ELF__ ++ .section .eh_frame,EH_FRAME_FLAGS,@progbits ++#elif defined __osf__ ++ .data ++ .align 3 ++ .globl _GLOBAL__F_ffi_call_osf ++_GLOBAL__F_ffi_call_osf: ++#endif ++__FRAME_BEGIN__: ++ UA_SI $LECIE1-$LSCIE1 # Length of Common Information Entry ++$LSCIE1: ++ UA_SI 0x0 # CIE Identifier Tag ++ .byte 0x1 # CIE Version ++ .ascii "zR\0" # CIE Augmentation ++ .byte 0x1 # uleb128 0x1; CIE Code Alignment Factor ++ .byte 0x78 # sleb128 -8; CIE Data Alignment Factor ++ .byte 26 # CIE RA Column ++ .byte 0x1 # uleb128 0x1; Augmentation size ++ .byte FDE_ENCODING # FDE Encoding ++ .byte 0xc # DW_CFA_def_cfa ++ .byte 30 # uleb128 column 30 ++ .byte 0 # uleb128 offset 0 ++ .align 3 ++$LECIE1: ++$LSFDE1: ++ UA_SI $LEFDE1-$LASFDE1 # FDE Length ++$LASFDE1: ++ UA_SI $LASFDE1-__FRAME_BEGIN__ # FDE CIE offset ++ FDE_ENCODE($LFB1) # FDE initial location ++ FDE_ARANGE($LFE1-$LFB1) # FDE address range ++ .byte 0x0 # uleb128 0x0; Augmentation size ++ ++ .byte 0x4 # DW_CFA_advance_loc4 ++ UA_SI $LCFI1-$LFB1 ++ .byte 0x9a # DW_CFA_offset, column 26 ++ .byte 4 # uleb128 4*-8 ++ .byte 0x8f # DW_CFA_offset, column 15 ++ .byte 0x3 # uleb128 3*-8 ++ .byte 0xc # DW_CFA_def_cfa ++ .byte 15 # uleb128 column 15 ++ .byte 32 # uleb128 offset 32 ++ ++ .byte 0x4 # DW_CFA_advance_loc4 ++ UA_SI $LCFI2-$LCFI1 ++ .byte 0xda # DW_CFA_restore, column 26 ++ .align 3 ++$LEFDE1: ++ ++$LSFDE3: ++ UA_SI $LEFDE3-$LASFDE3 # FDE Length ++$LASFDE3: ++ UA_SI $LASFDE3-__FRAME_BEGIN__ # FDE CIE offset ++ FDE_ENCODE($LFB2) # FDE initial location ++ FDE_ARANGE($LFE2-$LFB2) # FDE address range ++ .byte 0x0 # uleb128 0x0; Augmentation size ++ ++ .byte 0x4 # DW_CFA_advance_loc4 ++ UA_SI $LCFI5-$LFB2 ++ .byte 0xe # DW_CFA_def_cfa_offset ++ .byte 0x80,0x1 # uleb128 128 ++ ++ .byte 0x4 # DW_CFA_advance_loc4 ++ UA_SI $LCFI6-$LCFI5 ++ .byte 0x9a # DW_CFA_offset, column 26 ++ .byte 16 # uleb128 offset 16*-8 ++ .align 3 ++$LEFDE3: ++#if defined __osf__ ++ .align 0 ++ .long 0 # End of Table ++#endif ++ ++#if defined __ELF__ && defined __linux__ ++ .section .note.GNU-stack,"",@progbits ++#endif +diff --git a/src/types.c b/src/types.c +index 0de5994..001a6c5 100644 +--- a/src/types.c ++++ b/src/types.c +@@ -74,7 +74,7 @@ FFI_TYPEDEF(pointer, void*, FFI_TYPE_POINTER); + FFI_TYPEDEF(float, float, FFI_TYPE_FLOAT); + FFI_TYPEDEF(double, double, FFI_TYPE_DOUBLE); + +-#ifdef __alpha__ ++#if defined __alpha__ || defined __sw_64__ + /* Even if we're not configured to default to 128-bit long double, + maintain binary compatibility, as -mlong-double-128 can be used + at any time. */ +-- +2.31.1 + diff --git a/libffi.spec b/libffi.spec index 6af8a14..fdfc566 100644 --- a/libffi.spec +++ b/libffi.spec @@ -1,4 +1,4 @@ -%define anolis_release .0.3 +%define anolis_release .0.4 %global multilib_arches %{ix86} ppc ppc64 ppc64p7 s390 s390x x86_64 @@ -23,6 +23,7 @@ Patch7: libffi-3.1-memfd.patch Patch1000: 0001-arch-support-loongarch64-platform.patch Patch1001: 0001-add-loongarch64-objects.patch +Patch1002: 0002-libffi-add-sw.patch %description Compilers for high level languages generate code that follow certain @@ -85,6 +86,7 @@ Doc pages for %{name}. %patch1000 -p1 %patch1001 -p1 +%patch1002 -p1 %build @@ -147,6 +149,9 @@ fi %{_infodir}/libffi.info.gz %changelog +* Tue Jun 27 2023 wxiat - 3.1-23.0.4 +- add sw patch + * Thu Sep 15 2022 Liwei Ge - 3.1-23.0.3 - Link loongarch objects -- Gitee