Problems with the value returned from a function - MCF52233

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Problems with the value returned from a function - MCF52233

跳至解决方案
1,503 次查看
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 解答
900 次查看
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 回复数
901 次查看
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 项奖励
回复
900 次查看
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 项奖励
回复