S12X: Possible to put large heap in __GPAGE_SEG RAM?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S12X: Possible to put large heap in __GPAGE_SEG RAM?

Jump to solution
3,295 Views
dp
Contributor III
CodeWarrior HCS12X 4.5
S12XDP512
Banked memory model
Minimal start-up

Is it possible to put the heap in a __GPAGE_SEG at 0xF8000'G? I need a heap size of 28000. I came close to making it work by altering heap.c, the prm, and libdefs.h but malloc() choked when it ran in simulation (HeaderPtr p = 0x5A5A5A on the first iteration).

Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
1,462 Views
CrasyCat
Specialist III
Hello
 
I assume you are building in banked memory model. I did some quick smoke test locally.
If you want to use far Heap you need to do the following:
   1- edit the file {Install}\lib\hc12c\include\libdefs.h
   2-Go to line 180 and change
         #define LIBDEF_FAR_HEAP_DATA  0
       into
          #define LIBDEF_FAR_HEAP_DATA  1
   3- On line 193, adjust LIBDEF_HEAPSIZE to the desired size.
   4- If you intend to use dynamically allocated data into other ANSI C functions you need to adjust also
       macros  LIBDEF_FAR_CONST_STRINGS, LIBDEF_FAR_STRINGS,
        LIBDEF_FAR_CONST_VOID_PTR, LIBDEF_FAR_VOID_PTR.
   5- There is an issue in the delivered alloc.c source file.
        Edit the file alloc.c and change it as follows:
        Change line 84 from:
              free_ptr        = (header *) &_heap_[0];  
        to
                  free_ptr        = (header *LIBDEF_HEAP_DPTRQ) &_heap_[0];  
   6- Rebuild the libraries
   7- In your .prm file define a global memory area to store your heap. If you need 28000 bytes of heap,
       then the paged RAM area should be defined as
           GLOBAL_RAM    = NO_INIT     0xF8000'G TO 0xFEFFF'G;
      and the RAM memory area should be redefined as
           RAM           = READ_WRITE    0x3000 TO   0x3FFF;
     I would define the big paged memory area as NO_INIT so it will not be initialized at Startup.   
     RAM memory area needs to be adjusted because address 0xFE000'G is the same as 0x2000'L.  
     So I defined a smaller RAM area to avoid overlap.
   8- place HEAP_SEGMENT in GLOBAL_RAM in your .prm file
 
   That should be it.
 
  I will report the issue with the wrong code in alloc.c to engineering for a fix in a future release of the
  library.
  
 
CrasyCat

View solution in original post

0 Kudos
Reply
3 Replies
1,462 Views
dp
Contributor III
free_ptr = (header *LIBDEF_HEAP_DPTRQ) &_heap_[0];

That was the problem. I had gotten everything else. Thank you.
0 Kudos
Reply
1,462 Views
CrasyCat
Specialist III
Hello
 
Already get confirmation from engineering that we will get that fixed in the next release of the tools.
 By the way if you are using function free or realloc, you will also be facing some issues.
 
There are also some casts there where you would need to add LIBDEF_HEAP_DPTRQ qualifier.
 
CrasyCat
0 Kudos
Reply
1,463 Views
CrasyCat
Specialist III
Hello
 
I assume you are building in banked memory model. I did some quick smoke test locally.
If you want to use far Heap you need to do the following:
   1- edit the file {Install}\lib\hc12c\include\libdefs.h
   2-Go to line 180 and change
         #define LIBDEF_FAR_HEAP_DATA  0
       into
          #define LIBDEF_FAR_HEAP_DATA  1
   3- On line 193, adjust LIBDEF_HEAPSIZE to the desired size.
   4- If you intend to use dynamically allocated data into other ANSI C functions you need to adjust also
       macros  LIBDEF_FAR_CONST_STRINGS, LIBDEF_FAR_STRINGS,
        LIBDEF_FAR_CONST_VOID_PTR, LIBDEF_FAR_VOID_PTR.
   5- There is an issue in the delivered alloc.c source file.
        Edit the file alloc.c and change it as follows:
        Change line 84 from:
              free_ptr        = (header *) &_heap_[0];  
        to
                  free_ptr        = (header *LIBDEF_HEAP_DPTRQ) &_heap_[0];  
   6- Rebuild the libraries
   7- In your .prm file define a global memory area to store your heap. If you need 28000 bytes of heap,
       then the paged RAM area should be defined as
           GLOBAL_RAM    = NO_INIT     0xF8000'G TO 0xFEFFF'G;
      and the RAM memory area should be redefined as
           RAM           = READ_WRITE    0x3000 TO   0x3FFF;
     I would define the big paged memory area as NO_INIT so it will not be initialized at Startup.   
     RAM memory area needs to be adjusted because address 0xFE000'G is the same as 0x2000'L.  
     So I defined a smaller RAM area to avoid overlap.
   8- place HEAP_SEGMENT in GLOBAL_RAM in your .prm file
 
   That should be it.
 
  I will report the issue with the wrong code in alloc.c to engineering for a fix in a future release of the
  library.
  
 
CrasyCat
0 Kudos
Reply