aboutsummaryrefslogtreecommitdiff
path: root/ARMeilleure/Instructions/InstEmitMemoryExHelper.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2020-12-13 12:19:38 -0300
committerGitHub <noreply@github.com>2020-12-13 12:19:38 -0300
commitc8bb3cc50e32e957609ee190dd5f35b9a349f640 (patch)
tree054243022dfe2de8fe689e0ea64a2f10db4c5705 /ARMeilleure/Instructions/InstEmitMemoryExHelper.cs
parent6bc2733c1796788590c9f0114013d2e4b555e31e (diff)
Fix register read after write on STREX implementation (#1801)
* Fix register read after write on STREX implementation * PTC version update
Diffstat (limited to 'ARMeilleure/Instructions/InstEmitMemoryExHelper.cs')
-rw-r--r--ARMeilleure/Instructions/InstEmitMemoryExHelper.cs19
1 files changed, 18 insertions, 1 deletions
diff --git a/ARMeilleure/Instructions/InstEmitMemoryExHelper.cs b/ARMeilleure/Instructions/InstEmitMemoryExHelper.cs
index 5b890dd3..317e4276 100644
--- a/ARMeilleure/Instructions/InstEmitMemoryExHelper.cs
+++ b/ARMeilleure/Instructions/InstEmitMemoryExHelper.cs
@@ -48,6 +48,18 @@ namespace ARMeilleure.Instructions
Operand exValuePtr = context.Add(arg0, Const((long)NativeContext.GetExclusiveValueOffset()));
context.Store(exAddrPtr, context.BitwiseAnd(address, Const(address.Type, GetExclusiveAddressMask())));
+
+ // Make sure the unused higher bits of the value are cleared.
+ if (size < 3)
+ {
+ context.Store(exValuePtr, Const(0UL));
+ }
+ if (size < 4)
+ {
+ context.Store(context.Add(exValuePtr, Const(exValuePtr.Type, 8L)), Const(0UL));
+ }
+
+ // Store the new exclusive value.
context.Store(exValuePtr, value);
return value;
@@ -74,6 +86,11 @@ namespace ARMeilleure.Instructions
if (exclusive)
{
+ // We overwrite one of the register (Rs),
+ // keep a copy of the values to ensure we are working with the correct values.
+ address = context.Copy(address);
+ value = context.Copy(value);
+
void SetRs(Operand value)
{
if (a32)
@@ -98,7 +115,7 @@ namespace ARMeilleure.Instructions
Operand lblExit = Label();
- SetRs(exFailed);
+ SetRs(Const(1));
context.BranchIfTrue(lblExit, exFailed);