MICROLIB + Initialised stack

I want to use MICROLIB as (from my initial measurements) it appears to offer space savings of around 1.4KB.

However, I am having problems getting it to work with an initialised STACK. I want to initialise the stacks to known values (e.g. "STAC") for debugging and stack sizing purposes and have modified "startup.s" accordingly. This worked fine without MICROLIB, but using MICROLIB causes a crash. What appears to happen is as follows :-

1) At the start of _main, library code is called to perform initialisation (R/W and ZI).
2) LR (and R4) are pushed on the stack.
3) The stack contents are then initialised to the specified value, overwriting the saved LR (and R4).
4) The LR (and R4) are popped of the stack and the code attempts to branch to the value stored in LR (now "STAC").


I have tried adding an uninitialised ("NOINIT") 8 bytes at the end of the initialised stack, and can configure it so that this area is used for the two register pushes, but these 8 bytes are still being zero-initialised - I don't know why.

The stack declaration looks like this :-

                 GBLA     count
                 AREA     STACK, READWRITE, ALIGN=3
Stack_Mem

count            SETA     0
                 WHILE    count < (Stack_Size / 4)
count            SETA     (count + 1)

                 DCD      STACK_INIT_VAL

                 WEND

                 AREA     STACK, NOINIT, READWRITE, ALIGN=3
                 SPACE    8

__initial_sp
Stack_Top        EQU      (Stack_Mem + Stack_Size + 8)

Any ideas how I can either actually prevent the initialisation of a "NOINIT" section, or get around this in another way ?

Also, is there any easier way to initialise a block of data than the above, which seems overly complex compared to other assemblers I have used. I would expect some sort of declaration that allowed me to specify the size, number of items and initial value. I'm sure I'm missing something obvious but can't find it in the online help.

Thanks,

David.

Parents
  • Declaring an area in the assembler as NOINIT is the first step but it must be put also in a linker region which is not initialized (otherwise the linker region settings will override area settings).

    This can be achieved quickly by redefining the memory layout under the Option for Target - Target. Split the defined RAM and define a separate region with NoInit flag. Then assign your stack to this region (you can simply assign the ZI data of the complete startup file to this region - right mouse click on startup file in the Project Workspace).

    The whole process is a little bit complex but your request is also not ordinary and you must keep in mind that stack is already used by _main which also does among others the RW & ZI initialization.

Reply
  • Declaring an area in the assembler as NOINIT is the first step but it must be put also in a linker region which is not initialized (otherwise the linker region settings will override area settings).

    This can be achieved quickly by redefining the memory layout under the Option for Target - Target. Split the defined RAM and define a separate region with NoInit flag. Then assign your stack to this region (you can simply assign the ZI data of the complete startup file to this region - right mouse click on startup file in the Project Workspace).

    The whole process is a little bit complex but your request is also not ordinary and you must keep in mind that stack is already used by _main which also does among others the RW & ZI initialization.

Children
More questions in this forum