Memory layout

The current memory layout used by cpik is the following4:
Name Addresses Size Usage
Soft Stack [GG+1->TT] device dependent software stack, grows upward to top of memory
Globals [PP+1->GG] program dependent global variables
Scratch [22->PP] SCRATCH_SIZE-20 returned value area
FP aux [14-21] 8 auxiliary zone for FP routines
Registers [2->13] 12 R0,R1,R2,R3,R4,R5 pseudo-registers
C18_errno [1->1] 1 reserved by libraries
IT mask [0->0] 1 reserved by RTL

Addresses from 0 to 21 (22 bytes) are reserved for the run-time library. The Register zone (20 bytes) is used for both integer and floating point calculation, and is also used to store the values returned by functions. Because a function can return more then 20 bytes, the Register zone can be extended by the Scratch zone. The size of this area can be ajusted by editing the prolog file /usr/share/cpik/<version>/lib/cpik.prolog
The default size specified in this file is sufficient to handle functions returning 40 byte long structures. If you are not happy with this size, just change the SCRATCH_SIZE definition to the value you want. However, remember than SCRATCH_SIZE cannot be less than 20 bytes.

The Globals zone is used to store the static data (ie: global or static variables).

Finally, the Soft stack begins at the end of the Globals zone and uses the remaining of the memory.

There is currently no reserved zone to implement a heap for dynamic memory allocation (malloc(), free()). However such a zone could be obviously implemented at the end of physical memory, and must expand from top (high addresses) to bottom.

AG 2013-04-10