Registers used by calling conventions

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Registers used by calling conventions

Anthony Walter-3
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?

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Registers used by calling conventions

Jonas Maebe-3
On 08/03/2019 22:33, 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Registers used by calling conventions

silvioprog
In reply to this post by Anthony Walter-3
On Fri, Mar 8, 2019 at 6:34 PM Anthony Walter <[hidden email]> 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)
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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Registers used by calling conventions

Anthony Walter-3
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.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Registers used by calling conventions

Christo Crause
On Sat, Mar 9, 2019 at 12:13 AM Anthony Walter <[hidden email]> wrote:
... 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.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Registers used by calling conventions

Anthony Walter-3
Christo, that did it. Thanks.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Registers used by calling conventions

Free Pascal - General mailing list
In reply to this post by Anthony Walter-3
Anthony Walter <[hidden email]> schrieb am Fr., 8. März 2019, 22:34:
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 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal