Explorar o código

CPU: Fix PC alignment for ADR thumb instruction (#6613)

* Fix PC alignment for ADR thumb instruction

* PPTC version bump
gdkchan %!s(int64=2) %!d(string=hai) anos
pai
achega
808803d97a

+ 12 - 0
src/ARMeilleure/Instructions/InstEmitAlu32.cs

@@ -19,6 +19,12 @@ namespace ARMeilleure.Instructions
             Operand n = GetAluN(context);
             Operand n = GetAluN(context);
             Operand m = GetAluM(context, setCarry: false);
             Operand m = GetAluM(context, setCarry: false);
 
 
+            if (op.Rn == RegisterAlias.Aarch32Pc && op is OpCodeT32AluImm12)
+            {
+                // For ADR, PC is always 4 bytes aligned, even in Thumb mode.
+                n = context.BitwiseAnd(n, Const(~3u));
+            }
+
             Operand res = context.Add(n, m);
             Operand res = context.Add(n, m);
 
 
             if (ShouldSetFlags(context))
             if (ShouldSetFlags(context))
@@ -467,6 +473,12 @@ namespace ARMeilleure.Instructions
             Operand n = GetAluN(context);
             Operand n = GetAluN(context);
             Operand m = GetAluM(context, setCarry: false);
             Operand m = GetAluM(context, setCarry: false);
 
 
+            if (op.Rn == RegisterAlias.Aarch32Pc && op is OpCodeT32AluImm12)
+            {
+                // For ADR, PC is always 4 bytes aligned, even in Thumb mode.
+                n = context.BitwiseAnd(n, Const(~3u));
+            }
+
             Operand res = context.Subtract(n, m);
             Operand res = context.Subtract(n, m);
 
 
             if (ShouldSetFlags(context))
             if (ShouldSetFlags(context))

+ 1 - 1
src/ARMeilleure/Translation/PTC/Ptc.cs

@@ -29,7 +29,7 @@ namespace ARMeilleure.Translation.PTC
         private const string OuterHeaderMagicString = "PTCohd\0\0";
         private const string OuterHeaderMagicString = "PTCohd\0\0";
         private const string InnerHeaderMagicString = "PTCihd\0\0";
         private const string InnerHeaderMagicString = "PTCihd\0\0";
 
 
-        private const uint InternalVersion = 5518; //! To be incremented manually for each change to the ARMeilleure project.
+        private const uint InternalVersion = 6613; //! To be incremented manually for each change to the ARMeilleure project.
 
 
         private const string ActualDir = "0";
         private const string ActualDir = "0";
         private const string BackupDir = "1";
         private const string BackupDir = "1";