DSPRelated.com
Forums

stack and #pragma FUNC_NEVER_RETURNS

Started by Bernhard 'Gustl' Bauer November 12, 2004

Hi,

im running a 6713 and have CCS 2.2

First I start a boot loader. This searches for a key in ext ROM and
jumps at the code (boot_code) after the key.

boot_code inits EMIF and copies code from ext ROM to int RAM. Then it
jumps to to sdram_init.

sdram_init is now in int RAM. It copies code from ext ROM to ext RAM.
Then it calls c_int00. Which is the start of the program I really want
to run. c_int00 is now located in ext. RAM.

My problem is that the boot loader and the program I really want to run
have different stacks. So when boot_code and sdram_init are running they
store their return pointers onto the old stack. This destroys part of
the code.

I tried to force them not to use a return pointer by using the pragma
FUNC_NEVER_RETURNS. But this doesn't work. Any Idea why?

The other possibility is to set the stack to the new value in boot_code.
But I don't know how to do this in C.

TIA

Gustl




Hello Gustl,
 
I have read your email a couple of times, but i am not sure that i understand your problem.
 
To simplify, I will call everything before the execution of _cint00 of your application 'initialization' and everything after 'application'.
 
When initialization is running, it uses its own stack. At the end of initialization [when you 'goto' _cint00] you should be able to reuse any of the internal memory used by initialization.  i assume that everything is working well at this point.  if you are experiencing problems 'stepping on code' at this point, I would think that either your heap or stack is too small.  Since you can reuse this memory, be generous with the stack and heap.
 
The application should define and use its own stack and should not care or know anything about the original stack.  This is why i am confused about your problem...
 
mikedunn

Bernhard 'Gustl' Bauer <g...@quantec.de> wrote:


Hi,

im running a 6713 and have CCS 2.2

First I start a boot loader. This searches for a key in ext ROM and
jumps at the code (boot_code) after the key.

boot_code inits EMIF and copies code from ext ROM to int RAM. Then it
jumps to to sdram_init.

sdram_init is now in int RAM. It copies code from ext ROM to ext RAM.
Then it calls c_int00. Which is the start of the program I really want
to run. c_int00 is now located in ext. RAM.

My problem is that the boot loader and the program I really want to run
have different stacks. So when boot_code and sdram_init are running they
store their return pointers onto the old stack. This destroys part of
the code.

I tried to force them not to use a return pointer by using the pragma
FUNC_NEVER_RETURNS. But this doesn't work. Any Idea why?

The other possibility is to set the stack to the new value in boot_code.
But I don't know how to do this in C.

TIA

Gustl_____________________________________
Note: If you do a simple "reply" with your email client, only the author of this message will receive your answer. You need to do a "reply all" if you want your answer to be distributed to the entire group.

_____________________________________
About this discussion group:

To Join: Send an email to c...@yahoogroups.com

To Post: Send an email to c...@yahoogroups.com

To Leave: Send an email to c...@yahoogroups.com

Archives: http://www.yahoogroups.com/group/c6x

Other Groups: http://www.dsprelated.com

Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/c6x/

<*> To unsubscribe from this group, send an email to:
c...@yahoogroups.com

<*





Hello Mike,

what I call boot loader is a program that is able to receive an
'application' via serial line and store it into flash. It also starts
the application. Boot loader and application have stacks at different
locations.

Initialisation is part of application and has to be run before c_int00.
Therefor SP points to the stack of boot loader. Initialisation
overrides this stack with code. When c_int00 is called a return address
is stored on the boot loader stack and destroys the code copied there.
So I have to prevent the return address to be stored
(FUNC_NEVER_RETURNS) or to load SP with the new location of the stack.

I have done this by:
asm(" MVK .S2 0xFFFF80FC,SP");
asm(" MVKH .S2 0x10000,SP");
asm(" AND .S2 -8,SP,SP");

I'm not sure if this is all I have to do?

Pragma FUNC_NEVER_RETURNS seams not to work. Why is a return address
stored if the function does not return?

Gustl

Mike Dunn wrote:

> Hello Gustl,
>
> I have read your email a couple of times, but i am not sure that i
> understand your problem.
>
> To simplify, I will call everything before the execution of _cint00 of
> your application 'initialization' and everything after 'application'.
>
> When initialization is running, it uses its own stack. At the end of
> initialization [when you 'goto' _cint00] you should be able to reuse any
> of the internal memory used by initialization. i assume that everything
> is working well at this point. if you are experiencing problems
> 'stepping on code' at this point, I would think that either your heap or
> stack is too small. Since you can reuse this memory, be generous with
> the stack and heap.
>
> The application should define and use its own stack and should not care
> or know anything about the original stack. This is why i am confused
> about your problem...
>
> mikedunn
>
> Bernhard 'Gustl' Bauer <> wrote: >
> Hi,
>
> im running a 6713 and have CCS 2.2
>
> First I start a boot loader. This searches for a key in ext ROM and
> jumps at the code (boot_code) after the key.
>
> boot_code inits EMIF and copies code from ext ROM to int RAM. Then it
> jumps to to sdram_init.
>
> sdram_init is now in int RAM. It copies code from ext ROM to ext RAM.
> Then it calls c_int00. Which is the start of the program I really want
> to run. c_int00 is now located in ext. RAM.
>
> My problem is that the boot loader and the program I really want to run
> have different stacks. So when boot_code and sdram_init are running
> they
> store their return pointers onto the old stack. This destroys part of
> the code.
>
> I tried to force them not to use a return pointer by using the pragma
> FUNC_NEVER_RETURNS. But this doesn't work. Any Idea why?
>
> The other possib! ility is to set the stack to the new value in
> boot_code.
> But I don't know how to do this in C.
>
> TIA
>
> Gustl
>





Gustl,
 
Why can't you 'goto' or branch to [via asm] c_int00??
 
I believe that the PRAGMA only serves to notify the compiler that a called function will not return - it does not prevent it from saving a return address.
 
mikedunn

Bernhard 'Gustl' Bauer <g...@quantec.de> wrote:


Hello Mike,

what I call boot loader is a program that is able to receive an
'application' via serial line and store it into flash. It also starts
the application. Boot loader and application have stacks at different
locations.

Initialisation is part of application and has to be run before c_int00.
Therefor SP points to the stack of boot loader. Initialisation
overrides this stack with code. When c_int00 is called a return address
is stored on the boot loader stack and destroys the code copied there.
So I have to prevent the return address to be stored
(FUNC_NEVER_RETURNS) or to load SP with the new location of the stack.

I have done this by:
asm(" MVK .S2 0xFFFF80FC,SP");
asm(" MVKH .S2 0x10000,SP");
asm(" AND .S2 -8,SP,SP");

I'm not sure if this is all I have to do?

Pragma FUNC_NEVER_RETURNS seams not to work. Why is a return address
stored if the function does not return?

Gustl

Mike Dunn wrote:

> Hello Gustl,
>
> I have read your email a couple of times, but i am not sure that i
> understand your problem.
>
> To simplify, I will call everything before the execution of _cint00 of
> your application 'initialization' and everything after 'application'.
>
> When initialization is running, it uses its own stack. At the end of
> initialization [when you 'goto' _cint00] you should be able to reuse any
> of the internal memory used by initialization. i assume that everything
> is working well at this point. if you are experiencing problems
> 'stepping on code' at this point, I would think that either your heap or
> stack is too small. Since you can reuse this memory, be generous with
> the stack and heap.
>
> The application should define and use its own stack and should not care
> or know anything about the original stack. This is why i am confused
> about your problem...
>
> mikedunn
>
> Bernhard 'Gustl' Bauer wrote:>
> Hi,
>
> im running a 6713 and have CCS 2.2
>
> First I start a boot loader. This searches for a key in ext ROM and
> jumps at the code (boot_code) after the key.
>
> boot_code inits EMIF and copies code from ext ROM to int RAM. Then it
> jumps to to sdram_init.
>
> sdram_init is now in int RAM. It copies code from ext ROM to ext RAM.
> Then it calls c_int00. Which is the start of the program I really want
> to run. c_int00 is now located in ext. RAM.
>
> My problem is that the boot loader and the program I really want to run
> have different stacks. So when boot_code and sdram_init are running
> they
> store their return pointers onto the old stack. This destroys part of
> the code.
>
> I tried to force them not to use a return pointer by using the pragma
> FUNC_NEVER_RETURNS. But this doesn't work. Any Idea why?
>
> The other possib! ility is to set the stack to the new value in
> boot_code.
> But I don't know how to do this in C.
>
> TIA
>
> Gustl

_____________________________________
Note: If you do a simple "reply" with your email client, only the author of this message will receive your answer. You need to do a "reply all" if you want your answer to be distributed to the entire group.

_____________________________________
About this discussion group:

To Join: Send an email to c...@yahoogroups.com

To Post: Send an email to c...@yahoogroups.com

To Leave: Send an email to c...@yahoogroups.com

Archives: http://www.yahoogroups.com/group/c6x

Other Groups: http://www.dsprelated.com

Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/c6x/

<*> To unsubscribe from this group, send an email to:
c...@yahoogroups.com

<*