bug-mes
[Top][All Lists]
Advanced

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

[bug-mes] Displacements on ARM


From: Danny Milosavljevic
Subject: [bug-mes] Displacements on ARM
Date: Thu, 7 Feb 2019 10:26:39 +0100

Hi,

I'm currently improving the support for displacements on ARM, adding support 
for branches.

However, there's already a small implementation for displacements in 
mescc-tools in hex2_linker.c in storePointer.

Jeremiah, who are the users of the following chunk?

        if('!' == ch)
        {
                if(40 == Architecture) outputPointer(displacement - 7, 1); /* 
Deal with ! */
                else outputPointer(displacement, 1); /* Deal with ! */
        }

For branches the immediate encoded in the branch instruction should be:

  (target - base - 8)/4

if we assume that base is still on the beginning of the branch instruction.

But Architectural_displacement says:

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); <--------

        file_print("Unknown Architecture, aborting before harm is done\n", 
stderr);
        exit(EXIT_FAILURE);
}

I'm tempted to just change the Architectural_displacement to say

        else if(40 == Architecture) return (target - (base - 1) - 8)/4;

Which means

        else if(40 == Architecture) return (target - base + 1 - 8)/4;

Which means

        else if(40 == Architecture) return (target - base - 7)/4;

Or maybe much better to do the following in general on ARM (because it works no 
matter where in the instruction the ~,!,whatever is):

        else if(40 == Architecture) return (target - (base &~ 3) - 8)/4;

Or maybe faster and needs fewer (complicated) division instructions

        else if(40 == Architecture) return ((target - (base &~ 3)) >> 2) - 2;

But that would mean that we couldn't ever store byte-offset displacements (for 
example for load/store instructions).
That could be fine, though.  Is it?

But why is the following special case in storePointer rather than in 
Architectural_displacement ?

                if(40 == Architecture) outputPointer(displacement - 7, 1); /* 
Deal with ! */

(To be clear, I'm not objecting, I just want to understand it :) )

Attachment: pgpOIsh1RCOnD.pgp
Description: OpenPGP digital signature


reply via email to

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