diff --git a/Makefile.in b/Makefile.in index e6fc8ec8224..2bfbf698f37 100644 --- a/Makefile.in +++ b/Makefile.in @@ -84,7 +84,11 @@ ifneq ($(XLEN),32) XLEN := 64 endif -make_tuple = riscv$(1)-unknown-$(2) +ifeq (@endian@,big) +ENDIAN_POSTFIX := be +endif + +make_tuple = riscv$(1)$(ENDIAN_POSTFIX)-unknown-$(2) LINUX_TUPLE ?= $(call make_tuple,$(XLEN),linux-gnu) NEWLIB_TUPLE ?= $(call make_tuple,$(XLEN),elf) MUSL_TUPLE ?= $(call make_tuple,$(XLEN),linux-musl) diff --git a/README.md b/README.md index 8dc1910937a..125f2aa2bc6 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,15 @@ This option only takes effect for the GNU toolchain. The toolchain has an option `--enable-strip` to control strip of host binaries, strip is disabled by default. +### Big Endian configuration + +To build either cross-compiler with support for big endian targets, run the following command: + +``` +./configure --prefix=/opt/riscv --with-endian=big +make (target) +``` + ### Troubleshooting Build Problems Builds work best if installing into an empty directory. If you build a diff --git a/configure b/configure index 2fc589e7db6..b76b701a629 100755 --- a/configure +++ b/configure @@ -641,6 +641,7 @@ configure_host target_cxxflags target_cflags cmodel +endian gcc_checking musl_multilib_names newlib_multilib_names @@ -730,6 +731,7 @@ with_multilib_generator with_extra_multilib_test enable_gcc_checking with_cmodel +with_endian with_target_cflags with_target_cxxflags with_host @@ -1426,6 +1428,7 @@ Optional Packages: --with-extra-multilib-test="rv64gcv-lp64;rv64gcv_zba-lp64" --with-cmodel Select the code model to use when building libc and libgcc [--with-cmodel=medlow] + --with-endian Select the target endianess [--with-endian=little] --with-target-cflags Add extra target flags for C for library code --with-target-cxxflags Add extra target flags for C++ for library code --with-host=x86_64-w64-mingw32 @@ -4080,6 +4083,19 @@ WITH_SIM=$with_sim WITH_LANGUAGES=$with_languages +# Check whether --with-endian was given. +if test "${with_endian+set}" = set; then : + withval=$with_endian; +fi + +if test "x$with_endian" != x; then : + endian=$with_endian + +else + endian=little + +fi + # Check whether --enable-multilib was given. if test ${enable_multilib+y} then : @@ -4138,7 +4154,12 @@ fi if test "x$enable_multilib" = xyes then : - glibc_multilib_names="rv32imac-ilp32 rv32gc-ilp32d rv64imac-lp64 rv64gc-lp64d rv64gcv-lp64d" + glibc_multilib_names="rv32imac-ilp32 rv32gc-ilp32d rv64imac-lp64 rv64gc-lp64d" + # Vector extension is currently not supported on Big-endian systems. + if test "x$endian" = xlittle + then : + glibc_multilib_names+=" rv64gcv-lp64d" + fi else $as_nop glibc_multilib_names="$with_arch-$with_abi" diff --git a/configure.ac b/configure.ac index 80ca038bbe0..bae4c57ffae 100644 --- a/configure.ac +++ b/configure.ac @@ -188,6 +188,10 @@ AS_IF([test "x$with_cmodel" != xno], [AC_SUBST(cmodel, -mcmodel=$with_cmodel)], [AC_SUBST(cmodel, -mcmodel=medlow)]) +AS_IF([test "x$with_endian" != x], + [AC_SUBST(endian, endian=$with_endian)], + [AC_SUBST(endian, endian=little)]) + AC_ARG_WITH(target_cflags, [AS_HELP_STRING([--with-target-cflags], [Add extra target flags for C for library code])], diff --git a/linux-headers/include/asm/byteorder.h b/linux-headers/include/asm/byteorder.h index 03ac550720f..44552373908 100644 --- a/linux-headers/include/asm/byteorder.h +++ b/linux-headers/include/asm/byteorder.h @@ -7,6 +7,10 @@ #ifndef _ASM_RISCV_BYTEORDER_H #define _ASM_RISCV_BYTEORDER_H +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #include +#else +#include +#endif #endif /* _ASM_RISCV_BYTEORDER_H */