Conditional assembler on register passing setting (CW6.3 on M5223X)

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Conditional assembler on register passing setting (CW6.3 on M5223X)

3,252件の閲覧回数
mjbcswitzerland
Specialist V
Hi All

I have the following desire...

I have a small amount of assembler code which needs to know whether C calls are passing a parameter in D0 or on the stack. D0 is used when the project is configured to use register parameter passing rather than compact or standard.

I have found that C-code can make use of the pre-processor define

#if __REGABI__ == 1  // 0 = not register passing, 1 = register passing
...
#endif

but this is not valid for assembler files and I don't want to inline the assembler code in a C-file (for unreleated reasons).

If it were, the problem could be simply solved by

_assembler_routine:
#if __REGABI__ == 0
    move.l  4(SP),D0
#endif


This would means that assember code were compatible for either project configuration.
But this technique doesn't work so I am on the look out for an alternative which will do the trick.

Any ideas???

Regards

Mark Butcher

www.uTasker.com



Message Edited by mjbcswitzerland on 2007-09-19 11:06 PM
ラベル(1)
タグ(1)
0 件の賞賛
返信
6 返答(返信)

673件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee
Maybe provide functions for both calling conventions at once is also an option?
The calling convention would have to be mangled into the function name, but that could happen transparently for the used in the C header file.

Also I wonder if it really is necessary to provide functions for both calling conventions.
There is a syntax to let the compiler explicitly know about the CC for a particular function, so C header could be just adapted specify the calling convention instead of using default one.
If this is the right thing to do also depends if there are any function pointers, if so, the user would have to be aware about the calling convention too. With just direct function calls, the compiler can take care of that.

Daniel

0 件の賞賛
返信

673件の閲覧回数
CrasyCat
Specialist III
Hello
 
  Actually there is no calling convention configuration when you are coding in assembler.
  Programmer has to define the ABI he wants to use himself.
  So there is no option for ABI settings in macro assembler.
 
  Only thing you can do is define a prefix file, where you add the preprocessing instruction
        #define __REGABI__  0
 
 
CrasyCat
0 件の賞賛
返信

673件の閲覧回数
rocco
Senior Contributor II


CrasyCat wrote:
  Actually there is no calling convention configuration when you are coding in assembler.

Hi Crasy,

I think that is his point, and Mark is trying to tie his own ABI into what the C compiler is producing.

If you are mixing assembly language and C, then there is a calling convention configuration when you are coding in assembly language, and that has to be whatever convention the C compiler is using. As I understand Mark's question, it is "How can you code an assembly-language module so that it can conform to the ABI settings of the C modules, without having to change everything manually?"

I have been wrestling with this issue as well.
0 件の賞賛
返信

673件の閲覧回数
bkatt
Contributor IV


rocco wrote:

"How can you code an assembly-language module so that it can conform to the ABI settings of the C modules, without having to change everything manually?"

I have been wrestling with this issue as well.


While the assember does not define __REGABI__, it does define __MWERKS__. So I am triggering on #ifdef __MWERKS__ and assuming my CodeWarrior is always set to the register ABI.

Normally I use the GNU tools, so my assembly files (all 3 of them!) use the .S (capital) extension, which causes GNU to pass it through the C preprocessor and accept #ifdef. In the GNU build the stack ABI is automatically assembled.

By the way, are these ABIs defined or standardized anywhere? It appears that CodeWarrior uses Coldfire register d2 as scratch like d0 and d1, while GNU saves d2 like d3-d7?

0 件の賞賛
返信

673件の閲覧回数
CrasyCat
Specialist III
Hello
 
Only solution here would be to use inline assembler, which is processed by the compiler.
You should be able to check predefined macro __REGABI__  in inline assembler code.
 
The compiler and the assembler are two distinct binary and one do not know which are the options used by the other....
 
CrasyCat
0 件の賞賛
返信

673件の閲覧回数
Black
Contributor I
I think the only way to do it for the ColdFire build tools is to add the #define in an assembler prefix file that would be used for that target as CrasyCat said.
0 件の賞賛
返信