Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2010-07

arm embedded cortexm3 procedure address

9 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Geoffrey Barton

disassembling from an elf file produce by FPC cross-assembling for arm embedded, an empty procedure:-

procedure UART0int:nostackframe;
begin
end;

looks like this:-

000001a4 <P$UARTTEST_UART0INT>:
1a4: 46f7 mov pc, lr
1a6: 46c0 nop (mov r8, r8)

if I grab the address of this procedure as a constant in assembler (or assign it to a pointer using @; same result):-

asm
.long UART0int
end;

the resulting constant disassembles as:-

1bc: 000001a5 .word 0x000001a5

which seems to be one greater than the address of the procedure. Is this right? If so, why?

also, why does the compiler sometimes add a 'nop' to the end of a procedure (as above)?

Geoffrey

Reply by email

Jonas Maebe
to Geoffrey Barton

Geoffrey Barton wrote on Wed, 14 Jul 2010:

Show quoted text 6 lines
the resulting constant disassembles as:- 1bc: 000001a5 .word 0x000001a5 which seems to be one greater than the address of the procedure. Is this right?

Yes.

If so, why?

To identify the code as Thumb code.

also, why does the compiler sometimes add a 'nop' to the end of a procedure (as above)?

The default alignment of routines is 4 bytes. And it's most likely the assembler or linker that adds the nop, rather than the compiler.

Jonas

---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.

Reply by email

Geoffrey Barton
to Jonas Maebe
Jonas Maebe wrote 14 lines
Geoffrey Barton wrote on Wed, 14 Jul 2010: > the resulting constant disassembles as:- > > 1bc: 000001a5 .word 0x000001a5 > > which seems to be one greater than the address of the procedure. > Is this right? Yes. > If so, why? To identify the code as Thumb code.

I was aware of the requirement to add one to the address of an ISR, but not to other calls.
A normal procedural call seems to assemble as a 'BL' to an even address? I must be missing something:-)

Show quoted text 6 lines
> also, why does the compiler sometimes add a 'nop' to the end of a > procedure (as above)? The default alignment of routines is 4 bytes. And it's most likely the assembler or linker that adds the nop, rather than the compiler.

Yes, right. Probably the linker. Presumably because it is slightly faster.

thanks,
Geoffrey

Show quoted text 10 lines
Jonas ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Jonas Maebe
to Geoffrey Barton

Geoffrey Barton wrote on Thu, 15 Jul 2010:

Show quoted text 7 lines
On 14 Jul 2010, at 17:35, Jonas Maebe wrote: > To identify the code as Thumb code. I was aware of the requirement to add one to the address of an ISR, but not to other calls.

The address of the symbol is set to an odd value so that the linker can identify the subsequent code as Thumb code.

A normal procedural call seems to assemble as a 'BL' to an even address? I must be missing something:-)

BL always goes from ARM to ARM or from Thumb to Thumb code. Therefore, the hardware does not need the extra bit in the address since the instruction encodes what kind of code is at the destination.

Jonas

---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.

Reply by email

Jeppe Johansen
to Michael Schnell

I think it is on Thumb2 devices. To my understanding, they did so on purpose so you no longer have to use interwork intermidiate functions to switch between arm and thumb mode

Michael Schnell wrote 9 lines
On 07/15/2010 11:12 AM, Geoffrey Barton wrote: > A normal procedural call seems to assemble as a 'BL' to an even address? I doubt that it's possible to call thumb code from "ARM" code with a "BL". -Michael _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email