cancel
Showing results for 
Search instead for 
Did you mean: 

overlap local variables with stack area

seecure
Associate II
Posted on April 17, 2004 at 18:08

overlap local variables with stack area

12 REPLIES 12
seecure
Associate II
Posted on April 09, 2004 at 13:48

ST72F521,cosmic, compile in '+modsl'

In some subroutines,the cosmic compiler allocate the local variables

at stack area. for ex:

void UTL_copy_integer_F(UINT8 *dest,UINT8 *src,UINT8 len)

{

char i;

int txdata;

int *tx_buff=(UINT16 *)&dest;

...............................

...............................

}

compiler allocation:

i - 0x1e5

txdata - 0x1e3

tx_buff - 0x1e1

SP register - 0x1e0 (stack range - 0x100-0x1FF)

How can I avoid this overlap?

see the 'lkf' attached file.

thanks,

atz

________________

Attachments :

project.lkf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I00K&d=%2Fa%2F0X0000000bVR%2FGrSpOO_ZSQoTNucAaJC6iOwFYtfgZ_VdTGpttMpXiY8&asPdf=false
jatin
Associate II
Posted on April 12, 2004 at 10:52

It is because you are using the stack model (+modsl) which uses the physical stack. So either you can use memory model which uses the simulated stack or use @nostack option in order to forcibly use simulated stack by the compiler. For more details please refer cosmic compiler manual (Memory Models Section).

seecure
Associate II
Posted on April 13, 2004 at 07:37

hi jatin,

I've changed to +modml, and it still reset the stack pointer by

'rsp' (in crtsx.s) put the SP at 0x1ff. (phycical address).

How can I allocate the SP in any address I'd like to for ex. SP=0x87f ?

thanks,

atz
luca239955_st
Associate III
Posted on April 13, 2004 at 14:13

Hi Datz,

why would you want to set the stack pointer to an absolute address?

If you have a valid reason, I think (haven't tried) it's enough to write SP=value, but note that this will almost surely mess up the execution.

Also note that, with your chip, the stack must be in page 1, that is address 0x87F won't work.

If you explain better what you're trying to achieve maybe I can help.

Regards,

Luca

seecure
Associate II
Posted on April 13, 2004 at 14:30

hi loca

as I explain above there are overlap of local variables in some subroutins with stack area. when the software run in these subroutines the system crach and reset is being occured. I'd like to

prevent this overlap. I'd like it will transparent to me as a cosmic user compiler and not take care evry time I'll add a subrotine with parametres and loacls.

atz
luca239955_st
Associate III
Posted on April 14, 2004 at 06:03

Datz,

as Jatin explained, it's normal that in stack mode (mods, modsl) all the local variables (including function parameters) are in the stack. This is done to allow reentrancy.

The code and stack values you show in the original post look correct to me, so the problem is probably somewhere else.

Can you specify which instruction exactly causes the ''crash'', what you mean by it (execution out of code, chip reset, the debugger hangs...) and how you go about to debug (which hw, which debugger, step by step or bkpt...)?

If you can reproduce the problem is simulation you can post the whole code here and I'll take a look.

Regards,

Luca (Cosmic)

seecure
Associate II
Posted on April 15, 2004 at 12:34

hi luca

My project is about 40K I cant deliver it. anyway I don't think there is a software problem. I think there is a problem in the the cosmic link phase.

if the ram location(0100-0x1ff for ST72F521) is deticted to stack area, the link phase must avoid addressing locals,parameters,globals in that dynamic stack area.

In any compiler you can allocate the stack pointer at the linker by switche declareion.

I see at lkf this command:

# define the __stack symbol for stack models only

#

+def __stack=0x100 # stack page ( stack models)

but there is no Influence because in map file I see:

__stack 00000100 defined in command file

*** not used ***

and it does not change of any +def=0xnnn

what the ' *** not used ***' means, while in run time the stack is very

active and SP start address is 0x1ff.

atz

sjo
Associate II
Posted on April 15, 2004 at 19:43

The __stack declaration in the linker file is not used anymore by the cosmic compiler.

The stack pointer will be set to 0x1FF by the device reset, or via 'rsp' instruction.

The stack pointer can be changed but why would you want to unless you are writing a multitasking os, for example.

I think more information is required to help you further:

Regards

sjo
seecure
Associate II
Posted on April 15, 2004 at 21:24

Hi forum,

please see the attached file. it is a snapshote of run into the routine.

note to the SP value, the locals and parameters addressing are in

same area location. the return PC of the called subroutines whish

stored in stack are crached. the PC run out of program and the watch dog reset the system.

I've only changed the length buffer from 2 to 6, and system which runs

for weeks, sudanly crach. it is a critical bug!

atz

________________

Attachments :

overlap.doc : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0Aj&d=%2Fa%2F0X0000000bVP%2FcoAYqFrmNGBZ3SXUJ36W0VufPDkBTgk8ZE5yk569xGs&asPdf=false