Skip to content

Commit 3840d49

Browse files
sorearatgreen
authored andcommitted
New RISC-V port (#281)
* Add RISC-V support This patch adds support for the RISC-V architecture (https://riscv.org). This patch has been tested using QEMU user-mode emulation and GCC 7.2.0 in the following configurations: * -march=rv32imac -mabi=ilp32 * -march=rv32g -mabi=ilp32d * -march=rv64imac -mabi=lp64 * -march=rv64g -mabi=lp64d The ABI currently can be found at https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md . * Add RISC-V to README * RISC-V: fix configure.host
1 parent dca52b5 commit 3840d49

File tree

7 files changed

+739
-0
lines changed

7 files changed

+739
-0
lines changed

Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ noinst_HEADERS = \
109109
src/or1k/ffitarget.h \
110110
src/pa/ffitarget.h \
111111
src/powerpc/ffitarget.h src/powerpc/asm.h src/powerpc/ffi_powerpc.h \
112+
src/riscv/ffitarget.h \
112113
src/s390/ffitarget.h src/s390/internal.h \
113114
src/sh/ffitarget.h \
114115
src/sh64/ffitarget.h \
@@ -144,6 +145,7 @@ EXTRA_libffi_la_SOURCES = \
144145
src/powerpc/linux64_closure.S src/powerpc/ppc_closure.S \
145146
src/powerpc/aix.S src/powerpc/darwin.S src/powerpc/aix_closure.S \
146147
src/powerpc/darwin_closure.S src/powerpc/ffi_darwin.c \
148+
src/riscv/ffi.c src/riscv/sysv.S \
147149
src/s390/ffi.c src/s390/sysv.S \
148150
src/sh/ffi.c src/sh/sysv.S \
149151
src/sh64/ffi.c src/sh64/sysv.S \

README

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ tested:
8484
| PowerPC 64-bit | FreeBSD | GCC |
8585
| PowerPC 64-bit | Linux ELFv1 | GCC |
8686
| PowerPC 64-bit | Linux ELFv2 | GCC |
87+
| RISC-V 32-bit | Linux | GCC |
88+
| RISC-V 64-bit | Linux | GCC |
8789
| S390 | Linux | GCC |
8890
| S390X | Linux | GCC |
8991
| SPARC | Linux | GCC |
@@ -188,6 +190,7 @@ See the git log for details at http://github.com/libffi/libffi.
188190

189191
4.0 TBD
190192
New API in support of GO closures.
193+
Add RISC-V support.
191194

192195
3.2.1 Nov-12-14
193196
Build fix for non-iOS AArch64 targets.

configure.host

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ case "${host}" in
206206
TARGET=POWERPC; TARGETDIR=powerpc
207207
;;
208208

209+
riscv*-*)
210+
TARGET=RISCV; TARGETDIR=riscv
211+
SOURCES="ffi.c sysv.S"
212+
;;
213+
209214
s390-*-* | s390x-*-*)
210215
TARGET=S390; TARGETDIR=s390
211216
SOURCES="ffi.c sysv.S"

include/ffi_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ void ffi_type_test(ffi_type *a, char *file, int line);
7474
#define FFI_ASSERT_VALID_TYPE(x)
7575
#endif
7676

77+
/* v cast to size_t and aligned up to a multiple of a */
7778
#define FFI_ALIGN(v, a) (((((size_t) (v))-1) | ((a)-1))+1)
79+
/* v cast to size_t and aligned down to a multiple of a */
7880
#define ALIGN_DOWN(v, a) (((size_t) (v)) & -a)
7981

8082
/* Perform machine dependent cif processing */

0 commit comments

Comments
 (0)