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