All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Holland <samuel@sholland.org>
To: gcc-patches@gcc.gnu.org
Cc: openrisc@lists.librecores.org
Subject: [PATCH] or1k: Add support for a little-endian target variant
Date: Thu,  9 Jun 2022 01:03:57 -0500	[thread overview]
Message-ID: <20220609060357.26436-1-samuel@sholland.org> (raw)

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


             reply	other threads:[~2022-06-09  6:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-09  6:03 Samuel Holland [this message]
2022-06-09 11:29 ` [PATCH] or1k: Add support for a little-endian target variant 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220609060357.26436-1-samuel@sholland.org \
    --to=samuel@sholland.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=openrisc@lists.librecores.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.