Search code examples
armembeddedstm32gnucortex-m

why Entry point address is 0x800107d,but first instruction start 0x800107c


using arm-none-eabi-readelf -h ideself.elf could find:

Entry point address:               0x800107d

using arm-none-eabi-objdump -D ideself.elf could find:

0800107c <Reset_Handler>:                       
 800107c:   f8df d034   ldr.w   sp, [pc, #52]   ; 80010b4 <LoopForever+0x2>
 8001080:......................................................

why the start reset_handler is not equal 0x800107d instead of 0x800107c

the byte in the 0x800107c don't execute? execute 3/4 four bytes instructions ?


Solution

  • ARM processors have two different instruction sets, Thumb and ARM. The Thumb instruction set has 16 bits per instruction, and the ARM instruction set has 32 bits per instruction. Instructions are aligned in memory.

    The value of the instruction pointer is therefore even, meaning that bit 0 of the instruction's address is 0. This makes the bit "free to use" for other purposes.

    So, the processor decides on bit 0 of the target address whether they continue in Thumb mode or in ARM mode. A bit 0 = 1 switches the processor into Thumb mode, resulting in an odd target address. However, the actual instruction's address is still even and by one less.