2

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.

  • Name : R_MSP430X_ABS20_ADR_DST
  • Signedness : Unsigned
  • ContainerSize : 32
  • Field : [0,4]+[16,16]

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.

10 Rep
  • 2,217
  • 7
  • 19
  • 33
UDKOX
  • 738
  • 3
  • 15

1 Answers1

2

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
CL.
  • 173,858
  • 17
  • 217
  • 259
  • The answer looks awesome. I really think you just solved it, but there is something I am worried about. Wikipedia says it is *Built around a 16-bit CPU*. Does it matter when reading 32 bytes ? Does this still read it like that ? – UDKOX Jan 27 '16 at 19:25
  • The relocation just describes how the fields are layed out in memory. This has nothing to do with how the CPU reads and executes them. – CL. Jan 27 '16 at 20:10
  • I am checking it tomorrw at work and will come back. If that is it I will figure out how to mark your answer as accepted ! Danke ! – UDKOX Jan 27 '16 at 23:21