decoding an ARM instruction ixus160 - General Discussion and Assistance - CHDK Forum

decoding an ARM instruction ixus160

  • 2 Replies
  • 3453 Views
*

Offline axman

  • ***
  • 145
decoding an ARM instruction ixus160
« on: 30 / May / 2017, 20:07:22 »
Advertisements
Decoding my way through filewrite.c for ixus160, looking at what code_gen.txt is doing.  Dumped the start of filewrite the way code_gen does;

Code: [Select]
tools/capdis -v -s='0xffab8cf0' -c=42 -stubs=platform/ixus160_elph160/sub/100a/ -d ../ixus160/PRIMARY.BIN 0xff810000
then I go thru ARM instructions and operands.  Match up ARM instructions to the reference manual.  I think I have the PUSH decoded correctly.  The next instruction is

    ldr     r5, =0x0000b584 ; [pc, #448] (0xffab8ebc)

I think, from instruction syntax, that it is ldr type 3

    ldr3 = 32b mem useful for ProgramCounter PC relative data

Paraphrased from the arm v5 ref manual;
Code: [Select]
# LDR <Rd>, [PC, #<immed_8> * 4]
# Rd is dest register,
# pc is program counter, used to calc mem addr;
#    Bit 1 of pc val forced to 0 for this calc,
#     such that addr (results?) is word-aligned.
# immed_8 is 8bit val * 4 and added to PC to form mem addr

It must be related, due to      Rd = (0xffab8ebc) ...  I suspect this, because loc_ffab8eac !!!   It's the address written to 7 (jpg) chunk times <from hdr file>.  Also suspect this because ldr3 is the only ldr instruction in the ref mentioning PC.
     
So, what's r5, =blah ?   Destination register's position.. we know 0xffab8ebc is dest register's address.  The instruction is represented by mix of arm and C syntax;

'#' is GNU arm assm     *immediate operand prefix
';' is GNU arm assm     *Statement Separator  math rules apply?  (left hand eval before right)
',' is C      *expression to discard previous value
'=' is C      *initialization -> assignment expression
'[' is C      *punctuators
']' is C      *punctuators
'('    C      *not sure what form..
')'    C      *

* are used in the instruction, so it must be.

So,

Before performing [PC, #<immed_8> * 4], we eval r5, =0x0000b584

Meaning, discard what's in r5 and assign 0x0000b584 to it.

Then, discard what's in PC (by comma), and uhh,

0x0000b584 * 4 = 2D610, PC becomes this ?

*

Offline reyalp

  • ******
  • 14126
Re: decoding an ARM instruction ixus160
« Reply #1 on: 30 / May / 2017, 23:00:50 »
    ldr     r5, =0x0000b584 ; [pc, #448] (0xffab8ebc)

So, what's r5, =blah ?   Destination register's position.. we know 0xffab8ebc is dest register's address.  The instruction is represented by mix of arm and C syntax;
Everything after the ; is a comment, describing how the preceding instruction actually gets 0x0000b584 into r5.

When you do
ldr rx, =blah

You are actually telling the assembler to generate PC relative load (as described in the documentation you quoted), and store to the 0x... constant somewhere nearby.

So the [pc, #448] means the assembler decided to put the constant at the current address +448 (subject to some details), and the (0xffab8ebc) is the resulting physical address of PC+448. So if you looked at address 0xffab8ebc (e.g. using rmem in chdkptp), you should see the constant 0x0000b584 there.

The "nearby" part is why our inline assembly is littered with .ltorg directives, because you need to tell the assembler where it can put these things.
Don't forget what the H stands for.

*

Offline axman

  • ***
  • 145
Re: decoding an ARM instruction ixus160
« Reply #2 on: 31 / May / 2017, 12:02:16 »
Knowing that the ';' marks the start of comments in the assembler code is very, very helpful.  Thanks for the explanation, and the rmem suggestion! 

 

Related Topics


SimplePortal © 2008-2014, SimplePortal