REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4433

There is a return value bug. SyncIncrement and SyncDecrement functions
should return the updated value. But destination register rd in
amoadd instruction will not have final incremented value. Fix this
by loading the incremented value from the memory where amoadd
instruction would have stored the final incremented value.

Signed-off-by: Sunil V L <suni...@ventanamicro.com>
Reported-by: Chao Li <lic...@loongson.cn>
Cc: Daniel Schaefer <g...@danielschaefer.me>
Cc: Michael D Kinney <michael.d.kin...@intel.com>
Cc: Liming Gao <gaolim...@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang....@intel.com>
Cc: Andrei Warkentin <andrei.warken...@intel.com>
---
 .../Library/BaseSynchronizationLib/RiscV64/Synchronization.S  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Library/BaseSynchronizationLib/RiscV64/Synchronization.S 
b/MdePkg/Library/BaseSynchronizationLib/RiscV64/Synchronization.S
index f287ef38f651..34672507d8dc 100644
--- a/MdePkg/Library/BaseSynchronizationLib/RiscV64/Synchronization.S
+++ b/MdePkg/Library/BaseSynchronizationLib/RiscV64/Synchronization.S
@@ -61,7 +61,7 @@ exit2:
 ASM_PFX (InternalSyncIncrement):
     li  a1, 1
     amoadd.w  a2, a1, (a0)
-    mv  a0, a2
+    ld  a0, 0(a0)
     ret
 
 //
@@ -72,5 +72,5 @@ ASM_PFX (InternalSyncIncrement):
 ASM_PFX (InternalSyncDecrement):
     li  a1, -1
     amoadd.w  a2, a1, (a0)
-    mv  a0, a2
+    ld  a0, 0(a0)
     ret
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#105809): https://edk2.groups.io/g/devel/message/105809
Mute This Topic: https://groups.io/mt/99367819/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to