1
votes

I have small application that compiles and runs well on my ARM Cortex M4. But when I disassemble binary file, that I flush, here is how first bytes look like:

00000000 <.data>:
  0:   20020000        andcs   r0, r2, r0
  4:   080003b5        stmdaeq r0, {r0, r2, r4, r5, r7, r8, r9}
  8:   08000345        stmdaeq r0, {r0, r2, r6, r8, r9}
  c:   08000351        stmdaeq r0, {r0, r4, r6, r8, r9}

080003b5 should be the address of Reset handler (I have .word Reset_Handler there), but disassembling ELF shows that Reset handler is actually located at 080003b4, which is 1 byte before:

080003b4 <Reset_Handler>:
  80003b4:  2100        movs    r1, #0
  80003b6:  e003        b.n 80003c0 <InitData>

(It's running in THUMB mode, I have 2byte instructions).

Even if I disassemble the binary file, it's located at 080003b4:

000003b4 <.data+0x3b4>:
  3b4:   2100            movs    r1, #0
  3b6:   e003            b.n     0x3c0

My question is, why does it point 1 byte after? This code surprisingly works on actual board. Even without disassembling, shouldn't instructions be aligned by 2 byte? how can address be 0x000003b5?

1
I believe the ARM requires aligned addresses for instructions, so 080003b5 is not correct for sure. But the least significant bit is probably used for thumb/full32 mode marking (your address then maybe means reset handler is "thumb" code at 080003b4), can't recall how it was from head, and I'm not going to check CPU docs, so take is as a vague hint, which may be completely wrong.Ped7g
It's been asked here many times in various forms, feel free to search for the most appropriate duplicate (I don't have time right now). In short, read up on how Thumb symbols/code addresses work with regard to interworking.Notlikethat
When you use jump instruction, B, it needs to know if it's jumping to Thumb or ARM instruction, the odd address is to let it know it's Thumb. The LSBit is ignored anyway when it gets the jump address.hesham_EE

1 Answers

2
votes

Answer: ARM uses it for switching to THUMB mode.