µTasker Forum
µTasker Forum => NXPTM M522XX, KINETIS and i.MX RT => Topic started by: svl on June 11, 2009, 01:47:12 PM
-
Hi
I have been trying to use the malloc function in the uTasker system, but with no luck.
When I call the malloc function with the size that I want to allocat e.g. malloc(hdr.stp).
Malloc are called but the problem is that the value that I use ac parameter are change from e.g. 2536 to 0x20007F14.
I have tried almost everything also the thing mention in http://www.utasker.com/forum/index.php?topic=96.0 (http://www.utasker.com/forum/index.php?topic=96.0).
Any suggestion?
Regards Steen
-
Hi Steen
Can you show us how the hdr.stp is defined?
0x20007f14 looks like an address on the stack rather than a value - are you somehow passing a pointer rather than the amount of heap that you would like to take?
What happens if you try with malloc(2536)?
Regards
Mark
-
Hi Mark
The hdr are a struct of:
typedef struct tagAMX_HEADER {
int32_t size PACKED; /* size of the "file" */
uint16_t magic PACKED; /* signature */
char file_version; /* file format version */
char amx_version; /* required version of the AMX */
int16_t flags PACKED;
int16_t defsize PACKED; /* size of a definition record */
int32_t cod PACKED; /* initial value of COD - code block */
int32_t dat PACKED; /* initial value of DAT - data block */
int32_t hea PACKED; /* initial value of HEA - start of the heap */
int32_t stp PACKED; /* initial value of STP - stack top */
int32_t cip PACKED; /* initial value of CIP - the instruction pointer */
int32_t publics PACKED; /* offset to the "public functions" table */
int32_t natives PACKED; /* offset to the "native functions" table */
int32_t libraries PACKED; /* offset to the table of libraries */
int32_t pubvars PACKED; /* offset to the "public variables" table */
int32_t tags PACKED; /* offset to the "public tagnames" table */
int32_t nametable PACKED; /* offset to the name table */
int32_t overlays PACKED; /* offset to the overlay table */
} AMX_HEADER;
AMX_HEADER hdr;
memblock = malloc(hdr.stp);
When caling malloc(2536) I get the same result.
I think that it looks like the parameter not are passe allong when calling the malloc function.
But the reason for this do not understand.
The stdlib.h are includet in the config.h and i tried to include in the .c file aswell but with same result.
Regards
Steen
-
Hi Steen
This sounds as though the library doesn't match the application. That is, the application is compiled using register passing - which gives best code density and (probably) speed - but the library was not. If the library is not build using the same setting it will expect the passed parameter on the stack.
You have a choice of libraries, who's names informs about how they are built - make sure that you link one named with ***REGABI**.a
See also the following for details about using libraries:
http://www.utasker.com/docs/Coldfire/ColdFire_Build_Tools_Reference.pdf (page 206 and onwards)
Regards
Mark
-
Hi Mark
Are you the best or what? ;D
The problem was that I was using C_4i_CF_SZ_MSL.a as mention in the http://www.utasker.com/forum/index.php?topic=96.0 (http://www.utasker.com/forum/index.php?topic=96.0).
But when changing the to C_4i_CF_RegABI_SZ_MSL.a as you suggested it almost work.
The malloc was returning 0. But after I recompiled the lib, it worked perfect.
Ones again you saved the day...
Many thanks
Regards Steen
-
Hi Steen
Thanks for the feedback. I have just updated the other thread since register passing was introduced in SP6, so the information is no longer absolutely correct (as you found out).
Regards
Mark