From 95ab9caba1f2b47c708ba69e4fd54df4003c3e4a Mon Sep 17 00:00:00 2001 From: WangRunji Date: Fri, 26 Oct 2018 02:31:05 +0800 Subject: [PATCH] Add impl of atomic_fetch_* --- kernel/src/arch/riscv32/compiler_rt.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kernel/src/arch/riscv32/compiler_rt.c b/kernel/src/arch/riscv32/compiler_rt.c index c2f2fb8..1d41cf6 100644 --- a/kernel/src/arch/riscv32/compiler_rt.c +++ b/kernel/src/arch/riscv32/compiler_rt.c @@ -46,4 +46,16 @@ char __atomic_compare_exchange_4(int* dst, int* expected, int desired) { return sc_ret == 0; } return 0; +} + +int __atomic_fetch_add_4(int* ptr, int val) { + int res; + __asm__ __volatile__("amoadd.w.rl %0, %1, (%2)" : "=r"(res) : "r"(val), "r"(ptr) : "memory"); + return res; +} + +int __atomic_fetch_sub_4(int* ptr, int val) { + int res; + __asm__ __volatile__("amoadd.w.rl %0, %1, (%2)" : "=r"(res) : "r"(-val), "r"(ptr) : "memory"); + return res; } \ No newline at end of file