Recent

Author Topic: [SOLVED]Do we will have a general calling convention for pascal?  (Read 2308 times)

TYDQ

  • Full Member
  • ***
  • Posts: 102
These times I am trying to booting my kernel with my UEFI boot loader.
However,I was upset about free pascal don't have cross-platform(not cross-processor,due to processors have different assembly calling convention) calling conventions.I was testing MWPascal,MS_abi_default,MS_abi_cdecl and read the compiled assembly code.As a result,I don't get the same calling convention which can be processor-specific and operating system independent.If there are general calling convention for pascal which is system-independent,It will be more convenient for pascal programmer to not to consider what the system abi will effect the program.
« Last Edit: August 19, 2024, 12:33:33 pm by TYDQ »

Laksen

  • Hero Member
  • *****
  • Posts: 776
    • J-Software
Re: Do we will have a general calling convention for pascal?
« Reply #1 on: August 11, 2024, 06:22:48 pm »
No. Because making more calling conventions is just going to create more problems

This was a thing popular in the past, but luckily long done. Even if some of the new calling convention standards are pretty terrible (looking at you riscv...)

Thaddy

  • Hero Member
  • *****
  • Posts: 15687
  • Censorship about opinions does not belong here.
Re: Do we will have a general calling convention for pascal?
« Reply #2 on: August 11, 2024, 06:44:12 pm »
There is a work-around and, wait for it, it is cross-platform despite its name:
Use winapi as calling convention.
You can examine the compiler code on how this is achieved.
Using winapi as calling convention solves 90% of the problems.
And is cross-platform.
If I smell bad code it usually is bad code and that includes my own code.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5678
  • Compiler Developer
Re: Do we will have a general calling convention for pascal?
« Reply #3 on: August 11, 2024, 08:19:50 pm »
However,I was upset about free pascal don't have cross-platform(not cross-processor,due to processors have different assembly calling convention) calling conventions.I was testing MWPascal,MS_abi_default,MS_abi_cdecl and read the compiled assembly code.As a result,I don't get the same calling convention which can be processor-specific and operating system independent.If there are general calling convention for pascal which is system-independent,It will be more convenient for pascal programmer to not to consider what the system abi will effect the program.

Calling conventions are only really relevant on x86 (both i8086 and i386 and to a lesser extend x86_64). On all other architectures(*) there is only a single calling convention. If you don't need to interact with third party systems on i386 or i8086then simply stay with the default register calling convention, otherwise use the corresponding third party calling convention. For x86_64 the default depends on whether the system in question uses the Win64 calling convention (Windows itself and UEFI) or the Sys-V one (all Unix-like systems). And the differences here in assembly code can easily be accounted for with some compiler defines as does FPC's RTL.

(*) m68k also has a custom calling convention for FPC as that makes use of more registers than the default calling convention

TYDQ

  • Full Member
  • ***
  • Posts: 102
Re: Do we will have a general calling convention for pascal?
« Reply #4 on: August 12, 2024, 04:18:06 am »
However,I was upset about free pascal don't have cross-platform(not cross-processor,due to processors have different assembly calling convention) calling conventions.I was testing MWPascal,MS_abi_default,MS_abi_cdecl and read the compiled assembly code.As a result,I don't get the same calling convention which can be processor-specific and operating system independent.If there are general calling convention for pascal which is system-independent,It will be more convenient for pascal programmer to not to consider what the system abi will effect the program.

Calling conventions are only really relevant on x86 (both i8086 and i386 and to a lesser extend x86_64). On all other architectures(*) there is only a single calling convention. If you don't need to interact with third party systems on i386 or i8086then simply stay with the default register calling convention, otherwise use the corresponding third party calling convention. For x86_64 the default depends on whether the system in question uses the Win64 calling convention (Windows itself and UEFI) or the Sys-V one (all Unix-like systems). And the differences here in assembly code can easily be accounted for with some compiler defines as does FPC's RTL.

(*) m68k also has a custom calling convention for FPC as that makes use of more registers than the default calling convention
So does calling convention winapi in x86_64 will be ignored if I try to force the code to winapi calling convention in x86_64?

Thaddy

  • Hero Member
  • *****
  • Posts: 15687
  • Censorship about opinions does not belong here.
Re: Do we will have a general calling convention for pascal?
« Reply #5 on: August 12, 2024, 08:59:32 am »
Well, winapi works like a selector: it chooses stdcall for win32 and all other will be according to the specific calling convention for the ABI. e.g. win64 has no such thing as stdcall.
If I smell bad code it usually is bad code and that includes my own code.

TYDQ

  • Full Member
  • ***
  • Posts: 102
Re: Do we will have a general calling convention for pascal?
« Reply #6 on: August 12, 2024, 11:18:56 am »
Well, winapi works like a selector: it chooses stdcall for win32 and all other will be according to the specific calling convention for the ABI. e.g. win64 has no such thing as stdcall.
Yes,winapi will be ignored when I trying the compile the code in x86_64 linux fpc.

TYDQ

  • Full Member
  • ***
  • Posts: 102
Re: Do we will have a general calling convention for pascal?
« Reply #7 on: August 12, 2024, 11:41:06 am »
I suggesting that our FPC team should make the MS_ABI_Default in all x86_64 based systems vaild as passing parameter like MS_ABI_default due to I discovered that fpc won't compile with winapi in linux elf according to the assembly code.

TRon

  • Hero Member
  • *****
  • Posts: 3263
Re: Do we will have a general calling convention for pascal?
« Reply #8 on: August 12, 2024, 11:53:43 am »
I suggesting that our FPC team should make the MS_ABI_Default in all x86_64 based systems vaild as passing parameter like MS_ABI_default due to I discovered that fpc won't compile with winapi in linux elf according to the assembly code.
H*ll no !  :)

As strange as it might perhaps sound to you but there actually is real life besides M$
This tagline is powered by AI

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11771
  • FPC developer.
Re: Do we will have a general calling convention for pascal?
« Reply #9 on: August 12, 2024, 11:57:42 am »
I think he means to say his UEFI uses ELF but microsoft calling conventions.

A proper solution would be to define a new target for that, and list the defaults ABI and binary format to match, rather than generalize multiple calling conventions on all targets.

TRon

  • Hero Member
  • *****
  • Posts: 3263
Re: Do we will have a general calling convention for pascal?
« Reply #10 on: August 12, 2024, 12:00:10 pm »
I think he means to say his UEFI uses ELF but microsoft calling conventions.
I suspected as such. I just found the proposal a bit intrusive  :)

Quote
A proper solution would be to define a new target for that, and list the defaults ABI and binary format to match, rather than generalize multiple calling conventions on all targets.
+1
This tagline is powered by AI

TYDQ

  • Full Member
  • ***
  • Posts: 102
Re: Do we will have a general calling convention for pascal?
« Reply #11 on: August 12, 2024, 12:16:18 pm »
I think he means to say his UEFI uses ELF but microsoft calling conventions.

A proper solution would be to define a new target for that, and list the defaults ABI and binary format to match, rather than generalize multiple calling conventions on all targets.
That is a really good idea,I will take it into consideration.

Thaddy

  • Hero Member
  • *****
  • Posts: 15687
  • Censorship about opinions does not belong here.
Re: Do we will have a general calling convention for pascal?
« Reply #12 on: August 12, 2024, 06:50:56 pm »
If I smell bad code it usually is bad code and that includes my own code.

TYDQ

  • Full Member
  • ***
  • Posts: 102
Re: Do we will have a general calling convention for pascal?
« Reply #13 on: August 13, 2024, 12:40:12 pm »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5678
  • Compiler Developer
Re: Do we will have a general calling convention for pascal?
« Reply #14 on: August 13, 2024, 09:31:33 pm »
So does calling convention winapi in x86_64 will be ignored if I try to force the code to winapi calling convention in x86_64?

The winapi calling convention will select stdcall on all Windows-like targets and cdecl on all other targets. On most targets stdcall and cdecl are the same and simply mean the default operating system calling convention (and more often than not the only supported calling convention).

 

TinyPortal © 2005-2018