Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a5dabdc

Browse files
davidltDavid AbdurachmanovCropi
authoredJan 3, 2025
Add support for RISC-V 32-bit & 64-bit (riscv32, riscv64) (#73)
* Add support for RISC-V 32-bit & 64-bit (riscv32, riscv64) archs --------- Signed-off-by: David Abdurachmanov <davidlt@rivosinc.com> Co-authored-by: David Abdurachmanov <davidlt@rivosinc.com> Co-authored-by: Attila Lakatos <Cropi@users.noreply.github.com>
1 parent 0351700 commit a5dabdc

12 files changed

+855
-2
lines changed
 

‎auparse/interpret.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ static const char *print_arch(const char *val, unsigned int machine)
713713
const char *ptr;
714714
char *out;
715715

716-
if (machine > MACH_AARCH64) {
716+
if (machine > MACH_RISCV64) {
717717
unsigned int ival;
718718

719719
errno = 0;

‎configure.ac

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,18 @@ fi
323323
AM_CONDITIONAL(USE_AARCH64, test x$use_aarch64 = xyes)
324324
AC_MSG_RESULT($use_aarch64)
325325

326+
withval=""
327+
AC_MSG_CHECKING(whether to include riscv processor support)
328+
AC_ARG_WITH(riscv,
329+
AS_HELP_STRING([--with-riscv],[enable riscv processor support]),
330+
use_riscv=$withval,
331+
use_riscv=no)
332+
if test x$use_riscv != xno ; then
333+
AC_DEFINE(WITH_RISCV,1,[Define if you want to enable RISC-V processor support.])
334+
fi
335+
AM_CONDITIONAL(USE_RISCV, test x$use_riscv = xyes)
336+
AC_MSG_RESULT($use_riscv)
337+
326338
withval=""
327339
AC_MSG_CHECKING(whether to use apparmor)
328340
AC_ARG_WITH(apparmor,

‎lib/Makefile.am

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ endif
5454
if USE_AARCH64
5555
BUILT_SOURCES += aarch64_tables.h
5656
endif
57+
if USE_RISCV
58+
BUILT_SOURCES += riscv64_tables.h riscv32_tables.h
59+
endif
5760
noinst_PROGRAMS = gen_actiontabs_h gen_errtabs_h gen_fieldtabs_h \
5861
gen_flagtabs_h gen_fstypetabs_h gen_ftypetabs_h gen_i386_tables_h \
5962
gen_machinetabs_h gen_msg_typetabs_h gen_optabs_h \
@@ -65,6 +68,9 @@ endif
6568
if USE_AARCH64
6669
noinst_PROGRAMS += gen_aarch64_tables_h
6770
endif
71+
if USE_RISCV
72+
noinst_PROGRAMS += gen_riscv64_tables_h gen_riscv32_tables_h
73+
endif
6874
gen_actiontabs_h_SOURCES = gen_tables.c gen_tables.h actiontab.h
6975
gen_actiontabs_h_CFLAGS = '-DTABLE_H="actiontab.h"'
7076
$(gen_actiontabs_h_OBJECTS): CC=$(CC_FOR_BUILD)
@@ -108,6 +114,34 @@ aarch64_tables.h: gen_aarch64_tables_h Makefile
108114
./gen_aarch64_tables_h --lowercase --i2s --s2i aarch64_syscall > $@
109115
endif
110116

117+
if USE_RISCV
118+
gen_riscv64_tables_h_SOURCES = gen_tables.c gen_tables.h riscv64_table.h
119+
gen_riscv64_tables_h_CFLAGS = '-DTABLE_H="riscv64_table.h"'
120+
$(gen_riscv64_tables_h_OBJECTS): CC=$(CC_FOR_BUILD)
121+
$(gen_riscv64_tables_h_OBJECTS): CFLAGS=$(CFLAGS_FOR_BUILD)
122+
$(gen_riscv64_tables_h_OBJECTS): CPPFLAGS=$(CPPFLAGS_FOR_BUILD)
123+
$(gen_riscv64_tables_h_OBJECTS): LDFLAGS=$(LDFLAGS_FOR_BUILD)
124+
gen_riscv64_tables_h$(BUILD_EXEEXT): CC=$(CC_FOR_BUILD)
125+
gen_riscv64_tables_h$(BUILD_EXEEXT): CFLAGS=$(CFLAGS_FOR_BUILD)
126+
gen_riscv64_tables_h$(BUILD_EXEEXT): CPPFLAGS=$(CPPFLAGS_FOR_BUILD)
127+
gen_riscv64_tables_h$(BUILD_EXEEXT): LDFLAGS=$(LDFLAGS_FOR_BUILD)
128+
riscv64_tables.h: gen_riscv64_tables_h Makefile
129+
./gen_riscv64_tables_h --lowercase --i2s --s2i riscv64_syscall > $@
130+
131+
gen_riscv32_tables_h_SOURCES = gen_tables.c gen_tables.h riscv32_table.h
132+
gen_riscv32_tables_h_CFLAGS = '-DTABLE_H="riscv32_table.h"'
133+
$(gen_riscv32_tables_h_OBJECTS): CC=$(CC_FOR_BUILD)
134+
$(gen_riscv32_tables_h_OBJECTS): CFLAGS=$(CFLAGS_FOR_BUILD)
135+
$(gen_riscv32_tables_h_OBJECTS): CPPFLAGS=$(CPPFLAGS_FOR_BUILD)
136+
$(gen_riscv32_tables_h_OBJECTS): LDFLAGS=$(LDFLAGS_FOR_BUILD)
137+
gen_riscv32_tables_h$(BUILD_EXEEXT): CC=$(CC_FOR_BUILD)
138+
gen_riscv32_tables_h$(BUILD_EXEEXT): CFLAGS=$(CFLAGS_FOR_BUILD)
139+
gen_riscv32_tables_h$(BUILD_EXEEXT): CPPFLAGS=$(CPPFLAGS_FOR_BUILD)
140+
gen_riscv32_tables_h$(BUILD_EXEEXT): LDFLAGS=$(LDFLAGS_FOR_BUILD)
141+
riscv32_tables.h: gen_riscv32_tables_h Makefile
142+
./gen_riscv32_tables_h --lowercase --i2s --s2i riscv32_syscall > $@
143+
endif
144+
111145
gen_errtabs_h_SOURCES = gen_tables.c gen_tables.h errtab.h
112146
gen_errtabs_h_CFLAGS = '-DTABLE_H="errtab.h"'
113147
$(gen_errtabs_h_OBJECTS): CC=$(CC_FOR_BUILD)

‎lib/libaudit.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,8 @@ int audit_determine_machine(const char *arch)
14411441
machine = MACH_S390;
14421442
else if (bits == ~__AUDIT_ARCH_64BIT && machine == MACH_AARCH64)
14431443
machine = MACH_ARM;
1444+
else if (bits == ~__AUDIT_ARCH_64BIT && machine == MACH_RISCV64)
1445+
machine = MACH_RISCV32;
14441446

14451447
/* Check for errors - return -6
14461448
* We don't allow 32 bit machines to specify 64 bit. */
@@ -1469,11 +1471,18 @@ int audit_determine_machine(const char *arch)
14691471
if (bits && bits != __AUDIT_ARCH_64BIT)
14701472
return -6; /* 64 bit only */
14711473
break;
1474+
#endif
1475+
#ifdef WITH_RISCV
1476+
case MACH_RISCV32:
1477+
if (bits == __AUDIT_ARCH_64BIT)
1478+
return -6;
1479+
break;
14721480
#endif
14731481
case MACH_86_64: /* fallthrough */
14741482
case MACH_PPC64: /* fallthrough */
14751483
case MACH_S390X: /* fallthrough */
14761484
case MACH_IO_URING:
1485+
case MACH_RISCV64: /* fallthrough */
14771486
break;
14781487
case MACH_PPC64LE: /* 64 bit only */
14791488
if (bits && bits != __AUDIT_ARCH_64BIT)

‎lib/libaudit.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ typedef enum {
180180
MACH_ARM,
181181
MACH_AARCH64,
182182
MACH_PPC64LE,
183-
MACH_IO_URING
183+
MACH_IO_URING,
184+
MACH_RISCV32,
185+
MACH_RISCV64
184186
} machine_t;
185187

186188
/* These are the valid audit failure tunable enum values */

‎lib/lookup_table.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
#ifdef WITH_AARCH64
4848
#include "aarch64_tables.h"
4949
#endif
50+
#ifdef WITH_RISCV
51+
#include "riscv64_tables.h"
52+
#include "riscv32_tables.h"
53+
#endif
5054
#include "i386_tables.h"
5155
#include "ppc_tables.h"
5256
#include "s390_tables.h"
@@ -86,6 +90,10 @@ static const struct int_transtab elftab[] = {
8690
#ifdef WITH_AARCH64
8791
{ MACH_AARCH64, AUDIT_ARCH_AARCH64},
8892
#endif
93+
#ifdef WITH_RISCV
94+
{ MACH_RISCV32, AUDIT_ARCH_RISCV32 },
95+
{ MACH_RISCV64, AUDIT_ARCH_RISCV64 },
96+
#endif
8997
};
9098
#define AUDIT_ELF_NAMES (sizeof(elftab)/sizeof(elftab[0]))
9199

@@ -157,6 +165,14 @@ int audit_name_to_syscall(const char *sc, int machine)
157165
found = aarch64_syscall_s2i(sc, &res);
158166
break;
159167
#endif
168+
#ifdef WITH_RISCV
169+
case MACH_RISCV64:
170+
found = riscv64_syscall_s2i(sc, &res);
171+
break;
172+
case MACH_RISCV32:
173+
found = riscv32_syscall_s2i(sc, &res);
174+
break;
175+
#endif
160176
#endif
161177
case MACH_IO_URING:
162178
return audit_name_to_uringop(sc);
@@ -203,6 +219,12 @@ const char *audit_syscall_to_name(int sc, int machine)
203219
#ifdef WITH_AARCH64
204220
case MACH_AARCH64:
205221
return aarch64_syscall_i2s(sc);
222+
#endif
223+
#ifdef WITH_RISCV
224+
case MACH_RISCV64:
225+
return riscv64_syscall_i2s(sc);
226+
case MACH_RISCV32:
227+
return riscv32_syscall_i2s(sc);
206228
#endif
207229
case MACH_IO_URING:
208230
return audit_uringop_to_name(sc);

‎lib/machinetab.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,8 @@ _S(MACH_AARCH64, "armv8l")
4545
#ifdef WITH_IO_URING
4646
_S(MACH_IO_URING, "uring")
4747
#endif
48+
#ifdef WITH_RISCV
49+
_S(MACH_RISCV32, "riscv32")
50+
_S(MACH_RISCV64, "riscv64")
51+
#endif
4852

0 commit comments

Comments
 (0)
Please sign in to comment.