Welcome! Log In Create A New Profile


[Resolved] Position dependent or not?

Posted by arasium 
[Resolved] Position dependent or not?
May 02, 2011 04:42PM

i'm trying to understand how the elf loader at the beginning of the app file (the ES, FFS, IOSP one) works.
Referring to wiibrew and the code, it seems to be position independent.

For example, i've this:

LDR R12, =(sub_8C+1 - 0x448)
ADD R12, R12, PC

And sub_8C = 0x8C

The ADD instruction is at the 0x440 (so the PC is at the 0x448 offset) and R12 is the position independent address of sub_8C.

This is ok for me.

But i've also found this at the begining of the binary:

BL sub_60

This isn't position independent.... How can this works?

Edited 1 time(s). Last edit at 05/02/2011 10:20PM by arasium.
Re: Position dependent or not?
May 02, 2011 10:19PM
I will answer to my question :)

My first exemple then ue BX. The second one use BL.

BX isn't a position relative branch (ie the target is specified by the instruction), whereas BL is. I mean, when BL is called, the target is calculated with the current PC value and the BL argument. It'sjust an offset to the current position:

The offset for branch instructions is calculated by the assembler:
• By taking the difference between the branch instruction and the
target address minus 8 (to allow for the pipeline).
• This gives a 26 bit offset which is right shifted 2 bits (as the
bottom two bits are always zero as instructions are word –
aligned) and stored into the instruction encoding.
• This gives a range of +/- 32 Mbytes.
Re: [Resolved] Position dependent or not?
May 03, 2011 10:12AM
Not sure if you're aware, but the other difference is that BX is used to switch between THUMB and ARM mode based on the LSB of the address in the register (that's why it appears to be jumping to sub_8C+1).
Re: [Resolved] Position dependent or not?
May 03, 2011 10:30AM
Indeed, i was aware of that. But i didn't write anything about that because it wasn't the problem here :)
But thank you for this precision, if someone read this, it can help him.
Sorry, only registered users may post in this forum.

Click here to login