public inbox for gcc-patches@gcc.gnu.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; 3+ messages in thread
From: Samuel Holland @ 2022-06-09  6:03 UTC (permalink / raw)
  To: gcc-patches; +Cc: openrisc, Stafford Horne, Samuel Holland

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	[flat|nested] 3+ 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; 3+ messages in thread
From: Stafford Horne @ 2022-06-09 11:29 UTC (permalink / raw)
  To: Samuel Holland; +Cc: gcc-patches, openrisc

> 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] 3+ 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; 3+ messages in thread
From: Samuel Holland @ 2022-06-10  2:07 UTC (permalink / raw)
  To: Stafford Horne; +Cc: gcc-patches, openrisc

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] 3+ messages in thread

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

Thread overview: 3+ 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).