Skip to content

Commit d54e7f1

Browse files
authored
[RISCV][CHERI] Support both Xcheri and Zcheri assembly in runtime libs. (#780)
This is in preparation for standard CHERI encodings. Use the unprefixed instruction mnemonics in compiler-rt and libunwind, to support both xcheri and RVY.
1 parent beaccc5 commit d54e7f1

File tree

3 files changed

+7
-19
lines changed

3 files changed

+7
-19
lines changed

compiler-rt/lib/builtins/riscv/int_mul_impl.inc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,4 @@ __mulxi3:
3030
srli a1, a1, 1
3131
slli a2, a2, 1
3232
bnez a1, .L1
33-
#ifdef __CHERI_PURE_CAPABILITY__
34-
cret
35-
#else
3633
ret
37-
#endif

libunwind/src/UnwindRegistersRestore.S

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,15 +1308,15 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind15Registers_sparc6jumptoEv)
13081308

13091309
.macro restore_fpr num, ctxreg
13101310
#ifdef __CHERI_PURE_CAPABILITY__
1311-
cfld f\num, (RISCV_FOFFSET + RISCV_FSIZE * \num)(c\ctxreg)
1311+
fld f\num, (RISCV_FOFFSET + RISCV_FSIZE * \num)(c\ctxreg)
13121312
#else
13131313
FLOAD f\num, (RISCV_FOFFSET + RISCV_FSIZE * \num)(\ctxreg)
13141314
#endif
13151315
.endm
13161316

13171317
.macro restore_gpr num, ctxreg
13181318
#ifdef __CHERI_PURE_CAPABILITY__
1319-
clc c\num, (__SIZEOF_CHERI_CAPABILITY__ * \num)(c\ctxreg)
1319+
lc c\num, (__SIZEOF_CHERI_CAPABILITY__ * \num)(c\ctxreg)
13201320
#else
13211321
ILOAD x\num, (RISCV_ISIZE * \num)(\ctxreg)
13221322
#endif
@@ -1338,7 +1338,7 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind15Registers_riscv6jumptoEv)
13381338

13391339
// x0 is zero
13401340
#ifdef __CHERI_PURE_CAPABILITY__
1341-
clc c1, (__SIZEOF_CHERI_CAPABILITY__ * 0)(ca0) // restore pc into ra
1341+
lc c1, (__SIZEOF_CHERI_CAPABILITY__ * 0)(ca0) // restore pc into ra
13421342
#else
13431343
ILOAD x1, (RISCV_ISIZE * 0)(a0) // restore pc into ra
13441344
#endif
@@ -1351,11 +1351,7 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind15Registers_riscv6jumptoEv)
13511351
.endr
13521352
restore_gpr 10, a0 // restore a0
13531353

1354-
#ifdef __CHERI_PURE_CAPABILITY__
1355-
cret // jump to cra
1356-
#else
13571354
ret // jump to ra
1358-
#endif
13591355
END_LIBUNWIND_FUNCTION(_ZN9libunwind15Registers_riscv6jumptoEv)
13601356

13611357
#elif defined(__s390x__)

libunwind/src/UnwindRegistersSave.S

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,15 +1237,15 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
12371237

12381238
.macro save_fpr num, ctxreg
12391239
#ifdef __CHERI_PURE_CAPABILITY__
1240-
cfsd f\num, (RISCV_FOFFSET + RISCV_FSIZE * \num)(c\ctxreg)
1240+
fsd f\num, (RISCV_FOFFSET + RISCV_FSIZE * \num)(c\ctxreg)
12411241
#else
12421242
FSTORE f\num, (RISCV_FOFFSET + RISCV_FSIZE * \num)(\ctxreg)
12431243
#endif
12441244
.endm
12451245

12461246
.macro save_gpr num, ctxreg
12471247
#ifdef __CHERI_PURE_CAPABILITY__
1248-
csc c\num, (__SIZEOF_CHERI_CAPABILITY__ * \num)(c\ctxreg)
1248+
sc c\num, (__SIZEOF_CHERI_CAPABILITY__ * \num)(c\ctxreg)
12491249
#else
12501250
ISTORE x\num, (RISCV_ISIZE * \num)(\ctxreg)
12511251
#endif
@@ -1259,7 +1259,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
12591259
#
12601260
DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
12611261
#ifdef __CHERI_PURE_CAPABILITY__
1262-
csc c1, (__SIZEOF_CHERI_CAPABILITY__ * 0)(ca0) // store ra as pc
1262+
sc c1, (__SIZEOF_CHERI_CAPABILITY__ * 0)(ca0) // store ra as pc
12631263
#else
12641264
ISTORE x1, (RISCV_ISIZE * 0)(a0) // store ra as pc
12651265
#endif
@@ -1274,11 +1274,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
12741274
# endif
12751275

12761276
li a0, 0 // return UNW_ESUCCESS
1277-
#ifdef __CHERI_PURE_CAPABILITY__
1278-
cret // jump to cra
1279-
#else
1280-
ret // jump to ra
1281-
#endif
1277+
ret // jump to ra
12821278
END_LIBUNWIND_FUNCTION(__unw_getcontext)
12831279

12841280
#elif defined(__s390x__)

0 commit comments

Comments
 (0)