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: Implement some base instructions #6014

Merged
merged 8 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 4 additions & 3 deletions core/arch/asm_defines.asm
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,11 @@ ASSUME fs:_DATA @N@\
* x4(tp) : Thread pointer
* x5(t0) : Temporary/alternate link register
* x6..7(t1..2) : Temporaries
* x8(s0/fp) : Calee saved register/frame pointer
* x9(s1) : Calee saved register
* x8(s0/fp) : Callee saved register/frame pointer
* x9(s1) : Callee saved register
* x10..11(a0..1) : Function arguments/return values
* x12..17(a2..7) : Function arguments
* x18..27(s2..11) : Calee saved registers
* x18..27(s2..11) : Callee saved registers
* x28..31(t3..6) : Temporaries
*
* f0..7(ft0..7) : FP temporaries
Expand All @@ -563,6 +563,7 @@ ASSUME fs:_DATA @N@\
# define ARG6 REG_R15
# define ARG7 REG_R16
# define ARG8 REG_R17
# define SYSNUM_REG REG_R17
/* Arguments are passed on stack right-to-left. */
# define ARG9 0(REG_SP) /* no ret addr */
# define ARG10 ARG_SZ(REG_SP)
Expand Down
41 changes: 37 additions & 4 deletions core/arch/riscv64/riscv64.asm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,34 @@ GLOBAL_LABEL(cpuid_supported:)
*/
DECLARE_FUNC(call_switch_stack)
GLOBAL_LABEL(call_switch_stack:)
/* FIXME i#3544: Not implemented */
/* Init the stack. */
addi sp, sp, -32
/* Use two callee-save regs to call func. */
sd ra, 24 (sp)
sd s0, 16 (sp)
sd s1, 8 (sp)
sd s2, 0 (sp)
/* Check mutex_to_free. */
beqz ARG4, call_dispatch_alt_stack_no_free
/* Release the mutex. */
addi ARG4, x0, 0
call_dispatch_alt_stack_no_free:
/* Copy AGG5 (return_on_return) to callee-save reg. */
mv s2, ARG5
/* Switch the stack. */
addi s0, sp, 0
addi sp, ARG2, 0
/* Call func. */
jr ARG3
/* Switch stack back. */
addi sp, s0, 0
beqz s2, GLOBAL_LABEL(unexpected_return)
/* Restore the stack. */
ld s2 0 (sp)
ld s1, 8 (sp)
ld s0, 16 (sp)
ld ra, 24 (sp)
addi sp, sp, 32
ret
END_FUNC(call_switch_stack)

Expand Down Expand Up @@ -138,7 +165,10 @@ GLOBAL_LABEL(cleanup_and_terminate:)
/* void atomic_add(int *adr, int val) */
DECLARE_FUNC(atomic_add)
GLOBAL_LABEL(atomic_add:)
/* FIXME i#3544: Not implemented */
1: lr.d a2, (a0)
add a2, a2, a1
sc.d a3, a2, (a0)
bnez a3, 1b
ret
END_FUNC(atomic_add)

Expand Down Expand Up @@ -240,13 +270,16 @@ GLOBAL_LABEL(dynamorio_clone:)

DECLARE_FUNC(dynamorio_sigreturn)
GLOBAL_LABEL(dynamorio_sigreturn:)
/* FIXME i#3544: Not implemented */
li SYSNUM_REG, SYS_rt_sigreturn
ecall
jal GLOBAL_REF(unexpected_return)
END_FUNC(dynamorio_sigreturn)

DECLARE_FUNC(dynamorio_sys_exit)
GLOBAL_LABEL(dynamorio_sys_exit:)
/* FIXME i#3544: Not implemented */
li a0, 0 /* exit code */
li SYSNUM_REG, SYS_exit /* SYS_exit number */
ecall
jal GLOBAL_REF(unexpected_return)
END_FUNC(dynamorio_sys_exit)

Expand Down