bug-mes
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-mes] [PATCH mescc-tools 2/2] Architectural_displacement: Handle ARM


From: Danny Milosavljevic
Subject: [bug-mes] [PATCH mescc-tools 2/2] Architectural_displacement: Handle ARM.
Date: Wed, 13 Feb 2019 16:07:50 +0100

---
 hex2_linker.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/hex2_linker.c b/hex2_linker.c
index 47d305f..6147d79 100644
--- a/hex2_linker.c
+++ b/hex2_linker.c
@@ -218,7 +218,28 @@ int Architectural_displacement(int target, int base)
        if(0 == Architecture) return (target - base);
        else if(1 == Architecture) return (target - base);
        else if(2 == Architecture) return (target - base);
-       else if(40 == Architecture) return (target - base);
+       else if(40 == Architecture)
+       {
+               /* Note: Branch displacements on ARM are in number of
+                  instructions to skip, basically. */
+               if (base & 3)
+               {
+                       file_print("Unaligned base, aborting\n", stderr);
+                       exit(EXIT_FAILURE);
+               }
+               if (target & 3)
+               {
+                       file_print("Unaligned target, aborting\n", stderr);
+                       exit(EXIT_FAILURE);
+               }
+               /* The "fetch" stage already moved forward by 8 from the
+                  beginning of the instruction because it is already
+                  prefetching the next instruction.
+                  We already moved forward by 4 (see Update_Pointer).
+                  Compensate for it by subtracting the space for
+                  one instruction (not the branch instruction). */
+               return ((target - base) >> 2) - 1;
+       }
 
        file_print("Unknown Architecture, aborting before harm is done\n", 
stderr);
        exit(EXIT_FAILURE);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]