Sign in Join

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

Mailing lists / fpc-pascal / 2019-03

Registers used by calling conventions

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Anthony Walter

What registers are used by default calling convention and where can I find more information about Free Pascal asm details?

When writing code using the asm block on Delphi in Windows, the default calling convention (fastcall) would pass arguments in registers EAX, EDX, ECX then the stack in that order.

Checking registers in Lazarus on 64 bit Linux, I see the default calling convention is using RSI and RDI, the source and destination index registers.

Also is it possible to get the Lazarus assembler to show instructions in Intel mode rather than AT&T?

Jonas Maebe
to Anthony Walter
Anthony Walter wrote
Checking registers in Lazarus on 64 bit Linux, I see the default calling convention is using RSI and RDI, the source and destination index registers.

For any platform except for i386, FPC uses the official ABI.

The Win64 calling convention is documented by Microsoft: https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=vs-2017

Other x86-64 platforms use the standard calling convention for that platform: https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI

Jonas

silvioprog
to Anthony Walter: What registers are used by default calling convention and where can I find more…
PM Anthony Walter wrote
What registers are used by default calling convention and where can I find more information about Free Pascal asm details?

For linux64 the default C.C is sysv x64. Some links with info you are looking for:

1. https://bugs.freepascal.org/view.php?id=34743 (a low-level Delphi-like invoke() almost done for Linux x86_64)
2. https://www3.nd.edu/~dthain/courses/cse40243/fall2017/intel-intro.html (Introduction to X86-64 Assembly for Compiler Writers)
3. https://www.uclibc.org/docs/psABI-x86_64.pdf (System V ABI [AMD64])
4. https://wiki.osdev.org/System_V_ABI (some related links)

[....]

Also is it possible to get the Lazarus assembler to show instructions in Intel mode rather than AT&T?

Yes, just change the $asmmode to the syntax you want, e.g {$asmmode intel}.

Silvio Clécio
Anthony Walter
to silvioprog

Jonas, thanks I found that information useful. The pdf on page 22 says "If the class is INTEGER, the next available register of the sequence %rdi, %rsi, %rdx, %rcx, %r8 and %r9 is used"

Silvio, maybe I was unclear in my second question. The {$asmmode intel} compiler directive changes the asm syntax of what's allowed in your unit, but it does not change how dissasembled code is displayed in the Lazarus dissasembler view. I'd like to see instructions dissambled in the Lazarus helper window using the Intel style. I wasn't referring to the asm code in the source code editor.

Christo Crause
to Anthony Walter
AM Anthony Walter wrote 6 lines
... The {$asmmode intel} compiler directive changes the asm syntax of what's allowed in your unit, but it does not change how dissasembled code is displayed in the Lazarus dissasembler view. I'd like to see instructions dissambled in the Lazarus helper window using the Intel style. I wasn't referring to the asm code in the source code editor.

The disassembly is prepared by the debugger. For GDB you can set the disassemble flavour by "set disassemble-flavor intel". In Lazarus: Tools - Options, go to Debugger - General then look for property AssemblerStyle and change to gdasIntel.

Sven Barth
to Anthony Walter: What registers are used by default calling convention and where can I find more…

Anthony Walter schrieb am Fr., 8. März 2019, 22:34:

Show quoted text 13 lines
What registers are used by default calling convention and where can I find more information about Free Pascal asm details? When writing code using the asm block on Delphi in Windows, the default calling convention (fastcall) would pass arguments in registers EAX, EDX, ECX then the stack in that order. Checking registers in Lazarus on 64 bit Linux, I see the default calling convention is using RSI and RDI, the source and destination index registers. Also is it possible to get the Lazarus assembler to show instructions in Intel mode rather than AT&T?

For the "register" calling convention on i386 (aka the default calling convention there) you can also look at
packages/rtl-objpas/src/i386/invoke.inc which contains the function call manager for i386 (and the x86_64 contains the one for that platform though currently only the Win64 one is supported).

Regards,
Sven