or1k: Add support for a little-endian target variant
PATCH 1/1 or1k: Add support for a little-endian target variant
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*.
--- 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(-)
gcc/config.gcc +5 -0
@@ -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"
gcc/config/or1k/elf.h +1 -0
@@ -27,6 +27,7 @@#undef LINK_SPEC#define LINK_SPEC "%{h*} \ + %{mbig-endian:-EB} %{mlittle-endian:-EL} \ %{static:-Bstatic} \ %{shared:-shared} \ %{symbolic:-Bsymbolic} \
gcc/config/or1k/linux.h +1 -0
@@ -36,6 +36,7 @@#undef LINK_SPEC#define LINK_SPEC "%{h*} \ + %{mbig-endian:-EB} %{mlittle-endian:-EL} \ %{static:-Bstatic} \ %{shared:-shared} \ %{symbolic:-Bsymbolic} \
gcc/config/or1k/or1k.h +17 -2
@@ -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
gcc/config/or1k/or1k.opt +8 -0
@@ -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
libgcc/config.host +2 -2
@@ -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" ;;
Signature · 1 line
2.35.1
gcc/config.gcc or1k*-*-*) · line 2870
Quoted 10 lines
gcc/config.gcc +2
-0@@ -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*-*?
Quoted 14 lines
gcc/config.gcc +3
-0+ 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"gcc/config/or1k/or1k.opt +0
-0@@ -24,6 +24,14 @@ HeaderInclude
gcc/config/or1k/or1k.opt line 34
Quoted 10 lines
gcc/config/or1k/or1k.opt +8
-0config/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
Hi Stafford,
Quoted 8 lines · Stafford Horne
Quoted 8 lines
gcc/config.gcc +0
-0@@ -2866,6 +2866,11 @@ or1k*-*-*) done TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'`
Quoted 4 lines
gcc/config.gcc or1k*-*-*) · line 2870
Quoted 2 lines
gcc/config.gcc +2
-0+ 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.
Quoted 27 lines
Quoted 14 lines
gcc/config.gcc +3
-0+ 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"gcc/config/or1k/or1k.opt +0
-0@@ -24,6 +24,14 @@ HeaderIncludegcc/config/or1k/or1k.opt line 34
Quoted 10 lines
gcc/config/or1k/or1k.opt +8
-0config/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.
Quoted 1 line
Can you also document in: gcc/doc/invoke.texi
Yes, I will do that for v2.
Regards,
Samuel