From: "Marcus Comstedt" <marcus@mc.pp.se>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Cc: Marcus Comstedt <marcus@mc.pp.se>
Subject: [PATCH v2 1/5] RISC-V: Support -mlittle-endian and -mbig-endian
Date: Sun, 21 Feb 2021 01:08:59 +0100 [thread overview]
Message-ID: <20210221000903.32039-2-marcus@mc.pp.se> (raw)
In-Reply-To: <20210221000903.32039-1-marcus@mc.pp.se>
gcc/
* config/riscv/elf.h (LINK_SPEC): Pass linker endianness flag.
* config/riscv/freebsd.h (LINK_SPEC): Likewise.
* config/riscv/linux.h (LINK_SPEC): Likewise.
* config/riscv/riscv.h (ASM_SPEC): Pass -mbig-endian and
-mlittle-endian.
(BYTES_BIG_ENDIAN): Handle big endian.
(WORDS_BIG_ENDIAN): Define to BYTES_BIG_ENDIAN.
* config/riscv/riscv.opt (-mbig-endian, -mlittle-endian): New
options.
* doc/invoke.texi (-mbig-endian, -mlittle-endian): Document.
---
gcc/config/riscv/elf.h | 2 ++
gcc/config/riscv/freebsd.h | 2 ++
gcc/config/riscv/linux.h | 2 ++
gcc/config/riscv/riscv.h | 6 ++++--
gcc/config/riscv/riscv.opt | 8 ++++++++
gcc/doc/invoke.texi | 12 ++++++++++++
6 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/gcc/config/riscv/elf.h b/gcc/config/riscv/elf.h
index d136d46e4fa..973efdaed7b 100644
--- a/gcc/config/riscv/elf.h
+++ b/gcc/config/riscv/elf.h
@@ -20,6 +20,8 @@ along with GCC; see the file COPYING3. If not see
#define LINK_SPEC "\
-melf" XLEN_SPEC "lriscv \
%{mno-relax:--no-relax} \
+%{mbig-endian:-EB} \
+%{mlittle-endian:-EL} \
%{shared}"
/* Link against Newlib libraries, because the ELF backend assumes Newlib.
diff --git a/gcc/config/riscv/freebsd.h b/gcc/config/riscv/freebsd.h
index a48bf9bffe4..f3aca9f7673 100644
--- a/gcc/config/riscv/freebsd.h
+++ b/gcc/config/riscv/freebsd.h
@@ -44,6 +44,8 @@ along with GCC; see the file COPYING3. If not see
%{p:%nconsider using `-pg' instead of `-p' with gprof (1)} \
%{v:-V} \
%{assert*} %{R*} %{rpath*} %{defsym*} \
+ %{mbig-endian:-EB} \
+ %{mlittle-endian:-EL} \
%{shared:-Bshareable %{h*} %{soname*}} \
%{symbolic:-Bsymbolic} \
%{static:-Bstatic} \
diff --git a/gcc/config/riscv/linux.h b/gcc/config/riscv/linux.h
index 9238de5bc92..e74f5d3f914 100644
--- a/gcc/config/riscv/linux.h
+++ b/gcc/config/riscv/linux.h
@@ -60,6 +60,8 @@ along with GCC; see the file COPYING3. If not see
#define LINK_SPEC "\
-melf" XLEN_SPEC "lriscv" LD_EMUL_SUFFIX " \
%{mno-relax:--no-relax} \
+%{mbig-endian:-EB} \
+%{mlittle-endian:-EL} \
%{shared} \
%{!shared: \
%{!static: \
diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index c6f8bee07ef..0b667d2e8b9 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -91,6 +91,8 @@ extern const char *riscv_default_mtune (int argc, const char **argv);
%{" FPIE_OR_FPIC_SPEC ":-fpic} \
%{march=*} \
%{mabi=*} \
+%{mbig-endian} \
+%{mlittle-endian} \
%(subtarget_asm_spec)" \
ASM_MISA_SPEC
@@ -126,8 +128,8 @@ ASM_MISA_SPEC
/* Target machine storage layout */
#define BITS_BIG_ENDIAN 0
-#define BYTES_BIG_ENDIAN 0
-#define WORDS_BIG_ENDIAN 0
+#define BYTES_BIG_ENDIAN (TARGET_BIG_ENDIAN != 0)
+#define WORDS_BIG_ENDIAN (BYTES_BIG_ENDIAN)
#define MAX_BITS_PER_WORD 64
diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt
index 761a09d18c3..e294e223151 100644
--- a/gcc/config/riscv/riscv.opt
+++ b/gcc/config/riscv/riscv.opt
@@ -21,6 +21,14 @@
HeaderInclude
config/riscv/riscv-opts.h
+mbig-endian
+Target RejectNegative Mask(BIG_ENDIAN)
+Assume target CPU is configured as big endian.
+
+mlittle-endian
+Target RejectNegative InverseMask(BIG_ENDIAN)
+Assume target CPU is configured as little endian.
+
mbranch-cost=
Target RejectNegative Joined UInteger Var(riscv_branch_cost)
-mbranch-cost=N Set the cost of branches to roughly N instructions.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e8baa545eee..9279a37a832 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1169,6 +1169,7 @@ See RS/6000 and PowerPC Options.
-mrelax -mno-relax @gol
-mriscv-attribute -mmo-riscv-attribute @gol
-malign-data=@var{type} @gol
+-mbig-endian -mlittle-endian @gol
+-mstack-protector-guard=@var{guard} -mstack-protector-guard-reg=@var{reg} @gol
+-mstack-protector-guard-offset=@var{offset}}
@@ -26721,6 +26722,17 @@ types. Supported values for @var{type} are @samp{xlen} which uses x register
width as the alignment value, and @samp{natural} which uses natural alignment.
@samp{xlen} is the default.
+@item -mbig-endian
+@opindex mbig-endian
+Generate big-endian code. This is the default when GCC is configured for a
+@samp{riscv64be-*-*} or @samp{riscv32be-*-*} target.
+
+@item -mlittle-endian
+@opindex mlittle-endian
+Generate little-endian code. This is the default when GCC is configured for a
+@samp{riscv64-*-*} or @samp{riscv32-*-*} but not a @samp{riscv64be-*-*} or
+@samp{riscv32be-*-*} target.
+
@item -mstack-protector-guard=@var{guard}
@itemx -mstack-protector-guard-reg=@var{reg}
@itemx -mstack-protector-guard-offset=@var{offset}
--
2.26.2
next prev parent reply other threads:[~2021-02-21 0:09 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-21 0:08 [PATCH v2 0/5] RISC-V big endian support Marcus Comstedt
2021-02-21 0:08 ` Marcus Comstedt [this message]
2021-02-21 0:09 ` [PATCH v2 2/5] RISC-V: Add riscv{32,64}be with big endian as default Marcus Comstedt
2021-02-21 0:09 ` [PATCH v2 3/5] RISC-V: Update soft-fp config for big-endian Marcus Comstedt
2021-02-21 0:09 ` [PATCH v2 4/5] RISC-V: Fix trampoline generation on big endian Marcus Comstedt
2021-02-21 0:09 ` [PATCH v2 5/5] RISC-V: Update shift-shift-5.c testcase for " Marcus Comstedt
2021-02-23 2:38 ` [PATCH v2 0/5] RISC-V big endian support Kito Cheng
2021-02-23 7:12 ` Kito Cheng
2021-02-23 7:23 ` Marcus Comstedt
2021-02-24 7:45 ` Kito Cheng
2021-02-24 18:03 ` Marcus Comstedt
2021-02-24 19:23 ` Marcus Comstedt
2021-02-26 20:46 ` Marcus Comstedt
2021-03-14 21:42 ` Marcus Comstedt
2021-03-19 16:22 ` Kito Cheng
2021-03-23 22:52 ` Jim Wilson
2021-03-22 14:36 ` Maciej W. Rozycki
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=20210221000903.32039-2-marcus@mc.pp.se \
--to=marcus@mc.pp.se \
--cc=gcc-patches@gcc.gnu.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 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).