English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. Language (https://eab.abime.net/forumdisplay.php?f=114)
-   -   Calling convention for gcc (m68k-amigaos) (https://eab.abime.net/showthread.php?t=100380)

sparhawk 11 January 2020 18:05

Calling convention for gcc (m68k-amigaos)
 
When I call an assembler function, d0/d1 and a0/a1 don't need to be saved?


The first four params are passed in d0/d1 and a0/a1, or does this depend on wether it's a pointer or value?


Is there some compiler hint to tell the compiler which registers a param might be expected in?

Samurai_Crow 11 January 2020 18:13

Quote:

Originally Posted by sparhawk (Post 1370955)
When I call an assembler function, d0/d1 and a0/a1 don't need to be saved?


The first four params are passed in d0/d1 and a0/a1, or does this depend on wether it's a pointer or value?


Is there some compiler hint to tell the compiler which registers a param might be expected in?

D0/D1/A0/A1 are scratch registers so yes. All other registers need to be preserved.

Whether it's a pointer or not matters.

Yes, GCC has register directives for passing parameters in to subroutines and especially inline Assembly.

jotd 11 January 2020 18:13

With gcc, the params are passed on stack if you don't specify anything (that's empiric, it worked for a quick test I did).

Bebbo gcc 6 supports SDI_compiler include. You can specify "passing by register" and which register. Return value is always taken from D0 (here the return type is void so it doesn't matter)

Code:

#ifndef SDI_COMPILER_H
#include <SDI_compiler.h>
#endif


  void ASM mt_install_cia(REG(a6, void *custom),
                          REG(a0, void *VectorBase), REG(d0, UBYTE PALflag));

I suggest that you preserve ALL registers when calling asm. Compiler may use some.

sparhawk 11 January 2020 18:36

Thanks! When I use that REG() notation, do I still need to preserve the register, or does the compiler know in this case that it can get scratched?
It's still faster if I don't have to translate the registers, so it still makes sense to use this anyway.
Which include is this defined in? I'm using the 1.3 includes, is this also supported there because I can't find any traces of this (also not in the OS 2.x+ includes).


All times are GMT +2. The time now is 00:39.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.04818 seconds with 11 queries