Problems with the value returned from a function - MCF52233

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

Problems with the value returned from a function - MCF52233

ソリューションへジャンプ
936件の閲覧回数
RValls
Contributor III

Hi everyone!

I am having problems with a function that should return a pointer if it find free memory (it is calloc1, in the Interniche Lite Stack). The problem is that when it returns a valid memory, it returns a correct result, but when it should return NULL, then it returns something but NULL. I am having problems also with tcp_pkalloc, having exactly the same behaviour.

I have been looking at the ASM code, and realized that when they return an address, they use A0, but when they return the NULL, both functions put a zero in D0, NOT in A0, but the caller function (in both cases) takes A0 as the register where is the result, resulting in malfunction only when result is NULL.

I have got this functions in a pre-compiled library using Standard Parameter Passing, that is the same I am using in my application.

 

I am using MCF52233 and CodeWarrior for ColdFire V 6.3. 

 

I am absolutely lost on this.  Any help is welcomed.

 

Thanks in advance,

Rubén

Message Edited by RValls on 2009-12-02 12:58 PM
ラベル(1)
0 件の賞賛
1 解決策
333件の閲覧回数
mjbcswitzerland
Specialist V

Hi Rubén

 

Check in your header files (particularly in mwerks.h) for the pragma #pragma pointers_in_A0

If this is set it means that addresses are returned in the register A0. Non-addresses will be returned in D0.

 

You need to ensure that your libraries (like the one with malloc() in is compiled with the same setting otherwise things can go wrong).

 

By removing the pragma all returns are in D0. (but again the library must have been built with the same setting)

 

Regards

 

Mark

 

www.uTasker.com
- OS, TCP/IP stack, USB, device drivers and simulator for M521X, M521XX, M5221X, M5222X, M5223X, M5225X. One package does them all - "Embedding it better..."

 

Message Edited by mjbcswitzerland on 2009-12-03 12:16 AM

元の投稿で解決策を見る

0 件の賞賛
2 返答(返信)
334件の閲覧回数
mjbcswitzerland
Specialist V

Hi Rubén

 

Check in your header files (particularly in mwerks.h) for the pragma #pragma pointers_in_A0

If this is set it means that addresses are returned in the register A0. Non-addresses will be returned in D0.

 

You need to ensure that your libraries (like the one with malloc() in is compiled with the same setting otherwise things can go wrong).

 

By removing the pragma all returns are in D0. (but again the library must have been built with the same setting)

 

Regards

 

Mark

 

www.uTasker.com
- OS, TCP/IP stack, USB, device drivers and simulator for M521X, M521XX, M5221X, M5222X, M5223X, M5225X. One package does them all - "Embedding it better..."

 

Message Edited by mjbcswitzerland on 2009-12-03 12:16 AM
0 件の賞賛
333件の閲覧回数
RValls
Contributor III

Hi Mark! Thanks a lot for your answer, both for the quickly reply and for the solution!

 

I have searched that file, "mwerks.h" but I haven't got it included. then I searched for "pointers_" and I found that the pragma "#pragma pointers_in_D0" was defined in "cw.h".

 

The file where I have this functions (calloc1 is in "memio.c") hasn't got "cw.h" as an #include, so the pragma doesn't affect it.

I suppose (I have not checked it nor found it in the "ColdFire_Build_Tools_Reference") that by default the compiler may use "#pragma pointers_in_A0", so I am having this behaviour. Otherwhise, my project would work fine...

To solve this, I made a new file "options.h" where I defined "#pragma pointers_in_D0", and included it in all files through the "C/C++ Preprocessor" and "ColdFire Assembler" pannels in the library's project options.

I have done the same in the application's project options, and now it works fine.

 

Thanks again for the solution.

Regards, 

 

Rubén

 

 

0 件の賞賛