microcontrollerelfmsp430relocation

ELF Relocation Types on MSP430


I have to take a relocatable ELF file and fix the addresses in a MSP430-F5529 with red hat compiler (not TI). However, I don't understand how the relocations have to be made as I don't get the notation used.

Here are the types and their details.

Let's take this one for example.

And the following generated ASM :

0C60 0000 : MOVA R12, &0x00000

If we search the MOVA opcode in Wikipedia we see that the structure of the opcode is as it follows:

Offset : [7] [6] [5] [4] [3] [2] [1] [0]

Hex Value : [0] [dst] [6] [src] [src] [src] [src] [src]

We now know that dst C stands for R12 and that the last 20 bits are for the address to be replaced (last 4 bits plus another 16 bits - last 4 0s-).

I know need to understand how to interpret [0,4]+[16,16]. Looks like the [0,4] references to the last 4 bits on the first 2 bytes (0060 0000), but how does it work ? And how should I read the [16,16] ?

Here is the quote of the explanation on the PDF in case someone understands.

The field is specified using the tuple [CS, O, FS], where CS is the container size, O is the starting offset from the LSB of the container to the LSB of the field, and FS is the size of the field. All values are in bits. The notation [x,y]+[z,w] indicates that relocation occupies discontiguous bit ranges, which should be concatenated to form the field.


Solution

  • Your "Offset" values are wrong.

    "ContainerSize: 32" means that you have to view the instruction as a single, little-endian, 32-bit value. As a 32-bit value, it would be written as 00000C60. The four bytes are, in order, 60, 0C, 00, and 00. The bits are as follows:

    31302928272625242322212019181716151413121110 9 8 7 6 5 4 3 2 1 0
     a a a a a a a a a a a a a a a a 0 0 0 0 s s s s 0 1 1 0 a a a a