Skip to content

Commit

Permalink
Add riscv64 support
Browse files Browse the repository at this point in the history
Signed-off-by: Eduard Vintilă <[email protected]>
  • Loading branch information
eduardvintila committed Jul 20, 2022
1 parent 6375324 commit 7dcfd80
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
15 changes: 15 additions & 0 deletions Makefile.uk
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ LIBNEWLIBC_COMMON_INCLUDES-y += -I$(LIBNEWLIBC_BASE)/musl-imported/include
LIBNEWLIBC_COMMON_INCLUDES-y += -I$(LIBNEWLIBC_BASE)/musl-imported/arch/generic
LIBNEWLIBGLUE_CINCLUDES-y += -I$(LIBNEWLIBC_BASE)/musl-imported/src/include
LIBNEWLIBC_COMMON_INCLUDES-$(CONFIG_ARCH_X86_64) += -I$(LIBNEWLIBC_BASE)/musl-imported/arch/x86_64
LIBNEWLIBC_COMMON_INCLUDES-$(CONFIG_ARCH_RISCV_64) += -I$(LIBNEWLIB_LIBC)/machine/riscv
LIBNEWLIBC_COMMON_INCLUDES-y += -I$(LIBNEWLIB_LIBC)/include

CINCLUDES-$(CONFIG_LIBNEWLIBC) += $(LIBNEWLIBC_COMMON_INCLUDES-y)
ASINCLUDES-$(CONFIG_LIBNEWLIBC) += $(LIBNEWLIBC_COMMON_INCLUDES-y)
CXXINCLUDES-$(CONFIG_LIBNEWLIBC) += $(LIBNEWLIBC_COMMON_INCLUDES-y)

LIBNEWLIBM_CINCLUDES += -I$(LIBNEWLIB_LIBM)/common
Expand All @@ -93,6 +95,9 @@ ifeq ($(CONFIG_ARCH_X86_64),y)
LIBNEWLIB_GLOBAL_FLAGS-y += -D_LDBL_EQ_DBL
LIBNEWLIB_GLOBAL_FLAGS-y += -D_HAVE_LONG_DOUBLE
endif
ifeq ($(CONFIG_ARCH_RISCV_64),y)
LIBNEWLIB_GLOBAL_FLAGS-y += -D_HAVE_LONG_DOUBLE
endif

CFLAGS-$(CONFIG_LIBNEWLIBC) += $(LIBNEWLIB_GLOBAL_FLAGS-y)
CXXFLAGS-$(CONFIG_LIBNEWLIBC) += $(LIBNEWLIB_GLOBAL_FLAGS-y)
Expand Down Expand Up @@ -742,11 +747,14 @@ LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strcasecmp.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strcat.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBNEWLIB_LIBC)/string/strchr.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBNEWLIB_LIBC)/machine/aarch64/strchr.S
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_RISCV_64) += $(LIBNEWLIB_LIBC)/string/strchr.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBNEWLIB_LIBC)/string/strcmp.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBNEWLIB_LIBC)/machine/aarch64/strcmp.S
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_RISCV_64) += $(LIBNEWLIB_LIBC)/machine/riscv/strcmp.S
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strcoll.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBNEWLIB_LIBC)/string/strcpy.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBNEWLIB_LIBC)/machine/aarch64/strcpy.S
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_RISCV_64) += $(LIBNEWLIB_LIBC)/machine/riscv/strcpy.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strcspn.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strdup.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strdup_r.c
Expand All @@ -756,19 +764,23 @@ LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strlcat.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strlcpy.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBNEWLIB_LIBC)/string/strlen.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBNEWLIB_LIBC)/machine/aarch64/strlen.S
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_RISCV_64) += $(LIBNEWLIB_LIBC)/machine/riscv/strlen.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strlwr.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strncasecmp.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strncasecmp_l.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strncat.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBNEWLIB_LIBC)/string/strncmp.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBNEWLIB_LIBC)/machine/aarch64/strncmp.S
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_RISCV_64) += $(LIBNEWLIB_LIBC)/string/strncmp.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strncpy.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBNEWLIB_LIBC)/string/strnlen.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBNEWLIB_LIBC)/machine/aarch64/strnlen.S
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_RISCV_64) += $(LIBNEWLIB_LIBC)/string/strnlen.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strnstr.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strpbrk.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBNEWLIB_LIBC)/string/strrchr.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBNEWLIB_LIBC)/machine/aarch64/strrchr.S
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_RISCV_64) += $(LIBNEWLIB_LIBC)/string/strrchr.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strsep.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strsignal.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strspn.c
Expand Down Expand Up @@ -813,11 +825,13 @@ LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/memccpy.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/mempcpy.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBNEWLIB_LIBC)/string/stpcpy.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBNEWLIB_LIBC)/machine/aarch64/stpcpy.S
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_RISCV_64) += $(LIBNEWLIB_LIBC)/string/stpcpy.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/stpncpy.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strndup.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strcasestr.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBNEWLIB_LIBC)/string/strchrnul.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBNEWLIB_LIBC)/machine/aarch64/strchrnul.S
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_RISCV_64) += $(LIBNEWLIB_LIBC)/string/strchrnul.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/strndup_r.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/wcpcpy.c
LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/string/wcpncpy.c
Expand Down Expand Up @@ -867,6 +881,7 @@ LIBNEWLIBC_SRCS-y += $(LIBNEWLIB_LIBC)/unix/dirname.c
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBNEWLIB_LIBC)/machine/x86_64/setjmp.S
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_ARM_32) += $(LIBNEWLIB_LIBC)/machine/arm/setjmp.S
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBNEWLIB_LIBC)/machine/aarch64/setjmp.S
LIBNEWLIBC_SRCS-$(CONFIG_ARCH_RISCV_64) += $(LIBNEWLIB_LIBC)/machine/riscv/setjmp.S

################################################################################
# Newlib/libm code -- math
Expand Down
2 changes: 1 addition & 1 deletion include/fcntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <uk/config.h>

#if (defined CONFIG_ARCH_X86_64)
#if ((defined CONFIG_ARCH_X86_64) || (defined CONFIG_ARCH_RISCV_64))
#define O_NOFOLLOW 0400000
#define O_DIRECTORY 0200000
#define O_CLOEXEC 02000000
Expand Down
2 changes: 1 addition & 1 deletion include/limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#define SHRT_MAX 0x7fff
#define USHRT_MAX 0xffff

#if defined(__x86_64__)
#if defined(__x86_64__) || defined(__RISCV_64__)
# define LONG_MAX 0x7fffffffffffffffL
# define ULONG_MAX 0xffffffffffffffffUL
#else
Expand Down
41 changes: 41 additions & 0 deletions patches/0013-Define-llroundl-for-all-targets.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
From c3737ee23f13b8cf453cf91c28be4c0e4a320970 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Eduard=20Vintil=C4=83?= <[email protected]>
Date: Thu, 21 Jul 2022 00:26:24 +0300
Subject: [PATCH] Define llroundl for all targets
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The RISC-V ABI spec states that sizeof(long double) is equal to 16,
hence on such targets a double is not as wide as a long double.

Newlibc's implementation for llroundl is just a wrapper for llround, and
is not defined at all for targets where the size of the two types differ.
Musl wraps llround using llroundl regardless of the difference between double and long double,
so we remove the compile-time check such that llroundl is defined for all targets in newlibc as well.

Signed-off-by: Eduard Vintilă <[email protected]>
---
newlib/libm/common/llroundl.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/newlib/libm/common/llroundl.c b/newlib/libm/common/llroundl.c
index d663226..1e1fda4 100644
--- a/newlib/libm/common/llroundl.c
+++ b/newlib/libm/common/llroundl.c
@@ -31,12 +31,9 @@ POSSIBILITY OF SUCH DAMAGE.
#include <math.h>
#include "local.h"

-/* On platforms where long double is as wide as double. */
-#ifdef _LDBL_EQ_DBL
long long int
llroundl (long double x)
{
return llround(x);
}
-#endif

--
2.37.1

0 comments on commit 7dcfd80

Please sign in to comment.