[SOLVED]Do we will have a general calling convention for pascal? lazarus / 64-FPC development ---------------------------------------------------------------------- TYDQ · 2024-08-11 15:42 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. ---------------------------------------------------------------------- Laksen · 2024-08-11 16:22 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 · 2024-08-11 16:44 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. ---------------------------------------------------------------------- PascalDragon · 2024-08-11 18:19 Quote from: TYDQ on August 11, 2024, 05:42:15 pmHowever,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 · 2024-08-12 02:18 Quote from: PascalDragon on August 11, 2024, 08:19:50 pmQuote from: TYDQ on August 11, 2024, 05:42:15 pmHowever,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 · 2024-08-12 06:59 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. ---------------------------------------------------------------------- TYDQ · 2024-08-12 09:18 Quote from: Thaddy on August 12, 2024, 08:59:32 amWell, 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 · 2024-08-12 09:41 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 · 2024-08-12 09:53 Quote from: TYDQ on August 12, 2024, 11:41:06 amI 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$ ---------------------------------------------------------------------- marcov · 2024-08-12 09:57 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 · 2024-08-12 10:00 Quote from: marcov on August 12, 2024, 11:57:42 amI 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  QuoteA 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 ---------------------------------------------------------------------- TYDQ · 2024-08-12 10:16 Quote from: marcov on August 12, 2024, 11:57:42 amI 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 · 2024-08-12 16:50 See https://wiki.osdev.org/UEFI#POSIX-UEFI,_GNU-EFI_and_GCC on how to handle it. ---------------------------------------------------------------------- TYDQ · 2024-08-13 10:40 Quote from: Thaddy on August 12, 2024, 06:50:56 pmSee https://wiki.osdev.org/UEFI#POSIX-UEFI,_GNU-EFI_and_GCC on how to handle it. That's helpful,thank you for responding. ---------------------------------------------------------------------- PascalDragon · 2024-08-13 19:31 Quote from: TYDQ on August 12, 2024, 04:18:06 amSo 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). ---------------------------------------------------------------------- TYDQ · 2024-08-14 09:47 Quote from: PascalDragon on August 13, 2024, 09:31:33 pmQuote from: TYDQ on August 12, 2024, 04:18:06 amSo 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). Is it vaild use MS_ABI_default in non-windows targets when compiling?That was from our Free Pascal wiki. ---------------------------------------------------------------------- PascalDragon · 2024-08-15 17:56 Quote from: TYDQ on August 14, 2024, 11:47:21 amIs it vaild use MS_ABI_default in non-windows targets when compiling?That was from our Free Pascal wiki. It is valid to use, but it will only have an effect on x86_64-based targets, because the calling convention is only relevant there. ---------------------------------------------------------------------- TYDQ · 2024-08-16 01:20 Quote from: PascalDragon on August 15, 2024, 07:56:52 pmQuote from: TYDQ on August 14, 2024, 11:47:21 amIs it vaild use MS_ABI_default in non-windows targets when compiling?That was from our Free Pascal wiki. It is valid to use, but it will only have an effect on x86_64-based targets, because the calling convention is only relevant there. Thank you.