All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] or1k: Add support for a little-endian target variant
@ 2022-06-09  6:03 Samuel Holland
  2022-06-09 11:29 ` Stafford Horne
  0 siblings, 1 reply; 7+ messages in thread
From: Samuel Holland @ 2022-06-09  6:03 UTC (permalink / raw)
  To: gcc-patches; +Cc: openrisc

While not officially sanctioned by the architecture spec, little-endian
or1k processors do exist in the wild, for example the Allwinner AR100.
Let's add native support for this, instead of hacks like using objcopy
to byteswap ELF file contents.

gcc/ChangeLog:

	* config.gcc: Set TARGET_LITTLE_ENDIAN_DEFAULT from target.
	* config/or1k/elf.h (LINK_SPEC): Pass -EB/-EL to the linker.
	* config/or1k/linux.h (LINK_SPEC): Pass -EB/-EL to the linker.
	* config/or1k/or1k.h (ENDIAN_SPEC): Set default endianness.
	(DRIVER_SELF_SPECS): Set default endianness.
	(ASM_SPEC): Pass -EB/-EL to the assembler.
	(LINK_SPEC): Pass -EB/-EL to the linker.
	(BYTES_BIG_ENDIAN): Make dependent on TARGET_BIG_ENDIAN.
	(WORDS_BIG_ENDIAN): Likewise.
	* config/or1k/or1k.opt: Add -mbig-endian/-mlittle-endian.

libgcc/ChangeLog:

	* config.host (or1k): Generalize arch to or1k*.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---
 gcc/config.gcc           |  5 +++++
 gcc/config/or1k/elf.h    |  1 +
 gcc/config/or1k/linux.h  |  1 +
 gcc/config/or1k/or1k.h   | 19 +++++++++++++++++--
 gcc/config/or1k/or1k.opt |  8 ++++++++
 libgcc/config.host       |  4 ++--
 6 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index c5064dd37666..0c3a09dfe810 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2866,6 +2866,11 @@ or1k*-*-*)
 	done
 	TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'`
 
+	case ${target} in
+	or1k*le*-*)
+		tm_defines="${tm_defines} TARGET_LITTLE_ENDIAN_DEFAULT=1"
+		;;
+	esac
 	case ${target} in
 	or1k*-*-linux*)
 		tm_file="${tm_file} gnu-user.h linux.h glibc-stdint.h"
diff --git a/gcc/config/or1k/elf.h b/gcc/config/or1k/elf.h
index d3d27028aa37..44c0a0687c7f 100644
--- a/gcc/config/or1k/elf.h
+++ b/gcc/config/or1k/elf.h
@@ -27,6 +27,7 @@
 
 #undef	LINK_SPEC
 #define LINK_SPEC "%{h*}			\
+   %{mbig-endian:-EB} %{mlittle-endian:-EL}	\
    %{static:-Bstatic}				\
    %{shared:-shared}				\
    %{symbolic:-Bsymbolic}			\
diff --git a/gcc/config/or1k/linux.h b/gcc/config/or1k/linux.h
index 80f77c722322..8fe8b0168b11 100644
--- a/gcc/config/or1k/linux.h
+++ b/gcc/config/or1k/linux.h
@@ -36,6 +36,7 @@
 
 #undef LINK_SPEC
 #define LINK_SPEC "%{h*}			\
+   %{mbig-endian:-EB} %{mlittle-endian:-EL}	\
    %{static:-Bstatic}				\
    %{shared:-shared}				\
    %{symbolic:-Bsymbolic}			\
diff --git a/gcc/config/or1k/or1k.h b/gcc/config/or1k/or1k.h
index 18a526d386f1..b5e4a2181336 100644
--- a/gcc/config/or1k/or1k.h
+++ b/gcc/config/or1k/or1k.h
@@ -23,6 +23,21 @@
 
 #include "config/or1k/or1k-opts.h"
 
+#ifndef TARGET_LITTLE_ENDIAN_DEFAULT
+#define ENDIAN_SPEC "-mbig-endian"
+#else
+#define ENDIAN_SPEC "-mlittle-endian"
+#endif
+
+/* Force the default endianness and ABI flags onto the command line
+   in order to make the other specs easier to write.  */
+#undef DRIVER_SELF_SPECS
+#define DRIVER_SELF_SPECS \
+  " %{!mbig-endian:%{!mlittle-endian:" ENDIAN_SPEC "}}"
+
+#define ASM_SPEC "%{mbig-endian:-EB} %{mlittle-endian:-EL}"
+#define LINK_SPEC "%{mbig-endian:-EB} %{mlittle-endian:-EL}"
+
 /* Names to predefine in the preprocessor for this target machine.  */
 #define TARGET_CPU_CPP_BUILTINS()		\
   do						\
@@ -48,8 +63,8 @@
 
 #define DEFAULT_SIGNED_CHAR 1
 #define BITS_BIG_ENDIAN 0
-#define BYTES_BIG_ENDIAN 1
-#define WORDS_BIG_ENDIAN 1
+#define BYTES_BIG_ENDIAN (TARGET_BIG_ENDIAN)
+#define WORDS_BIG_ENDIAN (TARGET_BIG_ENDIAN)
 #define BITS_PER_WORD 32
 #define UNITS_PER_WORD 4
 #define POINTER_SIZE 32
diff --git a/gcc/config/or1k/or1k.opt b/gcc/config/or1k/or1k.opt
index 8a66832a99b1..497f259faae9 100644
--- a/gcc/config/or1k/or1k.opt
+++ b/gcc/config/or1k/or1k.opt
@@ -24,6 +24,14 @@
 HeaderInclude
 config/or1k/or1k-opts.h
 
+mbig-endian
+Target Report RejectNegative Mask(BIG_ENDIAN)
+Use big-endian byte order.
+
+mlittle-endian
+Target Report RejectNegative InverseMask(BIG_ENDIAN, LITTLE_ENDIAN)
+Use little-endian byte order.
+
 mhard-div
 Target RejectNegative InverseMask(SOFT_DIV)
 Enable generation of hardware divide (l.div, l.divu) instructions.  This is the
diff --git a/libgcc/config.host b/libgcc/config.host
index 8c56fcae5d2f..45c8d1a47d9a 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -1144,12 +1144,12 @@ nios2-*-*)
 	tmake_file="$tmake_file nios2/t-nios2 t-softfp-sfdf t-softfp-excl t-softfp"
 	extra_parts="$extra_parts crti.o crtn.o"
 	;;
-or1k-*-linux*)
+or1k*-*-linux*)
 	tmake_file="$tmake_file or1k/t-or1k or1k/t-crtstuff"
 	tmake_file="$tmake_file t-softfp-sfdf t-softfp"
 	md_unwind_header=or1k/linux-unwind.h
 	;;
-or1k-*-*)
+or1k*-*-*)
 	tmake_file="$tmake_file or1k/t-or1k or1k/t-crtstuff"
 	tmake_file="$tmake_file t-softfp-sfdf t-softfp"
 	;;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] or1k: Add support for a little-endian target variant
  2022-06-09  6:03 [PATCH] or1k: Add support for a little-endian target variant Samuel Holland
@ 2022-06-09 11:29 ` Stafford Horne
  2022-06-10  2:07   ` Samuel Holland
  0 siblings, 1 reply; 7+ messages in thread
From: Stafford Horne @ 2022-06-09 11:29 UTC (permalink / raw)
  To: Samuel Holland; +Cc: openrisc, gcc-patches

> diff --git a/gcc/config.gcc b/gcc/config.gcc
> index c5064dd37666..0c3a09dfe810 100644
> --- a/gcc/config.gcc
> +++ b/gcc/config.gcc
> @@ -2866,6 +2866,11 @@ or1k*-*-*)
>  	done
>  	TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'`
>  
> +	case ${target} in
> +	or1k*le*-*)

Should this be just or1kle*-*?

> +		tm_defines="${tm_defines} TARGET_LITTLE_ENDIAN_DEFAULT=1"
> +		;;
> +	esac
>  	case ${target} in
>  	or1k*-*-linux*)
>  		tm_file="${tm_file} gnu-user.h linux.h glibc-stdint.h"


> diff --git a/gcc/config/or1k/or1k.opt b/gcc/config/or1k/or1k.opt
> index 8a66832a99b1..497f259faae9 100644
> --- a/gcc/config/or1k/or1k.opt
> +++ b/gcc/config/or1k/or1k.opt
> @@ -24,6 +24,14 @@
>  HeaderInclude
>  config/or1k/or1k-opts.h
>  
> +mbig-endian
> +Target Report RejectNegative Mask(BIG_ENDIAN)
> +Use big-endian byte order.
> +
> +mlittle-endian
> +Target Report RejectNegative InverseMask(BIG_ENDIAN, LITTLE_ENDIAN)
> +Use little-endian byte order.
> +

We should explain what is the default int he doc's.

Can you also document in: gcc/doc/invoke.texi

This looks good, thank you.

-Stafford

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] or1k: Add support for a little-endian target variant
  2022-06-09 11:29 ` Stafford Horne
@ 2022-06-10  2:07   ` Samuel Holland
  0 siblings, 0 replies; 7+ messages in thread
From: Samuel Holland @ 2022-06-10  2:07 UTC (permalink / raw)
  To: Stafford Horne; +Cc: openrisc, gcc-patches

Hi Stafford,

On 6/9/22 6:29 AM, Stafford Horne wrote:
>> diff --git a/gcc/config.gcc b/gcc/config.gcc
>> index c5064dd37666..0c3a09dfe810 100644
>> --- a/gcc/config.gcc
>> +++ b/gcc/config.gcc
>> @@ -2866,6 +2866,11 @@ or1k*-*-*)
>>  	done
>>  	TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'`
>>  
>> +	case ${target} in
>> +	or1k*le*-*)
> 
> Should this be just or1kle*-*?

I wasn't sure what the order of "le" and "nd" would be if both were present.

>> +		tm_defines="${tm_defines} TARGET_LITTLE_ENDIAN_DEFAULT=1"
>> +		;;
>> +	esac
>>  	case ${target} in
>>  	or1k*-*-linux*)
>>  		tm_file="${tm_file} gnu-user.h linux.h glibc-stdint.h"
> 
> 
>> diff --git a/gcc/config/or1k/or1k.opt b/gcc/config/or1k/or1k.opt
>> index 8a66832a99b1..497f259faae9 100644
>> --- a/gcc/config/or1k/or1k.opt
>> +++ b/gcc/config/or1k/or1k.opt
>> @@ -24,6 +24,14 @@
>>  HeaderInclude
>>  config/or1k/or1k-opts.h
>>  
>> +mbig-endian
>> +Target Report RejectNegative Mask(BIG_ENDIAN)
>> +Use big-endian byte order.
>> +
>> +mlittle-endian
>> +Target Report RejectNegative InverseMask(BIG_ENDIAN, LITTLE_ENDIAN)
>> +Use little-endian byte order.
>> +
> 
> We should explain what is the default int he doc's.
> 
> Can you also document in: gcc/doc/invoke.texi

Yes, I will do that for v2.

Regards,
Samuel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] or1k: Add support for a little-endian target variant
  2022-06-09 11:21 ` Stafford Horne
  2022-06-10  1:00   ` Alan Modra
@ 2022-06-10  1:39   ` Samuel Holland
  1 sibling, 0 replies; 7+ messages in thread
From: Samuel Holland @ 2022-06-10  1:39 UTC (permalink / raw)
  To: Stafford Horne; +Cc: openrisc, binutils

Hi Stafford,

Thanks for the review.

On 6/9/22 6:21 AM, Stafford Horne wrote:
> On Thu, Jun 09, 2022 at 01:01:33AM -0500, Samuel Holland wrote:
>> While not officially sanctioned by the architecture spec, little-endian
>> or1k processors do exist in the wild, for example the Allwinner AR100.
>> Let's add native support for this, instead of hacks like using objcopy
>> to byteswap ELF file contents.
> 
> Hello,
> 
> In general I have no objections to this.  If there are processors that
> are little endian it makes sense to support it.  Do you have any details
> of how people built for these before? I am curious.

We post-process the binary with "objcopy --reverse-bytes 4".

https://github.com/crust-firmware/crust/blob/master/Makefile#L193
https://github.com/intelligent-agent/klipper/blob/master/src/ar100/Makefile#L39
https://github.com/nfeske/genode-allwinner/blob/scp/src/scp/Makefile#L22

The processor has both a word-invariant mode (the default), and a byte-invariant
mode:

https://linux-sunxi.org/AR100#Byte-invariant_Ranges

With a big-endian toolchain, in the word-invariant mode, all GCC optimizations
work fine, but sharing data with other software is painful. Sub-32-bit memory
accesses are reversed within each group of 4 bytes, which affects strings and
struct layouts.

In the byte-invariant mode, sharing strings and structs causes no problems, but
some GCC optimizations like -fstore-merging are broken.

>> diff --git a/gas/config/tc-or1k.c b/gas/config/tc-or1k.c
>> index ae4e3452f48..9dc5a46f2e2 100644
>> --- a/gas/config/tc-or1k.c
>> +++ b/gas/config/tc-or1k.c
>> @@ -58,8 +58,16 @@ const char FLT_CHARS[]            = "dD";
>>  #define OR1K_SHORTOPTS "m:"
>>  const char * md_shortopts = OR1K_SHORTOPTS;
>>  
>> +enum
>> +{
>> +  OPTION_LITTLE_ENDIAN = OPTION_MD_BASE,
>> +  OPTION_BIG_ENDIAN
>> +};
>> +
>>  struct option md_longopts[] =
>>  {
>> +  {"EB", no_argument, NULL, OPTION_BIG_ENDIAN},
>> +  {"EL", no_argument, NULL, OPTION_LITTLE_ENDIAN},
>>    {NULL, no_argument, NULL, 0}
>>  };
>>  size_t md_longopts_size = sizeof (md_longopts);
>> @@ -67,14 +75,30 @@ size_t md_longopts_size = sizeof (md_longopts);
>>  unsigned long or1k_machine = 0; /* default */
>>  
>>  int
>> -md_parse_option (int c ATTRIBUTE_UNUSED, const char * arg ATTRIBUTE_UNUSED)
>> +md_parse_option (int c, const char * arg ATTRIBUTE_UNUSED)
>>  {
>> -  return 0;
>> +  switch (c)
>> +    {
>> +    case OPTION_BIG_ENDIAN:
>> +      target_big_endian = 1;
>> +      break;
>> +    case OPTION_LITTLE_ENDIAN:
>> +      target_big_endian = 0;
>> +      break;
>> +    default:
>> +      return 0;
>> +    }
>> +
>> +  return 1;
>>  }
>>  
>>  void
>> -md_show_usage (FILE * stream ATTRIBUTE_UNUSED)
>> +md_show_usage (FILE * stream)
>>  {
>> +  fprintf (stream, _(" OR1K-specific assembler options:\n"));
>> +  fprintf (stream, _("\
>> +  --EB			generate code for a big endian machine\n\
>> +  --EL			generate code for a little endian machine\n"));
>>  }
> 
> Aboce you mention -EB, -EL, here is is --EB, --EL.

They are long options. I will fix the changelog.

> Does this setup big endian as the default?  We should specify that in the
> options.  i.e. "generate code for a big endian machine, this is the default."
> 
> But I am not sure how that defaulting works now.  I will try to build this
> and understand better.

The default depends on the target. It comes from gas/configure.tgt.

Regards,
Samuel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] or1k: Add support for a little-endian target variant
  2022-06-09 11:21 ` Stafford Horne
@ 2022-06-10  1:00   ` Alan Modra
  2022-06-10  1:39   ` Samuel Holland
  1 sibling, 0 replies; 7+ messages in thread
From: Alan Modra @ 2022-06-10  1:00 UTC (permalink / raw)
  To: Stafford Horne; +Cc: openrisc, binutils

On Thu, Jun 09, 2022 at 08:21:19PM +0900, Stafford Horne via Binutils wrote:
> In general I have no objections to this.  If there are processors that
> hare little endian it makes sense to support it.  Do you have any details
> of how people built for these before? I am curious.

The patch looks fine to me too, except that I suspect the testsuite
needs updating for little-endian.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] or1k: Add support for a little-endian target variant
  2022-06-09  6:01 Samuel Holland
@ 2022-06-09 11:21 ` Stafford Horne
  2022-06-10  1:00   ` Alan Modra
  2022-06-10  1:39   ` Samuel Holland
  0 siblings, 2 replies; 7+ messages in thread
From: Stafford Horne @ 2022-06-09 11:21 UTC (permalink / raw)
  To: Samuel Holland; +Cc: openrisc, binutils

On Thu, Jun 09, 2022 at 01:01:33AM -0500, Samuel Holland wrote:
> While not officially sanctioned by the architecture spec, little-endian
> or1k processors do exist in the wild, for example the Allwinner AR100.
> Let's add native support for this, instead of hacks like using objcopy
> to byteswap ELF file contents.

Hello,

In general I have no objections to this.  If there are processors that
hare little endian it makes sense to support it.  Do you have any details
of how people built for these before? I am curious.

> diff --git a/gas/config/tc-or1k.c b/gas/config/tc-or1k.c
> index ae4e3452f48..9dc5a46f2e2 100644
> --- a/gas/config/tc-or1k.c
> +++ b/gas/config/tc-or1k.c
> @@ -58,8 +58,16 @@ const char FLT_CHARS[]            = "dD";
>  #define OR1K_SHORTOPTS "m:"
>  const char * md_shortopts = OR1K_SHORTOPTS;
>  
> +enum
> +{
> +  OPTION_LITTLE_ENDIAN = OPTION_MD_BASE,
> +  OPTION_BIG_ENDIAN
> +};
> +
>  struct option md_longopts[] =
>  {
> +  {"EB", no_argument, NULL, OPTION_BIG_ENDIAN},
> +  {"EL", no_argument, NULL, OPTION_LITTLE_ENDIAN},
>    {NULL, no_argument, NULL, 0}
>  };
>  size_t md_longopts_size = sizeof (md_longopts);
> @@ -67,14 +75,30 @@ size_t md_longopts_size = sizeof (md_longopts);
>  unsigned long or1k_machine = 0; /* default */
>  
>  int
> -md_parse_option (int c ATTRIBUTE_UNUSED, const char * arg ATTRIBUTE_UNUSED)
> +md_parse_option (int c, const char * arg ATTRIBUTE_UNUSED)
>  {
> -  return 0;
> +  switch (c)
> +    {
> +    case OPTION_BIG_ENDIAN:
> +      target_big_endian = 1;
> +      break;
> +    case OPTION_LITTLE_ENDIAN:
> +      target_big_endian = 0;
> +      break;
> +    default:
> +      return 0;
> +    }
> +
> +  return 1;
>  }
>  
>  void
> -md_show_usage (FILE * stream ATTRIBUTE_UNUSED)
> +md_show_usage (FILE * stream)
>  {
> +  fprintf (stream, _(" OR1K-specific assembler options:\n"));
> +  fprintf (stream, _("\
> +  --EB			generate code for a big endian machine\n\
> +  --EL			generate code for a little endian machine\n"));
>  }

Aboce you mention -EB, -EL, here is is --EB, --EL.

Does this setup big endian as the default?  We should specify that in the
options.  i.e. "generate code for a big endian machine, this is the default."

But I am not sure how that defaulting works now.  I will try to build this
and understand better.

-Stafford

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] or1k: Add support for a little-endian target variant
@ 2022-06-09  6:01 Samuel Holland
  2022-06-09 11:21 ` Stafford Horne
  0 siblings, 1 reply; 7+ messages in thread
From: Samuel Holland @ 2022-06-09  6:01 UTC (permalink / raw)
  To: binutils; +Cc: openrisc

While not officially sanctioned by the architecture spec, little-endian
or1k processors do exist in the wild, for example the Allwinner AR100.
Let's add native support for this, instead of hacks like using objcopy
to byteswap ELF file contents.

bfd/
	* config.bfd (or1k): Split out or1k_elf32_{be,le}vec. Accept
	  or1kle* target variant.
	* configure (or1k): Split out or1k_elf32_{be,le}vec.
	* configure.ac (or1k): Likewise.
	* elf32-or1k.c: Likewise.
	* targets.c: Likewise.

gas/
	* tc-or1k.c: Add -EB and -EL options. Support dynamic endianness
	  selection.
	* tc-or1k.h: Support dynamic endianness selection.
	* configure (or1k): Generalize arch to or1k*.
	* configure.ac (or1k): Likewise.
	* configure.tgt (or1k): Select default endianness from target.

ld/
	* configure.tgt (or1k): Generalize arch to or1k*.
	* emulparams/elf32or1k.sh: Split out big/little target variants.
	* testsuite/ld-elf/binutils.exp: Generalize arch to or1k*.
	* testsuite/ld-ifunc/ifunc.exp: Generalize arch to or1k*.

opcodes/
	* or1k-opc.h: Make CGEN_DIS_HASH endianness-agnostic.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---
 bfd/config.bfd                   | 12 +++++----
 bfd/configure                    |  3 ++-
 bfd/configure.ac                 |  3 ++-
 bfd/elf32-or1k.c                 |  5 +++-
 bfd/targets.c                    |  6 +++--
 gas/config/tc-or1k.c             | 42 ++++++++++++++++++++++++++------
 gas/config/tc-or1k.h             |  5 +++-
 gas/configure                    |  2 +-
 gas/configure.ac                 |  2 +-
 gas/configure.tgt                |  7 ++++--
 ld/configure.tgt                 |  4 +--
 ld/emulparams/elf32or1k.sh       |  4 ++-
 ld/testsuite/ld-elf/binutils.exp |  2 +-
 ld/testsuite/ld-ifunc/ifunc.exp  |  2 +-
 opcodes/or1k-opc.h               |  2 +-
 15 files changed, 73 insertions(+), 28 deletions(-)

diff --git a/bfd/config.bfd b/bfd/config.bfd
index cfe58247882..d42fea46077 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -208,7 +208,7 @@ mips*)		 targ_archs=bfd_mips_arch ;;
 nds32*)		 targ_archs=bfd_nds32_arch ;;
 nfp)		 targ_archs=bfd_nfp_arch ;;
 nios2*)          targ_archs=bfd_nios2_arch ;;
-or1k*|or1knd*)	 targ_archs=bfd_or1k_arch ;;
+or1k*)		 targ_archs=bfd_or1k_arch ;;
 pdp11*)		 targ_archs=bfd_pdp11_arch ;;
 pj*)		 targ_archs="bfd_pj_arch bfd_i386_arch";;
 powerpc*)	 targ_archs="bfd_rs6000_arch bfd_powerpc_arch" ;;
@@ -1046,12 +1046,14 @@ case "${targ}" in
     targ_selvecs=nios2_elf32_be_vec
     ;;
 
-  or1k-*-elf | or1k-*-linux* | or1k-*-rtems*)
-    targ_defvec=or1k_elf32_vec
+  or1kle*-*-elf | or1kle*-*-linux* | or1kle*-*-rtems*)
+    targ_defvec=or1k_elf32_le_vec
+    targ_selvecs=or1k_elf32_be_vec
     ;;
 
-  or1knd-*-elf | or1knd-*-linux* | or1knd-*-rtems*)
-    targ_defvec=or1k_elf32_vec
+  or1k*-*-elf | or1k*-*-linux* | or1k*-*-rtems*)
+    targ_defvec=or1k_elf32_be_vec
+    targ_selvecs=or1k_elf32_le_vec
     ;;
 
   pdp11-*-*)
diff --git a/bfd/configure b/bfd/configure
index b23c9eebfd7..3f6c5aaabc9 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -13515,7 +13515,8 @@ do
     nios2_elf32_le_vec)		 tb="$tb elf32-nios2.lo elf32.lo $elf" ;;
     ns32k_aout_pc532mach_vec)	 tb="$tb pc532-mach.lo aout-ns32k.lo" ;;
     ns32k_aout_pc532nbsd_vec)	 tb="$tb ns32knetbsd.lo aout-ns32k.lo" ;;
-    or1k_elf32_vec)		 tb="$tb elf32-or1k.lo elf32.lo $elf" ;;
+    or1k_elf32_be_vec)		 tb="$tb elf32-or1k.lo elf32.lo $elf" ;;
+    or1k_elf32_le_vec)		 tb="$tb elf32-or1k.lo elf32.lo $elf" ;;
     pdp11_aout_vec)		 tb="$tb pdp11.lo" ;;
     pef_vec)			 tb="$tb pef.lo" ;;
     pef_xlib_vec)		 tb="$tb pef.lo" ;;
diff --git a/bfd/configure.ac b/bfd/configure.ac
index a9078965c40..1998603a414 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -594,7 +594,8 @@ do
     nios2_elf32_le_vec)		 tb="$tb elf32-nios2.lo elf32.lo $elf" ;;
     ns32k_aout_pc532mach_vec)	 tb="$tb pc532-mach.lo aout-ns32k.lo" ;;
     ns32k_aout_pc532nbsd_vec)	 tb="$tb ns32knetbsd.lo aout-ns32k.lo" ;;
-    or1k_elf32_vec)		 tb="$tb elf32-or1k.lo elf32.lo $elf" ;;
+    or1k_elf32_be_vec)		 tb="$tb elf32-or1k.lo elf32.lo $elf" ;;
+    or1k_elf32_le_vec)		 tb="$tb elf32-or1k.lo elf32.lo $elf" ;;
     pdp11_aout_vec)		 tb="$tb pdp11.lo" ;;
     pef_vec)			 tb="$tb pef.lo" ;;
     pef_xlib_vec)		 tb="$tb pef.lo" ;;
diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c
index 192e83aa7bc..c080402b3c4 100644
--- a/bfd/elf32-or1k.c
+++ b/bfd/elf32-or1k.c
@@ -3356,9 +3356,12 @@ or1k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
 #define ELF_TARGET_ID			OR1K_ELF_DATA
 #define ELF_MAXPAGESIZE			0x2000
 
-#define TARGET_BIG_SYM			or1k_elf32_vec
+#define TARGET_BIG_SYM			or1k_elf32_be_vec
 #define TARGET_BIG_NAME			"elf32-or1k"
 
+#define TARGET_LITTLE_SYM		or1k_elf32_le_vec
+#define TARGET_LITTLE_NAME		"elf32-or1kle"
+
 #define elf_info_to_howto_rel		NULL
 #define elf_info_to_howto		or1k_info_to_howto_rela
 #define elf_backend_relocate_section	or1k_elf_relocate_section
diff --git a/bfd/targets.c b/bfd/targets.c
index 18fec45f02a..e9ed5104414 100644
--- a/bfd/targets.c
+++ b/bfd/targets.c
@@ -835,7 +835,8 @@ extern const bfd_target nios2_elf32_be_vec;
 extern const bfd_target nios2_elf32_le_vec;
 extern const bfd_target ns32k_aout_pc532mach_vec;
 extern const bfd_target ns32k_aout_pc532nbsd_vec;
-extern const bfd_target or1k_elf32_vec;
+extern const bfd_target or1k_elf32_be_vec;
+extern const bfd_target or1k_elf32_le_vec;
 extern const bfd_target pdp11_aout_vec;
 extern const bfd_target pef_vec;
 extern const bfd_target pef_xlib_vec;
@@ -1219,7 +1220,8 @@ static const bfd_target * const _bfd_target_vector[] =
 	&ns32k_aout_pc532mach_vec,
 	&ns32k_aout_pc532nbsd_vec,
 
-	&or1k_elf32_vec,
+	&or1k_elf32_be_vec,
+	&or1k_elf32_le_vec,
 
 	&pdp11_aout_vec,
 
diff --git a/gas/config/tc-or1k.c b/gas/config/tc-or1k.c
index ae4e3452f48..9dc5a46f2e2 100644
--- a/gas/config/tc-or1k.c
+++ b/gas/config/tc-or1k.c
@@ -58,8 +58,16 @@ const char FLT_CHARS[]            = "dD";
 #define OR1K_SHORTOPTS "m:"
 const char * md_shortopts = OR1K_SHORTOPTS;
 
+enum
+{
+  OPTION_LITTLE_ENDIAN = OPTION_MD_BASE,
+  OPTION_BIG_ENDIAN
+};
+
 struct option md_longopts[] =
 {
+  {"EB", no_argument, NULL, OPTION_BIG_ENDIAN},
+  {"EL", no_argument, NULL, OPTION_LITTLE_ENDIAN},
   {NULL, no_argument, NULL, 0}
 };
 size_t md_longopts_size = sizeof (md_longopts);
@@ -67,14 +75,30 @@ size_t md_longopts_size = sizeof (md_longopts);
 unsigned long or1k_machine = 0; /* default */
 
 int
-md_parse_option (int c ATTRIBUTE_UNUSED, const char * arg ATTRIBUTE_UNUSED)
+md_parse_option (int c, const char * arg ATTRIBUTE_UNUSED)
 {
-  return 0;
+  switch (c)
+    {
+    case OPTION_BIG_ENDIAN:
+      target_big_endian = 1;
+      break;
+    case OPTION_LITTLE_ENDIAN:
+      target_big_endian = 0;
+      break;
+    default:
+      return 0;
+    }
+
+  return 1;
 }
 
 void
-md_show_usage (FILE * stream ATTRIBUTE_UNUSED)
+md_show_usage (FILE * stream)
 {
+  fprintf (stream, _(" OR1K-specific assembler options:\n"));
+  fprintf (stream, _("\
+  --EB			generate code for a big endian machine\n\
+  --EL			generate code for a little endian machine\n"));
 }
 
 static void
@@ -111,9 +135,10 @@ md_begin (void)
 
   /* Set the machine number and endian.  */
   gas_cgen_cpu_desc = or1k_cgen_cpu_open (CGEN_CPU_OPEN_MACHS, 0,
-                                              CGEN_CPU_OPEN_ENDIAN,
-                                              CGEN_ENDIAN_BIG,
-                                              CGEN_CPU_OPEN_END);
+                                          CGEN_CPU_OPEN_ENDIAN,
+                                          target_big_endian ?
+                                          CGEN_ENDIAN_BIG : CGEN_ENDIAN_LITTLE,
+                                          CGEN_CPU_OPEN_END);
   or1k_cgen_init_asm (gas_cgen_cpu_desc);
 
   /* This is a callback from cgen to gas to parse operands.  */
@@ -268,7 +293,10 @@ md_cgen_lookup_reloc (const CGEN_INSN *    insn ATTRIBUTE_UNUSED,
 void
 md_number_to_chars (char * buf, valueT val, int n)
 {
-  number_to_chars_bigendian (buf, val, n);
+  if (target_big_endian)
+    number_to_chars_bigendian (buf, val, n);
+  else
+    number_to_chars_littleendian (buf, val, n);
 }
 
 /* Turn a string in input_line_pointer into a floating point constant of type
diff --git a/gas/config/tc-or1k.h b/gas/config/tc-or1k.h
index dd4f7c837c7..6d81b01db7a 100644
--- a/gas/config/tc-or1k.h
+++ b/gas/config/tc-or1k.h
@@ -26,8 +26,11 @@
 extern unsigned long or1k_machine;
 #define TARGET_MACH (or1k_machine)
 
-#define TARGET_FORMAT           "elf32-or1k"
+#define TARGET_FORMAT           (target_big_endian ? "elf32-or1k" : "elf32-or1kle")
+
+#ifndef TARGET_BYTES_BIG_ENDIAN
 #define TARGET_BYTES_BIG_ENDIAN 1
+#endif
 
 extern const char or1k_comment_chars [];
 #define tc_comment_chars or1k_comment_chars
diff --git a/gas/configure b/gas/configure
index dc6a6682aa4..9ea95a3396b 100755
--- a/gas/configure
+++ b/gas/configure
@@ -12684,7 +12684,7 @@ esac
 cgen_cpu_prefix=""
 if test $using_cgen = yes ; then
   case ${target_cpu} in
-    or1knd)
+    or1k*)
        cgen_cpu_prefix=or1k ;;
     *) cgen_cpu_prefix=${target_cpu} ;;
   esac
diff --git a/gas/configure.ac b/gas/configure.ac
index 572e56e281c..03786ed073b 100644
--- a/gas/configure.ac
+++ b/gas/configure.ac
@@ -812,7 +812,7 @@ esac
 cgen_cpu_prefix=""
 if test $using_cgen = yes ; then
   case ${target_cpu} in
-    or1knd)
+    or1k*)
        cgen_cpu_prefix=or1k ;;
     *) cgen_cpu_prefix=${target_cpu} ;;
   esac
diff --git a/gas/configure.tgt b/gas/configure.tgt
index 62f806bdfe8..f4f6e6c216a 100644
--- a/gas/configure.tgt
+++ b/gas/configure.tgt
@@ -86,7 +86,8 @@ case ${cpu} in
   mt)			cpu_type=mt endian=big ;;
   nds32be)		cpu_type=nds32 endian=big ;;
   nds32le)		cpu_type=nds32 endian=little ;;
-  or1k* | or1knd*)	cpu_type=or1k endian=big ;;
+  or1kle*)		cpu_type=or1k endian=little ;;
+  or1k*)		cpu_type=or1k endian=big ;;
   pjl*)			cpu_type=pj endian=little ;;
   pj*)			cpu_type=pj endian=big ;;
   powerpc*le*)		cpu_type=ppc endian=little ;;
@@ -349,7 +350,9 @@ case ${generic_target} in
   ns32k-pc532-lites*)			fmt=aout em=nbsd532 ;;
   ns32k-*-*n*bsd*)			fmt=aout em=nbsd532 ;;
 
+  or1kle*-*-elf | or1kle*-*-rtems*) 	fmt=elf endian=little ;;
   or1k*-*-elf | or1k*-*-rtems*) 	fmt=elf endian=big ;;
+  or1kle*-*-linux*)			fmt=elf em=linux endian=little ;;
   or1k*-*-linux*)			fmt=elf em=linux endian=big ;;
 
   pj*)					fmt=elf ;;
@@ -447,7 +450,7 @@ esac
 
 case ${cpu_type} in
   aarch64 | alpha | arm | csky | i386 | ia64 | microblaze | mips | ns32k | \
-  or1k | or1knd | pdp11 | ppc | riscv | sh | sparc | z80 | z8k | loongarch)
+  or1k | pdp11 | ppc | riscv | sh | sparc | z80 | z8k | loongarch)
     bfd_gas=yes
     ;;
 esac
diff --git a/ld/configure.tgt b/ld/configure.tgt
index c7acf3f11ff..6ab4dceb6be 100644
--- a/ld/configure.tgt
+++ b/ld/configure.tgt
@@ -621,10 +621,10 @@ ns32k-pc532-mach* | ns32k-pc532-ux*)  targ_emul=pc532macha
 ns32k-*-*bsd* | ns32k-pc532-lites*) targ_emul=ns32knbsd
 			targ_extra_ofiles=
 			;;
-or1k-*-elf | or1knd-*-elf | or1k-*-rtems* | or1knd-*-rtems*)
+or1k*-*-elf | or1k*-*-rtems*)
 			targ_emul=elf32or1k
 			;;
-or1k-*-linux* | or1knd-*-linux*)	targ_emul=elf32or1k_linux
+or1k*-*-linux*)		targ_emul=elf32or1k_linux
 			;;
 pdp11-*-*)		targ_emul=pdp11
 			targ_extra_ofiles=
diff --git a/ld/emulparams/elf32or1k.sh b/ld/emulparams/elf32or1k.sh
index 48d2ecfa2b0..ccf940dc1b4 100644
--- a/ld/emulparams/elf32or1k.sh
+++ b/ld/emulparams/elf32or1k.sh
@@ -1,7 +1,9 @@
 SCRIPT_NAME=elf
 MACHINE=
 TEMPLATE_NAME=elf
-OUTPUT_FORMAT="elf32-or1k"
+BIG_OUTPUT_FORMAT="elf32-or1k"
+LITTLE_OUTPUT_FORMAT="elf32-or1kle"
+OUTPUT_FORMAT="$BIG_OUTPUT_FORMAT"
 NOP=0x15000000
 TEXT_START_ADDR=0x0000
 TARGET_PAGE_SIZE=0x2000
diff --git a/ld/testsuite/ld-elf/binutils.exp b/ld/testsuite/ld-elf/binutils.exp
index ee90009bb9b..fd459a2223d 100644
--- a/ld/testsuite/ld-elf/binutils.exp
+++ b/ld/testsuite/ld-elf/binutils.exp
@@ -94,7 +94,7 @@ proc binutils_test { prog_name ld_options test {test_name ""} {readelf_options "
 			      || [istarget "metag-*-*"] \
 			      || [istarget "mips*-*-*"] \
 			      || [istarget "nios2*-*-*"] \
-			      || [istarget "or1k-*-*"] \
+			      || [istarget "or1k*-*-*"] \
 			      || [istarget "riscv*-*-*"] \
 			      || [istarget "sh*-*-*"] \
 			      || [istarget "x86_64-*-rdos*"])]
diff --git a/ld/testsuite/ld-ifunc/ifunc.exp b/ld/testsuite/ld-ifunc/ifunc.exp
index 1cd8d388b26..122468477ec 100644
--- a/ld/testsuite/ld-ifunc/ifunc.exp
+++ b/ld/testsuite/ld-ifunc/ifunc.exp
@@ -38,7 +38,7 @@ if { ![is_elf_format] || ![supports_gnu_osabi]
      || [istarget mn10300-*-*]
      || [istarget nds32*-*-*]
      || [istarget nios2-*-*]
-     || [istarget or1k-*-*]
+     || [istarget or1k*-*-*]
      || [istarget score*-*-*]
      || [istarget sh*-*-*]
      || [istarget tic6x-*-*]
diff --git a/opcodes/or1k-opc.h b/opcodes/or1k-opc.h
index d0950755250..53a3ca4ee21 100644
--- a/opcodes/or1k-opc.h
+++ b/opcodes/or1k-opc.h
@@ -35,7 +35,7 @@ extern "C" {
 #undef  CGEN_DIS_HASH_SIZE
 #define CGEN_DIS_HASH_SIZE 256
 #undef  CGEN_DIS_HASH
-#define CGEN_DIS_HASH(buffer, value) (((unsigned char *) (buffer))[0] >> 2)
+#define CGEN_DIS_HASH(buffer, value) ((value) >> 26)
 
 /* Check applicability of instructions against machines.  */
 #define CGEN_VALIDATE_INSN_SUPPORTED
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-06-10  2:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-09  6:03 [PATCH] or1k: Add support for a little-endian target variant Samuel Holland
2022-06-09 11:29 ` Stafford Horne
2022-06-10  2:07   ` Samuel Holland
  -- strict thread matches above, loose matches on Subject: below --
2022-06-09  6:01 Samuel Holland
2022-06-09 11:21 ` Stafford Horne
2022-06-10  1:00   ` Alan Modra
2022-06-10  1:39   ` Samuel Holland

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.