Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i#3544 riscv64: Implemented dr_setjmp and dr_longjmp #6071

Merged
merged 9 commits into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/arch/arch_exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,10 @@ typedef struct dr_jmp_buf_t {
#elif defined(AARCH64) /* for aarch64.asm */
# define REGS_IN_JMP_BUF 22 /* See dr_setjmp and dr_longjmp. */
reg_t regs[REGS_IN_JMP_BUF];
#endif /* X86/AARCH64/ARM */
#elif defined(RISCV64) /* For riscv64.asm. */
# define REGS_IN_JMP_BUF 25 /* See dr_setjmp and dr_longjmp. */
reg_t regs[REGS_IN_JMP_BUF];
#endif /* X86/AARCH64/ARM/RISCV64 */
#if defined(UNIX) && defined(DEBUG)
/* i#226/PR 492568: we avoid the cost of storing this by using the
* mask in the fault's signal frame, but we do record it in debug
Expand Down
73 changes: 68 additions & 5 deletions core/arch/riscv64/riscv64.asm
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,51 @@ ADDRTAKEN_LABEL(safe_read_asm_recover:)
*/
DECLARE_EXPORTED_FUNC(dr_try_start)
GLOBAL_LABEL(dr_try_start:)
addi ARG1, ARG1, TRY_CXT_SETJMP_OFFS
addi ARG1, ARG1, TRY_CXT_SETJMP_OFFS
j GLOBAL_REF(dr_setjmp)
END_FUNC(dr_try_start)

/*
/* We save only callee-saved registers: SP, x8/fp, x9, x18-x27, f8-9, f18-27:
* a total of 25 reg_t (64-bit) slots. See definition of dr_jmp_buf_t.
*
* int dr_setjmp(dr_jmp_buf_t *buf);
*/
DECLARE_FUNC(dr_setjmp)
GLOBAL_LABEL(dr_setjmp:)
/* FIXME i#3544: Not implemented */
mv t0, sp
shiptux marked this conversation as resolved.
Show resolved Hide resolved
sd t0, 0 (ARG1)
sd x8, 8 (ARG1)
sd x9, 16 (ARG1)
sd x18, 24 (ARG1)
sd x19, 32 (ARG1)
sd x20, 40 (ARG1)
sd x21, 48 (ARG1)
sd x22, 56 (ARG1)
sd x23, 64 (ARG1)
sd x24, 72 (ARG1)
sd x25, 80 (ARG1)
sd x26, 88 (ARG1)
sd x27, 96 (ARG1)
fsd f8, 104 (ARG1)
fsd f9, 112 (ARG1)
fsd f18, 120 (ARG1)
fsd f19, 128 (ARG1)
fsd f20, 136 (ARG1)
fsd f21, 144 (ARG1)
fsd f22, 152 (ARG1)
fsd f23, 160 (ARG1)
fsd f24, 168 (ARG1)
fsd f25, 176 (ARG1)
fsd f26, 184 (ARG1)
fsd f27, 192 (ARG1)
# ifdef UNIX
addi sp, sp, -16
sd ra, 0 (sp)
jal GLOBAL_REF(dr_setjmp_sigmask)
ld ra, 0 (sp)
add sp, sp, 16
# endif
li a0, 0
ret
END_FUNC(dr_setjmp)

Expand All @@ -226,8 +261,36 @@ GLOBAL_LABEL(dr_setjmp:)
*/
DECLARE_FUNC(dr_longjmp)
GLOBAL_LABEL(dr_longjmp:)
/* FIXME i#3544: Not implemented */
ret
ld t0, 0 (ARG1)
mv sp, t0
ld x8, 8 (ARG1)
ld x9, 16 (ARG1)
ld x18, 24 (ARG1)
ld x19, 32 (ARG1)
ld x20, 40 (ARG1)
ld x21, 48 (ARG1)
ld x22, 56 (ARG1)
ld x23, 64 (ARG1)
ld x24, 72 (ARG1)
ld x25, 80 (ARG1)
ld x26, 88 (ARG1)
ld x27, 96 (ARG1)
fld f8, 104 (ARG1)
fld f9, 112 (ARG1)
fld f18, 120 (ARG1)
fld f19, 128 (ARG1)
fld f20, 136 (ARG1)
fld f21, 144 (ARG1)
fld f22, 152 (ARG1)
fld f23, 160 (ARG1)
fld f24, 168 (ARG1)
fld f25, 176 (ARG1)
fld f26, 184 (ARG1)
fld f27, 192 (ARG1)
beqz ARG1, skip
shiptux marked this conversation as resolved.
Show resolved Hide resolved
addi ARG1, ARG1, 1
skip:
jalr ra
shiptux marked this conversation as resolved.
Show resolved Hide resolved
shiptux marked this conversation as resolved.
Show resolved Hide resolved
END_FUNC(dr_longjmp)

/* int atomic_swap(int *adr, int val) */
Expand Down