feat: remove nios2 support upstream/3.4.7
authorAnthony Green <green@moxielogic.com>
Sat, 8 Feb 2025 16:32:05 +0000 (11:32 -0500)
committerAnthony Green <green@moxielogic.com>
Sat, 8 Feb 2025 16:32:05 +0000 (11:32 -0500)
Acked-by: Anthony Green <green@moxielogic.com>
Makefile.am
README.md
configure.host
src/nios2/ffi.c [deleted file]
src/nios2/ffitarget.h [deleted file]
src/nios2/sysv.S [deleted file]
src/prep_cif.c

index 3de0bea4737dff791df08d6b0c2fe357f1532a18..1f8aa9cceaaebe459d259f775fcc5c56f48535b3 100644 (file)
@@ -55,7 +55,7 @@ noinst_HEADERS = src/aarch64/ffitarget.h src/aarch64/internal.h               \
        src/m32r/ffitarget.h src/m68k/ffitarget.h                       \
        src/m88k/ffitarget.h src/metag/ffitarget.h                      \
        src/microblaze/ffitarget.h src/mips/ffitarget.h                 \
-       src/moxie/ffitarget.h src/nios2/ffitarget.h                     \
+       src/moxie/ffitarget.h \
        src/or1k/ffitarget.h src/pa/ffitarget.h                         \
        src/powerpc/ffitarget.h src/powerpc/asm.h                       \
        src/powerpc/ffi_powerpc.h src/riscv/ffitarget.h                 \
@@ -80,7 +80,7 @@ EXTRA_libffi_la_SOURCES = src/aarch64/ffi.c src/aarch64/sysv.S                \
        src/metag/ffi.c src/metag/sysv.S src/microblaze/ffi.c           \
        src/microblaze/sysv.S src/mips/ffi.c src/mips/o32.S             \
        src/mips/n32.S src/moxie/ffi.c src/moxie/eabi.S                 \
-       src/nios2/ffi.c src/nios2/sysv.S src/or1k/ffi.c                 \
+       src/or1k/ffi.c                  \
        src/or1k/sysv.S src/pa/ffi.c src/pa/linux.S src/pa/hpux32.S     \
        src/pa/hpux64.S src/powerpc/ffi.c src/powerpc/ffi_sysv.c        \
        src/powerpc/ffi_linux64.c src/powerpc/sysv.S                    \
index 48f483299bdeba09dc1b58e815232c0fa5c29bf1..0d4c242435f4c216b064fc8f92ea80ae5386a0dc 100644 (file)
--- a/README.md
+++ b/README.md
@@ -76,7 +76,6 @@ tested:
 | MIPS            | RTEMS            | GCC                     |
 | MIPS64          | Linux            | GCC                     |
 | Moxie           | Bare metal       | GCC                     |
-| Nios II         | Linux            | GCC                     |
 | OpenRISC        | Linux            | GCC                     |
 | PowerPC 32-bit  | AIX              | GCC                     |
 | PowerPC 32-bit  | AIX              | IBM XL C                |
@@ -209,6 +208,7 @@ See the git log for details at http://github.com/libffi/libffi.
         Fix x86-64 calls with 6 GP registers and some SSE registers.
         Miscellaneous fixes for ARC and Darwin ARM64.
         Fix OpenRISC or1k and Solaris 10 builds.
+        Remove nios2 port.
 
     3.4.6 Feb-18-2024
         Fix long double regression on mips64 and alpha.
index 4cc69be4fe294ff0c005c15bf575499709ac526f..c69a49cefb028724e62fc1aefdd876a6c4e68b90 100644 (file)
@@ -185,11 +185,6 @@ case "${host}" in
        TARGET=MIPS; TARGETDIR=mips
        ;;
 
-  nios2*-linux*)
-       TARGET=NIOS2; TARGETDIR=nios2
-       SOURCES="ffi.c sysv.S"
-       ;;
-
   or1k*-*-*)
        TARGET=OR1K; TARGETDIR=or1k
        SOURCES="ffi.c sysv.S"
diff --git a/src/nios2/ffi.c b/src/nios2/ffi.c
deleted file mode 100644 (file)
index 721080d..0000000
+++ /dev/null
@@ -1,304 +0,0 @@
-/* libffi support for Altera Nios II.
-
-   Copyright (c) 2013 Mentor Graphics.
-
-   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 <ffi.h>
-#include <ffi_common.h>
-
-#include <stdlib.h>
-
-/* The Nios II Processor Reference Handbook defines the procedure call
-   ABI as follows.
-
-   Arguments are passed as if a structure containing the types of
-   the arguments were constructed.  The first 16 bytes are passed in r4
-   through r7, the remainder on the stack.  The first 16 bytes of a function
-   taking variable arguments are passed in r4-r7 in the same way.
-
-   Return values of types up to 8 bytes are returned in r2 and r3.  For
-   return values greater than 8 bytes, the caller must allocate memory for
-   the result and pass the address as if it were argument 0.  
-
-   While this isn't specified explicitly in the ABI documentation, GCC
-   promotes integral arguments smaller than int size to 32 bits.
-
-   Also of note, the ABI specifies that all structure objects are
-   aligned to 32 bits even if all their fields have a smaller natural
-   alignment.  See FFI_AGGREGATE_ALIGNMENT.  */
-
-
-/* Declare the assembly language hooks.  */
-
-extern UINT64 ffi_call_sysv (void (*) (char *, extended_cif *),
-                            extended_cif *,
-                            unsigned, 
-                            void (*fn) (void));
-extern void ffi_closure_sysv (void);
-
-/* Perform machine-dependent cif processing.  */
-
-ffi_status ffi_prep_cif_machdep (ffi_cif *cif)
-{
-  /* We always want at least 16 bytes in the parameter block since it
-     simplifies the low-level call function.  Also round the parameter
-     block size up to a multiple of 4 bytes to preserve
-     32-bit alignment of the stack pointer.  */
-  if (cif->bytes < 16)
-    cif->bytes = 16;
-  else
-    cif->bytes = (cif->bytes + 3) & ~3;
-
-  return FFI_OK;
-}
-
-
-/* ffi_prep_args is called by the assembly routine to transfer arguments
-   to the stack using the pointers in the ecif array.
-   Note that the stack buffer is big enough to fit all the arguments,
-   but the first 16 bytes will be copied to registers for the actual
-   call.  */
-
-void ffi_prep_args (char *stack, extended_cif *ecif)
-{
-  char *argp = stack;
-  unsigned int i;
-
-  /* The implicit return value pointer is passed as if it were a hidden
-     first argument.  */
-  if (ecif->cif->rtype->type == FFI_TYPE_STRUCT
-      && ecif->cif->rtype->size > 8)
-    {
-      (*(void **) argp) = ecif->rvalue;
-      argp += 4;
-    }
-
-  for (i = 0; i < ecif->cif->nargs; i++)
-    {
-      void *avalue = ecif->avalue[i];
-      ffi_type *atype = ecif->cif->arg_types[i];
-      size_t size = atype->size;
-      size_t alignment = atype->alignment;
-
-      /* Align argp as appropriate for the argument type.  */
-      if ((alignment - 1) & (unsigned) argp)
-       argp = (char *) FFI_ALIGN (argp, alignment);
-
-      /* Copy the argument, promoting integral types smaller than a
-        word to word size.  */
-      if (size < sizeof (int))
-       {
-         size = sizeof (int);
-         switch (atype->type)
-           {
-           case FFI_TYPE_SINT8:
-             *(signed int *) argp = (signed int) *(SINT8 *) avalue;
-             break;
-                 
-           case FFI_TYPE_UINT8:
-             *(unsigned int *) argp = (unsigned int) *(UINT8 *) avalue;
-             break;
-                 
-           case FFI_TYPE_SINT16:
-             *(signed int *) argp = (signed int) *(SINT16 *) avalue;
-             break;
-                 
-           case FFI_TYPE_UINT16:
-             *(unsigned int *) argp = (unsigned int) *(UINT16 *) avalue;
-             break;
-
-           case FFI_TYPE_STRUCT:
-             memcpy (argp, avalue, atype->size);
-             break;
-
-           default:
-             FFI_ASSERT(0);
-           }
-       }
-      else if (size == sizeof (int))
-       *(unsigned int *) argp = (unsigned int) *(UINT32 *) avalue;
-      else
-       memcpy (argp, avalue, size);
-      argp += size;
-    }
-}
-
-
-/* Call FN using the prepared CIF.  RVALUE points to space allocated by
-   the caller for the return value, and AVALUE is an array of argument
-   pointers.  */
-
-void ffi_call (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue)
-{
-
-  extended_cif ecif;
-  UINT64 result;
-
-  /* If bigret is true, this is the case where a return value of larger
-     than 8 bytes is handled by being passed by reference as an implicit
-     argument.  */
-  int bigret = (cif->rtype->type == FFI_TYPE_STRUCT
-               && cif->rtype->size > 8);
-
-  ecif.cif = cif;
-  ecif.avalue = avalue;
-
-  /* Allocate space for return value if this is the pass-by-reference case
-     and the caller did not provide a buffer.  */
-  if (rvalue == NULL && bigret)
-    ecif.rvalue = alloca (cif->rtype->size);
-  else
-    ecif.rvalue = rvalue;
-
-  result = ffi_call_sysv (ffi_prep_args, &ecif, cif->bytes, fn);
-
-  /* Now result contains the 64 bit contents returned from fn in
-     r2 and r3.  Copy the value of the appropriate size to the user-provided
-     rvalue buffer.  */
-  if (rvalue && !bigret)
-    switch (cif->rtype->size)
-      {
-      case 1:
-       *(UINT8 *)rvalue = (UINT8) result;
-       break;
-      case 2:
-       *(UINT16 *)rvalue = (UINT16) result;
-       break;
-      case 4:
-       *(UINT32 *)rvalue = (UINT32) result;
-       break;
-      case 8:
-       *(UINT64 *)rvalue = (UINT64) result;
-       break;
-      default:
-       memcpy (rvalue, (void *)&result, cif->rtype->size);
-       break;
-      }
-}
-
-/* This function is invoked from the closure trampoline to invoke
-   CLOSURE with argument block ARGS.  Parse ARGS according to
-   CLOSURE->cfi and invoke CLOSURE->fun.  */
-
-static UINT64
-ffi_closure_helper (unsigned char *args,
-                   ffi_closure *closure)
-{
-  ffi_cif *cif = closure->cif;
-  unsigned char *argp = args;
-  void **parsed_args = alloca (cif->nargs * sizeof (void *));
-  UINT64 result;
-  void *retptr;
-  unsigned int i;
-
-  /* First figure out what to do about the return type.  If this is the
-     big-structure-return case, the first arg is the hidden return buffer
-     allocated by the caller.  */
-  if (cif->rtype->type == FFI_TYPE_STRUCT
-      && cif->rtype->size > 8)
-    {
-      retptr = *((void **) argp);
-      argp += 4;
-    }
-  else
-    retptr = (void *) &result;
-
-  /* Fill in the array of argument pointers.  */
-  for (i = 0; i < cif->nargs; i++)
-    {
-      size_t size = cif->arg_types[i]->size;
-      size_t alignment = cif->arg_types[i]->alignment;
-
-      /* Align argp as appropriate for the argument type.  */
-      if ((alignment - 1) & (unsigned) argp)
-       argp = (char *) FFI_ALIGN (argp, alignment);
-
-      /* Arguments smaller than an int are promoted to int.  */
-      if (size < sizeof (int))
-       size = sizeof (int);
-
-      /* Store the pointer.  */
-      parsed_args[i] = argp;
-      argp += size;
-    }
-
-  /* Call the user-supplied function.  */
-  (closure->fun) (cif, retptr, parsed_args, closure->user_data);
-  return result;
-}
-
-
-/* Initialize CLOSURE with a trampoline to call FUN with
-   CIF and USER_DATA.  */
-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 = (unsigned int *) &closure->tramp[0];
-  int i;
-
-  if (cif->abi != FFI_SYSV)
-    return FFI_BAD_ABI;
-
-  /* The trampoline looks like:
-       movhi r8, %hi(ffi_closure_sysv)
-       ori r8, r8, %lo(ffi_closure_sysv)
-       movhi r9, %hi(ffi_closure_helper)
-       ori r0, r9, %lo(ffi_closure_helper)
-       movhi r10, %hi(closure)
-       ori r10, r10, %lo(closure)
-       jmp r8
-     and then ffi_closure_sysv retrieves the closure pointer out of r10
-     in addition to the arguments passed in the normal way for the call,
-     and invokes ffi_closure_helper.  We encode the pointer to
-     ffi_closure_helper in the trampoline because making a PIC call
-     to it in ffi_closure_sysv would be messy (it would have to indirect
-     through the GOT).  */
-
-#define HI(x) ((((unsigned int) (x)) >> 16) & 0xffff)
-#define LO(x) (((unsigned int) (x)) & 0xffff)
-  tramp[0] = (0 << 27) | (8 << 22) | (HI (ffi_closure_sysv) << 6) | 0x34;
-  tramp[1] = (8 << 27) | (8 << 22) | (LO (ffi_closure_sysv) << 6) | 0x14;
-  tramp[2] = (0 << 27) | (9 << 22) | (HI (ffi_closure_helper) << 6) | 0x34;
-  tramp[3] = (9 << 27) | (9 << 22) | (LO (ffi_closure_helper) << 6) | 0x14;
-  tramp[4] = (0 << 27) | (10 << 22) | (HI (closure) << 6) | 0x34;
-  tramp[5] = (10 << 27) | (10 << 22) | (LO (closure) << 6) | 0x14;
-  tramp[6] = (8 << 27) | (0x0d << 11) | 0x3a;
-#undef HI
-#undef LO
-
-  /* Flush the caches.
-     See Example 9-4 in the Nios II Software Developer's Handbook.  */
-  for (i = 0; i < 7; i++)
-    asm volatile ("flushd 0(%0); flushi %0" :: "r"(tramp + i) : "memory");
-  asm volatile ("flushp" ::: "memory");
-
-  closure->cif = cif;
-  closure->fun = fun;
-  closure->user_data = user_data;
-
-  return FFI_OK;
-}
-
diff --git a/src/nios2/ffitarget.h b/src/nios2/ffitarget.h
deleted file mode 100644 (file)
index 134d118..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/* libffi target includes for Altera Nios II.
-
-   Copyright (c) 2013 Mentor Graphics.
-
-   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_SYSV,
-  FFI_LAST_ABI,
-  FFI_DEFAULT_ABI = FFI_SYSV
-} ffi_abi;
-#endif
-
-/* Structures have a 4-byte alignment even if all the fields have lesser
-   alignment requirements.  */
-#define FFI_AGGREGATE_ALIGNMENT 4
-
-#define FFI_CLOSURES 1
-#define FFI_TRAMPOLINE_SIZE 28   /* 7 instructions */
-#define FFI_NATIVE_RAW_API 0
-
-#endif
diff --git a/src/nios2/sysv.S b/src/nios2/sysv.S
deleted file mode 100644 (file)
index 75f442b..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/* Low-level libffi support for Altera Nios II.
-
-   Copyright (c) 2013 Mentor Graphics.
-
-   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.  */
-
-/* This function is declared on the C side as 
-
-   extern UINT64 ffi_call_sysv (void (*arghook) (char *, extended_cif *),
-                               extended_cif *ecif,
-                               unsigned nbytes, 
-                               void (*fn) (void));
-       
-   On input, the arguments appear as
-       r4 = arghook
-       r5 = ecif
-       r6 = nbytes
-       r7 = fn
-*/
-
-       .section        .text
-       .align  2
-       .global ffi_call_sysv
-       .type   ffi_call_sysv, @function
-
-ffi_call_sysv:
-       .cfi_startproc
-
-       /* Create the stack frame, saving r16 so we can use it locally.  */
-       addi    sp, sp, -12
-       .cfi_def_cfa_offset 12
-       stw     ra, 8(sp)
-       stw     fp, 4(sp)
-       stw     r16, 0(sp)
-       .cfi_offset 31, -4
-       .cfi_offset 28, -8
-       .cfi_offset 16, -12
-       mov     fp, sp
-       .cfi_def_cfa_register 28
-       mov     r16, r7
-
-       /* Adjust the stack pointer to create the argument buffer
-          nbytes long.  */
-       sub     sp, sp, r6
-
-       /* Call the arghook function.  */
-       mov     r2, r4          /* fn */
-       mov     r4, sp          /* argbuffer */
-       callr   r2              /* r5 already contains ecif */
-
-       /* Pop off the first 16 bytes of the argument buffer on the stack,
-          transferring the contents to the argument registers.  */
-       ldw     r4, 0(sp)
-       ldw     r5, 4(sp)
-       ldw     r6, 8(sp)
-       ldw     r7, 12(sp)
-       addi    sp, sp, 16
-
-       /* Call the user function, which leaves its result in r2 and r3.  */
-       callr   r16
-
-       /* Pop off the stack frame.  */
-       mov     sp, fp
-       ldw     ra, 8(sp)
-       ldw     fp, 4(sp)
-       ldw     r16, 0(sp)
-       addi    sp, sp, 12
-       ret
-       .cfi_endproc
-       .size   ffi_call_sysv, .-ffi_call_sysv
-
-
-/* Closure trampolines jump here after putting the C helper address
-   in r9 and the closure pointer in r10.  The user-supplied arguments
-   to the closure are in the normal places, in r4-r7 and on the
-   stack.  Push the register arguments on the stack too and then call the
-   C helper function to deal with them.  */
-   
-       .section        .text
-       .align  2
-       .global ffi_closure_sysv
-       .type   ffi_closure_sysv, @function
-
-ffi_closure_sysv:
-       .cfi_startproc
-
-       /* Create the stack frame, pushing the register args on the stack
-          just below the stack args.  This is the same trick illustrated
-          in Figure 7-3 in the Nios II Processor Reference Handbook, used
-          for variable arguments and structures passed by value.  */
-       addi    sp, sp, -20
-       .cfi_def_cfa_offset 20
-       stw     ra, 0(sp)
-       .cfi_offset 31, -20
-       stw     r4, 4(sp)
-       .cfi_offset 4, -16
-       stw     r5, 8(sp)
-       .cfi_offset 5, -12
-       stw     r6, 12(sp)
-       .cfi_offset 6, -8
-       stw     r7, 16(sp)
-       .cfi_offset 7, -4
-
-       /* Call the helper.
-          r4 = pointer to arguments on stack
-          r5 = closure pointer (loaded in r10 by the trampoline)
-          r9 = address of helper function (loaded by trampoline) */
-       addi    r4, sp, 4
-       mov     r5, r10
-       callr   r9
-       
-       /* Pop the stack and return.  */
-       ldw     ra, 0(sp)
-       addi    sp, sp, 20
-       .cfi_def_cfa_offset -20
-       ret
-       .cfi_endproc
-       .size   ffi_closure_sysv, .-ffi_closure_sysv
-
index 0e2d58e5e5c1c5d38767156d7e2b06c01e4db50f..47c9259470c5eef70d2a11352f532e923ff4cf53 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------
-   prep_cif.c - Copyright (c) 2011, 2012, 2021  Anthony Green
+   prep_cif.c - Copyright (c) 2011, 2012, 2021, 2025  Anthony Green
                 Copyright (c) 1996, 1998, 2007  Red Hat, Inc.
                 Copyright (c) 2022 Oracle and/or its affiliates.
 
@@ -158,9 +158,6 @@ ffi_status FFI_HIDDEN ffi_prep_cif_core(ffi_cif *cif, ffi_abi abi,
 #endif
 #ifdef XTENSA
       && (cif->rtype->size > 16)
-#endif
-#ifdef NIOS2
-      && (cif->rtype->size > 8)
 #endif
      )
     bytes = STACK_ARG_SIZE(sizeof(void*));