C function stack and core local memory

Any technical questions about the Epiphany chip and Parallella HW Platform.

Moderator: aolofsson

C function stack and core local memory

Postby CIB » Mon Aug 05, 2013 8:46 pm

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!
CIB
 
Posts: 108
Joined: Sat Jul 13, 2013 1:57 pm

Re: C function stack and core local memory

Postby EggBaconAndSpam » Mon Aug 05, 2013 9:14 pm

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)
EggBaconAndSpam
 
Posts: 32
Joined: Tue Jul 16, 2013 2:39 pm

Re: C function stack and core local memory

Postby CIB » Mon Aug 05, 2013 9:25 pm

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.
CIB
 
Posts: 108
Joined: Sat Jul 13, 2013 1:57 pm

Re: C function stack and core local memory

Postby timpart » Mon Aug 05, 2013 10:53 pm

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
timpart
 
Posts: 302
Joined: Mon Dec 17, 2012 3:25 am
Location: UK

Re: C function stack and core local memory

Postby CIB » Mon Aug 05, 2013 11:16 pm

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).
CIB
 
Posts: 108
Joined: Sat Jul 13, 2013 1:57 pm

Re: C function stack and core local memory

Postby ysapir » Mon Aug 05, 2013 11:29 pm

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.
User avatar
ysapir
 
Posts: 393
Joined: Tue Dec 11, 2012 7:05 pm

Re: C function stack and core local memory

Postby Gravis » Tue Aug 06, 2013 1:43 am

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)?
User avatar
Gravis
 
Posts: 445
Joined: Mon Dec 17, 2012 3:27 am
Location: East coast USA.

Re: C function stack and core local memory

Postby ysapir » Tue Aug 06, 2013 1:56 am

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.
User avatar
ysapir
 
Posts: 393
Joined: Tue Dec 11, 2012 7:05 pm

Re: C function stack and core local memory

Postby Gravis » Tue Aug 06, 2013 2:08 am

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. ;)
User avatar
Gravis
 
Posts: 445
Joined: Mon Dec 17, 2012 3:27 am
Location: East coast USA.

Re: C function stack and core local memory

Postby hewsmike » Tue Aug 06, 2013 2:10 am

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.
hewsmike
 
Posts: 85
Joined: Mon Dec 17, 2012 3:20 am

Next

Return to Epiphany and Parallella Q & A

Who is online

Users browsing this forum: Majestic-12 [Bot] and 6 guests