Index | Thread | Search

From:
Brian Callahan <bcallah@posteo.net>
Subject:
lang/gcc/11: Enable gdc for riscv64
To:
OpenBSD Ports ML <ports@openbsd.org>, pascal@openbsd.org
Date:
Tue, 25 Jun 2024 06:30:41 +0000

Download raw body.

Thread
  • Brian Callahan:

    lang/gcc/11: Enable gdc for riscv64

Hello --

I was recently gifted a SiFive Unleashed system. Attached is a diff to
build gdc on riscv64. I am able to build D programs on my machine with it.

Would appreciate other eyes on especially the build system parts to make
sure I didn't break anything. Eyes on the riscv64 assembly also appreciated.

OK?

~Brian
Index: Makefile
===================================================================
RCS file: /cvs/ports/lang/gcc/11/Makefile,v
retrieving revision 1.33
diff -u -p -r1.33 Makefile
--- Makefile	15 Apr 2024 23:00:53 -0000	1.33
+++ Makefile	25 Jun 2024 06:24:27 -0000
@@ -9,7 +9,7 @@ ONLY_FOR_ARCHS = aarch64 alpha amd64 arm
 	powerpc powerpc64 riscv64 sparc64
 
 ONLY_FOR_ARCHS-ada = amd64 i386 mips64 powerpc
-ONLY_FOR_ARCHS-dlang = aarch64 amd64 arm i386 powerpc powerpc64
+ONLY_FOR_ARCHS-dlang = aarch64 amd64 arm i386 powerpc powerpc64 riscv64
 
 DPB_PROPERTIES = parallel
 
@@ -18,7 +18,7 @@ USE_NOEXECONLY = Yes
 V = 11.2.0
 FULL_VERSION = $V
 FULL_PKGVERSION = $V
-REVISION = 13
+REVISION = 14
 REVISION-c++ = 14
 
 ADASTRAP-amd64 = adastrap-amd64-$V-4.tar.xz
Index: patches/patch-libphobos_configure
===================================================================
RCS file: /cvs/ports/lang/gcc/11/patches/patch-libphobos_configure,v
retrieving revision 1.2
diff -u -p -r1.2 patch-libphobos_configure
--- patches/patch-libphobos_configure	11 Mar 2022 19:28:58 -0000	1.2
+++ patches/patch-libphobos_configure	25 Jun 2024 06:24:27 -0000
@@ -1,15 +1,16 @@
-Add fiber asm for powerpc64, to avoid
+Add fiber asm for powerpc64 and riscv64, to avoid
 "configure: error: setcontext required but not found"
 
 Index: libphobos/configure
 --- libphobos/configure.orig
 +++ libphobos/configure
-@@ -15196,7 +15196,7 @@ fi
+@@ -15196,7 +15196,8 @@ fi
      aarch64* | \
      arm* | \
      i[34567]86|x86_64 | \
 -    powerpc)
-+    powerpc*)
++    powerpc* | \
++    riscv64)
        druntime_fiber_asm_external=yes
        ;;
    esac
Index: patches/patch-libphobos_libdruntime_Makefile_in
===================================================================
RCS file: /cvs/ports/lang/gcc/11/patches/patch-libphobos_libdruntime_Makefile_in,v
retrieving revision 1.2
diff -u -p -r1.2 patch-libphobos_libdruntime_Makefile_in
--- patches/patch-libphobos_libdruntime_Makefile_in	11 Mar 2022 19:28:58 -0000	1.2
+++ patches/patch-libphobos_libdruntime_Makefile_in	25 Jun 2024 06:24:27 -0000
@@ -1,7 +1,60 @@
 Index: libphobos/libdruntime/Makefile.in
 --- libphobos/libdruntime/Makefile.in.orig
 +++ libphobos/libdruntime/Makefile.in
-@@ -775,8 +775,9 @@ ALL_DRUNTIME_SOURCES = $(DRUNTIME_DSOURCES) $(DRUNTIME
+@@ -126,6 +126,7 @@ target_triplet = @target@
+ @DRUNTIME_CPU_ARM_TRUE@am__append_12 = config/arm/switchcontext.S
+ @DRUNTIME_CPU_MIPS_TRUE@am__append_13 = config/mips/switchcontext.S
+ @DRUNTIME_CPU_POWERPC_TRUE@am__append_14 = config/powerpc/switchcontext.S
++@DRUNTIME_CPU_RISCV64_TRUE@am__append_19 = config/riscv64/switchcontext.S
+ @DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_TRUE@am__append_15 = config/mingw/switchcontext.S
+ @DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_FALSE@am__append_16 = config/x86/switchcontext.S
+ @DRUNTIME_CPU_SYSTEMZ_TRUE@am__append_17 = config/systemz/get_tls_offset.S
+@@ -449,6 +450,7 @@ am__objects_21 = core/sys/solaris/dlfcn.lo core/sys/so
+ @DRUNTIME_CPU_ARM_TRUE@am__objects_24 = config/arm/libgdruntime_la-switchcontext.lo
+ @DRUNTIME_CPU_MIPS_TRUE@am__objects_25 = config/mips/libgdruntime_la-switchcontext.lo
+ @DRUNTIME_CPU_POWERPC_TRUE@am__objects_26 = config/powerpc/libgdruntime_la-switchcontext.lo
++@DRUNTIME_CPU_RISCV64_TRUE@am__objects_47 = config/riscv64/libgdruntime_la-switchcontext.lo
+ @DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_TRUE@am__objects_27 = config/mingw/libgdruntime_la-switchcontext.lo
+ @DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_FALSE@am__objects_28 = config/x86/libgdruntime_la-switchcontext.lo
+ @DRUNTIME_CPU_SYSTEMZ_TRUE@am__objects_29 = config/systemz/libgdruntime_la-get_tls_offset.lo
+@@ -458,7 +460,8 @@ am__objects_31 = $(am__objects_4) $(am__objects_6) $(a
+ 	$(am__objects_16) $(am__objects_18) $(am__objects_20) \
+ 	$(am__objects_22) $(am__objects_23) $(am__objects_24) \
+ 	$(am__objects_25) $(am__objects_26) $(am__objects_27) \
+-	$(am__objects_28) $(am__objects_29) $(am__objects_30)
++	$(am__objects_28) $(am__objects_29) $(am__objects_30) \
++	$(am__objects_47)
+ am__objects_32 = gcc/config.lo gcc/libbacktrace.lo
+ am__objects_33 = $(am__objects_1) $(am__objects_2) $(am__objects_31) \
+ 	$(am__objects_32)
+@@ -472,6 +475,7 @@ am__objects_34 = core/stdc/libgdruntime_convenience_la
+ @DRUNTIME_CPU_ARM_TRUE@am__objects_37 = config/arm/libgdruntime_convenience_la-switchcontext.lo
+ @DRUNTIME_CPU_MIPS_TRUE@am__objects_38 = config/mips/libgdruntime_convenience_la-switchcontext.lo
+ @DRUNTIME_CPU_POWERPC_TRUE@am__objects_39 = config/powerpc/libgdruntime_convenience_la-switchcontext.lo
++@DRUNTIME_CPU_RISCV64_TRUE@am__objects_48 = config/riscv64/libgdruntime_convenience_la-switchcontext.lo
+ @DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_TRUE@am__objects_40 = config/mingw/libgdruntime_convenience_la-switchcontext.lo
+ @DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_FALSE@am__objects_41 = config/x86/libgdruntime_convenience_la-switchcontext.lo
+ @DRUNTIME_CPU_SYSTEMZ_TRUE@am__objects_42 = config/systemz/libgdruntime_convenience_la-get_tls_offset.lo
+@@ -481,7 +485,8 @@ am__objects_44 = $(am__objects_4) $(am__objects_6) $(a
+ 	$(am__objects_16) $(am__objects_18) $(am__objects_35) \
+ 	$(am__objects_22) $(am__objects_36) $(am__objects_37) \
+ 	$(am__objects_38) $(am__objects_39) $(am__objects_40) \
+-	$(am__objects_41) $(am__objects_42) $(am__objects_43)
++	$(am__objects_41) $(am__objects_42) $(am__objects_43) \
++	$(am__objects_48)
+ am__objects_45 = $(am__objects_1) $(am__objects_34) $(am__objects_44) \
+ 	$(am__objects_32)
+ am__objects_46 = $(am__objects_45)
+@@ -758,7 +763,7 @@ DRUNTIME_SOURCES_CONFIGURED = $(am__append_1) $(am__ap
+ 	$(am__append_9) $(am__append_10) $(am__append_11) \
+ 	$(am__append_12) $(am__append_13) $(am__append_14) \
+ 	$(am__append_15) $(am__append_16) $(am__append_17) \
+-	$(am__append_18)
++	$(am__append_18) $(am__append_19)
+ 
+ # Provide __start_minfo, __stop_minfo if linker doesn't.
+ @DRUNTIME_OS_MINFO_BRACKETING_FALSE@DRTSTUFF = gcc/drtbegin.o gcc/drtend.o
+@@ -775,8 +780,9 @@ ALL_DRUNTIME_SOURCES = $(DRUNTIME_DSOURCES) $(DRUNTIME
  toolexeclib_LTLIBRARIES = libgdruntime.la
  libgdruntime_la_SOURCES = $(ALL_DRUNTIME_SOURCES)
  libgdruntime_la_LIBTOOLFLAGS = 
@@ -12,3 +65,76 @@ Index: libphobos/libdruntime/Makefile.in
  
  libgdruntime_la_LIBADD = $(LIBATOMIC) $(LIBBACKTRACE)
  libgdruntime_la_DEPENDENCIES = $(DRTSTUFF)
+@@ -1791,8 +1797,18 @@ config/powerpc/$(am__dirstamp):
+ 	@: > config/powerpc/$(am__dirstamp)
+ config/powerpc/libgdruntime_la-switchcontext.lo:  \
+ 	config/powerpc/$(am__dirstamp)
++config/riscv64/$(am__dirstamp):
++	@$(MKDIR_P) config/riscv64
++	@: > config/riscv64/$(am__dirstamp)
++config/riscv64/libgdruntime_la-switchcontext.lo:  \
++	config/riscv64/$(am__dirstamp)
+ config/mingw/libgdruntime_la-switchcontext.lo:  \
+ 	config/mingw/$(am__dirstamp)
++config/riscv64/$(am__dirstamp):
++	@$(MKDIR_P) config/riscv64
++	@: > config/riscv64/$(am__dirstamp)
++config/riscv64/libgdruntime_la-switchcontext.lo:  \
++	config/riscv64/$(am__dirstamp)
+ config/x86/$(am__dirstamp):
+ 	@$(MKDIR_P) config/x86
+ 	@: > config/x86/$(am__dirstamp)
+@@ -1825,6 +1841,8 @@ config/mips/libgdruntime_convenience_la-switchcontext.
+ 	config/mips/$(am__dirstamp)
+ config/powerpc/libgdruntime_convenience_la-switchcontext.lo:  \
+ 	config/powerpc/$(am__dirstamp)
++config/riscv64/libgdruntime_convenience_la-switchcontext.lo:  \
++	config/riscv64/$(am__dirstamp)
+ config/mingw/libgdruntime_convenience_la-switchcontext.lo:  \
+ 	config/mingw/$(am__dirstamp)
+ config/x86/libgdruntime_convenience_la-switchcontext.lo:  \
+@@ -1849,6 +1867,8 @@ mostlyclean-compile:
+ 	-rm -f config/mips/*.lo
+ 	-rm -f config/powerpc/*.$(OBJEXT)
+ 	-rm -f config/powerpc/*.lo
++	-rm -f config/riscv64/*.$(OBJEXT)
++	-rm -f config/riscv64/*.lo
+ 	-rm -f config/s390/*.$(OBJEXT)
+ 	-rm -f config/s390/*.lo
+ 	-rm -f config/systemz/*.$(OBJEXT)
+@@ -1967,6 +1987,9 @@ config/powerpc/libgdruntime_la-switchcontext.lo: confi
+ config/mingw/libgdruntime_la-switchcontext.lo: config/mingw/switchcontext.S
+ 	$(AM_V_CPPAS)$(LIBTOOL) $(AM_V_lt) $(libgdruntime_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS) -c -o config/mingw/libgdruntime_la-switchcontext.lo `test -f 'config/mingw/switchcontext.S' || echo '$(srcdir)/'`config/mingw/switchcontext.S
+ 
++config/riscv64/libgdruntime_la-switchcontext.lo: config/riscv64/switchcontext.S
++	$(AM_V_CPPAS)$(LIBTOOL) $(AM_V_lt) $(libgdruntime_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS) -c -o config/riscv64/libgdruntime_la-switchcontext.lo `test -f 'config/riscv64/switchcontext.S' || echo '$(srcdir)/'`config/riscv64/switchcontext.S
++
+ config/x86/libgdruntime_la-switchcontext.lo: config/x86/switchcontext.S
+ 	$(AM_V_CPPAS)$(LIBTOOL) $(AM_V_lt) $(libgdruntime_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS) -c -o config/x86/libgdruntime_la-switchcontext.lo `test -f 'config/x86/switchcontext.S' || echo '$(srcdir)/'`config/x86/switchcontext.S
+ 
+@@ -1991,6 +2014,9 @@ config/powerpc/libgdruntime_convenience_la-switchconte
+ config/mingw/libgdruntime_convenience_la-switchcontext.lo: config/mingw/switchcontext.S
+ 	$(AM_V_CPPAS)$(LIBTOOL) $(AM_V_lt) $(libgdruntime_convenience_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS) -c -o config/mingw/libgdruntime_convenience_la-switchcontext.lo `test -f 'config/mingw/switchcontext.S' || echo '$(srcdir)/'`config/mingw/switchcontext.S
+ 
++config/riscv64/libgdruntime_convenience_la-switchcontext.lo: config/riscv64/switchcontext.S
++	$(AM_V_CPPAS)$(LIBTOOL) $(AM_V_lt) $(libgdruntime_convenience_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS) -c -o config/riscv64/libgdruntime_convenience_la-switchcontext.lo `test -f 'config/riscv64/switchcontext.S' || echo '$(srcdir)/'`config/riscv64/switchcontext.S
++
+ config/x86/libgdruntime_convenience_la-switchcontext.lo: config/x86/switchcontext.S
+ 	$(AM_V_CPPAS)$(LIBTOOL) $(AM_V_lt) $(libgdruntime_convenience_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS) -c -o config/x86/libgdruntime_convenience_la-switchcontext.lo `test -f 'config/x86/switchcontext.S' || echo '$(srcdir)/'`config/x86/switchcontext.S
+ 
+@@ -2031,6 +2057,7 @@ clean-libtool:
+ 	-rm -rf config/mingw/.libs config/mingw/_libs
+ 	-rm -rf config/mips/.libs config/mips/_libs
+ 	-rm -rf config/powerpc/.libs config/powerpc/_libs
++	-rm -rf config/riscv64/.libs config/riscv64/_libs
+ 	-rm -rf config/s390/.libs config/s390/_libs
+ 	-rm -rf config/systemz/.libs config/systemz/_libs
+ 	-rm -rf config/x86/.libs config/x86/_libs
+@@ -2187,6 +2214,7 @@ distclean-generic:
+ 	-rm -f config/mingw/$(am__dirstamp)
+ 	-rm -f config/mips/$(am__dirstamp)
+ 	-rm -f config/powerpc/$(am__dirstamp)
++	-rm -f config/riscv64/$(am__dirstamp)
+ 	-rm -f config/s390/$(am__dirstamp)
+ 	-rm -f config/systemz/$(am__dirstamp)
+ 	-rm -f config/x86/$(am__dirstamp)
Index: patches/patch-libphobos_libdruntime_config_riscv64_switchcontext_S
===================================================================
RCS file: patches/patch-libphobos_libdruntime_config_riscv64_switchcontext_S
diff -N patches/patch-libphobos_libdruntime_config_riscv64_switchcontext_S
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-libphobos_libdruntime_config_riscv64_switchcontext_S	25 Jun 2024 06:24:27 -0000
@@ -0,0 +1,125 @@
+Index: libphobos/libdruntime/config/riscv64/switchcontext.S
+--- libphobos/libdruntime/config/riscv64/switchcontext.S.orig
++++ libphobos/libdruntime/config/riscv64/switchcontext.S
+@@ -0,0 +1,121 @@
++/* RISC-V 64 support code for fibers and multithreading.
++   Copyright (C) 2023-2024 Free Software Foundation, Inc.
++
++This file is part of GCC.
++
++GCC is free software; you can redistribute it and/or modify it under
++the terms of the GNU General Public License as published by the Free
++Software Foundation; either version 3, or (at your option) any later
++version.
++
++GCC is distributed in the hope that it will be useful, but WITHOUT ANY
++WARRANTY; without even the implied warranty of MERCHANTABILITY or
++FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
++for more details.
++
++Under Section 7 of GPL version 3, you are granted additional
++permissions described in the GCC Runtime Library Exception, version
++3.1, as published by the Free Software Foundation.
++
++You should have received a copy of the GNU General Public License and
++a copy of the GCC Runtime Library Exception along with this program;
++see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
++<http://www.gnu.org/licenses/>.  */
++
++#include "../common/threadasm.S"
++
++/**
++ * Performs a context switch.
++ *
++ * $a0 - void** - ptr to old stack pointer
++ * $a1 - void*  - new stack pointer
++ *
++ */
++
++#define GPR_L ld
++#define GPR_S sd
++#define SZ_GPR 8
++#define ADDSP(si)   addi  sp, sp, si
++#define FPR_L fld
++#define FPR_S fsd
++#define SZ_FPR 8
++
++    .text
++    .align 2
++    .global fiber_switchContext
++    .type   fiber_switchContext, @function
++fiber_switchContext:
++    .cfi_startproc
++    ADDSP(-12 * SZ_GPR)
++
++    // fp regs and return address are stored below the stack
++    // because we don't want the GC to scan them.
++
++    // return address (ra)
++    GPR_S  ra, -SZ_GPR(sp)
++
++    // callee-saved scratch FPRs (fs0-fs11)
++    FPR_S  fs0, -SZ_GPR-1*SZ_FPR(sp)
++    FPR_S  fs1, -SZ_GPR-2*SZ_FPR(sp)
++    FPR_S  fs2, -SZ_GPR-3*SZ_FPR(sp)
++    FPR_S  fs3, -SZ_GPR-4*SZ_FPR(sp)
++    FPR_S  fs4, -SZ_GPR-5*SZ_FPR(sp)
++    FPR_S  fs5, -SZ_GPR-6*SZ_FPR(sp)
++    FPR_S  fs6, -SZ_GPR-7*SZ_FPR(sp)
++    FPR_S  fs7, -SZ_GPR-8*SZ_FPR(sp)
++    FPR_S  fs8, -SZ_GPR-9*SZ_FPR(sp)
++    FPR_S  fs9, -SZ_GPR-10*SZ_FPR(sp)
++    FPR_S fs10, -SZ_GPR-11*SZ_FPR(sp)
++    FPR_S fs11, -SZ_GPR-12*SZ_FPR(sp)
++
++    // callee-saved GPRs (s0/fp (x8), s1 (x9), s2-s11 (x18-x27))
++    GPR_S  s0, 0*SZ_GPR(sp)
++    GPR_S  s1, 1*SZ_GPR(sp)
++    GPR_S  s2, 2*SZ_GPR(sp)
++    GPR_S  s3, 3*SZ_GPR(sp)
++    GPR_S  s4, 4*SZ_GPR(sp)
++    GPR_S  s5, 5*SZ_GPR(sp)
++    GPR_S  s6, 6*SZ_GPR(sp)
++    GPR_S  s7, 7*SZ_GPR(sp)
++    GPR_S  s8, 8*SZ_GPR(sp)
++    GPR_S  s9, 9*SZ_GPR(sp)
++    GPR_S s10, 10*SZ_GPR(sp)
++    GPR_S s11, 11*SZ_GPR(sp)
++
++    // swap stack pointer
++    GPR_S sp, 0(a0)
++    add sp, a1, zero
++
++    GPR_L  ra, -SZ_GPR(sp)
++
++    FPR_L  fs0, -SZ_GPR-1*SZ_FPR(sp)
++    FPR_L  fs1, -SZ_GPR-2*SZ_FPR(sp)
++    FPR_L  fs2, -SZ_GPR-3*SZ_FPR(sp)
++    FPR_L  fs3, -SZ_GPR-4*SZ_FPR(sp)
++    FPR_L  fs4, -SZ_GPR-5*SZ_FPR(sp)
++    FPR_L  fs5, -SZ_GPR-6*SZ_FPR(sp)
++    FPR_L  fs6, -SZ_GPR-7*SZ_FPR(sp)
++    FPR_L  fs7, -SZ_GPR-8*SZ_FPR(sp)
++    FPR_L  fs8, -SZ_GPR-9*SZ_FPR(sp)
++    FPR_L  fs9, -SZ_GPR-10*SZ_FPR(sp)
++    FPR_L fs10, -SZ_GPR-11*SZ_FPR(sp)
++    FPR_L fs11, -SZ_GPR-12*SZ_FPR(sp)
++
++    GPR_L  s0, 0*SZ_GPR(sp)
++    GPR_L  s1, 1*SZ_GPR(sp)
++    GPR_L  s2, 2*SZ_GPR(sp)
++    GPR_L  s3, 3*SZ_GPR(sp)
++    GPR_L  s4, 4*SZ_GPR(sp)
++    GPR_L  s5, 5*SZ_GPR(sp)
++    GPR_L  s6, 6*SZ_GPR(sp)
++    GPR_L  s7, 7*SZ_GPR(sp)
++    GPR_L  s8, 8*SZ_GPR(sp)
++    GPR_L  s9, 9*SZ_GPR(sp)
++    GPR_L s10, 10*SZ_GPR(sp)
++    GPR_L s11, 11*SZ_GPR(sp)
++
++    ADDSP(12 * SZ_GPR)
++
++    jalr zero, 0(a1) // return
++    .cfi_endproc
++    .size fiber_switchContext,.-fiber_switchContext
Index: patches/patch-libphobos_libdruntime_core_sys_posix_config_d
===================================================================
RCS file: /cvs/ports/lang/gcc/11/patches/patch-libphobos_libdruntime_core_sys_posix_config_d,v
retrieving revision 1.2
diff -u -p -r1.2 patch-libphobos_libdruntime_core_sys_posix_config_d
--- patches/patch-libphobos_libdruntime_core_sys_posix_config_d	11 Mar 2022 19:28:58 -0000	1.2
+++ patches/patch-libphobos_libdruntime_core_sys_posix_config_d	25 Jun 2024 06:24:27 -0000
@@ -1,7 +1,7 @@
 Index: libphobos/libdruntime/core/sys/posix/config.d
 --- libphobos/libdruntime/core/sys/posix/config.d.orig
 +++ libphobos/libdruntime/core/sys/posix/config.d
-@@ -169,6 +169,12 @@ else version (OpenBSD)
+@@ -169,11 +169,23 @@ else version (OpenBSD)
          enum _STACKALIGNBYTES = 15;
          enum _MAX_PAGE_SHIFT = 12;
      }
@@ -14,3 +14,14 @@ Index: libphobos/libdruntime/core/sys/po
      else version (SPARC64)
      {
          enum _ALIGNBYTES = 15;
+         enum _STACKALIGNBYTES = 15;
+         enum _MAX_PAGE_SHIFT = 13;
++    }
++    else version (RISCV64)
++    {
++        enum _ALIGNBYTES = c_long.sizeof - 1;
++        enum _STACKALIGNBYTES = 15;
++        enum _MAX_PAGE_SHIFT = 12;
+     }
+     else
+         static assert(false, "Architecture not supported.");
Index: patches/patch-libphobos_libdruntime_core_sys_posix_setjmp_d
===================================================================
RCS file: /cvs/ports/lang/gcc/11/patches/patch-libphobos_libdruntime_core_sys_posix_setjmp_d,v
retrieving revision 1.3
diff -u -p -r1.3 patch-libphobos_libdruntime_core_sys_posix_setjmp_d
--- patches/patch-libphobos_libdruntime_core_sys_posix_setjmp_d	11 Mar 2022 19:28:58 -0000	1.3
+++ patches/patch-libphobos_libdruntime_core_sys_posix_setjmp_d	25 Jun 2024 06:24:27 -0000
@@ -12,7 +12,7 @@ Index: libphobos/libdruntime/core/sys/po
      else version (MIPS64)
      {
          enum _JBLEN = 83;
-@@ -276,6 +280,10 @@ else version (OpenBSD)
+@@ -276,6 +280,14 @@ else version (OpenBSD)
      else version (SPARC64)
      {
          enum _JBLEN = 14;
@@ -20,6 +20,10 @@ Index: libphobos/libdruntime/core/sys/po
 +    else version (AArch64)
 +    {
 +        enum _JBLEN = 64;
++    }
++    else version (RISCV64)
++    {
++        enum _JBLEN = 32;
      }
      else
          static assert(0);
Index: patches/patch-libphobos_libdruntime_core_sys_posix_ucontext_d
===================================================================
RCS file: /cvs/ports/lang/gcc/11/patches/patch-libphobos_libdruntime_core_sys_posix_ucontext_d,v
retrieving revision 1.2
diff -u -p -r1.2 patch-libphobos_libdruntime_core_sys_posix_ucontext_d
--- patches/patch-libphobos_libdruntime_core_sys_posix_ucontext_d	11 Mar 2022 19:28:58 -0000	1.2
+++ patches/patch-libphobos_libdruntime_core_sys_posix_ucontext_d	25 Jun 2024 06:24:27 -0000
@@ -27,3 +27,29 @@ Index: libphobos/libdruntime/core/sys/po
      else version (SPARC64)
      {
          struct sigcontext
+@@ -1393,6 +1412,25 @@ else version (OpenBSD)
+             c_long sc_g1;
+             c_long sc_o0;
+             int    sc_mask;
++        }
++    }
++    else version (RISCV64)
++    {
++        struct sigcontext
++        {
++            int        __sc_unused;
++            int        sc_mask;
++            c_long     sc_ra;
++            c_long     sc_sp;
++            c_long     sc_gp;
++            c_long     sc_tp;
++            c_long[7]  sc_t;
++            c_long[12] sc_s;
++            c_long[8]  sc_a;
++            c_long     sc_sepc;
++            c_long[32] sc_f;
++            c_long     sc_fcsr;
++            c_long     sc_cookie;
+         }
+     }
+     else
Index: patches/patch-libphobos_libdruntime_core_thread_fiber_d
===================================================================
RCS file: /cvs/ports/lang/gcc/11/patches/patch-libphobos_libdruntime_core_thread_fiber_d,v
retrieving revision 1.2
diff -u -p -r1.2 patch-libphobos_libdruntime_core_thread_fiber_d
--- patches/patch-libphobos_libdruntime_core_thread_fiber_d	11 Mar 2022 19:28:58 -0000	1.2
+++ patches/patch-libphobos_libdruntime_core_thread_fiber_d	25 Jun 2024 06:24:27 -0000
@@ -24,7 +24,23 @@ Index: libphobos/libdruntime/core/thread
              version = AlignFiberStackTo16Byte;
          }
      }
-@@ -1033,10 +1036,13 @@ class Fiber (private)
+@@ -174,6 +177,15 @@ private
+     {
+         version = AlignFiberStackTo16Byte;
+     }
++    else version (RISCV64)
++    {
++        version (Posix)
++        {
++            version = AsmRISCV64_Posix;
++            version = AsmExternal;
++            version = AlignFiberStackTo16Byte;
++        }
++    }
+ 
+     version (Posix)
+     {
+@@ -1033,10 +1045,13 @@ class Fiber (private)
                  // Allocate more for the memory guard
                  sz += guardPageSize;
  
@@ -39,7 +55,7 @@ Index: libphobos/libdruntime/core/thread
                                 -1,
                                 0 );
                  if ( m_pmem == MAP_FAILED )
-@@ -1338,27 +1344,22 @@ class Fiber (private)
+@@ -1338,27 +1353,22 @@ class Fiber (private)
          }
          else version (AsmPPC_Posix)
          {
@@ -78,3 +94,22 @@ Index: libphobos/libdruntime/core/thread
              }
  
              assert( (cast(size_t) pstack & 0x0f) == 0 );
+@@ -1480,6 +1490,18 @@ class Fiber (private)
+              * Position the stack pointer above the lr register
+              */
+             pstack += int.sizeof * 1;
++        }
++        else version (AsmRISCV64_Posix)
++        {
++            version (StackGrowsDown) {}
++            else
++                static assert(false, "Only full descending stacks supported on RISC-V 64");
++
++            // Only need to set return address (lr).  Everything else is fine
++            // zero initialized.
++            pstack -= size_t.sizeof * 12;
++            push(cast(size_t) &fiber_entryPoint);
++            pstack += size_t.sizeof;
+         }
+         else version (GNU_AsmX86_Windows)
+         {