Page 1 of 2

C function stack and core local memory

PostPosted: Mon Aug 05, 2013 8:46 pm
by CIB
I'm currently attempting to write a lightweight memory manager that's supposed to run on a single epiphany core. Now there's two questions I have:

1. Where is the C function stack stored, how large can it be potentially, and how do I avoid clashing with it?
2. How can I explicitly find out the address and size of the local memory of the current core, and how does that relate to my first question?

Thanks in advance!

Re: C function stack and core local memory

PostPosted: Mon Aug 05, 2013 9:14 pm
by EggBaconAndSpam
The latest linker scripts handle the stack as follows:
PROVIDE (__stack_start_ = ORIGIN(INTERNAL_RAM) + LENGTH(INTERNAL_RAM) - 0x10);
.stack __stack_start_ : { ___stack = .; *(.stack) }

This sets the stack to grow from (highest sram address - 0x10) downwards.
There are no hardware limitations as to how large it can become, the software side of things is described by the linker file (not my area of expertise).

Local SRAM memory always starts at 0x00000000. Concerning the size, I don't think the default linker scripts actually export any symbols concerning the memory setup, modifying them might help you there. (You could also just add a #define, you know)

Re: C function stack and core local memory

PostPosted: Mon Aug 05, 2013 9:25 pm
by CIB
EggBaconAndSpam wrote:The latest linker scripts handle the stack as follows:
PROVIDE (__stack_start_ = ORIGIN(INTERNAL_RAM) + LENGTH(INTERNAL_RAM) - 0x10);
.stack __stack_start_ : { ___stack = .; *(.stack) }

This sets the stack to grow from (highest sram address - 0x10) downwards.
There are no hardware limitations as to how large it can become, the software side of things is described by the linker file (not my area of expertise).


Thanks a bunch, I don't know very much about internal linker workings, so this really helps.

Local SRAM memory always starts at 0x00000000. Concerning the size, I don't think the default linker scripts actually export any symbols concerning the memory setup, modifying them might help you there. (You could also just add a #define, you know)


Ah, that's conveniently simple. Really sounds like I should have a look at that linker script, it might have more information on which memory areas I shouldn't touch.

Re: C function stack and core local memory

PostPosted: Mon Aug 05, 2013 10:53 pm
by timpart
Yes starting at address zero is convenient, but don't put a heap there as the interrupt vector table lives there. The linker by default puts code after the table then areas for data. The SDK manual gives some more info. The heap mentioned there usually resides in external RAM. Though I suppose you could tell the linker to put it in local RAM instead. Then C malloc would use that RAM. Limited in size though.

Tim

Re: C function stack and core local memory

PostPosted: Mon Aug 05, 2013 11:16 pm
by CIB
timpart wrote:Yes starting at address zero is convenient, but don't put a heap there as the interrupt vector table lives there. The linker by default puts code after the table then areas for data. The SDK manual gives some more info.


Mmm, yeah, I found it. Seems like I'll want to put my data either at .text_bank0 or .data_bank3, depending on whether those bank sections are used for anything important.

The heap mentioned there usually resides in external RAM. Though I suppose you could tell the linker to put it in local RAM instead. Then C malloc would use that RAM. Limited in size though.

Tim


Yup, I don't plan to use C malloc. Rather, I just want to manage a small amount of objects locally and try to completely do without SD-RAM(except when explicitly requested).

Re: C function stack and core local memory

PostPosted: Mon Aug 05, 2013 11:29 pm
by ysapir
Mmm, yeah, I found it. Seems like I'll want to put my data either at .text_bank0 or .data_bank3, depending on whether those bank sections are used for anything important.


Note that bank0 is used for IVT and code, by default.

Re: C function stack and core local memory

PostPosted: Tue Aug 06, 2013 1:43 am
by Gravis
ysapir wrote:Note that bank0 is used for IVT and code, by default.

by default? wait... is there a way to change the location of the IVT (like to a different bank)?

Re: C function stack and core local memory

PostPosted: Tue Aug 06, 2013 1:56 am
by ysapir
Gravis wrote:
ysapir wrote:Note that bank0 is used for IVT and code, by default.

by default? wait... is there a way to change the location of the IVT (like to a different bank)?


No. I was relating to the code.

Re: C function stack and core local memory

PostPosted: Tue Aug 06, 2013 2:08 am
by Gravis
ysapir wrote:
Gravis wrote:
ysapir wrote:Note that bank0 is used for IVT and code, by default.

by default? wait... is there a way to change the location of the IVT (like to a different bank)?

No. I was relating to the code.

i figured as much but hey... dare to dream. ;)

Re: C function stack and core local memory

PostPosted: Tue Aug 06, 2013 2:10 am
by hewsmike
If I may pose a related question : what is/are the typical/recommended assembly level instruction sequences/structures used to implement pushes and pops ?

[ That is : given that the only general register with implicit use is R14 ]

Cheers, Mike.